00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "unit.hpp"
00020
00021 #include <iostream>
00022 #include <scripting/FunctionGraph.hpp>
00023 #include <OperationCaller.hpp>
00024 #include <extras/SimulationActivity.hpp>
00025 #include <extras/SimulationThread.hpp>
00026 #include <Service.hpp>
00027 #include <TaskContext.hpp>
00028 #include <scripting/ScriptingService.hpp>
00029 #include <scripting/Parser.hpp>
00030 #include <Service.hpp>
00031 #include <types/GlobalsRepository.hpp>
00032 #include <types/Types.hpp>
00033 #include <types/StructTypeInfo.hpp>
00034 #include <types/SequenceTypeInfo.hpp>
00035
00036 #include "datasource_fixture.hpp"
00037 #include "operations_fixture.hpp"
00038
00039 using namespace std;
00040 using namespace RTT;
00041 using namespace RTT::detail;
00042
00043 class TypesTest : public OperationsFixture
00044 {
00045 public:
00046 Parser parser;
00047 ScriptingService::shared_ptr sa;
00048 void executePrograms(const std::string& prog);
00049 void executeStates(const std::string& state);
00050
00051 TypesTest()
00052 : sa( ScriptingService::Create(tc) )
00053 {
00054 tc->stop();
00055 BOOST_REQUIRE( tc->setActivity(new SimulationActivity(0.01)) );
00056 BOOST_REQUIRE( tc->start() );
00057 SimulationThread::Instance()->stop();
00058 }
00059 ~TypesTest(){
00060 }
00061 };
00062
00063
00064
00065 BOOST_FIXTURE_TEST_SUITE( TypesTestSuite, TypesTest )
00066
00067
00068 BOOST_AUTO_TEST_CASE( testStringCapacity )
00069 {
00070 Attribute<string> str = Types()->type("string")->buildVariable("str",10);
00071 size_t strCapacity=str.get().capacity();
00072
00073 BOOST_CHECK_EQUAL( str.get().size() , 10 );
00074
00075
00076
00077
00078 str.set() = "hello";
00079 BOOST_CHECK_EQUAL( str.get().size() , 5 );
00080 BOOST_CHECK_EQUAL( str.get().capacity() , strCapacity );
00081
00082
00083 Attribute<string> copy("copy");
00084 BOOST_CHECK_EQUAL( copy.get().size() , 0 );
00085
00086
00087
00088
00089 copy.getDataSource()->update( str.getDataSource().get() );
00090
00091 BOOST_CHECK_EQUAL( copy.get().size(), 5 );
00092
00093
00094 BOOST_CHECK_EQUAL( copy.get(), str.get() );
00095
00096 copy.set() = "world";
00097
00098
00099 str.getDataSource()->update( copy.getDataSource().get() );
00100 BOOST_CHECK_EQUAL( str.get().size() , 5 );
00101 BOOST_CHECK_EQUAL( str.get().capacity() , strCapacity );
00102 BOOST_CHECK_EQUAL( copy.get(), str.get() );
00103
00104
00105
00106
00107 str.set() = "hello";
00108 strCapacity=str.get().capacity();
00109
00110 BOOST_CHECK_EQUAL( str.get().size() , 5 );
00111
00112
00113
00114
00115 ActionInterface* act = copy.getDataSource()->updateAction( str.getDataSource().get() );
00116 BOOST_CHECK( act );
00117 act->readArguments();
00118 BOOST_CHECK( act->execute() );
00119 delete act;
00120
00121 BOOST_CHECK_EQUAL( copy.get().size(), 5 );
00122
00123
00124 BOOST_CHECK_EQUAL( copy.get(), str.get() );
00125
00126 copy.set() = "world";
00127
00128
00129 act = str.getDataSource()->updateAction( copy.getDataSource().get() );
00130 BOOST_CHECK( act );
00131 act->readArguments();
00132 BOOST_CHECK( act->execute() );
00133 delete act;
00134
00135 BOOST_CHECK_EQUAL( str.get().size() , 5 );
00136 BOOST_CHECK_EQUAL( str.get().capacity() , strCapacity );
00137 BOOST_CHECK_EQUAL( copy.get(), str.get() );
00138
00139 }
00140 BOOST_AUTO_TEST_CASE( testTypes )
00141 {
00142 string test =
00143
00144 string("var int i2 = -1, j = 10, k; set k = 20\n") +
00145 "do test.assert( i2 == -1 ) ; do test.assert( j == 10 ); do test.assert(k == 20)\n" +
00146 "var double d = 10.0\n"+
00147 "do test.assert( d == 10.0 )\n" +
00148 "var bool b = false\n"+
00149 "do test.assert( b == false )\n" +
00150 "var string s=\"string\"\n"+
00151 "do test.assert( s == \"string\" )\n" +
00152 "const int ic = i2\n" +
00153 "do test.assert( ic == 0 )\n" +
00154 "const double dc = 10.0\n"+
00155 "do test.assert( dc == 10.0 )\n" +
00156 "const bool bc = true && false\n"+
00157 "do test.assert( bc == false )\n" +
00158 "const string sc= \"hello\"\n"+
00159 "do test.assert( sc == \"hello\" )\n" +
00160 "var array ar(10)\n"+
00161 "do test.assert( ar.size == 10)\n"+
00162
00163 "do test.assert( ar.capacity == 10)\n"+
00164 "set ar[0] = 0.0\n"+
00165 "set ar[1] = 1.0\n"+
00166 "set ar[2] = 0.2\n"+
00167 "set ar[8] = 0.8\n"+
00168 "set ar[9] = 9.0\n"+
00169 "do test.assert( ar[0] == 0.0 )\n"+
00170 "do test.assert( ar[1] == 1.0 )\n"+
00171 "do test.assert( ar[2] == 0.2 )\n"+
00172 "do test.assert( ar[8] == 0.8 )\n"+
00173
00174 "do test.assert( ar[9] == 9.0 )\n"+
00175 "do test.assert( ar[10] == 0.0 )\n"+
00176 "var array ar1 = array(12,2.0)\n"+
00177 "do test.assert(ar1.size == 12)\n"+
00178
00179 "do test.assert(ar1[0] == 2.0)\n"+
00180 "var array ar2 = array(5,3.0)\n"+
00181 "do test.assert(ar2.size == 5)\n"+
00182 "do test.assert(ar2[0] == 3.0)\n"+
00183 "var array ar3(3) = array(2.0,3.0,4.0)\n"+
00184 "do test.assert(ar3.size == 3)\n"+
00185
00186 "do test.assert(ar3[0]==2.0)\n"+
00187 "do test.assert(ar3[1]==3.0)\n"+
00188 "do test.assert(ar3[2]==4.0)\n"+
00189 "var array ar4 = array(2.0,3.0,4.0,5.0)\n"+
00190 "do test.assert(ar4.size == 4)\n"+
00191 "do test.assert(ar4[0]==2.0)\n"+
00192 "do test.assert(ar4[1]==3.0)\n"+
00193 "do test.assert(ar4[2]==4.0)\n"+
00194 "do test.assert(ar4[3]==5.0)\n"+
00195 "var string str(10)\n"+
00196 "var int strCapacity = str.capacity\n"
00197
00198
00199
00200 "do test.assertEqual( str.size, 10)\n"+
00201
00202 "set str = \"hello\"\n"+
00203
00204
00205 "do test.assertEqual( str.size, 5)\n"+
00206 "do test.assertEqual( str.capacity, strCapacity)\n"+
00207 "set str[0] = 'a'\n"+
00208 "set str[1] = 'b'\n"+
00209 "set str[2] = 'c'\n"+
00210 "do test.assert( str[0] == 'a' )\n"+
00211 "do test.assert( str[1] == 'b' )\n"+
00212 "do test.assert( str[2] == 'c' )\n"+
00213 "do test.assert( str == \"abclo\" )\n"+
00214 "do test.assert( str[20] == '\\0' )\n"+
00215
00216 "do test.assert( str[8] == '\\0' )\n"+
00217 "do test.assert( str[9] == '\\0' )\n"+
00218 "do test.assert( str[10] == '\\0' )\n"+
00219
00220 "set ar2 = array(10.,5.)\n"+
00221 "do test.assertEqual( ar2.size, 2)\n"+
00222 "do test.assertEqual( ar2.capacity, 5)\n"+
00223 "do test.assert( ar2[0] == 10.0 )\n"+
00224 "do test.assert( ar2[1] == 5.0 )\n"+
00225 "set ar3 = array(10.)\n"+
00226 "do test.assert( ar3.size == 1)\n"+
00227
00228 "do test.assert( ar3.capacity >= 1)\n"+
00229 "do test.assert( ar3[0] == 10.0 )\n"+
00230 "set ar4 = array(2, 7.)\n"+
00231 "do test.assert( ar4.size == 2)\n"+
00232 "do test.assert( ar4.capacity >= 2)\n"+
00233 "do test.assert( ar4[0] == 7.0 )\n"+
00234 "do test.assert( ar4[1] == 7.0 )\n"+
00235
00236 "set ar2 = ar4\n"+
00237 "do test.assert( ar2.size == 2)\n"+
00238 "do test.assert( ar2.capacity >= 5)\n"+
00239
00240 "do test.assert( ar2[0] == 7.0 )\n"+
00241 "do test.assert( ar2[1] == 7.0 )\n"+
00242 "do test.assert( ar.capacity == 10)\n"+
00243 "var array ar7(7) = array(7)\n"+
00244 "set ar = ar7\n"+
00245
00246 "do test.assert( ar.size == 7)\n"+
00247
00248 "do test.assertEqual( ar.capacity, 10)\n"+
00249
00250 "do test.assert( ar2[0] == 7.0 )\n"+
00251 "do test.assert( ar2[1] == 7.0 )\n";
00252
00253 string state = string("StateMachine X { initial state Init { entry {\n")
00254 +test
00255 +"} }\n"
00256 +"final state Fini {} }\n"
00257 +"RootMachine X x\n";
00258
00259 string prog = string("program x {\n") + test + "}\n";
00260
00261 executePrograms(prog);
00262 executeStates(state);
00263
00264
00265 }
00266
00267 BOOST_AUTO_TEST_CASE( testCharType )
00268 {
00269 string test =
00270
00271 string("var char c = char('c');\n") +
00272
00273
00274 "var char d = char('d');\n" +
00275
00276
00277 "set c = char('a');\n" +
00278 "do test.assert( char('a') == c ); \n" +
00279 "do test.assert( c != d ); \n" +
00280 "do test.assert( c < d ); \n" +
00281 "do test.assert( c <= d ); \n" +
00282 "do test.assert( d > c ); \n" +
00283 "do test.assert( d >= c ); \n" +
00284 "set d = c;\n" +
00285 "do test.assert( c == d ); \n" +
00286 "do test.assert( char('a') == d ); \n" +
00287 "do test.assert( char('a') == char('a') ); \n" +
00288 "do test.assert( char('a') != char('b') ); \n" +
00289 "do test.assert( char('a') < char('b') ); \n" +
00290 "do test.assert( char('a') <= char('b') ); \n" +
00291 "do test.assert( char('a') <= char('a') ); \n" +
00292 "do test.assert( char('z') > char('w') ); \n" +
00293 "do test.assert( char('z') >= char('w') ); \n" +
00294 "do test.assert( char('z') >= char('z') ); \n"
00295 ;
00296
00297 string state = string("StateMachine X { initial state Init { entry {\n")
00298 +test
00299 +"} }\n"
00300 +"final state Fini {} }\n"
00301 +"RootMachine X x\n";
00302
00303 string prog = string("program x {\n") + test + "}\n";
00304
00305 executePrograms(prog);
00306 executeStates(state);
00307 }
00308
00312 BOOST_AUTO_TEST_CASE( testOperators )
00313 {
00314 string prog = string("program x {\n") +
00315 "var int i = 3\n" +
00316 "var char c = 'c'\n" +
00317 "var double d = 10.0*i\n"+
00318 "do test.assert( d == 30.0 )\n" +
00319 "var bool b = false\n"+
00320 "var string s=\"string\"\n"+
00321 "set b = b || b && true && false || true\n"+
00322 "try test.assertMsg( s == \"string\", \"Unexpected string:\'\" + s +\"' instead of 'string'\")\n"+
00323 "set s = \" \" + s + \" \"\n"+
00324 "try test.assertMsg( s == \" string \", \"Unexpected string:\'\" + s +\"' instead of ' string '\")\n"+
00325 "set s = s + int(10)\n"+
00326 "try test.assertMsg( s == \" string 10\", \"Unexpected string:\'\" + s +\"' instead of ' string 10'\")\n"+
00327 "set s = s + \" \" + false\n"+
00328 "do test.assertMsg( s == \" string 10 false\", \"Unexpected string:\'\" + s +\"' instead of ' string 10 false'\")\n"+
00329 "set b = b\n ||\n b\n &&\n true\n && false\n || true\n"+
00330 "do test.assert( b == false )\n" +
00331 "var array a1 = array(2, 7.)\n"+
00332 "do test.assert( a1.size == 2 )\n" +
00333 "do test.assert( a1.capacity == 2 )\n" +
00334
00335 "}";
00336
00337 executePrograms(prog);
00338 }
00339
00344 BOOST_AUTO_TEST_CASE( testDotsAndIndexes )
00345 {
00346 Types()->addType( new SequenceTypeInfo<std::vector<std::vector<double> >,false >("matrix"));
00347 Types()->addType( new StructTypeInfo<AType,false>("astruct"));
00348 Types()->addType( new StructTypeInfo<CType,false>("cstruct"));
00349 Types()->addType( new SequenceTypeInfo<std::vector<CType>,false >("cstructv"));
00350 Types()->addType( new SequenceTypeInfo<std::vector<AType>,false >("astructv"));
00351 string prog = string("program x {\n") +
00352 "var matrix m = matrix(8,array(10))\n" +
00353 "test.assertMsg(m.size == 8, \"Matrix column size is wrong.\")\n" +
00354 "test.assertMsg(m[0].size == 10, \"Matrix row size is wrong.\")\n" +
00355 "m[0][0] = 3.33\n" +
00356 "m[1][1] = 4.33\n" +
00357 "m[2][2] = 5.33\n" +
00358 "m[8][10] = 6.33\n" +
00359 "test.assertMsg(m[0][0] == 3.33, \"Matrix element assignment failed.\")\n"+
00360 "test.assertMsg(m[1][1] == 4.33, \"Matrix element assignment failed.\")\n"+
00361 "test.assertMsg(m[2][2] == 5.33, \"Matrix element assignment failed.\")\n"+
00362 "test.assertMsg(m[8][10] == 6.33, \"Matrix element assignment failed.\")\n"+
00363 "var matrix m2 = m;\n"
00364 "test.assertMsg(m2[0][0] == 3.33, \"Matrix assignment failed.\")\n"+
00365 "test.assertMsg(m2[1][1] == 4.33, \"Matrix assignment failed.\")\n"+
00366 "test.assertMsg(m2[2][2] == 5.33, \"Matrix assignment failed.\")\n"+
00367 "test.assertMsg(m2[8][10] == 6.33, \"Matrix assignment failed.\")\n"+
00368 "var cstructv structv = cstructv(3)\n"+
00369 "structv[1].a.b = 3.33\n"+
00370 "test.assertMsg(structv[1].a.b == 3.33, \"Sequence of struct element assignment failed.\")\n"+
00371 "structv[1].av[3].b = 4.33\n"+
00372 "test.assertMsg(structv[1].av[3].b == 4.33, \"Sequence of struct element assignment failed.\")\n"+
00373 "}";
00374
00375 executePrograms(prog);
00376 }
00377
00382 BOOST_AUTO_TEST_CASE( testConversions )
00383 {
00384 string prog = string("program x {\n") +
00385 "var int i = 3.0\n" +
00386 "var double d = float(10.0*i)\n"+
00387 "do test.assert( float(d) == float(30.0) )\n" +
00388 "var float f = 5\n" +
00389 "set f = double(5) * double(-1) + i\n" +
00390 "set i = f\n" +
00391 "set f = i\n" +
00392 "set i = double(float(int(f)))\n" +
00393 "set f = int(float(double(int(3.333))))\n" +
00394 "do test.assert( f == 3 )\n" +
00395 "}";
00396
00397 executePrograms(prog);
00398 }
00399
00403 BOOST_AUTO_TEST_CASE( testHex )
00404 {
00405 string prog = string("program x {\n") +
00406 "var uint i = 0xabc\n" +
00407 "test.assert( i == 0xabc )\n"+
00408 "test.assert( i == 2748 )\n"+
00409 "i = 0Xcba\n" +
00410 "test.assert( i == 0Xcba )\n"+
00411 "test.assert( i == 3258 )\n"+
00412 "i = 0XABC\n" +
00413 "test.assert( i == 0XABC )\n"+
00414 "test.assert( i == 2748 )\n"+
00415 "i = 0xCBA\n" +
00416 "test.assert( i == 0xCBA )\n"+
00417 "test.assert( i == 3258 )\n"+
00418 "}";
00419
00420 executePrograms(prog);
00421 }
00422
00426 BOOST_AUTO_TEST_CASE( testProperties )
00427 {
00428 string prog = string("program x {\n") +
00429 "do test.assert( Double1 == 1.234 )\n" +
00430 "do test.assert( Double2 == 2.234 )\n" +
00431 "do test.assert( Double3 == 3.234 )\n" +
00432 "do test.assert( Collection.Double1 == 1.234 )\n" +
00433 "do test.assert( Collection.Double3 == 3.234 )\n" +
00434 "do test.assert( Collection.Collection.Double1 == 1.234 )\n" +
00435 "do test.assert( Collection.Collection.Collection.Double3 == 3.234 )\n" +
00436 "do test.assert( V[0] == 4.0 )\n" +
00437 "do test.assert( V[1] == 4.0 )\n" +
00438 "do test.assert( V[2] == 4.0 )\n" +
00439 "do test.assert( V[3] == 4.0 )\n" +
00440
00441 "set Double1 = 4.321\n" +
00442 "set Double2 = Double1\n" +
00443
00444 "set Collection.Double3 = 0.3\n" +
00445 "set V[0] = 0.321\n" +
00446 "set V[1] = 1.321\n" +
00447 "set V[2] = 2.321\n" +
00448 "set V[3] = 3.321\n" +
00449 "do test.assert( Double1 == 4.321 )\n" +
00450 "do test.assert( Double2 == 4.321 )\n" +
00451 "do test.assert( Double3 == 0.3 )\n" +
00452 "set Collection.Collection.Collection.Double3 = 3.0\n" +
00453 "do test.assert( Double3 == 3.0 )\n" +
00454 "}";
00455
00456 Property<PropertyBag> pb("Collection","");
00457 Property<double> pd1("Double1","",1.234);
00458 Property<double> pd2("Double2","",2.234);
00459 Property<double> pd3("Double3","",3.234);
00460
00461 Property< std::vector<double> > pv("V","",std::vector<double>(4, 4.0) );
00462
00463 pb.value().addProperty( pd1 );
00464 pb.value().addProperty( pd3 );
00465 pb.value().addProperty( pb );
00466
00467 tc->properties()->addProperty( pd1 );
00468 tc->properties()->addProperty( pd2 );
00469 tc->properties()->addProperty( pd3 );
00470 tc->properties()->addProperty( pb );
00471 tc->properties()->addProperty( pv );
00472
00473
00474 executePrograms(prog);
00475
00476 BOOST_CHECK_EQUAL( 4.321, pd1.get() );
00477 BOOST_CHECK_EQUAL( 3.0, pd3.get() );
00478 BOOST_CHECK_EQUAL( 0.321, pv.value()[0] );
00479 BOOST_CHECK_EQUAL( 1.321, pv.value()[1] );
00480 BOOST_CHECK_EQUAL( 2.321, pv.value()[2] );
00481 BOOST_CHECK_EQUAL( 3.321, pv.value()[3] );
00482 }
00483
00484 BOOST_AUTO_TEST_CASE( testOperatorOrder )
00485 {
00486 string prog = string("program x {\n") +
00487 "do test.assert( 6/2*4 == 12 )\n" +
00488 "do test.assert( 6*2/4 == 3 )\n" +
00489 "do test.assert( 3+2*5 == 13)\n" +
00490 "do test.assert( 3 < 2 != 5 > 1)\n" +
00491 "do test.assert( 3*2 <= 12/2 )\n" +
00492 "do test.assert( 3*2 < 6+1 )\n" +
00493 "do test.assert( 6 - 9 % 2*3 == 15/3 % 3 + 1 )\n" +
00494 "do test.assert( 3*(2+1) == 9 )\n" +
00495 "do test.assert( 1 - 1 + 5 == 5 )\n" +
00496 "var int a,b,c;\n" +
00497 " a = b = c = 3;\n" +
00498 "do test.assertEqual( a, 3 )\n" +
00499 "do test.assertEqual( b, 3 )\n" +
00500 "do test.assertEqual( c, 3 )\n" +
00501 "}";
00502
00503 executePrograms(prog);
00504 }
00505
00506 BOOST_AUTO_TEST_CASE( testGlobals )
00507 {
00508 GlobalsRepository::Instance()->setValue( new Constant<double>("cd_num", 3.33));
00509 GlobalsRepository::Instance()->setValue( new Constant<string>("c_string", "Hello World!"));
00510 GlobalsRepository::Instance()->setValue( new Attribute<double>("d_num", 3.33));
00511 string prog = string("program x {\n") +
00512 "do test.assert( cd_num == 3.33 )\n" +
00513 "do test.assert( cd_num == d_num )\n" +
00514 "do test.assert( c_string == \"Hello World!\")\n" +
00515 "set d_num = 6.66\n" +
00516 "do test.assert( d_num == 6.66 )\n" +
00517 "}";
00518
00519 executePrograms(prog);
00520 }
00521
00522 BOOST_AUTO_TEST_CASE( testFlowStatus )
00523 {
00524 BOOST_CHECK (GlobalsRepository::Instance()->getValue("NewData") );
00525 BOOST_CHECK (GlobalsRepository::Instance()->getValue("OldData") );
00526 BOOST_CHECK (GlobalsRepository::Instance()->getValue("NoData") );
00527 string prog = string("program x {\n") +
00528 "do test.assert( NewData )\n" +
00529 "do test.assert( OldData )\n" +
00530 "do test.assert( !bool(NoData) )\n" +
00531 "do test.assert( NewData > NoData )\n" +
00532 "do test.assert( NewData > OldData )\n" +
00533 "do test.assert( OldData > NoData )\n" +
00534 "do test.assert( OldData == OldData )\n" +
00535 "if ( bool(NewData) && OldData ) then {\n" +
00536 "} else {\n" +
00537 " do test.assert(false)\n" +
00538 "}\n" +
00539 "if ( bool(NoData) ) then {\n" +
00540 " do test.assert(false)\n" +
00541 "}\n" +
00542 "if ( !bool(NoData) ) then {} else {\n" +
00543 " do test.assert(false)\n" +
00544 "}\n" +
00545 "}";
00546
00547 executePrograms(prog);
00548 }
00549 BOOST_AUTO_TEST_SUITE_END()
00550
00551 void TypesTest::executePrograms(const std::string& prog )
00552 {
00553 BOOST_CHECK( tc->engine() );
00554
00555 Parser::ParsedPrograms pg_list;
00556 try {
00557 pg_list = parser.parseProgram( prog, tc );
00558 }
00559 catch( const file_parse_exception& exc )
00560 {
00561 BOOST_REQUIRE_MESSAGE( false , exc.what());
00562 }
00563 if ( pg_list.empty() )
00564 {
00565 BOOST_REQUIRE( false && "Got empty test program." );
00566 }
00567
00568 BOOST_CHECK( sa->loadProgram( *pg_list.begin() ) );
00569 BOOST_CHECK( (*pg_list.begin())->start() );
00570
00571 BOOST_CHECK( SimulationThread::Instance()->run(1000) );
00572
00573 if ( (*pg_list.begin())->inError() ) {
00574 stringstream errormsg;
00575 errormsg << " Program error on line " << (*pg_list.begin())->getLineNumber() <<"."<<endl;
00576 BOOST_CHECK_MESSAGE( false, errormsg.str() );
00577 }
00578
00579 if ( (*pg_list.begin())->isRunning() ) {
00580 stringstream errormsg;
00581 errormsg << " Program still running on line " << (*pg_list.begin())->getLineNumber() <<"."<<endl;
00582 BOOST_CHECK_MESSAGE( false, errormsg.str() );
00583 }
00584
00585 if ( (*pg_list.begin())->isStopped() == false ) {
00586 stringstream errormsg;
00587 errormsg << " Program not stopped on line " << (*pg_list.begin())->getLineNumber() <<"."<<endl;
00588 BOOST_CHECK_MESSAGE( false , errormsg.str() );
00589 }
00590 BOOST_CHECK( (*pg_list.begin())->stop() );
00591 BOOST_CHECK( sa->unloadProgram( (*pg_list.begin())->getName() ) );
00592 }
00593
00594 void TypesTest::executeStates(const std::string& state )
00595 {
00596 BOOST_CHECK( tc->engine() );
00597 Parser::ParsedStateMachines pg_list;
00598 try {
00599 pg_list = parser.parseStateMachine( state, tc );
00600 }
00601 catch( const file_parse_exception& exc )
00602 {
00603 BOOST_REQUIRE_MESSAGE( false , exc.what());
00604 }
00605 if ( pg_list.empty() )
00606 {
00607 BOOST_REQUIRE_MESSAGE( false, "Parser returned no state machines to execute." );
00608 }
00609
00610 BOOST_CHECK( sa->loadStateMachine( *pg_list.begin() ) );
00611 BOOST_CHECK( (*pg_list.begin())->activate() );
00612 BOOST_CHECK( (*pg_list.begin())->start() );
00613
00614 BOOST_CHECK( SimulationThread::Instance()->run(1000) );
00615 if ( (*pg_list.begin())->inError() ) {
00616 stringstream errormsg;
00617 errormsg << " State error on line " << (*pg_list.begin())->getLineNumber() <<"."<<endl;
00618 BOOST_CHECK_MESSAGE( false , errormsg.str());
00619 }
00620
00621 BOOST_CHECK( (*pg_list.begin())->stop() );
00622 BOOST_CHECK( SimulationThread::Instance()->run(100) );
00623 BOOST_CHECK( (*pg_list.begin())->deactivate() );
00624
00625 sa->unloadStateMachine( (*pg_list.begin())->getName() );
00626 }