value_test.cpp
Go to the documentation of this file.
00001 #include "Value.hpp"
00002 #include <type_traits>
00003 #include "ByteVector.hpp"
00004 #include "gtest/gtest.h"
00005 
00006 namespace msp {
00007 
00008 // The fixture for testing class Foo.
00009 template <typename T> class valueTest : public ::testing::Test {
00010 protected:
00011     // You can remove any or all of the following functions if its body
00012     // is empty.
00013 
00014     valueTest() {
00015         // You can do set-up work for each test here.
00016     }
00017 
00018     virtual ~valueTest() {
00019         // You can do clean-up work that doesn't throw exceptions here.
00020     }
00021 
00022     // If the constructor and destructor are not enough for setting up
00023     // and cleaning up each test, you can define the following methods:
00024 
00025     virtual void SetUp() {
00026         // Code here will be called immediately after the constructor (right
00027         // before each test).
00028     }
00029 
00030     virtual void TearDown() {
00031         // Code here will be called immediately after each test (right
00032         // before the destructor).
00033     }
00034 
00035     // Objects declared here can be used by all tests in the test case for Foo.
00036 };
00037 
00038 typedef ::testing::Types<bool, uint8_t, uint16_t, uint32_t, int8_t, int16_t,
00039                          int32_t, float, double>
00040     numTypes;
00041 TYPED_TEST_CASE(valueTest, numTypes);
00042 
00043 // Tests that the Foo::Bar() method does Abc.
00044 TYPED_TEST(valueTest, Initialzation) {
00045     Value<TypeParam> v;
00046     EXPECT_EQ(TypeParam(0), v());
00047     EXPECT_FALSE(v.set());
00048 }
00049 
00050 TYPED_TEST(valueTest, AssignmentZero) {
00051     Value<TypeParam> v1, v2;
00052 
00053     TypeParam ref = 0;
00054     v1            = ref;
00055     EXPECT_EQ(ref, v1());
00056     EXPECT_TRUE(v1.set());
00057     v2 = v1;
00058     EXPECT_EQ(ref, v2());
00059     EXPECT_TRUE(v2.set());
00060 }
00061 
00062 TYPED_TEST(valueTest, AssignmentMax) {
00063     Value<TypeParam> v1, v2;
00064 
00065     TypeParam ref = std::numeric_limits<TypeParam>::max();
00066     ;
00067     v1 = ref;
00068     EXPECT_EQ(ref, v1());
00069     EXPECT_TRUE(v1.set());
00070     v2 = v1;
00071     EXPECT_EQ(ref, v2());
00072     EXPECT_TRUE(v2.set());
00073 }
00074 
00075 TYPED_TEST(valueTest, AssignmentMin) {
00076     Value<TypeParam> v1, v2;
00077 
00078     TypeParam ref = std::numeric_limits<TypeParam>::min();
00079     ;
00080     v1 = ref;
00081     EXPECT_EQ(ref, v1());
00082     EXPECT_TRUE(v1.set());
00083     v2 = v1;
00084     EXPECT_EQ(ref, v2());
00085     EXPECT_TRUE(v2.set());
00086 }
00087 
00088 TYPED_TEST(valueTest, AssignmentCast) {
00089     Value<TypeParam> v;
00090     EXPECT_FALSE(v.set());
00091 
00092     const TypeParam ref1 = std::numeric_limits<TypeParam>::max();
00093 
00094     v = ref1;
00095     EXPECT_TRUE(v.set());
00096 
00097     EXPECT_EQ(ref1, v());
00098 
00099     const TypeParam ref2 = v;
00100     EXPECT_EQ(ref1, ref2);
00101 }
00102 
00103 TEST(valueTest, stringInit) {
00104     Value<std::string> v;
00105     EXPECT_EQ("", v());
00106     EXPECT_EQ(false, v.set());
00107 }
00108 
00109 TEST(valueTest, stringAssign) {
00110     Value<std::string> v1, v2;
00111     v1 = std::string("test");
00112     EXPECT_EQ("test", v1());
00113     EXPECT_EQ(true, v1.set());
00114     v2 = v1;
00115     EXPECT_EQ("test", v2());
00116     EXPECT_EQ(true, v2.set());
00117 }
00118 
00119 TEST(valueTest, ByteVecInit) {
00120     Value<ByteVector> v;
00121     EXPECT_EQ(true, v().empty());
00122     EXPECT_EQ(false, v.set());
00123 }
00124 
00125 TEST(valueTest, ByteVecAssign) {
00126     Value<ByteVector> v1, v2;
00127     v1 = ByteVector(1, 1);
00128     EXPECT_EQ(1, v1()[0]);
00129     EXPECT_EQ(true, v1.set());
00130     v2 = v1;
00131     EXPECT_EQ(1, v2()[0]);
00132     EXPECT_EQ(true, v2.set());
00133 }
00134 
00135 }  // namespace msp
00136 
00137 int main(int argc, char **argv) {
00138     ::testing::InitGoogleTest(&argc, argv);
00139     return RUN_ALL_TESTS();
00140 }


msp
Author(s): Christian Rauch
autogenerated on Thu Jun 20 2019 19:40:38