DataMangler_Test.cpp
Go to the documentation of this file.
00001 #include <iostream>
00002 #include <gtest/gtest.h>
00003 #include <boost/shared_ptr.hpp>
00004 #include "robot_instance/RobonetDataElement.h"
00005 
00006 using namespace std;
00007 using namespace boost;
00008 
00009 TEST(DataMangler, CombineRawValues)
00010 {
00011     EXPECT_EQ(0, DataMangler::combineRawValues(pair<uint16_t, uint16_t>(0, 0)));
00012 
00013     // Edge cases for first
00014     EXPECT_EQ(1,     DataMangler::combineRawValues(pair<uint16_t, uint16_t>(1, 0)));
00015     EXPECT_EQ(65535, DataMangler::combineRawValues(pair<uint16_t, uint16_t>(65535, 0)));
00016     EXPECT_EQ(0,     DataMangler::combineRawValues(pair<uint16_t, uint16_t>((uint16_t)65536, 0)));
00017 
00018     // Edge cases for second
00019     EXPECT_EQ(65536,      DataMangler::combineRawValues(pair<uint16_t, uint16_t>(0, 1)));
00020     EXPECT_EQ(4294901760, DataMangler::combineRawValues(pair<uint16_t, uint16_t>(0, 65535)));
00021     EXPECT_EQ(0,          DataMangler::combineRawValues(pair<uint16_t, uint16_t>(0, (uint16_t)65536)));
00022 
00023     // Edge cases for both
00024     EXPECT_EQ(65537,      DataMangler::combineRawValues(pair<uint16_t, uint16_t>(1, 1)));
00025     EXPECT_EQ(131071,     DataMangler::combineRawValues(pair<uint16_t, uint16_t>(65535, 1)));
00026     EXPECT_EQ(65536,      DataMangler::combineRawValues(pair<uint16_t, uint16_t>((uint16_t)65536, 1)));
00027     EXPECT_EQ(4294901761, DataMangler::combineRawValues(pair<uint16_t, uint16_t>(1, 65535)));
00028     EXPECT_EQ(1,          DataMangler::combineRawValues(pair<uint16_t, uint16_t>(1, (uint16_t)65536)));
00029     EXPECT_EQ(4294967295, DataMangler::combineRawValues(pair<uint16_t, uint16_t>(65535, 65535)));
00030     EXPECT_EQ(4294901760, DataMangler::combineRawValues(pair<uint16_t, uint16_t>((uint16_t)65536, 65535)));
00031     EXPECT_EQ(65535,      DataMangler::combineRawValues(pair<uint16_t, uint16_t>(65535, (uint16_t)65536)));
00032     EXPECT_EQ(0,          DataMangler::combineRawValues(pair<uint16_t, uint16_t>((uint16_t)65536, (uint16_t)65536)));
00033 }
00034 
00035 TEST(DataMangler, SeparateRawValues)
00036 {
00037     EXPECT_EQ(0, DataMangler::separateRawValues(0).first);
00038     EXPECT_EQ(0, DataMangler::separateRawValues(0).second);
00039 
00040     EXPECT_EQ(1,     DataMangler::separateRawValues(1).first);
00041     EXPECT_EQ(0,     DataMangler::separateRawValues(1).second);
00042     EXPECT_EQ(65535, DataMangler::separateRawValues(65535).first);
00043     EXPECT_EQ(0,     DataMangler::separateRawValues(65535).second);
00044     EXPECT_EQ(0,     DataMangler::separateRawValues(65536).first);
00045     EXPECT_EQ(1,     DataMangler::separateRawValues(65536).second);
00046     EXPECT_EQ(0,     DataMangler::separateRawValues(4294901760).first);
00047     EXPECT_EQ(65535, DataMangler::separateRawValues(4294901760).second);
00048     EXPECT_EQ(65535, DataMangler::separateRawValues(4294967295).first);
00049     EXPECT_EQ(65535, DataMangler::separateRawValues(4294967295).second);
00050     EXPECT_EQ(0,     DataMangler::separateRawValues((uint32_t)4294967296).first);
00051     EXPECT_EQ(0,     DataMangler::separateRawValues((uint32_t)4294967296).second);
00052 }
00053 
00054 TEST(DataMangler, FromUnsignedIntTo)
00055 {
00056     uint32_t value;
00057 
00058     value = 0;
00059     EXPECT_EQ(0, DataMangler::fromUnsignedIntTo<unsigned int>(value));
00060     EXPECT_EQ(0, DataMangler::fromUnsignedIntTo<int>(value));
00061     EXPECT_FALSE(DataMangler::fromUnsignedIntTo<bool>(value));
00062     EXPECT_FLOAT_EQ(0, DataMangler::fromUnsignedIntTo<float>(value));
00063 
00064     value = 0x0000FFFF;
00065     EXPECT_EQ(65535, DataMangler::fromUnsignedIntTo<unsigned int>(value));
00066     EXPECT_EQ(65535, DataMangler::fromUnsignedIntTo<int>(value));
00067     EXPECT_TRUE(DataMangler::fromUnsignedIntTo<bool>(value));
00068     EXPECT_FLOAT_EQ(9.1834E-41, DataMangler::fromUnsignedIntTo<float>(value));
00069 
00070     value = 0xABCD0000;
00071     EXPECT_EQ(2882338816,  DataMangler::fromUnsignedIntTo<unsigned int>(value));
00072     EXPECT_EQ(-1412628480, DataMangler::fromUnsignedIntTo<int>(value));
00073     EXPECT_TRUE(DataMangler::fromUnsignedIntTo<bool>(value));
00074     EXPECT_FLOAT_EQ(-1.4566126E-12, DataMangler::fromUnsignedIntTo<float>(value));
00075 
00076     value = 0xFFFFFFFF;
00077     EXPECT_EQ(4294967295, DataMangler::fromUnsignedIntTo<unsigned int>(value));
00078     EXPECT_EQ(-1,         DataMangler::fromUnsignedIntTo<int>(value));
00079     EXPECT_TRUE(DataMangler::fromUnsignedIntTo<bool>(value));
00080     // float(FFFFFFFF) is NaN
00081 
00082     value = 0xABCD1234;
00083     EXPECT_EQ(2882343476,  DataMangler::fromUnsignedIntTo<unsigned int>(value));
00084     EXPECT_EQ(-1412623820, DataMangler::fromUnsignedIntTo<int>(value));
00085     EXPECT_TRUE(DataMangler::fromUnsignedIntTo<bool>(value));
00086     EXPECT_FLOAT_EQ(-1.4571178E-12, DataMangler::fromUnsignedIntTo<float>(value));
00087 }
00088 
00089 TEST(DataMangler, ToUnsignedIntFrom)
00090 {
00091     EXPECT_EQ(0,          DataMangler::toUnsignedIntFrom<unsigned int>(0));
00092     EXPECT_EQ(65535,      DataMangler::toUnsignedIntFrom<unsigned int>(65535));
00093     EXPECT_EQ(4294967295, DataMangler::toUnsignedIntFrom<unsigned int>(-1));
00094 
00095     EXPECT_EQ(0,          DataMangler::toUnsignedIntFrom<int>(0));
00096     EXPECT_EQ(65535,      DataMangler::toUnsignedIntFrom<int>(65535));
00097     EXPECT_EQ(4294967295, DataMangler::toUnsignedIntFrom<int>(-1));
00098 
00099     EXPECT_EQ(0, (DataMangler::toUnsignedIntFrom<bool>(0) & BitMinion::EIGHT_BIT_MASK));
00100     EXPECT_EQ(0, (DataMangler::toUnsignedIntFrom<bool>(false) & BitMinion::EIGHT_BIT_MASK));
00101     EXPECT_EQ(1, (DataMangler::toUnsignedIntFrom<bool>(1) & BitMinion::EIGHT_BIT_MASK));
00102     EXPECT_EQ(1, (DataMangler::toUnsignedIntFrom<bool>(true) & BitMinion::EIGHT_BIT_MASK));
00103     EXPECT_EQ(1, (DataMangler::toUnsignedIntFrom<bool>(-1) & BitMinion::EIGHT_BIT_MASK));
00104 
00105     EXPECT_EQ(0,          DataMangler::toUnsignedIntFrom<float>(0));
00106     EXPECT_EQ(2882343476, DataMangler::toUnsignedIntFrom<float>(-1.4571178E-12));
00107 }
00108 
00109 int main(int argc, char** argv)
00110 {
00111     testing::InitGoogleTest(&argc, argv);
00112     return RUN_ALL_TESTS();
00113 }


robot_instance
Author(s):
autogenerated on Sat Jun 8 2019 20:43:12