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