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