46 #ifndef StateMachine_cpp 47 #define StateMachine_cpp 49 #include <cppunit/ui/text/TestRunner.h> 50 #include <cppunit/TextOutputter.h> 51 #include <cppunit/extensions/TestFactoryRegistry.h> 52 #include <cppunit/extensions/HelperMacros.h> 53 #include <cppunit/TestAssert.h> 55 #include <coil/TimeValue.h> 77 static const int DO = 2;
84 m_fsm.setListener(
this);
126 m_fsm.setStartState(initialStates);
131 for (
int i = 0; i < 50; ++i)
291 m_callbackLog.push_back(sa);
296 :
public CppUnit::TestFixture
299 CPPUNIT_TEST(test_transition_story1);
300 CPPUNIT_TEST_SUITE_END();
348 SMC::StateAndAction expected[] =
350 { SMC::STATE_1, SMC::PREDO },
351 { SMC::STATE_1, SMC::EXIT },
352 { SMC::STATE_2, SMC::ENTRY },
353 { SMC::STATE_2, SMC::PREDO },
354 { SMC::STATE_2, SMC::DO },
355 { SMC::STATE_2, SMC::EXIT },
356 { SMC::STATE_3, SMC::ENTRY },
357 { SMC::STATE_3, SMC::PREDO },
358 { SMC::STATE_3, SMC::DO },
359 { SMC::STATE_3, SMC::POSTDO },
360 { SMC::STATE_3, SMC::EXIT },
361 { SMC::STATE_4, SMC::ENTRY },
362 { SMC::STATE_4, SMC::EXIT },
363 { SMC::STATE_5, SMC::ENTRY },
364 { SMC::STATE_5, SMC::PREDO },
365 { SMC::STATE_5, SMC::DO },
366 { SMC::STATE_5, SMC::POSTDO },
367 { SMC::STATE_5, SMC::PREDO }
373 const std::vector<SMC::StateAndAction> log = context.getCallbackLog();
374 for (
int i = 0; i <
sizeof(expected) /
sizeof(SMC::StateAndAction); ++i)
376 CPPUNIT_ASSERT_EQUAL(expected[i].
state, log[i].state);
377 CPPUNIT_ASSERT_EQUAL(expected[i].
action, log[i].action);
390 int main(
int argc,
char* argv[])
403 std::string arg(argv[i]);
404 std::string next_arg;
405 if (i + 1 < argc) next_arg = argv[i + 1];
408 if (arg ==
"--text") { format =
TEXT_OUT;
break; }
421 ofs.open(fname.c_str());
423 if ( arg ==
"--compiler" ) { format =
COMPILER_OUT;
break; }
424 if ( arg ==
"--cerr" ) { target = 1;
break; }
425 if ( arg ==
"--xsl" )
427 if (next_arg ==
"") xsl =
"default.xsl";
430 if ( arg ==
"--namespace" )
434 std::cerr <<
"no namespace specified" << std::endl;
444 CppUnit::TextUi::TestRunner runner;
446 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
448 runner.addTest(CppUnit::TestFactoryRegistry::getRegistry(ns).makeTest());
449 CppUnit::Outputter* outputter = 0;
450 std::ostream* stream = target ? &std::cerr : &std::cout;
454 outputter =
new CppUnit::TextOutputter(&runner.result(),*stream);
457 std::cout <<
"XML_OUT" << std::endl;
458 outputter =
new CppUnit::XmlOutputter(&runner.result(),
460 static_cast<CppUnit::XmlOutputter*
>(outputter)->setStyleSheet(xsl);
463 outputter =
new CppUnit::CompilerOutputter(&runner.result(),*stream);
466 runner.setOutputter(outputter);
471 #endif // StateMachine_cpp void onPreDo_STATE_1(const RTC_Utils::StateHolder< int > &states)
int main(int argc, char **argv)
void onPostDo_STATE_1(const RTC_Utils::StateHolder< int > &states)
~StateMachineTests()
Destructor.
void onDo_STATE_4(const RTC_Utils::StateHolder< int > &states)
virtual void setUp()
Test initialization.
void onExit_STATE_1(const RTC_Utils::StateHolder< int > &states)
void onDo_STATE_6(const RTC_Utils::StateHolder< int > &states)
void onPostDo_STATE_3(const RTC_Utils::StateHolder< int > &states)
static const int SIZEOF_ACTION
void onEntry_STATE_6(const RTC_Utils::StateHolder< int > &states)
void onPostDo_STATE_6(const RTC_Utils::StateHolder< int > &states)
void onPreDo_STATE_3(const RTC_Utils::StateHolder< int > &states)
void onDo_STATE_2(const RTC_Utils::StateHolder< int > &states)
void onPreDo_STATE_6(const RTC_Utils::StateHolder< int > &states)
void onEntry_STATE_5(const RTC_Utils::StateHolder< int > &states)
void onDo_STATE_5(const RTC_Utils::StateHolder< int > &states)
void onExit_STATE_5(const RTC_Utils::StateHolder< int > &states)
void logCallback(int state, int action)
void onPostDo_STATE_5(const RTC_Utils::StateHolder< int > &states)
void onDo_STATE_3(const RTC_Utils::StateHolder< int > &states)
void onExit_STATE_2(const RTC_Utils::StateHolder< int > &states)
StateMachineTests()
Constructor.
static const int SIZEOF_STATE
const std::vector< StateAndAction > & getCallbackLog() const
void onExit_STATE_6(const RTC_Utils::StateHolder< int > &states)
void test_transition_story1()
StateMachineによる状態遷移のテスト
virtual void tearDown()
Test finalization.
void onDo_STATE_1(const RTC_Utils::StateHolder< int > &states)
void onExit_STATE_4(const RTC_Utils::StateHolder< int > &states)
void onExit_STATE_3(const RTC_Utils::StateHolder< int > &states)
void onPostDo_STATE_2(const RTC_Utils::StateHolder< int > &states)
std::vector< StateAndAction > m_callbackLog
void onPreDo_STATE_4(const RTC_Utils::StateHolder< int > &states)
RTC_Utils::StateMachine< int, StateMachineContext1 > m_fsm
void onEntry_STATE_1(const RTC_Utils::StateHolder< int > &states)
void onEntry_STATE_2(const RTC_Utils::StateHolder< int > &states)
State machine template class.
void onPreDo_STATE_5(const RTC_Utils::StateHolder< int > &states)
void onEntry_STATE_4(const RTC_Utils::StateHolder< int > &states)
void onPostDo_STATE_4(const RTC_Utils::StateHolder< int > &states)
void onPreDo_STATE_2(const RTC_Utils::StateHolder< int > &states)
CPPUNIT_TEST_SUITE_REGISTRATION(StateMachineTests::StateMachineTests)
void onEntry_STATE_3(const RTC_Utils::StateHolder< int > &states)