blob: 41242460c1ac7173ca19c5eebecec47561b0cc33 [file] [log] [blame]
Patrick Venture3d6d3182018-08-31 09:33:09 -07001#include "data_types.hpp"
2
Brad Bishopc9e173f2017-05-09 00:23:11 -04003#include <array>
4#include <string>
Patrick Venture3d6d3182018-08-31 09:33:09 -07005
Brad Bishopc9e173f2017-05-09 00:23:11 -04006#include <gtest/gtest.h>
Brad Bishopc9e173f2017-05-09 00:23:11 -04007
8using namespace std::string_literals;
9using namespace phosphor::dbus::monitoring;
10
11using Property =
Brad Bishopd1eac882018-03-29 10:34:05 -040012 TupleOfRefs<const std::string, const std::string, const std::string>;
Brad Bishopc9e173f2017-05-09 00:23:11 -040013
Brad Bishop6522cdc2018-07-10 12:04:04 -040014using GroupOfProperties = std::vector<::Property>;
Brad Bishopc9e173f2017-05-09 00:23:11 -040015
16#include "propertygentest.hpp"
Brad Bishopd1eac882018-03-29 10:34:05 -040017const std::array<std::string, 3> expectedMeta = {
Brad Bishopbabf3b72017-05-31 19:44:53 -040018 "PROPERTY1"s,
19 "PROPERTY2"s,
20 "PROPERTY3"s,
Brad Bishopc9e173f2017-05-09 00:23:11 -040021};
22
Brad Bishopd1eac882018-03-29 10:34:05 -040023const std::array<std::string, 4> expectedInterfaces = {
Brad Bishopc9e173f2017-05-09 00:23:11 -040024 "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
Brad Bishopd1eac882018-03-29 10:34:05 -040030const std::array<std::string, 4> expectedProperties = {
Brad Bishopc9e173f2017-05-09 00:23:11 -040031 "Foo"s,
32 "Value"s,
33 "Bar"s,
34 "Baz"s,
35};
36
Brad Bishopd1eac882018-03-29 10:34:05 -040037const std::array<GroupOfProperties, 4> expectedGroups = {{
Brad Bishopc9e173f2017-05-09 00:23:11 -040038 {
Brad Bishop6522cdc2018-07-10 12:04:04 -040039 ::Property{interfaces[0], properties[0], meta[0]},
40 ::Property{interfaces[1], properties[1], meta[1]},
Brad Bishopd1eac882018-03-29 10:34:05 -040041 },
42 {
Brad Bishop6522cdc2018-07-10 12:04:04 -040043 ::Property{interfaces[0], properties[2], meta[0]},
44 ::Property{interfaces[1], properties[0], meta[1]},
Brad Bishopd1eac882018-03-29 10:34:05 -040045 },
46 {
Brad Bishop6522cdc2018-07-10 12:04:04 -040047 ::Property{interfaces[2], properties[0], meta[0]},
48 ::Property{interfaces[3], properties[1], meta[1]},
Brad Bishopd1eac882018-03-29 10:34:05 -040049 },
50 {
Brad Bishop6522cdc2018-07-10 12:04:04 -040051 ::Property{interfaces[0], properties[2], meta[0]},
52 ::Property{interfaces[1], properties[1], meta[1]},
53 ::Property{interfaces[2], properties[3], meta[2]},
Brad Bishopd1eac882018-03-29 10:34:05 -040054 },
55}};
Brad Bishopc9e173f2017-05-09 00:23:11 -040056
Brad Bishopd1eac882018-03-29 10:34:05 -040057const std::array<std::string, 4> expectedTypes = {
Brad Bishopc9e173f2017-05-09 00:23:11 -040058 "uint32_t"s,
59 "int32_t"s,
60 "std::string"s,
61 "int32_t"s,
62};
63
64TEST(PropertyGenTest, MetaSameSize)
65{
66 ASSERT_EQ(sizeof(expectedMeta), sizeof(meta));
67}
68
69TEST(PropertyGenTest, IfacesSameSize)
70{
71 ASSERT_EQ(sizeof(expectedInterfaces), sizeof(interfaces));
72}
73
74TEST(PropertyGenTest, PropertiesSameSize)
75{
76 ASSERT_EQ(sizeof(expectedProperties), sizeof(properties));
77}
78
79TEST(PropertyGenTest, GroupsSameSize)
80{
81 ASSERT_EQ(sizeof(expectedGroups), sizeof(groups));
82}
83
84TEST(PropertyGenTest, TypesSameSize)
85{
86 ASSERT_EQ(sizeof(expectedTypes), sizeof(types));
87}
88
89TEST(PropertyGenTest, MetaSameContent)
90{
91 size_t i;
92 for (i = 0; i < expectedMeta.size(); ++i)
93 {
Brad Bishopd1eac882018-03-29 10:34:05 -040094 ASSERT_EQ(meta[i], expectedMeta[i]);
Brad Bishopc9e173f2017-05-09 00:23:11 -040095 }
96}
97
98TEST(PropertyGenTest, IfacesSameContent)
99{
100 size_t i;
101 for (i = 0; i < expectedInterfaces.size(); ++i)
102 {
Brad Bishopd1eac882018-03-29 10:34:05 -0400103 ASSERT_EQ(interfaces[i], expectedInterfaces[i]);
Brad Bishopc9e173f2017-05-09 00:23:11 -0400104 }
105}
106
107TEST(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
116TEST(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
Brad Bishopd1eac882018-03-29 10:34:05 -0400128 const auto& expectedProperty =
129 std::get<1>(expectedGroups[i][j]).get();
Brad Bishopc9e173f2017-05-09 00:23:11 -0400130 const auto& actualProperty = std::get<1>(groups[i][j]).get();
131 ASSERT_EQ(expectedProperty, actualProperty);
132
133 const auto& expectedMeta = std::get<1>(expectedGroups[i][j]).get();
134 const auto& actualMeta = std::get<1>(groups[i][j]).get();
135 ASSERT_EQ(expectedMeta, actualMeta);
136 }
137 }
138}
139
140TEST(PropertyGenTest, TypesSameContent)
141{
142 size_t i;
143 for (i = 0; i < expectedTypes.size(); ++i)
144 {
145 ASSERT_EQ(expectedTypes[i], types[i]);
146 }
147}