00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #define ORO_TEST_OPERATION_CALLER
00022
00023 #include <TaskContext.hpp>
00024 #include <OperationCaller.hpp>
00025 #include <Operation.hpp>
00026 #include <Service.hpp>
00027
00028 #include "unit.hpp"
00029 #include "operations_fixture.hpp"
00030
00034 BOOST_FIXTURE_TEST_SUITE( OperationCallerTestSuite, OperationsFixture )
00035
00036 BOOST_AUTO_TEST_CASE(testClientThreadOperationCaller)
00037 {
00038
00039 OperationCaller<double(void)> m0("m0", &OperationsFixture::m0, this);
00040 OperationCaller<double(int)> m1("m1", &OperationsFixture::m1, this);
00041 OperationCaller<double(int,double)> m2("m2", &OperationsFixture::m2, this);
00042 OperationCaller<double(int,double,bool)> m3("m3", &OperationsFixture::m3, this);
00043 OperationCaller<double(int,double,bool,std::string)> m4("m4", &OperationsFixture::m4, this);
00044 OperationCaller<double(int,double,bool,std::string,float)> m5("m5", &OperationsFixture::m5, this);
00045 OperationCaller<double(int,double,bool,std::string,float,char)> m6("m6", &OperationsFixture::m6, this);
00046 OperationCaller<double(int,double,bool,std::string,float,char,unsigned int)> m7("m7", &OperationsFixture::m7, this);
00047
00048 BOOST_CHECK_EQUAL( -1.0, m0() );
00049 BOOST_CHECK_EQUAL( -2.0, m1(1) );
00050 BOOST_CHECK_EQUAL( -3.0, m2(1, 2.0) );
00051 BOOST_CHECK_EQUAL( -4.0, m3(1, 2.0, true) );
00052 BOOST_CHECK_EQUAL( -5.0, m4(1, 2.0, true,"hello") );
00053 BOOST_CHECK_EQUAL( -6.0, m5(1, 2.0, true,"hello",5.0) );
00054 BOOST_CHECK_EQUAL( -7.0, m6(1, 2.0, true,"hello",5.0,'a') );
00055 BOOST_CHECK_EQUAL( -8.0, m7(1, 2.0, true,"hello",5.0,'a',7) );
00056 }
00057
00058 BOOST_AUTO_TEST_CASE(testOwnThreadOperationCallerCall)
00059 {
00060
00061 OperationCaller<double(void)> m0("m0", &OperationsFixture::m0, this, tc->engine(), caller->engine(), OwnThread);
00062 OperationCaller<double(int)> m1("m1", &OperationsFixture::m1, this, tc->engine(), caller->engine(), OwnThread);
00063 OperationCaller<double(int,double)> m2("m2", &OperationsFixture::m2, this, tc->engine(), caller->engine(), OwnThread);
00064 OperationCaller<double(int,double,bool)> m3("m3", &OperationsFixture::m3, this, tc->engine(), caller->engine(), OwnThread);
00065 OperationCaller<double(int,double,bool,std::string)> m4("m4", &OperationsFixture::m4, this, tc->engine(), caller->engine(), OwnThread);
00066 OperationCaller<double(int,double,bool,std::string,float)> m5("m5", &OperationsFixture::m5, this, tc->engine(), caller->engine(), OwnThread);
00067 OperationCaller<double(int,double,bool,std::string,float,char)> m6("m6", &OperationsFixture::m6, this, tc->engine(), caller->engine(), OwnThread);
00068 OperationCaller<double(int,double,bool,std::string,float,char,unsigned int)> m7("m7", &OperationsFixture::m7, this, tc->engine(), caller->engine(), OwnThread);
00069
00070 BOOST_REQUIRE( tc->isRunning() );
00071 BOOST_REQUIRE( caller->isRunning() );
00072 BOOST_CHECK_EQUAL( -1.0, m0() );
00073 BOOST_CHECK_EQUAL( -2.0, m1(1) );
00074 BOOST_CHECK_EQUAL( -3.0, m2(1, 2.0) );
00075 BOOST_CHECK_EQUAL( -4.0, m3(1, 2.0, true) );
00076 BOOST_CHECK_EQUAL( -5.0, m4(1, 2.0, true,"hello") );
00077 BOOST_CHECK_EQUAL( -6.0, m5(1, 2.0, true,"hello",5.0) );
00078 BOOST_CHECK_EQUAL( -7.0, m6(1, 2.0, true,"hello",5.0,'a') );
00079 BOOST_CHECK_EQUAL( -8.0, m7(1, 2.0, true,"hello",5.0,'a',7) );
00080 }
00081
00082 BOOST_AUTO_TEST_CASE(testClientThreadOperationCallerSend)
00083 {
00084
00085 OperationCaller<double(void)> m0("m0", &OperationsFixture::m0, this, 0, caller->engine());
00086 OperationCaller<double(int)> m1("m1", &OperationsFixture::m1, this, 0, caller->engine());
00087 OperationCaller<double(int,double)> m2("m2", &OperationsFixture::m2, this, 0, caller->engine());
00088 OperationCaller<double(int,double,bool)> m3("m3", &OperationsFixture::m3, this, 0, caller->engine());
00089 OperationCaller<double(int,double,bool,std::string)> m4("m4", &OperationsFixture::m4, this, 0, caller->engine());
00090 OperationCaller<double(int,double,bool,std::string,float)> m5("m5", &OperationsFixture::m5, this, 0, caller->engine());
00091 OperationCaller<double(int,double,bool,std::string,float,char)> m6("m6", &OperationsFixture::m6, this, 0, caller->engine());
00092 OperationCaller<double(int,double,bool,std::string,float,char,unsigned int)> m7("m7", &OperationsFixture::m7, this, 0, caller->engine());
00093
00094
00095 BOOST_REQUIRE( tc->isRunning() );
00096 BOOST_REQUIRE( caller->isRunning() );
00097 SendHandle<double(void)> h0 = m0.send();
00098 SendHandle<double(int)> h1 = m1.send(1);
00099 SendHandle<double(int,double)> h2 = m2.send(1, 2.0);
00100 SendHandle<double(int,double,bool)> h3 = m3.send(1, 2.0, true);
00101 SendHandle<double(int,double,bool,std::string)> h4 = m4.send(1, 2.0, true,"hello");
00102 SendHandle<double(int,double,bool,std::string,float)> h5 = m5.send(1, 2.0, true,"hello",5.0);
00103 SendHandle<double(int,double,bool,std::string,float,char)> h6 = m6.send(1, 2.0, true,"hello",5.0,'a');
00104 SendHandle<double(int,double,bool,std::string,float,char,unsigned int)> h7 = m7.send(1, 2.0, true,"hello",5.0,'a',7);
00105
00106 double retn=0;
00107 BOOST_CHECK_EQUAL( SendSuccess, h0.collect(retn) );
00108 BOOST_CHECK_EQUAL( retn, -1.0 );
00109 BOOST_CHECK_EQUAL( SendSuccess, h1.collect(retn) );
00110 BOOST_CHECK_EQUAL( retn, -2.0 );
00111 BOOST_CHECK_EQUAL( SendSuccess, h2.collect(retn) );
00112 BOOST_CHECK_EQUAL( retn, -3.0 );
00113 BOOST_CHECK_EQUAL( SendSuccess, h3.collect(retn) );
00114 BOOST_CHECK_EQUAL( retn, -4.0 );
00115 BOOST_CHECK_EQUAL( SendSuccess, h4.collect(retn) );
00116 BOOST_CHECK_EQUAL( retn, -5.0 );
00117 BOOST_CHECK_EQUAL( SendSuccess, h5.collect(retn) );
00118 BOOST_CHECK_EQUAL( retn, -6.0 );
00119 BOOST_CHECK_EQUAL( SendSuccess, h6.collect(retn) );
00120 BOOST_CHECK_EQUAL( retn, -7.0 );
00121 BOOST_CHECK_EQUAL( SendSuccess, h7.collect(retn) );
00122 BOOST_CHECK_EQUAL( retn, -8.0 );
00123
00124
00125 BOOST_CHECK_EQUAL( SendSuccess, h0.collectIfDone(retn) );
00126 BOOST_CHECK_EQUAL( retn, -1.0 );
00127 BOOST_CHECK_EQUAL( SendSuccess, h1.collectIfDone(retn) );
00128 BOOST_CHECK_EQUAL( retn, -2.0 );
00129 BOOST_CHECK_EQUAL( SendSuccess, h2.collectIfDone(retn) );
00130 BOOST_CHECK_EQUAL( retn, -3.0 );
00131 BOOST_CHECK_EQUAL( SendSuccess, h3.collectIfDone(retn) );
00132 BOOST_CHECK_EQUAL( retn, -4.0 );
00133 BOOST_CHECK_EQUAL( SendSuccess, h4.collectIfDone(retn) );
00134 BOOST_CHECK_EQUAL( retn, -5.0 );
00135 BOOST_CHECK_EQUAL( SendSuccess, h5.collectIfDone(retn) );
00136 BOOST_CHECK_EQUAL( retn, -6.0 );
00137 BOOST_CHECK_EQUAL( SendSuccess, h6.collectIfDone(retn) );
00138 BOOST_CHECK_EQUAL( retn, -7.0 );
00139 BOOST_CHECK_EQUAL( SendSuccess, h7.collectIfDone(retn) );
00140 BOOST_CHECK_EQUAL( retn, -8.0 );
00141
00142
00143 BOOST_CHECK_EQUAL( -1.0, h0.ret() );
00144 BOOST_CHECK_EQUAL( -2.0, h1.ret(1) );
00145 BOOST_CHECK_EQUAL( -3.0, h2.ret(1, 2.0) );
00146 BOOST_CHECK_EQUAL( -4.0, h3.ret(1, 2.0, true) );
00147 BOOST_CHECK_EQUAL( -5.0, h4.ret(1, 2.0, true,"hello") );
00148 BOOST_CHECK_EQUAL( -6.0, h5.ret(1, 2.0, true,"hello",5.0) );
00149 BOOST_CHECK_EQUAL( -7.0, h6.ret(1, 2.0, true,"hello",5.0,'a') );
00150 BOOST_CHECK_EQUAL( -8.0, h7.ret(1, 2.0, true,"hello",5.0,'a',7) );
00151
00152 BOOST_CHECK_EQUAL( -2.0, h1.ret() );
00153 BOOST_CHECK_EQUAL( -3.0, h2.ret() );
00154 BOOST_CHECK_EQUAL( -4.0, h3.ret() );
00155 BOOST_CHECK_EQUAL( -5.0, h4.ret() );
00156 BOOST_CHECK_EQUAL( -6.0, h5.ret() );
00157 BOOST_CHECK_EQUAL( -7.0, h6.ret() );
00158 BOOST_CHECK_EQUAL( -8.0, h7.ret() );
00159 }
00160
00161 BOOST_AUTO_TEST_CASE(testOwnThreadOperationCallerSend)
00162 {
00163 OperationCaller<double(void)> m0("m0", &OperationsFixture::m0, this, tc->engine(), caller->engine(), OwnThread);
00164 OperationCaller<double(int)> m1("m1", &OperationsFixture::m1, this, tc->engine(), caller->engine(), OwnThread);
00165 OperationCaller<double(int,double)> m2("m2", &OperationsFixture::m2, this, tc->engine(), caller->engine(), OwnThread);
00166 OperationCaller<double(int,double,bool)> m3("m3", &OperationsFixture::m3, this, tc->engine(), caller->engine(), OwnThread);
00167 OperationCaller<double(int,double,bool,std::string)> m4("m4", &OperationsFixture::m4, this, tc->engine(), caller->engine(), OwnThread);
00168 OperationCaller<double(int,double,bool,std::string,float)> m5("m5", &OperationsFixture::m5, this, tc->engine(), caller->engine(), OwnThread);
00169 OperationCaller<double(int,double,bool,std::string,float,char)> m6("m6", &OperationsFixture::m6, this, tc->engine(), caller->engine(), OwnThread);
00170 OperationCaller<double(int,double,bool,std::string,float,char,unsigned int)> m7("m7", &OperationsFixture::m7, this, tc->engine(), caller->engine(), OwnThread);
00171
00172 BOOST_REQUIRE( tc->isRunning() );
00173 BOOST_REQUIRE( caller->isRunning() );
00174 SendHandle<double(void)> h0 = m0.send();
00175 SendHandle<double(int)> h1 = m1.send(1);
00176 SendHandle<double(int,double)> h2 = m2.send(1, 2.0);
00177 SendHandle<double(int,double,bool)> h3 = m3.send(1, 2.0, true);
00178 SendHandle<double(int,double,bool,std::string)> h4 = m4.send(1, 2.0, true,"hello");
00179 SendHandle<double(int,double,bool,std::string,float)> h5 = m5.send(1, 2.0, true,"hello",5.0);
00180 SendHandle<double(int,double,bool,std::string,float,char)> h6 = m6.send(1, 2.0, true,"hello",5.0,'a');
00181 SendHandle<double(int,double,bool,std::string,float,char,unsigned int)> h7 = m7.send(1, 2.0, true,"hello",5.0,'a',7);
00182
00183
00184 double retn=0;
00185 BOOST_CHECK_EQUAL( SendSuccess, h0.collect(retn) );
00186 BOOST_CHECK_EQUAL( retn, -1.0 );
00187 BOOST_CHECK_EQUAL( SendSuccess, h1.collect(retn) );
00188 BOOST_CHECK_EQUAL( retn, -2.0 );
00189 BOOST_CHECK_EQUAL( SendSuccess, h2.collect(retn) );
00190 BOOST_CHECK_EQUAL( retn, -3.0 );
00191 BOOST_CHECK_EQUAL( SendSuccess, h3.collect(retn) );
00192 BOOST_CHECK_EQUAL( retn, -4.0 );
00193 BOOST_CHECK_EQUAL( SendSuccess, h4.collect(retn) );
00194 BOOST_CHECK_EQUAL( retn, -5.0 );
00195 BOOST_CHECK_EQUAL( SendSuccess, h5.collect(retn) );
00196 BOOST_CHECK_EQUAL( retn, -6.0 );
00197 BOOST_CHECK_EQUAL( SendSuccess, h6.collect(retn) );
00198 BOOST_CHECK_EQUAL( retn, -7.0 );
00199 BOOST_CHECK_EQUAL( SendSuccess, h7.collect(retn) );
00200 BOOST_CHECK_EQUAL( retn, -8.0 );
00201
00202
00203 BOOST_CHECK_EQUAL( SendSuccess, h0.collectIfDone(retn) );
00204 BOOST_CHECK_EQUAL( retn, -1.0 );
00205 BOOST_CHECK_EQUAL( SendSuccess, h1.collectIfDone(retn) );
00206 BOOST_CHECK_EQUAL( retn, -2.0 );
00207 BOOST_CHECK_EQUAL( SendSuccess, h2.collectIfDone(retn) );
00208 BOOST_CHECK_EQUAL( retn, -3.0 );
00209 BOOST_CHECK_EQUAL( SendSuccess, h3.collectIfDone(retn) );
00210 BOOST_CHECK_EQUAL( retn, -4.0 );
00211 BOOST_CHECK_EQUAL( SendSuccess, h4.collectIfDone(retn) );
00212 BOOST_CHECK_EQUAL( retn, -5.0 );
00213 BOOST_CHECK_EQUAL( SendSuccess, h5.collectIfDone(retn) );
00214 BOOST_CHECK_EQUAL( retn, -6.0 );
00215 BOOST_CHECK_EQUAL( SendSuccess, h6.collectIfDone(retn) );
00216 BOOST_CHECK_EQUAL( retn, -7.0 );
00217 BOOST_CHECK_EQUAL( SendSuccess, h7.collectIfDone(retn) );
00218 BOOST_CHECK_EQUAL( retn, -8.0 );
00219
00220
00221
00222 BOOST_CHECK_EQUAL( -1.0, h0.ret() );
00223 BOOST_CHECK_EQUAL( -2.0, h1.ret(1) );
00224 BOOST_CHECK_EQUAL( -3.0, h2.ret(1, 2.0) );
00225 BOOST_CHECK_EQUAL( -4.0, h3.ret(1, 2.0, true) );
00226 BOOST_CHECK_EQUAL( -5.0, h4.ret(1, 2.0, true,"hello") );
00227 BOOST_CHECK_EQUAL( -6.0, h5.ret(1, 2.0, true,"hello",5.0) );
00228 BOOST_CHECK_EQUAL( -7.0, h6.ret(1, 2.0, true,"hello",5.0,'a') );
00229 BOOST_CHECK_EQUAL( -8.0, h7.ret(1, 2.0, true,"hello",5.0,'a',7) );
00230
00231 BOOST_CHECK_EQUAL( -2.0, h1.ret() );
00232 BOOST_CHECK_EQUAL( -3.0, h2.ret() );
00233 BOOST_CHECK_EQUAL( -4.0, h3.ret() );
00234 BOOST_CHECK_EQUAL( -5.0, h4.ret() );
00235 BOOST_CHECK_EQUAL( -6.0, h5.ret() );
00236 BOOST_CHECK_EQUAL( -7.0, h6.ret() );
00237 BOOST_CHECK_EQUAL( -8.0, h7.ret() );
00238 }
00239
00240 BOOST_AUTO_TEST_CASE(testLocalOperationCallerFactory)
00241 {
00242
00243
00244
00245
00246 Operation<double(void)> m0("m0");
00247 m0.calls(&OperationsFixture::m0, this);
00248 Operation<double(int)> m1("m1");
00249 m1.calls(&OperationsFixture::m1, this);
00250 Operation<double(int,double)> m2("m2");
00251 m2.calls(&OperationsFixture::m2, this);
00252 BOOST_CHECK( !m0.ready() );
00253 BOOST_CHECK( !m1.ready() );
00254 BOOST_CHECK( !m2.ready() );
00255
00256
00257 Service::shared_ptr to = Service::Create("task");
00258
00259
00260 BOOST_CHECK( to->addLocalOperation(m0) );
00261 BOOST_CHECK( !m0.ready() );
00262
00263 to->setOwner(tc);
00264 BOOST_CHECK( m0.ready() );
00265
00266
00267 BOOST_CHECK( to->addLocalOperation(m0) );
00268 BOOST_CHECK( to->addLocalOperation(m0) );
00269 BOOST_CHECK( to->addLocalOperation(m1) );
00270 BOOST_CHECK( to->addLocalOperation(m2) );
00271
00272
00273 OperationCaller<double(void)> mm0 = to->getLocalOperation("m0");
00274 BOOST_CHECK( mm0.getOperationCallerImpl() );
00275 BOOST_CHECK( mm0.ready() );
00276
00277
00278 OperationCaller<double(int)> mm1;
00279 mm1 = to->getLocalOperation("m1");
00280 BOOST_CHECK( mm1.getOperationCallerImpl() );
00281 BOOST_CHECK( mm1.ready() );
00282
00283 OperationCaller<double(int,double)> mm2 = to->getLocalOperation("m2");
00284 BOOST_CHECK( mm2.getOperationCallerImpl() );
00285 BOOST_CHECK( mm2.ready() );
00286
00287
00288 BOOST_CHECK_EQUAL( -1.0, mm0() );
00289
00290 BOOST_CHECK_EQUAL( -2.0, mm1(1) );
00291 BOOST_CHECK_EQUAL( -3.0, mm2(1, 2.0) );
00292
00293
00294
00295 Operation<void(void)> ovoid("ovoid");
00296 BOOST_CHECK(to->addLocalOperation( ovoid ) == true);
00297 ovoid = Operation<void(void)>("ovoid");
00298 BOOST_CHECK(to->addLocalOperation( ovoid ) == true);
00299
00300
00301 OperationCaller<void(void)> mvoid;
00302 mvoid = to->getLocalOperation("m1");
00303 BOOST_CHECK( mvoid.ready() == false );
00304
00305 mvoid = to->getLocalOperation("m2");
00306 BOOST_CHECK( mvoid.ready() == false );
00307
00308 mvoid = to->getLocalOperation("m0");
00309 BOOST_CHECK( mvoid.ready() == false );
00310
00311 mvoid = to->getLocalOperation("voidm");
00312 BOOST_CHECK( mvoid.ready() == false );
00313
00314
00315 mvoid();
00316
00317 }
00318
00319 BOOST_AUTO_TEST_CASE(testRefAndConstRefOperationCallerCall_ClientThread)
00320 {
00321 this->ret = -3.3;
00322
00323 OperationCaller<double&(void)> m0r("m0r", &OperationsFixture::m0r, this, tc->engine(), caller->engine(), ClientThread );
00324 OperationCaller<const double&(void)> m0cr("m0cr", &OperationsFixture::m0cr, this, tc->engine(), caller->engine(), ClientThread );
00325
00326 OperationCaller<double(double&)> m1r("m1r", &OperationsFixture::m1r, this, tc->engine(), caller->engine(), ClientThread );
00327 OperationCaller<double(const double&)> m1cr("m1cr", &OperationsFixture::m1cr, this, tc->engine(), caller->engine(), ClientThread );
00328
00329 BOOST_CHECK_EQUAL( -3.3, m0r() );
00330 BOOST_CHECK_EQUAL( -3.3, m0cr() );
00331
00332 double value = 5.3;
00333 BOOST_CHECK_EQUAL( 5.3*2, m1r(value) );
00334 BOOST_CHECK_EQUAL( 5.3*2, value );
00335 BOOST_CHECK_EQUAL( 5.3, m1cr(5.3) );
00336 }
00337
00338 BOOST_AUTO_TEST_CASE(testRefAndConstRefOperationCallerCall_OwnThread)
00339 {
00340 this->ret = -3.3;
00341
00342 OperationCaller<double&(void)> m0r("m0r", &OperationsFixture::m0r, this,tc->engine(), caller->engine(), OwnThread);
00343 OperationCaller<const double&(void)> m0cr("m0cr", &OperationsFixture::m0cr, this,tc->engine(), caller->engine(), OwnThread);
00344
00345 OperationCaller<double(double&)> m1r("m1r", &OperationsFixture::m1r, this,tc->engine(), caller->engine(), OwnThread);
00346 OperationCaller<double(const double&)> m1cr("m1cr", &OperationsFixture::m1cr, this,tc->engine(), caller->engine(), OwnThread);
00347
00348 BOOST_CHECK_EQUAL( -3.3, m0r() );
00349 BOOST_CHECK_EQUAL( -3.3, m0cr() );
00350
00351 double value = 5.3;
00352 BOOST_CHECK_EQUAL( 5.3*2, m1r(value) );
00353 BOOST_CHECK_EQUAL( 5.3*2, value );
00354 BOOST_CHECK_EQUAL( 5.3, m1cr(5.3) );
00355 }
00356
00357 BOOST_AUTO_TEST_CASE(testDSOperationCaller)
00358 {
00359 ServicePtr to = Service::Create("task", tc);
00360
00361
00362
00363
00364
00365
00366 Operation<double(boost::shared_ptr<OperationsFixture>)> meth0("m0");
00367 meth0.calls( boost::bind(&OperationsFixture::m0, _1));
00368
00369
00370
00371 Operation<double(boost::shared_ptr<OperationsFixture>,int)> meth1("m1");
00372 meth1.calls(boost::bind(&OperationsFixture::m1, _1,_2));
00373
00374
00375
00376
00377 boost::shared_ptr<OperationsFixture> ptr( new OperationsFixture() );
00378 ValueDataSource<boost::shared_ptr<OperationsFixture> >::shared_ptr wp = new ValueDataSource<boost::shared_ptr<OperationsFixture> >( ptr );
00379 BOOST_CHECK( to->addOperationDS( wp.get(), meth0).doc("desc" ).ready() );
00380 BOOST_CHECK( to->addOperationDS( wp.get(), meth1).doc("desc").arg("a1", "d1" ).ready() );
00381
00382
00383
00384
00385 double ret;
00386 OperationCallerC c0 = to->create("m0", tc->engine()).ret(ret);
00387 BOOST_CHECK( c0.call() );
00388 BOOST_CHECK_EQUAL( -1.0, ret );
00389 OperationCallerC c1 = to->create("m1", tc->engine()).argC(1).ret(ret);
00390 BOOST_CHECK( c1.call() );
00391 BOOST_CHECK_EQUAL( -2.0, ret );
00392
00393 }
00394
00395 BOOST_AUTO_TEST_SUITE_END()