marshalling_test.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:54:57 CEST 2010 marshalling_test.cpp
3 
4  marshalling_test.cpp - demarshription
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 "operations_fixture.hpp"
22 #include <marsh/Marshalling.hpp>
24 #include "plugin/PluginLoader.hpp"
25 #include "datasource_fixture.hpp"
26 
27 using namespace std;
28 using namespace boost;
29 using namespace RTT;
30 using namespace RTT::detail;
31 
32 #include <boost/shared_ptr.hpp>
33 
35 {
36  boost::shared_ptr<Marshalling> marsh;
38  PluginLoader::shared_ptr pl = PluginLoader::Instance();
39  pl->loadTypekit("testtypes",".;..");
40  marsh = tc->getProvider<Marshalling>("marshalling");
41  }
42 };
43 
44 // Registers the fixture into the 'registry'
45 BOOST_FIXTURE_TEST_SUITE( MarshallingTestSuite, MarshallingFixture )
46 
47 // Tests getProvider for marshalling service
48 BOOST_AUTO_TEST_CASE(TestGetProvider)
49 {
50  //MarshallingService* sa = new MarshallingService( tc ); // done by TC or plugin
51 
52  boost::shared_ptr<Marshalling> marsh2 = tc->getProvider<Marshalling>("marshalling");
53  BOOST_REQUIRE( marsh );
54  BOOST_REQUIRE( marsh2 );
55  BOOST_CHECK( marsh->ready() );
56  BOOST_CHECK( marsh2->ready() );
57 }
58 
59 // Tests marshalling a matrix type (sequence of sequence)
60 BOOST_AUTO_TEST_CASE(TestMarshallMatrix)
61 {
62  typedef std::vector<std::vector<double> > MatrixType;
63  typedef std::vector<double> RowType;
64  MatrixType mx( 5, RowType(5,5.0)); // matrix 5x5 with values '5.0'
65  MatrixType mxz( 5, RowType(5,0.0)); // matrix 5x5 with values '0.0'
66  MatrixType mxrz; // real empty matrix
67 
68  // check initial values:
69  BOOST_CHECK_EQUAL( mx[0][0], 5.0);
70  BOOST_CHECK_EQUAL( mx[4][4], 5.0);
71  BOOST_CHECK_EQUAL( mx[0][2], 5.0);
72  BOOST_CHECK_EQUAL( mx[2][0], 5.0);
73  BOOST_CHECK_EQUAL( mx[3][3], 5.0);
74 
75  tc->addProperty("mx", mx);
76  // write a non-existing file:
77  BOOST_CHECK( marsh->writeProperties("TestMarshallMatrix.cpf") );
78  // zero out our copy:
79  mx = mxrz;
80  BOOST_REQUIRE( marsh->readProperties("TestMarshallMatrix.cpf") );
81  BOOST_REQUIRE_EQUAL( mx.size(), 5);
82  BOOST_REQUIRE_EQUAL( mx[0].size(), 5);
83  // check restored result:
84  BOOST_CHECK_EQUAL( mx[0][0], 5.0);
85  BOOST_CHECK_EQUAL( mx[4][4], 5.0);
86  BOOST_CHECK_EQUAL( mx[0][2], 5.0);
87  BOOST_CHECK_EQUAL( mx[2][0], 5.0);
88  BOOST_CHECK_EQUAL( mx[3][3], 5.0);
89 
90  // write it again to an existing file:
91  BOOST_CHECK( marsh->writeProperties("TestMarshallMatrix.cpf") );
92  // zero out our copy:
93  mx = mxz;
94  BOOST_REQUIRE( marsh->readProperties("TestMarshallMatrix.cpf") );
95  // check restored result:
96  BOOST_CHECK_EQUAL( mx[0][0], 5.0);
97  BOOST_CHECK_EQUAL( mx[4][4], 5.0);
98  BOOST_CHECK_EQUAL( mx[0][2], 5.0);
99  BOOST_CHECK_EQUAL( mx[2][0], 5.0);
100  BOOST_CHECK_EQUAL( mx[3][3], 5.0);
101 }
102 
103 // Tests marshalling a struct type
104 BOOST_AUTO_TEST_CASE(TestMarshallStructAType)
105 {
106  // filled in type and zero type:
107  AType at, atref;
108  at.init(); atref.init();
109  AType atz; atz.clear();
110 
111  tc->addProperty("at", at);
112  // write a non-existing file:
113  BOOST_CHECK( marsh->storeProperties("TestMarshallAType.cpf") );
114  // zero out our copy:
115  at = atz;
116  BOOST_REQUIRE( marsh->readProperties("TestMarshallAType.cpf") );
117  // check restored result:
118  BOOST_CHECK_EQUAL( at, atref);
119 
120  // write it again to an existing file:
121  BOOST_CHECK( marsh->writeProperties("TestMarshallAType.cpf") );
122  // zero out our copy:
123  at = atz;
124  BOOST_REQUIRE( marsh->readProperties("TestMarshallAType.cpf") );
125  // check restored result:
126  BOOST_CHECK_EQUAL( at, atref);
127 }
128 
129 // Tests marshalling a struct type
130 BOOST_AUTO_TEST_CASE(TestMarshallStructBType)
131 {
132  // filled in type and zero type:
133  BType at, atref;
134  at.init(); atref.init();
135  BType atz; atz.clear();
136 
137  tc->addProperty("at", at);
138  // write a non-existing file:
139  BOOST_CHECK( marsh->storeProperties("TestMarshallBType.cpf") );
140  // zero out our copy:
141  at = atz;
142  BOOST_REQUIRE( marsh->readProperties("TestMarshallBType.cpf") );
143  // check restored result:
144  BOOST_CHECK_EQUAL( at, atref);
145 
146  // write it again to an existing file:
147  BOOST_CHECK( marsh->writeProperties("TestMarshallBType.cpf") );
148  // zero out our copy:
149  at = atz;
150  BOOST_REQUIRE( marsh->readProperties("TestMarshallBType.cpf") );
151  // check restored result:
152  BOOST_CHECK_EQUAL( at, atref);
153 }
154 
155 // Tests marshalling a struct type
156 BOOST_AUTO_TEST_CASE(TestMarshallStructCType)
157 {
158  // filled in type and zero type:
159  CType at, atref;
160  at.init(); atref.init();
161  CType atz; atz.clear();
162 
163  tc->addProperty("at", at);
164  // write a non-existing file:
165  BOOST_CHECK( marsh->storeProperties("TestMarshallCType.cpf") );
166  // zero out our copy:
167  at = atz;
168  BOOST_REQUIRE( marsh->readProperties("TestMarshallCType.cpf") );
169  // check restored result:
170  BOOST_CHECK_EQUAL( at, atref);
171 
172  // write it again to an existing file:
173  BOOST_CHECK( marsh->writeProperties("TestMarshallCType.cpf") );
174  // zero out our copy:
175  at = atz;
176  BOOST_REQUIRE( marsh->readProperties("TestMarshallCType.cpf") );
177  // check restored result:
178  BOOST_CHECK_EQUAL( at, atref);
179 }
180 
181 // Tests marshalling a struct type
182 BOOST_AUTO_TEST_CASE(TestMarshallStructATypes)
183 {
184  // filled in type and zero type:
185  AType init; init.init();
186  ATypes at, atref;
187  at.resize(5, init); atref.resize(5, init);
188  ATypes atz;
189 
190  tc->addProperty("at", at);
191  // write a non-existing file:
192  BOOST_CHECK( marsh->storeProperties("TestMarshallATypes.cpf") );
193  // zero out our copy:
194  at = atz;
195  BOOST_REQUIRE( marsh->readProperties("TestMarshallATypes.cpf") );
196  // check restored result:
197  BOOST_CHECK_EQUAL( at, atref);
198 
199  // write it again to an existing file:
200  BOOST_CHECK( marsh->writeProperties("TestMarshallATypes.cpf") );
201  // zero out our copy:
202  at = atz;
203  BOOST_REQUIRE( marsh->readProperties("TestMarshallATypes.cpf") );
204  // check restored result:
205  BOOST_CHECK_EQUAL( at, atref);
206 }
207 
208 // Tests marshalling a struct type
209 BOOST_AUTO_TEST_CASE(TestMarshallStructBTypes)
210 {
211  // filled in type and zero type:
212  BType init; init.init();
213  BTypes at, atref;
214  at.resize(5,init); atref.resize(5,init);
215  BTypes atz; atz.clear();
216 
217  tc->addProperty("at", at);
218  // write a non-existing file:
219  BOOST_CHECK( marsh->storeProperties("TestMarshallBTypes.cpf") );
220  // zero out our copy:
221  at = atz;
222  BOOST_REQUIRE( marsh->readProperties("TestMarshallBTypes.cpf") );
223  // check restored result:
224  BOOST_CHECK_EQUAL( at, atref);
225 
226  // write it again to an existing file:
227  BOOST_CHECK( marsh->writeProperties("TestMarshallBTypes.cpf") );
228  // zero out our copy:
229  at = atz;
230  BOOST_REQUIRE( marsh->readProperties("TestMarshallBTypes.cpf") );
231  // check restored result:
232  BOOST_CHECK_EQUAL( at, atref);
233 }
234 
235 // Tests marshalling a struct type
236 BOOST_AUTO_TEST_CASE(TestMarshallStructCTypes)
237 {
238  // filled in type and zero type:
239  CType init; init.init();
240  CTypes at, atref;
241  at.resize(5,init); atref.resize(5,init);
242  CTypes atz; atz.clear();
243 
244  tc->addProperty("at", at);
245  // write a non-existing file:
246  BOOST_CHECK( marsh->storeProperties("TestMarshallCTypes.cpf") );
247  // zero out our copy:
248  at = atz;
249  BOOST_REQUIRE( marsh->readProperties("TestMarshallCTypes.cpf") );
250  // check restored result:
251  BOOST_CHECK_EQUAL( at, atref);
252 
253  // write it again to an existing file:
254  BOOST_CHECK( marsh->writeProperties("TestMarshallCTypes.cpf") );
255  // zero out our copy:
256  at = atz;
257  BOOST_REQUIRE( marsh->readProperties("TestMarshallCTypes.cpf") );
258  // check restored result:
259  BOOST_CHECK_EQUAL( at, atref);
260 }
261 
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
#define BOOST_AUTO_TEST_SUITE_END()
Definition: mystd.hpp:163
BOOST_AUTO_TEST_CASE(TestGetProvider)
std::vector< BType > BTypes
std::vector< AType > ATypes
boost::shared_ptr< Marshalling > marsh
std::vector< CType > CTypes
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
boost::shared_ptr< PluginLoader > shared_ptr


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