property_composition_test.cpp
Go to the documentation of this file.
1 #include <typeinfo>
4 #include <Property.hpp>
5 #include <PropertyBag.hpp>
6 #include <Logger.hpp>
7 
8 #include "unit.hpp"
9 
11 {
12 public:
17 
19  :pv("pv","pvd", vector<double>(10,5.0))
20  {
21  }
23  {
24  }
25 };
26 
27 bool operator==(const std::vector<double>& a, const std::vector<double>& b)
28 {
29  if ( a.size() != b.size() ) {
30  log(Error) << "Wrong vector sizes : " << a.size() <<" "<< b.size()<<endlog();
31  return false;
32  }
33  for(unsigned int i =0; i != a.size(); ++i)
34  {
35  if (a[i] != b[i]) {
36  log(Error) << "Wrong vector element: "<<a[i]<<" != "<<b[i]<<" i:" << i<<endlog();
37  return false;
38  }
39  }
40  return true;
41 }
42 
43 namespace std {
44 std::ostream& operator<<(std::ostream& os, const std::vector<double>& vect) {
45  os << '[';
46  for(unsigned int i= 0; i != vect.size(); ++i)
47  os << vect[i] << (i+1 == vect.size() ? "]" : ", ");
48  return os;
49 }
50 }
51 namespace RTT {
52  // todo
53 bool operator==(const PropertyBag& a, const PropertyBag& b) {
54  if( a.size() == b.size() ) {
56 // PropertyBag::const_iterator itb = b.begin();
57  while ( ita != a.end() ) {
58  //if ( (*ita)->equals(*itb) )
59  return false;
60  }
61  }
62  return false;
63 }
64 }
65 
66 
68 
69 BOOST_AUTO_TEST_CASE( testDecomposeComposeEmptyBag )
70 {
71  BOOST_CHECK( decomposePropertyBag(source, target) );
72  BOOST_CHECK_EQUAL( target.size(), 0);
73  BOOST_CHECK( composePropertyBag(target, result) );
74  BOOST_CHECK_EQUAL( result.size(), 0);
75 }
76 
77 BOOST_AUTO_TEST_CASE( testDecomposeComposeWrongTargetBag )
78 {
80  BOOST_CHECK( decomposePropertyBag(source, target) == false );
81  BOOST_CHECK_EQUAL( target.size(), 1);
83  BOOST_CHECK( composePropertyBag(target, result) == false );
84  BOOST_CHECK_EQUAL( result.size(), 1);
85 }
86 
87 BOOST_AUTO_TEST_CASE( testDecomposeComposeVector )
88 {
90 
91  BOOST_CHECK( decomposePropertyBag(source, target) );
92  BOOST_CHECK_EQUAL( target.size(), 1);
93 
95  BOOST_REQUIRE( decomposed.ready() );
96  BOOST_CHECK_EQUAL( decomposed.value().getType(), "array" );
97 
98  // check that target bag has equal number of decomposed elements:
99  BOOST_CHECK_EQUAL( decomposed.getDescription(), pv.getDescription() );
100  BOOST_CHECK_EQUAL( decomposed.value().size(), pv.value().size() );
101 
102  BOOST_CHECK( composePropertyBag(target, result) );
103 
105  pr = result.getProperty("pv");
106  BOOST_REQUIRE( pr.ready() );
107  BOOST_CHECK_EQUAL( pr.value().size(), pv.value().size() );
108  BOOST_CHECK_EQUAL( pr.value(), pv.value() );
109 }
110 
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
Property< T > * getPropertyType(const std::string &name) const
#define BOOST_AUTO_TEST_SUITE_END()
Definition: mystd.hpp:163
bool RTT_API composePropertyBag(PropertyBag const &sourcebag, PropertyBag &target)
bool operator==(const std::vector< double > &a, const std::vector< double > &b)
A container for holding references to properties.
Definition: PropertyBag.hpp:96
reference_t value()
Definition: Property.hpp:277
BOOST_AUTO_TEST_CASE(testDecomposeComposeEmptyBag)
bool RTT_API decomposePropertyBag(PropertyBag const &sourcebag, PropertyBag &target)
Property< T > & addProperty(const std::string &name, T &attr)
Property< vector< double > > pv
A property represents a named value of any type with a description.
Definition: Property.hpp:76
const std::string & getDescription() const
Properties::const_iterator const_iterator
base::PropertyBase * getProperty(const std::string &name) const
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
size_t size() const
static Logger & log()
Definition: Logger.hpp:350
static Logger::LogFunction endlog()
Definition: Logger.hpp:362
iterator begin()


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