21 #define ORO_TEST_OPERATION_CALLER 33 #define wait_for_equal( a, b, times ) do { \ 34 bool wait_for_helper; \ 36 while( (wait_for_helper = ((a) != (b))) && wait++ != times ) \ 38 if (wait_for_helper) BOOST_CHECK_EQUAL( a, b ); \ 50 boost::shared_ptr<DisposableInterface> implementation(
new RemoteOperationCaller<
double(
void)>(tc->provides(
"methods")->getPart(
"m0"),
"m0", 0 ) );
52 BOOST_CHECK( m0.
ready() );
55 implementation.reset(
new RemoteOperationCaller<
double(
int)>(tc->provides(
"methods")->getPart(
"m1"),
"m1", 0) );
57 BOOST_CHECK( m1.ready() );
60 implementation.reset(
new RemoteOperationCaller<
void(
void)>(tc->provides(
"methods")->getPart(
"m0except"),
"m0except", 0) );
62 BOOST_CHECK( m0e.ready() );
64 BOOST_CHECK_EQUAL( 2.0, m1(0) );
65 BOOST_CHECK_EQUAL( -2.0, m1(1) );
66 BOOST_CHECK_EQUAL( -1.0, m0() );
67 BOOST_CHECK_THROW( m0e(), std::runtime_error);
68 BOOST_REQUIRE( tc->inException() );
75 mc = tc->provides(
"methods")->create(
"m0", caller->engine()).ret( r );
76 BOOST_CHECK( mc.
call() );
77 BOOST_CHECK_EQUAL( r, -1.0 );
79 mc = tc->provides(
"methods")->create(
"m2", caller->engine()).argC(1).
argC(2.0).
ret( r );
80 BOOST_CHECK( mc.
call() );
81 BOOST_CHECK_EQUAL( r, -3.0 );
83 mc = tc->provides(
"methods")->create(
"m3", caller->engine()).ret( r ).
argC(1).
argC(2.0).
argC(
true);
84 BOOST_CHECK( mc.
call() );
85 BOOST_CHECK( r == -4.0 );
87 mc = tc->provides(
"methods")->create(
"m4", caller->engine()).ret( r ).
argC(1).
argC(2.0).
argC(
true).
argC(
string(
"hello"));
88 BOOST_CHECK( mc.
call() );
89 BOOST_CHECK( r == -5.0 );
91 mc = tc->provides(
"methods")->create(
"m5", caller->engine()).argC(1).
argC(2.0).
argC(
true).
argC(
string(
"hello")).
argC(5.0f).
ret( r );
92 BOOST_CHECK( mc.
call() );
93 BOOST_CHECK( r == -6.0 );
95 mc = tc->provides(
"methods")->create(
"m6", caller->engine()).ret( r ).
argC(1).
argC(2.0).
argC(
true).
argC(
string(
"hello")).
argC(5.0f).
argC(
'a');
96 BOOST_CHECK( mc.
call() );
97 BOOST_CHECK( r == -7.0 );
99 mc = tc->provides(
"methods")->create(
"m7", caller->engine()).ret( r ).
argC(1).
argC(2.0).
argC(
true).
argC(
string(
"hello")).
argC(5.0f).
argC(
'a').
argC((
unsigned int)7);
100 BOOST_CHECK( mc.
call() );
101 BOOST_CHECK( r == -8.0 );
103 mc = tc->provides(
"methods")->create(
"m0except", caller->engine());
104 BOOST_CHECK_THROW( mc.
call(), std::runtime_error);
106 mc = tc->provides(
"methods")->create(
"o0except", caller->engine());
107 BOOST_CHECK_THROW( mc.call(), std::runtime_error);
108 BOOST_REQUIRE( tc->inException() );
117 mc = tc->provides(
"methods")->create(
"m0", caller->engine()).ret( r );
118 BOOST_CHECK_NO_THROW( mc.
check() );
121 BOOST_CHECK( shc.ready() );
122 BOOST_CHECK_NO_THROW( shc.check() );
125 BOOST_CHECK_EQUAL( r, 0.0 );
126 BOOST_CHECK_EQUAL( cr, -1.0 );
128 mc = tc->provides(
"methods")->create(
"m2", caller->engine()).argC(1).
argC(2.0).
ret( r );
129 BOOST_CHECK_NO_THROW( mc.
check() );
132 BOOST_CHECK( shc.ready() );
133 BOOST_CHECK_NO_THROW( shc.check() );
136 BOOST_CHECK_EQUAL( r, 0.0 );
137 BOOST_CHECK_EQUAL( cr, -3.0 );
139 mc = tc->provides(
"methods")->create(
"m3", caller->engine()).ret( r ).
argC(1).
argC(2.0).
argC(
true);
140 BOOST_CHECK_NO_THROW( mc.
check() );
143 BOOST_CHECK( shc.ready() );
144 BOOST_CHECK_NO_THROW( shc.check() );
147 BOOST_CHECK_EQUAL( r, 0.0 );
148 BOOST_CHECK_EQUAL( cr, -4.0 );
150 mc = tc->provides(
"methods")->create(
"m4", caller->engine()).ret( r ).
argC(1).
argC(2.0).
argC(
true).
argC(
string(
"hello"));
151 BOOST_CHECK_NO_THROW( mc.
check() );
154 BOOST_CHECK( shc.ready() );
155 BOOST_CHECK_NO_THROW( shc.check() );
158 BOOST_CHECK_EQUAL( r, 0.0 );
159 BOOST_CHECK_EQUAL( cr, -5.0 );
161 mc = tc->provides(
"methods")->create(
"m5", caller->engine()).ret( r ).
argC(1).
argC(2.0).
argC(
true).
argC(
string(
"hello")).
argC(5.0f);
162 BOOST_CHECK_NO_THROW( mc.
check() );
165 BOOST_CHECK( shc.ready() );
166 BOOST_CHECK_NO_THROW( shc.check() );
169 BOOST_CHECK_EQUAL( r, 0.0 );
170 BOOST_CHECK_EQUAL( cr, -6.0 );
172 mc = tc->provides(
"methods")->create(
"m6", caller->engine()).ret( r ).
argC(1).
argC(2.0).
argC(
true).
argC(
string(
"hello")).
argC(5.0f).
argC(
'a');
173 BOOST_CHECK_NO_THROW( mc.
check() );
176 BOOST_CHECK( shc.ready() );
177 BOOST_CHECK_NO_THROW( shc.check() );
180 BOOST_CHECK_EQUAL( r, 0.0 );
181 BOOST_CHECK_EQUAL( cr, -7.0 );
183 mc = tc->provides(
"methods")->create(
"m7", caller->engine()).ret( r ).
argC(1).
argC(2.0).
argC(
true).
argC(
string(
"hello")).
argC(5.0f).
argC(
'a').
argC((
unsigned int)7);
184 BOOST_CHECK_NO_THROW( mc.
check() );
187 BOOST_CHECK( shc.ready() );
188 BOOST_CHECK_NO_THROW( shc.check() );
191 BOOST_CHECK_EQUAL( r, 0.0 );
192 BOOST_CHECK_EQUAL( cr, -8.0 );
194 mc = tc->provides(
"methods")->create(
"m0except", caller->engine());
195 BOOST_CHECK_NO_THROW( mc.
check() );
197 BOOST_CHECK( shc.ready() );
198 BOOST_CHECK_NO_THROW( shc.check() );
200 BOOST_CHECK_THROW( shc.collect(), std::runtime_error );
201 BOOST_REQUIRE(tc->inException() );
228 BOOST_CHECK( mc0.
call() );
229 BOOST_CHECK_EQUAL(-1.0, ret);
230 BOOST_CHECK( mc1.
call() );
231 BOOST_CHECK_EQUAL(-2.0, ret);
232 BOOST_CHECK( mc2.
call() );
233 BOOST_CHECK_EQUAL(-3.0, ret);
234 BOOST_CHECK( mc3.
call() );
235 BOOST_CHECK_EQUAL(-4.0, ret);
236 BOOST_CHECK( mc4.
call() );
237 BOOST_CHECK_EQUAL(-5.0, ret);
238 BOOST_CHECK( mc5.
call() );
239 BOOST_CHECK_EQUAL(-6.0, ret);
240 BOOST_CHECK( mc6.
call() );
241 BOOST_CHECK_EQUAL(-7.0, ret);
242 BOOST_CHECK( mc7.
call() );
243 BOOST_CHECK_EQUAL(-8.0, ret);
245 BOOST_CHECK_THROW( mc0e.
call(), std::runtime_error );
246 BOOST_REQUIRE(tc->inException() );
276 BOOST_CHECK( mm0.getOperationCallerImpl() );
277 BOOST_CHECK( mm0.ready() );
280 BOOST_CHECK( mm0e.getOperationCallerImpl() );
281 BOOST_CHECK( mm0e.ready() );
286 BOOST_CHECK( mm1.getOperationCallerImpl() );
287 BOOST_CHECK( mm1.ready() );
290 BOOST_CHECK( mm2.getOperationCallerImpl() );
291 BOOST_CHECK( mm2.ready() );
294 BOOST_CHECK_EQUAL( -1.0, mm0() );
296 BOOST_CHECK_EQUAL( -2.0, mm1(1) );
297 BOOST_CHECK_EQUAL( -3.0, mm2(1, 2.0) );
299 BOOST_CHECK_THROW( mm0e(), std::runtime_error );
310 BOOST_CHECK( mvoid.
ready() == false );
313 BOOST_CHECK( mvoid.ready() == false );
316 BOOST_CHECK( mvoid.ready() == true );
319 BOOST_CHECK( mvoid.ready() == false );
329 boost::shared_ptr<DisposableInterface> implementation(
new RemoteOperationCaller<
int(
int)>(tc->provides(
"methods")->getPart(
"sleepAndIncOwnThread"),
"sleepAndIncOwnThread", 0) );
330 sleepAndIncOwnThread = implementation;
331 BOOST_CHECK( sleepAndIncOwnThread.ready() );
334 sleepAndIncOwnThread.call(1);
335 sleepAndIncOwnThread.call(1);
336 sleepAndIncOwnThread.call(1);
337 BOOST_CHECK_EQUAL( 3, i );
340 sleepAndIncOwnThread.send(1);
341 sleepAndIncOwnThread.send(1);
342 sleepAndIncOwnThread.send(1);
351 boost::shared_ptr<DisposableInterface> implementation(
new RemoteOperationCaller<
const void *(
const int&)>(tc->provides(
"methods")->getPart(
"returnAddressOfConst"),
"returnAddressOfConst", 0) );
352 returnAddressOfConst = implementation;
353 BOOST_CHECK( returnAddressOfConst.ready() );
355 implementation.reset(
new RemoteOperationCaller<
void *(
int&)>(tc->provides(
"methods")->getPart(
"returnAddressOf"),
"returnAddressOf", 0) );
356 returnAddressOf = implementation;
357 BOOST_CHECK( returnAddressOf.ready() );
362 BOOST_CHECK_EQUAL(&var, returnAddressOf(var));
363 BOOST_CHECK_EQUAL(&var, returnAddressOfConst(var));
370 BOOST_CHECK_EQUAL(&var, sh.ret());
375 returnAddressOfConst = tc->provides(
"methods")->getPart(
"returnAddressOfConst");
376 returnAddressOf = tc->provides(
"methods")->getPart(
"returnAddressOf");
377 BOOST_CHECK_EQUAL(&var, returnAddressOf(var));
378 BOOST_CHECK_EQUAL(&var, returnAddressOfConst(var));
384 BOOST_CHECK_EQUAL(&var, sh.ret());
389 returnAddressOfByValue = tc->provides(
"methods")->getPart(
"returnAddressOfConst");
390 BOOST_CHECK(returnAddressOfByValue.ready());
392 BOOST_CHECK_NE(&var, returnAddressOfByValue(var));
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
#define BOOST_AUTO_TEST_SUITE_END()
Operation< Signature > & addOperation(Operation< Signature > &op)
#define wait_for_equal(a, b, times)
SendHandleC & arg(base::DataSourceBase::shared_ptr a)
The SendHandle is used to collect the result values of an asynchronous invocation. The template argument Signature must have the same type as the method being invoked.
boost::shared_ptr< Service > ServicePtr
OperationCallerC & ret(base::AttributeBase *r)
BOOST_AUTO_TEST_CASE(testRemoteOperationCaller)
Operation & calls(boost::function< Signature > func, ExecutionThread et=ClientThread, ExecutionEngine *ownerEngine=NULL)
OperationCallerC & argC(const ArgT a)
OperationInterfacePart * getOperation(std::string name)
SendStatus collect() const
void setOwner(TaskContext *new_owner)
double m2(int i, double d)