28 #include <transports/corba/ServiceC.h> 66 enum { INITIAL, CALL,
SEND, FINAL } callBackPeer_step;
74 void testPortDataConnection();
75 void testPortBufferConnection();
76 void testPortDisconnected();
81 int count = ++callBackPeer_count;
83 if (callBackPeer_step == INITIAL) {
86 callBackPeer_step = CALL;
89 log(
Info) <<
"Test executes callBackPeer():"<< count <<
endlog();
90 if (callBackPeer_step == CALL) {
91 callBackPeer_step = SEND;
93 op1(tc,
"callBackPeer");
96 else if (callBackPeer_step == SEND) {
97 callBackPeer_step = FINAL;
99 handle = op1.send(tc,
"callBackPeerOwn");
100 log(
Info) <<
"Test finishes server send:"<< count <<
endlog();
102 log(
Info) <<
"Test finishes callBackPeer():"<< count <<
endlog();
119 tc->ports()->addPort( *mo );
124 callBackPeer_count = 0;
125 callBackPeer_step = INITIAL;
148 signalled_port = port;
152 #define ASSERT_PORT_SIGNALLING(code, read_port) do { \ 153 signalled_port = 0; \ 156 while (read_port != signalled_port && wait++ != 5) \ 158 BOOST_CHECK( read_port == signalled_port ); \ 161 #define wait_for( cond, times ) do { \ 162 bool wait_for_helper; \ 164 while( (wait_for_helper = !(cond)) && wait++ != times ) \ 166 if (wait_for_helper) BOOST_CHECK( cond ); \ 169 #define wait_for_equal( a, b, times ) do { \ 170 bool wait_for_helper; \ 172 while( (wait_for_helper = ((a) != (b))) && wait++ != times ) \ 174 if (wait_for_helper) BOOST_CHECK_EQUAL( a, b ); \ 181 BOOST_CHECK( mo->connected() );
182 BOOST_CHECK( mi->connected() );
187 BOOST_CHECK_EQUAL( mi->read(value),
NoData );
191 BOOST_CHECK( mi->read(value) );
192 BOOST_CHECK_EQUAL( 1.0, value );
194 BOOST_CHECK( mi->read(value) );
195 BOOST_CHECK_EQUAL( 2.0, value );
202 BOOST_CHECK( mo->connected() );
203 BOOST_CHECK( mi->connected() );
208 BOOST_CHECK_EQUAL( mi->read(value),
NoData );
215 BOOST_CHECK( mi->read(value) );
216 BOOST_CHECK_EQUAL( 1.0, value );
217 BOOST_CHECK( mi->read(value) );
218 BOOST_CHECK_EQUAL( 2.0, value );
219 BOOST_CHECK( mi->read(value) );
220 BOOST_CHECK_EQUAL( 3.0, value );
221 BOOST_CHECK_EQUAL( mi->read(value),
OldData );
226 BOOST_CHECK( !mo->connected() );
227 BOOST_CHECK( !mi->connected() );
245 mc = tp->provides(
"methods")->create(
"vm0", tc->engine() );
246 BOOST_CHECK( mc.
call() );
247 BOOST_CHECK( r == 0.0 );
249 mc = tp->provides(
"methods")->create(
"m0", tc->engine() ).ret( r );
250 BOOST_CHECK( mc.
call() );
251 BOOST_CHECK( r == -1.0 );
253 mc = tp->provides(
"methods")->create(
"m2", tc->engine()).argC(1).
argC(2.0).
ret( r );
254 BOOST_CHECK( mc.
call() );
255 BOOST_CHECK( r == -3.0 );
257 mc = tp->provides(
"methods")->create(
"m3", tc->engine()).ret( r ).
argC(1).
argC(2.0).
argC(
true);
258 BOOST_CHECK( mc.
call() );
259 BOOST_CHECK( r == -4.0 );
277 BOOST_CHECK_EQUAL( -1.0, m0() );
278 BOOST_CHECK_EQUAL( -2.0, m1(1) );
279 BOOST_CHECK_EQUAL( -3.0, m2(1, 2.0) );
280 BOOST_CHECK_EQUAL( -4.0, m3(1, 2.0,
true) );
281 BOOST_CHECK_EQUAL( -5.0, m4(1, 2.0,
true,
"hello") );
299 BOOST_REQUIRE_EQUAL( (
int) callBackPeer_step, (
int) INITIAL );
300 this->callBackPeer(tp,
"callBackPeer");
302 BOOST_CHECK_EQUAL( (
int) callBackPeer_step, (
int) FINAL );
303 BOOST_CHECK_EQUAL( callBackPeer_count, 3 );
304 BOOST_CHECK( handle.ready() );
305 BOOST_CHECK_EQUAL( handle.collectIfDone(),
SendSuccess );
319 corba::CService_var co = s->getProvider(
"methods");
320 BOOST_CHECK( co.in() );
322 corba::CAnyArguments_var any_args =
new corba::CAnyArguments(0);
323 CORBA::Any_var vm0 = co->callOperation(
"vm0", any_args.inout() );
326 CORBA::Any_var m0 = co->callOperation(
"m0", any_args.inout());
327 BOOST_CHECK( m0 >>= d );
328 BOOST_CHECK_EQUAL(d, -1.0 );
330 any_args =
new corba::CAnyArguments(1);
332 unsigned int index = 0;
333 any_args[index] <<= (CORBA::Long) 1;
335 BOOST_CHECK_NO_THROW( m1 = co->callOperation(
"m1", any_args.inout()));
336 BOOST_CHECK( m1 >>= d );
337 BOOST_CHECK_EQUAL(d, -2.0 );
340 any_args =
new corba::CAnyArguments(2);
343 any_args[index] <<= (CORBA::Long) 1;
345 any_args[index] <<= (CORBA::Double) 2.0;
347 BOOST_CHECK_NO_THROW( m2 = co->callOperation(
"m2", any_args.inout()));
348 BOOST_CHECK( m2 >>= d );
349 BOOST_CHECK_EQUAL(d, -3.0 );
351 any_args =
new corba::CAnyArguments(3);
354 any_args[index] <<= (CORBA::Long) 1;
356 any_args[index] <<= (CORBA::Double) 2.0;
358 any_args[index] <<= CORBA::Any::from_boolean(
true );
360 BOOST_CHECK_NO_THROW( m3= co->callOperation(
"m3", any_args.inout()) );
361 BOOST_CHECK( m3 >>= d );
362 BOOST_CHECK_EQUAL(d, -4.0 );
364 any_args =
new corba::CAnyArguments(4);
367 any_args[index] <<= (CORBA::Long) 1;
369 any_args[index] <<= (CORBA::Double) 2.0;
371 any_args[index] <<= CORBA::Any::from_boolean(
true );
373 any_args[index] <<=
"hello";
375 BOOST_CHECK_NO_THROW ( m4 = co->callOperation(
"m4", any_args.inout()) );
376 BOOST_CHECK( m4 >>= d );
377 BOOST_CHECK_EQUAL(d, -5.0 );
387 corba::CDataFlowInterface_var ports = tp->server()->ports();
389 corba::CDataFlowInterface::CPortNames_var names =
392 BOOST_CHECK_EQUAL(CORBA::ULong(2), names->length());
393 BOOST_CHECK_EQUAL(
string(
"mi"),
string(names[CORBA::ULong(0)]));
394 BOOST_CHECK_EQUAL(
string(
"mo"),
string(names[CORBA::ULong(1)]));
397 BOOST_CHECK_EQUAL(RTT::corba::COutput,
398 ports->getPortType(
"mo"));
399 BOOST_CHECK_EQUAL(RTT::corba::CInput,
400 ports->getPortType(
"mi"));
403 CORBA::String_var cstr = ports->getDataType(
"mo");
404 BOOST_CHECK_EQUAL(
string(
"double"),
427 corba::CDataFlowInterface_var ports = s->ports();
428 corba::CDataFlowInterface_var ports2 = s2->ports();
431 BOOST_CHECK_THROW( ports->createConnection(
"mo", ports2,
"does_not_exist", policy), CNoSuchPortException );
432 BOOST_CHECK_THROW( ports->createConnection(
"does_not_exist", ports2,
"mi", policy), CNoSuchPortException );
433 BOOST_CHECK_THROW( ports->createConnection(
"does_not_exist", ports2,
"does_not_exist", policy), CNoSuchPortException );
434 BOOST_CHECK_THROW( ports->createConnection(
"mo", ports2,
"mo", policy), CNoSuchPortException );
435 BOOST_CHECK_THROW( ports->createConnection(
"mi", ports2,
"mi", policy), CNoSuchPortException );
436 BOOST_CHECK_THROW( ports->createConnection(
"mi", ports2,
"mo", policy), CNoSuchPortException );
439 BOOST_CHECK( tc->start() );
446 policy.type = RTT::corba::CData;
448 BOOST_CHECK( ports->createConnection(
"mo", ports2,
"mi", policy) );
449 BOOST_CHECK( ports2->createConnection(
"mo", ports,
"mi", policy) );
450 testPortDataConnection();
451 ports->disconnectPort(
"mo");
452 ports->disconnectPort(
"mi");
453 testPortDisconnected();
457 policy.type = RTT::corba::CData;
459 BOOST_CHECK( ports2->createConnection(
"mo", ports,
"mi", policy) );
460 BOOST_CHECK( ports2->createConnection(
"mo", ports,
"mi", policy) );
461 testPortDataConnection();
462 ports2->disconnectPort(
"mi");
463 ports2->disconnectPort(
"mo");
464 testPortDisconnected();
466 policy.type = RTT::corba::CBuffer;
469 BOOST_CHECK( ports->createConnection(
"mo", ports2,
"mi", policy) );
470 BOOST_CHECK( ports2->createConnection(
"mo", ports,
"mi", policy) );
471 testPortBufferConnection();
472 ports->disconnectPort(
"mo");
473 ports->disconnectPort(
"mi");
474 testPortDisconnected();
476 policy.type = RTT::corba::CBuffer;
478 BOOST_CHECK( ports->createConnection(
"mo", ports2,
"mi", policy) );
479 BOOST_CHECK( ports2->createConnection(
"mo", ports,
"mi", policy) );
480 testPortBufferConnection();
481 ports2->disconnectPort(
"mo");
482 ports2->disconnectPort(
"mi");
483 testPortDisconnected();
488 mo->createConnection(*mi);
490 ports->removeConnection(
"mo", ports2,
"mi");
491 ports->removeConnection(
"mi", ports2,
"mo");
493 BOOST_CHECK(mo->connected());
494 BOOST_CHECK(mi->connected());
495 BOOST_CHECK(!mi->connected());
510 untyped_port = tp->ports()->getPort(
"mi");
511 BOOST_CHECK(untyped_port);
513 BOOST_CHECK(read_port);
515 untyped_port = tp->ports()->getPort(
"mo");
516 BOOST_CHECK(untyped_port);
518 BOOST_CHECK(write_port);
522 BOOST_CHECK(dynamic_cast<corba::RemoteInputPort*>(read_port));
523 BOOST_CHECK(dynamic_cast<corba::RemoteOutputPort*>(write_port));
526 BOOST_CHECK(read_port->
getTypeInfo() == mi->getTypeInfo());
528 BOOST_CHECK(write_port->
getTypeInfo() == mo->getTypeInfo());
530 mo->createConnection(*read_port);
542 mo->createConnection(*read_port);
552 #if __cplusplus > 199711L 553 unique_ptr<base::InputPortInterface>
555 auto_ptr<base::InputPortInterface>
557 read_clone(dynamic_cast<base::InputPortInterface*>(read_port->
clone()));
558 BOOST_CHECK(mo->createConnection(*read_clone));
559 BOOST_CHECK(read_clone->connected());
566 if(std::getenv(
"CI") != NULL) {
567 BOOST_TEST_MESSAGE(
"Skipping testDataHalfs because it can fail on integration servers.");
586 corba::CDataFlowInterface_var ports = s->ports();
587 BOOST_REQUIRE( ports.in() );
591 mo->connectTo( tp->ports()->getPort(
"mi"),
toRTT(policy) );
592 CChannelElement_var cce = ports->buildChannelInput(
"mo", policy);
593 CORBA::Any_var sample;
594 BOOST_REQUIRE( cce.in() );
600 BOOST_CHECK_EQUAL( result, 3.33);
604 BOOST_CHECK_EQUAL( cce->read( sample.out(),
true), COldData );
606 BOOST_CHECK_EQUAL( result, 3.33);
612 cce = ports->buildChannelOutput(
"mi", policy);
613 cce->channelReady(policy);
615 mi->connectTo( tp->ports()->getPort(
"mo"),
toRTT(policy) );
616 sample =
new CORBA::Any();
617 BOOST_REQUIRE( cce.in() );
622 cce->write( sample.in() );
624 BOOST_CHECK_EQUAL( result, 4.44 );
628 BOOST_CHECK_EQUAL( mi->read( result ),
OldData );
629 BOOST_CHECK_EQUAL( result, 4.44);
634 if(std::getenv(
"CI") != NULL) {
635 BOOST_TEST_MESSAGE(
"Skipping testBufferHalfs because it can fail on integration servers.");
655 corba::CDataFlowInterface_var ports = s->ports();
656 BOOST_REQUIRE( ports.in() );
660 mo->connectTo( tp->ports()->getPort(
"mi"),
toRTT(policy) );
661 CChannelElement_var cce = ports->buildChannelInput(
"mo", policy);
662 CORBA::Any_var sample;
663 BOOST_REQUIRE( cce.in() );
670 #ifndef RTT_CORBA_PORTS_WRITE_ONEWAY 671 BOOST_CHECK_EQUAL( result, 6.33);
673 BOOST_CHECK( (result == 6.33) || (result == 3.33) );
677 #ifndef RTT_CORBA_PORTS_WRITE_ONEWAY 678 BOOST_CHECK_EQUAL( result, 3.33);
680 BOOST_CHECK( (result == 6.33) || (result == 3.33) );
685 BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), COldData );
687 #ifndef RTT_CORBA_PORTS_WRITE_ONEWAY 688 BOOST_CHECK_EQUAL( result, 3.33);
690 BOOST_CHECK( (result == 6.33) || (result == 3.33) );
697 mi->connectTo( tp->ports()->getPort(
"mo"),
toRTT(policy) );
698 cce = ports->buildChannelOutput(
"mi", policy);
699 cce->channelReady(policy);
700 sample =
new CORBA::Any();
701 BOOST_REQUIRE( cce.in() );
706 cce->write( sample.in() );
708 cce->write( sample.in() );
710 BOOST_CHECK_EQUAL( result, 6.44 );
712 BOOST_CHECK_EQUAL( result, 4.44 );
716 BOOST_CHECK_EQUAL( mi->read( result ),
OldData );
717 BOOST_CHECK_EQUAL( result, 4.44);
virtual PortInterface * clone() const =0
static ConnPolicy data(int lock_policy=LOCK_FREE, bool init_connection=true, bool pull=false)
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
void new_data_listener(base::PortInterface *port)
virtual const types::TypeInfo * getTypeInfo() const =0
#define wait_for_equal(a, b, times)
#define ASSERT_PORT_SIGNALLING(code, read_port)
BOOST_AUTO_TEST_CASE(testRemoteOperationCallerC)
void callBackPeer(TaskContext *peer, string const &opname)
void testPortDisconnected()
#define BOOST_AUTO_TEST_SUITE_END()
SendHandle< void(TaskContext *, string const &)> handle
RTT::ConnPolicy toRTT(RTT::corba::CConnPolicy const &corba_policy)
static TaskContextServer * Create(TaskContext *tc, bool use_naming=true, bool require_name_service=false)
OutputPort< double > * mo
static TaskContextProxy * CreateFromFile(std::string filename)
bool createConnection(InputPortInterface &sink)
static ConnPolicy buffer(int size, int lock_policy=LOCK_FREE, bool init_connection=false, bool pull=false)
virtual bool connected() const
void testPortBufferConnection()
OperationCallerC & ret(base::AttributeBase *r)
unsigned int sleep(unsigned int s)
RTT::corba::CConnPolicy toCORBA(RTT::ConnPolicy const &policy)
OperationInterfacePart * getOperation(std::string name)
#define ORO_CORBA_PROTOCOL_ID
virtual void disconnect()
corba::TaskContextServer * ts
OperationCallerC & argC(const ArgT a)
corba::TaskContextServer * ts2
void testPortDataConnection()
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
base::PortInterface * signalled_port
static TaskContextProxy * Create(std::string name, bool is_ior=false)
const ExecutionEngine * engine() const
static Logger::LogFunction endlog()