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