Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00022
00023 #include <icl_comm/ByteOrderConversion.h>
00024
00025 #include <boost/test/unit_test.hpp>
00026
00027 using icl_comm::ArrayBuilder;
00028
00029 BOOST_AUTO_TEST_SUITE(ts_ByteOrderConversion)
00030
00031
00032
00033 BOOST_AUTO_TEST_CASE(ConvertTest)
00034 {
00035 float test_float = 15.08;
00036 int test_int = 1508;
00037 u_int8_t test_uint = 128;
00038 u_int16_t test_uint2 = 128;
00039 ArrayBuilder ab;
00040 ab << test_int << test_float << test_uint <<test_uint2;
00041
00042
00043
00044 float test_float_out = 0.0;
00045 int test_int_out = 0;
00046 u_int8_t test_uint_out = 0;
00047 u_int16_t test_uint2_out = 2;
00048 int test_to_mouch = 0;
00049
00050 ab >> test_int_out >> test_float_out >> test_uint_out >>test_uint2_out >> test_to_mouch;
00051
00052
00053
00054
00055 BOOST_CHECK_EQUAL(test_float,test_float_out);
00056 BOOST_CHECK_EQUAL(test_int,test_int_out);
00057 BOOST_CHECK_EQUAL(test_uint,test_uint_out);
00058 BOOST_CHECK_EQUAL(test_uint2,test_uint2_out);
00059 BOOST_CHECK_EQUAL(test_to_mouch,0);
00060 }
00061
00062 BOOST_AUTO_TEST_CASE(ConvertVectorsTest)
00063 {
00064 ArrayBuilder ab;
00065 std::vector<u_int8_t> test_uint8_vector;
00066 std::vector<u_int16_t> test_uint16_vector;
00067 std::vector<u_int8_t> test_uint8_vector_out(4,0);
00068 std::vector<u_int16_t> test_uint16_vector_out(4,0);
00069
00070
00071 test_uint8_vector.push_back(1);
00072 test_uint8_vector.push_back(2);
00073 test_uint8_vector.push_back(3);
00074 test_uint8_vector.push_back(4);
00075 ab << test_uint8_vector ;
00076
00077
00078
00079 test_uint16_vector.push_back(5);
00080 test_uint16_vector.push_back(6);
00081 test_uint16_vector.push_back(7);
00082 test_uint16_vector.push_back(8);
00083 ab << test_uint16_vector ;
00084
00085
00086
00087
00088 ab >> test_uint8_vector_out;
00089 ab >> test_uint16_vector_out;
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 BOOST_CHECK_EQUAL_COLLECTIONS(test_uint8_vector.begin(),test_uint8_vector.end(),test_uint8_vector_out.begin(),test_uint8_vector_out.end());
00108 BOOST_CHECK_EQUAL_COLLECTIONS(test_uint16_vector.begin(),test_uint16_vector.end(),test_uint16_vector_out.begin(),test_uint16_vector_out.end());
00109 }
00110
00111 BOOST_AUTO_TEST_CASE(ReadBackTest)
00112 {
00113 ArrayBuilder ab;
00114
00115 u_int32_t size = 12;
00116 u_int32_t size_peek = 0;
00117 u_int32_t size_out = 0;
00118
00119 ab << size;
00120 size_peek = ab.readBack<u_int32_t>();
00121 ab >> size_out;
00122
00123
00124 BOOST_CHECK_EQUAL(size,size_out);
00125 BOOST_CHECK_EQUAL(size,size_peek);
00126
00127 ab >> size_out;
00128
00129
00130 BOOST_CHECK_EQUAL(size_out,0);
00131 size_peek = ab.readBack<u_int32_t>();
00132 BOOST_CHECK_EQUAL(size,size_peek);
00133 }
00134
00135
00136
00137 BOOST_AUTO_TEST_SUITE_END()