ts_ByteOrderConversion.cpp
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
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   //std::cout << "ArrayBuilder read the values " << test_int << " , " << test_float << " , " << (int)test_uint << " , is currently at POS(r/w): "<<(int)ab.read_pos<<"/"<<(int)ab.write_pos<< " And contains the " << (int)ab.array.size() << " Byte long Byte array: " << ab << std::endl;
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   //std::cout << "ArrayBuilder reconstructed the values: "<< test_int_out << " , " << test_float_out << " , " << (int)test_uint_out << " , is currently at POS(r/w): "<<(int)ab.read_pos<<"/"<<(int)ab.write_pos<< " And contains the " << (int)ab.array.size() << " Byte long Byte array: " << ab << std::endl;
00053   //std::cout << "This value should contain 0: "<< test_to_mouch << std::endl;
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   // Test if the Vectors Work with the ArrayBuilder
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   //std::cout << "Put a vector with the uint8_t type and the data 1,2,3,4 into the array builder, RAW Data: "<< ab << std::endl;
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   //std::cout << "Added a vector with the uint16_t type and the data 5,6,7,8 into the array builder, RAW Data: "<< ab << std::endl;
00086 
00087   //Read out the arrays aggain
00088   ab >> test_uint8_vector_out;
00089   ab >> test_uint16_vector_out;
00090 
00091 
00092 //  std::cout << "Test_uint_16_vector was reconstructed with the elements: ";
00093 //  for (std::vector<u_int16_t>::const_iterator it = test_uint16_vector_out.begin() ; it != test_uint16_vector_out.end(); ++it)
00094 //  {
00095 //    std::cout << (int)*it << ", ";
00096 //  }
00097 //  std::cout << std::endl;
00098 
00099 //  std::cout << "Test_uint_8_vector was reconstructed with the elements: ";
00100 //  for (std::vector<u_int8_t>::const_iterator it = test_uint8_vector_out.begin() ; it != test_uint8_vector_out.end(); ++it)
00101 //  {
00102 //    std::cout << (int)*it << ", ";
00103 //  }
00104 //  std::cout << std::endl;
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   //std::cout << "Size: "<<(int)size << " Size_peek "<< size_peek << " size_out" << size_out << std::endl;
00124   BOOST_CHECK_EQUAL(size,size_out);
00125   BOOST_CHECK_EQUAL(size,size_peek);
00126 
00127   ab >> size_out;
00128 
00129   // This should return zero as the read pointer is empty.,However,readback should still function as the last element written is still there
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()


fzi_icl_comm
Author(s):
autogenerated on Thu Jun 6 2019 21:31:31