12 #include <rtt-config.h> 42 void doState(
const std::string& name,
const std::string& prog,
TaskContext*,
bool test=
true );
43 void parseState(
const std::string& prog,
TaskContext*,
bool test=
true );
44 void runState(
const std::string& name,
TaskContext*,
bool test=
true );
45 void checkState(
const std::string& name,
TaskContext*,
bool test=
true );
46 void finishState( std::string
const& name,
TaskContext*,
bool test=
true );
69 string prog = string(
"StateMachine X {\n")
70 +
" initial state INIT {\n" 71 +
" var rt_string s1\n" 72 +
" transitions { select FINI }\n" 74 +
" final state FINI {\n" 77 +
" RootMachine X x\n" 80 this->doState(
"x", prog, tc );
81 this->finishState(
"x", tc );
86 string prog = string(
"StateMachine X {\n")
87 +
" initial state INIT {\n" 88 +
" var rt_string s1(22)\n" 89 +
" transitions { select FINI }\n" 91 +
" final state FINI {\n" 94 +
" RootMachine X x\n" 97 this->doState(
"x", prog, tc );
98 this->finishState(
"x", tc );
105 string prog = string(
"StateMachine X {\n")
106 +
" initial state INIT {\n" 107 +
" var rt_string s1(\"hello world\")\n" 108 +
" transitions { select FINI }\n" 110 +
" final state FINI {\n" 113 +
" RootMachine X x\n" 115 this->doState(
"x", prog, tc );
116 this->finishState(
"x", tc );
122 string prog = string(
"StateMachine X {\n")
123 +
" initial state INIT {\n" 124 +
" var rt_string s1 = rt_string(\"hello world\")\n" 125 +
" transitions { select FINI }\n" 127 +
" final state FINI {\n" 130 +
" RootMachine X x\n" 133 this->doState(
"x", prog, tc );
134 this->finishState(
"x", tc );
139 string prog = string(
"StateMachine X {\n")
140 +
" initial state INIT {\n" 141 +
" var rt_string s1\n" 143 +
" s1 = rt_string(\"Multiply \")\n" 145 +
" s1 = s1 + rt_string(\" times \")\n" 146 +
" s1 = s1 + 33.3\n" 147 +
" s1 = rt_string(\"Now: \") + 1 + rt_string(\"st \") + s1 + '!'\n" 149 +
" transitions { select FINI }\n" 151 +
" final state FINI {\n" 154 +
" RootMachine X x\n" 157 this->doState(
"x", prog, tc );
158 this->finishState(
"x", tc );
163 string prog = string(
"StateMachine X {\n")
164 +
" initial state INIT {\n" 165 +
" var rt_string rts1\n" 169 +
" rts1 = rt_string(\"rts1\")\n" 170 +
" test.assert(s1 == \"s1\")\n" 171 +
" test.assert(rts1 == rt_string(\"rts1\"))\n" 172 +
" s1 = string(rts1)\n" 173 +
" test.assert(s1 == string(rts1))\n" 174 +
" test.assert(s1 == \"rts1\")\n" 176 +
" rts1 = rt_string(s1)\n" 177 +
" test.assert(rts1 == rt_string(\"s1\"))\n" 178 +
" s1 = string( rt_string(\" s1 \") )\n" 179 +
" rts1 = rt_string( string(\" rts1 \") )\n" 180 +
" test.assert(s1 == \" s1 \")\n" 181 +
" test.assert(rts1 == rt_string(\" rts1 \"))\n" 183 +
" transitions { select FINI }\n" 185 +
" final state FINI {\n" 188 +
" RootMachine X x\n" 191 this->doState(
"x", prog, tc );
192 this->finishState(
"x", tc );
200 BOOST_CHECK( tc->engine() );
202 parseState( prog, tc, test);
203 runState(name, tc, test);
204 checkState(name, tc, test);
211 sa->loadStateMachines( prog, std::string(
"state_test.cpp"),
true );
215 BOOST_REQUIRE_MESSAGE( !test, exc.
what() );
219 BOOST_REQUIRE_MESSAGE( !test, exc.
what() );
223 BOOST_REQUIRE_MESSAGE( !test, e.
what() );
225 catch(
const std::exception& e ) {
226 BOOST_CHECK_MESSAGE( !test , e.what());
227 BOOST_REQUIRE_MESSAGE( !test,
"Uncaught Processor load exception" );
238 BOOST_CHECK( act(sm.get()) );
240 BOOST_CHECK_MESSAGE( sm->isActive(),
"Error : Activate Command for '"+sm->getName()+
"' did not have effect." );
241 BOOST_CHECK( autom(sm.get()) || !test );
252 BOOST_CHECK_MESSAGE( sm->isActive(),
"Error : State Context '"+sm->getName()+
"' did not get activated." );
253 stringstream errormsg;
254 int line = sm->getLineNumber();
255 errormsg <<
" in StateMachine "+sm->getName()
256 <<
" in state "<< (sm->currentState() ? sm->currentState()->getName() :
"(null)")
257 <<
" on line " << line <<
" of that StateMachine:"<<
endl;
259 stringstream sctext( sm->getText() );
261 while ( cnt++ <line && sctext ) {
263 getline( sctext, garbage,
'\n' );
265 getline( sctext, sline,
'\n' );
267 errormsg <<
"here > " << sline <<
endl;
268 if ( sm->inError() ) {
272 BOOST_CHECK_MESSAGE( sm->inError() ==
false,
"Runtime error (inError() == true) encountered" + errormsg.str() );
275 StateMachine::ChildList::iterator clit = cl.begin();
276 while( clit != cl.end() ) {
277 line = (*clit)->getLineNumber();
279 stringstream sctext( (*clit)->getText() );
281 while ( cnt++ <line && sctext ) {
283 getline( sctext, garbage,
'\n' );
285 getline( sctext, sline,
'\n' );
287 stringstream cerrormsg;
288 if ( (*clit)->currentState() )
289 cerrormsg <<
" in child "<< (*clit)->getName() <<
" in state "<<(*clit)->currentState()->getName()<<
" on line " << (*clit)->getLineNumber() <<
" of that StateMachine."<<endl <<
"here > " << sline <<
endl;
291 cerrormsg <<
" child "<< (*clit)->getName() <<
" (deactivated) on line " << (*clit)->getLineNumber() <<
" of that StateMachine."<<endl<<
"here > " << sline <<
endl;
293 BOOST_CHECK_MESSAGE( (*clit)->inError() ==
false,
"Runtime error (inError() == true) encountered" + cerrormsg.str() );
294 if ( (*clit)->inError() ==
false && sm->inError() ==
true) {
295 cout <<
"Child Status:" << cerrormsg.str() <<
endl;
306 BOOST_CHECK( sa->getStateMachine( name )->stop() );
309 stringstream errormsg;
310 errormsg <<
" on line " << sm->getLineNumber() <<
", status is "<< sa->getStateMachineStatusStr(name) <<
endl <<
"here > " << sline <<
endl;;
311 BOOST_CHECK_MESSAGE( sm->isStopped(),
"StateMachine stalled " + errormsg.str() );
315 BOOST_CHECK( sa->getStateMachine( name )->deactivate() );
317 if ( sm->isActive() )
318 BOOST_CHECK( sa->getStateMachine( name )->deactivate() );
320 BOOST_CHECK( sa->getStateMachine( name )->isActive() == false );
326 BOOST_CHECK( sa->unloadStateMachine( name ) );
330 BOOST_REQUIRE_MESSAGE(
false, e.
what() );
333 BOOST_REQUIRE_MESSAGE(
false,
"Uncaught Processor unload exception" );
void checkState(const std::string &name, TaskContext *, bool test=true)
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
void parseState(const std::string &prog, TaskContext *, bool test=true)
#define BOOST_AUTO_TEST_SUITE_END()
void runState(const std::string &name, TaskContext *, bool test=true)
void DumpObject(Service::shared_ptr peer)
const char * what() const
void finishState(std::string const &name, TaskContext *, bool test=true)
This class is the public interface to the Orocos Program Parser Framework. It parsers Orocos program ...
boost::shared_ptr< StateMachine > StateMachinePtr
basic_ostreams & endl(basic_ostreams &s)
std::vector< StateMachinePtr > ChildList
ScriptingService::shared_ptr sa
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
BOOST_AUTO_TEST_CASE(testCreateRtString)