mqueue_archive_test.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: The SourceWorks  Tue Sep 7 00:54:57 CEST 2010  mqueue_archive_test.cpp
00003 
00004                         mqueue_archive_test.cpp -  description
00005                            -------------------
00006     begin                : Tue September 07 2010
00007     copyright            : (C) 2010 The SourceWorks
00008     email                : peter@thesourceworks.com
00009 
00010  ***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #include "unit.hpp"
00020 
00021 #include <boost/iostreams/stream.hpp>
00022 #include <boost/iostreams/device/array.hpp>
00023 #include <boost/serialization/vector.hpp>
00024 #include <boost/archive/binary_iarchive.hpp>
00025 
00026 #include <rtt-fwd.hpp>
00027 #include <transports/mqueue/binary_data_archive.hpp>
00028 #include <os/fosi.h>
00029 
00030 using namespace std;
00031 using namespace boost::archive;
00032 using namespace RTT::detail;
00033 using namespace RTT::mqueue;
00034 namespace io = boost::iostreams;
00035 
00036 class MQueueArchiveTest
00037 {
00038 public:
00039     MQueueArchiveTest() { }
00040     ~MQueueArchiveTest() { }
00041 };
00042 
00043 // Registers the fixture into the 'registry'
00044 BOOST_FIXTURE_TEST_SUITE(  MQueueArchiveTestSuite,  MQueueArchiveTest )
00045 
00046 using namespace boost::serialization;
00047 
00048 // Test writing a data sample + a vector into a binary data archive
00049 // this must be a complete real-time operation. Use valgrind to check
00050 // allocs.
00051 BOOST_AUTO_TEST_CASE( testBinaryDataArchive )
00052 {
00053     char sink[1000];
00054     memset( sink, 0, 1000);
00055     double d = 3.0;
00056     vector<double> c(10, 9.99);
00057 
00058     rtos_enable_rt_warning();
00059     io::stream<io::array_sink>  outbuf(sink,1000);
00060     binary_data_oarchive out( outbuf ); // +0 alloc
00061     out << d; // +0 alloc
00062     out << c; // +0 alloc
00063     rtos_disable_rt_warning();
00064 
00065     unsigned int stored = out.getArchiveSize();
00066     BOOST_CHECK( stored > 10*sizeof(double) );
00067 
00068 
00069     d = 0.0;
00070     c.clear();
00071     c.resize(20,0.0);
00072 
00073     rtos_enable_rt_warning();
00074     io::stream<io::array_source>  inbuf(sink,1000);
00075     binary_data_iarchive in( inbuf ); // +0 alloc
00076     in >> d; // +0 alloc
00077     in >> c; // +0 alloc
00078     rtos_disable_rt_warning();
00079 
00080     BOOST_CHECK_CLOSE( d, 3.0, 0.01);
00081     BOOST_CHECK_EQUAL( c.size(), 10);
00082     for(int i=0; i != 10; ++i) {
00083         BOOST_CHECK_CLOSE( c[i], 9.99, 0.01);
00084     }
00085     BOOST_CHECK_EQUAL( stored, in.getArchiveSize() );
00086 }
00087 
00092 BOOST_AUTO_TEST_CASE( testFixedStringBinaryDataArchive )
00093 {
00094     char sink[1000];
00095     memset( sink, 0, 1000);
00096     char c[10] = "123456789";
00097 
00098     rtos_enable_rt_warning();
00099     io::stream<io::array_sink>  outbuf(sink,1000);
00100     binary_data_oarchive out( outbuf ); // +0 alloc
00101     out << make_array(c, 10); // +0 alloc
00102     rtos_disable_rt_warning();
00103 
00104     unsigned int stored = out.getArchiveSize();
00105     BOOST_CHECK( stored >= 10*sizeof(char) );
00106 
00107     rtos_enable_rt_warning();
00108     io::stream<io::array_source>  inbuf(sink,1000);
00109     binary_data_iarchive in( inbuf ); // +0 alloc
00110     boost::serialization::array<char> ma = boost::serialization::make_array(c, 10);
00111     in >> ma; // +0 alloc
00112     rtos_disable_rt_warning();
00113 
00114     BOOST_CHECK_EQUAL(c, "123456789");
00115     BOOST_CHECK_EQUAL( stored, in.getArchiveSize() );
00116 }
00117 
00121 BOOST_AUTO_TEST_CASE( testMakeArrayBinaryDataArchive )
00122 {
00123     char sink[1000];
00124     memset( sink, 0, 1000);
00125     double c[10] = {-1,1,2,3,4,5,6,7,8,9};
00126     double r[10] = {0,0,0,0,0,0,0,0,0,0};
00127 
00128     rtos_enable_rt_warning();
00129     io::stream<io::array_sink>  outbuf(sink,1000);
00130     binary_data_oarchive out( outbuf );
00131     out & make_nvp("array", make_array(c, 10) );
00132     rtos_disable_rt_warning();
00133 
00134     unsigned int stored = out.getArchiveSize();
00135     BOOST_CHECK( stored >= 10*sizeof(double) );
00136 
00137     rtos_enable_rt_warning();
00138     io::stream<io::array_source>  inbuf(sink,1000);
00139     binary_data_iarchive in( inbuf );
00140     in & make_nvp("array", make_array(r, 10) );
00141     rtos_disable_rt_warning();
00142 
00143     BOOST_CHECK_EQUAL(r[0], c[0]);
00144     BOOST_CHECK_EQUAL(r[4], c[4]);
00145     BOOST_CHECK_EQUAL(r[9], c[9]);
00146     BOOST_CHECK_EQUAL( stored, in.getArchiveSize() );
00147 }
00148 
00149 BOOST_AUTO_TEST_SUITE_END()
00150 


rtt
Author(s): RTT Developers
autogenerated on Wed Aug 26 2015 16:15:49