blob: 17c3395ebad71d0cfdbfc227db01c62855b02ea6 [file] [log] [blame]
Matt Spinler99c2b402019-05-23 14:29:16 -05001#include "elog_entry.hpp"
2#include "extensions.hpp"
3
4#include <gtest/gtest.h>
5
6using namespace phosphor::logging;
7
8// gtest doesn't like this happening in another file, so do it here.
9StartupFunctions Extensions::startupFunctions{};
10CreateFunctions Extensions::createFunctions{};
11DeleteFunctions Extensions::deleteFunctions{};
12DeleteProhibitedFunctions Extensions::deleteProhibitedFunctions{};
13Extensions::DefaultErrorCaps Extensions::defaultErrorCaps =
14 Extensions::DefaultErrorCaps::enable;
15
16void startup1(internal::Manager& manager)
17{
18}
19
20void startup2(internal::Manager& manager)
21{
22}
23
24void create1(const std::string& message, uint32_t id, uint64_t timestamp,
25 Entry::Level severity, const AdditionalDataArg& additionalData,
26 const AssociationEndpointsArg& assocs)
27{
28}
29
30void create2(const std::string& message, uint32_t id, uint64_t timestamp,
31 Entry::Level severity, const AdditionalDataArg& additionalData,
32 const AssociationEndpointsArg& assocs)
33{
34}
35
36void deleteLog1(uint32_t id)
37{
38}
39
40void deleteLog2(uint32_t id)
41{
42}
43
44void deleteProhibited1(uint32_t id, bool& prohibited)
45{
46 prohibited = true;
47}
48
49void deleteProhibited2(uint32_t id, bool& prohibited)
50{
51 prohibited = true;
52}
53
54DISABLE_LOG_ENTRY_CAPS();
55REGISTER_EXTENSION_FUNCTION(startup1);
56REGISTER_EXTENSION_FUNCTION(startup2);
57REGISTER_EXTENSION_FUNCTION(create1);
58REGISTER_EXTENSION_FUNCTION(create2);
59REGISTER_EXTENSION_FUNCTION(deleteProhibited1);
60REGISTER_EXTENSION_FUNCTION(deleteProhibited2);
61REGISTER_EXTENSION_FUNCTION(deleteLog1);
62REGISTER_EXTENSION_FUNCTION(deleteLog2);
63
64TEST(ExtensionsTest, FunctionCallTest)
65{
66 auto bus = sdbusplus::bus::new_default();
67 internal::Manager manager(bus, "testpath");
68
69 EXPECT_EQ(Extensions::getStartupFunctions().size(), 2);
70 for (auto& s : Extensions::getStartupFunctions())
71 {
72 s(manager);
73 }
74
75 AdditionalDataArg ad;
76 AssociationEndpointsArg assocs;
77 EXPECT_EQ(Extensions::getCreateFunctions().size(), 2);
78 for (auto& c : Extensions::getCreateFunctions())
79 {
80 c("test", 5, 6, Entry::Level::Informational, ad, assocs);
81 }
82
83 EXPECT_EQ(Extensions::getDeleteFunctions().size(), 2);
84 for (auto& d : Extensions::getDeleteFunctions())
85 {
86 d(5);
87 }
88
89 EXPECT_EQ(Extensions::getDeleteProhibitedFunctions().size(), 2);
90 for (auto& p : Extensions::getDeleteProhibitedFunctions())
91 {
92 bool prohibited = false;
93 p(5, prohibited);
94 EXPECT_TRUE(prohibited);
95 }
96
97 EXPECT_TRUE(Extensions::disableDefaultLogCaps());
98}