<commit_before>// Copyright 2004-present Facebook. All Rights Reserved.

#include "osquery/core/test_util.h"

#include <gtest/gtest.h>
#include <glog/logging.h>

#include <sqlite3.h>

using namespace osquery::core;

class TestUtilTests : public testing::Test {};

TEST_F(TestUtilTests, test_expected_results) {
  int err;
  auto db = createTestDB();
  auto results = aggregateQuery(kTestQuery, err, db);
  sqlite3_close(db);
  EXPECT_EQ(err, 0);
  EXPECT_EQ(results, getTestDBExpectedResults());
}

TEST_F(TestUtilTests, test_get_test_db_result_stream) {
  auto db = createTestDB();
  auto results = getTestDBResultStream();
  for (auto r : results) {
    char* err_char = nullptr;
    sqlite3_exec(db, (r.first).c_str(), nullptr, nullptr, &err_char);
    EXPECT_TRUE(err_char == nullptr);
    if (err_char != nullptr) {
      sqlite3_free(err_char);
      ASSERT_TRUE(false);
    }
    int err_int;
    auto expected = aggregateQuery(kTestQuery, err_int, db);
    sqlite3_close(db);
    EXPECT_EQ(expected, r.second);
  }
}

int main(int argc, char* argv[]) {
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
<commit_msg>was closing the db in the middle of the loop instead of after it, causing subsequent queries to fail<commit_after>// Copyright 2004-present Facebook. All Rights Reserved.

#include "osquery/core/test_util.h"

#include <gtest/gtest.h>
#include <glog/logging.h>

#include <sqlite3.h>

using namespace osquery::core;

class TestUtilTests : public testing::Test {};

TEST_F(TestUtilTests, test_expected_results) {
  int err;
  auto db = createTestDB();
  auto results = aggregateQuery(kTestQuery, err, db);
  sqlite3_close(db);
  EXPECT_EQ(err, 0);
  EXPECT_EQ(results, getTestDBExpectedResults());
}

TEST_F(TestUtilTests, test_get_test_db_result_stream) {
  auto db = createTestDB();
  auto results = getTestDBResultStream();
  for (auto r : results) {
    char* err_char = nullptr;
    sqlite3_exec(db, (r.first).c_str(), nullptr, nullptr, &err_char);
    EXPECT_TRUE(err_char == nullptr);
    if (err_char != nullptr) {
      sqlite3_free(err_char);
      ASSERT_TRUE(false);
    }
    int err_int;
    auto expected = aggregateQuery(kTestQuery, err_int, db);
    EXPECT_EQ(expected, r.second);
  }
  sqlite3_close(db);
}

int main(int argc, char* argv[]) {
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

{'fraction_non_alphanumeric': 0.12801013941698353, 'fraction_numerical': 0.008449514152936205, 'mean_word_length': 4.624703087885986, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '342095', 'n_tokens_mistral': 834, 'n_tokens_neox': 831, 'n_words': 188}