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 using PathMeta = TupleOfRefs<const std::string, const std::string>; 9 10 #include "pathgentest.hpp" 11 12 const std::array<std::string, 3> expectedMeta = 13 { 14 "path1"s, 15 "path3"s, 16 "path2"s, 17 }; 18 19 const std::array<std::string, 6> expectedPaths = 20 { 21 "/xyz/openbmc_project/testing/inst1"s, 22 "/xyz/openbmc_project/testing/inst2"s, 23 "/xyz/openbmc_project/testing/inst3"s, 24 "/xyz/openbmc_project/testing/inst4"s, 25 "/xyz/openbmc_project/testing/inst5"s, 26 "/xyz/openbmc_project/testing/inst6"s, 27 }; 28 29 const std::array<PathMeta, 14> expectedPathMeta = 30 { 31 { 32 PathMeta{ paths[0], meta[0] }, 33 PathMeta{ paths[1], meta[0] }, 34 PathMeta{ paths[2], meta[0] }, 35 PathMeta{ paths[3], meta[0] }, 36 PathMeta{ paths[0], meta[1] }, 37 PathMeta{ paths[1], meta[1] }, 38 PathMeta{ paths[2], meta[1] }, 39 PathMeta{ paths[3], meta[1] }, 40 PathMeta{ paths[4], meta[0] }, 41 PathMeta{ paths[5], meta[0] }, 42 PathMeta{ paths[3], meta[2] }, 43 PathMeta{ paths[2], meta[2] }, 44 PathMeta{ paths[1], meta[2] }, 45 PathMeta{ paths[0], meta[2] }, 46 } 47 }; 48 49 const std::array<RefVector<const std::string>, 4> expectedGroups = 50 { 51 { 52 { 53 paths[0], 54 paths[1], 55 paths[2], 56 paths[3], 57 }, 58 { 59 paths[0], 60 paths[1], 61 paths[2], 62 paths[3], 63 }, 64 { 65 paths[0], 66 paths[1], 67 paths[4], 68 paths[5], 69 }, 70 { 71 paths[3], 72 paths[2], 73 paths[1], 74 paths[0], 75 }, 76 } 77 }; 78 79 TEST(PathGenTest, MetaSameSize) 80 { 81 ASSERT_EQ(sizeof(expectedMeta), sizeof(meta)); 82 } 83 84 TEST(PathGenTest, PathsSameSize) 85 { 86 ASSERT_EQ(sizeof(expectedPaths), sizeof(paths)); 87 } 88 89 TEST(PathGenTest, PathMetaSameSize) 90 { 91 ASSERT_EQ(sizeof(expectedPathMeta), sizeof(pathMeta)); 92 } 93 94 TEST(PathGenTest, GroupsSameSize) 95 { 96 ASSERT_EQ(sizeof(expectedGroups), sizeof(groups)); 97 } 98 99 TEST(PathGenTest, MetaSameContent) 100 { 101 size_t i; 102 for (i = 0; i < expectedMeta.size(); ++i) 103 { 104 ASSERT_EQ(meta[i], expectedMeta[i]); 105 } 106 } 107 108 TEST(PathGenTest, PathsSameContent) 109 { 110 size_t i; 111 for (i = 0; i < expectedPaths.size(); ++i) 112 { 113 ASSERT_EQ(paths[i], expectedPaths[i]); 114 } 115 } 116 117 TEST(PathGenTest, PathMetaSameContent) 118 { 119 size_t i; 120 for (i = 0; i < expectedPathMeta.size(); ++i) 121 { 122 const auto& path = std::get<0>(pathMeta[i]).get(); 123 const auto& expPath = std::get<0>(expectedPathMeta[i]).get(); 124 const auto& meta = std::get<1>(pathMeta[i]).get(); 125 const auto& expMeta = std::get<1>(expectedPathMeta[i]).get(); 126 127 ASSERT_EQ(path, expPath); 128 ASSERT_EQ(meta, expMeta); 129 } 130 } 131 132 TEST(PathGenTest, GroupsSameContent) 133 { 134 size_t i; 135 for (i = 0; i < expectedGroups.size(); ++i) 136 { 137 size_t j; 138 for (j = 0; j < groups[i].size(); ++j) 139 { 140 ASSERT_EQ(groups[i][j].get(), expectedGroups[i][j].get()); 141 142 } 143 } 144 } 145