blob: e9da73346baff5e7da3a9db6a28783480c806f96 [file] [log] [blame]
Brad Bishopc9e173f2017-05-09 00:23:11 -04001#include <array>
2#include <string>
3#include <gtest/gtest.h>
4#include "data_types.hpp"
5
6using namespace std::string_literals;
7using namespace phosphor::dbus::monitoring;
8
9using Property =
Brad Bishopd1eac882018-03-29 10:34:05 -040010 TupleOfRefs<const std::string, const std::string, const std::string>;
Brad Bishopc9e173f2017-05-09 00:23:11 -040011
Brad Bishop6522cdc2018-07-10 12:04:04 -040012using GroupOfProperties = std::vector<::Property>;
Brad Bishopc9e173f2017-05-09 00:23:11 -040013
14#include "propertygentest.hpp"
Brad Bishopd1eac882018-03-29 10:34:05 -040015const std::array<std::string, 3> expectedMeta = {
Brad Bishopbabf3b72017-05-31 19:44:53 -040016 "PROPERTY1"s,
17 "PROPERTY2"s,
18 "PROPERTY3"s,
Brad Bishopc9e173f2017-05-09 00:23:11 -040019};
20
Brad Bishopd1eac882018-03-29 10:34:05 -040021const std::array<std::string, 4> expectedInterfaces = {
Brad Bishopc9e173f2017-05-09 00:23:11 -040022 "xyz.openbmc_project.Test.Iface3"s,
23 "xyz.openbmc_project.Test.Iface2"s,
24 "xyz.openbmc_project.Test.Iface6"s,
25 "xyz.openbmc_project.Test.Iface1"s,
26};
27
Brad Bishopd1eac882018-03-29 10:34:05 -040028const std::array<std::string, 4> expectedProperties = {
Brad Bishopc9e173f2017-05-09 00:23:11 -040029 "Foo"s,
30 "Value"s,
31 "Bar"s,
32 "Baz"s,
33};
34
Brad Bishopd1eac882018-03-29 10:34:05 -040035const std::array<GroupOfProperties, 4> expectedGroups = {{
Brad Bishopc9e173f2017-05-09 00:23:11 -040036 {
Brad Bishop6522cdc2018-07-10 12:04:04 -040037 ::Property{interfaces[0], properties[0], meta[0]},
38 ::Property{interfaces[1], properties[1], meta[1]},
Brad Bishopd1eac882018-03-29 10:34:05 -040039 },
40 {
Brad Bishop6522cdc2018-07-10 12:04:04 -040041 ::Property{interfaces[0], properties[2], meta[0]},
42 ::Property{interfaces[1], properties[0], meta[1]},
Brad Bishopd1eac882018-03-29 10:34:05 -040043 },
44 {
Brad Bishop6522cdc2018-07-10 12:04:04 -040045 ::Property{interfaces[2], properties[0], meta[0]},
46 ::Property{interfaces[3], properties[1], meta[1]},
Brad Bishopd1eac882018-03-29 10:34:05 -040047 },
48 {
Brad Bishop6522cdc2018-07-10 12:04:04 -040049 ::Property{interfaces[0], properties[2], meta[0]},
50 ::Property{interfaces[1], properties[1], meta[1]},
51 ::Property{interfaces[2], properties[3], meta[2]},
Brad Bishopd1eac882018-03-29 10:34:05 -040052 },
53}};
Brad Bishopc9e173f2017-05-09 00:23:11 -040054
Brad Bishopd1eac882018-03-29 10:34:05 -040055const std::array<std::string, 4> expectedTypes = {
Brad Bishopc9e173f2017-05-09 00:23:11 -040056 "uint32_t"s,
57 "int32_t"s,
58 "std::string"s,
59 "int32_t"s,
60};
61
62TEST(PropertyGenTest, MetaSameSize)
63{
64 ASSERT_EQ(sizeof(expectedMeta), sizeof(meta));
65}
66
67TEST(PropertyGenTest, IfacesSameSize)
68{
69 ASSERT_EQ(sizeof(expectedInterfaces), sizeof(interfaces));
70}
71
72TEST(PropertyGenTest, PropertiesSameSize)
73{
74 ASSERT_EQ(sizeof(expectedProperties), sizeof(properties));
75}
76
77TEST(PropertyGenTest, GroupsSameSize)
78{
79 ASSERT_EQ(sizeof(expectedGroups), sizeof(groups));
80}
81
82TEST(PropertyGenTest, TypesSameSize)
83{
84 ASSERT_EQ(sizeof(expectedTypes), sizeof(types));
85}
86
87TEST(PropertyGenTest, MetaSameContent)
88{
89 size_t i;
90 for (i = 0; i < expectedMeta.size(); ++i)
91 {
Brad Bishopd1eac882018-03-29 10:34:05 -040092 ASSERT_EQ(meta[i], expectedMeta[i]);
Brad Bishopc9e173f2017-05-09 00:23:11 -040093 }
94}
95
96TEST(PropertyGenTest, IfacesSameContent)
97{
98 size_t i;
99 for (i = 0; i < expectedInterfaces.size(); ++i)
100 {
Brad Bishopd1eac882018-03-29 10:34:05 -0400101 ASSERT_EQ(interfaces[i], expectedInterfaces[i]);
Brad Bishopc9e173f2017-05-09 00:23:11 -0400102 }
103}
104
105TEST(PropertyGenTest, PropertiesSameContent)
106{
107 size_t i;
108 for (i = 0; i < expectedProperties.size(); ++i)
109 {
110 ASSERT_EQ(expectedProperties[i], properties[i]);
111 }
112}
113
114TEST(PropertyGenTest, GroupsSameContent)
115{
116 size_t i;
117 for (i = 0; i < expectedGroups.size(); ++i)
118 {
119 size_t j;
120 for (j = 0; j < expectedGroups[i].size(); ++j)
121 {
122 const auto& expectedIface = std::get<0>(expectedGroups[i][j]).get();
123 const auto& actualIface = std::get<0>(groups[i][j]).get();
124 ASSERT_EQ(expectedIface, actualIface);
125
Brad Bishopd1eac882018-03-29 10:34:05 -0400126 const auto& expectedProperty =
127 std::get<1>(expectedGroups[i][j]).get();
Brad Bishopc9e173f2017-05-09 00:23:11 -0400128 const auto& actualProperty = std::get<1>(groups[i][j]).get();
129 ASSERT_EQ(expectedProperty, actualProperty);
130
131 const auto& expectedMeta = std::get<1>(expectedGroups[i][j]).get();
132 const auto& actualMeta = std::get<1>(groups[i][j]).get();
133 ASSERT_EQ(expectedMeta, actualMeta);
134 }
135 }
136}
137
138TEST(PropertyGenTest, TypesSameContent)
139{
140 size_t i;
141 for (i = 0; i < expectedTypes.size(); ++i)
142 {
143 ASSERT_EQ(expectedTypes[i], types[i]);
144 }
145}