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