summaryrefslogtreecommitdiffstats
path: root/test/src/test-lifecycle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/src/test-lifecycle.cpp')
-rw-r--r--test/src/test-lifecycle.cpp346
1 files changed, 293 insertions, 53 deletions
diff --git a/test/src/test-lifecycle.cpp b/test/src/test-lifecycle.cpp
index 4c044c4..c0fb55c 100644
--- a/test/src/test-lifecycle.cpp
+++ b/test/src/test-lifecycle.cpp
@@ -88,8 +88,115 @@ void customTerminate() {
#endif
abort();
}
+
+using namespace uscxml;
+
+enum CallbackType {
+ USCXML_BEFOREPROCESSINGEVENT,
+ USCXML_BEFOREMICROSTEP,
+ USCXML_BEFOREEXITINGSTATE,
+ USCXML_AFTEREXITINGSTATE,
+ USCXML_BEFOREEXECUTINGCONTENT,
+ USCXML_AFTEREXECUTINGCONTENT,
+ USCXML_BEFOREUNINVOKING,
+ USCXML_AFTERUNINVOKING,
+ USCXML_BEFORETAKINGTRANSITION,
+ USCXML_AFTERTAKINGTRANSITION,
+ USCXML_BEFOREENTERINGSTATE,
+ USCXML_AFTERENTERINGSTATE,
+ USCXML_BEFOREINVOKING,
+ USCXML_AFTERINVOKING,
+ USCXML_AFTERMICROSTEP,
+ USCXML_ONSTABLECONFIGURATION,
+ USCXML_BEFORECOMPLETION,
+ USCXML_AFTERCOMPLETION
+};
+
+std::list<CallbackType> callBackSeq;
+
+#define CHECK_CALLBACK_TYPE(type)\
+{\
+ assert(!callBackSeq.empty());\
+ assert(callBackSeq.front() == type);\
+ callBackSeq.pop_front();\
+}
+
+
+class SequenceCheckingMonitor : public InterpreterMonitor {
+ virtual void beforeProcessingEvent(Interpreter interpreter, const Event& event) {
+ CHECK_CALLBACK_TYPE(USCXML_BEFOREPROCESSINGEVENT);
+ }
+ virtual void beforeMicroStep(Interpreter interpreter) {
+ CHECK_CALLBACK_TYPE(USCXML_BEFOREMICROSTEP);
+ }
+
+ virtual void beforeExitingState(Interpreter interpreter, const Arabica::DOM::Element<std::string>& state, bool moreComing) {
+ if (!moreComing)
+ CHECK_CALLBACK_TYPE(USCXML_BEFOREEXITINGSTATE);
+ }
+ virtual void afterExitingState(Interpreter interpreter, const Arabica::DOM::Element<std::string>& state, bool moreComing) {
+ if (!moreComing)
+ CHECK_CALLBACK_TYPE(USCXML_AFTEREXITINGSTATE);
+ }
+
+ virtual void beforeExecutingContent(Interpreter interpreter, const Arabica::DOM::Element<std::string>& element) {
+ CHECK_CALLBACK_TYPE(USCXML_BEFOREEXECUTINGCONTENT);
+ }
+ virtual void afterExecutingContent(Interpreter interpreter, const Arabica::DOM::Element<std::string>& element) {
+ CHECK_CALLBACK_TYPE(USCXML_AFTEREXECUTINGCONTENT);
+ }
+
+ virtual void beforeUninvoking(Interpreter interpreter, const Arabica::DOM::Element<std::string>& invokeElem, const std::string& invokeid) {
+ CHECK_CALLBACK_TYPE(USCXML_BEFOREUNINVOKING);
+ }
+ virtual void afterUninvoking(Interpreter interpreter, const Arabica::DOM::Element<std::string>& invokeElem, const std::string& invokeid) {
+ CHECK_CALLBACK_TYPE(USCXML_AFTERUNINVOKING);
+ }
+
+ virtual void beforeTakingTransition(Interpreter interpreter, const Arabica::DOM::Element<std::string>& transition, bool moreComing) {
+ if (!moreComing)
+ CHECK_CALLBACK_TYPE(USCXML_BEFORETAKINGTRANSITION);
+ }
+ virtual void afterTakingTransition(Interpreter interpreter, const Arabica::DOM::Element<std::string>& transition, bool moreComing) {
+ if (!moreComing)
+ CHECK_CALLBACK_TYPE(USCXML_AFTERTAKINGTRANSITION);
+ }
+
+ virtual void beforeEnteringState(Interpreter interpreter, const Arabica::DOM::Element<std::string>& state, bool moreComing) {
+ if (!moreComing)
+ CHECK_CALLBACK_TYPE(USCXML_BEFOREENTERINGSTATE);
+ }
+ virtual void afterEnteringState(Interpreter interpreter, const Arabica::DOM::Element<std::string>& state, bool moreComing) {
+ if (!moreComing)
+ CHECK_CALLBACK_TYPE(USCXML_AFTERENTERINGSTATE);
+ }
+
+ virtual void beforeInvoking(Interpreter interpreter, const Arabica::DOM::Element<std::string>& invokeElem, const std::string& invokeid) {
+ CHECK_CALLBACK_TYPE(USCXML_BEFOREINVOKING);
+ }
+ virtual void afterInvoking(Interpreter interpreter, const Arabica::DOM::Element<std::string>& invokeElem, const std::string& invokeid) {
+ CHECK_CALLBACK_TYPE(USCXML_AFTERINVOKING);
+ }
+
+ virtual void afterMicroStep(Interpreter interpreter) {
+ CHECK_CALLBACK_TYPE(USCXML_AFTERMICROSTEP);
+ }
+
+ virtual void onStableConfiguration(Interpreter interpreter) {
+ CHECK_CALLBACK_TYPE(USCXML_ONSTABLECONFIGURATION);
+ }
+
+ virtual void beforeCompletion(Interpreter interpreter) {
+ CHECK_CALLBACK_TYPE(USCXML_BEFORECOMPLETION);
+ }
+ virtual void afterCompletion(Interpreter interpreter) {
+ CHECK_CALLBACK_TYPE(USCXML_AFTERCOMPLETION);
+ }
+
+};
+
+
int main(int argc, char** argv) {
- using namespace uscxml;
std::set_terminate(customTerminate);
@@ -99,80 +206,213 @@ int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
google::LogToStderr();
- InterpreterState state;
+ SequenceCheckingMonitor* mon = new SequenceCheckingMonitor();
+
int iterations = 1;
while(iterations--) {
if (1) {
// syntactic xml parse error
- const char* xml = "<invalid>";
- Interpreter interpreter = Interpreter::fromXML(xml);
- state = interpreter.getState();
- assert(!interpreter);
- assert(state == uscxml::InterpreterState::USCXML_FAULTED);
- std::cout << interpreter.getState() << std::endl;
+ try {
+ const char* xml = "<invalid";
+ Interpreter interpreter = Interpreter::fromXML(xml);
+ assert(false);
+ } catch (Event& e) {
+ std::cout << e;
+ }
}
if (1) {
// semantic xml parse error
- const char* xml = "<invalid />";
- Interpreter interpreter = Interpreter::fromXML(xml);
- state = interpreter.getState();
- assert(state == uscxml::InterpreterState::USCXML_INSTANTIATED);
+ try {
+ const char* xml = "<invalid />";
+ Interpreter interpreter = Interpreter::fromXML(xml);
+ interpreter.addMonitor(mon);
+ assert(interpreter.getState() == USCXML_INSTANTIATED);
+ interpreter.step();
+ assert(false);
+ } catch (Event& e) {
+ std::cout << e;
+ }
+ }
- assert(interpreter.step() == uscxml::InterpreterState::USCXML_FAULTED);
- std::cout << interpreter.getState() << std::endl;
+ if (1) {
+ // request unknown datamodel
+ try {
+ const char* xml =
+ "<scxml datamodel=\"invalid\">"
+ " <state id=\"start\">"
+ " <transition target=\"done\" />"
+ " </state>"
+ " <final id=\"done\" />"
+ "</scxml>";
+ Interpreter interpreter = Interpreter::fromXML(xml);
+ interpreter.addMonitor(mon);
+ assert(interpreter.getState() == USCXML_INSTANTIATED);
+ interpreter.step();
+ assert(false);
+ } catch (Event& e) {
+ std::cout << e;
+ }
}
if (1) {
+ // two microsteps
+ const char* xml =
+ "<scxml>"
+ " <state id=\"start\">"
+ " <transition target=\"s2\" />"
+ " </state>"
+ " <state id=\"s2\">"
+ " <transition target=\"done\" />"
+ " </state>"
+ " <final id=\"done\" />"
+ "</scxml>";
+
+ Interpreter interpreter = Interpreter::fromXML(xml);
+ interpreter.addMonitor(mon);
+
+ callBackSeq.push_back(USCXML_BEFOREENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERENTERINGSTATE);
+
+ callBackSeq.push_back(USCXML_BEFOREMICROSTEP);
+ callBackSeq.push_back(USCXML_BEFOREEXITINGSTATE);
+ callBackSeq.push_back(USCXML_AFTEREXITINGSTATE);
+ callBackSeq.push_back(USCXML_BEFORETAKINGTRANSITION);
+ callBackSeq.push_back(USCXML_AFTERTAKINGTRANSITION);
+ callBackSeq.push_back(USCXML_BEFOREENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERMICROSTEP);
+
+ callBackSeq.push_back(USCXML_BEFOREMICROSTEP);
+ callBackSeq.push_back(USCXML_BEFOREEXITINGSTATE);
+ callBackSeq.push_back(USCXML_AFTEREXITINGSTATE);
+ callBackSeq.push_back(USCXML_BEFORETAKINGTRANSITION);
+ callBackSeq.push_back(USCXML_AFTERTAKINGTRANSITION);
+ callBackSeq.push_back(USCXML_BEFOREENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERMICROSTEP);
+
+ callBackSeq.push_back(USCXML_BEFORECOMPLETION);
+ callBackSeq.push_back(USCXML_AFTERCOMPLETION);
+
+ assert(interpreter.getState() == USCXML_INSTANTIATED);
+ assert(interpreter.step() == USCXML_MICROSTEPPED);
+ assert(interpreter.step() == USCXML_MICROSTEPPED);
+ assert(interpreter.step() == USCXML_FINISHED);
+ assert(callBackSeq.empty());
+ }
+
+ if (1) {
// single macrostep, multiple runs
const char* xml =
- "<scxml>"
- " <state id=\"start\">"
- " <transition target=\"done\" />"
- " </state>"
- " <final id=\"done\" />"
- "</scxml>";
-
+ "<scxml>"
+ " <state id=\"start\">"
+ " <transition target=\"done\" />"
+ " </state>"
+ " <final id=\"done\" />"
+ "</scxml>";
+
Interpreter interpreter = Interpreter::fromXML(xml);
- assert(interpreter.getState() == uscxml::InterpreterState::USCXML_INSTANTIATED);
- assert(interpreter.step() == uscxml::InterpreterState::USCXML_MICROSTEPPED);
- assert(interpreter.step() == uscxml::InterpreterState::USCXML_FINISHED);
- interpreter.reset();
- assert(interpreter.getState() == uscxml::InterpreterState::USCXML_INSTANTIATED);
- assert(interpreter.step() == uscxml::InterpreterState::USCXML_MICROSTEPPED);
- assert(interpreter.step() == uscxml::InterpreterState::USCXML_FINISHED);
- interpreter.reset();
- assert(interpreter.getState() == uscxml::InterpreterState::USCXML_INSTANTIATED);
- assert(interpreter.step() == uscxml::InterpreterState::USCXML_MICROSTEPPED);
- assert(interpreter.step() == uscxml::InterpreterState::USCXML_FINISHED);
+ interpreter.addMonitor(mon);
+
+ callBackSeq.push_back(USCXML_BEFOREENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERENTERINGSTATE);
+
+ callBackSeq.push_back(USCXML_BEFOREMICROSTEP);
+ callBackSeq.push_back(USCXML_BEFOREEXITINGSTATE);
+ callBackSeq.push_back(USCXML_AFTEREXITINGSTATE);
+ callBackSeq.push_back(USCXML_BEFORETAKINGTRANSITION);
+ callBackSeq.push_back(USCXML_AFTERTAKINGTRANSITION);
+ callBackSeq.push_back(USCXML_BEFOREENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERMICROSTEP);
+
+ callBackSeq.push_back(USCXML_BEFORECOMPLETION);
+ callBackSeq.push_back(USCXML_AFTERCOMPLETION);
+
+ assert(interpreter.getState() == USCXML_INSTANTIATED);
+ assert(interpreter.step() == USCXML_MICROSTEPPED);
+ assert(interpreter.step() == USCXML_FINISHED);
interpreter.reset();
- assert(interpreter.getState() == uscxml::InterpreterState::USCXML_INSTANTIATED);
- assert(interpreter.step() == uscxml::InterpreterState::USCXML_MICROSTEPPED);
- assert(interpreter.step() == uscxml::InterpreterState::USCXML_FINISHED);
- }
+ callBackSeq.push_back(USCXML_BEFOREENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERENTERINGSTATE);
+
+ callBackSeq.push_back(USCXML_BEFOREMICROSTEP);
+ callBackSeq.push_back(USCXML_BEFOREEXITINGSTATE);
+ callBackSeq.push_back(USCXML_AFTEREXITINGSTATE);
+ callBackSeq.push_back(USCXML_BEFORETAKINGTRANSITION);
+ callBackSeq.push_back(USCXML_AFTERTAKINGTRANSITION);
+ callBackSeq.push_back(USCXML_BEFOREENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERMICROSTEP);
+
+ callBackSeq.push_back(USCXML_BEFORECOMPLETION);
+ callBackSeq.push_back(USCXML_AFTERCOMPLETION);
+
+ assert(interpreter.getState() == USCXML_INSTANTIATED);
+ assert(interpreter.step() == USCXML_MICROSTEPPED);
+ assert(interpreter.step() == USCXML_FINISHED);
+ }
+
if (1) {
- // two microsteps
+ // macrostep in between
const char* xml =
- "<scxml>"
- " <state id=\"start\">"
- " <transition target=\"s2\" />"
- " </state>"
- " <state id=\"s2\">"
- " <transition target=\"done\" />"
- " </state>"
- " <final id=\"done\" />"
- "</scxml>";
-
+ "<scxml>"
+ " <state id=\"start\">"
+ " <onentry>"
+ " <send event=\"continue\" delay=\"2s\"/>"
+ " </onentry>"
+ " <transition target=\"s2\" event=\"continue\" />"
+ " </state>"
+ " <state id=\"s2\">"
+ " <transition target=\"done\" />"
+ " </state>"
+ " <final id=\"done\" />"
+ "</scxml>";
+
Interpreter interpreter = Interpreter::fromXML(xml);
-
- assert(interpreter.getState() == uscxml::InterpreterState::USCXML_INSTANTIATED);
- assert(interpreter.step() == uscxml::InterpreterState::USCXML_MICROSTEPPED);
- assert(interpreter.step() == uscxml::InterpreterState::USCXML_MICROSTEPPED);
- assert(interpreter.step() == uscxml::InterpreterState::USCXML_FINISHED);
+ interpreter.addMonitor(mon);
+
+ callBackSeq.push_back(USCXML_BEFOREENTERINGSTATE);
+ callBackSeq.push_back(USCXML_BEFOREEXECUTINGCONTENT);
+ callBackSeq.push_back(USCXML_AFTEREXECUTINGCONTENT);
+ callBackSeq.push_back(USCXML_AFTERENTERINGSTATE);
+ callBackSeq.push_back(USCXML_ONSTABLECONFIGURATION);
+
+ callBackSeq.push_back(USCXML_BEFOREPROCESSINGEVENT);
+ callBackSeq.push_back(USCXML_BEFOREMICROSTEP);
+ callBackSeq.push_back(USCXML_BEFOREEXITINGSTATE);
+ callBackSeq.push_back(USCXML_AFTEREXITINGSTATE);
+ callBackSeq.push_back(USCXML_BEFORETAKINGTRANSITION);
+ callBackSeq.push_back(USCXML_AFTERTAKINGTRANSITION);
+ callBackSeq.push_back(USCXML_BEFOREENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERMICROSTEP);
+
+ callBackSeq.push_back(USCXML_BEFOREMICROSTEP);
+ callBackSeq.push_back(USCXML_BEFOREEXITINGSTATE);
+ callBackSeq.push_back(USCXML_AFTEREXITINGSTATE);
+ callBackSeq.push_back(USCXML_BEFORETAKINGTRANSITION);
+ callBackSeq.push_back(USCXML_AFTERTAKINGTRANSITION);
+ callBackSeq.push_back(USCXML_BEFOREENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERENTERINGSTATE);
+ callBackSeq.push_back(USCXML_AFTERMICROSTEP);
+
+ callBackSeq.push_back(USCXML_BEFORECOMPLETION);
+ callBackSeq.push_back(USCXML_AFTERCOMPLETION);
+
+ assert(interpreter.getState() == USCXML_INSTANTIATED);
+ assert(interpreter.step() == USCXML_IDLE);
+ assert(interpreter.step(true) == USCXML_MACROSTEPPED);
+ assert(interpreter.step() == USCXML_MICROSTEPPED);
+ assert(interpreter.step() == USCXML_FINISHED);
}
+
+#if 0
+
if (0) {
// macrostep in between
@@ -271,7 +511,7 @@ int main(int argc, char** argv) {
assert(!(state & InterpreterState::USCXML_THREAD_RUNNING));
}
+#endif
}
-
return EXIT_SUCCESS;
} \ No newline at end of file