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