00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "unit.hpp"
00022
00023 #include <transports/corba/corba.h>
00024 #include <rtt/InputPort.hpp>
00025 #include <rtt/OutputPort.hpp>
00026 #include <rtt/OperationCaller.hpp>
00027 #include <rtt/TaskContext.hpp>
00028 #include <transports/corba/TaskContextServer.hpp>
00029 #include <transports/corba/TaskContextProxy.hpp>
00030 #include <rtt/Service.hpp>
00031 #include <rtt/transports/corba/DataFlowI.h>
00032 #include <rtt/transports/corba/RemotePorts.hpp>
00033 #include <transports/corba/ServiceC.h>
00034 #include <transports/corba/CorbaLib.hpp>
00035
00036 #include "operations_fixture.hpp"
00037
00038 using namespace std;
00039 using corba::TaskContextProxy;
00040
00041 class CorbaTest : public OperationsFixture
00042 {
00043 public:
00044 CorbaTest() :
00045 pint1("pint1", "", 3), pdouble1(new Property<double>("pdouble1", "", -3.0)),
00046 aint1(3), adouble1(-3.0), wait(0)
00047 {
00048
00049 mi1 = new InputPort<double> ("mi");
00050 mo1 = new OutputPort<double> ("mo");
00051
00052 mi2 = new InputPort<double> ("mi");
00053 mo2 = new OutputPort<double> ("mo");
00054
00055 tc->ports()->addPort(*mi1);
00056 tc->ports()->addPort(*mo1);
00057
00058 t2 = new TaskContext("local");
00059 t2->ports()->addPort(*mi2);
00060 t2->ports()->addPort(*mo2);
00061
00062 ts2 = ts = 0;
00063 tp2 = tp = 0;
00064
00065
00066 tc->provides()->addProperty(pint1);
00067 storeProperty(*tc->provides()->properties(), "s1.s2", pdouble1 );
00068
00069 tc->addAttribute("aint1", aint1);
00070 tc->addAttribute("adouble1", adouble1);
00071 }
00072 ~CorbaTest()
00073 {
00074 delete tp;
00075 delete ts;
00076 delete tp2;
00077 delete ts2;
00078 delete t2;
00079
00080 delete mi1;
00081 delete mo1;
00082 delete mi2;
00083 delete mo2;
00084 }
00085
00086 TaskContext* t2;
00087 TaskContext* tp;
00088 corba::TaskContextServer* ts;
00089 TaskContext* tp2;
00090 corba::TaskContextServer* ts2;
00091
00092 base::PortInterface* signalled_port;
00093 void new_data_listener(base::PortInterface* port);
00094
00095
00096 InputPort<double>* mi1;
00097 OutputPort<double>* mo1;
00098 InputPort<double>* mi2;
00099 OutputPort<double>* mo2;
00100
00101 Property<int> pint1;
00102 Property<double>* pdouble1;
00103
00104 int aint1;
00105 double adouble1;
00106 int wait;
00107
00108
00109 void testPortDataConnection();
00110 void testPortBufferConnection();
00111 void testPortDisconnected();
00112 };
00113
00114 void CorbaTest::new_data_listener(base::PortInterface* port)
00115 {
00116 signalled_port = port;
00117 }
00118
00119
00120 #define ASSERT_PORT_SIGNALLING(code, read_port) \
00121 signalled_port = 0; wait = 0;\
00122 code; \
00123 while (read_port != signalled_port && wait++ != 5) \
00124 usleep(100000); \
00125 BOOST_CHECK( read_port == signalled_port );
00126
00127 bool wait_for_helper;
00128 #define wait_for( cond, times ) \
00129 wait = 0; \
00130 while( (wait_for_helper = !(cond)) && wait++ != times ) \
00131 usleep(100000); \
00132 if (wait_for_helper) BOOST_CHECK( cond );
00133
00134 #define wait_for_equal( a, b, times ) \
00135 wait = 0; \
00136 while( (wait_for_helper = ((a) != (b))) && wait++ != times ) \
00137 usleep(100000); \
00138 if (wait_for_helper) BOOST_CHECK_EQUAL( a, b );
00139
00140 void CorbaTest::testPortDataConnection()
00141 {
00142
00143
00144 BOOST_CHECK( mo1->connected() );
00145 BOOST_CHECK( mi2->connected() );
00146
00147 double value = 0;
00148
00149
00150 BOOST_CHECK_EQUAL( mi2->read(value), NoData );
00151
00152
00153 ASSERT_PORT_SIGNALLING(mo1->write(1.0), mi2)
00154 BOOST_CHECK( mi2->read(value) );
00155 BOOST_CHECK_EQUAL( 1.0, value );
00156 ASSERT_PORT_SIGNALLING(mo1->write(2.0), mi2);
00157 BOOST_CHECK( mi2->read(value) );
00158 BOOST_CHECK_EQUAL( 2.0, value );
00159 }
00160
00161 void CorbaTest::testPortBufferConnection()
00162 {
00163
00164
00165 BOOST_CHECK( mo1->connected() );
00166 BOOST_CHECK( mi2->connected() );
00167
00168 double value = 0;
00169
00170
00171 BOOST_CHECK_EQUAL( mi2->read(value), NoData );
00172
00173
00174 ASSERT_PORT_SIGNALLING(mo1->write(1.0), mi2);
00175 ASSERT_PORT_SIGNALLING(mo1->write(2.0), mi2);
00176 ASSERT_PORT_SIGNALLING(mo1->write(3.0), mi2);
00177 BOOST_CHECK( mi2->read(value) );
00178 BOOST_CHECK_EQUAL( 1.0, value );
00179 BOOST_CHECK( mi2->read(value) );
00180 BOOST_CHECK_EQUAL( 2.0, value );
00181 BOOST_CHECK( mi2->read(value) );
00182 BOOST_CHECK_EQUAL( 3.0, value );
00183 BOOST_CHECK_EQUAL( mi2->read(value), OldData );
00184 }
00185
00186 void CorbaTest::testPortDisconnected()
00187 {
00188 BOOST_CHECK( !mo1->connected() );
00189 BOOST_CHECK( !mi2->connected() );
00190 }
00191
00192
00193
00194 BOOST_FIXTURE_TEST_SUITE( CorbaTestSuite, CorbaTest )
00195
00196 BOOST_AUTO_TEST_CASE( testAttributes )
00197 {
00198 ts = corba::TaskContextServer::Create( tc, false );
00199 BOOST_CHECK( ts );
00200 tp = corba::TaskContextProxy::Create( ts->server(), true );
00201 BOOST_CHECK( tp );
00202
00203 BOOST_CHECK( tp->provides()->hasAttribute("aint1") );
00204 Attribute<int> proxy_int = tp->provides()->getAttribute("aint1");
00205 BOOST_REQUIRE( proxy_int.ready() );
00206
00207
00208 BOOST_CHECK_EQUAL( proxy_int.get(), 3);
00209
00210 aint1 = 4;
00211 BOOST_CHECK_EQUAL( proxy_int.set(), 4);
00212
00213 proxy_int.set( 5 );
00214 BOOST_CHECK_EQUAL( aint1, 5);
00215
00216 BOOST_CHECK( tp->provides()->hasAttribute("adouble1") );
00217 Attribute<double> proxy_double = tp->provides()->getAttribute("adouble1");
00218 BOOST_REQUIRE( proxy_double.ready() );
00219
00220
00221 BOOST_CHECK_EQUAL( proxy_double.set(), -3.0 );
00222
00223 proxy_double.set( 5.0 );
00224 BOOST_CHECK_EQUAL( adouble1, 5.0 );
00225 BOOST_CHECK_EQUAL( proxy_double.get(), 5.0);
00226 adouble1 = 6.0;
00227
00228 BOOST_CHECK_EQUAL( proxy_double.get(), 6.0);
00229 }
00230
00231 BOOST_AUTO_TEST_CASE( testProperties )
00232 {
00233 ts = corba::TaskContextServer::Create( tc, false );
00234 BOOST_CHECK( ts );
00235 tp = corba::TaskContextProxy::Create( ts->server(), true );
00236 BOOST_CHECK( tp );
00237
00238 BOOST_CHECK( findProperty( *tp->provides()->properties(), "pint1") );
00239 Property<int> proxy_int = findProperty( *tp->provides()->properties(), "pint1");
00240 BOOST_REQUIRE( proxy_int.ready() );
00241
00242 BOOST_CHECK_EQUAL( proxy_int.get(), 3);
00243
00244 pint1 = 4;
00245 BOOST_CHECK_EQUAL( proxy_int.set(), 4);
00246
00247 proxy_int.set( 5 );
00248 BOOST_CHECK_EQUAL( pint1, 5);
00249
00250 BOOST_CHECK( findProperty( *tp->provides()->properties(), "s1.s2.pdouble1") );
00251 Property<double> proxy_d = findProperty( *tp->provides()->properties(), "s1.s2.pdouble1");
00252 BOOST_REQUIRE( proxy_d.ready() );
00253
00254 BOOST_CHECK_EQUAL( proxy_d.set(), -3.0 );
00255
00256 proxy_d.set( 5.0 );
00257 BOOST_CHECK_EQUAL( pdouble1->get(), 5.0 );
00258 BOOST_CHECK_EQUAL( proxy_d.get(), 5.0);
00259 pdouble1->set( 6.0 );
00260
00261 BOOST_CHECK_EQUAL( proxy_d.get(), 6.0);
00262 }
00263
00264 BOOST_AUTO_TEST_CASE( testOperationCallerC_Call )
00265 {
00266
00267 ts = corba::TaskContextServer::Create( tc, false );
00268 BOOST_CHECK( ts );
00269 tp = corba::TaskContextProxy::Create( ts->server(), true );
00270 BOOST_CHECK( tp );
00271
00272
00273 internal::OperationCallerC mc;
00274 double r = 0.0;
00275 mc = tp->provides("methods")->create("vm0", tc->engine() );
00276 BOOST_CHECK( mc.call() );
00277 BOOST_CHECK( r == 0.0 );
00278
00279 mc = tp->provides("methods")->create("m0", tc->engine() ).ret( r );
00280 BOOST_CHECK( mc.call() );
00281 BOOST_CHECK( r == -1.0 );
00282
00283 mc = tp->provides("methods")->create("m2", tc->engine() ).argC(1).argC(2.0).ret( r );
00284 BOOST_CHECK( mc.call() );
00285 BOOST_CHECK( r == -3.0 );
00286
00287 mc = tp->provides("methods")->create("m3", tc->engine() ).ret( r ).argC(1).argC(2.0).argC(true);
00288 BOOST_CHECK( mc.call() );
00289 BOOST_CHECK( r == -4.0 );
00290
00291 }
00292
00293 BOOST_AUTO_TEST_CASE( testOperationCallerC_Send )
00294 {
00295
00296 ts = corba::TaskContextServer::Create( tc, false );
00297 BOOST_CHECK( ts );
00298 tp = corba::TaskContextProxy::Create( ts->server(), true );
00299 BOOST_CHECK( tp );
00300
00301 OperationCallerC mc;
00302 SendHandleC shc;
00303 double r = 0.0;
00304 double cr = 0.0;
00305 mc = tp->provides("methods")->create("m0", caller->engine()).ret( r );
00306 BOOST_CHECK_NO_THROW( mc.check() );
00307 shc = mc.send();
00308 shc.arg(cr);
00309 BOOST_CHECK( shc.ready() );
00310 BOOST_CHECK_NO_THROW( shc.check() );
00311
00312 BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
00313 BOOST_CHECK_EQUAL( r, 0.0 );
00314 BOOST_CHECK_EQUAL( cr, -1.0 );
00315
00316 mc = tp->provides("methods")->create("m2", caller->engine()).argC(1).argC(2.0).ret( r );
00317 BOOST_CHECK_NO_THROW( mc.check() );
00318 shc = mc.send();
00319 shc.arg(cr);
00320 BOOST_CHECK( shc.ready() );
00321 BOOST_CHECK_NO_THROW( shc.check() );
00322
00323 BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
00324 BOOST_CHECK_EQUAL( r, 0.0 );
00325 BOOST_CHECK_EQUAL( cr, -3.0 );
00326
00327 mc = tp->provides("methods")->create("m3", caller->engine()).ret( r ).argC(1).argC(2.0).argC(true);
00328 BOOST_CHECK_NO_THROW( mc.check() );
00329 shc = mc.send();
00330 shc.arg(cr);
00331 BOOST_CHECK( shc.ready() );
00332 BOOST_CHECK_NO_THROW( shc.check() );
00333
00334 BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
00335 BOOST_CHECK_EQUAL( r, 0.0 );
00336 BOOST_CHECK_EQUAL( cr, -4.0 );
00337
00338 mc = tp->provides("methods")->create("m4", caller->engine()).ret( r ).argC(1).argC(2.0).argC(true).argC(string("hello"));
00339 BOOST_CHECK_NO_THROW( mc.check() );
00340 shc = mc.send();
00341 shc.arg(cr);
00342 BOOST_CHECK( shc.ready() );
00343 BOOST_CHECK_NO_THROW( shc.check() );
00344
00345 BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
00346 BOOST_CHECK_EQUAL( r, 0.0 );
00347 BOOST_CHECK_EQUAL( cr, -5.0 );
00348 }
00349
00350 BOOST_AUTO_TEST_CASE( testRemoteOperationCallerCall )
00351 {
00352
00353 ts = corba::TaskContextServer::Create( tc, false );
00354 tp = corba::TaskContextProxy::Create( ts->server(), true );
00355
00356
00357
00358 RTT::OperationCaller<double(void)> m0 = tp->provides("methods")->getOperation("m0");
00359 RTT::OperationCaller<double(int)> m1 = tp->provides("methods")->getOperation("m1");
00360 RTT::OperationCaller<double(int,double)> m2 = tp->provides("methods")->getOperation("m2");
00361 RTT::OperationCaller<double(int,double,bool)> m3 = tp->provides("methods")->getOperation("m3");
00362 RTT::OperationCaller<double(int,double,bool,std::string)> m4 = tp->provides("methods")->getOperation("m4");
00363
00364 BOOST_CHECK_EQUAL( -1.0, m0() );
00365 BOOST_CHECK_EQUAL( -2.0, m1(1) );
00366 BOOST_CHECK_EQUAL( -3.0, m2(1, 2.0) );
00367 BOOST_CHECK_EQUAL( -4.0, m3(1, 2.0, true) );
00368 BOOST_CHECK_EQUAL( -5.0, m4(1, 2.0, true,"hello") );
00369 }
00370
00371 BOOST_AUTO_TEST_CASE( testAnyOperationCaller )
00372 {
00373 double d;
00374
00375 ts = corba::TaskContextServer::Create( tc, false );
00376 tp = corba::TaskContextProxy::Create( ts->server() , true);
00377
00378
00379 corba::CService_var co = ts->server()->getProvider("methods");
00380 BOOST_CHECK( co.in() );
00381
00382 corba::CAnyArguments_var any_args = new corba::CAnyArguments(0);
00383 CORBA::Any_var vm0 = co->callOperation("vm0", any_args.inout() );
00384
00385
00386 CORBA::Any_var m0 = co->callOperation("m0", any_args.inout());
00387 BOOST_CHECK( m0 >>= d );
00388 BOOST_CHECK_EQUAL(d, -1.0 );
00389
00390 any_args = new corba::CAnyArguments(1);
00391 any_args->length(1);
00392 unsigned int index = 0;
00393 any_args[index] <<= (CORBA::Long) 1;
00394 CORBA::Any_var m1;
00395 BOOST_CHECK_NO_THROW( m1 = co->callOperation("m1", any_args.inout()));
00396 BOOST_CHECK( m1 >>= d );
00397 BOOST_CHECK_EQUAL(d, -2.0 );
00398
00399
00400 any_args = new corba::CAnyArguments(2);
00401 any_args->length(2);
00402 index = 0;
00403 any_args[index] <<= (CORBA::Long) 1;
00404 ++index;
00405 any_args[index] <<= (CORBA::Double) 2.0;
00406 CORBA::Any_var m2;
00407 BOOST_CHECK_NO_THROW( m2 = co->callOperation("m2", any_args.inout()));
00408 BOOST_CHECK( m2 >>= d );
00409 BOOST_CHECK_EQUAL(d, -3.0 );
00410
00411 any_args = new corba::CAnyArguments(3);
00412 any_args->length(3);
00413 index = 0;
00414 any_args[index] <<= (CORBA::Long) 1;
00415 ++index;
00416 any_args[index] <<= (CORBA::Double) 2.0;
00417 ++index;
00418 any_args[index] <<= CORBA::Any::from_boolean( true );
00419 CORBA::Any_var m3;
00420 BOOST_CHECK_NO_THROW( m3= co->callOperation("m3", any_args.inout()) );
00421 BOOST_CHECK( m3 >>= d );
00422 BOOST_CHECK_EQUAL(d, -4.0 );
00423
00424 any_args = new corba::CAnyArguments(4);
00425 any_args->length(4);
00426 index = 0;
00427 any_args[index] <<= (CORBA::Long) 1;
00428 ++index;
00429 any_args[index] <<= (CORBA::Double) 2.0;
00430 ++index;
00431 any_args[index] <<= CORBA::Any::from_boolean( true );
00432 ++index;
00433 any_args[index] <<= "hello";
00434 CORBA::Any_var m4;
00435 BOOST_CHECK_NO_THROW ( m4 = co->callOperation("m4", any_args.inout()) );
00436 BOOST_CHECK( m4 >>= d );
00437 BOOST_CHECK_EQUAL(d, -5.0 );
00438
00439 }
00440
00441 BOOST_AUTO_TEST_CASE(testDataFlowInterface)
00442 {
00443 ts = corba::TaskContextServer::Create( tc, false );
00444
00445 corba::CDataFlowInterface_var ports = ts->server()->ports();
00446
00447 corba::CDataFlowInterface::CPortNames_var names =
00448 ports->getPorts();
00449
00450 BOOST_CHECK_EQUAL(CORBA::ULong(2), names->length());
00451 BOOST_CHECK_EQUAL(string("mi"), string(names[CORBA::ULong(0)]));
00452 BOOST_CHECK_EQUAL(string("mo"), string(names[CORBA::ULong(1)]));
00453
00454
00455 BOOST_CHECK_EQUAL(RTT::corba::COutput,
00456 ports->getPortType("mo"));
00457 BOOST_CHECK_EQUAL(RTT::corba::CInput,
00458 ports->getPortType("mi"));
00459
00460
00461 CORBA::String_var cstr = ports->getDataType("mo");
00462 BOOST_CHECK_EQUAL(string("double"),
00463 string(cstr.in()));
00464 }
00465
00466 BOOST_AUTO_TEST_CASE( testPortConnections )
00467 {
00468
00469 ts = corba::TaskContextServer::Create( tc, false );
00470 ts2 = corba::TaskContextServer::Create( t2, false );
00471
00472
00473 RTT::corba::CConnPolicy policy;
00474 policy.type = RTT::corba::CData;
00475 policy.init = false;
00476 policy.lock_policy = RTT::corba::CLockFree;
00477 policy.size = 0;
00478 policy.transport = ORO_CORBA_PROTOCOL_ID;
00479
00480
00481 Handle hl( mi2->getNewDataOnPortEvent()->setup(
00482 boost::bind(&CorbaTest::new_data_listener, this, _1) ) );
00483 hl.connect();
00484
00485 corba::CDataFlowInterface_var ports = ts->server()->ports();
00486 corba::CDataFlowInterface_var ports2 = ts2->server()->ports();
00487
00488
00489 BOOST_CHECK_THROW( ports->createConnection("mo", ports2, "does_not_exist", policy), CNoSuchPortException );
00490 BOOST_CHECK_THROW( ports->createConnection("does_not_exist", ports2, "mi", policy), CNoSuchPortException );
00491 BOOST_CHECK_THROW( ports->createConnection("does_not_exist", ports2, "does_not_exist", policy), CNoSuchPortException );
00492 BOOST_CHECK_THROW( ports->createConnection("mo", ports2, "mo", policy), CNoSuchPortException );
00493 BOOST_CHECK_THROW( ports->createConnection("mi", ports2, "mi", policy), CNoSuchPortException );
00494 BOOST_CHECK_THROW( ports->createConnection("mi", ports2, "mo", policy), CNoSuchPortException );
00495
00496
00497
00498
00499
00500 policy.type = RTT::corba::CData;
00501 policy.pull = false;
00502 BOOST_CHECK( ports->createConnection("mo", ports2, "mi", policy) );
00503 testPortDataConnection();
00504 ports->disconnectPort("mo");
00505 testPortDisconnected();
00506
00507 policy.type = RTT::corba::CData;
00508 policy.pull = true;
00509 BOOST_CHECK( ports->createConnection("mo", ports2, "mi", policy) );
00510 testPortDataConnection();
00511 ports2->disconnectPort("mi");
00512 testPortDisconnected();
00513
00514 policy.type = RTT::corba::CBuffer;
00515 policy.pull = false;
00516 policy.size = 3;
00517 BOOST_CHECK( ports->createConnection("mo", ports2, "mi", policy) );
00518 testPortBufferConnection();
00519 ports->disconnectPort("mo");
00520 testPortDisconnected();
00521
00522 policy.type = RTT::corba::CBuffer;
00523 policy.pull = true;
00524 BOOST_CHECK( ports->createConnection("mo", ports2, "mi", policy) );
00525 testPortBufferConnection();
00526
00527
00528 mo1->createConnection(*mi1);
00529
00530 ports->removeConnection("mo", ports2, "mi");
00531
00532 BOOST_CHECK(mo1->connected());
00533 BOOST_CHECK(mi1->connected());
00534 BOOST_CHECK(!mi2->connected());
00535 }
00536
00537 BOOST_AUTO_TEST_CASE( testPortProxying )
00538 {
00539 ts = corba::TaskContextServer::Create( tc, false );
00540 tp = corba::TaskContextProxy::Create( ts->server(), true );
00541 ts2 = corba::TaskContextServer::Create( t2, false );
00542 tp2 = corba::TaskContextProxy::Create( ts2->server(), true );
00543
00544 base::PortInterface* untyped_port;
00545
00546 untyped_port = tp->ports()->getPort("mi");
00547 BOOST_CHECK(untyped_port);
00548 base::InputPortInterface* read_port = dynamic_cast<base::InputPortInterface*>(tp->ports()->getPort("mi"));
00549 BOOST_CHECK(read_port);
00550
00551 untyped_port = tp->ports()->getPort("mi");
00552 BOOST_CHECK(untyped_port);
00553 base::OutputPortInterface* write_port = dynamic_cast<base::OutputPortInterface*>(tp2->ports()->getPort("mo"));
00554 BOOST_CHECK(write_port);
00555
00556
00557
00558 BOOST_CHECK(dynamic_cast<corba::RemoteInputPort*>(read_port));
00559 BOOST_CHECK(dynamic_cast<corba::RemoteOutputPort*>(write_port));
00560
00561 BOOST_CHECK(!read_port->connected());
00562 BOOST_CHECK(read_port->getTypeInfo() == mi1->getTypeInfo());
00563 BOOST_CHECK(!write_port->connected());
00564 BOOST_CHECK(write_port->getTypeInfo() == mo2->getTypeInfo());
00565
00566 mo2->createConnection(*read_port);
00567 BOOST_CHECK(read_port->connected());
00568 BOOST_CHECK(write_port->connected());
00569 read_port->disconnect();
00570 BOOST_CHECK(!read_port->connected());
00571 BOOST_CHECK(!write_port->connected());
00572
00573 mo2->createConnection(*read_port);
00574 BOOST_CHECK(read_port->connected());
00575 BOOST_CHECK(write_port->connected());
00576 write_port->disconnect();
00577 BOOST_CHECK(!read_port->connected());
00578 BOOST_CHECK(!write_port->connected());
00579
00580
00581 auto_ptr<base::InputPortInterface> read_clone(dynamic_cast<base::InputPortInterface*>(read_port->clone()));
00582 BOOST_CHECK(mo2->createConnection(*read_clone));
00583 BOOST_CHECK(read_clone->connected());
00584 BOOST_CHECK(!read_port->connected());
00585 mo2->disconnect();
00586 }
00587
00588 BOOST_AUTO_TEST_CASE( testDataHalfs )
00589 {
00590 double result;
00591
00592 ts = corba::TaskContextServer::Create( tc, false );
00593
00594
00595 RTT::corba::CConnPolicy policy;
00596 policy.type = RTT::corba::CData;
00597 policy.init = false;
00598 policy.lock_policy = RTT::corba::CLockFree;
00599 policy.size = 0;
00600 policy.transport = ORO_CORBA_PROTOCOL_ID;
00601
00602
00603 Handle hl( mi1->getNewDataOnPortEvent()->setup(
00604 boost::bind(&CorbaTest::new_data_listener, this, _1) ) );
00605 BOOST_CHECK( hl.connect() );
00606
00607 corba::CDataFlowInterface_var ports = ts->server()->ports();
00608 BOOST_REQUIRE( ports.in() );
00609
00610
00611 policy.pull = false;
00612 CChannelElement_var cce = ports->buildChannelInput("mo", policy);
00613 CORBA::Any_var sample = new CORBA::Any();
00614 BOOST_REQUIRE( cce.in() );
00615
00616 BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), CNoData );
00617
00618 mo1->write( 3.33 );
00619 BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), CNewData );
00620 sample >>= result;
00621 BOOST_CHECK_EQUAL( result, 3.33);
00622
00623
00624 sample <<= 0.0;
00625 BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), COldData );
00626 sample >>= result;
00627 BOOST_CHECK_EQUAL( result, 3.33);
00628
00629 cce->disconnect();
00630
00631
00632 cce = ports->buildChannelOutput("mi", policy);
00633 ports->channelReady("mi", cce);
00634 sample = new CORBA::Any();
00635 BOOST_REQUIRE( cce.in() );
00636
00637
00638 result = 0.0;
00639 sample <<= 4.44;
00640 cce->write( sample.in() );
00641 BOOST_CHECK_EQUAL( mi1->read( result ), NewData );
00642 BOOST_CHECK_EQUAL( result, 4.44 );
00643
00644
00645 result = 0.0;
00646 BOOST_CHECK_EQUAL( mi1->read( result ), OldData );
00647 BOOST_CHECK_EQUAL( result, 4.44);
00648 }
00649
00650 BOOST_AUTO_TEST_CASE( testBufferHalfs )
00651 {
00652 double result;
00653
00654 ts = corba::TaskContextServer::Create( tc, false );
00655
00656
00657 RTT::corba::CConnPolicy policy;
00658 policy.type = RTT::corba::CBuffer;
00659 policy.init = false;
00660 policy.lock_policy = RTT::corba::CLockFree;
00661 policy.size = 10;
00662 policy.transport = ORO_CORBA_PROTOCOL_ID;
00663
00664
00665 Handle hl( mi1->getNewDataOnPortEvent()->setup(
00666 boost::bind(&CorbaTest::new_data_listener, this, _1) ) );
00667 BOOST_CHECK( hl.connect() );
00668
00669 corba::CDataFlowInterface_var ports = ts->server()->ports();
00670 BOOST_REQUIRE( ports.in() );
00671
00672
00673 policy.pull = false;
00674 CChannelElement_var cce = ports->buildChannelInput("mo", policy);
00675 CORBA::Any_var sample = new CORBA::Any();
00676 BOOST_REQUIRE( cce.in() );
00677
00678 BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), CNoData );
00679
00680 mo1->write( 6.33 );
00681 mo1->write( 3.33 );
00682 BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), CNewData );
00683 sample >>= result;
00684 BOOST_CHECK_EQUAL( result, 6.33);
00685 BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), CNewData );
00686 sample >>= result;
00687 BOOST_CHECK_EQUAL( result, 3.33);
00688
00689
00690 sample <<= 0.0;
00691 BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), COldData );
00692 sample >>= result;
00693 BOOST_CHECK_EQUAL( result, 3.33);
00694
00695 cce->disconnect();
00696
00697
00698 cce = ports->buildChannelOutput("mi", policy);
00699 ports->channelReady("mi", cce);
00700 sample = new CORBA::Any();
00701 BOOST_REQUIRE( cce.in() );
00702
00703
00704 result = 0.0;
00705 sample <<= 6.44;
00706 cce->write( sample.in() );
00707 sample <<= 4.44;
00708 cce->write( sample.in() );
00709 BOOST_CHECK_EQUAL( mi1->read( result ), NewData );
00710 BOOST_CHECK_EQUAL( result, 6.44 );
00711 BOOST_CHECK_EQUAL( mi1->read( result ), NewData );
00712 BOOST_CHECK_EQUAL( result, 4.44 );
00713
00714
00715 result = 0.0;
00716 BOOST_CHECK_EQUAL( mi1->read( result ), OldData );
00717 BOOST_CHECK_EQUAL( result, 4.44);
00718 }
00719
00720 BOOST_AUTO_TEST_SUITE_END()
00721