-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcorba_test.cpp
726 lines (605 loc) · 24.5 KB
/
corba_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
/***************************************************************************
tag: Peter Soetens Mon Jun 26 13:26:02 CEST 2006 generictask_test.cpp
generictask_test.cpp - description
-------------------
begin : Mon June 26 2006
copyright : (C) 2006 Peter Soetens
email : [email protected]
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "unit.hpp"
#include <transports/corba/corba.h>
#include <rtt/InputPort.hpp>
#include <rtt/OutputPort.hpp>
#include <rtt/OperationCaller.hpp>
#include <rtt/TaskContext.hpp>
#include <transports/corba/TaskContextServer.hpp>
#include <transports/corba/TaskContextProxy.hpp>
#include <rtt/Service.hpp>
#include <rtt/transports/corba/DataFlowI.h>
#include <rtt/transports/corba/RemotePorts.hpp>
#include <transports/corba/ServiceC.h>
#include <transports/corba/CorbaLib.hpp>
#include "operations_fixture.hpp"
using namespace std;
using corba::TaskContextProxy;
class CorbaTest : public OperationsFixture
{
public:
CorbaTest() :
pint1("pint1", "", 3), pdouble1(new Property<double>("pdouble1", "", -3.0)),
aint1(3), adouble1(-3.0), wait(0)
{
// connect DataPorts
mi1 = new InputPort<double> ("mi");
mo1 = new OutputPort<double> ("mo");
mi2 = new InputPort<double> ("mi");
mo2 = new OutputPort<double> ("mo");
tc->ports()->addEventPort(*mi1);
tc->ports()->addPort(*mo1);
t2 = new TaskContext("local");
t2->ports()->addEventPort(*mi2,boost::bind(&CorbaTest::new_data_listener, this, _1));
t2->ports()->addPort(*mo2);
ts2 = ts = 0;
tp2 = tp = 0;
// store nested properties:
tc->provides()->addProperty(pint1);
storeProperty(*tc->provides()->properties(), "s1.s2", pdouble1 );
tc->addAttribute("aint1", aint1);
tc->addAttribute("adouble1", adouble1);
}
~CorbaTest()
{
delete tp;
delete ts;
delete tp2;
delete ts2;
delete t2;
delete mi1;
delete mo1;
delete mi2;
delete mo2;
}
TaskContext* t2;
TaskContext* tp;
corba::TaskContextServer* ts;
TaskContext* tp2;
corba::TaskContextServer* ts2;
base::PortInterface* signalled_port;
void new_data_listener(base::PortInterface* port);
// Ports
InputPort<double>* mi1;
OutputPort<double>* mo1;
InputPort<double>* mi2;
OutputPort<double>* mo2;
Property<int> pint1;
Property<double>* pdouble1;
int aint1;
double adouble1;
int wait;
// helper test functions
void testPortDataConnection();
void testPortBufferConnection();
void testPortDisconnected();
};
void CorbaTest::new_data_listener(base::PortInterface* port)
{
signalled_port = port;
}
#define ASSERT_PORT_SIGNALLING(code, read_port) \
signalled_port = 0; wait = 0;\
code; \
while (read_port != signalled_port && wait++ != 5) \
usleep(100000); \
BOOST_CHECK( read_port == signalled_port );
bool wait_for_helper;
#define wait_for( cond, times ) \
wait = 0; \
while( (wait_for_helper = !(cond)) && wait++ != times ) \
usleep(100000); \
if (wait_for_helper) BOOST_CHECK( cond );
#define wait_for_equal( a, b, times ) \
wait = 0; \
while( (wait_for_helper = ((a) != (b))) && wait++ != times ) \
usleep(100000); \
if (wait_for_helper) BOOST_CHECK_EQUAL( a, b );
void CorbaTest::testPortDataConnection()
{
// This test assumes that there is a data connection mo1 => mi2
// Check if connection succeeded both ways:
BOOST_CHECK( mo1->connected() );
BOOST_CHECK( mi2->connected() );
double value = 0;
// Check if no-data works
BOOST_CHECK_EQUAL( mi2->read(value), NoData );
// Check if writing works (including signalling)
ASSERT_PORT_SIGNALLING(mo1->write(1.0), mi2)
BOOST_CHECK( mi2->read(value) );
BOOST_CHECK_EQUAL( 1.0, value );
ASSERT_PORT_SIGNALLING(mo1->write(2.0), mi2);
BOOST_CHECK( mi2->read(value) );
BOOST_CHECK_EQUAL( 2.0, value );
}
void CorbaTest::testPortBufferConnection()
{
// This test assumes that there is a buffer connection mo1 => mi2 of size 3
// Check if connection succeeded both ways:
BOOST_CHECK( mo1->connected() );
BOOST_CHECK( mi2->connected() );
double value = 0;
// Check if no-data works
BOOST_CHECK_EQUAL( mi2->read(value), NoData );
// Check if writing works
ASSERT_PORT_SIGNALLING(mo1->write(1.0), mi2);
ASSERT_PORT_SIGNALLING(mo1->write(2.0), mi2);
ASSERT_PORT_SIGNALLING(mo1->write(3.0), mi2);
BOOST_CHECK( mi2->read(value) );
BOOST_CHECK_EQUAL( 1.0, value );
BOOST_CHECK( mi2->read(value) );
BOOST_CHECK_EQUAL( 2.0, value );
BOOST_CHECK( mi2->read(value) );
BOOST_CHECK_EQUAL( 3.0, value );
BOOST_CHECK_EQUAL( mi2->read(value), OldData );
}
void CorbaTest::testPortDisconnected()
{
BOOST_CHECK( !mo1->connected() );
BOOST_CHECK( !mi2->connected() );
}
// Registers the fixture into the 'registry'
BOOST_FIXTURE_TEST_SUITE( CorbaTestSuite, CorbaTest )
BOOST_AUTO_TEST_CASE( testAttributes )
{
ts = corba::TaskContextServer::Create( tc, false ); //no-naming
BOOST_CHECK( ts );
tp = corba::TaskContextProxy::Create( ts->server(), true );
BOOST_CHECK( tp );
BOOST_CHECK( tp->provides()->hasAttribute("aint1") );
Attribute<int> proxy_int = tp->provides()->getAttribute("aint1");
BOOST_REQUIRE( proxy_int.ready() );
// initial read through get:
BOOST_CHECK_EQUAL( proxy_int.get(), 3);
// reading through set:
aint1 = 4;
BOOST_CHECK_EQUAL( proxy_int.set(), 4);
// doing remote set:
proxy_int.set( 5 );
BOOST_CHECK_EQUAL( aint1, 5);
BOOST_CHECK( tp->provides()->hasAttribute("adouble1") );
Attribute<double> proxy_double = tp->provides()->getAttribute("adouble1");
BOOST_REQUIRE( proxy_double.ready() );
// initial reading through set:
BOOST_CHECK_EQUAL( proxy_double.set(), -3.0 );
// doing remote set, check local and remote result:
proxy_double.set( 5.0 );
BOOST_CHECK_EQUAL( adouble1, 5.0 );
BOOST_CHECK_EQUAL( proxy_double.get(), 5.0);
adouble1 = 6.0;
// reading changed remote:
BOOST_CHECK_EQUAL( proxy_double.get(), 6.0);
}
BOOST_AUTO_TEST_CASE( testProperties )
{
ts = corba::TaskContextServer::Create( tc, false ); //no-naming
BOOST_CHECK( ts );
tp = corba::TaskContextProxy::Create( ts->server(), true );
BOOST_CHECK( tp );
BOOST_CHECK( findProperty( *tp->provides()->properties(), "pint1") );
Property<int> proxy_int = findProperty( *tp->provides()->properties(), "pint1");
BOOST_REQUIRE( proxy_int.ready() );
// initial read through get:
BOOST_CHECK_EQUAL( proxy_int.get(), 3);
// reading through set:
pint1 = 4;
BOOST_CHECK_EQUAL( proxy_int.set(), 4);
// doing remote set:
proxy_int.set( 5 );
BOOST_CHECK_EQUAL( pint1, 5);
BOOST_CHECK( findProperty( *tp->provides()->properties(), "s1.s2.pdouble1") );
Property<double> proxy_d = findProperty( *tp->provides()->properties(), "s1.s2.pdouble1");
BOOST_REQUIRE( proxy_d.ready() );
// initial reading through set:
BOOST_CHECK_EQUAL( proxy_d.set(), -3.0 );
// doing remote set, check local and remote result:
proxy_d.set( 5.0 );
BOOST_CHECK_EQUAL( pdouble1->get(), 5.0 );
BOOST_CHECK_EQUAL( proxy_d.get(), 5.0);
pdouble1->set( 6.0 );
// reading changed remote:
BOOST_CHECK_EQUAL( proxy_d.get(), 6.0);
}
BOOST_AUTO_TEST_CASE( testOperationCallerC_Call )
{
ts = corba::TaskContextServer::Create( tc, false ); //no-naming
BOOST_CHECK( ts );
tp = corba::TaskContextProxy::Create( ts->server(), true );
BOOST_CHECK( tp );
// This test tests 'transparant' remote invocation of Orocos internal::OperationCallerC objects.
internal::OperationCallerC mc;
double r = 0.0;
mc = tp->provides("methods")->create("vm0", tc->engine() );
BOOST_CHECK( mc.call() );
BOOST_CHECK( r == 0.0 );
mc = tp->provides("methods")->create("m0", tc->engine() ).ret( r );
BOOST_CHECK( mc.call() );
BOOST_CHECK( r == -1.0 );
mc = tp->provides("methods")->create("m2", tc->engine() ).argC(1).argC(2.0).ret( r );
BOOST_CHECK( mc.call() );
BOOST_CHECK( r == -3.0 );
mc = tp->provides("methods")->create("m3", tc->engine() ).ret( r ).argC(1).argC(2.0).argC(true);
BOOST_CHECK( mc.call() );
BOOST_CHECK( r == -4.0 );
mc = tp->provides("methods")->create("m0except", tc->engine() );
BOOST_CHECK_THROW( mc.call(), std::runtime_error );
BOOST_REQUIRE( tc->inException() );
}
BOOST_AUTO_TEST_CASE( testOperationCallerC_Send )
{
ts = corba::TaskContextServer::Create( tc, false ); //no-naming
BOOST_CHECK( ts );
tp = corba::TaskContextProxy::Create( ts->server(), true );
BOOST_CHECK( tp );
OperationCallerC mc;
SendHandleC shc;
double r = 0.0;
double cr = 0.0;
mc = tp->provides("methods")->create("m0", caller->engine()).ret( r );
BOOST_CHECK_NO_THROW( mc.check() );
shc = mc.send();
shc.arg(cr);
BOOST_CHECK( shc.ready() ); // 1 argument to collect.
BOOST_CHECK_NO_THROW( shc.check() );
// now collect:
BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
BOOST_CHECK_EQUAL( r, 0.0 );
BOOST_CHECK_EQUAL( cr, -1.0 );
mc = tp->provides("methods")->create("m2", caller->engine()).argC(1).argC(2.0).ret( r );
BOOST_CHECK_NO_THROW( mc.check() );
shc = mc.send();
shc.arg(cr);
BOOST_CHECK( shc.ready() ); // 1 argument to collect.
BOOST_CHECK_NO_THROW( shc.check() );
// now collect:
BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
BOOST_CHECK_EQUAL( r, 0.0 );
BOOST_CHECK_EQUAL( cr, -3.0 );
mc = tp->provides("methods")->create("m3", caller->engine()).ret( r ).argC(1).argC(2.0).argC(true);
BOOST_CHECK_NO_THROW( mc.check() );
shc = mc.send();
shc.arg(cr);
BOOST_CHECK( shc.ready() ); // 1 argument to collect.
BOOST_CHECK_NO_THROW( shc.check() );
// now collect:
BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
BOOST_CHECK_EQUAL( r, 0.0 );
BOOST_CHECK_EQUAL( cr, -4.0 );
mc = tp->provides("methods")->create("m4", caller->engine()).ret( r ).argC(1).argC(2.0).argC(true).argC(string("hello"));
BOOST_CHECK_NO_THROW( mc.check() );
shc = mc.send();
shc.arg(cr);
BOOST_CHECK( shc.ready() ); // 1 argument to collect.
BOOST_CHECK_NO_THROW( shc.check() );
// now collect:
BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
BOOST_CHECK_EQUAL( r, 0.0 );
BOOST_CHECK_EQUAL( cr, -5.0 );
mc = tp->provides("methods")->create("m0except", caller->engine());
BOOST_CHECK_NO_THROW( mc.check() );
shc = mc.send();
BOOST_CHECK( shc.ready() ); // 1 argument to collect.
BOOST_CHECK_NO_THROW( shc.check() );
// now collect:
BOOST_CHECK_THROW( shc.collect(), std::runtime_error);
BOOST_REQUIRE( tc->inException() );
}
BOOST_AUTO_TEST_CASE( testRemoteOperationCallerCall )
{
ts = corba::TaskContextServer::Create( tc, false ); //no-naming
tp = corba::TaskContextProxy::Create( ts->server(), true );
// This test tests 'transparant' remote invocation of Orocos methods.
// This requires the internal::RemoteOperationCaller class, which does not work yet.
RTT::OperationCaller<double(void)> m0 = tp->provides("methods")->getOperation("m0");
RTT::OperationCaller<double(int)> m1 = tp->provides("methods")->getOperation("m1");
RTT::OperationCaller<double(int,double)> m2 = tp->provides("methods")->getOperation("m2");
RTT::OperationCaller<double(int,double,bool)> m3 = tp->provides("methods")->getOperation("m3");
RTT::OperationCaller<double(int,double,bool,std::string)> m4 = tp->provides("methods")->getOperation("m4");
RTT::OperationCaller<void(void)> m0e = tp->provides("methods")->getOperation("m0except");
BOOST_CHECK_EQUAL( -1.0, m0() );
BOOST_CHECK_EQUAL( -2.0, m1(1) );
BOOST_CHECK_EQUAL( -3.0, m2(1, 2.0) );
BOOST_CHECK_EQUAL( -4.0, m3(1, 2.0, true) );
BOOST_CHECK_EQUAL( -5.0, m4(1, 2.0, true,"hello") );
BOOST_CHECK_THROW( m0e(), std::runtime_error );
BOOST_REQUIRE( tc->inException() );
}
BOOST_AUTO_TEST_CASE( testAnyOperationCaller )
{
double d;
ts = corba::TaskContextServer::Create( tc, false ); //no-naming
tp = corba::TaskContextProxy::Create( ts->server() , true);
// This test tests the callOperation() function of the server.
corba::CService_var co = ts->server()->getProvider("methods");
BOOST_CHECK( co.in() );
corba::CAnyArguments_var any_args = new corba::CAnyArguments(0);
CORBA::Any_var vm0 = co->callOperation("vm0", any_args.inout() );
//BOOST_CHECK( vm0.in() );
CORBA::Any_var m0 = co->callOperation("m0", any_args.inout());
BOOST_CHECK( m0 >>= d );
BOOST_CHECK_EQUAL(d, -1.0 );
any_args = new corba::CAnyArguments(1);
any_args->length(1);
unsigned int index = 0;
any_args[index] <<= (CORBA::Long) 1;
CORBA::Any_var m1;
BOOST_CHECK_NO_THROW( m1 = co->callOperation("m1", any_args.inout()));
BOOST_CHECK( m1 >>= d );
BOOST_CHECK_EQUAL(d, -2.0 );
any_args = new corba::CAnyArguments(2);
any_args->length(2);
index = 0;
any_args[index] <<= (CORBA::Long) 1;
++index;
any_args[index] <<= (CORBA::Double) 2.0;
CORBA::Any_var m2;
BOOST_CHECK_NO_THROW( m2 = co->callOperation("m2", any_args.inout()));
BOOST_CHECK( m2 >>= d );
BOOST_CHECK_EQUAL(d, -3.0 );
any_args = new corba::CAnyArguments(3);
any_args->length(3);
index = 0;
any_args[index] <<= (CORBA::Long) 1;
++index;
any_args[index] <<= (CORBA::Double) 2.0;
++index;
any_args[index] <<= CORBA::Any::from_boolean( true );
CORBA::Any_var m3;
BOOST_CHECK_NO_THROW( m3= co->callOperation("m3", any_args.inout()) );
BOOST_CHECK( m3 >>= d );
BOOST_CHECK_EQUAL(d, -4.0 );
any_args = new corba::CAnyArguments(4);
any_args->length(4);
index = 0;
any_args[index] <<= (CORBA::Long) 1;
++index;
any_args[index] <<= (CORBA::Double) 2.0;
++index;
any_args[index] <<= CORBA::Any::from_boolean( true );
++index;
any_args[index] <<= "hello";
CORBA::Any_var m4;
BOOST_CHECK_NO_THROW ( m4 = co->callOperation("m4", any_args.inout()) );
BOOST_CHECK( m4 >>= d );
BOOST_CHECK_EQUAL(d, -5.0 );
any_args = new corba::CAnyArguments(0);
BOOST_CHECK_THROW(co->callOperation("m0except", any_args.inout() ), ::RTT::corba::CCallError);
BOOST_REQUIRE( tc->inException() );
}
BOOST_AUTO_TEST_CASE(testDataFlowInterface)
{
ts = corba::TaskContextServer::Create( tc, false ); //no-naming
corba::CDataFlowInterface_var ports = ts->server()->ports();
corba::CDataFlowInterface::CPortNames_var names =
ports->getPorts();
BOOST_CHECK_EQUAL(CORBA::ULong(2), names->length());
BOOST_CHECK_EQUAL(string("mi"), string(names[CORBA::ULong(0)]));
BOOST_CHECK_EQUAL(string("mo"), string(names[CORBA::ULong(1)]));
// Now check directions
BOOST_CHECK_EQUAL(RTT::corba::COutput,
ports->getPortType("mo"));
BOOST_CHECK_EQUAL(RTT::corba::CInput,
ports->getPortType("mi"));
// And check type names
CORBA::String_var cstr = ports->getDataType("mo");
BOOST_CHECK_EQUAL(string("double"),
string(cstr.in()));
}
BOOST_AUTO_TEST_CASE( testPortConnections )
{
// This test tests the differen port-to-port connections.
ts = corba::TaskContextServer::Create( tc, false ); //no-naming
ts2 = corba::TaskContextServer::Create( t2, false ); //no-naming
// Create a default CORBA policy specification
RTT::corba::CConnPolicy policy;
policy.type = RTT::corba::CData;
policy.init = false;
policy.lock_policy = RTT::corba::CLockFree;
policy.size = 0;
policy.transport = ORO_CORBA_PROTOCOL_ID; // force creation of non-local connections
corba::CDataFlowInterface_var ports = ts->server()->ports();
corba::CDataFlowInterface_var ports2 = ts2->server()->ports();
// Test cases that should not connect
BOOST_CHECK_THROW( ports->createConnection("mo", ports2, "does_not_exist", policy), CNoSuchPortException );
BOOST_CHECK_THROW( ports->createConnection("does_not_exist", ports2, "mi", policy), CNoSuchPortException );
BOOST_CHECK_THROW( ports->createConnection("does_not_exist", ports2, "does_not_exist", policy), CNoSuchPortException );
BOOST_CHECK_THROW( ports->createConnection("mo", ports2, "mo", policy), CNoSuchPortException );
BOOST_CHECK_THROW( ports->createConnection("mi", ports2, "mi", policy), CNoSuchPortException );
BOOST_CHECK_THROW( ports->createConnection("mi", ports2, "mo", policy), CNoSuchPortException );
// must be running to catch event port signalling.
BOOST_CHECK( t2->start() );
// WARNING: in the following, there is four configuration tested. There is
// also three different ways to disconnect. We need to test those three
// "disconnection methods", so beware when you change something ...
policy.type = RTT::corba::CData;
policy.pull = false;
BOOST_CHECK( ports->createConnection("mo", ports2, "mi", policy) );
testPortDataConnection();
ports->disconnectPort("mo");
testPortDisconnected();
policy.type = RTT::corba::CData;
policy.pull = true;
BOOST_CHECK( ports->createConnection("mo", ports2, "mi", policy) );
testPortDataConnection();
ports2->disconnectPort("mi");
testPortDisconnected();
policy.type = RTT::corba::CBuffer;
policy.pull = false;
policy.size = 3;
BOOST_CHECK( ports->createConnection("mo", ports2, "mi", policy) );
testPortBufferConnection();
ports->disconnectPort("mo");
testPortDisconnected();
policy.type = RTT::corba::CBuffer;
policy.pull = true;
BOOST_CHECK( ports->createConnection("mo", ports2, "mi", policy) );
testPortBufferConnection();
// Here, check removal of specific connections. So first add another
// connection ...
mo1->createConnection(*mi1);
// Remove the remote connection
ports->removeConnection("mo", ports2, "mi");
// Check it is removed
BOOST_CHECK(mo1->connected());
BOOST_CHECK(mi1->connected());
BOOST_CHECK(!mi2->connected());
}
BOOST_AUTO_TEST_CASE( testPortProxying )
{
ts = corba::TaskContextServer::Create( tc, false ); //no-naming
tp = corba::TaskContextProxy::Create( ts->server(), true );
ts2 = corba::TaskContextServer::Create( t2, false ); //no-naming
tp2 = corba::TaskContextProxy::Create( ts2->server(), true );
base::PortInterface* untyped_port;
untyped_port = tp->ports()->getPort("mi");
BOOST_CHECK(untyped_port);
base::InputPortInterface* read_port = dynamic_cast<base::InputPortInterface*>(tp->ports()->getPort("mi"));
BOOST_CHECK(read_port);
untyped_port = tp->ports()->getPort("mi");
BOOST_CHECK(untyped_port);
base::OutputPortInterface* write_port = dynamic_cast<base::OutputPortInterface*>(tp2->ports()->getPort("mo"));
BOOST_CHECK(write_port);
// Just make sure 'read_port' and 'write_port' are actually proxies and not
// the real thing
BOOST_CHECK(dynamic_cast<corba::RemoteInputPort*>(read_port));
BOOST_CHECK(dynamic_cast<corba::RemoteOutputPort*>(write_port));
BOOST_CHECK(!read_port->connected());
BOOST_CHECK(read_port->getTypeInfo() == mi1->getTypeInfo());
BOOST_CHECK(!write_port->connected());
BOOST_CHECK(write_port->getTypeInfo() == mo2->getTypeInfo());
mo2->createConnection(*read_port);
BOOST_CHECK(read_port->connected());
BOOST_CHECK(write_port->connected());
read_port->disconnect();
BOOST_CHECK(!read_port->connected());
BOOST_CHECK(!write_port->connected());
mo2->createConnection(*read_port);
BOOST_CHECK(read_port->connected());
BOOST_CHECK(write_port->connected());
write_port->disconnect();
BOOST_CHECK(!read_port->connected());
BOOST_CHECK(!write_port->connected());
// Test cloning
auto_ptr<base::InputPortInterface> read_clone(dynamic_cast<base::InputPortInterface*>(read_port->clone()));
BOOST_CHECK(mo2->createConnection(*read_clone));
BOOST_CHECK(read_clone->connected());
BOOST_CHECK(!read_port->connected());
mo2->disconnect();
}
BOOST_AUTO_TEST_CASE( testDataHalfs )
{
double result;
// This test tests the differen port-to-port connections.
ts = corba::TaskContextServer::Create( tc, false ); //no-naming
// Create a default CORBA policy specification
RTT::corba::CConnPolicy policy;
policy.type = RTT::corba::CData;
policy.init = false;
policy.lock_policy = RTT::corba::CLockFree;
policy.size = 0;
policy.transport = ORO_CORBA_PROTOCOL_ID; // force creation of non-local connections
corba::CDataFlowInterface_var ports = ts->server()->ports();
BOOST_REQUIRE( ports.in() );
// test unbuffered C++ write --> Corba read
policy.pull = false; // note: buildChannelInput must correct policy to pull = true (adds a buffer).
CChannelElement_var cce = ports->buildChannelInput("mo", policy);
CORBA::Any_var sample = new CORBA::Any();
BOOST_REQUIRE( cce.in() );
BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), CNoData );
// Check read of new data
mo1->write( 3.33 );
BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), CNewData );
sample >>= result;
BOOST_CHECK_EQUAL( result, 3.33);
// Check re-read of old data.
sample <<= 0.0;
BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), COldData );
sample >>= result;
BOOST_CHECK_EQUAL( result, 3.33);
cce->disconnect();
// test unbuffered Corba write --> C++ read
cce = ports->buildChannelOutput("mi", policy);
ports->channelReady("mi", cce);
sample = new CORBA::Any();
BOOST_REQUIRE( cce.in() );
// Check read of new data
result = 0.0;
sample <<= 4.44;
cce->write( sample.in() );
BOOST_CHECK_EQUAL( mi1->read( result ), NewData );
BOOST_CHECK_EQUAL( result, 4.44 );
// Check re-read of old data.
result = 0.0;
BOOST_CHECK_EQUAL( mi1->read( result ), OldData );
BOOST_CHECK_EQUAL( result, 4.44);
}
BOOST_AUTO_TEST_CASE( testBufferHalfs )
{
double result;
// This test tests the differen port-to-port connections.
ts = corba::TaskContextServer::Create( tc, false ); //no-naming
// Create a default CORBA policy specification
RTT::corba::CConnPolicy policy;
policy.type = RTT::corba::CBuffer;
policy.init = false;
policy.lock_policy = RTT::corba::CLockFree;
policy.size = 10;
policy.transport = ORO_CORBA_PROTOCOL_ID; // force creation of non-local connections
corba::CDataFlowInterface_var ports = ts->server()->ports();
BOOST_REQUIRE( ports.in() );
// test unbuffered C++ write --> Corba read
policy.pull = false; // note: buildChannelInput must correct policy to pull = true (adds a buffer).
CChannelElement_var cce = ports->buildChannelInput("mo", policy);
CORBA::Any_var sample = new CORBA::Any();
BOOST_REQUIRE( cce.in() );
BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), CNoData );
// Check read of new data
mo1->write( 6.33 );
mo1->write( 3.33 );
BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), CNewData );
sample >>= result;
BOOST_CHECK_EQUAL( result, 6.33);
BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), CNewData );
sample >>= result;
BOOST_CHECK_EQUAL( result, 3.33);
// Check re-read of old data.
sample <<= 0.0;
BOOST_CHECK_EQUAL( cce->read( sample.out(), true ), COldData );
sample >>= result;
BOOST_CHECK_EQUAL( result, 3.33);
cce->disconnect();
// test unbuffered Corba write --> C++ read
cce = ports->buildChannelOutput("mi", policy);
ports->channelReady("mi", cce);
sample = new CORBA::Any();
BOOST_REQUIRE( cce.in() );
// Check read of new data
result = 0.0;
sample <<= 6.44;
cce->write( sample.in() );
sample <<= 4.44;
cce->write( sample.in() );
BOOST_CHECK_EQUAL( mi1->read( result ), NewData );
BOOST_CHECK_EQUAL( result, 6.44 );
BOOST_CHECK_EQUAL( mi1->read( result ), NewData );
BOOST_CHECK_EQUAL( result, 4.44 );
// Check re-read of old data.
result = 0.0;
BOOST_CHECK_EQUAL( mi1->read( result ), OldData );
BOOST_CHECK_EQUAL( result, 4.44);
}
BOOST_AUTO_TEST_SUITE_END()