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 "osquery/core/test_util.h"
|
|
|
|
|
2014-09-13 21:28:45 +00:00
|
|
|
namespace osquery {
|
|
|
|
namespace core {
|
|
|
|
|
2014-07-31 00:35:19 +00:00
|
|
|
class SQLiteUtilTests : public testing::Test {};
|
|
|
|
|
|
|
|
TEST_F(SQLiteUtilTests, test_simple_query_execution) {
|
|
|
|
int err;
|
2014-08-21 21:35:51 +00:00
|
|
|
auto db = createTestDB();
|
2014-09-16 06:07:03 +00:00
|
|
|
auto results = query(kTestQuery, err, db);
|
2014-08-21 21:35:51 +00:00
|
|
|
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;
|
2014-08-21 21:35:51 +00:00
|
|
|
auto db = createTestDB();
|
2014-08-30 11:06:21 +00:00
|
|
|
sqlite3_exec(db, kTestQuery.c_str(), query_data_callback, nullptr, &err);
|
2014-08-21 21:35:51 +00:00
|
|
|
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;
|
2014-08-21 21:35:51 +00:00
|
|
|
auto db = createTestDB();
|
2014-09-16 06:07:03 +00:00
|
|
|
QueryData d = query(kTestQuery, err, db);
|
2014-08-21 21:35:51 +00:00
|
|
|
sqlite3_close(db);
|
2014-07-31 00:35:19 +00:00
|
|
|
EXPECT_EQ(err, 0);
|
|
|
|
}
|
2014-09-13 21:28:45 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
testing::InitGoogleTest(&argc, argv);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|