property_composition_test.cpp
Go to the documentation of this file.
00001 #include <typeinfo>
00002 #include <internal/DataSourceTypeInfo.hpp>
00003 #include <types/PropertyComposition.hpp>
00004 #include <Property.hpp>
00005 #include <PropertyBag.hpp>
00006 #include <Logger.hpp>
00007 
00008 #include "unit.hpp"
00009 
00010 class PropertyCompositionTest
00011 {
00012 public:
00013     PropertyBag source;
00014     PropertyBag target;
00015     PropertyBag result;
00016     Property<vector<double> > pv;
00017 
00018     PropertyCompositionTest()
00019     :pv("pv","pvd", vector<double>(10,5.0))
00020     {
00021     }
00022     ~PropertyCompositionTest()
00023     {
00024     }
00025 };
00026 
00027 bool operator==(const std::vector<double>& a, const std::vector<double>& b)
00028 {
00029     if ( a.size() != b.size() ) {
00030         log(Error) << "Wrong vector sizes : " << a.size() <<" "<< b.size()<<endlog();
00031         return false;
00032     }
00033     for(unsigned int i =0; i != a.size(); ++i)
00034         {
00035             if (a[i] != b[i]) {
00036                 log(Error) << "Wrong vector element: "<<a[i]<<" != "<<b[i]<<" i:" << i<<endlog();
00037                 return false;
00038             }
00039         }
00040     return true;
00041 }
00042 
00043 namespace std {
00044 std::ostream& operator<<(std::ostream& os, const std::vector<double>& vect) {
00045     os << '[';
00046     for(unsigned int i= 0; i != vect.size(); ++i)
00047         os << vect[i] << (i+1 == vect.size() ? "]" : ", ");
00048     return os;
00049 }
00050 }
00051 namespace RTT {
00052     // todo
00053 bool operator==(const PropertyBag& a, const PropertyBag& b) {
00054     if( a.size() == b.size() ) {
00055         PropertyBag::const_iterator ita = a.begin();
00056 //        PropertyBag::const_iterator itb = b.begin();
00057         while ( ita != a.end() ) {
00058             //if ( (*ita)->equals(*itb) )
00059                 return false;
00060         }
00061     }
00062     return false;
00063 }
00064 }
00065 
00066 
00067 BOOST_FIXTURE_TEST_SUITE( PropertyTestSuite, PropertyCompositionTest )
00068 
00069 BOOST_AUTO_TEST_CASE( testDecomposeComposeEmptyBag )
00070 {
00071     BOOST_CHECK( decomposePropertyBag(source, target) );
00072     BOOST_CHECK_EQUAL( target.size(), 0);
00073     BOOST_CHECK( composePropertyBag(target, result) );
00074     BOOST_CHECK_EQUAL( result.size(), 0);
00075 }
00076 
00077 BOOST_AUTO_TEST_CASE( testDecomposeComposeWrongTargetBag )
00078 {
00079     target.addProperty(pv);
00080     BOOST_CHECK( decomposePropertyBag(source, target) == false );
00081     BOOST_CHECK_EQUAL( target.size(), 1);
00082     result.addProperty(pv);
00083     BOOST_CHECK( composePropertyBag(target, result) == false );
00084     BOOST_CHECK_EQUAL( result.size(), 1);
00085 }
00086 
00087 BOOST_AUTO_TEST_CASE( testDecomposeComposeVector )
00088 {
00089     source.addProperty(pv);
00090 
00091     BOOST_CHECK( decomposePropertyBag(source, target) );
00092     BOOST_CHECK_EQUAL( target.size(), 1);
00093 
00094     Property<PropertyBag> decomposed = target.getPropertyType<PropertyBag>("pv");
00095     BOOST_REQUIRE( decomposed.ready() );
00096     BOOST_CHECK_EQUAL( decomposed.value().getType(), "array" );
00097 
00098     // check that target bag has equal number of decomposed elements:
00099     BOOST_CHECK_EQUAL( decomposed.getDescription(), pv.getDescription() );
00100     BOOST_CHECK_EQUAL( decomposed.value().size(), pv.value().size() );
00101 
00102     BOOST_CHECK( composePropertyBag(target, result) );
00103 
00104     Property<vector<double> > pr;
00105     pr = result.getProperty("pv");
00106     BOOST_REQUIRE( pr.ready() );
00107     BOOST_CHECK_EQUAL( pr.value().size(), pv.value().size() );
00108     BOOST_CHECK_EQUAL( pr.value(), pv.value() );
00109 }
00110 
00111 BOOST_AUTO_TEST_SUITE_END()


rtt
Author(s): RTT Developers
autogenerated on Fri Sep 9 2016 04:01:56