datasource_test.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:54:57 CEST 2010 datasource_test.cpp
3 
4  datasource_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/array.hpp>
23 
24 #include <rtt-fwd.hpp>
25 
26 #include <internal/DataSources.hpp>
29 //#include <internal/OffsetPartDataSource.hpp>
30 #include <internal/carray.hpp>
31 
32 #include <boost/serialization/array.hpp>
33 
34 #include <os/fosi.h>
35 #include "datasource_fixture.hpp"
36 
38 {
39 public:
42 
46  atype.init();
47  atype_orig.init();
48  btype.init();
49  btype_orig.init();
50  }
52 };
53 
54 // Registers the fixture into the 'registry'
55 BOOST_FIXTURE_TEST_SUITE( DataSourceTestSuite, DataSourceTest )
56 
57 // Test semantics of ValueDataSource and test fixture.
58 BOOST_AUTO_TEST_CASE( testValueDataSource )
59 {
61 
62  // Test fixture:
63  BOOST_CHECK_EQUAL( atype, atype );
64  BOOST_CHECK_EQUAL( atype, atype_orig );
65 
66  // Do not take by reference:
67  BOOST_CHECK_EQUAL( d->set(), atype );
68  atype.a = -atype.a;
69  BOOST_CHECK_EQUAL( d->set(), atype_orig );
70 }
71 
72 // Test constant DataSource.
73 BOOST_AUTO_TEST_CASE( testConstantDataSource )
74 {
76 
77  // Do not take by reference:
78  BOOST_CHECK_EQUAL( d->get(), atype );
79  atype.a = -atype.a;
80  BOOST_CHECK_EQUAL( d->get(), atype_orig );
81 }
82 
83 // Test reference to C++ data
84 BOOST_AUTO_TEST_CASE( testReferenceDataSource )
85 {
87 
88  // Take by reference:
89  BOOST_CHECK_EQUAL( d->set(), atype );
90  atype.a = -atype.a;
91  BOOST_CHECK_EQUAL( d->set(), atype );
92 
93  d->set().a = 55;
94  BOOST_CHECK_EQUAL( d->set(), atype );
95 }
96 
97 // Test const reference to C++ data
98 BOOST_AUTO_TEST_CASE( testConstReferenceDataSource )
99 {
101 
102  // Take by reference:
103  BOOST_CHECK_EQUAL( d->get(), atype );
104  atype.a = -atype.a;
105  BOOST_CHECK_EQUAL( d->get(), atype );
106 }
107 
108 // Test part reference to C++ data
109 BOOST_AUTO_TEST_CASE( testPartDataSource )
110 {
113 
114  // Take string by reference:
115  BOOST_CHECK_EQUAL( d->set(), atype.c );
116  atype.c = "world";
117  BOOST_CHECK_EQUAL( d->set(), atype.c );
118 
119  // Test both versions of set(). This also checks updated():
120  d->set( "Long gone!" );
121  BOOST_CHECK_EQUAL( d->set(), abase->get().c );
122  BOOST_CHECK_EQUAL( d->set(), atype.c );
123 
124  d->set() = "And back!";
125  d->updated();
126  BOOST_CHECK_EQUAL( d->set(), abase->get().c );
127  BOOST_CHECK_EQUAL( d->set(), atype.c );
128 }
129 
132 BOOST_AUTO_TEST_CASE( testArrayDataSource )
133 {
135  AssignableDataSource<carray<char> >::shared_ptr d =
137 
138  // Take string by reference (!):
139  BOOST_CHECK_EQUAL( d->set().address(), btype.c );
140  strcpy( btype.c, "world");
141  BOOST_CHECK_EQUAL( "world", btype.c );
142  BOOST_CHECK_EQUAL( d->set().address(), btype.c );
143 
144  // Test both versions of set(). This also checks updated():
145  *d->set().address() = 'L';
146  d->updated();
147  BOOST_CHECK_EQUAL( "Lorld", btype.c );
148  BOOST_CHECK_EQUAL( "Lorld", d->get().address() );
149  BOOST_CHECK_EQUAL( d->set().address(), btype.c );
150 }
151 
154 BOOST_AUTO_TEST_CASE( testArrayPartDataSource )
155 {
159 
160  // Take string by reference:
161  BOOST_CHECK_EQUAL( &d->set(), btype.c );
162  strcpy( btype.c, "world");
163  BOOST_CHECK_EQUAL( "world", btype.c );
164  BOOST_CHECK_EQUAL( &d->set(), btype.c );
165 
166  // Test both versions of set(). This also checks updated():
167  d->set( 'L' );
168  BOOST_CHECK_EQUAL( "Lorld", btype.c );
169  BOOST_CHECK( strcmp( &d->set(), abase->get().c) == 0 );
170  BOOST_CHECK_EQUAL( &d->set(), btype.c );
171 
172  d->set() = 'W';
173  d->updated();
174  BOOST_CHECK_EQUAL( "World", btype.c );
175  BOOST_CHECK( strcmp( &d->set(), abase->get().c) == 0 );
176  BOOST_CHECK_EQUAL( &d->set(), btype.c );
177 
178  index->set( 3 );
179  d->set( 'L' );
180  BOOST_CHECK_EQUAL( "WorLd", btype.c );
181  BOOST_CHECK( strcmp( &d->set(), &abase->get().c[3]) == 0 );
182  BOOST_CHECK_EQUAL( &d->set(), &btype.c[3] );
183 }
184 
185 
187 
#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
BOOST_AUTO_TEST_CASE(testValueDataSource)
DataSource< T >::result_t get() const
boost::intrusive_ptr< DataSource< T > > shared_ptr
Definition: DataSource.hpp:115
boost::intrusive_ptr< AssignableDataSource< T > > shared_ptr
Definition: DataSource.hpp:198


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:23