service_test.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: The SourceWorks  Tue Sep 7 00:54:57 CEST 2010  service_test.cpp
00003 
00004                         service_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 #include <TaskContext.hpp>
00022 #include <OperationCaller.hpp>
00023 #include <Operation.hpp>
00024 #include <Service.hpp>
00025 #include <ServiceRequester.hpp>
00026 
00027 #include "unit.hpp"
00028 #include "operations_fixture.hpp"
00029 
00030 // Registers the suite into the 'registry'
00031 BOOST_FIXTURE_TEST_SUITE(  ServiceTestSuite,  OperationsFixture )
00032 
00033 
00038 BOOST_AUTO_TEST_CASE(testClientThreadCall)
00039 {
00040     // Tests using no caller with methods (collect is not used).
00041     OperationCaller<double(void)> m0("m0");
00042     m0 = tc->provides("methods");
00043     OperationCaller<double(int)> m1("m1", tc->provides("methods"));
00044     OperationCaller<double(int,double)> m2( tc->provides("methods")->getOperation("m2") );
00045     OperationCaller<double(int,double,bool)> m3("m3", tc->provides("methods"));
00046     OperationCaller<double(int,double,bool,std::string)> m4("m4", tc->provides("methods"));
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 
00054     // Tests using a caller
00055     m0.setCaller( caller->engine() );
00056     m1.setCaller( caller->engine() );
00057     m2.setCaller( caller->engine() );
00058     m3.setCaller( caller->engine() );
00059     m4.setCaller( caller->engine() );
00060 
00061     BOOST_CHECK_EQUAL( -1.0, m0() );
00062     BOOST_CHECK_EQUAL( -2.0, m1(1) );
00063     BOOST_CHECK_EQUAL( -3.0, m2(1, 2.0) );
00064     BOOST_CHECK_EQUAL( -4.0, m3(1, 2.0, true) );
00065     BOOST_CHECK_EQUAL( -5.0, m4(1, 2.0, true,"hello") );
00066 
00067 }
00068 
00069 BOOST_AUTO_TEST_CASE(testOwnThreadOperationCallerCall)
00070 {
00071     // test using initial caller
00072     OperationCaller<double(void)> m0("o0", caller->engine() );
00073     m0 = tc->provides("methods");
00074     OperationCaller<double(int)> m1("o1", tc->provides("methods"), caller->engine() );
00075     OperationCaller<double(int,double)> m2( tc->provides("methods")->getOperation("o2"), caller->engine() );
00076     OperationCaller<double(int,double,bool)> m3("o3", tc->provides("methods"), caller->engine() );
00077     OperationCaller<double(int,double,bool,std::string)> m4("o4", tc->provides("methods"), caller->engine() );
00078 
00079     BOOST_REQUIRE( tc->isRunning() );
00080     BOOST_CHECK_EQUAL( -1.0, m0() );
00081     BOOST_CHECK_EQUAL( -2.0, m1(1) );
00082     BOOST_CHECK_EQUAL( -3.0, m2(1, 2.0) );
00083     BOOST_CHECK_EQUAL( -4.0, m3(1, 2.0, true) );
00084     BOOST_CHECK_EQUAL( -5.0, m4(1, 2.0, true,"hello") );
00085 
00086     // Tests using a caller
00087     m0.setCaller( caller->engine() );
00088     m1.setCaller( caller->engine() );
00089     m2.setCaller( caller->engine() );
00090     m3.setCaller( caller->engine() );
00091     m4.setCaller( caller->engine() );
00092 
00093     BOOST_REQUIRE( caller->isRunning() );
00094     BOOST_CHECK_EQUAL( -1.0, m0() );
00095     BOOST_CHECK_EQUAL( -2.0, m1(1) );
00096     BOOST_CHECK_EQUAL( -3.0, m2(1, 2.0) );
00097     BOOST_CHECK_EQUAL( -4.0, m3(1, 2.0, true) );
00098     BOOST_CHECK_EQUAL( -5.0, m4(1, 2.0, true,"hello") );
00099 }
00100 
00101 BOOST_AUTO_TEST_CASE(testClientThreadOperationCallerSend)
00102 {
00103     // test using initial caller
00104     OperationCaller<double(void)> m0("m0", caller->engine() );
00105     m0 = tc->provides("methods");
00106     OperationCaller<double(int)> m1("m1", tc->provides("methods"), caller->engine() );
00107     OperationCaller<double(int,double)> m2( tc->provides("methods")->getOperation("m2"), caller->engine() );
00108     OperationCaller<double(int,double,bool)> m3("m3", tc->provides("methods"), caller->engine() );
00109     OperationCaller<double(int,double,bool,std::string)> m4("m4", tc->provides("methods"), caller->engine() );
00110 
00111     BOOST_REQUIRE( tc->isRunning() );
00112     SendHandle<double(void)> h0 = m0.send();
00113     SendHandle<double(int)> h1 = m1.send(1);
00114     SendHandle<double(int,double)> h2 = m2.send(1, 2.0);
00115     SendHandle<double(int,double,bool)> h3 = m3.send(1, 2.0, true);
00116     SendHandle<double(int,double,bool,std::string)> h4 = m4.send(1, 2.0, true,"hello");
00117 
00118     double retn=0;
00119     BOOST_CHECK_EQUAL( SendSuccess, h0.collect(retn) );
00120     BOOST_CHECK_EQUAL( retn, -1.0 );
00121     BOOST_CHECK_EQUAL( SendSuccess, h1.collect(retn) );
00122     BOOST_CHECK_EQUAL( retn, -2.0 );
00123     BOOST_CHECK_EQUAL( SendSuccess, h2.collect(retn) );
00124     BOOST_CHECK_EQUAL( retn, -3.0 );
00125     BOOST_CHECK_EQUAL( SendSuccess, h3.collect(retn) );
00126     BOOST_CHECK_EQUAL( retn, -4.0 );
00127     BOOST_CHECK_EQUAL( SendSuccess, h4.collect(retn) );
00128     BOOST_CHECK_EQUAL( retn, -5.0 );
00129 
00130     // collectIfDone will certainly succeed after collect
00131     BOOST_CHECK_EQUAL( SendSuccess, h0.collectIfDone(retn) );
00132     BOOST_CHECK_EQUAL( retn, -1.0 );
00133     BOOST_CHECK_EQUAL( SendSuccess, h1.collectIfDone(retn) );
00134     BOOST_CHECK_EQUAL( retn, -2.0 );
00135     BOOST_CHECK_EQUAL( SendSuccess, h2.collectIfDone(retn) );
00136     BOOST_CHECK_EQUAL( retn, -3.0 );
00137     BOOST_CHECK_EQUAL( SendSuccess, h3.collectIfDone(retn) );
00138     BOOST_CHECK_EQUAL( retn, -4.0 );
00139     BOOST_CHECK_EQUAL( SendSuccess, h4.collectIfDone(retn) );
00140     BOOST_CHECK_EQUAL( retn, -5.0 );
00141 
00142     // the return value api.
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( -2.0, h1.ret() );
00149     BOOST_CHECK_EQUAL( -3.0, h2.ret() );
00150     BOOST_CHECK_EQUAL( -4.0, h3.ret() );
00151     BOOST_CHECK_EQUAL( -5.0, h4.ret() );
00152 
00153     // Tests using a caller
00154     m0.setCaller( caller->engine() );
00155     m1.setCaller( caller->engine() );
00156     m2.setCaller( caller->engine() );
00157     m3.setCaller( caller->engine() );
00158     m4.setCaller( caller->engine() );
00159 
00160     BOOST_REQUIRE( caller->isRunning() );
00161     BOOST_REQUIRE( tc->isRunning() );
00162     h0 = m0.send();
00163     h1 = m1.send(1);
00164     h2 = m2.send(1, 2.0);
00165     h3 = m3.send(1, 2.0, true);
00166     h4 = m4.send(1, 2.0, true,"hello");
00167 
00168     retn=0;
00169     BOOST_CHECK_EQUAL( SendSuccess, h0.collect(retn) );
00170     BOOST_CHECK_EQUAL( retn, -1.0 );
00171     BOOST_CHECK_EQUAL( SendSuccess, h1.collect(retn) );
00172     BOOST_CHECK_EQUAL( retn, -2.0 );
00173     BOOST_CHECK_EQUAL( SendSuccess, h2.collect(retn) );
00174     BOOST_CHECK_EQUAL( retn, -3.0 );
00175     BOOST_CHECK_EQUAL( SendSuccess, h3.collect(retn) );
00176     BOOST_CHECK_EQUAL( retn, -4.0 );
00177     BOOST_CHECK_EQUAL( SendSuccess, h4.collect(retn) );
00178     BOOST_CHECK_EQUAL( retn, -5.0 );
00179 
00180     // collectIfDone will certainly succeed after collect
00181     BOOST_CHECK_EQUAL( SendSuccess, h0.collectIfDone(retn) );
00182     BOOST_CHECK_EQUAL( retn, -1.0 );
00183     BOOST_CHECK_EQUAL( SendSuccess, h1.collectIfDone(retn) );
00184     BOOST_CHECK_EQUAL( retn, -2.0 );
00185     BOOST_CHECK_EQUAL( SendSuccess, h2.collectIfDone(retn) );
00186     BOOST_CHECK_EQUAL( retn, -3.0 );
00187     BOOST_CHECK_EQUAL( SendSuccess, h3.collectIfDone(retn) );
00188     BOOST_CHECK_EQUAL( retn, -4.0 );
00189     BOOST_CHECK_EQUAL( SendSuccess, h4.collectIfDone(retn) );
00190     BOOST_CHECK_EQUAL( retn, -5.0 );
00191 
00192     // the return value api.
00193     BOOST_CHECK_EQUAL( -1.0, h0.ret() );
00194     BOOST_CHECK_EQUAL( -2.0, h1.ret(1) );
00195     BOOST_CHECK_EQUAL( -3.0, h2.ret(1, 2.0) );
00196     BOOST_CHECK_EQUAL( -4.0, h3.ret(1, 2.0, true) );
00197     BOOST_CHECK_EQUAL( -5.0, h4.ret(1, 2.0, true,"hello") );
00198     BOOST_CHECK_EQUAL( -2.0, h1.ret() );
00199     BOOST_CHECK_EQUAL( -3.0, h2.ret() );
00200     BOOST_CHECK_EQUAL( -4.0, h3.ret() );
00201     BOOST_CHECK_EQUAL( -5.0, h4.ret() );
00202 }
00203 
00204 BOOST_AUTO_TEST_CASE(testOwnThreadOperationCallerSend)
00205 {
00206     // test using initial caller
00207     OperationCaller<double(void)> m0("o0", caller->engine() );
00208     m0 = tc->provides("methods");
00209     OperationCaller<double(int)> m1("o1", tc->provides("methods"), caller->engine() );
00210     OperationCaller<double(int,double)> m2( tc->provides("methods")->getOperation("o2"), caller->engine() );
00211     OperationCaller<double(int,double,bool)> m3("o3", tc->provides("methods"), caller->engine() );
00212     OperationCaller<double(int,double,bool,std::string)> m4("o4", tc->provides("methods"), caller->engine() );
00213 
00214     BOOST_REQUIRE( tc->isRunning() );
00215     SendHandle<double(void)> h0 = m0.send();
00216     SendHandle<double(int)> h1 = m1.send(1);
00217     SendHandle<double(int,double)> h2 = m2.send(1, 2.0);
00218     SendHandle<double(int,double,bool)> h3 = m3.send(1, 2.0, true);
00219     SendHandle<double(int,double,bool,std::string)> h4 = m4.send(1, 2.0, true,"hello");
00220 
00221     double retn=0;
00222     BOOST_CHECK_EQUAL( SendSuccess, h0.collect(retn) );
00223     BOOST_CHECK_EQUAL( retn, -1.0 );
00224     BOOST_CHECK_EQUAL( SendSuccess, h1.collect(retn) );
00225     BOOST_CHECK_EQUAL( retn, -2.0 );
00226     BOOST_CHECK_EQUAL( SendSuccess, h2.collect(retn) );
00227     BOOST_CHECK_EQUAL( retn, -3.0 );
00228     BOOST_CHECK_EQUAL( SendSuccess, h3.collect(retn) );
00229     BOOST_CHECK_EQUAL( retn, -4.0 );
00230     BOOST_CHECK_EQUAL( SendSuccess, h4.collect(retn) );
00231     BOOST_CHECK_EQUAL( retn, -5.0 );
00232 
00233     // collectIfDone will certainly succeed after collect
00234     BOOST_CHECK_EQUAL( SendSuccess, h0.collectIfDone(retn) );
00235     BOOST_CHECK_EQUAL( retn, -1.0 );
00236     BOOST_CHECK_EQUAL( SendSuccess, h1.collectIfDone(retn) );
00237     BOOST_CHECK_EQUAL( retn, -2.0 );
00238     BOOST_CHECK_EQUAL( SendSuccess, h2.collectIfDone(retn) );
00239     BOOST_CHECK_EQUAL( retn, -3.0 );
00240     BOOST_CHECK_EQUAL( SendSuccess, h3.collectIfDone(retn) );
00241     BOOST_CHECK_EQUAL( retn, -4.0 );
00242     BOOST_CHECK_EQUAL( SendSuccess, h4.collectIfDone(retn) );
00243     BOOST_CHECK_EQUAL( retn, -5.0 );
00244 
00245     // the return value api.
00246     BOOST_CHECK_EQUAL( -1.0, h0.ret() );
00247     BOOST_CHECK_EQUAL( -2.0, h1.ret(1) );
00248     BOOST_CHECK_EQUAL( -3.0, h2.ret(1, 2.0) );
00249     BOOST_CHECK_EQUAL( -4.0, h3.ret(1, 2.0, true) );
00250     BOOST_CHECK_EQUAL( -5.0, h4.ret(1, 2.0, true,"hello") );
00251     BOOST_CHECK_EQUAL( -2.0, h1.ret() );
00252     BOOST_CHECK_EQUAL( -3.0, h2.ret() );
00253     BOOST_CHECK_EQUAL( -4.0, h3.ret() );
00254     BOOST_CHECK_EQUAL( -5.0, h4.ret() );
00255 
00256     // Tests using a caller
00257     m0.setCaller( caller->engine() );
00258     m1.setCaller( caller->engine() );
00259     m2.setCaller( caller->engine() );
00260     m3.setCaller( caller->engine() );
00261     m4.setCaller( caller->engine() );
00262 
00263     BOOST_REQUIRE( caller->isRunning() );
00264     BOOST_REQUIRE( tc->isRunning() );
00265     h0 = m0.send();
00266     h1 = m1.send(1);
00267     h2 = m2.send(1, 2.0);
00268     h3 = m3.send(1, 2.0, true);
00269     h4 = m4.send(1, 2.0, true,"hello");
00270 
00271     retn=0;
00272     BOOST_CHECK_EQUAL( SendSuccess, h0.collect(retn) );
00273     BOOST_CHECK_EQUAL( retn, -1.0 );
00274     BOOST_CHECK_EQUAL( SendSuccess, h1.collect(retn) );
00275     BOOST_CHECK_EQUAL( retn, -2.0 );
00276     BOOST_CHECK_EQUAL( SendSuccess, h2.collect(retn) );
00277     BOOST_CHECK_EQUAL( retn, -3.0 );
00278     BOOST_CHECK_EQUAL( SendSuccess, h3.collect(retn) );
00279     BOOST_CHECK_EQUAL( retn, -4.0 );
00280     BOOST_CHECK_EQUAL( SendSuccess, h4.collect(retn) );
00281     BOOST_CHECK_EQUAL( retn, -5.0 );
00282 
00283     // collectIfDone will certainly succeed after collect
00284     BOOST_CHECK_EQUAL( SendSuccess, h0.collectIfDone(retn) );
00285     BOOST_CHECK_EQUAL( retn, -1.0 );
00286     BOOST_CHECK_EQUAL( SendSuccess, h1.collectIfDone(retn) );
00287     BOOST_CHECK_EQUAL( retn, -2.0 );
00288     BOOST_CHECK_EQUAL( SendSuccess, h2.collectIfDone(retn) );
00289     BOOST_CHECK_EQUAL( retn, -3.0 );
00290     BOOST_CHECK_EQUAL( SendSuccess, h3.collectIfDone(retn) );
00291     BOOST_CHECK_EQUAL( retn, -4.0 );
00292     BOOST_CHECK_EQUAL( SendSuccess, h4.collectIfDone(retn) );
00293     BOOST_CHECK_EQUAL( retn, -5.0 );
00294 
00295     // the return value api.
00296     BOOST_CHECK_EQUAL( -1.0, h0.ret() );
00297     BOOST_CHECK_EQUAL( -2.0, h1.ret(1) );
00298     BOOST_CHECK_EQUAL( -3.0, h2.ret(1, 2.0) );
00299     BOOST_CHECK_EQUAL( -4.0, h3.ret(1, 2.0, true) );
00300     BOOST_CHECK_EQUAL( -5.0, h4.ret(1, 2.0, true,"hello") );
00301     BOOST_CHECK_EQUAL( -2.0, h1.ret() );
00302     BOOST_CHECK_EQUAL( -3.0, h2.ret() );
00303     BOOST_CHECK_EQUAL( -4.0, h3.ret() );
00304     BOOST_CHECK_EQUAL( -5.0, h4.ret() );
00305 
00306 }
00307 
00308 BOOST_AUTO_TEST_CASE(testOwnThreadOperationCallerSend_ChangePolicy)
00309 {
00310     // Tests changing the policy later on
00311     OperationCaller<double(void)> m0("o0", caller->engine() );
00312 
00313     // set to ClientThread and send/collect it:
00314     tc->provides("methods")->setOperationThread("o0",ClientThread);
00315     m0 = tc->provides("methods");
00316 
00317     BOOST_REQUIRE( tc->isRunning() );
00318     SendHandle<double(void)> h0 = m0.send();
00319 
00320     double retn=0;
00321     BOOST_CHECK_EQUAL( SendSuccess, h0.collect(retn) );
00322     BOOST_CHECK_EQUAL( retn, -1.0 );
00323 
00324     // set to OwnThread and send/collect it:
00325     tc->provides("methods")->setOperationThread("o0",OwnThread);
00326     m0 = tc->provides("methods");
00327 
00328     BOOST_REQUIRE( tc->isRunning() );
00329     h0 = m0.send();
00330 
00331     retn = 0;
00332     BOOST_CHECK_EQUAL( SendSuccess, h0.collect(retn) );
00333     BOOST_CHECK_EQUAL( retn, -1.0 );
00334 }
00335 
00336 BOOST_AUTO_TEST_SUITE_END()


rtt
Author(s): RTT Developers
autogenerated on Sat Jun 8 2019 18:46:18