test_module_version.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * C++ unit test for dbw_mkz_can/ModuleVersion.h
3  *********************************************************************/
4 
5 #include <gtest/gtest.h>
6 
7 // File under test
9 using namespace dbw_mkz_can;
10 
11 // Test empty constructor
13 {
14  EXPECT_EQ(0, ModuleVersion().major());
15  EXPECT_EQ(0, ModuleVersion().minor());
16  EXPECT_EQ(0, ModuleVersion().build());
17  EXPECT_FALSE(ModuleVersion().valid());
18 }
19 
20 // Test validity
22 {
23  // Test zeros and ones
24  EXPECT_FALSE(ModuleVersion(0,0,0).valid());
25  EXPECT_TRUE (ModuleVersion(1,0,0).valid());
26  EXPECT_TRUE (ModuleVersion(0,1,0).valid());
27  EXPECT_TRUE (ModuleVersion(0,0,1).valid());
28 
29  // Test all valid values (non-zero)
30  for (size_t i = 1; i <= UINT16_MAX; i++) {
31  EXPECT_TRUE(ModuleVersion(i,0,0).valid()) << i;
32  EXPECT_TRUE(ModuleVersion(0,i,0).valid()) << i;
33  EXPECT_TRUE(ModuleVersion(0,0,i).valid()) << i;
34  EXPECT_TRUE(ModuleVersion(i,i,i).valid()) << i;
35  }
36 }
37 
38 // Test fields (major,minor,build)
40 {
41  EXPECT_EQ(1, ModuleVersion(1,2,3).major());
42  EXPECT_EQ(2, ModuleVersion(1,2,3).minor());
43  EXPECT_EQ(3, ModuleVersion(1,2,3).build());
44 }
45 
46 // Test operators
47 TEST(ModuleVersion, operators)
48 {
49  EXPECT_LT(ModuleVersion(1,0,0), ModuleVersion(2,3,4));
50  EXPECT_LT(ModuleVersion(1,9,9), ModuleVersion(2,3,4));
51  EXPECT_LE(ModuleVersion(1,9,9), ModuleVersion(2,3,4));
52  EXPECT_LE(ModuleVersion(2,3,4), ModuleVersion(2,3,4));
53  EXPECT_GT(ModuleVersion(2,3,4), ModuleVersion(1,0,0));
54  EXPECT_GT(ModuleVersion(2,3,4), ModuleVersion(1,9,9));
55  EXPECT_GE(ModuleVersion(2,3,4), ModuleVersion(1,9,9));
56  EXPECT_GE(ModuleVersion(2,3,4), ModuleVersion(2,3,4));
57  EXPECT_EQ(ModuleVersion(1,2,3), ModuleVersion(1,2,3));
58  EXPECT_NE(ModuleVersion(1,2,3), ModuleVersion(3,2,1));
59 }
60 
61 int main(int argc, char **argv)
62 {
63  testing::InitGoogleTest(&argc, argv);
64  return RUN_ALL_TESTS();
65 }
66 
int main(int argc, char **argv)
TEST(ModuleVersion, empty)


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