osquery-1/osquery/dispatcher/dispatcher_tests.cpp

52 lines
1.2 KiB
C++
Raw Normal View History

/*
* 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 <gtest/gtest.h>
2015-02-19 23:19:00 +00:00
#include "osquery/dispatcher/dispatcher.h"
namespace osquery {
class DispatcherTests : public testing::Test {};
TEST_F(DispatcherTests, test_singleton) {
2014-09-30 02:06:33 +00:00
auto& one = Dispatcher::getInstance();
auto& two = Dispatcher::getInstance();
EXPECT_EQ(one.getThreadManager().get(), two.getThreadManager().get());
}
2015-02-04 03:55:16 +00:00
class TestRunnable : public InternalRunnable {
public:
int* i;
TestRunnable(int* i) : i(i) {}
2015-02-05 01:31:06 +00:00
virtual void enter() { ++*i; }
};
TEST_F(DispatcherTests, test_add_work) {
2014-09-30 02:06:33 +00:00
auto& dispatcher = Dispatcher::getInstance();
int base = 5;
2014-09-13 21:18:54 +00:00
int repetitions = 1;
int i = base;
2014-09-13 21:18:54 +00:00
for (int c = 0; c < repetitions; ++c) {
2014-09-30 02:06:33 +00:00
dispatcher.add(std::make_shared<TestRunnable>(&i));
}
2014-09-30 02:06:33 +00:00
while (dispatcher.totalTaskCount() > 0) {
}
2014-09-13 21:18:54 +00:00
EXPECT_EQ(i, base + repetitions);
}
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}