osquery-1/osquery/dispatcher/dispatcher_tests.cpp
2015-02-24 03:47:12 -08:00

54 lines
1.3 KiB
C++

/*
* 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.
*
*/
#include <boost/make_shared.hpp>
#include <gtest/gtest.h>
#include "osquery/dispatcher/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 InternalRunnable {
public:
int* i;
explicit TestRunnable(int* i) : i(i) {}
virtual void enter() { ++*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(OSQUERY_THRIFT_POINTER::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();
}