type_discovery_test.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:54:57 CEST 2010 type_discovery_test.cpp
3 
4  type_discovery_test.cpp - description
5  -------------------
6  begin : Tue September 07 2010
7  copyright : (C) 2010 The SourceWorks
8  email : peter@thesourceworks.com
9 
10  ***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 
20 #include "unit.hpp"
21 
22 #include <boost/serialization/vector.hpp>
23 #include <boost/array.hpp>
24 
25 #include <rtt-fwd.hpp>
26 #include <internal/DataSources.hpp>
27 #include <types/type_discovery.hpp>
28 #include <os/fosi.h>
29 
30 #include "datasource_fixture.hpp"
31 #include "types/StructTypeInfo.hpp"
32 #include "types/CArrayTypeInfo.hpp"
35 
36 using namespace boost::archive;
37 using namespace boost::serialization;
38 
40 {
41 public:
44 };
45 
46 // Registers the fixture into the 'registry'
47 BOOST_FIXTURE_TEST_SUITE( TypeArchiveTestSuite, TypeArchiveTest )
48 
49 // Test writing an AType data sample into a type data archive
50 BOOST_AUTO_TEST_CASE( testATypeDiscovery )
51 {
53 
54  // decompose a complex type
55  type_discovery out( atype );
56  out.discover( atype->set() );
57 
58  BOOST_CHECK_EQUAL( out.mnames.size(), 5 );
59  BOOST_CHECK_EQUAL( out.mparts.size(), 5 );
60  BOOST_CHECK_EQUAL( out.mparent, atype);
61 
62  BOOST_REQUIRE_EQUAL( out.mparts.size(), 5);
63 
67  AssignableDataSource<types::carray<int> >::shared_ptr ai = AssignableDataSource<types::carray<int> >::narrow( out.mparts[3].get());
68  AssignableDataSource<vector<double> >::shared_ptr vd = AssignableDataSource<vector<double> >::narrow( out.mparts[4].get());
69 
70  BOOST_REQUIRE( a );
71  BOOST_REQUIRE( b );
72  BOOST_REQUIRE( c );
73  BOOST_REQUIRE( ai );
74  BOOST_REQUIRE( vd );
75 
76  // Check reading parts (must equal parent)
77  BOOST_CHECK_EQUAL( a->get(), atype->get().a );
78  BOOST_CHECK_EQUAL( b->get(), atype->get().b );
79  BOOST_CHECK_EQUAL( c->get(), atype->get().c );
80  BOOST_CHECK_EQUAL( ai->get().address()[3], atype->get().ai[3] );
81  BOOST_CHECK_EQUAL( vd->get()[3], atype->get().vd[3] );
82 
83  // Check writing a part (must change in parent too).
84  a->set(10);
85  BOOST_CHECK_EQUAL( a->get(), 10 );
86  BOOST_CHECK_EQUAL( a->get(), atype->get().a );
87 
88  // Check getMember function.
89  BOOST_CHECK_EQUAL( out.getMember("a"), out.mparts[0] );
90  BOOST_CHECK_EQUAL( out.getMember("b"), out.mparts[1] );
91  BOOST_CHECK_EQUAL( out.getMember("c"), out.mparts[2] );
92  BOOST_CHECK_EQUAL( out.getMember("ai"), out.mparts[3] );
93  BOOST_CHECK_EQUAL( out.getMember("vd"), out.mparts[4] );
94 }
95 
96 // Test writing a BType data sample into a type data archive
97 BOOST_AUTO_TEST_CASE( testBTypeDiscovery )
98 {
100 
101  // decompose a complex type
102  type_discovery out( atype );
103  out.discover( atype->set() );
104 
105  BOOST_CHECK_EQUAL( out.mnames.size(), 5 );
106  BOOST_CHECK_EQUAL( out.mparts.size(), 5 );
107  BOOST_CHECK_EQUAL( out.mparent, atype);
108 
109  BOOST_REQUIRE_EQUAL( out.mparts.size(), 5);
110 
113  AssignableDataSource< carray<char> >::shared_ptr c = AssignableDataSource< carray<char> >::narrow( out.mparts[2].get());
114  AssignableDataSource< carray<int> >::shared_ptr ai = AssignableDataSource< carray<int> >::narrow( out.mparts[3].get());
115  AssignableDataSource< carray<double> >::shared_ptr vd = AssignableDataSource< carray<double> >::narrow( out.mparts[4].get());
116 
117  BOOST_REQUIRE( a );
118  BOOST_REQUIRE( b );
119  BOOST_REQUIRE( c );
120  BOOST_REQUIRE( ai );
121  BOOST_REQUIRE( vd );
122 
123  BOOST_CHECK( !out.getMember("zort") );
124 
125 
126  // Check reading parts (must equal parent)
127  BOOST_CHECK_EQUAL( a->get(), atype->get().a );
128  BOOST_CHECK_EQUAL( b->get(), atype->get().b );
129  BOOST_CHECK_EQUAL( c->get().address(), atype->set().c );
130  BOOST_CHECK_EQUAL( ai->get().address()[3], atype->set().ai[3] );
131  BOOST_CHECK_EQUAL( vd->get().address()[3], atype->set().vd[3] );
132 
133  // Check writing a part (must change in parent too).
134  a->set(10);
135  BOOST_CHECK_EQUAL( a->get(), 10 );
136  BOOST_CHECK_EQUAL( a->get(), atype->get().a );
137 
138  c->set().address()[3] = 'L';
139  BOOST_CHECK_EQUAL( c->get().address(), "helLo" );
140  BOOST_CHECK_EQUAL( c->get().address(), atype->set().c );
141 
142  // Check getMember function.
143  BOOST_CHECK_EQUAL( out.getMember("a"), out.mparts[0] );
144  BOOST_CHECK_EQUAL( out.getMember("b"), out.mparts[1] );
145  BOOST_CHECK_EQUAL( out.getMember("c"), out.mparts[2] );
146  BOOST_CHECK_EQUAL( out.getMember("ai"), out.mparts[3] );
147  BOOST_CHECK_EQUAL( out.getMember("vd"), out.mparts[4] );
148 }
149 
151 
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
virtual result_t get() const =0
#define BOOST_AUTO_TEST_SUITE_END()
virtual void set(param_t t)=0
virtual shared_ptr getMember(const std::string &member_name)
Definition: DataSource.cpp:124
BOOST_AUTO_TEST_CASE(testATypeDiscovery)
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
Definition: DataSource.hpp:198
vector< double > vd
boost::array< int, 5 > ai
DataSource< T >::result_t get() const
Definition: DataSources.hpp:78


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