configuration_test.cpp
Go to the documentation of this file.
1 #include "unit.hpp"
2 #include <Attribute.hpp>
3 #include <Property.hpp>
4 #include <TaskContext.hpp>
5 
10 {
11 public:
13  int i;
17 
18 public:
20  : tc("root"), i(0)
21  {
22  }
23 
25  {
26  }
27 };
28 
29 
30 // Registers the fixture into the 'registry'
31 BOOST_FIXTURE_TEST_SUITE( ConfigurationTestSuite, ConfigurationTestFixture )
32 
33 // Tests properties() interface:
34 BOOST_AUTO_TEST_CASE( testProperties)
35 {
36  Property<double> d1("d1", "desc1", 1.234);
37  tc.properties()->addProperty( d1 );
38 
39  BOOST_CHECK_EQUAL( double(1.234), d1.get() );
40  BOOST_CHECK_EQUAL( double(1.234), tc.properties()->getPropertyType<double>("d1")->get() );
41 
42  // test setup of mirror:
44  BOOST_CHECK( !s1.ready() );
45  Property<string> s2("hello","description", "world");
46  BOOST_CHECK( s2.ready() );
47 
48  BOOST_CHECK(tc.properties()->addProperty( s1 ) == false);
49  BOOST_CHECK(tc.properties()->addProperty( s2 ) );
50  s1 = tc.properties()->getProperty("hello");
51  BOOST_CHECK( s1.ready() );
52 
53  BOOST_CHECK_EQUAL(std::string("hello"), s1.getName() );
54  BOOST_CHECK_EQUAL(std::string("description"), s1.getDescription() );
55  BOOST_CHECK_EQUAL(std::string("world"), s1.get() );
56 
57  // Test mirroring of 'set' and 'get':
58  s1.set("universe");
59  BOOST_CHECK_EQUAL(std::string("universe"), s2.get() );
60 
61 }
62 
63 // Tests attributes() interface:
64 BOOST_AUTO_TEST_CASE( testAttributes)
65 {
66  // test attribute repository:
67  Attribute<int> i1("i1");
68  Attribute<double> d1("d1", 1.234);
69  BOOST_CHECK( i1.ready() );
70  BOOST_CHECK( d1.ready() );
71  BOOST_CHECK(tc.addAttribute( d1 ));
72  BOOST_CHECK(tc.addAttribute( i1 ));
73 
74  i1.set( 3 );
75  BOOST_CHECK_EQUAL( double(1.234), d1.get() );
76  BOOST_CHECK_EQUAL( int(3), i1.get() );
77 
78  d1 = tc.getAttribute("d1");
79  BOOST_CHECK_EQUAL( double(1.234), d1.get() );
80  Attribute<int> i2 = tc.getAttribute("i1");
81  BOOST_CHECK_EQUAL( int(3), i2.get() );
82 
83  // test setup of mirror:
85  BOOST_CHECK( !s1.ready() );
86  Attribute<string> s2("hello","world");
87  BOOST_CHECK( s2.ready() );
88 
89  BOOST_CHECK(tc.addAttribute( s1 ) == false);
90  BOOST_CHECK(tc.addAttribute( s2 ) );
91  s1 = tc.getAttribute("hello");
92  BOOST_CHECK( s1.ready() );
93 
94  BOOST_CHECK_EQUAL(std::string("hello"), s1.getName() );
95  BOOST_CHECK_EQUAL(std::string("world"), s1.get() );
96 
97  // Test mirroring of 'set' and 'get':
98  s1.set("universe");
99  BOOST_CHECK_EQUAL(std::string("universe"), s2.get() );
100 
101 }
102 
103 // Tests add + double adds of the objects themselves:
104 BOOST_AUTO_TEST_CASE( testAddPropertyObjects )
105 {
106  BOOST_CHECK( tc.provides()->addProperty("p",p).doc("foo").ready() );
107  BOOST_CHECK( tc.provides()->addAttribute("a",a).ready() );
108  BOOST_CHECK( tc.provides()->addConstant("c",c).ready() );
109 
110  BOOST_CHECK( p.ready() ); BOOST_CHECK_EQUAL( p.getName(), "p" ); BOOST_CHECK_EQUAL( p.getDescription(), "foo" );
111  BOOST_CHECK( a.ready() ); BOOST_CHECK_EQUAL( a.getName(), "a" );
112  BOOST_CHECK( c.ready() ); BOOST_CHECK_EQUAL( c.getName(), "c" );
113 
114  BOOST_CHECK( tc.provides()->addProperty("p2",p).doc("bar").ready() );
115  BOOST_CHECK( tc.provides()->addAttribute("a2",a).ready() );
116  BOOST_CHECK( tc.provides()->addConstant("c2",c).ready() );
117 
118  BOOST_CHECK( p.ready() ); BOOST_CHECK_EQUAL( p.getName(), "p2" ); BOOST_CHECK_EQUAL( p.getDescription(), "bar" );
119  BOOST_CHECK( a.ready() ); BOOST_CHECK_EQUAL( a.getName(), "a2" );
120  BOOST_CHECK( c.ready() ); BOOST_CHECK_EQUAL( c.getName(), "c2" );
121 }
122 
123 // Tests add + double adds of a property/attribute/constant reference to a member
124 BOOST_AUTO_TEST_CASE( testAddProperties )
125 {
126  // Tests add + double adds of the objects themselves:
127  i = 3;
128  BOOST_CHECK( tc.provides()->addProperty("p",i).doc("foo").ready() );
129  BOOST_CHECK( tc.provides()->addAttribute("a",i) );
130  BOOST_CHECK( tc.provides()->addConstant("c",i) );
131 
132  p = tc.provides()->getProperty("p");
133  a = tc.provides()->getAttribute("a");
134  c = tc.provides()->getConstant("c");
135 
136  BOOST_CHECK( p.ready() ); BOOST_CHECK_EQUAL( p.getName(), "p" ); BOOST_CHECK_EQUAL( p.getDescription(), "foo" ); BOOST_CHECK_EQUAL( p.get(), 3);
137  BOOST_CHECK( a.ready() ); BOOST_CHECK_EQUAL( a.getName(), "a" ); BOOST_CHECK_EQUAL( a.get(), 3);
138  BOOST_CHECK( c.ready() ); BOOST_CHECK_EQUAL( c.getName(), "c" ); BOOST_CHECK_EQUAL( c.get(), 3);
139  BOOST_CHECK_EQUAL(i , 3); // not modified 'i'
140 
141  // check reference to i:
142  i = 4;
143  BOOST_CHECK_EQUAL( p.get(), 4);
144  BOOST_CHECK_EQUAL( p.get(), 4);
145  BOOST_CHECK_EQUAL( p.get(), 4);
146 
147  BOOST_CHECK( tc.provides()->addProperty("p2",i).doc("bar").ready() );
148  BOOST_CHECK( tc.provides()->addAttribute("a2",i) );
149  BOOST_CHECK( tc.provides()->addConstant("c2",i) );
150 
151  p = tc.provides()->getProperty("p2");
152  a = tc.provides()->getAttribute("a2");
153  c = tc.provides()->getConstant("c2");
154 
155  BOOST_CHECK( p.ready() ); BOOST_CHECK_EQUAL( p.getName(), "p2" ); BOOST_CHECK_EQUAL( p.getDescription(), "bar" ); BOOST_CHECK_EQUAL( p.get(), 4);
156  BOOST_CHECK( a.ready() ); BOOST_CHECK_EQUAL( a.getName(), "a2" ); BOOST_CHECK_EQUAL( a.get(), 4);
157  BOOST_CHECK( c.ready() ); BOOST_CHECK_EQUAL( c.getName(), "c2" ); BOOST_CHECK_EQUAL( c.get(), 4);
158 }
159 
160 
162 
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
DataSourceType get() const
Definition: Property.hpp:246
Property< T > * getPropertyType(const std::string &name) const
Service::shared_ptr provides()
#define BOOST_AUTO_TEST_SUITE_END()
void set(T const &t)
Definition: Attribute.hpp:199
T const & get() const
Definition: Attribute.hpp:188
BOOST_AUTO_TEST_CASE(testProperties)
T get() const
Definition: Attribute.hpp:344
Property< T > & addProperty(const std::string &name, T &attr)
base::AttributeBase * getAttribute(const std::string &name) const
const std::string & getDescription() const
bool addAttribute(const std::string &name, T &attr)
base::PropertyBase * getProperty(const std::string &name) const
PropertyBag * properties()
const std::string & getName() const
const std::string & getName() const
Definition: Attribute.cpp:59


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