2014-12-18 18:50:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
2014-12-03 23:14:02 +00:00
|
|
|
#include <osquery/core.h>
|
2014-09-13 21:28:45 +00:00
|
|
|
#include "osquery/core/test_util.h"
|
|
|
|
|
|
|
|
namespace osquery {
|
|
|
|
namespace core {
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
class TestUtilTests : public testing::Test {};
|
|
|
|
|
|
|
|
TEST_F(TestUtilTests, test_expected_results) {
|
|
|
|
int err;
|
2014-08-30 10:07:14 +00:00
|
|
|
auto db = createTestDB();
|
2014-09-16 06:07:03 +00:00
|
|
|
auto results = query(kTestQuery, err, db);
|
2014-08-30 10:07:14 +00:00
|
|
|
sqlite3_close(db);
|
2014-07-31 00:35:19 +00:00
|
|
|
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;
|
2014-09-16 06:07:03 +00:00
|
|
|
auto expected = query(kTestQuery, err_int, db);
|
2014-07-31 00:35:19 +00:00
|
|
|
EXPECT_EQ(expected, r.second);
|
|
|
|
}
|
2014-08-30 10:49:49 +00:00
|
|
|
sqlite3_close(db);
|
2014-07-31 00:35:19 +00:00
|
|
|
}
|
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();
|
|
|
|
}
|