1 #include "data_types.hpp"
2
3 #include <array>
4 #include <string>
5
6 #include <gtest/gtest.h>
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
14 const std::array<std::string, 3> expectedMeta = {
15 "PATH1"s,
16 "PATH3"s,
17 "PATH2"s,
18 };
19
20 const std::array<std::string, 6> expectedPaths = {
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
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 }};
45
46 const std::array<RefVector<const std::string>, 4> expectedGroups = {{
47 {
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 }};
72
TEST(PathGenTest,MetaSameSize)73 TEST(PathGenTest, MetaSameSize)
74 {
75 ASSERT_EQ(sizeof(expectedMeta), sizeof(meta));
76 }
77
TEST(PathGenTest,PathsSameSize)78 TEST(PathGenTest, PathsSameSize)
79 {
80 ASSERT_EQ(sizeof(expectedPaths), sizeof(paths));
81 }
82
TEST(PathGenTest,PathMetaSameSize)83 TEST(PathGenTest, PathMetaSameSize)
84 {
85 ASSERT_EQ(sizeof(expectedPathMeta), sizeof(pathMeta));
86 }
87
TEST(PathGenTest,GroupsSameSize)88 TEST(PathGenTest, GroupsSameSize)
89 {
90 ASSERT_EQ(sizeof(expectedGroups), sizeof(groups));
91 }
92
TEST(PathGenTest,MetaSameContent)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
TEST(PathGenTest,PathsSameContent)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
TEST(PathGenTest,PathMetaSameContent)111 TEST(PathGenTest, PathMetaSameContent)
112 {
113 size_t i;
114 for (i = 0; i < expectedPathMeta.size(); ++i)
115 {
116 const auto& oriPath = std::get<0>(pathMeta[i]).get();
117 const auto& expPath = std::get<0>(expectedPathMeta[i]).get();
118 const auto& oriMeta = std::get<1>(pathMeta[i]).get();
119 const auto& expMeta = std::get<1>(expectedPathMeta[i]).get();
120
121 ASSERT_EQ(oriPath, expPath);
122 ASSERT_EQ(oriMeta, expMeta);
123 }
124 }
125
TEST(PathGenTest,GroupsSameContent)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());
135 }
136 }
137 }
138