blob: 9e0e073b53b62f61c0696e0de9cacabe5d669658 [file] [log] [blame]
Patrick Venture3d6d3182018-08-31 09:33:09 -07001#include "data_types.hpp"
2
Brad Bishopb6044802017-05-07 23:14:57 -04003#include <array>
4#include <string>
Patrick Venture3d6d3182018-08-31 09:33:09 -07005
Brad Bishopb6044802017-05-07 23:14:57 -04006#include <gtest/gtest.h>
Brad Bishopb6044802017-05-07 23:14:57 -04007
8using namespace std::string_literals;
9using namespace phosphor::dbus::monitoring;
10using PathMeta = TupleOfRefs<const std::string, const std::string>;
11
12#include "pathgentest.hpp"
13
Brad Bishopd1eac882018-03-29 10:34:05 -040014const std::array<std::string, 3> expectedMeta = {
Brad Bishopbabf3b72017-05-31 19:44:53 -040015 "PATH1"s,
16 "PATH3"s,
17 "PATH2"s,
Brad Bishopb6044802017-05-07 23:14:57 -040018};
19
Brad Bishopd1eac882018-03-29 10:34:05 -040020const std::array<std::string, 6> expectedPaths = {
Brad Bishopb6044802017-05-07 23:14:57 -040021 "/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 Bishopd1eac882018-03-29 10:34:05 -040029const 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 Bishopb6044802017-05-07 23:14:57 -040045
Brad Bishopd1eac882018-03-29 10:34:05 -040046const std::array<RefVector<const std::string>, 4> expectedGroups = {{
Brad Bishopb6044802017-05-07 23:14:57 -040047 {
Brad Bishopd1eac882018-03-29 10:34:05 -040048 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 Bishopb6044802017-05-07 23:14:57 -040072
73TEST(PathGenTest, MetaSameSize)
74{
75 ASSERT_EQ(sizeof(expectedMeta), sizeof(meta));
76}
77
78TEST(PathGenTest, PathsSameSize)
79{
80 ASSERT_EQ(sizeof(expectedPaths), sizeof(paths));
81}
82
83TEST(PathGenTest, PathMetaSameSize)
84{
85 ASSERT_EQ(sizeof(expectedPathMeta), sizeof(pathMeta));
86}
87
88TEST(PathGenTest, GroupsSameSize)
89{
90 ASSERT_EQ(sizeof(expectedGroups), sizeof(groups));
91}
92
93TEST(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
102TEST(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
111TEST(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
126TEST(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 Bishopb6044802017-05-07 23:14:57 -0400135 }
136 }
137}