Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <marsh/PropertyMarshaller.hpp>
00022 #include <marsh/PropertyDemarshaller.hpp>
00023 #include <Property.hpp>
00024 #include <PropertyBag.hpp>
00025 #include <types/PropertyComposition.hpp>
00026
00027 #include "unit.hpp"
00028
00029 class PropertyMarshTest
00030 {
00031 public:
00032 PropertyMarshTest()
00033 {
00034 }
00035 ~PropertyMarshTest()
00036 {
00037 }
00038 };
00039
00040
00041 BOOST_FIXTURE_TEST_SUITE( PropertyMarshTestSuite, PropertyMarshTest )
00042
00043
00044 BOOST_AUTO_TEST_CASE( testPropMarsh )
00045 {
00046 std::string filename = "testPropMarsh.tst";
00047
00048 PropertyBag source;
00049 PropertyBag target;
00050
00051 Property<PropertyBag> b1("b1","b1d");
00052 Property<PropertyBag> b2("b2","b2d");
00053 Property<int> p1("p1","p1d",-1);
00054
00055
00056 source.addProperty( b1 );
00057 b1.value().addProperty( b2 );
00058 b2.value().addProperty( p1 );
00059
00060 {
00061
00062 PropertyMarshaller pm( filename );
00063 pm.serialize( source );
00064 }
00065
00066 {
00067
00068 PropertyDemarshaller pd( filename );
00069 BOOST_REQUIRE( pd.deserialize( target ) );
00070 }
00071
00072 Property<PropertyBag> bag = target.getProperty("b1");
00073 BOOST_REQUIRE( bag.ready() );
00074 BOOST_CHECK( bag.getDescription() == "b1d" );
00075
00076 bag = bag.rvalue().getProperty("b2");
00077 BOOST_REQUIRE( bag.ready() );
00078 BOOST_CHECK( bag.getDescription() == "b2d" );
00079
00080 Property<int> pi = bag.rvalue().getProperty("p1");
00081 BOOST_REQUIRE( pi.ready() );
00082 BOOST_CHECK( pi.get() == -1 );
00083 BOOST_CHECK( pi.getDescription() == "p1d" );
00084 deletePropertyBag( target );
00085 }
00086
00088 BOOST_AUTO_TEST_CASE( testPropMarshVect )
00089 {
00090 std::string filename = "testPropMarshVect.tst";
00091
00092 PropertyBag source;
00093 PropertyBag target;
00094
00095 Property<std::vector<double> >* p1 = new Property<std::vector<double> >("p1","p1d", std::vector<double>(7, 1.234) );
00096
00097
00098 source.addProperty( *p1 );
00099
00100 {
00101
00102 PropertyMarshaller pm( filename );
00103 pm.serialize( source );
00104 }
00105
00106 p1->set() = std::vector<double>(3, 0.234);
00107 {
00108
00109 PropertyDemarshaller pd( filename );
00110 BOOST_REQUIRE( pd.deserialize( target ) );
00111 }
00112
00113
00114 Property<PropertyBag> bag = target.getProperty("p1");
00115 BOOST_REQUIRE( bag.ready() );
00116 BOOST_CHECK( bag.getDescription() == "p1d" );
00117 BOOST_CHECK_EQUAL( bag.rvalue().size(), 7 );
00118
00119
00120 PropertyBag composed;
00121 BOOST_CHECK( composePropertyBag(target, composed));
00122 BOOST_CHECK( updateProperties( source, composed) );
00123
00124
00125 BOOST_REQUIRE( p1->ready() );
00126 BOOST_CHECK_EQUAL( p1->rvalue().size() , 7 );
00127 BOOST_CHECK_EQUAL( p1->rvalue()[0] , 1.234 );
00128
00129 deletePropertyBag( target );
00130 deletePropertyBag( source );
00131 }
00132
00134 BOOST_AUTO_TEST_CASE( testPropMarshVectLegacy )
00135 {
00136 PropertyBag target;
00137 PropertyBag source;
00138
00139 Property<std::vector<double> >* p1 = new Property<std::vector<double> >("driveLimits","p1d", std::vector<double>(7, 1.234) );
00140
00141
00142 target.addProperty( *p1 );
00143 {
00144
00145 PropertyDemarshaller pd( "testPropMarshVectLegacy.cpf" );
00146 BOOST_REQUIRE( pd.deserialize( source ) );
00147 }
00148
00149 Property<PropertyBag> bag = source.getProperty("driveLimits");
00150 BOOST_REQUIRE( bag.ready() );
00151
00152 BOOST_CHECK_EQUAL( bag.value().size() , 7 );
00153
00154
00155 PropertyBag composed;
00156 BOOST_CHECK( composePropertyBag(source, composed));
00157 BOOST_CHECK( refreshProperties( target, composed) );
00158
00159
00160 BOOST_REQUIRE( p1->ready() );
00161
00162
00163 BOOST_CHECK_EQUAL( p1->rvalue().size() , 6 );
00164 BOOST_CHECK_EQUAL( p1->rvalue()[0] , 1 );
00165
00166 deletePropertyBag( source );
00167 }
00168
00169 BOOST_AUTO_TEST_SUITE_END()