value_test.cpp
Go to the documentation of this file.
1 #include "Value.hpp"
2 #include <type_traits>
3 #include "ByteVector.hpp"
4 #include "gtest/gtest.h"
5 
6 namespace msp {
7 
8 // The fixture for testing class Foo.
9 template <typename T> class valueTest : public ::testing::Test {
10 protected:
11  // You can remove any or all of the following functions if its body
12  // is empty.
13 
15  // You can do set-up work for each test here.
16  }
17 
18  virtual ~valueTest() {
19  // You can do clean-up work that doesn't throw exceptions here.
20  }
21 
22  // If the constructor and destructor are not enough for setting up
23  // and cleaning up each test, you can define the following methods:
24 
25  virtual void SetUp() {
26  // Code here will be called immediately after the constructor (right
27  // before each test).
28  }
29 
30  virtual void TearDown() {
31  // Code here will be called immediately after each test (right
32  // before the destructor).
33  }
34 
35  // Objects declared here can be used by all tests in the test case for Foo.
36 };
37 
38 typedef ::testing::Types<bool, uint8_t, uint16_t, uint32_t, int8_t, int16_t,
39  int32_t, float, double>
42 
43 // Tests that the Foo::Bar() method does Abc.
44 TYPED_TEST(valueTest, Initialzation) {
46  EXPECT_EQ(TypeParam(0), v());
47  EXPECT_FALSE(v.set());
48 }
49 
50 TYPED_TEST(valueTest, AssignmentZero) {
51  Value<TypeParam> v1, v2;
52 
53  TypeParam ref = 0;
54  v1 = ref;
55  EXPECT_EQ(ref, v1());
56  EXPECT_TRUE(v1.set());
57  v2 = v1;
58  EXPECT_EQ(ref, v2());
59  EXPECT_TRUE(v2.set());
60 }
61 
62 TYPED_TEST(valueTest, AssignmentMax) {
63  Value<TypeParam> v1, v2;
64 
65  TypeParam ref = std::numeric_limits<TypeParam>::max();
66  ;
67  v1 = ref;
68  EXPECT_EQ(ref, v1());
69  EXPECT_TRUE(v1.set());
70  v2 = v1;
71  EXPECT_EQ(ref, v2());
72  EXPECT_TRUE(v2.set());
73 }
74 
75 TYPED_TEST(valueTest, AssignmentMin) {
76  Value<TypeParam> v1, v2;
77 
78  TypeParam ref = std::numeric_limits<TypeParam>::min();
79  ;
80  v1 = ref;
81  EXPECT_EQ(ref, v1());
82  EXPECT_TRUE(v1.set());
83  v2 = v1;
84  EXPECT_EQ(ref, v2());
85  EXPECT_TRUE(v2.set());
86 }
87 
88 TYPED_TEST(valueTest, AssignmentCast) {
90  EXPECT_FALSE(v.set());
91 
92  const TypeParam ref1 = std::numeric_limits<TypeParam>::max();
93 
94  v = ref1;
95  EXPECT_TRUE(v.set());
96 
97  EXPECT_EQ(ref1, v());
98 
99  const TypeParam ref2 = v;
100  EXPECT_EQ(ref1, ref2);
101 }
102 
103 TEST(valueTest, stringInit) {
105  EXPECT_EQ("", v());
106  EXPECT_EQ(false, v.set());
107 }
108 
109 TEST(valueTest, stringAssign) {
110  Value<std::string> v1, v2;
111  v1 = std::string("test");
112  EXPECT_EQ("test", v1());
113  EXPECT_EQ(true, v1.set());
114  v2 = v1;
115  EXPECT_EQ("test", v2());
116  EXPECT_EQ(true, v2.set());
117 }
118 
119 TEST(valueTest, ByteVecInit) {
121  EXPECT_EQ(true, v().empty());
122  EXPECT_EQ(false, v.set());
123 }
124 
125 TEST(valueTest, ByteVecAssign) {
126  Value<ByteVector> v1, v2;
127  v1 = ByteVector(1, 1);
128  EXPECT_EQ(1, v1()[0]);
129  EXPECT_EQ(true, v1.set());
130  v2 = v1;
131  EXPECT_EQ(1, v2()[0]);
132  EXPECT_EQ(true, v2.set());
133 }
134 
135 } // namespace msp
136 
137 int main(int argc, char **argv) {
138  ::testing::InitGoogleTest(&argc, argv);
139  return RUN_ALL_TESTS();
140 }
virtual void SetUp()
Definition: value_test.cpp:25
TYPED_TEST_CASE(ByteVectorBasicTest, basicTypes)
TEST(ByteVectorBasicTest, Initialzation)
virtual void TearDown()
Definition: value_test.cpp:30
::testing::Types< bool, uint8_t, uint16_t, uint32_t, int8_t, int16_t, int32_t, float, double > numTypes
Definition: value_test.cpp:40
TYPED_TEST(ByteVectorBasicTest, Pack1zero)
int main(int argc, char **argv)
Definition: value_test.cpp:137
bool set() const
Queries if the data has been set.
Definition: Value.hpp:53
virtual ~valueTest()
Definition: value_test.cpp:18


msp
Author(s): Christian Rauch
autogenerated on Tue Oct 6 2020 03:39:02