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