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