1*b604480aSBrad Bishop #include <array>
2*b604480aSBrad Bishop #include <string>
3*b604480aSBrad Bishop #include <gtest/gtest.h>
4*b604480aSBrad Bishop #include "data_types.hpp"
5*b604480aSBrad Bishop 
6*b604480aSBrad Bishop using namespace std::string_literals;
7*b604480aSBrad Bishop using namespace phosphor::dbus::monitoring;
8*b604480aSBrad Bishop using PathMeta = TupleOfRefs<const std::string, const std::string>;
9*b604480aSBrad Bishop 
10*b604480aSBrad Bishop #include "pathgentest.hpp"
11*b604480aSBrad Bishop 
12*b604480aSBrad Bishop const std::array<std::string, 3> expectedMeta =
13*b604480aSBrad Bishop {
14*b604480aSBrad Bishop     "path1"s,
15*b604480aSBrad Bishop     "path3"s,
16*b604480aSBrad Bishop     "path2"s,
17*b604480aSBrad Bishop };
18*b604480aSBrad Bishop 
19*b604480aSBrad Bishop const std::array<std::string, 6> expectedPaths =
20*b604480aSBrad Bishop {
21*b604480aSBrad Bishop     "/xyz/openbmc_project/testing/inst1"s,
22*b604480aSBrad Bishop     "/xyz/openbmc_project/testing/inst2"s,
23*b604480aSBrad Bishop     "/xyz/openbmc_project/testing/inst3"s,
24*b604480aSBrad Bishop     "/xyz/openbmc_project/testing/inst4"s,
25*b604480aSBrad Bishop     "/xyz/openbmc_project/testing/inst5"s,
26*b604480aSBrad Bishop     "/xyz/openbmc_project/testing/inst6"s,
27*b604480aSBrad Bishop };
28*b604480aSBrad Bishop 
29*b604480aSBrad Bishop const std::array<PathMeta, 14> expectedPathMeta =
30*b604480aSBrad Bishop {
31*b604480aSBrad Bishop     {
32*b604480aSBrad Bishop         PathMeta{ paths[0], meta[0] },
33*b604480aSBrad Bishop         PathMeta{ paths[1], meta[0] },
34*b604480aSBrad Bishop         PathMeta{ paths[2], meta[0] },
35*b604480aSBrad Bishop         PathMeta{ paths[3], meta[0] },
36*b604480aSBrad Bishop         PathMeta{ paths[0], meta[1] },
37*b604480aSBrad Bishop         PathMeta{ paths[1], meta[1] },
38*b604480aSBrad Bishop         PathMeta{ paths[2], meta[1] },
39*b604480aSBrad Bishop         PathMeta{ paths[3], meta[1] },
40*b604480aSBrad Bishop         PathMeta{ paths[4], meta[0] },
41*b604480aSBrad Bishop         PathMeta{ paths[5], meta[0] },
42*b604480aSBrad Bishop         PathMeta{ paths[3], meta[2] },
43*b604480aSBrad Bishop         PathMeta{ paths[2], meta[2] },
44*b604480aSBrad Bishop         PathMeta{ paths[1], meta[2] },
45*b604480aSBrad Bishop         PathMeta{ paths[0], meta[2] },
46*b604480aSBrad Bishop     }
47*b604480aSBrad Bishop };
48*b604480aSBrad Bishop 
49*b604480aSBrad Bishop const std::array<RefVector<const std::string>, 4> expectedGroups =
50*b604480aSBrad Bishop {
51*b604480aSBrad Bishop     {
52*b604480aSBrad Bishop         {
53*b604480aSBrad Bishop             paths[0],
54*b604480aSBrad Bishop             paths[1],
55*b604480aSBrad Bishop             paths[2],
56*b604480aSBrad Bishop             paths[3],
57*b604480aSBrad Bishop         },
58*b604480aSBrad Bishop         {
59*b604480aSBrad Bishop             paths[0],
60*b604480aSBrad Bishop             paths[1],
61*b604480aSBrad Bishop             paths[2],
62*b604480aSBrad Bishop             paths[3],
63*b604480aSBrad Bishop         },
64*b604480aSBrad Bishop         {
65*b604480aSBrad Bishop             paths[0],
66*b604480aSBrad Bishop             paths[1],
67*b604480aSBrad Bishop             paths[4],
68*b604480aSBrad Bishop             paths[5],
69*b604480aSBrad Bishop         },
70*b604480aSBrad Bishop         {
71*b604480aSBrad Bishop             paths[3],
72*b604480aSBrad Bishop             paths[2],
73*b604480aSBrad Bishop             paths[1],
74*b604480aSBrad Bishop             paths[0],
75*b604480aSBrad Bishop         },
76*b604480aSBrad Bishop     }
77*b604480aSBrad Bishop };
78*b604480aSBrad Bishop 
79*b604480aSBrad Bishop TEST(PathGenTest, MetaSameSize)
80*b604480aSBrad Bishop {
81*b604480aSBrad Bishop     ASSERT_EQ(sizeof(expectedMeta), sizeof(meta));
82*b604480aSBrad Bishop }
83*b604480aSBrad Bishop 
84*b604480aSBrad Bishop TEST(PathGenTest, PathsSameSize)
85*b604480aSBrad Bishop {
86*b604480aSBrad Bishop     ASSERT_EQ(sizeof(expectedPaths), sizeof(paths));
87*b604480aSBrad Bishop }
88*b604480aSBrad Bishop 
89*b604480aSBrad Bishop TEST(PathGenTest, PathMetaSameSize)
90*b604480aSBrad Bishop {
91*b604480aSBrad Bishop     ASSERT_EQ(sizeof(expectedPathMeta), sizeof(pathMeta));
92*b604480aSBrad Bishop }
93*b604480aSBrad Bishop 
94*b604480aSBrad Bishop TEST(PathGenTest, GroupsSameSize)
95*b604480aSBrad Bishop {
96*b604480aSBrad Bishop     ASSERT_EQ(sizeof(expectedGroups), sizeof(groups));
97*b604480aSBrad Bishop }
98*b604480aSBrad Bishop 
99*b604480aSBrad Bishop TEST(PathGenTest, MetaSameContent)
100*b604480aSBrad Bishop {
101*b604480aSBrad Bishop     size_t i;
102*b604480aSBrad Bishop     for (i = 0; i < expectedMeta.size(); ++i)
103*b604480aSBrad Bishop     {
104*b604480aSBrad Bishop         ASSERT_EQ(meta[i], expectedMeta[i]);
105*b604480aSBrad Bishop     }
106*b604480aSBrad Bishop }
107*b604480aSBrad Bishop 
108*b604480aSBrad Bishop TEST(PathGenTest, PathsSameContent)
109*b604480aSBrad Bishop {
110*b604480aSBrad Bishop     size_t i;
111*b604480aSBrad Bishop     for (i = 0; i < expectedPaths.size(); ++i)
112*b604480aSBrad Bishop     {
113*b604480aSBrad Bishop         ASSERT_EQ(paths[i], expectedPaths[i]);
114*b604480aSBrad Bishop     }
115*b604480aSBrad Bishop }
116*b604480aSBrad Bishop 
117*b604480aSBrad Bishop TEST(PathGenTest, PathMetaSameContent)
118*b604480aSBrad Bishop {
119*b604480aSBrad Bishop     size_t i;
120*b604480aSBrad Bishop     for (i = 0; i < expectedPathMeta.size(); ++i)
121*b604480aSBrad Bishop     {
122*b604480aSBrad Bishop         const auto& path = std::get<0>(pathMeta[i]).get();
123*b604480aSBrad Bishop         const auto& expPath = std::get<0>(expectedPathMeta[i]).get();
124*b604480aSBrad Bishop         const auto& meta = std::get<1>(pathMeta[i]).get();
125*b604480aSBrad Bishop         const auto& expMeta = std::get<1>(expectedPathMeta[i]).get();
126*b604480aSBrad Bishop 
127*b604480aSBrad Bishop         ASSERT_EQ(path, expPath);
128*b604480aSBrad Bishop         ASSERT_EQ(meta, expMeta);
129*b604480aSBrad Bishop     }
130*b604480aSBrad Bishop }
131*b604480aSBrad Bishop 
132*b604480aSBrad Bishop TEST(PathGenTest, GroupsSameContent)
133*b604480aSBrad Bishop {
134*b604480aSBrad Bishop     size_t i;
135*b604480aSBrad Bishop     for (i = 0; i < expectedGroups.size(); ++i)
136*b604480aSBrad Bishop     {
137*b604480aSBrad Bishop         size_t j;
138*b604480aSBrad Bishop         for (j = 0; j < groups[i].size(); ++j)
139*b604480aSBrad Bishop         {
140*b604480aSBrad Bishop             ASSERT_EQ(groups[i][j].get(), expectedGroups[i][j].get());
141*b604480aSBrad Bishop 
142*b604480aSBrad Bishop         }
143*b604480aSBrad Bishop     }
144*b604480aSBrad Bishop }
145