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 <iostream>
00024 #include <TaskContext.hpp>
00025 #include <OperationCaller.hpp>
00026 #include <Operation.hpp>
00027 #include <internal/RemoteOperationCaller.hpp>
00028 #include <Service.hpp>
00029
00030 #include "unit.hpp"
00031 #include "operations_fixture.hpp"
00032
00037 BOOST_FIXTURE_TEST_SUITE( RemoteOperationCallerTestSuite, OperationsFixture )
00038
00039 BOOST_AUTO_TEST_CASE(testRemoteOperationCaller)
00040 {
00041 OperationCaller<double(void)> m0("mo");
00042 boost::shared_ptr<DisposableInterface> implementation( new RemoteOperationCaller<double(void)>(tc->provides("methods")->getPart("m0"),"m0", caller->engine() ) );
00043 m0 = implementation;
00044 BOOST_CHECK( m0.ready() );
00045
00046 OperationCaller<double(int)> m1;
00047 implementation.reset( new RemoteOperationCaller<double(int)>(tc->provides("methods")->getPart("m1"),"m1", caller->engine()) );
00048 m1 = implementation;
00049 BOOST_CHECK( m1.ready() );
00050
00051 BOOST_CHECK_EQUAL( 2.0, m1(0) );
00052 BOOST_CHECK_EQUAL( -2.0, m1(1) );
00053 BOOST_CHECK_EQUAL( -1.0, m0() );
00054 }
00055
00056 BOOST_AUTO_TEST_CASE(testOperationCallerC_Call)
00057 {
00058 OperationCallerC mc;
00059 double r = 0.0;
00060 mc = tc->provides("methods")->create("m0", caller->engine()).ret( r );
00061 BOOST_CHECK( mc.call() );
00062 BOOST_CHECK_EQUAL( r, -1.0 );
00063
00064 mc = tc->provides("methods")->create("m2", caller->engine()).argC(1).argC(2.0).ret( r );
00065 BOOST_CHECK( mc.call() );
00066 BOOST_CHECK_EQUAL( r, -3.0 );
00067
00068 mc = tc->provides("methods")->create("m3", caller->engine()).ret( r ).argC(1).argC(2.0).argC(true);
00069 BOOST_CHECK( mc.call() );
00070 BOOST_CHECK( r == -4.0 );
00071
00072 mc = tc->provides("methods")->create("m4", caller->engine()).ret( r ).argC(1).argC(2.0).argC(true).argC(string("hello"));
00073 BOOST_CHECK( mc.call() );
00074 BOOST_CHECK( r == -5.0 );
00075
00076 mc = tc->provides("methods")->create("m5", caller->engine()).argC(1).argC(2.0).argC(true).argC(string("hello")).argC(5.0f).ret( r );
00077 BOOST_CHECK( mc.call() );
00078 BOOST_CHECK( r == -6.0 );
00079
00080 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');
00081 BOOST_CHECK( mc.call() );
00082 BOOST_CHECK( r == -7.0 );
00083
00084 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);
00085 BOOST_CHECK( mc.call() );
00086 BOOST_CHECK( r == -8.0 );
00087 }
00088
00089 BOOST_AUTO_TEST_CASE(testOperationCallerC_Send)
00090 {
00091 OperationCallerC mc;
00092 SendHandleC shc;
00093 double r = 0.0;
00094 double cr = 0.0;
00095 mc = tc->provides("methods")->create("m0", caller->engine()).ret( r );
00096 BOOST_CHECK_NO_THROW( mc.check() );
00097 shc = mc.send();
00098 shc.arg(cr);
00099 BOOST_CHECK( shc.ready() );
00100 BOOST_CHECK_NO_THROW( shc.check() );
00101
00102 BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
00103 BOOST_CHECK_EQUAL( r, 0.0 );
00104 BOOST_CHECK_EQUAL( cr, -1.0 );
00105
00106 mc = tc->provides("methods")->create("m2", caller->engine()).argC(1).argC(2.0).ret( r );
00107 BOOST_CHECK_NO_THROW( mc.check() );
00108 shc = mc.send();
00109 shc.arg(cr);
00110 BOOST_CHECK( shc.ready() );
00111 BOOST_CHECK_NO_THROW( shc.check() );
00112
00113 BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
00114 BOOST_CHECK_EQUAL( r, 0.0 );
00115 BOOST_CHECK_EQUAL( cr, -3.0 );
00116
00117 mc = tc->provides("methods")->create("m3", caller->engine()).ret( r ).argC(1).argC(2.0).argC(true);
00118 BOOST_CHECK_NO_THROW( mc.check() );
00119 shc = mc.send();
00120 shc.arg(cr);
00121 BOOST_CHECK( shc.ready() );
00122 BOOST_CHECK_NO_THROW( shc.check() );
00123
00124 BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
00125 BOOST_CHECK_EQUAL( r, 0.0 );
00126 BOOST_CHECK_EQUAL( cr, -4.0 );
00127
00128 mc = tc->provides("methods")->create("m4", caller->engine()).ret( r ).argC(1).argC(2.0).argC(true).argC(string("hello"));
00129 BOOST_CHECK_NO_THROW( mc.check() );
00130 shc = mc.send();
00131 shc.arg(cr);
00132 BOOST_CHECK( shc.ready() );
00133 BOOST_CHECK_NO_THROW( shc.check() );
00134
00135 BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
00136 BOOST_CHECK_EQUAL( r, 0.0 );
00137 BOOST_CHECK_EQUAL( cr, -5.0 );
00138
00139 mc = tc->provides("methods")->create("m5", caller->engine()).ret( r ).argC(1).argC(2.0).argC(true).argC(string("hello")).argC(5.0f);
00140 BOOST_CHECK_NO_THROW( mc.check() );
00141 shc = mc.send();
00142 shc.arg(cr);
00143 BOOST_CHECK( shc.ready() );
00144 BOOST_CHECK_NO_THROW( shc.check() );
00145
00146 BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
00147 BOOST_CHECK_EQUAL( r, 0.0 );
00148 BOOST_CHECK_EQUAL( cr, -6.0 );
00149
00150 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');
00151 BOOST_CHECK_NO_THROW( mc.check() );
00152 shc = mc.send();
00153 shc.arg(cr);
00154 BOOST_CHECK( shc.ready() );
00155 BOOST_CHECK_NO_THROW( shc.check() );
00156
00157 BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
00158 BOOST_CHECK_EQUAL( r, 0.0 );
00159 BOOST_CHECK_EQUAL( cr, -7.0 );
00160
00161 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);
00162 BOOST_CHECK_NO_THROW( mc.check() );
00163 shc = mc.send();
00164 shc.arg(cr);
00165 BOOST_CHECK( shc.ready() );
00166 BOOST_CHECK_NO_THROW( shc.check() );
00167
00168 BOOST_CHECK_EQUAL( shc.collect(), SendSuccess);
00169 BOOST_CHECK_EQUAL( r, 0.0 );
00170 BOOST_CHECK_EQUAL( cr, -8.0 );
00171 }
00172
00173 BOOST_AUTO_TEST_CASE(testOperationCallerFromDS)
00174 {
00175 ServicePtr sp = tc->provides("methods");
00176
00177 double ret;
00178 OperationCallerC mc0 = sp->create("m0", caller->engine() );
00179 mc0.ret(ret);
00180 OperationCallerC mc1 = sp->create("m1", caller->engine() );
00181 mc1.argC(1).ret(ret);
00182 OperationCallerC mc2 = sp->create("m2", caller->engine() );
00183 mc2.argC(1).argC(2.0).ret(ret);
00184 OperationCallerC mc3 = sp->create("m3", caller->engine() );
00185 mc3.argC(1).argC(2.0).argC(true).ret(ret);
00186 OperationCallerC mc4 = sp->create("m4", caller->engine() );
00187 mc4.argC(1).argC(2.0).argC(true).argC(std::string("hello")).ret(ret);
00188 OperationCallerC mc5 = sp->create("m5", caller->engine() );
00189 mc5.argC(1).argC(2.0).argC(true).argC(std::string("hello")).argC(5.0f).ret(ret);
00190 OperationCallerC mc6 = sp->create("m6", caller->engine() );
00191 mc6.argC(1).argC(2.0).argC(true).argC(std::string("hello")).argC(5.0f).argC('a').ret(ret);
00192 OperationCallerC mc7 = sp->create("m7", caller->engine() );
00193 mc7.argC(1).argC(2.0).argC(true).argC(std::string("hello")).argC(5.0f).argC('a').argC((unsigned int)7).ret(ret);
00194
00195 BOOST_CHECK( mc0.call() );
00196 BOOST_CHECK_EQUAL(-1.0, ret);
00197 BOOST_CHECK( mc1.call() );
00198 BOOST_CHECK_EQUAL(-2.0, ret);
00199 BOOST_CHECK( mc2.call() );
00200 BOOST_CHECK_EQUAL(-3.0, ret);
00201 BOOST_CHECK( mc3.call() );
00202 BOOST_CHECK_EQUAL(-4.0, ret);
00203 BOOST_CHECK( mc4.call() );
00204 BOOST_CHECK_EQUAL(-5.0, ret);
00205 BOOST_CHECK( mc5.call() );
00206 BOOST_CHECK_EQUAL(-6.0, ret);
00207 BOOST_CHECK( mc6.call() );
00208 BOOST_CHECK_EQUAL(-7.0, ret);
00209 BOOST_CHECK( mc7.call() );
00210 BOOST_CHECK_EQUAL(-8.0, ret);
00211 }
00212
00213 BOOST_AUTO_TEST_CASE(testRemoteOperationCallerFactory)
00214 {
00215
00216
00217
00218
00219 Operation<double(void)> m0("m0");
00220 m0.calls(&OperationsFixture::m0, this);
00221 Operation<double(int)> m1("m1");
00222 m1.calls(&OperationsFixture::m1, this);
00223 Operation<double(int,double)> m2("m2");
00224 m2.calls(&OperationsFixture::m2, this);
00225
00226 Service to("task");
00227
00228 BOOST_CHECK( !to.addOperation(m0).ready() );
00229 to.setOwner(tc);
00230 BOOST_CHECK( to.addOperation(m0).ready() );
00231 BOOST_CHECK( to.addOperation(m0).ready() );
00232 BOOST_CHECK( to.addOperation(m1).ready() );
00233 BOOST_CHECK( to.addOperation(m2).ready() );
00234
00235
00236 OperationCaller<double(void)> mm0 = to.getOperation("m0");
00237 BOOST_CHECK( mm0.getOperationCallerImpl() );
00238 BOOST_CHECK( mm0.ready() );
00239
00240
00241 OperationCaller<double(int)> mm1;
00242 mm1 = to.getOperation("m1");
00243 BOOST_CHECK( mm1.getOperationCallerImpl() );
00244 BOOST_CHECK( mm1.ready() );
00245
00246 OperationCaller<double(int,double)> mm2 = to.getOperation("m2");
00247 BOOST_CHECK( mm2.getOperationCallerImpl() );
00248 BOOST_CHECK( mm2.ready() );
00249
00250
00251 BOOST_CHECK_EQUAL( -1.0, mm0() );
00252
00253 BOOST_CHECK_EQUAL( -2.0, mm1(1) );
00254 BOOST_CHECK_EQUAL( -3.0, mm2(1, 2.0) );
00255
00256
00257 Operation<void(void)> ovoid("ovoid");
00258 BOOST_CHECK(to.addOperation( ovoid ).ready() == true);
00259 ovoid = Operation<void(void)>("ovoid");
00260 BOOST_CHECK(to.addOperation( ovoid ).ready() == true);
00261
00262
00263 OperationCaller<void(void)> mvoid;
00264 mvoid = to.getOperation("m1");
00265 BOOST_CHECK( mvoid.ready() == false );
00266
00267 mvoid = to.getOperation("m2");
00268 BOOST_CHECK( mvoid.ready() == false );
00269
00270 mvoid = to.getOperation("m0");
00271 BOOST_CHECK( mvoid.ready() == true );
00272
00273 mvoid = to.getOperation("voidm");
00274 BOOST_CHECK( mvoid.ready() == false );
00275
00276
00277 mvoid();
00278
00279 }
00280
00281 BOOST_AUTO_TEST_SUITE_END()