marshalling_test.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: The SourceWorks  Tue Sep 7 00:54:57 CEST 2010  marshalling_test.cpp
00003 
00004                         marshalling_test.cpp -  demarshription
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 "operations_fixture.hpp"
00022 #include <marsh/Marshalling.hpp>
00023 #include <marsh/MarshallingService.hpp>
00024 #include "plugin/PluginLoader.hpp"
00025 #include "datasource_fixture.hpp"
00026 
00027 using namespace std;
00028 using namespace boost;
00029 using namespace RTT;
00030 using namespace RTT::detail;
00031 
00032 #include <boost/shared_ptr.hpp>
00033 
00034 struct MarshallingFixture : public OperationsFixture
00035 {
00036     boost::shared_ptr<Marshalling> marsh;
00037     MarshallingFixture() {
00038         PluginLoader::shared_ptr pl = PluginLoader::Instance();
00039         pl->loadTypekit("testtypes",".;..");
00040         marsh = tc->getProvider<Marshalling>("marshalling");
00041     }
00042 };
00043 
00044 // Registers the fixture into the 'registry'
00045 BOOST_FIXTURE_TEST_SUITE(  MarshallingTestSuite,  MarshallingFixture )
00046 
00047 // Tests getProvider for marshalling service
00048 BOOST_AUTO_TEST_CASE(TestGetProvider)
00049 {
00050     //MarshallingService* sa = new MarshallingService( tc ); // done by TC or plugin
00051 
00052     boost::shared_ptr<Marshalling> marsh2 = tc->getProvider<Marshalling>("marshalling");
00053     BOOST_REQUIRE( marsh );
00054     BOOST_REQUIRE( marsh2 );
00055     BOOST_CHECK( marsh->ready() );
00056     BOOST_CHECK( marsh2->ready() );
00057 }
00058 
00059 // Tests marshalling a matrix type (sequence of sequence)
00060 BOOST_AUTO_TEST_CASE(TestMarshallMatrix)
00061 {
00062     typedef std::vector<std::vector<double> > MatrixType;
00063     typedef std::vector<double> RowType;
00064     MatrixType mx( 5, RowType(5,5.0)); // matrix 5x5 with values '5.0'
00065     MatrixType mxz( 5, RowType(5,0.0)); // matrix 5x5 with values '0.0'
00066     MatrixType mxrz; // real empty matrix
00067 
00068     // check initial values:
00069     BOOST_CHECK_EQUAL( mx[0][0], 5.0);
00070     BOOST_CHECK_EQUAL( mx[4][4], 5.0);
00071     BOOST_CHECK_EQUAL( mx[0][2], 5.0);
00072     BOOST_CHECK_EQUAL( mx[2][0], 5.0);
00073     BOOST_CHECK_EQUAL( mx[3][3], 5.0);
00074 
00075     tc->addProperty("mx", mx);
00076     // write a non-existing file:
00077     BOOST_CHECK( marsh->writeProperties("TestMarshallMatrix.cpf") );
00078     // zero out our copy:
00079     mx = mxrz;
00080     BOOST_REQUIRE( marsh->readProperties("TestMarshallMatrix.cpf") );
00081     BOOST_REQUIRE_EQUAL( mx.size(), 5);
00082     BOOST_REQUIRE_EQUAL( mx[0].size(), 5);
00083     // check restored result:
00084     BOOST_CHECK_EQUAL( mx[0][0], 5.0);
00085     BOOST_CHECK_EQUAL( mx[4][4], 5.0);
00086     BOOST_CHECK_EQUAL( mx[0][2], 5.0);
00087     BOOST_CHECK_EQUAL( mx[2][0], 5.0);
00088     BOOST_CHECK_EQUAL( mx[3][3], 5.0);
00089 
00090     // write it again to an existing file:
00091     BOOST_CHECK( marsh->writeProperties("TestMarshallMatrix.cpf") );
00092     // zero out our copy:
00093     mx = mxz;
00094     BOOST_REQUIRE( marsh->readProperties("TestMarshallMatrix.cpf") );
00095     // check restored result:
00096     BOOST_CHECK_EQUAL( mx[0][0], 5.0);
00097     BOOST_CHECK_EQUAL( mx[4][4], 5.0);
00098     BOOST_CHECK_EQUAL( mx[0][2], 5.0);
00099     BOOST_CHECK_EQUAL( mx[2][0], 5.0);
00100     BOOST_CHECK_EQUAL( mx[3][3], 5.0);
00101 }
00102 
00103 // Tests marshalling a struct type
00104 BOOST_AUTO_TEST_CASE(TestMarshallStructAType)
00105 {
00106     // filled in type and zero type:
00107     AType at, atref;
00108     at.init(); atref.init();
00109     AType atz; atz.clear();
00110 
00111     tc->addProperty("at", at);
00112     // write a non-existing file:
00113     BOOST_CHECK( marsh->storeProperties("TestMarshallAType.cpf") );
00114     // zero out our copy:
00115     at = atz;
00116     BOOST_REQUIRE( marsh->readProperties("TestMarshallAType.cpf") );
00117     // check restored result:
00118     BOOST_CHECK_EQUAL( at, atref);
00119 
00120     // write it again to an existing file:
00121     BOOST_CHECK( marsh->writeProperties("TestMarshallAType.cpf") );
00122     // zero out our copy:
00123     at = atz;
00124     BOOST_REQUIRE( marsh->readProperties("TestMarshallAType.cpf") );
00125     // check restored result:
00126     BOOST_CHECK_EQUAL( at, atref);
00127 }
00128 
00129 // Tests marshalling a struct type
00130 BOOST_AUTO_TEST_CASE(TestMarshallStructBType)
00131 {
00132     // filled in type and zero type:
00133     BType at, atref;
00134     at.init(); atref.init();
00135     BType atz; atz.clear();
00136 
00137     tc->addProperty("at", at);
00138     // write a non-existing file:
00139     BOOST_CHECK( marsh->storeProperties("TestMarshallBType.cpf") );
00140     // zero out our copy:
00141     at = atz;
00142     BOOST_REQUIRE( marsh->readProperties("TestMarshallBType.cpf") );
00143     // check restored result:
00144     BOOST_CHECK_EQUAL( at, atref);
00145 
00146     // write it again to an existing file:
00147     BOOST_CHECK( marsh->writeProperties("TestMarshallBType.cpf") );
00148     // zero out our copy:
00149     at = atz;
00150     BOOST_REQUIRE( marsh->readProperties("TestMarshallBType.cpf") );
00151     // check restored result:
00152     BOOST_CHECK_EQUAL( at, atref);
00153 }
00154 
00155 // Tests marshalling a struct type
00156 BOOST_AUTO_TEST_CASE(TestMarshallStructCType)
00157 {
00158     // filled in type and zero type:
00159     CType at, atref;
00160     at.init(); atref.init();
00161     CType atz; atz.clear();
00162 
00163     tc->addProperty("at", at);
00164     // write a non-existing file:
00165     BOOST_CHECK( marsh->storeProperties("TestMarshallCType.cpf") );
00166     // zero out our copy:
00167     at = atz;
00168     BOOST_REQUIRE( marsh->readProperties("TestMarshallCType.cpf") );
00169     // check restored result:
00170     BOOST_CHECK_EQUAL( at, atref);
00171 
00172     // write it again to an existing file:
00173     BOOST_CHECK( marsh->writeProperties("TestMarshallCType.cpf") );
00174     // zero out our copy:
00175     at = atz;
00176     BOOST_REQUIRE( marsh->readProperties("TestMarshallCType.cpf") );
00177     // check restored result:
00178     BOOST_CHECK_EQUAL( at, atref);
00179 }
00180 
00181 // Tests marshalling a struct type
00182 BOOST_AUTO_TEST_CASE(TestMarshallStructATypes)
00183 {
00184     // filled in type and zero type:
00185     AType init; init.init();
00186     ATypes at, atref;
00187     at.resize(5, init); atref.resize(5, init);
00188     ATypes atz;
00189 
00190     tc->addProperty("at", at);
00191     // write a non-existing file:
00192     BOOST_CHECK( marsh->storeProperties("TestMarshallATypes.cpf") );
00193     // zero out our copy:
00194     at = atz;
00195     BOOST_REQUIRE( marsh->readProperties("TestMarshallATypes.cpf") );
00196     // check restored result:
00197     BOOST_CHECK_EQUAL( at, atref);
00198 
00199     // write it again to an existing file:
00200     BOOST_CHECK( marsh->writeProperties("TestMarshallATypes.cpf") );
00201     // zero out our copy:
00202     at = atz;
00203     BOOST_REQUIRE( marsh->readProperties("TestMarshallATypes.cpf") );
00204     // check restored result:
00205     BOOST_CHECK_EQUAL( at, atref);
00206 }
00207 
00208 // Tests marshalling a struct type
00209 BOOST_AUTO_TEST_CASE(TestMarshallStructBTypes)
00210 {
00211     // filled in type and zero type:
00212     BType init; init.init();
00213     BTypes at, atref;
00214     at.resize(5,init); atref.resize(5,init);
00215     BTypes atz; atz.clear();
00216 
00217     tc->addProperty("at", at);
00218     // write a non-existing file:
00219     BOOST_CHECK( marsh->storeProperties("TestMarshallBTypes.cpf") );
00220     // zero out our copy:
00221     at = atz;
00222     BOOST_REQUIRE( marsh->readProperties("TestMarshallBTypes.cpf") );
00223     // check restored result:
00224     BOOST_CHECK_EQUAL( at, atref);
00225 
00226     // write it again to an existing file:
00227     BOOST_CHECK( marsh->writeProperties("TestMarshallBTypes.cpf") );
00228     // zero out our copy:
00229     at = atz;
00230     BOOST_REQUIRE( marsh->readProperties("TestMarshallBTypes.cpf") );
00231     // check restored result:
00232     BOOST_CHECK_EQUAL( at, atref);
00233 }
00234 
00235 // Tests marshalling a struct type
00236 BOOST_AUTO_TEST_CASE(TestMarshallStructCTypes)
00237 {
00238     // filled in type and zero type:
00239     CType init; init.init();
00240     CTypes at, atref;
00241     at.resize(5,init); atref.resize(5,init);
00242     CTypes atz; atz.clear();
00243 
00244     tc->addProperty("at", at);
00245     // write a non-existing file:
00246     BOOST_CHECK( marsh->storeProperties("TestMarshallCTypes.cpf") );
00247     // zero out our copy:
00248     at = atz;
00249     BOOST_REQUIRE( marsh->readProperties("TestMarshallCTypes.cpf") );
00250     // check restored result:
00251     BOOST_CHECK_EQUAL( at, atref);
00252 
00253     // write it again to an existing file:
00254     BOOST_CHECK( marsh->writeProperties("TestMarshallCTypes.cpf") );
00255     // zero out our copy:
00256     at = atz;
00257     BOOST_REQUIRE( marsh->readProperties("TestMarshallCTypes.cpf") );
00258     // check restored result:
00259     BOOST_CHECK_EQUAL( at, atref);
00260 }
00261 
00262 BOOST_AUTO_TEST_SUITE_END()


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