2014-07-31 00:35:19 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#include "osquery/core/test_util.h"
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <glog/logging.h>
|
|
|
|
|
2014-08-12 00:37:49 +00:00
|
|
|
#include <sqlite3.h>
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
using namespace osquery::core;
|
|
|
|
|
|
|
|
class TestUtilTests : public testing::Test {};
|
|
|
|
|
|
|
|
TEST_F(TestUtilTests, test_expected_results) {
|
|
|
|
int err;
|
|
|
|
auto results = aggregateQuery(kTestQuery, err, createTestDB());
|
|
|
|
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) {
|
2014-08-15 07:25:30 +00:00
|
|
|
char* err_char = nullptr;
|
2014-07-31 00:35:19 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|