$search
00001 /*************************************************************************** 00002 tag: The SourceWorks Tue Sep 7 00:54:57 CEST 2010 method_test.cpp 00003 00004 method_test.cpp - description 00005 ------------------- 00006 begin : Tue September 07 2010 00007 copyright : (C) 2010 The SourceWorks 00008 email : peter@thesourceworks.com 00009 00010 *************************************************************************** 00011 * * 00012 * This program is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU General Public License as published by * 00014 * the Free Software Foundation; either version 2 of the License, or * 00015 * (at your option) any later version. * 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 // Tests using no caller, no sender 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 OperationCaller<void(void)> m0e("m0except", &OperationsFixture::m0except, this); 00049 00050 BOOST_CHECK_EQUAL( -1.0, m0() ); 00051 BOOST_CHECK_EQUAL( -2.0, m1(1) ); 00052 BOOST_CHECK_EQUAL( -3.0, m2(1, 2.0) ); 00053 BOOST_CHECK_EQUAL( -4.0, m3(1, 2.0, true) ); 00054 BOOST_CHECK_EQUAL( -5.0, m4(1, 2.0, true,"hello") ); 00055 BOOST_CHECK_EQUAL( -6.0, m5(1, 2.0, true,"hello",5.0) ); 00056 BOOST_CHECK_EQUAL( -7.0, m6(1, 2.0, true,"hello",5.0,'a') ); 00057 BOOST_CHECK_EQUAL( -8.0, m7(1, 2.0, true,"hello",5.0,'a',7) ); 00058 00059 BOOST_CHECK_THROW(m0e(), std::runtime_error); 00060 } 00061 00062 BOOST_AUTO_TEST_CASE(testOwnThreadOperationCallerCall) 00063 { 00064 // Tests using caller and sender 00065 OperationCaller<double(void)> m0("m0", &OperationsFixture::m0, this, tc->engine(), caller->engine(), OwnThread); 00066 OperationCaller<double(int)> m1("m1", &OperationsFixture::m1, this, tc->engine(), caller->engine(), OwnThread); 00067 OperationCaller<double(int,double)> m2("m2", &OperationsFixture::m2, this, tc->engine(), caller->engine(), OwnThread); 00068 OperationCaller<double(int,double,bool)> m3("m3", &OperationsFixture::m3, this, tc->engine(), caller->engine(), OwnThread); 00069 OperationCaller<double(int,double,bool,std::string)> m4("m4", &OperationsFixture::m4, this, tc->engine(), caller->engine(), OwnThread); 00070 OperationCaller<double(int,double,bool,std::string,float)> m5("m5", &OperationsFixture::m5, this, tc->engine(), caller->engine(), OwnThread); 00071 OperationCaller<double(int,double,bool,std::string,float,char)> m6("m6", &OperationsFixture::m6, this, tc->engine(), caller->engine(), OwnThread); 00072 OperationCaller<double(int,double,bool,std::string,float,char,unsigned int)> m7("m7", &OperationsFixture::m7, this, tc->engine(), caller->engine(), OwnThread); 00073 00074 OperationCaller<void(void)> m0e("m0except", &OperationsFixture::m0except, this, tc->engine(), caller->engine(), OwnThread); 00075 00076 BOOST_REQUIRE( tc->isRunning() ); 00077 BOOST_REQUIRE( caller->isRunning() ); 00078 BOOST_CHECK_EQUAL( -1.0, m0() ); 00079 BOOST_CHECK_EQUAL( -2.0, m1(1) ); 00080 BOOST_CHECK_EQUAL( -3.0, m2(1, 2.0) ); 00081 BOOST_CHECK_EQUAL( -4.0, m3(1, 2.0, true) ); 00082 BOOST_CHECK_EQUAL( -5.0, m4(1, 2.0, true,"hello") ); 00083 BOOST_CHECK_EQUAL( -6.0, m5(1, 2.0, true,"hello",5.0) ); 00084 BOOST_CHECK_EQUAL( -7.0, m6(1, 2.0, true,"hello",5.0,'a') ); 00085 BOOST_CHECK_EQUAL( -8.0, m7(1, 2.0, true,"hello",5.0,'a',7) ); 00086 00087 BOOST_CHECK_THROW( m0e(), std::runtime_error); 00088 BOOST_REQUIRE( tc->inException() ); 00089 } 00090 00091 BOOST_AUTO_TEST_CASE(testClientThreadOperationCallerSend) 00092 { 00093 // we set the owner engine to zero and our caller engine to be able to send. 00094 OperationCaller<double(void)> m0("m0", &OperationsFixture::m0, this, 0, caller->engine()); 00095 OperationCaller<double(int)> m1("m1", &OperationsFixture::m1, this, 0, caller->engine()); 00096 OperationCaller<double(int,double)> m2("m2", &OperationsFixture::m2, this, 0, caller->engine()); 00097 OperationCaller<double(int,double,bool)> m3("m3", &OperationsFixture::m3, this, 0, caller->engine()); 00098 OperationCaller<double(int,double,bool,std::string)> m4("m4", &OperationsFixture::m4, this, 0, caller->engine()); 00099 OperationCaller<double(int,double,bool,std::string,float)> m5("m5", &OperationsFixture::m5, this, 0, caller->engine()); 00100 OperationCaller<double(int,double,bool,std::string,float,char)> m6("m6", &OperationsFixture::m6, this, 0, caller->engine()); 00101 OperationCaller<double(int,double,bool,std::string,float,char,unsigned int)> m7("m7", &OperationsFixture::m7, this, 0, caller->engine()); 00102 00103 OperationCaller<void(void)> m0e("m0except", &OperationsFixture::m0except, this, 0, caller->engine()); 00104 00105 00106 BOOST_REQUIRE( tc->isRunning() ); 00107 BOOST_REQUIRE( caller->isRunning() ); 00108 SendHandle<double(void)> h0 = m0.send(); 00109 SendHandle<double(int)> h1 = m1.send(1); 00110 SendHandle<double(int,double)> h2 = m2.send(1, 2.0); 00111 SendHandle<double(int,double,bool)> h3 = m3.send(1, 2.0, true); 00112 SendHandle<double(int,double,bool,std::string)> h4 = m4.send(1, 2.0, true,"hello"); 00113 SendHandle<double(int,double,bool,std::string,float)> h5 = m5.send(1, 2.0, true,"hello",5.0); 00114 SendHandle<double(int,double,bool,std::string,float,char)> h6 = m6.send(1, 2.0, true,"hello",5.0,'a'); 00115 SendHandle<double(int,double,bool,std::string,float,char,unsigned int)> h7 = m7.send(1, 2.0, true,"hello",5.0,'a',7); 00116 00117 SendHandle<void(void)> h0e = m0e.send(); 00118 00119 double retn=0; 00120 BOOST_CHECK_EQUAL( SendSuccess, h0.collect(retn) ); 00121 BOOST_CHECK_EQUAL( retn, -1.0 ); 00122 BOOST_CHECK_EQUAL( SendSuccess, h1.collect(retn) ); 00123 BOOST_CHECK_EQUAL( retn, -2.0 ); 00124 BOOST_CHECK_EQUAL( SendSuccess, h2.collect(retn) ); 00125 BOOST_CHECK_EQUAL( retn, -3.0 ); 00126 BOOST_CHECK_EQUAL( SendSuccess, h3.collect(retn) ); 00127 BOOST_CHECK_EQUAL( retn, -4.0 ); 00128 BOOST_CHECK_EQUAL( SendSuccess, h4.collect(retn) ); 00129 BOOST_CHECK_EQUAL( retn, -5.0 ); 00130 BOOST_CHECK_EQUAL( SendSuccess, h5.collect(retn) ); 00131 BOOST_CHECK_EQUAL( retn, -6.0 ); 00132 BOOST_CHECK_EQUAL( SendSuccess, h6.collect(retn) ); 00133 BOOST_CHECK_EQUAL( retn, -7.0 ); 00134 BOOST_CHECK_EQUAL( SendSuccess, h7.collect(retn) ); 00135 BOOST_CHECK_EQUAL( retn, -8.0 ); 00136 00137 BOOST_CHECK_THROW( h0e.collect(), std::runtime_error); 00138 00139 // collectIfDone will certainly succeed after collect 00140 BOOST_CHECK_EQUAL( SendSuccess, h0.collectIfDone(retn) ); 00141 BOOST_CHECK_EQUAL( retn, -1.0 ); 00142 BOOST_CHECK_EQUAL( SendSuccess, h1.collectIfDone(retn) ); 00143 BOOST_CHECK_EQUAL( retn, -2.0 ); 00144 BOOST_CHECK_EQUAL( SendSuccess, h2.collectIfDone(retn) ); 00145 BOOST_CHECK_EQUAL( retn, -3.0 ); 00146 BOOST_CHECK_EQUAL( SendSuccess, h3.collectIfDone(retn) ); 00147 BOOST_CHECK_EQUAL( retn, -4.0 ); 00148 BOOST_CHECK_EQUAL( SendSuccess, h4.collectIfDone(retn) ); 00149 BOOST_CHECK_EQUAL( retn, -5.0 ); 00150 BOOST_CHECK_EQUAL( SendSuccess, h5.collectIfDone(retn) ); 00151 BOOST_CHECK_EQUAL( retn, -6.0 ); 00152 BOOST_CHECK_EQUAL( SendSuccess, h6.collectIfDone(retn) ); 00153 BOOST_CHECK_EQUAL( retn, -7.0 ); 00154 BOOST_CHECK_EQUAL( SendSuccess, h7.collectIfDone(retn) ); 00155 BOOST_CHECK_EQUAL( retn, -8.0 ); 00156 00157 BOOST_CHECK_THROW( h0e.collectIfDone(), std::runtime_error); 00158 00159 // the return value api. 00160 BOOST_CHECK_EQUAL( -1.0, h0.ret() ); 00161 BOOST_CHECK_EQUAL( -2.0, h1.ret(1) ); 00162 BOOST_CHECK_EQUAL( -3.0, h2.ret(1, 2.0) ); 00163 BOOST_CHECK_EQUAL( -4.0, h3.ret(1, 2.0, true) ); 00164 BOOST_CHECK_EQUAL( -5.0, h4.ret(1, 2.0, true,"hello") ); 00165 BOOST_CHECK_EQUAL( -6.0, h5.ret(1, 2.0, true,"hello",5.0) ); 00166 BOOST_CHECK_EQUAL( -7.0, h6.ret(1, 2.0, true,"hello",5.0,'a') ); 00167 BOOST_CHECK_EQUAL( -8.0, h7.ret(1, 2.0, true,"hello",5.0,'a',7) ); 00168 00169 BOOST_CHECK_THROW( h0e.ret(), std::runtime_error); 00170 00171 BOOST_CHECK_EQUAL( -2.0, h1.ret() ); 00172 BOOST_CHECK_EQUAL( -3.0, h2.ret() ); 00173 BOOST_CHECK_EQUAL( -4.0, h3.ret() ); 00174 BOOST_CHECK_EQUAL( -5.0, h4.ret() ); 00175 BOOST_CHECK_EQUAL( -6.0, h5.ret() ); 00176 BOOST_CHECK_EQUAL( -7.0, h6.ret() ); 00177 BOOST_CHECK_EQUAL( -8.0, h7.ret() ); 00178 } 00179 00180 BOOST_AUTO_TEST_CASE(testOwnThreadOperationCallerSend) 00181 { 00182 OperationCaller<double(void)> m0("m0", &OperationsFixture::m0, this, tc->engine(), caller->engine(), OwnThread); 00183 OperationCaller<double(int)> m1("m1", &OperationsFixture::m1, this, tc->engine(), caller->engine(), OwnThread); 00184 OperationCaller<double(int,double)> m2("m2", &OperationsFixture::m2, this, tc->engine(), caller->engine(), OwnThread); 00185 OperationCaller<double(int,double,bool)> m3("m3", &OperationsFixture::m3, this, tc->engine(), caller->engine(), OwnThread); 00186 OperationCaller<double(int,double,bool,std::string)> m4("m4", &OperationsFixture::m4, this, tc->engine(), caller->engine(), OwnThread); 00187 OperationCaller<double(int,double,bool,std::string,float)> m5("m5", &OperationsFixture::m5, this, tc->engine(), caller->engine(), OwnThread); 00188 OperationCaller<double(int,double,bool,std::string,float,char)> m6("m6", &OperationsFixture::m6, this, tc->engine(), caller->engine(), OwnThread); 00189 OperationCaller<double(int,double,bool,std::string,float,char,unsigned int)> m7("m7", &OperationsFixture::m7, this, tc->engine(), caller->engine(), OwnThread); 00190 00191 OperationCaller<void(void)> m0e("m0except", &OperationsFixture::m0except, this, tc->engine(), caller->engine(), OwnThread); 00192 00193 BOOST_REQUIRE( tc->isRunning() ); 00194 BOOST_REQUIRE( caller->isRunning() ); 00195 SendHandle<double(void)> h0 = m0.send(); 00196 SendHandle<double(int)> h1 = m1.send(1); 00197 SendHandle<double(int,double)> h2 = m2.send(1, 2.0); 00198 SendHandle<double(int,double,bool)> h3 = m3.send(1, 2.0, true); 00199 SendHandle<double(int,double,bool,std::string)> h4 = m4.send(1, 2.0, true,"hello"); 00200 SendHandle<double(int,double,bool,std::string,float)> h5 = m5.send(1, 2.0, true,"hello",5.0); 00201 SendHandle<double(int,double,bool,std::string,float,char)> h6 = m6.send(1, 2.0, true,"hello",5.0,'a'); 00202 SendHandle<double(int,double,bool,std::string,float,char,unsigned int)> h7 = m7.send(1, 2.0, true,"hello",5.0,'a',7); 00203 00204 SendHandle<void(void)> h0e = m0e.send(); 00205 00206 double retn=0; 00207 BOOST_CHECK_EQUAL( SendSuccess, h0.collect(retn) ); 00208 BOOST_CHECK_EQUAL( retn, -1.0 ); 00209 BOOST_CHECK_EQUAL( SendSuccess, h1.collect(retn) ); 00210 BOOST_CHECK_EQUAL( retn, -2.0 ); 00211 BOOST_CHECK_EQUAL( SendSuccess, h2.collect(retn) ); 00212 BOOST_CHECK_EQUAL( retn, -3.0 ); 00213 BOOST_CHECK_EQUAL( SendSuccess, h3.collect(retn) ); 00214 BOOST_CHECK_EQUAL( retn, -4.0 ); 00215 BOOST_CHECK_EQUAL( SendSuccess, h4.collect(retn) ); 00216 BOOST_CHECK_EQUAL( retn, -5.0 ); 00217 BOOST_CHECK_EQUAL( SendSuccess, h5.collect(retn) ); 00218 BOOST_CHECK_EQUAL( retn, -6.0 ); 00219 BOOST_CHECK_EQUAL( SendSuccess, h6.collect(retn) ); 00220 BOOST_CHECK_EQUAL( retn, -7.0 ); 00221 BOOST_CHECK_EQUAL( SendSuccess, h7.collect(retn) ); 00222 BOOST_CHECK_EQUAL( retn, -8.0 ); 00223 00224 BOOST_CHECK_THROW( h0e.collect(), std::runtime_error); 00225 BOOST_REQUIRE( tc->inException() ); 00226 BOOST_REQUIRE( tc->recover() && tc->start() ); 00227 BOOST_REQUIRE( tc->isRunning() ); 00228 00229 // collectIfDone will certainly succeed after collect 00230 BOOST_CHECK_EQUAL( SendSuccess, h0.collectIfDone(retn) ); 00231 BOOST_CHECK_EQUAL( retn, -1.0 ); 00232 BOOST_CHECK_EQUAL( SendSuccess, h1.collectIfDone(retn) ); 00233 BOOST_CHECK_EQUAL( retn, -2.0 ); 00234 BOOST_CHECK_EQUAL( SendSuccess, h2.collectIfDone(retn) ); 00235 BOOST_CHECK_EQUAL( retn, -3.0 ); 00236 BOOST_CHECK_EQUAL( SendSuccess, h3.collectIfDone(retn) ); 00237 BOOST_CHECK_EQUAL( retn, -4.0 ); 00238 BOOST_CHECK_EQUAL( SendSuccess, h4.collectIfDone(retn) ); 00239 BOOST_CHECK_EQUAL( retn, -5.0 ); 00240 BOOST_CHECK_EQUAL( SendSuccess, h5.collectIfDone(retn) ); 00241 BOOST_CHECK_EQUAL( retn, -6.0 ); 00242 BOOST_CHECK_EQUAL( SendSuccess, h6.collectIfDone(retn) ); 00243 BOOST_CHECK_EQUAL( retn, -7.0 ); 00244 BOOST_CHECK_EQUAL( SendSuccess, h7.collectIfDone(retn) ); 00245 BOOST_CHECK_EQUAL( retn, -8.0 ); 00246 00247 BOOST_CHECK_THROW( h0e.collectIfDone(), std::runtime_error); 00248 // since tc has recover, it must be running 00249 BOOST_REQUIRE( tc->isRunning() ); 00250 00251 // the return value api. 00252 BOOST_CHECK_EQUAL( -1.0, h0.ret() ); 00253 BOOST_CHECK_EQUAL( -2.0, h1.ret(1) ); 00254 BOOST_CHECK_EQUAL( -3.0, h2.ret(1, 2.0) ); 00255 BOOST_CHECK_EQUAL( -4.0, h3.ret(1, 2.0, true) ); 00256 BOOST_CHECK_EQUAL( -5.0, h4.ret(1, 2.0, true,"hello") ); 00257 BOOST_CHECK_EQUAL( -6.0, h5.ret(1, 2.0, true,"hello",5.0) ); 00258 BOOST_CHECK_EQUAL( -7.0, h6.ret(1, 2.0, true,"hello",5.0,'a') ); 00259 BOOST_CHECK_EQUAL( -8.0, h7.ret(1, 2.0, true,"hello",5.0,'a',7) ); 00260 00261 BOOST_CHECK_THROW( h0e.ret(), std::runtime_error); 00262 BOOST_REQUIRE( tc->isRunning() ); 00263 00264 BOOST_CHECK_EQUAL( -2.0, h1.ret() ); 00265 BOOST_CHECK_EQUAL( -3.0, h2.ret() ); 00266 BOOST_CHECK_EQUAL( -4.0, h3.ret() ); 00267 BOOST_CHECK_EQUAL( -5.0, h4.ret() ); 00268 BOOST_CHECK_EQUAL( -6.0, h5.ret() ); 00269 BOOST_CHECK_EQUAL( -7.0, h6.ret() ); 00270 BOOST_CHECK_EQUAL( -8.0, h7.ret() ); 00271 } 00272 00273 BOOST_AUTO_TEST_CASE(testLocalOperationCallerFactory) 00274 { 00275 // Test the addition of 'simple' operationCallers to the operation interface, 00276 // and retrieving it back in a new OperationCaller object. 00277 // local operations do not use the remoting facility. 00278 00279 Operation<double(void)> m0("m0"); 00280 m0.calls(&OperationsFixture::m0, this); 00281 Operation<double(int)> m1("m1"); 00282 m1.calls(&OperationsFixture::m1, this); 00283 Operation<double(int,double)> m2("m2"); 00284 m2.calls(&OperationsFixture::m2, this); 00285 BOOST_CHECK( !m0.ready() ); 00286 BOOST_CHECK( !m1.ready() ); 00287 BOOST_CHECK( !m2.ready() ); 00288 00289 // We deliberately omit the owner 'tc' here: 00290 Service::shared_ptr to = Service::Create("task"); 00291 00292 // allow to add an operation even if no owner is set. 00293 BOOST_CHECK( to->addLocalOperation(m0) ); 00294 BOOST_CHECK( !m0.ready() ); 00295 // now set the owner and check the op: 00296 to->setOwner(tc); 00297 BOOST_CHECK( m0.ready() ); 00298 00299 // Overriding and adding: 00300 BOOST_CHECK( to->addLocalOperation(m0) ); 00301 BOOST_CHECK( to->addLocalOperation(m0) ); 00302 BOOST_CHECK( to->addLocalOperation(m1) ); 00303 BOOST_CHECK( to->addLocalOperation(m2) ); 00304 00305 // test constructor 00306 OperationCaller<double(void)> mm0 = to->getLocalOperation("m0"); 00307 BOOST_CHECK( mm0.getOperationCallerImpl() ); 00308 BOOST_CHECK( mm0.ready() ); 00309 00310 // test operator=() 00311 OperationCaller<double(int)> mm1; 00312 mm1 = to->getLocalOperation("m1"); 00313 BOOST_CHECK( mm1.getOperationCallerImpl() ); 00314 BOOST_CHECK( mm1.ready() ); 00315 00316 OperationCaller<double(int,double)> mm2 = to->getLocalOperation("m2"); 00317 BOOST_CHECK( mm2.getOperationCallerImpl() ); 00318 BOOST_CHECK( mm2.ready() ); 00319 00320 // execute operationCallers and check status: 00321 BOOST_CHECK_EQUAL( -1.0, mm0() ); 00322 00323 BOOST_CHECK_EQUAL( -2.0, mm1(1) ); 00324 BOOST_CHECK_EQUAL( -3.0, mm2(1, 2.0) ); 00325 00326 // test error cases: 00327 // Add uninitialised op: 00328 Operation<void(void)> ovoid("ovoid"); 00329 BOOST_CHECK(to->addLocalOperation( ovoid ) == true); 00330 ovoid = Operation<void(void)>("ovoid"); 00331 BOOST_CHECK(to->addLocalOperation( ovoid ) == true); 00332 00333 // wrong type 1: 00334 OperationCaller<void(void)> mvoid; 00335 mvoid = to->getLocalOperation("m1"); 00336 BOOST_CHECK( mvoid.ready() == false ); 00337 // wrong type 2: 00338 mvoid = to->getLocalOperation("m2"); 00339 BOOST_CHECK( mvoid.ready() == false ); 00340 // wrong type 3: 00341 mvoid = to->getLocalOperation("m0"); 00342 BOOST_CHECK( mvoid.ready() == false ); 00343 // non existing 00344 mvoid = to->getLocalOperation("voidm"); 00345 BOOST_CHECK( mvoid.ready() == false ); 00346 00347 // this line may not crash: 00348 mvoid(); 00349 00350 } 00351 00352 BOOST_AUTO_TEST_CASE(testRefAndConstRefOperationCallerCall_ClientThread) 00353 { 00354 this->ret = -3.3; 00355 00356 OperationCaller<double&(void)> m0r("m0r", &OperationsFixture::m0r, this, tc->engine(), caller->engine(), ClientThread ); 00357 OperationCaller<const double&(void)> m0cr("m0cr", &OperationsFixture::m0cr, this, tc->engine(), caller->engine(), ClientThread ); 00358 00359 OperationCaller<double(double&)> m1r("m1r", &OperationsFixture::m1r, this, tc->engine(), caller->engine(), ClientThread ); 00360 OperationCaller<double(const double&)> m1cr("m1cr", &OperationsFixture::m1cr, this, tc->engine(), caller->engine(), ClientThread ); 00361 00362 BOOST_CHECK_EQUAL( -3.3, m0r() ); 00363 BOOST_CHECK_EQUAL( -3.3, m0cr() ); 00364 00365 double value = 5.3; 00366 BOOST_CHECK_EQUAL( 5.3*2, m1r(value) ); 00367 BOOST_CHECK_EQUAL( 5.3*2, value ); 00368 BOOST_CHECK_EQUAL( 5.3, m1cr(5.3) ); 00369 } 00370 00371 BOOST_AUTO_TEST_CASE(testRefAndConstRefOperationCallerCall_OwnThread) 00372 { 00373 this->ret = -3.3; 00374 00375 OperationCaller<double&(void)> m0r("m0r", &OperationsFixture::m0r, this,tc->engine(), caller->engine(), OwnThread); 00376 OperationCaller<const double&(void)> m0cr("m0cr", &OperationsFixture::m0cr, this,tc->engine(), caller->engine(), OwnThread); 00377 00378 OperationCaller<double(double&)> m1r("m1r", &OperationsFixture::m1r, this,tc->engine(), caller->engine(), OwnThread); 00379 OperationCaller<double(const double&)> m1cr("m1cr", &OperationsFixture::m1cr, this,tc->engine(), caller->engine(), OwnThread); 00380 00381 BOOST_CHECK_EQUAL( -3.3, m0r() ); 00382 BOOST_CHECK_EQUAL( -3.3, m0cr() ); 00383 00384 double value = 5.3; 00385 BOOST_CHECK_EQUAL( 5.3*2, m1r(value) ); 00386 BOOST_CHECK_EQUAL( 5.3*2, value ); 00387 BOOST_CHECK_EQUAL( 5.3, m1cr(5.3) ); 00388 } 00389 00390 BOOST_AUTO_TEST_CASE(testDSOperationCaller) 00391 { 00392 ServicePtr to = Service::Create("task", tc); 00393 00394 // A operationCaller of which the first argument type is a pointer to the object 00395 // on which it must be invoked. The pointer is internally stored as a weak_ptr, 00396 // thus the object must be stored in a shared_ptr, in a DataSource. Scripting 00397 // requires this for copying state machines. 00398 00399 Operation<double(boost::shared_ptr<OperationsFixture>)> meth0("m0"); 00400 meth0.calls( boost::bind(&OperationsFixture::m0, _1)); 00401 00402 //method_ds("m0", &OperationsFixture::m0); 00403 00404 Operation<double(boost::shared_ptr<OperationsFixture>,int)> meth1("m1"); 00405 meth1.calls(boost::bind(&OperationsFixture::m1, _1,_2)); 00406 00407 //method_ds("m1", &OperationsFixture::m1); 00408 //method_ds("ms",&OperationsFixture::comstr ); 00409 00410 boost::shared_ptr<OperationsFixture> ptr( new OperationsFixture() ); 00411 ValueDataSource<boost::shared_ptr<OperationsFixture> >::shared_ptr wp = new ValueDataSource<boost::shared_ptr<OperationsFixture> >( ptr ); 00412 BOOST_CHECK( to->addOperationDS( wp.get(), meth0).doc("desc" ).ready() ); 00413 BOOST_CHECK( to->addOperationDS( wp.get(), meth1).doc("desc").arg("a1", "d1" ).ready() ); 00414 00415 // this actually works ! the operationCaller will detect the deleted pointer. 00416 //ptr.reset(); 00417 00418 double ret; 00419 OperationCallerC c0 = to->create("m0", tc->engine()).ret(ret); 00420 BOOST_CHECK( c0.call() ); 00421 BOOST_CHECK_EQUAL( -1.0, ret ); 00422 OperationCallerC c1 = to->create("m1", tc->engine()).argC(1).ret(ret); 00423 BOOST_CHECK( c1.call() ); 00424 BOOST_CHECK_EQUAL( -2.0, ret ); 00425 00426 } 00427 00428 BOOST_AUTO_TEST_SUITE_END()