osquery-1/osquery/core/sqlite_util_tests.cpp

50 lines
1.1 KiB
C++
Raw Normal View History

2014-07-31 00:35:19 +00:00
// Copyright 2004-present Facebook. All Rights Reserved.
#include "osquery/core.h"
2014-08-06 00:37:04 +00:00
#include "osquery/core/sqlite_util.h"
2014-07-31 00:35:19 +00:00
#include <iostream>
#include <gtest/gtest.h>
#include <glog/logging.h>
#include "osquery/core/test_util.h"
using namespace osquery::core;
using namespace osquery::db;
class SQLiteUtilTests : public testing::Test {};
TEST_F(SQLiteUtilTests, test_simple_query_execution) {
int err;
auto db = createTestDB();
auto results = aggregateQuery(kTestQuery, err, db);
sqlite3_close(db);
2014-07-31 00:35:19 +00:00
EXPECT_EQ(err, 0);
EXPECT_EQ(results, getTestDBExpectedResults());
}
TEST_F(SQLiteUtilTests, test_passing_callback_no_data_param) {
2014-08-15 07:25:30 +00:00
char* err = nullptr;
auto db = createTestDB();
2014-08-30 11:06:21 +00:00
sqlite3_exec(db, kTestQuery.c_str(), query_data_callback, nullptr, &err);
sqlite3_close(db);
2014-07-31 00:35:19 +00:00
EXPECT_TRUE(err != nullptr);
if (err != nullptr) {
sqlite3_free(err);
}
}
TEST_F(SQLiteUtilTests, test_aggregate_query) {
int err;
auto db = createTestDB();
QueryData d = aggregateQuery(kTestQuery, err, db);
sqlite3_close(db);
2014-07-31 00:35:19 +00:00
EXPECT_EQ(err, 0);
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}