configuration_test.cpp
Go to the documentation of this file.
00001 #include "unit.hpp"
00002 #include <Attribute.hpp>
00003 #include <Property.hpp>
00004 #include <TaskContext.hpp>
00005 
00009 class ConfigurationTestFixture
00010 {
00011 public:
00012     TaskContext tc;
00013     int i;
00014     Property<int> p;
00015     Attribute<int> a;
00016     Constant<int> c;
00017 
00018 public:
00019     ConfigurationTestFixture()
00020     : tc("root"), i(0)
00021     {
00022     }
00023 
00024     ~ConfigurationTestFixture()
00025     {
00026     }
00027 };
00028 
00029 
00030 // Registers the fixture into the 'registry'
00031 BOOST_FIXTURE_TEST_SUITE(  ConfigurationTestSuite,  ConfigurationTestFixture )
00032 
00033 // Tests properties() interface:
00034 BOOST_AUTO_TEST_CASE( testProperties)
00035 {
00036     Property<double> d1("d1", "desc1", 1.234);
00037     tc.properties()->addProperty( d1 );
00038 
00039     BOOST_CHECK_EQUAL( double(1.234), d1.get() );
00040     BOOST_CHECK_EQUAL( double(1.234), tc.properties()->getPropertyType<double>("d1")->get() );
00041 
00042     // test setup of mirror:
00043     Property<string> s1;
00044     BOOST_CHECK( !s1.ready() );
00045     Property<string> s2("hello","description", "world");
00046     BOOST_CHECK( s2.ready() );
00047 
00048     BOOST_CHECK(tc.properties()->addProperty( s1 ) == false);
00049     BOOST_CHECK(tc.properties()->addProperty( s2 ) );
00050     s1 = tc.properties()->getProperty("hello");
00051     BOOST_CHECK( s1.ready() );
00052 
00053     BOOST_CHECK_EQUAL(std::string("hello"), s1.getName() );
00054     BOOST_CHECK_EQUAL(std::string("description"), s1.getDescription() );
00055     BOOST_CHECK_EQUAL(std::string("world"), s1.get() );
00056 
00057     // Test mirroring of 'set' and 'get':
00058     s1.set("universe");
00059     BOOST_CHECK_EQUAL(std::string("universe"), s2.get() );
00060 
00061 }
00062 
00063 // Tests attributes() interface:
00064 BOOST_AUTO_TEST_CASE( testAttributes)
00065 {
00066     // test attribute repository:
00067     Attribute<int> i1("i1");
00068     Attribute<double> d1("d1", 1.234);
00069     BOOST_CHECK( i1.ready() );
00070     BOOST_CHECK( d1.ready() );
00071     BOOST_CHECK(tc.addAttribute( d1 ));
00072     BOOST_CHECK(tc.addAttribute( i1 ));
00073 
00074     i1.set( 3 );
00075     BOOST_CHECK_EQUAL( double(1.234), d1.get() );
00076     BOOST_CHECK_EQUAL( int(3), i1.get() );
00077 
00078     d1 = tc.getAttribute("d1");
00079     BOOST_CHECK_EQUAL( double(1.234), d1.get() );
00080     Attribute<int> i2 = tc.getAttribute("i1");
00081     BOOST_CHECK_EQUAL( int(3),        i2.get() );
00082 
00083     // test setup of mirror:
00084     Attribute<string> s1;
00085     BOOST_CHECK( !s1.ready() );
00086     Attribute<string> s2("hello","world");
00087     BOOST_CHECK( s2.ready() );
00088 
00089     BOOST_CHECK(tc.addAttribute( s1 ) == false);
00090     BOOST_CHECK(tc.addAttribute( s2 ) );
00091     s1 = tc.getAttribute("hello");
00092     BOOST_CHECK( s1.ready() );
00093 
00094     BOOST_CHECK_EQUAL(std::string("hello"), s1.getName() );
00095     BOOST_CHECK_EQUAL(std::string("world"), s1.get() );
00096 
00097     // Test mirroring of 'set' and 'get':
00098     s1.set("universe");
00099     BOOST_CHECK_EQUAL(std::string("universe"), s2.get() );
00100 
00101 }
00102 
00103 // Tests add + double adds of the objects themselves:
00104 BOOST_AUTO_TEST_CASE( testAddPropertyObjects )
00105 {
00106     BOOST_CHECK( tc.provides()->addProperty("p",p).doc("foo").ready() );
00107     BOOST_CHECK( tc.provides()->addAttribute("a",a).ready() );
00108     BOOST_CHECK( tc.provides()->addConstant("c",c).ready() );
00109 
00110     BOOST_CHECK( p.ready() ); BOOST_CHECK_EQUAL( p.getName(), "p" ); BOOST_CHECK_EQUAL( p.getDescription(), "foo" );
00111     BOOST_CHECK( a.ready() ); BOOST_CHECK_EQUAL( a.getName(), "a" );
00112     BOOST_CHECK( c.ready() ); BOOST_CHECK_EQUAL( c.getName(), "c" );
00113 
00114     BOOST_CHECK( tc.provides()->addProperty("p2",p).doc("bar").ready() );
00115     BOOST_CHECK( tc.provides()->addAttribute("a2",a).ready() );
00116     BOOST_CHECK( tc.provides()->addConstant("c2",c).ready() );
00117 
00118     BOOST_CHECK( p.ready() ); BOOST_CHECK_EQUAL( p.getName(), "p2" ); BOOST_CHECK_EQUAL( p.getDescription(), "bar" );
00119     BOOST_CHECK( a.ready() ); BOOST_CHECK_EQUAL( a.getName(), "a2" );
00120     BOOST_CHECK( c.ready() ); BOOST_CHECK_EQUAL( c.getName(), "c2" );
00121 }
00122 
00123 // Tests add + double adds of a property/attribute/constant reference to a member
00124 BOOST_AUTO_TEST_CASE( testAddProperties )
00125 {
00126     // Tests add + double adds of the objects themselves:
00127     i = 3;
00128     BOOST_CHECK( tc.provides()->addProperty("p",i).doc("foo").ready() );
00129     BOOST_CHECK( tc.provides()->addAttribute("a",i) );
00130     BOOST_CHECK( tc.provides()->addConstant("c",i) );
00131 
00132     p = tc.provides()->getProperty("p");
00133     a = tc.provides()->getAttribute("a");
00134     c = tc.provides()->getConstant("c");
00135 
00136     BOOST_CHECK( p.ready() ); BOOST_CHECK_EQUAL( p.getName(), "p" ); BOOST_CHECK_EQUAL( p.getDescription(), "foo" ); BOOST_CHECK_EQUAL( p.get(), 3);
00137     BOOST_CHECK( a.ready() ); BOOST_CHECK_EQUAL( a.getName(), "a" ); BOOST_CHECK_EQUAL( a.get(), 3);
00138     BOOST_CHECK( c.ready() ); BOOST_CHECK_EQUAL( c.getName(), "c" ); BOOST_CHECK_EQUAL( c.get(), 3);
00139     BOOST_CHECK_EQUAL(i , 3); // not modified 'i'
00140 
00141     // check reference to i:
00142     i = 4;
00143     BOOST_CHECK_EQUAL( p.get(), 4);
00144     BOOST_CHECK_EQUAL( p.get(), 4);
00145     BOOST_CHECK_EQUAL( p.get(), 4);
00146 
00147     BOOST_CHECK( tc.provides()->addProperty("p2",i).doc("bar").ready() );
00148     BOOST_CHECK( tc.provides()->addAttribute("a2",i) );
00149     BOOST_CHECK( tc.provides()->addConstant("c2",i) );
00150 
00151     p = tc.provides()->getProperty("p2");
00152     a = tc.provides()->getAttribute("a2");
00153     c = tc.provides()->getConstant("c2");
00154 
00155     BOOST_CHECK( p.ready() ); BOOST_CHECK_EQUAL( p.getName(), "p2" ); BOOST_CHECK_EQUAL( p.getDescription(), "bar" ); BOOST_CHECK_EQUAL( p.get(), 4);
00156     BOOST_CHECK( a.ready() ); BOOST_CHECK_EQUAL( a.getName(), "a2" ); BOOST_CHECK_EQUAL( a.get(), 4);
00157     BOOST_CHECK( c.ready() ); BOOST_CHECK_EQUAL( c.getName(), "c2" ); BOOST_CHECK_EQUAL( c.get(), 4);
00158 }
00159 
00160 
00161 BOOST_AUTO_TEST_SUITE_END()
00162 


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