mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-06 09:35:20 +00:00
events: Memoize EventFactory::getType (#6555)
This commit is contained in:
parent
4be11919c1
commit
ffdd5763a8
@ -71,17 +71,30 @@ class AnotherFakeEventPublisher
|
||||
};
|
||||
|
||||
TEST_F(EventsTests, test_event_publisher) {
|
||||
// Inspect the publisher "type", which is the publisher "name".
|
||||
auto pub = std::make_shared<FakeEventPublisher>();
|
||||
EXPECT_EQ(pub->type(), "FakePublisher");
|
||||
EXPECT_EQ(EventFactory::getType<FakeEventPublisher>(), "FakePublisher");
|
||||
// This is different for each publisher with an overridden type().
|
||||
EXPECT_EQ(EventFactory::getType<AnotherFakeEventPublisher>(),
|
||||
"AnotherFakePublisher");
|
||||
|
||||
// Test type names.
|
||||
auto pub_sub = pub->createSubscriptionContext();
|
||||
EXPECT_EQ(typeid(FakeSubscriptionContext), typeid(*pub_sub));
|
||||
|
||||
// This publisher has no type.
|
||||
auto basic_pub = std::make_shared<BasicEventPublisher>();
|
||||
EXPECT_TRUE(basic_pub->type().empty());
|
||||
EXPECT_TRUE(EventFactory::getType<BasicEventPublisher>().empty());
|
||||
basic_pub->setName("BasicPublisher");
|
||||
EXPECT_EQ(basic_pub->type(), "BasicPublisher");
|
||||
}
|
||||
|
||||
TEST_F(EventsTests, test_register_event_publisher) {
|
||||
auto basic_pub = std::make_shared<BasicEventPublisher>();
|
||||
auto status = EventFactory::registerEventPublisher(basic_pub);
|
||||
// This publisher has no type set, registration will fail.
|
||||
EXPECT_FALSE(status.ok());
|
||||
|
||||
// Set a name for the publisher, which becomes the type by default.
|
||||
|
@ -884,8 +884,8 @@ class EventFactory : private boost::noncopyable {
|
||||
*/
|
||||
template <class PUB>
|
||||
static const std::string getType() {
|
||||
auto pub = std::make_shared<PUB>();
|
||||
return pub->type();
|
||||
static std::string _type = std::make_shared<PUB>()->type();
|
||||
return _type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user