osquery-1/osquery/dispatcher/dispatcher_tests.cpp
2014-12-03 15:14:02 -08:00

44 lines
983 B
C++

// Copyright 2004-present Facebook. All Rights Reserved.
#include <gtest/gtest.h>
#include <osquery/dispatcher.h>
namespace osquery {
class DispatcherTests : public testing::Test {};
TEST_F(DispatcherTests, test_singleton) {
auto& one = Dispatcher::getInstance();
auto& two = Dispatcher::getInstance();
EXPECT_EQ(one.getThreadManager().get(), two.getThreadManager().get());
}
class TestRunnable : public apache::thrift::concurrency::Runnable {
public:
int* i;
TestRunnable(int* i) : i(i) {}
virtual void run() { ++*i; }
};
TEST_F(DispatcherTests, test_add_work) {
auto& dispatcher = Dispatcher::getInstance();
int base = 5;
int repetitions = 1;
int i = base;
for (int c = 0; c < repetitions; ++c) {
dispatcher.add(std::make_shared<TestRunnable>(&i));
}
while (dispatcher.totalTaskCount() > 0) {
}
EXPECT_EQ(i, base + repetitions);
}
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}