00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00045 BOOST_FIXTURE_TEST_SUITE( MarshallingTestSuite, MarshallingFixture )
00046
00047
00048 BOOST_AUTO_TEST_CASE(TestGetProvider)
00049 {
00050
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
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));
00065 MatrixType mxz( 5, RowType(5,0.0));
00066 MatrixType mxrz;
00067
00068
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
00077 BOOST_CHECK( marsh->writeProperties("TestMarshallMatrix.cpf") );
00078
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
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
00091 BOOST_CHECK( marsh->writeProperties("TestMarshallMatrix.cpf") );
00092
00093 mx = mxz;
00094 BOOST_REQUIRE( marsh->readProperties("TestMarshallMatrix.cpf") );
00095
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
00104 BOOST_AUTO_TEST_CASE(TestMarshallStructAType)
00105 {
00106
00107 AType at, atref;
00108 at.init(); atref.init();
00109 AType atz; atz.clear();
00110
00111 tc->addProperty("at", at);
00112
00113 BOOST_CHECK( marsh->storeProperties("TestMarshallAType.cpf") );
00114
00115 at = atz;
00116 BOOST_REQUIRE( marsh->readProperties("TestMarshallAType.cpf") );
00117
00118 BOOST_CHECK_EQUAL( at, atref);
00119
00120
00121 BOOST_CHECK( marsh->writeProperties("TestMarshallAType.cpf") );
00122
00123 at = atz;
00124 BOOST_REQUIRE( marsh->readProperties("TestMarshallAType.cpf") );
00125
00126 BOOST_CHECK_EQUAL( at, atref);
00127 }
00128
00129
00130 BOOST_AUTO_TEST_CASE(TestMarshallStructBType)
00131 {
00132
00133 BType at, atref;
00134 at.init(); atref.init();
00135 BType atz; atz.clear();
00136
00137 tc->addProperty("at", at);
00138
00139 BOOST_CHECK( marsh->storeProperties("TestMarshallBType.cpf") );
00140
00141 at = atz;
00142 BOOST_REQUIRE( marsh->readProperties("TestMarshallBType.cpf") );
00143
00144 BOOST_CHECK_EQUAL( at, atref);
00145
00146
00147 BOOST_CHECK( marsh->writeProperties("TestMarshallBType.cpf") );
00148
00149 at = atz;
00150 BOOST_REQUIRE( marsh->readProperties("TestMarshallBType.cpf") );
00151
00152 BOOST_CHECK_EQUAL( at, atref);
00153 }
00154
00155
00156 BOOST_AUTO_TEST_CASE(TestMarshallStructCType)
00157 {
00158
00159 CType at, atref;
00160 at.init(); atref.init();
00161 CType atz; atz.clear();
00162
00163 tc->addProperty("at", at);
00164
00165 BOOST_CHECK( marsh->storeProperties("TestMarshallCType.cpf") );
00166
00167 at = atz;
00168 BOOST_REQUIRE( marsh->readProperties("TestMarshallCType.cpf") );
00169
00170 BOOST_CHECK_EQUAL( at, atref);
00171
00172
00173 BOOST_CHECK( marsh->writeProperties("TestMarshallCType.cpf") );
00174
00175 at = atz;
00176 BOOST_REQUIRE( marsh->readProperties("TestMarshallCType.cpf") );
00177
00178 BOOST_CHECK_EQUAL( at, atref);
00179 }
00180
00181
00182 BOOST_AUTO_TEST_CASE(TestMarshallStructATypes)
00183 {
00184
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
00192 BOOST_CHECK( marsh->storeProperties("TestMarshallATypes.cpf") );
00193
00194 at = atz;
00195 BOOST_REQUIRE( marsh->readProperties("TestMarshallATypes.cpf") );
00196
00197 BOOST_CHECK_EQUAL( at, atref);
00198
00199
00200 BOOST_CHECK( marsh->writeProperties("TestMarshallATypes.cpf") );
00201
00202 at = atz;
00203 BOOST_REQUIRE( marsh->readProperties("TestMarshallATypes.cpf") );
00204
00205 BOOST_CHECK_EQUAL( at, atref);
00206 }
00207
00208
00209 BOOST_AUTO_TEST_CASE(TestMarshallStructBTypes)
00210 {
00211
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
00219 BOOST_CHECK( marsh->storeProperties("TestMarshallBTypes.cpf") );
00220
00221 at = atz;
00222 BOOST_REQUIRE( marsh->readProperties("TestMarshallBTypes.cpf") );
00223
00224 BOOST_CHECK_EQUAL( at, atref);
00225
00226
00227 BOOST_CHECK( marsh->writeProperties("TestMarshallBTypes.cpf") );
00228
00229 at = atz;
00230 BOOST_REQUIRE( marsh->readProperties("TestMarshallBTypes.cpf") );
00231
00232 BOOST_CHECK_EQUAL( at, atref);
00233 }
00234
00235
00236 BOOST_AUTO_TEST_CASE(TestMarshallStructCTypes)
00237 {
00238
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
00246 BOOST_CHECK( marsh->storeProperties("TestMarshallCTypes.cpf") );
00247
00248 at = atz;
00249 BOOST_REQUIRE( marsh->readProperties("TestMarshallCTypes.cpf") );
00250
00251 BOOST_CHECK_EQUAL( at, atref);
00252
00253
00254 BOOST_CHECK( marsh->writeProperties("TestMarshallCTypes.cpf") );
00255
00256 at = atz;
00257 BOOST_REQUIRE( marsh->readProperties("TestMarshallCTypes.cpf") );
00258
00259 BOOST_CHECK_EQUAL( at, atref);
00260 }
00261
00262 BOOST_AUTO_TEST_SUITE_END()