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