osquery-1/osquery/registry/registry_tests.cpp

56 lines
1.2 KiB
C++
Raw Normal View History

2014-07-31 00:35:19 +00:00
// Copyright 2004-present Facebook. All Rights Reserved.
#include <osquery/registry.h>
2014-07-31 00:35:19 +00:00
#include <memory>
#include <string>
#include <glog/logging.h>
2014-08-06 00:37:04 +00:00
#include <gtest/gtest.h>
2014-07-31 00:35:19 +00:00
class TestPlugin {
2014-08-15 07:25:30 +00:00
public:
virtual std::string getName() { return "test_base"; }
2014-07-31 00:35:19 +00:00
virtual ~TestPlugin() {}
2014-08-15 07:25:30 +00:00
protected:
2014-09-21 21:29:28 +00:00
TestPlugin(){};
2014-07-31 00:35:19 +00:00
};
2014-08-15 07:25:30 +00:00
DECLARE_REGISTRY(TestPlugins, std::string, std::shared_ptr<TestPlugin>)
2014-07-31 00:35:19 +00:00
#define REGISTERED_TEST_PLUGINS REGISTRY(TestPlugins)
#define REGISTER_TEST_PLUGIN(name, decorator) \
REGISTER(TestPlugins, name, decorator)
class TestPluginInstance : public TestPlugin {
2014-08-15 07:25:30 +00:00
public:
2014-09-21 21:29:28 +00:00
TestPluginInstance(){};
2014-07-31 00:35:19 +00:00
2014-08-15 07:25:30 +00:00
std::string getName() { return std::string("test_1"); }
2014-07-31 00:35:19 +00:00
virtual ~TestPluginInstance() {}
};
REGISTER_TEST_PLUGIN("test_1", std::make_shared<TestPluginInstance>());
class RegistryTests : public testing::Test {
2014-08-15 07:25:30 +00:00
public:
RegistryTests() { osquery::InitRegistry::get().run(); }
2014-07-31 00:35:19 +00:00
};
TEST_F(RegistryTests, test_plugin_method) {
auto plugin = REGISTERED_TEST_PLUGINS.at("test_1");
EXPECT_EQ(plugin->getName(), "test_1");
}
TEST_F(RegistryTests, test_plugin_map) {
EXPECT_EQ(REGISTERED_TEST_PLUGINS.size(), 1);
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}