xref: /openbmc/phosphor-dbus-monitor/src/test/propertygentest.cpp (revision ecef119120e31b5bdf0d316c7303a9ce48831464)
13d6d3182SPatrick Venture #include "data_types.hpp"
23d6d3182SPatrick Venture 
3c9e173f8SBrad Bishop #include <array>
4c9e173f8SBrad Bishop #include <string>
53d6d3182SPatrick Venture 
6c9e173f8SBrad Bishop #include <gtest/gtest.h>
7c9e173f8SBrad Bishop 
8c9e173f8SBrad Bishop using namespace std::string_literals;
9c9e173f8SBrad Bishop using namespace phosphor::dbus::monitoring;
10c9e173f8SBrad Bishop 
11c9e173f8SBrad Bishop using Property =
12d1eac88dSBrad Bishop     TupleOfRefs<const std::string, const std::string, const std::string>;
13c9e173f8SBrad Bishop 
146522cdcbSBrad Bishop using GroupOfProperties = std::vector<::Property>;
15c9e173f8SBrad Bishop 
16c9e173f8SBrad Bishop #include "propertygentest.hpp"
17d1eac88dSBrad Bishop const std::array<std::string, 3> expectedMeta = {
18babf3b78SBrad Bishop     "PROPERTY1"s,
19babf3b78SBrad Bishop     "PROPERTY2"s,
20babf3b78SBrad Bishop     "PROPERTY3"s,
21c9e173f8SBrad Bishop };
22c9e173f8SBrad Bishop 
23d1eac88dSBrad Bishop const std::array<std::string, 4> expectedInterfaces = {
24c9e173f8SBrad Bishop     "xyz.openbmc_project.Test.Iface3"s,
25c9e173f8SBrad Bishop     "xyz.openbmc_project.Test.Iface2"s,
26c9e173f8SBrad Bishop     "xyz.openbmc_project.Test.Iface6"s,
27c9e173f8SBrad Bishop     "xyz.openbmc_project.Test.Iface1"s,
28c9e173f8SBrad Bishop };
29c9e173f8SBrad Bishop 
30d1eac88dSBrad Bishop const std::array<std::string, 4> expectedProperties = {
31c9e173f8SBrad Bishop     "Foo"s,
32c9e173f8SBrad Bishop     "Value"s,
33c9e173f8SBrad Bishop     "Bar"s,
34c9e173f8SBrad Bishop     "Baz"s,
35c9e173f8SBrad Bishop };
36c9e173f8SBrad Bishop 
37d1eac88dSBrad Bishop const std::array<GroupOfProperties, 4> expectedGroups = {{
38c9e173f8SBrad Bishop     {
396522cdcbSBrad Bishop         ::Property{interfaces[0], properties[0], meta[0]},
406522cdcbSBrad Bishop         ::Property{interfaces[1], properties[1], meta[1]},
41c9e173f8SBrad Bishop     },
42c9e173f8SBrad Bishop     {
436522cdcbSBrad Bishop         ::Property{interfaces[0], properties[2], meta[0]},
446522cdcbSBrad Bishop         ::Property{interfaces[1], properties[0], meta[1]},
45c9e173f8SBrad Bishop     },
46c9e173f8SBrad Bishop     {
476522cdcbSBrad Bishop         ::Property{interfaces[2], properties[0], meta[0]},
486522cdcbSBrad Bishop         ::Property{interfaces[3], properties[1], meta[1]},
49c9e173f8SBrad Bishop     },
50c9e173f8SBrad Bishop     {
516522cdcbSBrad Bishop         ::Property{interfaces[0], properties[2], meta[0]},
526522cdcbSBrad Bishop         ::Property{interfaces[1], properties[1], meta[1]},
536522cdcbSBrad Bishop         ::Property{interfaces[2], properties[3], meta[2]},
54c9e173f8SBrad Bishop     },
55d1eac88dSBrad Bishop }};
56c9e173f8SBrad Bishop 
57d1eac88dSBrad Bishop const std::array<std::string, 4> expectedTypes = {
58c9e173f8SBrad Bishop     "uint32_t"s,
59c9e173f8SBrad Bishop     "int32_t"s,
60c9e173f8SBrad Bishop     "std::string"s,
61c9e173f8SBrad Bishop     "int32_t"s,
62c9e173f8SBrad Bishop };
63c9e173f8SBrad Bishop 
TEST(PropertyGenTest,MetaSameSize)64c9e173f8SBrad Bishop TEST(PropertyGenTest, MetaSameSize)
65c9e173f8SBrad Bishop {
66c9e173f8SBrad Bishop     ASSERT_EQ(sizeof(expectedMeta), sizeof(meta));
67c9e173f8SBrad Bishop }
68c9e173f8SBrad Bishop 
TEST(PropertyGenTest,IfacesSameSize)69c9e173f8SBrad Bishop TEST(PropertyGenTest, IfacesSameSize)
70c9e173f8SBrad Bishop {
71c9e173f8SBrad Bishop     ASSERT_EQ(sizeof(expectedInterfaces), sizeof(interfaces));
72c9e173f8SBrad Bishop }
73c9e173f8SBrad Bishop 
TEST(PropertyGenTest,PropertiesSameSize)74c9e173f8SBrad Bishop TEST(PropertyGenTest, PropertiesSameSize)
75c9e173f8SBrad Bishop {
76c9e173f8SBrad Bishop     ASSERT_EQ(sizeof(expectedProperties), sizeof(properties));
77c9e173f8SBrad Bishop }
78c9e173f8SBrad Bishop 
TEST(PropertyGenTest,GroupsSameSize)79c9e173f8SBrad Bishop TEST(PropertyGenTest, GroupsSameSize)
80c9e173f8SBrad Bishop {
81c9e173f8SBrad Bishop     ASSERT_EQ(sizeof(expectedGroups), sizeof(groups));
82c9e173f8SBrad Bishop }
83c9e173f8SBrad Bishop 
TEST(PropertyGenTest,TypesSameSize)84c9e173f8SBrad Bishop TEST(PropertyGenTest, TypesSameSize)
85c9e173f8SBrad Bishop {
86c9e173f8SBrad Bishop     ASSERT_EQ(sizeof(expectedTypes), sizeof(types));
87c9e173f8SBrad Bishop }
88c9e173f8SBrad Bishop 
TEST(PropertyGenTest,MetaSameContent)89c9e173f8SBrad Bishop TEST(PropertyGenTest, MetaSameContent)
90c9e173f8SBrad Bishop {
91c9e173f8SBrad Bishop     size_t i;
92c9e173f8SBrad Bishop     for (i = 0; i < expectedMeta.size(); ++i)
93c9e173f8SBrad Bishop     {
94d1eac88dSBrad Bishop         ASSERT_EQ(meta[i], expectedMeta[i]);
95c9e173f8SBrad Bishop     }
96c9e173f8SBrad Bishop }
97c9e173f8SBrad Bishop 
TEST(PropertyGenTest,IfacesSameContent)98c9e173f8SBrad Bishop TEST(PropertyGenTest, IfacesSameContent)
99c9e173f8SBrad Bishop {
100c9e173f8SBrad Bishop     size_t i;
101c9e173f8SBrad Bishop     for (i = 0; i < expectedInterfaces.size(); ++i)
102c9e173f8SBrad Bishop     {
103d1eac88dSBrad Bishop         ASSERT_EQ(interfaces[i], expectedInterfaces[i]);
104c9e173f8SBrad Bishop     }
105c9e173f8SBrad Bishop }
106c9e173f8SBrad Bishop 
TEST(PropertyGenTest,PropertiesSameContent)107c9e173f8SBrad Bishop TEST(PropertyGenTest, PropertiesSameContent)
108c9e173f8SBrad Bishop {
109c9e173f8SBrad Bishop     size_t i;
110c9e173f8SBrad Bishop     for (i = 0; i < expectedProperties.size(); ++i)
111c9e173f8SBrad Bishop     {
112c9e173f8SBrad Bishop         ASSERT_EQ(expectedProperties[i], properties[i]);
113c9e173f8SBrad Bishop     }
114c9e173f8SBrad Bishop }
115c9e173f8SBrad Bishop 
TEST(PropertyGenTest,GroupsSameContent)116c9e173f8SBrad Bishop TEST(PropertyGenTest, GroupsSameContent)
117c9e173f8SBrad Bishop {
118c9e173f8SBrad Bishop     size_t i;
119c9e173f8SBrad Bishop     for (i = 0; i < expectedGroups.size(); ++i)
120c9e173f8SBrad Bishop     {
121c9e173f8SBrad Bishop         size_t j;
122c9e173f8SBrad Bishop         for (j = 0; j < expectedGroups[i].size(); ++j)
123c9e173f8SBrad Bishop         {
124c9e173f8SBrad Bishop             const auto& expectedIface = std::get<0>(expectedGroups[i][j]).get();
125c9e173f8SBrad Bishop             const auto& actualIface = std::get<0>(groups[i][j]).get();
126c9e173f8SBrad Bishop             ASSERT_EQ(expectedIface, actualIface);
127c9e173f8SBrad Bishop 
128d1eac88dSBrad Bishop             const auto& expectedProperty =
129d1eac88dSBrad Bishop                 std::get<1>(expectedGroups[i][j]).get();
130c9e173f8SBrad Bishop             const auto& actualProperty = std::get<1>(groups[i][j]).get();
131c9e173f8SBrad Bishop             ASSERT_EQ(expectedProperty, actualProperty);
132c9e173f8SBrad Bishop 
133*ecef1191SGeorge Liu             const auto& retExpectedMeta =
134*ecef1191SGeorge Liu                 std::get<1>(expectedGroups[i][j]).get();
135*ecef1191SGeorge Liu             const auto& retActualMeta = std::get<1>(groups[i][j]).get();
136*ecef1191SGeorge Liu             ASSERT_EQ(retExpectedMeta, retActualMeta);
137c9e173f8SBrad Bishop         }
138c9e173f8SBrad Bishop     }
139c9e173f8SBrad Bishop }
140c9e173f8SBrad Bishop 
TEST(PropertyGenTest,TypesSameContent)141c9e173f8SBrad Bishop TEST(PropertyGenTest, TypesSameContent)
142c9e173f8SBrad Bishop {
143c9e173f8SBrad Bishop     size_t i;
144c9e173f8SBrad Bishop     for (i = 0; i < expectedTypes.size(); ++i)
145c9e173f8SBrad Bishop     {
146c9e173f8SBrad Bishop         ASSERT_EQ(expectedTypes[i], types[i]);
147c9e173f8SBrad Bishop     }
148c9e173f8SBrad Bishop }
149