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