test_platform_map.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * C++ unit test for dbw_mkz_can/PlatformMap.h
3  *********************************************************************/
4 
5 #include <gtest/gtest.h>
6 
7 // File under test
9 using namespace dbw_mkz_can;
10 
11 // Test if x equals any of y
12 template <typename T> static bool EQ3(T x, T y0, T y1, T y2) {
13  if (x == y0) return true;
14  if (x == y1) return true;
15  if (x == y2) return true;
16  return false;
17 }
18 
19 // Test constructors
20 TEST(PlatformMap, constructor)
21 {
22  const Platform p = (Platform)1;
23  const Module m = (Module)2;
24 
25  // Empty
26  EXPECT_EQ(ModuleVersion(), PlatformMap().findModule(p,m));
27 
28  // Individual fields
29  EXPECT_EQ(ModuleVersion(1,2,3), PlatformMap(p,m,ModuleVersion(1,2,3)).findModule(p,m));
30 
31  // PlatformVersion class
32  EXPECT_EQ(ModuleVersion(1,2,3), PlatformMap(PlatformVersion(p,m, ModuleVersion(1,2,3))).findModule(p,m));
33 
34  // Vector of PlatformVersion
35 #if 0 // Fails to compile in ROS Indigo: "call of overloaded ‘PlatformMap(<brace-enclosed initializer list>)’ is ambiguous"
36  EXPECT_EQ(ModuleVersion(1,2,3), PlatformMap({PlatformVersion(p,m, ModuleVersion(1,2,3))}).findModule(p,m));
37 #endif
38 }
39 
40 // Test the findModule() method
41 TEST(PlatformMap, findModule)
42 {
43  const Platform px = (Platform)0; const Module mx = (Module)0;
44  const Platform py = (Platform)1; const Module my = (Module)1;
45  const Platform pz = (Platform)2; const Module mz = (Module)2;
46  const Platform pw = (Platform)3; const Module mw = (Module)3;
47 
48  // Construct PlatformMap with multiple platforms and modules
49  const PlatformMap x({
50  {PlatformVersion(px,mx,ModuleVersion(10,11,12))},
51  {PlatformVersion(px,my,ModuleVersion(20,21,22))},
52  {PlatformVersion(px,mz,ModuleVersion(30,31,32))},
53  {PlatformVersion(py,mx,ModuleVersion(40,41,42))},
54  {PlatformVersion(py,my,ModuleVersion(50,51,52))},
55  {PlatformVersion(py,mz,ModuleVersion(60,61,62))},
56  {PlatformVersion(pz,mx,ModuleVersion(70,71,72))},
57  {PlatformVersion(pz,my,ModuleVersion(80,81,82))},
58  {PlatformVersion(pz,mz,ModuleVersion(90,91,92))},
59  });
60 
61  // Find entries that don't exist
62  EXPECT_EQ(ModuleVersion(), x.findModule(px,mw));
63  EXPECT_EQ(ModuleVersion(), x.findModule(pw,mx));
64  EXPECT_EQ(ModuleVersion(), x.findModule(PlatformVersion(px,mw,0,0,0)));
65  EXPECT_EQ(ModuleVersion(), x.findModule(PlatformVersion(pw,mx,0,0,0)));
66  EXPECT_EQ(ModuleVersion(), x.findModule(mw));
67 
68  // Find each entry
69  EXPECT_EQ(ModuleVersion(10,11,12), x.findModule(px,mx));
70  EXPECT_EQ(ModuleVersion(20,21,22), x.findModule(px,my));
71  EXPECT_EQ(ModuleVersion(30,31,32), x.findModule(px,mz));
72  EXPECT_EQ(ModuleVersion(40,41,42), x.findModule(py,mx));
73  EXPECT_EQ(ModuleVersion(50,51,52), x.findModule(py,my));
74  EXPECT_EQ(ModuleVersion(60,61,62), x.findModule(py,mz));
75  EXPECT_EQ(ModuleVersion(70,71,72), x.findModule(pz,mx));
76  EXPECT_EQ(ModuleVersion(80,81,82), x.findModule(pz,my));
77  EXPECT_EQ(ModuleVersion(90,91,92), x.findModule(pz,mz));
78  EXPECT_EQ(ModuleVersion(10,11,12), x.findModule(PlatformVersion(px,mx,0,0,0)));
79  EXPECT_EQ(ModuleVersion(20,21,22), x.findModule(PlatformVersion(px,my,0,0,0)));
80  EXPECT_EQ(ModuleVersion(30,31,32), x.findModule(PlatformVersion(px,mz,0,0,0)));
81  EXPECT_EQ(ModuleVersion(40,41,42), x.findModule(PlatformVersion(py,mx,0,0,0)));
82  EXPECT_EQ(ModuleVersion(50,51,52), x.findModule(PlatformVersion(py,my,0,0,0)));
83  EXPECT_EQ(ModuleVersion(60,61,62), x.findModule(PlatformVersion(py,mz,0,0,0)));
84  EXPECT_EQ(ModuleVersion(70,71,72), x.findModule(PlatformVersion(pz,mx,0,0,0)));
85  EXPECT_EQ(ModuleVersion(80,81,82), x.findModule(PlatformVersion(pz,my,0,0,0)));
86  EXPECT_EQ(ModuleVersion(90,91,92), x.findModule(PlatformVersion(pz,mz,0,0,0)));
87 
88  // Find any module regardless of platform
89  EXPECT_TRUE(EQ3(x.findModule(mx), ModuleVersion(10,11,12), ModuleVersion(40,41,42), ModuleVersion(70,71,72)));
90  EXPECT_TRUE(EQ3(x.findModule(my), ModuleVersion(20,21,22), ModuleVersion(50,51,52), ModuleVersion(80,81,82)));
91  EXPECT_TRUE(EQ3(x.findModule(mz), ModuleVersion(30,31,32), ModuleVersion(60,61,62), ModuleVersion(90,91,92)));
92 }
93 
94 // Test the findPlatform() method
95 TEST(PlatformMap, findPlatform)
96 {
97  const Platform px = (Platform)0; const Module mx = (Module)0;
98  const Platform py = (Platform)1; const Module my = (Module)1;
99  const Platform pz = (Platform)2; const Module mz = (Module)2;
100  const Platform pw = (Platform)3; const Module mw = (Module)3;
101 
102  // Construct PlatformMap with multiple platforms and modules
103  const PlatformMap x({
104  {PlatformVersion(px,mx,ModuleVersion(10,11,12))},
105  {PlatformVersion(px,my,ModuleVersion(20,21,22))},
106  {PlatformVersion(px,mz,ModuleVersion(30,31,32))},
107  {PlatformVersion(py,mx,ModuleVersion(40,41,42))},
108  {PlatformVersion(py,my,ModuleVersion(50,51,52))},
109  {PlatformVersion(py,mz,ModuleVersion(60,61,62))},
110  {PlatformVersion(pz,mx,ModuleVersion(70,71,72))},
111  {PlatformVersion(pz,my,ModuleVersion(80,81,82))},
112  {PlatformVersion(pz,mz,ModuleVersion(90,91,92))},
113  });
114 
115  // Find entries that don't exist
116  EXPECT_EQ(PlatformVersion(), x.findPlatform(mw));
117  EXPECT_EQ(PlatformVersion(), x.findPlatform(PlatformVersion(pw,mw,0,0,0)));
118 
119  // Find each entry
120  EXPECT_TRUE(EQ3(x.findPlatform(mx), PlatformVersion(px,mx,ModuleVersion(10,11,12)), PlatformVersion(py,mx,ModuleVersion(40,41,42)), PlatformVersion(pz,mx,ModuleVersion(70,71,72))));
121  EXPECT_TRUE(EQ3(x.findPlatform(my), PlatformVersion(px,my,ModuleVersion(20,21,22)), PlatformVersion(py,my,ModuleVersion(50,51,52)), PlatformVersion(pz,my,ModuleVersion(80,81,82))));
122  EXPECT_TRUE(EQ3(x.findPlatform(mz), PlatformVersion(px,mz,ModuleVersion(30,31,32)), PlatformVersion(py,mz,ModuleVersion(60,61,62)), PlatformVersion(pz,mz,ModuleVersion(90,91,92))));
123 }
124 
125 // Test operators
126 TEST(PlatformMap, operators)
127 {
128  const Platform px = (Platform)0; const Module mx = (Module)0;
129  const Platform py = (Platform)1; const Module my = (Module)1;
130  const Platform pz = (Platform)2; const Module mz = (Module)2;
131  const Platform pw = (Platform)3; const Module mw = (Module)3;
132 
133  // Construct PlatformMap with multiple platforms and modules
134  const PlatformMap x({
135  {PlatformVersion(px,mx,ModuleVersion(10,11,12))},
136  {PlatformVersion(px,my,ModuleVersion(20,21,22))},
137  {PlatformVersion(px,mz,ModuleVersion(30,31,32))},
138  {PlatformVersion(py,mx,ModuleVersion(40,41,42))},
139  {PlatformVersion(py,my,ModuleVersion(50,51,52))},
140  {PlatformVersion(py,mz,ModuleVersion(60,61,62))},
141  {PlatformVersion(pz,mx,ModuleVersion(70,71,72))},
142  {PlatformVersion(pz,my,ModuleVersion(80,81,82))},
143  {PlatformVersion(pz,mz,ModuleVersion(90,91,92))},
144  });
145 
146  // Compare PlatformVersion with PlatformMap entries that don't exist
147  EXPECT_TRUE (PlatformVersion(pw,mw,0,0,0) == x);
148  EXPECT_FALSE(PlatformVersion(pw,mw,1,1,1) < x);
149  EXPECT_FALSE(PlatformVersion(pw,mw,1,1,1) <= x);
150  EXPECT_TRUE (PlatformVersion(pw,mw,1,1,1) > x);
151  EXPECT_TRUE (PlatformVersion(pw,mw,1,1,1) >= x);
152  EXPECT_FALSE(PlatformVersion(pw,mw,1,1,1) == x);
153  EXPECT_TRUE (PlatformVersion(pw,mw,1,1,1) != x);
154 
155  // Compare PlatformVersion with PlatformMap entries
156  EXPECT_TRUE (PlatformVersion(py,my,45,45,45) < x);
157  EXPECT_FALSE(PlatformVersion(py,my,55,55,55) < x);
158  EXPECT_TRUE (PlatformVersion(py,my,45,45,45) <= x);
159  EXPECT_TRUE (PlatformVersion(py,my,50,51,52) <= x);
160  EXPECT_FALSE(PlatformVersion(py,my,55,55,55) <= x);
161  EXPECT_FALSE(PlatformVersion(py,my,45,45,45) > x);
162  EXPECT_TRUE (PlatformVersion(py,my,55,55,55) > x);
163  EXPECT_FALSE(PlatformVersion(py,my,45,45,45) >= x);
164  EXPECT_TRUE (PlatformVersion(py,my,50,51,52) >= x);
165  EXPECT_TRUE (PlatformVersion(py,my,55,55,55) >= x);
166  EXPECT_TRUE (PlatformVersion(py,my,50,51,52) == x);
167  EXPECT_FALSE(PlatformVersion(py,my,50,50,50) == x);
168  EXPECT_TRUE (PlatformVersion(py,my,50,50,50) != x);
169  EXPECT_FALSE(PlatformVersion(py,my,50,51,52) != x);
170 }
171 
172 int main(int argc, char **argv)
173 {
174  testing::InitGoogleTest(&argc, argv);
175  return RUN_ALL_TESTS();
176 }
177 
int main(int argc, char **argv)
float x
Definition: sonar_lut.h:43
static bool EQ3(T x, T y0, T y1, T y2)
TEST(PlatformMap, constructor)


dbw_mkz_can
Author(s): Kevin Hallenbeck
autogenerated on Fri May 14 2021 02:47:08