21 #include <rtt-config.h> 77 void log(
const std::string& msg) {
80 void doState(
const std::string& name,
const std::string& prog,
TaskContext*,
bool test=
true,
int runs = 1000 );
81 void parseState(
const std::string& prog,
TaskContext*,
bool test=
true );
82 void runState(
const std::string& name,
TaskContext*,
bool trace=
true,
bool test=
true,
int runs = 1000 );
83 void checkState(
const std::string& name,
TaskContext*,
bool test=
true );
84 void finishState( std::string
const& name,
TaskContext*,
bool test=
true );
90 d_event(
"d_event"), b_event(
"b_event"), t_event(
"t_event"), v_event(
"v_event"),o_event(
"o_event"),
91 v1_event(
"v1_event"),v2_event(
"v2_event"),v3_event(
"v3_event"),c_event(
"c_event"),
92 d_event_source(
"d_event_source"), b_event_source(
"b_event_source"), t_event_source(
"t_event_source")
101 tc->ports()->addPort( d_event );
102 tc->ports()->addPort( b_event );
103 tc->ports()->addPort( t_event );
104 #ifdef ORO_SIGNALLING_OPERATIONS 105 tc->provides()->addEventOperation( o_event );
106 tc->provides()->addEventOperation( v_event );
107 tc->provides()->addEventOperation( v1_event );
108 tc->provides()->addEventOperation( v2_event );
109 tc->provides()->addEventOperation( v3_event );
110 caller->provides()->addEventOperation( c_event );
112 tc->provides()->addOperation( o_event );
113 tc->provides()->addOperation( v_event );
114 tc->provides()->addOperation( v1_event );
115 tc->provides()->addOperation( v2_event );
116 tc->provides()->addOperation( v3_event );
117 caller->provides()->addOperation( c_event );
120 tc->provides()->addOperation(setState_op).
doc(
"Communicates state from SM").arg(
"state",
"Name of state");
122 tc->ports()->addPort( d_event_source );
123 tc->ports()->addPort( b_event_source );
124 tc->ports()->addPort( t_event_source );
135 tc->provides()->addAttribute(
"tvar_i", var_i);
136 tc->provides()->addAttribute(
"tss", tss);
137 tc->provides()->addConstant(
"tconst_i", const_i);
152 string prog = string(
"StateMachine X {\n")
153 +
" param int isten\n" 154 +
" param bool isflse\n" 155 +
" param bool isok\n" 156 +
" param double isnegative\n" 157 +
" var bool istrrue = true\n" 158 +
" var double d_dummy = -1.0\n" 159 +
" var int i_dummy = -1\n" 160 +
" var bool varinit = false\n" 161 +
" var bool b_dummy = true\n" 162 +
" initial state INIT {\n" 174 +
" set varinit = (d_dummy != -1.) || (i_dummy != -1) \n" 175 +
" do test.good()\n" 176 +
" set d_dummy = 1.234\n" 177 +
" set i_dummy = -2\n" 178 +
" do test.good()\n" 181 +
" do test.good()\n" 184 +
" do test.good()\n" 185 +
" set d_dummy = 0.0\n" 186 +
" set i_dummy = 0\n" 189 +
" if false then select ERROR\n" 190 +
" if varinit == true then select PRE_VARFAIL\n" 191 +
" if (d_dummy != 1.234) || (i_dummy != -2) then select ENTRYFAIL\n" 193 +
" transition if (istrrue == false) || (isflse == true) || (isten != 10) ||( isnegative >= 0. ) then select PARAMFAIL\n" 194 +
" transition if isok == false then select PARAMFAIL\n" 195 +
" transition select FINI\n" 196 +
" transition select ERROR\n" 198 +
" state PRE_ERROR { entry { do test.assert(false) }\n" 200 +
" state PRE_PARAMFAIL { entry { do test.assert(false) }\n" 202 +
" state PRE_VARFAIL { entry { do test.assert(false) }\n" 204 +
" state ERROR { entry { do test.assert(false) }\n" 206 +
" state PARAMFAIL {\n" 208 +
" do test.assertMsg( isten == 10, \"isten parameter not correctly initialised\")\n" 209 +
" do test.assertMsg( istrrue == true, \"istrrue parameter not correctly initialised\")\n" 210 +
" do test.assertMsg( isok == true, \"isok parameter not correctly initialised\")\n" 211 +
" do test.assertMsg( isflse == false, \"isflse parameter not correctly initialised\")\n" 212 +
" do test.assertMsg( true == true, \"true ident not correctly done\")\n" 213 +
" do test.assertMsg( false == false, \"false ident not correctly done\")\n" 214 +
" do test.assertMsg( isnegative == -1.0, \"isnegative parameter not correctly initialised\")\n" 217 +
" state VARFAIL { entry { do test.assert(false) }\n" 219 +
" state EXITFAIL { entry { do test.assert(false) }\n" 221 +
" state ENTRYFAIL { entry { do test.assert(false) }\n" 223 +
" final state FINI {\n" 224 +
" preconditions {\n" 225 +
" if (d_dummy != 0.) || (i_dummy != 0) then select EXITFAIL\n" 226 +
" if false then select ERROR\n" 229 +
" do test.good()\n" 230 +
" set d_dummy = -1.\n" 231 +
" set i_dummy = -1\n" 234 +
" do test.good()\n" 237 +
" do test.good()\n" 240 +
" if false then select ERROR\n" 247 +
" RootMachine X x( isten = 10, isok = true, isflse=false, isnegative = -1.0) \n" 250 this->doState(
"x", prog, tc );
251 this->finishState(
"x", tc );
259 string prog = string(
"StateMachine X {\n")
260 +
" initial state INIT {\n" 262 +
" do test.increase()\n" 263 +
" do test.assert( test.i != 1)\n" 266 +
" do test.assert( test.i != 2)\n" 269 +
" do test.assert( test.i != 3)\n" 272 +
" if (true) then { do test.assert( test.i != 7); } select FINI\n" 277 +
" final state FINI {\n" 279 +
" do test.assert( test.i != 4)\n" 282 +
" do test.assert( test.i != 5)\n" 285 +
" do test.assert( test.i != 6)\n" 292 +
" RootMachine X x\n" 298 while ( i < max && x < max) {
299 this->doState(
"x", prog, tc,
false );
302 BOOST_CHECK_MESSAGE( sa->getStateMachineStatus(
"x") == StateMachine::Status::error,
"Status is: " + sa->getStateMachineStatusStr(
"x") );
304 this->finishState(
"x", tc,
false);
311 string prog = string(
"StateMachine Y {\n")
312 +
" param double isnegative\n" 313 +
" var double t = 1.0\n" 314 +
" initial state INIT {\n" 316 +
" do test.good()\n" 319 +
" if isnegative >= 0. then select PARAMFAIL\n" 323 +
" state ERROR { entry { do test.assert(false) }\n" 325 +
" state PARAMFAIL { entry { do test.assert(false) }\n" 327 +
" state VARFAIL { entry { do test.assert(false) }\n" 329 +
" state EXITFAIL { entry { do test.assert(false) }\n" 331 +
" state ENTRYFAIL { entry { do test.assert(false) }\n" 333 +
" final state FINI {\n" 335 +
" do test.good()\n" 342 + string(
"StateMachine Z {\n")
343 +
" param double neg\n" 344 +
" initial state INIT {\n" 346 +
" if neg >= 0. then select PARAMFAIL\n" 350 +
" state PARAMFAIL { entry { do test.assert(false) }\n" 352 +
" final state FINI {\n" 358 + string(
"StateMachine X {\n")
359 +
" param double isnegative\n" 360 +
" var double d_dummy = -2.0\n" 361 +
" var int i_dummy = -1\n" 362 +
" SubMachine Y y1(isnegative = d_dummy)\n" 363 +
" SubMachine Y y2(isnegative = -3.0)\n" 364 +
" SubMachine Y y3(isnegative = isnegative)\n" 365 +
" SubMachine Z z1( neg = d_dummy)\n" 366 +
" initial state INIT {\n" 368 +
" do test.good()\n" 369 +
" do y1.activate()\n" 370 +
" do y2.activate()\n" 371 +
" do y3.activate()\n" 372 +
" do z1.activate()\n" 384 +
" state ERROR { entry { do test.assert(false) }\n" 386 +
" state PARAMFAIL {\n" 388 +
" do test.assertMsg( y3.isnegative == isnegative, \"y3 parameter not correctly initialised\")\n" 389 +
" do test.assertMsg( y2.isnegative == -3.0, \"y2 parameter not correctly initialised\")\n" 390 +
" do test.assertMsg( y1.isnegative == d_dummy, \"y1 parameter not correctly initialised\")\n" 391 +
" do test.assertMsg( z1.neg == d_dummy, \"z1 parameter not correctly initialised\")\n" 394 +
" state VARFAIL { entry { do test.assert(false) }\n" 396 +
" state EXITFAIL { entry { do test.assert(false) }\n" 398 +
" state ENTRYFAIL { entry { do test.assert(false) }\n" 400 +
" final state FINI {\n" 402 +
" do test.good()\n" 409 +
" do test.good()\n" 410 +
" do y1.deactivate()\n" 411 +
" do y2.deactivate()\n" 412 +
" do y3.deactivate()\n" 413 +
" do z1.deactivate()\n" 416 +
" if z1.neg != d_dummy then select PARAMFAIL\n" 417 +
" if y1.isnegative != d_dummy then select PARAMFAIL\n" 418 +
" if y2.isnegative != -3.0 then select PARAMFAIL\n" 419 +
" if y3.isnegative != isnegative then select PARAMFAIL\n" 424 +
" RootMachine X x( isnegative = -1.0) \n" 427 this->doState(
"x", prog, tc );
428 this->finishState(
"x", tc);
434 string prog = string(
"StateMachine X {\n")
435 +
" initial state INIT {\n" 442 +
" final state FINI {\n" 445 +
" RootMachine X x\n" 447 this->doState(
"x", prog, tc );
448 this->finishState(
"x", tc);
454 string prog = string(
"StateMachine Y {\n")
455 +
" initial state INIT {\n" 457 +
" final state FINI {\n" 460 +
"StateMachine X {\n" 461 +
" SubMachine Y y;\n" 462 +
" initial state INIT {\n" 464 +
" final state FINI {\n" 467 +
"RootMachine X x\n" 470 this->doState(
"x", prog, tc );
471 this->finishState(
"x", tc);
477 string prog = string(
"// Start here\n")
478 +
"StateMachine X { //\n" 479 +
" // comment on INIT\n" 480 +
" initial state INIT /* INIT */ { // \n" 481 +
" // comment in INIT\n" 482 +
" entry /* entry */ { // \n" 487 +
" // intermediate comment \n" 488 +
" final state FINI // \n" 494 +
" /* in entry */\n" 498 +
"// final comment\n" 501 +
"// instantiate comment\n" 503 +
"RootMachine X x // end\n" 505 this->doState(
"x", prog, tc );
506 this->finishState(
"x", tc);
512 string prog = string(
"StateMachine X {\n")
513 +
" initial state INIT {\n" 515 +
" setState( rt_string(\"INIT-ENTRY\") )\n" 522 +
" var double dret\n" 524 +
" setState( rt_string(\"TEST-ENTRY\") )\n" 527 +
" methods.m2(1,2.0)\n" 528 +
" methods.m3(1,2.0,true)\n" 529 +
" methods.m4(1,2.0,true,\"hello\")\n" 530 +
" methods.m5(1,2.0,true,\"hello\",5.0)\n" 531 +
" methods.m6(1,2.0,true,\"hello\",5.0,'a')\n" 532 +
" dret = methods.m7(1,2.0,true,\"hello\",5.0,'a',7)\n" 533 +
" test.assert( dret == -8.0 )\n" 536 +
" methods.o2(1,2.0)\n" 537 +
" methods.o3(1,2.0,true)\n" 538 +
" methods.o4(1,2.0,true,\"hello\")\n" 539 +
" methods.o5(1,2.0,true,\"hello\",5.0)\n" 540 +
" methods.o6(1,2.0,true,\"hello\",5.0,'a')\n" 541 +
" dret = methods.o7(1,2.0,true,\"hello\",5.0,'a',7)\n" 542 +
" test.assert( dret == -8.0 )\n" 545 +
" setState( rt_string(\"TEST-RUN\") )\n" 548 +
" methods.m2(1,2.0)\n" 549 +
" methods.m3(1,2.0,true)\n" 550 +
" methods.m4(1,2.0,true,\"hello\")\n" 551 +
" methods.m5(1,2.0,true,\"hello\",5.0)\n" 552 +
" methods.m6(1,2.0,true,\"hello\",5.0,'a')\n" 553 +
" dret = methods.m7(1,2.0,true,\"hello\",5.0,'a',7)\n" 554 +
" test.assert( dret == -8.0 )\n" 557 +
" methods.o2(1,2.0)\n" 558 +
" methods.o3(1,2.0,true)\n" 559 +
" methods.o4(1,2.0,true,\"hello\")\n" 560 +
" methods.o5(1,2.0,true,\"hello\",5.0)\n" 561 +
" methods.o6(1,2.0,true,\"hello\",5.0,'a')\n" 562 +
" dret = methods.o7(1,2.0,true,\"hello\",5.0,'a',7)\n" 563 +
" test.assert( dret == -8.0 )\n" 566 +
" setState( rt_string(\"TEST-EXIT\") )\n" 569 +
" methods.m2(1,2.0)\n" 570 +
" methods.m3(1,2.0,true)\n" 571 +
" methods.m4(1,2.0,true,\"hello\")\n" 572 +
" methods.m5(1,2.0,true,\"hello\",5.0)\n" 573 +
" methods.m6(1,2.0,true,\"hello\",5.0,'a')\n" 574 +
" dret = methods.m7(1,2.0,true,\"hello\",5.0,'a',7)\n" 575 +
" test.assert( dret == -8.0 )\n" 578 +
" methods.o2(1,2.0)\n" 579 +
" methods.o3(1,2.0,true)\n" 580 +
" methods.o4(1,2.0,true,\"hello\")\n" 581 +
" methods.o5(1,2.0,true,\"hello\",5.0)\n" 582 +
" methods.o6(1,2.0,true,\"hello\",5.0,'a')\n" 583 +
" methods.o7(1,2.0,true,\"hello\",5.0,'a',7)\n" 588 +
" setState( rt_string(\"TEST-TRANSIT\") )\n" 591 +
" methods.m2(1,2.0)\n" 592 +
" methods.m3(1,2.0,true)\n" 593 +
" methods.m4(1,2.0,true,\"hello\")\n" 594 +
" methods.m5(1,2.0,true,\"hello\",5.0)\n" 595 +
" methods.m6(1,2.0,true,\"hello\",5.0,'a')\n" 596 +
" dret = methods.m7(1,2.0,true,\"hello\",5.0,'a',7)\n" 597 +
" test.assert( dret == -8.0 )\n" 600 +
" methods.o2(1,2.0)\n" 601 +
" methods.o3(1,2.0,true)\n" 602 +
" methods.o4(1,2.0,true,\"hello\")\n" 603 +
" methods.o5(1,2.0,true,\"hello\",5.0)\n" 604 +
" methods.o6(1,2.0,true,\"hello\",5.0,'a')\n" 605 +
" dret = methods.o7(1,2.0,true,\"hello\",5.0,'a',7)\n" 606 +
" test.assert( dret == -8.0 )\n" 607 +
" } select TEST2;\n" 612 +
" setState( rt_string(\"TEST-ENTRY\") )\n" 615 +
" methods.m2(1,2.0)\n" 616 +
" methods.m3(1,2.0,true)\n" 617 +
" methods.m4(1,2.0,true,\"hello\")\n" 618 +
" methods.m5(1,2.0,true,\"hello\",5.0)\n" 619 +
" methods.m6(1,2.0,true,\"hello\",5.0,'a')\n" 620 +
" dret = methods.m7(1,2.0,true,\"hello\",5.0,'a',7)\n" 621 +
" test.assert( dret == -8.0 )\n" 624 +
" methods.o2(1,2.0)\n" 625 +
" methods.o3(1,2.0,true)\n" 626 +
" methods.o4(1,2.0,true,\"hello\")\n" 627 +
" methods.o5(1,2.0,true,\"hello\",5.0)\n" 628 +
" methods.o6(1,2.0,true,\"hello\",5.0,'a')\n" 629 +
" dret = methods.o7(1,2.0,true,\"hello\",5.0,'a',7)\n" 630 +
" test.assert( dret == -8.0 )\n" 633 +
" setState( rt_string(\"TEST-RUN\") )\n" 636 +
" methods.m2(1,2.0)\n" 637 +
" methods.m3(1,2.0,true)\n" 638 +
" methods.m4(1,2.0,true,\"hello\")\n" 639 +
" methods.m5(1,2.0,true,\"hello\",5.0)\n" 640 +
" methods.m6(1,2.0,true,\"hello\",5.0,'a')\n" 641 +
" dret = methods.m7(1,2.0,true,\"hello\",5.0,'a',7)\n" 642 +
" test.assert( dret == -8.0 )\n" 645 +
" methods.o2(1,2.0)\n" 646 +
" methods.o3(1,2.0,true)\n" 647 +
" methods.o4(1,2.0,true,\"hello\")\n" 648 +
" methods.o5(1,2.0,true,\"hello\",5.0)\n" 649 +
" methods.o6(1,2.0,true,\"hello\",5.0,'a')\n" 650 +
" dret = methods.o7(1,2.0,true,\"hello\",5.0,'a',7)\n" 651 +
" test.assert( dret == -8.0 )\n" 654 +
" setState( rt_string(\"TEST-EXIT\") )\n" 657 +
" methods.m2(1,2.0)\n" 658 +
" methods.m3(1,2.0,true)\n" 659 +
" methods.m4(1,2.0,true,\"hello\")\n" 660 +
" methods.m5(1,2.0,true,\"hello\",5.0)\n" 661 +
" methods.m6(1,2.0,true,\"hello\",5.0,'a')\n" 662 +
" dret = methods.m7(1,2.0,true,\"hello\",5.0,'a',7)\n" 663 +
" test.assert( dret == -8.0 )\n" 666 +
" methods.o2(1,2.0)\n" 667 +
" methods.o3(1,2.0,true)\n" 668 +
" methods.o4(1,2.0,true,\"hello\")\n" 669 +
" methods.o5(1,2.0,true,\"hello\",5.0)\n" 670 +
" methods.o6(1,2.0,true,\"hello\",5.0,'a')\n" 671 +
" methods.o7(1,2.0,true,\"hello\",5.0,'a',7)\n" 676 +
" setState( rt_string(\"TEST-TRANSIT\") )\n" 679 +
" methods.m2(1,2.0)\n" 680 +
" methods.m3(1,2.0,true)\n" 681 +
" methods.m4(1,2.0,true,\"hello\")\n" 682 +
" methods.m5(1,2.0,true,\"hello\",5.0)\n" 683 +
" methods.m6(1,2.0,true,\"hello\",5.0,'a')\n" 684 +
" dret = methods.m7(1,2.0,true,\"hello\",5.0,'a',7)\n" 685 +
" test.assert( dret == -8.0 )\n" 688 +
" methods.o2(1,2.0)\n" 689 +
" methods.o3(1,2.0,true)\n" 690 +
" methods.o4(1,2.0,true,\"hello\")\n" 691 +
" methods.o5(1,2.0,true,\"hello\",5.0)\n" 692 +
" methods.o6(1,2.0,true,\"hello\",5.0,'a')\n" 693 +
" dret = methods.o7(1,2.0,true,\"hello\",5.0,'a',7)\n" 694 +
" test.assert( dret == -8.0 )\n" 695 +
" } select FINI;\n" 698 +
" final state FINI {\n" 701 +
" RootMachine X x\n" 703 parseState( prog, tc,
true);
706 BOOST_REQUIRE( tc->getActivity()->stop() );
707 BOOST_REQUIRE( tc->setActivity(
new Activity(0, 0.001) ) );
708 BOOST_REQUIRE( tc->start() );
715 BOOST_CHECK( act(sm) );
716 BOOST_CHECK( autom(sm) );
720 checkState(
"x", tc);
721 BOOST_CHECK( sa->getStateMachine(
"x" )->inState(
"FINI") );
722 this->finishState(
"x", tc,
false);
729 string prog = string(
"StateMachine X {\n")
730 +
" initial state INIT {\n" 731 +
" var int i = 0;\n" 732 +
" var int j = 0;\n" 733 +
" var int k = 0;\n" 741 +
" if i < 5 then {\n" 742 +
" set i = i + 1;\n" 744 +
" if i < 10 then {\n" 745 +
" set i = i + 1;\n" 747 +
" if i < 10 then {\n" 748 +
" } select TRANS_SHOULD_NOT_CHECK\n" 749 +
" if i == 10 then {\n" 750 +
" set i = i + 1;\n" 751 +
" } select TEST_ENTRY\n" 754 +
" state TEST_ENTRY {\n" 756 +
" if k != i then {\n" 757 +
" } select RUN_FAILED\n" 758 +
" if j != 1 then {\n" 759 +
" } select ENTRY_FAILED\n" 760 +
" else select FINI\n" 763 +
" state TRANS_SHOULD_NOT_CHECK {\n" 764 +
" entry { do test.assert(false); }\n" 766 +
" state ENTRY_FAILED {\n" 767 +
" entry { do test.assert(false); }\n" 769 +
" state RUN_FAILED {\n" 770 +
" entry { do test.assert(false); }\n" 772 +
" final state FINI {\n" 775 +
" RootMachine X x\n" 777 this->doState(
"x", prog, tc );
778 BOOST_CHECK( sa->getStateMachine(
"x" )->inState(
"FINI") );
779 this->finishState(
"x", tc);
785 string prog = string(
"StateMachine X {\n")
786 +
" initial state INIT {\n" 788 +
" if stop() == true then select NEXT\n" 792 +
" entry { do test.assert(true); }\n" 794 +
" final state FINI {\n" 795 +
" entry { do test.assert(true); }\n" 798 +
" RootMachine X x\n" 800 this->doState(
"x", prog, tc );
801 BOOST_CHECK( sa->getStateMachine(
"x" )->inState(
"NEXT") );
802 this->finishState(
"x", tc);
808 string prog = string(
"StateMachine X {\n")
809 +
" initial state INIT {\n" 810 +
" var double d = 0.0\n" 811 +
" run { do o_event(1.0); test.i = 5; do test.assert(test.i == 5);\n" 814 +
" do test.assert(false); }\n" 815 +
" transition o_event(d) select NEXT;\n" 821 +
" entry { do test.assert(test.i == 5); }\n" 823 +
" final state FINI {\n" 824 +
" entry { do test.assert(true); }\n" 827 +
" RootMachine X x\n" 829 this->doState(
"x", prog, tc );
830 BOOST_CHECK( sa->getStateMachine(
"x" )->inState(
"NEXT") );
831 this->finishState(
"x", tc);
838 this->o_event.getOperationCaller()->setThread(
OwnThread, tc->engine() );
839 string prog = string(
"StateMachine X {\n")
840 +
" initial state INIT {\n" 841 +
" var double d = 0.0\n" 842 +
" run { do o_event.send(1.0); test.i = 5; do test.assert(test.i == 5);\n" 845 +
" do test.assert(false); }\n" 846 +
" transition o_event(d) select NEXT;\n" 852 +
" entry { do test.assert(test.i == 5); }\n" 854 +
" final state FINI {\n" 855 +
" entry { do test.assert(true); }\n" 858 +
" RootMachine X x\n" 860 this->doState(
"x", prog, tc );
861 BOOST_CHECK( sa->getStateMachine(
"x" )->inState(
"NEXT") );
862 this->finishState(
"x", tc);
868 string prog = string(
"StateMachine X {\n")
869 +
" initial state INIT {\n" 870 +
" var double d = 0.0\n" 872 +
" test.assertEqual( test.i, 0 )\n" 873 +
" var SendStatus ss\n" 874 +
" ss = test.increaseCmd.cmd() \n" 875 +
" test.assert( ss == SendSuccess )\n" 876 +
" test.assertEqual( test.i, 1 )\n" 877 +
" ss = test.increaseCmd.cmd()\n" 878 +
" test.assert( ss == SendSuccess )\n" 879 +
" test.assertEqual( test.i , 2 )\n" 881 +
" tss = methods.vo0.cmd() \n" 882 +
" test.assert( tss == SendSuccess )\n" 883 +
" tss = methods.vo0.cmd()\n" 884 +
" test.assert( tss == SendSuccess )\n" 890 +
" final state FINI {\n" 891 +
" entry { do test.assert(true); }\n" 894 +
" RootMachine X x\n" 896 this->doState(
"x", prog, tc );
897 BOOST_CHECK( sa->getStateMachine(
"x" )->inState(
"FINI") );
898 this->finishState(
"x", tc);
904 string func = string(
"export function foo(int arg) {\n")
905 +
" do test.assert( tvar_i == arg ) \n" 906 +
" do test.assert( tvar_i != tconst_i ) \n" 907 +
" set tvar_i = tvar_i+2\n" 908 +
" do test.assert( tvar_i == arg + 2 ) \n" 910 string prog = string(
"StateMachine X {\n")
911 +
" initial state INIT {\n" 915 +
" var SendHandle sh, sh2\n" 916 +
" sh = foo.send(tvar_i) \n" 920 +
" test.assert( sh.collectIfDone() == SendNotReady )\n" 921 +
" test.assertEqual( tvar_i, 0 )\n" 923 +
" while ( sh.collectIfDone() == SendNotReady) \n" 925 +
" test.assert( sh.collectIfDone() == SendSuccess )\n" 926 +
" test.assertEqual( tvar_i, 2 )\n" 928 +
" sh2 = foo.send(tvar_i) \n" 929 +
" test.assert( sh2.collectIfDone() == SendNotReady )\n" 930 +
" test.assertEqual( tvar_i, 2 )\n" 931 +
" while ( sh2.collectIfDone() == SendNotReady) \n" 933 +
" test.assert( sh2.collectIfDone() == SendSuccess )\n" 934 +
" test.assertEqual( tvar_i , 4 )\n" 941 +
" final state FINI {\n" 942 +
" entry { do test.assert(true); }\n" 945 +
" RootMachine X x\n" 947 BOOST_REQUIRE( sa->loadPrograms(func,
"func.ops",
false) );
948 this->doState(
"x", prog, tc,
true, 25 );
949 BOOST_CHECK( sa->getStateMachine(
"x" )->inState(
"FINI") );
950 this->finishState(
"x", tc);
956 string func = string(
"export function foo(int arg) {\n")
957 +
" do test.assert( tvar_i == arg ) \n" 958 +
" do test.assert( tvar_i != tconst_i ) \n" 959 +
" set tvar_i = tvar_i+2\n" 960 +
" do test.assert( tvar_i == arg + 2 ) \n" 962 string prog = string(
"StateMachine X {\n")
963 +
" initial state INIT {\n" 965 +
" var SendStatus ss\n" 968 +
" ss = foo.cmd(tvar_i)\n" 969 +
" test.assert( ss == SendSuccess )\n" 970 +
" test.assertEqual( tvar_i, 2 )\n" 972 +
" ss = foo.cmd(tvar_i)\n" 973 +
" test.assert( ss == SendSuccess )\n" 974 +
" test.assertEqual( tvar_i , 4 )\n" 976 +
" tss = foo.cmd(tvar_i)\n" 977 +
" test.assert( tss == SendSuccess )\n" 978 +
" tss = foo.cmd(tvar_i)\n" 979 +
" test.assert( tss == SendSuccess )\n" 980 +
" test.assertEqual( tvar_i , 8 )\n" 987 +
" final state FINI {\n" 988 +
" entry { do test.assert(true); }\n" 991 +
" RootMachine X x\n" 993 BOOST_REQUIRE( sa->loadPrograms(func,
"func.ops",
false) );
994 this->doState(
"x", prog, tc,
true, 25 );
995 BOOST_CHECK( sa->getStateMachine(
"x" )->inState(
"FINI") );
996 this->finishState(
"x", tc);
1003 string prog = string(
"StateMachine X {\n")
1004 +
" var int gi = 0;\n" 1005 +
" transitions {\n" 1007 +
" if gi < 5 then {\n" 1008 +
" set gi = gi + 1;\n" 1009 +
" } select INIT\n" 1011 +
" if gi < 10 then {\n" 1012 +
" if gi < 5 then do test.assert(false);\n" 1013 +
" set gi = gi + 1;\n" 1015 +
" if gi < 10 then {\n" 1016 +
" do test.assert(false);\n" 1017 +
" } select TRANS_SHOULD_NOT_CHECK\n" 1018 +
" if gi >= 10 then {\n" 1019 +
" } select FINI\n" 1021 +
" initial state INIT {\n" 1022 +
" var int i = 0;\n" 1023 +
" var int j = 0;\n" 1024 +
" var int k = 0;\n" 1026 +
" set j = j + 1\n" 1029 +
" set k = k + 1\n" 1031 +
" transitions {\n" 1032 +
" if i < 5 then {\n" 1033 +
" set i = i + 1;\n" 1034 +
" } select INIT\n" 1035 +
" if i < 10 then {\n" 1036 +
" set i = i + 1;\n" 1038 +
" if i < 10 then {\n" 1039 +
" } select TRANS_SHOULD_NOT_CHECK\n" 1042 +
" state TRANS_SHOULD_NOT_CHECK {\n" 1043 +
" entry { do test.assert(false); }\n" 1045 +
" state ENTRY_FAILED {\n" 1046 +
" entry { do test.assert(false); }\n" 1048 +
" state RUN_FAILED {\n" 1049 +
" entry { do test.assert(false); }\n" 1051 +
" final state FINI {\n" 1054 +
" RootMachine X x\n" 1056 this->doState(
"x", prog, tc );
1057 BOOST_CHECK( sa->getStateMachine(
"x" )->inState(
"FINI") );
1058 this->finishState(
"x", tc);
1065 string prog = string(
"StateMachine Y {\n")
1066 +
" param double isnegative\n" 1067 +
" var double t = 1.0\n" 1068 +
" initial state INIT {\n" 1069 +
" transitions {\n" 1070 +
" if isnegative >= 0. then select PARAMFAIL\n" 1071 +
" if t >= 0. then select VARFAIL\n" 1074 +
" exit { set isnegative = +1.0 }\n" 1076 +
" state ERROR { entry { do test.assert(false) }\n" 1078 +
" state PARAMFAIL { entry { do test.assert(false) }\n" 1080 +
" state VARFAIL { entry { do test.assert(false) }\n" 1082 +
" state EXITFAIL { entry { do test.assert(false) }\n" 1084 +
" state ENTRYFAIL { entry { do test.assert(false) }\n" 1086 +
" final state FINI {\n" 1087 +
" transitions {\n" 1088 +
" if isnegative <= 0. then select PARAMFAIL\n" 1092 + string(
"StateMachine X {\n")
1093 +
" param double isnegative\n" 1094 +
" var double d_dummy = -2.0\n" 1095 +
" var int i_dummy = -1\n" 1096 +
" SubMachine Y y1(isnegative = d_dummy)\n" 1097 +
" initial state INIT {\n" 1099 +
" do y1.trace(true)\n" 1100 +
" do y1.activate()\n" 1101 +
" set y1.t = -1.0 \n" 1104 +
" do test.assert( y1.start() )\n" 1106 +
" transitions {\n" 1113 +
" do test.assert( y1.inState(\"FINI\") )\n" 1115 +
" transitions {\n" 1119 +
" final state FINI {\n" 1124 +
" set y1.isnegative = -1.0 \n" 1125 +
" do y1.deactivate()\n" 1127 +
" transitions {\n" 1132 +
" RootMachine X x( isnegative = -1.0) \n" 1135 this->doState(
"x", prog, tc );
1136 this->finishState(
"x", tc);
1142 string prog = string(
"StateMachine Y {\n")
1143 +
" param double isnegative\n" 1144 +
" var double t = 1.0\n" 1145 +
" initial state INIT {\n" 1146 +
" transitions {\n" 1147 +
" if isnegative < 0. then select ISNEGATIVE\n" 1148 +
" if t >= 0. then select ISPOSITIVE\n" 1149 +
" select DEFAULT\n" 1152 +
" state ISNEGATIVE {\n" 1153 +
" transitions {\n" 1157 +
" state ISPOSITIVE {\n" 1158 +
" transitions {\n" 1163 +
" state DEFAULT {\n" 1164 +
" transitions {\n" 1168 +
" final state FINI {\n" 1171 + string(
"StateMachine X {\n")
1172 +
" SubMachine Y y1(isnegative = -1.0)\n" 1173 +
" initial state INIT {\n" 1175 +
" set y1.t = -1.0 \n" 1176 +
" do y1.activate()\n" 1177 +
" do y1.requestState(\"ISNEGATIVE\")\n" 1178 +
" do test.assert( y1.inState(\"ISNEGATIVE\") )\n" 1179 +
" do y1.requestState(\"INIT\")\n" 1180 +
" do test.assert( y1.inState(\"INIT\") )\n" 1181 +
" set y1.isnegative = +1.0 \n" 1182 +
" try y1.requestState(\"ISNEGATIVE\") \n " 1184 +
" do test.assert( y1.inState(\"INIT\") )\n" 1186 +
" do test.assert( y1.inState(\"INIT\") )\n" 1187 +
" do y1.requestState(\"FINI\")\n" 1188 +
" do test.assert( y1.inState(\"FINI\") )\n" 1191 +
" do y1.requestState(\"INIT\")\n" 1192 +
" do test.assert( y1.inState(\"INIT\") )\n" 1193 +
" set y1.isnegative = +1.0 \n" 1194 +
" set y1.t = -1.0 \n" 1195 +
" do y1.start()\n" 1196 +
" while ! y1.inState(\"FINI\") \n" 1199 +
" transitions {\n" 1203 +
" final state FINI {\n" 1208 +
" do y1.deactivate()\n" 1210 +
" transitions {\n" 1215 +
" RootMachine X x() \n" 1218 this->doState(
"x", prog, tc );
1219 this->finishState(
"x", tc);
1222 #ifdef ORO_SIGNALLING_OPERATIONS 1226 string prog = string(
"StateMachine X {\n")
1227 +
" var double et = 0.0\n" 1228 +
" initial state INIT {\n" 1229 +
" transition o_event(et) { test.assert(et == 3.33); } select FINI\n" 1231 +
" final state FINI { entry { test.assert( et == 3.33);} } \n" 1233 +
"RootMachine X x()\n";
1234 this->parseState( prog, tc );
1236 BOOST_REQUIRE( sm );
1237 this->runState(
"x", tc);
1238 checkState(
"x", tc);
1241 checkState(
"x", tc);
1243 checkState(
"x", tc);
1244 BOOST_CHECK( sm->inState(
"FINI") );
1245 this->checkState(
"x",tc);
1246 this->finishState(
"x", tc);
1252 string prog = string(
"StateMachine X {\n")
1253 +
" var double et = 0.0\n" 1254 +
" initial state INIT {\n" 1255 +
" transition caller.c_event(et) select FINI\n" 1257 +
" final state FINI {} \n" 1259 +
"RootMachine X x()\n";
1260 this->parseState( prog, tc );
1262 BOOST_REQUIRE( sm );
1263 this->runState(
"x", tc);
1264 checkState(
"x", tc);
1266 checkState(
"x", tc);
1269 checkState(
"x", tc);
1271 checkState(
"x", tc);
1272 BOOST_CHECK( sm->inState(
"FINI") );
1273 this->checkState(
"x",tc);
1274 this->finishState(
"x", tc);
1280 string prog = string(
"StateMachine X {\n")
1281 +
" initial state INIT {\n" 1282 +
" transitions { select STATE1 }\n" 1284 +
" state STATE1 {\n" 1285 +
" transition v_event() select STATE2\n" 1287 +
" state STATE2 {\n" 1288 +
" transition v_event() select FINI\n" 1290 +
" final state FINI {} \n" 1292 +
"RootMachine X x()\n";
1293 this->parseState( prog, tc );
1295 BOOST_REQUIRE( sm );
1298 this->runState(
"x", tc);
1299 checkState(
"x", tc);
1300 BOOST_CHECK_EQUAL(
"STATE1", sm->getCurrentStateName() );
1303 checkState(
"x", tc);
1304 BOOST_CHECK_EQUAL(
"STATE1", sm->getCurrentStateName() );
1307 BOOST_REQUIRE( mo.ready() );
1310 checkState(
"x", tc);
1311 BOOST_CHECK_EQUAL(
"STATE2", sm->getCurrentStateName() );
1314 checkState(
"x", tc);
1315 BOOST_CHECK_EQUAL(
"STATE2", sm->getCurrentStateName() );
1319 checkState(
"x", tc);
1320 BOOST_CHECK_EQUAL(
"FINI", sm->getCurrentStateName() );
1322 checkState(
"x", tc);
1323 BOOST_CHECK_EQUAL(
"FINI", sm->getCurrentStateName() );
1324 this->checkState(
"x",tc);
1325 this->finishState(
"x", tc);
1331 string prog = string(
"StateMachine X {\n")
1332 +
" initial state INIT {\n" 1333 +
" transitions { select STATE1 }\n" 1335 +
" state STATE1 {\n" 1336 +
" var double d;\n" 1337 +
" transition v_event() select STATE2\n" 1338 +
" transition v_event() select ERROR\n" 1339 +
" transition o_event(d) select ERROR\n" 1340 +
" transition v_event() select ERROR\n" 1342 +
" state STATE2 {\n" 1343 +
" transition v_event() select FINI\n" 1344 +
" transition v_event() select ERROR\n" 1345 +
" transition o_event(d) select ERROR\n" 1346 +
" transition v_event() select ERROR\n" 1348 +
" state ERROR {} \n" 1349 +
" final state FINI {} \n" 1351 +
"RootMachine X x()\n";
1352 this->parseState( prog, tc );
1354 BOOST_REQUIRE( sm );
1357 this->runState(
"x", tc);
1358 checkState(
"x", tc);
1359 BOOST_CHECK_EQUAL(
"STATE1", sm->getCurrentStateName() );
1362 checkState(
"x", tc);
1363 BOOST_CHECK_EQUAL(
"STATE1", sm->getCurrentStateName() );
1367 BOOST_REQUIRE( mo.ready() );
1373 checkState(
"x", tc);
1374 BOOST_CHECK_EQUAL(
"STATE2", sm->getCurrentStateName() );
1377 checkState(
"x", tc);
1378 BOOST_CHECK_EQUAL(
"STATE2", sm->getCurrentStateName() );
1385 checkState(
"x", tc);
1386 BOOST_CHECK_EQUAL(
"FINI", sm->getCurrentStateName() );
1388 checkState(
"x", tc);
1389 BOOST_CHECK_EQUAL(
"FINI", sm->getCurrentStateName() );
1390 this->checkState(
"x",tc);
1391 this->finishState(
"x", tc);
1397 string prog = string(
"StateMachine X {\n")
1398 +
" initial state INIT {\n" 1399 +
" transitions { select IDLE }\n" 1402 +
" transition v1_event() select STATE1\n" 1403 +
" transition v2_event() select STATE2\n" 1404 +
" transition v3_event() select STATE3\n" 1406 +
" state STATE1 {\n" 1407 +
" transition v_event() select IDLE\n" 1408 +
" transition v2_event() select STATE2\n" 1409 +
" transition v3_event() select STATE3\n" 1411 +
" state STATE2 {\n" 1412 +
" transition v_event() select IDLE\n" 1413 +
" transition v1_event() select STATE1\n" 1414 +
" transition v3_event() select STATE3\n" 1416 +
" state STATE3 {\n" 1417 +
" transition v_event() select IDLE\n" 1418 +
" transition v1_event() select STATE1\n" 1419 +
" transition v2_event() select STATE2\n" 1421 +
" final state FINI {} \n" 1423 +
"RootMachine X x()\n";
1424 this->parseState( prog, tc );
1426 BOOST_REQUIRE( sm );
1427 this->runState(
"x", tc);
1429 checkState(
"x", tc);
1430 BOOST_CHECK_EQUAL(
"IDLE", sm->getCurrentStateName() );
1432 checkState(
"x", tc);
1433 BOOST_CHECK_EQUAL(
"IDLE", sm->getCurrentStateName() );
1436 BOOST_REQUIRE( v.ready() );
1438 BOOST_REQUIRE( v1.ready() );
1440 BOOST_REQUIRE( v2.ready() );
1442 BOOST_REQUIRE( v3.ready() );
1444 #define DO_EVENT(event, name) \ 1446 BOOST_CHECK( SimulationThread::Instance()->run(1) ); \ 1447 checkState( "x", tc); \ 1448 BOOST_CHECK_EQUAL( name, sm->getCurrentStateName() ); \ 1449 BOOST_CHECK( SimulationThread::Instance()->run(100) ); \ 1450 checkState( "x", tc); \ 1451 BOOST_CHECK_EQUAL( name, sm->getCurrentStateName() ) 1453 DO_EVENT(v2,
"STATE2");
1454 DO_EVENT(v1,
"STATE1");
1455 DO_EVENT(v1,
"STATE1");
1456 DO_EVENT(v3,
"STATE3");
1457 DO_EVENT(v,
"IDLE");
1458 DO_EVENT(v3,
"STATE3");
1459 DO_EVENT(v,
"IDLE");
1460 DO_EVENT(v1,
"STATE1");
1464 this->checkState(
"x",tc);
1465 this->finishState(
"x", tc);
1470 string prog = string(
"StateMachine X {\n")
1471 +
" var double et = 0.0\n" 1472 +
" initial state INIT {\n" 1473 +
" transition o_event(et) { test.i = 5; } select FINI\n" 1475 +
" final state FINI {} \n" 1477 +
"RootMachine X x()\n";
1478 this->parseState( prog, tc );
1480 BOOST_REQUIRE( sm );
1482 this->runState(
"x", tc);
1483 checkState(
"x", tc);
1488 checkState(
"x", tc);
1490 BOOST_CHECK_EQUAL( i, 5 );
1491 checkState(
"x", tc);
1492 BOOST_CHECK( sm->inState(
"FINI") );
1493 this->checkState(
"x",tc);
1494 this->finishState(
"x", tc);
1499 string prog = string(
"StateMachine X {\n")
1500 +
" var double et = 0.0\n" 1501 +
" initial state INIT {\n" 1502 +
" transition o_event(et) if (et == 3.33) then \n" 1504 +
" else {log(\"received et != 3.33: \"+et+\": will fail.\") } select FAIL\n" 1506 +
" final state FINI {} \n" 1507 +
" state FAIL {} \n" 1509 +
"RootMachine X x()\n";
1510 this->parseState( prog, tc );
1512 BOOST_REQUIRE( sm );
1514 this->runState(
"x", tc);
1515 checkState(
"x", tc);
1520 checkState(
"x", tc);
1522 checkState(
"x", tc);
1523 BOOST_CHECK( sm->inState(
"FINI") );
1524 this->checkState(
"x",tc);
1525 this->finishState(
"x", tc);
1530 string prog = string(
"StateMachine X {\n")
1531 +
" var double et = 0.0\n" 1532 +
" initial state INIT {\n" 1533 +
" transition caller.c_event(et) if (et == 3.33) then\n" 1535 +
" else select FAIL\n" 1537 +
" final state FINI {} \n" 1538 +
" state FAIL {} \n" 1540 +
"RootMachine X x()\n";
1541 this->parseState( prog, tc );
1543 BOOST_REQUIRE( sm );
1545 this->runState(
"x", tc);
1546 checkState(
"x", tc);
1550 checkState(
"x", tc);
1552 checkState(
"x", tc);
1553 BOOST_CHECK( sm->inState(
"FINI") );
1554 this->checkState(
"x",tc);
1555 this->finishState(
"x", tc);
1562 string prog = string(
"StateMachine Y {\n")
1563 +
" var int t = 0\n" 1564 +
" var double et_global = 0.0, et_local = 0.0\n" 1565 +
" var bool eb = false\n" 1566 +
" var bool eflag = false\n" 1567 +
" transition t_event(t) { do log(\"Global Transition to TESTSELF\");} select TESTSELF\n" 1568 +
" transition d_event(et_global)\n" 1569 +
" if et_global < 0. then { do log(\"Global ISNEGATIVE Transition\");} select ISNEGATIVE\n" 1570 +
" else { do log(\"Global ISPOSITIVE Transition\");} select ISPOSITIVE\n" 1571 +
" initial state INIT {\n" 1572 +
" entry { do log(\"INIT\"); set eb = false; }\n" 1574 +
" state ISNEGATIVE {\n" 1575 +
" entry { do log(\"ISNEGATIVE\");}\n" 1576 +
" transition b_event(eb)\n" 1577 +
" if (eb) then { do log(\"Local ISNEGATIVE->INIT Transition\");} select INIT\n" 1579 +
" state ISPOSITIVE {\n" 1580 +
" entry { do log(\"ISPOSITIVE\");}\n" 1581 +
" transition b_event(eb)\n" 1582 +
" if (eb == true) then { do log(\"Local ISPOSITIVE->INIT Transition for b_event\");} select INIT\n" 1583 #ifdef ORO_SIGNALLING_OPERATIONS 1584 +
" transition o_event(et_local)\n" 1585 +
" if ( et_local == 3.0 ) then { do log(\"Local ISPOSITIVE->INIT Transition for o_event == \" + et_local);} select INIT\n" 1586 +
" else { do log(\"Invalid et_local: \"+et_local); } \n" 1589 +
" state TESTSELF {\n" 1591 +
" do log(\"TESTSELF\");\n" 1592 +
" set eflag = !eflag\n" 1594 +
" transition t_event(t) { do log(\"Self Transition in TESTSELF\");} select TESTSELF\n" 1595 +
" transition b_event(eb)\n" 1596 +
" if (eb == true) then { do log(\"Local TESTSELF->INIT Transition\");} select INIT\n" 1597 +
" else { log(\"Failed to select INIT upon event.\");}\n" 1599 +
" final state FINI {\n" 1600 +
" entry { do log(\"FINI\");}\n" 1603 + string(
"StateMachine X {\n")
1604 +
" SubMachine Y y1()\n" 1605 +
" initial state XINIT {\n" 1607 +
" do y1.trace(true)\n" 1608 +
" do y1.activate()\n" 1609 +
" do y1.start()\n" 1614 +
" do d_event_source.write(-1.0)\n" 1616 +
" do test.assert( !y1.inState(\"INIT\") )\n" 1617 +
" do test.assert( !y1.inState(\"ISPOSITIVE\") )\n" 1618 +
" do test.assert( y1.inState(\"ISNEGATIVE\") )\n" 1619 +
" do b_event_source.write( true )\n" 1621 +
" do test.assert( y1.inState(\"INIT\") )\n" 1622 +
" do d_event_source.write(+1.0)\n" 1625 +
" do test.assert( !y1.inState(\"INIT\") )\n" 1626 +
" do test.assert( y1.inState(\"ISPOSITIVE\") )\n" 1627 +
" do test.assert( !y1.inState(\"ISNEGATIVE\") )\n" 1628 +
" if ( !y1.inState(\"ISPOSITIVE\") ) then\n" 1629 +
" do test.assertMsg( false, \"Not ISNEGATIVE but \" + y1.getState() )\n" 1630 +
" do test.assert( y1.inState(\"ISPOSITIVE\") )\n" 1631 +
" do b_event_source.write( true )\n" 1633 +
" do test.assert( y1.inState(\"INIT\") )\n" 1634 #ifdef ORO_SIGNALLING_OPERATIONS 1636 +
" do d_event_source.write(+1.0)\n" 1639 +
" do test.assert( !y1.inState(\"INIT\") )\n" 1640 +
" do test.assert( y1.inState(\"ISPOSITIVE\") )\n" 1641 +
" do test.assert( !y1.inState(\"ISNEGATIVE\") )\n" 1642 +
" if ( !y1.inState(\"ISPOSITIVE\") ) then\n" 1643 +
" do test.assertMsg( false, \"Not ISPOSITIVE but \" + y1.getState() )\n" 1644 +
" do test.assert( y1.inState(\"ISPOSITIVE\") )\n" 1645 +
" do o_event( 3.0 )\n" 1649 +
" do test.assert( y1.inState(\"INIT\") )\n" 1652 +
" set y1.eflag = true;\n" 1653 +
" do t_event_source.write(1)\n" 1655 +
" do test.assert( !y1.inState(\"INIT\") )\n" 1656 +
" do test.assert( !y1.inState(\"ISPOSITIVE\") )\n" 1657 +
" do test.assert( !y1.inState(\"ISNEGATIVE\") )\n" 1658 +
" do test.assert( y1.inState(\"TESTSELF\") )\n" 1659 +
" do test.assert( y1.eflag == false ) /* first */\n" 1660 +
" do t_event_source.write(1)\n" 1662 +
" do test.assert( y1.inState(\"TESTSELF\") )\n" 1663 +
" do test.assert( y1.eflag == false ) /* second */\n" 1664 +
" do log(\"Trigger b_event.\");\n" 1665 +
" do b_event_source.write(true);\n" 1667 +
" do test.assert( y1.inState(\"INIT\") ) /* last */\n" 1669 +
" transitions {\n" 1673 +
" final state XFINI {\n" 1675 +
" do y1.deactivate()\n" 1678 +
" transitions {\n" 1683 +
" RootMachine X x() \n" 1686 this->doState(
"x", prog, tc );
1688 this->finishState(
"x", tc);
1695 string prog = string(
"StateMachine Y {\n")
1696 +
" var int t = 0\n" 1697 +
" var double et_global = 0.0, et_local = 0.0\n" 1698 +
" var bool eb = false\n" 1699 +
" var bool eflag = false\n" 1700 +
" transition if ( t_event.read(t) == NewData && t == 1 ) then { do log(\"Global Transition to TESTSELF\");} select TESTSELF\n" 1701 +
" transition d_event(et_global) if ( et_global < 0.) then \n" 1702 +
" { do log(\"Global ISNEGATIVE Transition\");} select ISNEGATIVE\n" 1703 +
" else { do log(\"Global ISPOSITIVE Transition\");} select ISPOSITIVE\n" 1704 +
" initial state INIT {\n" 1705 +
" entry { do log(\"INIT\"); set eb = false; }\n" 1707 +
" state ISNEGATIVE {\n" 1708 +
" entry { do log(\"ISNEGATIVE\");}\n" 1709 +
" transition if ( b_event.read(eb) != NoData && eb )\n" 1710 +
" then { do log(\"Local ISNEGATIVE->INIT Transition\");} select INIT\n" 1712 +
" state ISPOSITIVE {\n" 1713 +
" entry { do log(\"ISPOSITIVE\");}\n" 1714 +
" transition if ( b_event.read(eb) != NoData && eb == true) \n" 1715 +
" then { do log(\"Local ISPOSITIVE->INIT Transition for b_event\");} select INIT\n" 1716 #ifdef ORO_SIGNALLING_OPERATIONS 1717 +
" transition o_event(et_local) if ( et_local == 3.0)\n" 1718 +
" then { do log(\"Local ISPOSITIVE->INIT Transition for o_event == \" + et_local);} select INIT\n" 1719 +
" else { do log(\"Local ISPOSITIVE->INIT Transition FAILED for o_event == \" + et_local);}\n" 1722 +
" state TESTSELF {\n" 1724 +
" do log(\"TESTSELF\");\n" 1725 +
" set eflag = !eflag\n" 1727 +
" transition if ( t_event.read(t) == NewData ) { do log(\"Self Transition in TESTSELF\");} select TESTSELF\n" 1728 +
" transition if ( b_event.read(eb) == NewData && eb == true )\n" 1729 +
" then { do log(\"Local TESTSELF->INIT Transition\");} select INIT\n" 1730 +
" else { log(\"Failed to select INIT upon event.\");}\n" 1732 +
" final state FINI {\n" 1733 +
" entry { do log(\"FINI\");}\n" 1736 + string(
"StateMachine X {\n")
1737 +
" SubMachine Y y1()\n" 1738 +
" initial state INIT {\n" 1740 +
" do y1.trace(true)\n" 1741 +
" do y1.activate()\n" 1742 +
" do y1.start()\n" 1747 +
" do d_event_source.write(-1.0)\n" 1749 +
" do test.assert( !y1.inState(\"INIT\") )\n" 1750 +
" do test.assert( !y1.inState(\"ISPOSITIVE\") )\n" 1751 +
" do test.assert( y1.inState(\"ISNEGATIVE\") )\n" 1752 +
" do b_event_source.write( true )\n" 1754 +
" do test.assert( y1.inState(\"INIT\") )\n" 1755 +
" do b_event_source.write( false )\n" 1757 +
" do d_event_source.write(+1.0)\n" 1759 +
" do test.assert( !y1.inState(\"INIT\") )\n" 1760 +
" do test.assert( y1.inState(\"ISPOSITIVE\") )\n" 1761 +
" do test.assert( !y1.inState(\"ISNEGATIVE\") )\n" 1762 +
" if ( !y1.inState(\"ISPOSITIVE\") ) then\n" 1763 +
" do test.assertMsg( false, \"Not ISNEGATIVE but \" + y1.getState() )\n" 1764 +
" do test.assert( y1.inState(\"ISPOSITIVE\") )\n" 1765 +
" do b_event_source.write( true )\n" 1768 +
" do test.assert( y1.inState(\"INIT\") )\n" 1769 +
" do b_event_source.write( false )\n" 1770 #ifdef ORO_SIGNALLING_OPERATIONS 1772 +
" do d_event_source.write(+1.0)\n" 1774 +
" do test.assert( !y1.inState(\"INIT\") )\n" 1775 +
" do test.assert( y1.inState(\"ISPOSITIVE\") )\n" 1776 +
" do test.assert( !y1.inState(\"ISNEGATIVE\") )\n" 1777 +
" if ( !y1.inState(\"ISPOSITIVE\") ) then\n" 1778 +
" do test.assertMsg( false, \"Not ISPOSITIVE but \" + y1.getState() )\n" 1779 +
" do test.assert( y1.inState(\"ISPOSITIVE\") )\n" 1780 +
" do o_event( 3.0 )\n" 1784 +
" do test.assert( y1.inState(\"INIT\") )\n" 1787 +
" set y1.eflag = true;\n" 1788 +
" do t_event_source.write(1)\n" 1790 +
" do test.assert( !y1.inState(\"INIT\") )\n" 1791 +
" do test.assert( !y1.inState(\"ISPOSITIVE\") )\n" 1792 +
" do test.assert( !y1.inState(\"ISNEGATIVE\") )\n" 1793 +
" do test.assert( y1.inState(\"TESTSELF\") )\n" 1794 +
" do test.assert( y1.eflag == false ) /* first */\n" 1795 +
" do t_event_source.write(1)\n" 1797 +
" do test.assert( y1.inState(\"TESTSELF\") )\n" 1798 +
" do test.assert( y1.eflag == false ) /* second */\n" 1799 +
" do log(\"Trigger b_event.\");\n" 1800 +
" do b_event_source.write(true);\n" 1802 +
" do test.assert( y1.inState(\"INIT\") ) /* last */\n" 1804 +
" transitions {\n" 1808 +
" final state FINI {\n" 1810 +
" do y1.deactivate()\n" 1813 +
" transitions {\n" 1818 +
" RootMachine X x() \n" 1821 this->doState(
"x", prog, tc,
true, 100 );
1823 this->finishState(
"x", tc);
1828 string prog = string(
"StateMachine X {\n")
1829 +
" initial state INIT {\n" 1830 +
" transitions {select FINI} \n" 1832 +
" final state FINI {\n" 1834 +
" try scripting.deactivateStateMachine(\"x\")\n" 1838 +
"RootMachine X x()\n";
1839 this->parseState( prog, tc );
1841 BOOST_REQUIRE( sm );
1843 runState(
"x", tc,
false);
1844 BOOST_CHECK( !sm->isActive() );
1846 runState(
"x", tc,
true);
1847 BOOST_CHECK( !sm->isActive() );
1853 string prog = string(
"StateMachine X {\n")
1854 +
" initial state INIT {\n" 1855 +
" transitions {select FINI} \n" 1857 +
" final state FINI {\n" 1859 +
" try scripting.deactivateStateMachine(\"x\")\n" 1863 +
"RootMachine X x()\n";
1864 this->parseState( prog, tc );
1866 BOOST_REQUIRE( sm );
1868 runState(
"x", tc,
false);
1869 BOOST_CHECK( !sm->isActive() );
1871 runState(
"x", tc,
true);
1872 BOOST_CHECK( !sm->isActive() );
1877 string prog = string(
"StateMachine X {\n")
1878 +
" initial state INIT {\n" 1880 +
" try scripting.deactivateStateMachine(\"x\")\n" 1882 +
" transition if false == true then select FINI \n" 1884 +
" final state FINI {\n" 1887 +
"RootMachine X x()\n";
1888 this->parseState( prog, tc );
1890 BOOST_REQUIRE( sm );
1892 runState(
"x", tc,
false);
1893 BOOST_CHECK( !sm->isActive() );
1895 runState(
"x", tc,
true);
1896 BOOST_CHECK( !sm->isActive() );
1901 string prog = string(
"StateMachine X {\n")
1902 +
" initial state INIT {\n" 1904 +
" try scripting.deactivateStateMachine(\"x\")\n" 1906 +
" transitions {select FINI} \n" 1908 +
" final state FINI {\n" 1911 +
"RootMachine X x()\n";
1912 this->parseState( prog, tc );
1914 BOOST_REQUIRE( sm );
1916 runState(
"x", tc,
false);
1917 BOOST_CHECK( !sm->isActive() );
1919 runState(
"x", tc,
true);
1920 BOOST_CHECK( !sm->isActive() );
1925 string prog = string(
"StateMachine X {\n")
1926 +
" initial state INIT {\n" 1927 +
" transition if true then {\n" 1928 +
" scripting.deactivateStateMachine(\"x\")\n" 1929 +
" }select FINI \n" 1931 +
" final state FINI {\n" 1934 +
"RootMachine X x()\n";
1935 this->parseState( prog, tc );
1937 BOOST_REQUIRE( sm );
1939 runState(
"x", tc,
false);
1940 BOOST_CHECK( !sm->isActive() );
1942 runState(
"x", tc,
true);
1943 BOOST_CHECK( !sm->isActive() );
1950 BOOST_CHECK( tc->engine() );
1952 parseState( prog, tc, test);
1953 runState(name, tc,
true, test,runs);
1954 checkState(name, tc, test);
1961 sa->loadStateMachines( prog, std::string(
"state_test.cpp"),
true );
1965 BOOST_REQUIRE_MESSAGE( !test, exc.
what() );
1969 BOOST_REQUIRE_MESSAGE( !test, exc.
what() );
1973 BOOST_REQUIRE_MESSAGE( !test, e.
what() );
1975 catch(
const std::exception& e ) {
1976 BOOST_CHECK_MESSAGE( !test , e.what());
1977 BOOST_REQUIRE_MESSAGE( !test,
"Uncaught Processor load exception" );
1984 BOOST_REQUIRE( sm );
1987 for( StateMachine::ChildList::iterator it = children.begin(); it != children.end(); ++it)
1988 (*it)->trace(trace);
1991 BOOST_CHECK( act(sm) );
1993 BOOST_CHECK_MESSAGE( sm->isActive(),
"Error : Activate Command for '"+sm->getName()+
"' did not have effect." );
1994 BOOST_CHECK( autom(sm) || !test );
2002 BOOST_REQUIRE( sm );
2005 BOOST_CHECK_MESSAGE( sm->isActive(),
"Error : State Context '"+sm->getName()+
"' did not get activated." );
2006 stringstream errormsg;
2007 int line = sm->getLineNumber();
2008 errormsg <<
" in StateMachine "+sm->getName()
2009 <<
" in state "<< (sm->currentState() ? sm->currentState()->getName() :
"(null)")
2010 <<
" on line " << line <<
" of that StateMachine:"<<
endl;
2012 stringstream sctext( sm->getText() );
2014 while ( cnt++ <line && sctext ) {
2016 getline( sctext, garbage,
'\n' );
2018 getline( sctext, sline,
'\n' );
2020 errormsg <<
"here > " << sline <<
endl;
2021 if ( sm->inError() ) {
2025 BOOST_CHECK_MESSAGE( sm->inError() ==
false,
"Runtime error (inError() == true) encountered" + errormsg.str() );
2028 StateMachine::ChildList::iterator clit = cl.begin();
2029 while( clit != cl.end() ) {
2030 line = (*clit)->getLineNumber();
2032 stringstream sctext( (*clit)->getText() );
2034 while ( cnt++ <line && sctext ) {
2036 getline( sctext, garbage,
'\n' );
2038 getline( sctext, sline,
'\n' );
2040 stringstream cerrormsg;
2041 if ( (*clit)->currentState() )
2042 cerrormsg <<
" in child "<< (*clit)->getName() <<
" in state "<<(*clit)->currentState()->getName()<<
" on line " << (*clit)->getLineNumber() <<
" of that StateMachine."<<endl <<
"here > " << sline <<
endl;
2044 cerrormsg <<
" child "<< (*clit)->getName() <<
" (deactivated) on line " << (*clit)->getLineNumber() <<
" of that StateMachine."<<endl<<
"here > " << sline <<
endl;
2046 BOOST_CHECK_MESSAGE( (*clit)->inError() ==
false,
"Runtime error (inError() == true) encountered" + cerrormsg.str() );
2047 if ( (*clit)->inError() ==
false && sm->inError() ==
true) {
2048 cout <<
"Child Status:" << cerrormsg.str() <<
endl;
2058 BOOST_REQUIRE( sm );
2059 BOOST_CHECK( sa->getStateMachine( name )->stop() );
2062 stringstream errormsg;
2063 errormsg <<
" on line " << sm->getLineNumber() <<
", status is "<< sa->getStateMachineStatusStr(name) <<
endl <<
"here > " << sline <<
endl;;
2064 BOOST_CHECK_MESSAGE( sm->isStopped(),
"StateMachine stalled " + errormsg.str() );
2068 BOOST_CHECK( sa->getStateMachine( name )->deactivate() );
2070 if ( sm->isActive() )
2071 BOOST_CHECK( sa->getStateMachine( name )->deactivate() );
2073 BOOST_CHECK( sa->getStateMachine( name )->isActive() == false );
2079 BOOST_CHECK( sa->unloadStateMachine( name ) );
2083 BOOST_REQUIRE_MESSAGE(
false, e.
what() );
2086 BOOST_REQUIRE_MESSAGE(
false,
"Uncaught Processor unload exception" );
void checkState(const std::string &name, TaskContext *, bool test=true)
Operation< Signature > & doc(const std::string &description)
const std::string what() const
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
boost::shared_ptr< ScriptingService > shared_ptr
const char * what() const
Service::shared_ptr provides()
virtual const std::string what() const =0
std::basic_string< char, std::char_traits< char >, RTT::os::rt_allocator< char > > rt_string
Real-time allocatable, dynamically-sized string.
#define BOOST_AUTO_TEST_SUITE_END()
Operation< void(double)> o_event
InputPort< double > d_event
BOOST_AUTO_TEST_CASE(testParseState)
Operation< void(void)> v_event
ScriptingService::shared_ptr sa
Operation< void(double)> c_event
void DumpObject(Service::shared_ptr peer)
const char * what() const
static RTT_API ExecutionEngine * Instance()
void log(const std::string &msg)
void finishState(std::string const &name, TaskContext *, bool test=true)
virtual bool connectTo(PortInterface *other, ConnPolicy const &policy)
boost::shared_ptr< StateMachine > StateMachinePtr
OutputPort< bool > b_event_source
Operation< void(void)> v2_event
basic_ostreams & endl(basic_ostreams &s)
An Activity executes a RunnableInterface object in a (periodic) thread.
std::vector< StateMachinePtr > ChildList
unsigned int sleep(unsigned int s)
void setState(RTT::rt_string state)
OutputPort< double > d_event_source
void parseState(const std::string &prog, TaskContext *, bool test=true)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
RTT::Operation< void(RTT::rt_string)> setState_op
Operation< void(void)> v1_event
OutputPort< int > t_event_source
Operation< void(void)> v3_event
static Logger::LogFunction endlog()
void runState(const std::string &name, TaskContext *, bool trace=true, bool test=true, int runs=1000)
InputPort< bool > b_event