00001
00002
00003
00004
00005 #include <gtest/gtest.h>
00006
00007
00008 #include <dbw_fca_can/PlatformMap.h>
00009 using namespace dbw_fca_can;
00010
00011
00012 template <typename T> static bool EQ3(T x, T y0, T y1, T y2) {
00013 if (x == y0) return true;
00014 if (x == y1) return true;
00015 if (x == y2) return true;
00016 return false;
00017 }
00018
00019
00020 TEST(PlatformMap, constructor)
00021 {
00022 const Platform p = (Platform)1;
00023 const Module m = (Module)2;
00024
00025
00026 EXPECT_EQ(ModuleVersion(), PlatformMap().findModule(p,m));
00027
00028
00029 EXPECT_EQ(ModuleVersion(1,2,3), PlatformMap(p,m,ModuleVersion(1,2,3)).findModule(p,m));
00030
00031
00032 EXPECT_EQ(ModuleVersion(1,2,3), PlatformMap(PlatformVersion(p,m, ModuleVersion(1,2,3))).findModule(p,m));
00033
00034
00035 #if 0 // Fails to compile in ROS Indigo: "call of overloaded ‘PlatformMap(<brace-enclosed initializer list>)’ is ambiguous"
00036 EXPECT_EQ(ModuleVersion(1,2,3), PlatformMap({PlatformVersion(p,m, ModuleVersion(1,2,3))}).findModule(p,m));
00037 #endif
00038 }
00039
00040
00041 TEST(PlatformMap, findModule)
00042 {
00043 const Platform px = (Platform)0; const Module mx = (Module)0;
00044 const Platform py = (Platform)1; const Module my = (Module)1;
00045 const Platform pz = (Platform)2; const Module mz = (Module)2;
00046 const Platform pw = (Platform)3; const Module mw = (Module)3;
00047
00048
00049 const PlatformMap x({
00050 {PlatformVersion(px,mx,ModuleVersion(10,11,12))},
00051 {PlatformVersion(px,my,ModuleVersion(20,21,22))},
00052 {PlatformVersion(px,mz,ModuleVersion(30,31,32))},
00053 {PlatformVersion(py,mx,ModuleVersion(40,41,42))},
00054 {PlatformVersion(py,my,ModuleVersion(50,51,52))},
00055 {PlatformVersion(py,mz,ModuleVersion(60,61,62))},
00056 {PlatformVersion(pz,mx,ModuleVersion(70,71,72))},
00057 {PlatformVersion(pz,my,ModuleVersion(80,81,82))},
00058 {PlatformVersion(pz,mz,ModuleVersion(90,91,92))},
00059 });
00060
00061
00062 EXPECT_EQ(ModuleVersion(), x.findModule(px,mw));
00063 EXPECT_EQ(ModuleVersion(), x.findModule(pw,mx));
00064 EXPECT_EQ(ModuleVersion(), x.findModule(PlatformVersion(px,mw,0,0,0)));
00065 EXPECT_EQ(ModuleVersion(), x.findModule(PlatformVersion(pw,mx,0,0,0)));
00066 EXPECT_EQ(ModuleVersion(), x.findModule(mw));
00067
00068
00069 EXPECT_EQ(ModuleVersion(10,11,12), x.findModule(px,mx));
00070 EXPECT_EQ(ModuleVersion(20,21,22), x.findModule(px,my));
00071 EXPECT_EQ(ModuleVersion(30,31,32), x.findModule(px,mz));
00072 EXPECT_EQ(ModuleVersion(40,41,42), x.findModule(py,mx));
00073 EXPECT_EQ(ModuleVersion(50,51,52), x.findModule(py,my));
00074 EXPECT_EQ(ModuleVersion(60,61,62), x.findModule(py,mz));
00075 EXPECT_EQ(ModuleVersion(70,71,72), x.findModule(pz,mx));
00076 EXPECT_EQ(ModuleVersion(80,81,82), x.findModule(pz,my));
00077 EXPECT_EQ(ModuleVersion(90,91,92), x.findModule(pz,mz));
00078 EXPECT_EQ(ModuleVersion(10,11,12), x.findModule(PlatformVersion(px,mx,0,0,0)));
00079 EXPECT_EQ(ModuleVersion(20,21,22), x.findModule(PlatformVersion(px,my,0,0,0)));
00080 EXPECT_EQ(ModuleVersion(30,31,32), x.findModule(PlatformVersion(px,mz,0,0,0)));
00081 EXPECT_EQ(ModuleVersion(40,41,42), x.findModule(PlatformVersion(py,mx,0,0,0)));
00082 EXPECT_EQ(ModuleVersion(50,51,52), x.findModule(PlatformVersion(py,my,0,0,0)));
00083 EXPECT_EQ(ModuleVersion(60,61,62), x.findModule(PlatformVersion(py,mz,0,0,0)));
00084 EXPECT_EQ(ModuleVersion(70,71,72), x.findModule(PlatformVersion(pz,mx,0,0,0)));
00085 EXPECT_EQ(ModuleVersion(80,81,82), x.findModule(PlatformVersion(pz,my,0,0,0)));
00086 EXPECT_EQ(ModuleVersion(90,91,92), x.findModule(PlatformVersion(pz,mz,0,0,0)));
00087
00088
00089 EXPECT_TRUE(EQ3(x.findModule(mx), ModuleVersion(10,11,12), ModuleVersion(40,41,42), ModuleVersion(70,71,72)));
00090 EXPECT_TRUE(EQ3(x.findModule(my), ModuleVersion(20,21,22), ModuleVersion(50,51,52), ModuleVersion(80,81,82)));
00091 EXPECT_TRUE(EQ3(x.findModule(mz), ModuleVersion(30,31,32), ModuleVersion(60,61,62), ModuleVersion(90,91,92)));
00092 }
00093
00094
00095 TEST(PlatformMap, findPlatform)
00096 {
00097 const Platform px = (Platform)0; const Module mx = (Module)0;
00098 const Platform py = (Platform)1; const Module my = (Module)1;
00099 const Platform pz = (Platform)2; const Module mz = (Module)2;
00100 const Platform pw = (Platform)3; const Module mw = (Module)3;
00101
00102
00103 const PlatformMap x({
00104 {PlatformVersion(px,mx,ModuleVersion(10,11,12))},
00105 {PlatformVersion(px,my,ModuleVersion(20,21,22))},
00106 {PlatformVersion(px,mz,ModuleVersion(30,31,32))},
00107 {PlatformVersion(py,mx,ModuleVersion(40,41,42))},
00108 {PlatformVersion(py,my,ModuleVersion(50,51,52))},
00109 {PlatformVersion(py,mz,ModuleVersion(60,61,62))},
00110 {PlatformVersion(pz,mx,ModuleVersion(70,71,72))},
00111 {PlatformVersion(pz,my,ModuleVersion(80,81,82))},
00112 {PlatformVersion(pz,mz,ModuleVersion(90,91,92))},
00113 });
00114
00115
00116 EXPECT_EQ(PlatformVersion(), x.findPlatform(mw));
00117 EXPECT_EQ(PlatformVersion(), x.findPlatform(PlatformVersion(pw,mw,0,0,0)));
00118
00119
00120 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))));
00121 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))));
00122 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))));
00123 }
00124
00125
00126 TEST(PlatformMap, operators)
00127 {
00128 const Platform px = (Platform)0; const Module mx = (Module)0;
00129 const Platform py = (Platform)1; const Module my = (Module)1;
00130 const Platform pz = (Platform)2; const Module mz = (Module)2;
00131 const Platform pw = (Platform)3; const Module mw = (Module)3;
00132
00133
00134 const PlatformMap x({
00135 {PlatformVersion(px,mx,ModuleVersion(10,11,12))},
00136 {PlatformVersion(px,my,ModuleVersion(20,21,22))},
00137 {PlatformVersion(px,mz,ModuleVersion(30,31,32))},
00138 {PlatformVersion(py,mx,ModuleVersion(40,41,42))},
00139 {PlatformVersion(py,my,ModuleVersion(50,51,52))},
00140 {PlatformVersion(py,mz,ModuleVersion(60,61,62))},
00141 {PlatformVersion(pz,mx,ModuleVersion(70,71,72))},
00142 {PlatformVersion(pz,my,ModuleVersion(80,81,82))},
00143 {PlatformVersion(pz,mz,ModuleVersion(90,91,92))},
00144 });
00145
00146
00147 EXPECT_TRUE (PlatformVersion(pw,mw,0,0,0) == x);
00148 EXPECT_FALSE(PlatformVersion(pw,mw,1,1,1) < x);
00149 EXPECT_FALSE(PlatformVersion(pw,mw,1,1,1) <= x);
00150 EXPECT_TRUE (PlatformVersion(pw,mw,1,1,1) > x);
00151 EXPECT_TRUE (PlatformVersion(pw,mw,1,1,1) >= x);
00152 EXPECT_FALSE(PlatformVersion(pw,mw,1,1,1) == x);
00153 EXPECT_TRUE (PlatformVersion(pw,mw,1,1,1) != x);
00154
00155
00156 EXPECT_TRUE (PlatformVersion(py,my,45,45,45) < x);
00157 EXPECT_FALSE(PlatformVersion(py,my,55,55,55) < x);
00158 EXPECT_TRUE (PlatformVersion(py,my,45,45,45) <= x);
00159 EXPECT_TRUE (PlatformVersion(py,my,50,51,52) <= x);
00160 EXPECT_FALSE(PlatformVersion(py,my,55,55,55) <= x);
00161 EXPECT_FALSE(PlatformVersion(py,my,45,45,45) > x);
00162 EXPECT_TRUE (PlatformVersion(py,my,55,55,55) > x);
00163 EXPECT_FALSE(PlatformVersion(py,my,45,45,45) >= x);
00164 EXPECT_TRUE (PlatformVersion(py,my,50,51,52) >= x);
00165 EXPECT_TRUE (PlatformVersion(py,my,55,55,55) >= x);
00166 EXPECT_TRUE (PlatformVersion(py,my,50,51,52) == x);
00167 EXPECT_FALSE(PlatformVersion(py,my,50,50,50) == x);
00168 EXPECT_TRUE (PlatformVersion(py,my,50,50,50) != x);
00169 EXPECT_FALSE(PlatformVersion(py,my,50,51,52) != x);
00170 }
00171
00172 int main(int argc, char **argv)
00173 {
00174 testing::InitGoogleTest(&argc, argv);
00175 return RUN_ALL_TESTS();
00176 }
00177