corba_mqueue_test.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: The SourceWorks Tue Sep 7 00:54:57 CEST 2010 corba_mqueue_test.cpp
3 
4  corba_mqueue_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 #include "unit.hpp"
20 
21 #include "corba_mqueue_test.hpp"
22 
23 #include <iostream>
24 
29 
30 using namespace std;
32 
33 void
35 {
36  // connect DataPorts
37  mr1 = new InputPort<double>("mr");
38  mw1 = new OutputPort<double>("mw");
39 
40  mr2 = new InputPort<double>("mr");
41  mw2 = new OutputPort<double>("mw");
42 
43  tc = new TaskContext( "localroot" );
44  tc->ports()->addEventPort( *mr1, boost::bind(&CorbaMQueueTest::new_data_listener, this, _1) );
45  tc->ports()->addPort( *mw1 );
46 
47  t2 = new TaskContext("localother");
48  t2->ports()->addEventPort( *mr2,boost::bind(&CorbaMQueueTest::new_data_listener, this, _1) );
49  t2->ports()->addPort( *mw2 );
50 
51  ts2 = ts = 0;
52  tp2 = tp = 0;
53 }
54 
55 
56 void
58 {
59  delete tp;
60  delete ts;
61  delete tp2;
62  delete ts2;
63  delete tc;
64  delete t2;
65 
66  delete mr1;
67  delete mw1;
68  delete mr2;
69  delete mw2;
70 }
71 
73 {
74  signalled_port = port;
75 }
76 
77 
78 #define ASSERT_PORT_SIGNALLING(code, read_port) do { \
79  signalled_port = 0; \
80  code; \
81  usleep(100000); \
82  BOOST_CHECK( read_port == signalled_port ); \
83 } while(0)
84 
86 {
87  // This test assumes that there is a data connection mw1 => mr2
88  // Check if connection succeeded both ways:
89  BOOST_CHECK( mw1->connected() );
90  BOOST_CHECK( mr2->connected() );
91 
92  double value = 0;
93 
94  // Check if no-data works
95  BOOST_CHECK( !mr2->read(value) );
96 
97  // Check if writing works (including signalling)
98  ASSERT_PORT_SIGNALLING(mw1->write(1.0), mr2);
99  BOOST_CHECK( mr2->read(value) );
100  BOOST_CHECK_EQUAL( 1.0, value );
101  ASSERT_PORT_SIGNALLING(mw1->write(2.0), mr2);
102  BOOST_CHECK( mr2->read(value) );
103  BOOST_CHECK_EQUAL( 2.0, value );
104 }
105 
107 {
108  // This test assumes that there is a buffer connection mw1 => mr2 of size 3
109  // Check if connection succeeded both ways:
110  BOOST_CHECK( mw1->connected() );
111  BOOST_CHECK( mr2->connected() );
112 
113  double value = 0;
114 
115  // Check if no-data works
116  BOOST_CHECK( !mr2->read(value) );
117 
118  // Check if writing works
119  ASSERT_PORT_SIGNALLING(mw1->write(1.0), mr2);
120  ASSERT_PORT_SIGNALLING(mw1->write(2.0), mr2);
121  ASSERT_PORT_SIGNALLING(mw1->write(3.0), mr2);
122  // it will be emptied too fast by mqueue.
123  //ASSERT_PORT_SIGNALLING(mw1->write(4.0), 0);
124  BOOST_CHECK( mr2->read(value) );
125  BOOST_CHECK_EQUAL( 1.0, value );
126  BOOST_CHECK( mr2->read(value) );
127  BOOST_CHECK_EQUAL( 2.0, value );
128  BOOST_CHECK( mr2->read(value) );
129  BOOST_CHECK_EQUAL( 3.0, value );
130  BOOST_CHECK_EQUAL( mr2->read(value), OldData );
131 }
132 
134 {
135  BOOST_CHECK( !mw1->connected() );
136  BOOST_CHECK( !mr2->connected() );
137 }
138 
139 
140 // Registers the fixture into the 'registry'
141 BOOST_FIXTURE_TEST_SUITE( CorbaMQueueTestSuite, CorbaMQueueTest )
142 
143 
144 BOOST_AUTO_TEST_CASE( testPortConnections )
145 {
146  // This test tests the differen port-to-port connections.
147  ts = corba::TaskContextServer::Create( tc, false ); //no-naming
148  ts2 = corba::TaskContextServer::Create( t2, false ); //no-naming
149 
150  // Create a default CORBA policy specification
151  RTT::corba::CConnPolicy policy = toCORBA( RTT::ConnPolicy() );
152  policy.type = RTT::corba::CData;
153  policy.init = false;
154  policy.lock_policy = RTT::corba::CLockFree;
155  policy.size = 0;
156  policy.data_size = 0;
157 
158  corba::CDataFlowInterface_var ports = ts->server()->ports();
159  corba::CDataFlowInterface_var ports2 = ts2->server()->ports();
160 
161  // must be running to catch event port signalling.
162  BOOST_CHECK( t2->start() );
163  // WARNING: in the following, there is four configuration tested. There is
164  // also three different ways to disconnect. We need to test those three
165  // "disconnection methods", so beware when you change something ...
166 
167  policy.type = RTT::corba::CData;
168  policy.pull = false;
169  policy.transport = ORO_MQUEUE_PROTOCOL_ID;
170  BOOST_CHECK( ports->createConnection("mw", ports2, "mr", policy) );
171  usleep(100000); // gives dispatcher time to catch up.
172  testPortDataConnection();
173  ports->disconnectPort("mw");
174  testPortDisconnected();
175 
176  policy.type = RTT::corba::CData;
177  policy.pull = true;
178  policy.transport = ORO_MQUEUE_PROTOCOL_ID;
179  BOOST_CHECK( ports->createConnection("mw", ports2, "mr", policy) );
180  usleep(100000);
181  testPortDataConnection();
182  ports2->disconnectPort("mr");
183  testPortDisconnected();
184 
185 #if 1
186 
187  policy.type = RTT::corba::CBuffer;
188  policy.pull = false;
189  policy.size = 3;
190  policy.transport = ORO_MQUEUE_PROTOCOL_ID;
191  BOOST_CHECK( ports->createConnection("mw", ports2, "mr", policy) );
192  testPortBufferConnection();
193  ports->disconnectPort("mw");
194  testPortDisconnected();
195 
196  policy.type = RTT::corba::CBuffer;
197  policy.pull = true;
198  policy.size = 3;
199  policy.transport = ORO_MQUEUE_PROTOCOL_ID;
200  BOOST_CHECK( ports->createConnection("mw", ports2, "mr", policy) );
201  testPortBufferConnection();
202  ports->disconnectPort("mw");
203  testPortDisconnected();
204 #endif
205 }
206 
208 
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
BOOST_AUTO_TEST_CASE(testPortConnections)
#define BOOST_AUTO_TEST_SUITE_END()
Definition: mystd.hpp:163
int usleep(unsigned int us)
Definition: fosi.cpp:58
void new_data_listener(base::PortInterface *port)
RTT::corba::CConnPolicy toCORBA(RTT::ConnPolicy const &policy)
#define ASSERT_PORT_SIGNALLING(code, read_port)
#define ORO_MQUEUE_PROTOCOL_ID
Definition: MQLib.hpp:57


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