mqueue_archive_test.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:54:57 CEST 2010 mqueue_archive_test.cpp
3 
4  mqueue_archive_test.cpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
9 
10  ***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "unit.hpp"
20 
21 #include <boost/version.hpp>
22 #include <boost/iostreams/stream.hpp>
23 #include <boost/iostreams/device/array.hpp>
24 #if BOOST_VERSION >= 106400
25 // The class name has been changed from boost::serialization::array<T> to array_wrapper<T> in Boost 1.61,
26 // but the header has only be renamed in Boost 1.64. Starting from Boost 1.65 array.hpp includes array_wrapper.hpp,
27 // but with 1.64 compilation fails if array_wrapper.hpp is not included.
28 # include <boost/serialization/array_wrapper.hpp>
29 #else
30 # include <boost/serialization/array.hpp>
31 #endif
32 #include <boost/serialization/vector.hpp>
33 #include <boost/archive/binary_iarchive.hpp>
34 
35 #include <rtt-fwd.hpp>
37 #include <os/fosi.h>
38 
39 using namespace std;
40 using namespace boost::archive;
41 using namespace RTT::detail;
42 using namespace RTT::mqueue;
43 namespace io = boost::iostreams;
44 
46 {
47 public:
50 };
51 
52 // Registers the fixture into the 'registry'
53 BOOST_FIXTURE_TEST_SUITE( MQueueArchiveTestSuite, MQueueArchiveTest )
54 
55 using namespace boost::serialization;
56 
57 // Test writing a data sample + a vector into a binary data archive
58 // this must be a complete real-time operation. Use valgrind to check
59 // allocs.
60 BOOST_AUTO_TEST_CASE( testBinaryDataArchive )
61 {
62  char sink[1000];
63  memset( sink, 0, 1000);
64  double d = 3.0;
65  vector<double> c(10, 9.99);
66 
68  io::stream<io::array_sink> outbuf(sink,1000);
69  binary_data_oarchive out( outbuf ); // +0 alloc
70  out << d; // +0 alloc
71  out << c; // +0 alloc
73 
74  unsigned int stored = out.getArchiveSize();
75  BOOST_CHECK( stored > 10*sizeof(double) );
76 
77 
78  d = 0.0;
79  c.clear();
80  c.resize(20,0.0);
81 
83  io::stream<io::array_source> inbuf(sink,1000);
84  binary_data_iarchive in( inbuf ); // +0 alloc
85  in >> d; // +0 alloc
86  in >> c; // +0 alloc
88 
89  BOOST_CHECK_CLOSE( d, 3.0, 0.01);
90  BOOST_CHECK_EQUAL( c.size(), 10);
91  for(int i=0; i != 10; ++i) {
92  BOOST_CHECK_CLOSE( c[i], 9.99, 0.01);
93  }
94  BOOST_CHECK_EQUAL( stored, in.getArchiveSize() );
95 }
96 
101 BOOST_AUTO_TEST_CASE( testFixedStringBinaryDataArchive )
102 {
103  char sink[1000];
104  memset( sink, 0, 1000);
105  char c[10] = "123456789";
106 
108  io::stream<io::array_sink> outbuf(sink,1000);
109  binary_data_oarchive out( outbuf ); // +0 alloc
110  out << make_array(c, 10); // +0 alloc
112 
113  unsigned int stored = out.getArchiveSize();
114  BOOST_CHECK( stored >= 10*sizeof(char) );
115 
117  io::stream<io::array_source> inbuf(sink,1000);
118  binary_data_iarchive in( inbuf ); // +0 alloc
119 #if BOOST_VERSION >= 106100
120  boost::serialization::array_wrapper<char> ma = boost::serialization::make_array(c, 10);
121 #else
122  boost::serialization::array<char> ma = boost::serialization::make_array(c, 10);
123 #endif
124  in >> ma; // +0 alloc
126 
127  BOOST_CHECK_EQUAL(c, "123456789");
128  BOOST_CHECK_EQUAL( stored, in.getArchiveSize() );
129 }
130 
134 BOOST_AUTO_TEST_CASE( testMakeArrayBinaryDataArchive )
135 {
136  char sink[1000];
137  memset( sink, 0, 1000);
138  double c[10] = {-1,1,2,3,4,5,6,7,8,9};
139  double r[10] = {0,0,0,0,0,0,0,0,0,0};
140 
142  io::stream<io::array_sink> outbuf(sink,1000);
143  binary_data_oarchive out( outbuf );
144  out & make_nvp("array", make_array(c, 10) );
146 
147  unsigned int stored = out.getArchiveSize();
148  BOOST_CHECK( stored >= 10*sizeof(double) );
149 
151  io::stream<io::array_source> inbuf(sink,1000);
152  binary_data_iarchive in( inbuf );
153  in & make_nvp("array", make_array(r, 10) );
155 
156  BOOST_CHECK_EQUAL(r[0], c[0]);
157  BOOST_CHECK_EQUAL(r[4], c[4]);
158  BOOST_CHECK_EQUAL(r[9], c[9]);
159  BOOST_CHECK_EQUAL( stored, in.getArchiveSize() );
160 }
161 
163 
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
BOOST_AUTO_TEST_CASE(testBinaryDataArchive)
#define BOOST_AUTO_TEST_SUITE_END()
Definition: mystd.hpp:163
void rtos_disable_rt_warning()
void rtos_enable_rt_warning()


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:33