Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 1 | #include "data_types.hpp" |
| 2 | |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 3 | #include <array> |
| 4 | #include <string> |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 5 | |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 6 | #include <gtest/gtest.h> |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 7 | |
| 8 | using namespace std::string_literals; |
| 9 | using namespace phosphor::dbus::monitoring; |
| 10 | |
| 11 | using Property = |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 12 | TupleOfRefs<const std::string, const std::string, const std::string>; |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 13 | |
Brad Bishop | 6522cdc | 2018-07-10 12:04:04 -0400 | [diff] [blame] | 14 | using GroupOfProperties = std::vector<::Property>; |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 15 | |
| 16 | #include "propertygentest.hpp" |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 17 | const std::array<std::string, 3> expectedMeta = { |
Brad Bishop | babf3b7 | 2017-05-31 19:44:53 -0400 | [diff] [blame] | 18 | "PROPERTY1"s, |
| 19 | "PROPERTY2"s, |
| 20 | "PROPERTY3"s, |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 21 | }; |
| 22 | |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 23 | const std::array<std::string, 4> expectedInterfaces = { |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 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 | |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 30 | const std::array<std::string, 4> expectedProperties = { |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 31 | "Foo"s, |
| 32 | "Value"s, |
| 33 | "Bar"s, |
| 34 | "Baz"s, |
| 35 | }; |
| 36 | |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 37 | const std::array<GroupOfProperties, 4> expectedGroups = {{ |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 38 | { |
Brad Bishop | 6522cdc | 2018-07-10 12:04:04 -0400 | [diff] [blame] | 39 | ::Property{interfaces[0], properties[0], meta[0]}, |
| 40 | ::Property{interfaces[1], properties[1], meta[1]}, |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 41 | }, |
| 42 | { |
Brad Bishop | 6522cdc | 2018-07-10 12:04:04 -0400 | [diff] [blame] | 43 | ::Property{interfaces[0], properties[2], meta[0]}, |
| 44 | ::Property{interfaces[1], properties[0], meta[1]}, |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 45 | }, |
| 46 | { |
Brad Bishop | 6522cdc | 2018-07-10 12:04:04 -0400 | [diff] [blame] | 47 | ::Property{interfaces[2], properties[0], meta[0]}, |
| 48 | ::Property{interfaces[3], properties[1], meta[1]}, |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 49 | }, |
| 50 | { |
Brad Bishop | 6522cdc | 2018-07-10 12:04:04 -0400 | [diff] [blame] | 51 | ::Property{interfaces[0], properties[2], meta[0]}, |
| 52 | ::Property{interfaces[1], properties[1], meta[1]}, |
| 53 | ::Property{interfaces[2], properties[3], meta[2]}, |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 54 | }, |
| 55 | }}; |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 56 | |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 57 | const std::array<std::string, 4> expectedTypes = { |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 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 | { |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 94 | ASSERT_EQ(meta[i], expectedMeta[i]); |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | TEST(PropertyGenTest, IfacesSameContent) |
| 99 | { |
| 100 | size_t i; |
| 101 | for (i = 0; i < expectedInterfaces.size(); ++i) |
| 102 | { |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 103 | ASSERT_EQ(interfaces[i], expectedInterfaces[i]); |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 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 | |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 128 | const auto& expectedProperty = |
| 129 | std::get<1>(expectedGroups[i][j]).get(); |
Brad Bishop | c9e173f | 2017-05-09 00:23:11 -0400 | [diff] [blame] | 130 | 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 | |
| 140 | TEST(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 | } |