diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-06-23 23:38:20 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-06-23 23:38:20 (GMT) |
commit | febde41c4c69d8f38967d5c195328d468834d037 (patch) | |
tree | 4580a433d410e91a6f8df9203c20693e7a21128d /test/src | |
parent | eb6e9807cdb43b408de45ae789916cdf3bebe6f0 (diff) | |
download | uscxml-febde41c4c69d8f38967d5c195328d468834d037.zip uscxml-febde41c4c69d8f38967d5c195328d468834d037.tar.gz uscxml-febde41c4c69d8f38967d5c195328d468834d037.tar.bz2 |
Updated tests for IRP and work on bindings
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/test-lifecycle.cpp | 193 | ||||
-rw-r--r-- | test/src/test-predicates.cpp | 16 |
2 files changed, 177 insertions, 32 deletions
diff --git a/test/src/test-lifecycle.cpp b/test/src/test-lifecycle.cpp index 09341a3..d28d1a5 100644 --- a/test/src/test-lifecycle.cpp +++ b/test/src/test-lifecycle.cpp @@ -99,31 +99,176 @@ int main(int argc, char** argv) { google::InitGoogleLogging(argv[0]); google::LogToStderr(); - - Interpreter interpreter = Interpreter::fromURI("/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/ecma/test207.scxml"); InterpreterState state; - do { - state = interpreter.step(true); - switch (state) { - case uscxml::FINISHED: - std::cout << "FINISHED" << std::endl; - break; - case uscxml::INIT_FAILED: - std::cout << "INIT_FAILED" << std::endl; - break; - case uscxml::NOTHING_TODO: - std::cout << "NOTHING_TODO" << std::endl; - break; - case uscxml::INTERRUPTED: - std::cout << "INTERRUPTED" << std::endl; - break; - case uscxml::PROCESSED: - std::cout << "PROCESSED" << std::endl; - break; - default: - break; - } - } while(state != FINISHED); + + 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; + } + + if (1) { + // semantic xml parse error + const char* xml = "<invalid />"; + Interpreter interpreter = Interpreter::fromXML(xml); + state = interpreter.getState(); + assert(state == uscxml::InterpreterState::USCXML_INSTANTIATED); + + assert(interpreter.step() == uscxml::InterpreterState::USCXML_FAULTED); + std::cout << interpreter.getState() << std::endl; + } + + if (1) { + // single macrostep, multiple runs + const char* xml = + "<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.reset(); + assert(interpreter.getState() == uscxml::InterpreterState::USCXML_INSTANTIATED); + assert(interpreter.step() == uscxml::InterpreterState::USCXML_MICROSTEPPED); + assert(interpreter.step() == uscxml::InterpreterState::USCXML_FINISHED); + } + + 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); + + 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); + } + + if (0) { + // macrostep in between + const char* xml = + "<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_IDLE); + assert(interpreter.step(true) == uscxml::InterpreterState::USCXML_MACROSTEPPED); + 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_IDLE); + assert(interpreter.step(true) == uscxml::InterpreterState::USCXML_MACROSTEPPED); + assert(interpreter.step() == uscxml::InterpreterState::USCXML_MICROSTEPPED); + assert(interpreter.step() == uscxml::InterpreterState::USCXML_FINISHED); + } + + if (1) { + // macrostep in between, external event + const char* xml = + "<scxml>" + " <state id=\"start\">" + " <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_IDLE); + interpreter.receive(Event("continue")); + assert(interpreter.step(true) == uscxml::InterpreterState::USCXML_MACROSTEPPED); + 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_IDLE); + interpreter.receive(Event("continue")); + assert(interpreter.step(true) == uscxml::InterpreterState::USCXML_MACROSTEPPED); + assert(interpreter.step() == uscxml::InterpreterState::USCXML_MICROSTEPPED); + assert(interpreter.step() == uscxml::InterpreterState::USCXML_FINISHED); + } + + if (1) { + // macrostep in between, external event + const char* xml = + "<scxml>" + " <state id=\"start\">" + " <transition target=\"s2\" event=\"continue\" />" + " </state>" + " <state id=\"s2\">" + " <transition target=\"done\" />" + " </state>" + " <final id=\"done\" />" + "</scxml>"; + + Interpreter interpreter = Interpreter::fromXML(xml); + interpreter.start(); + // assume interpreter is started + assert(interpreter.getState() & InterpreterState::USCXML_THREAD_STARTED); + tthread::this_thread::sleep_for(tthread::chrono::milliseconds(100)); + + // assume it is started and running + std::cout << interpreter.getState() << std::endl; + + assert(interpreter.getState() & InterpreterState::USCXML_THREAD_STARTED); + assert(interpreter.getState() & InterpreterState::USCXML_THREAD_RUNNING); + assert(interpreter.getState() & InterpreterState::USCXML_IDLE); + + interpreter.receive(Event("continue")); + tthread::this_thread::sleep_for(tthread::chrono::milliseconds(200)); + + std::cout << interpreter.getState() << std::endl; + int state = interpreter.getState(); + assert(state & InterpreterState::USCXML_FINISHED); + assert(!(state & InterpreterState::USCXML_THREAD_STARTED)); + assert(!(state & InterpreterState::USCXML_THREAD_RUNNING)); + + } + return EXIT_SUCCESS; }
\ No newline at end of file diff --git a/test/src/test-predicates.cpp b/test/src/test-predicates.cpp index 00be408..3e3c278 100644 --- a/test/src/test-predicates.cpp +++ b/test/src/test-predicates.cpp @@ -15,17 +15,17 @@ int main(int argc, char** argv) { Interpreter interpreter = Interpreter::fromURI(argv[1]); assert(interpreter); - Node<std::string> atomicState = interpreter.getState("atomic"); + Node<std::string> atomicState = interpreter.getImpl()->getState("atomic"); assert(InterpreterImpl::isAtomic(atomicState)); assert(!InterpreterImpl::isParallel(atomicState)); assert(!InterpreterImpl::isCompound(atomicState)); - Node<std::string> compoundState = interpreter.getState("compound"); + Node<std::string> compoundState = interpreter.getImpl()->getState("compound"); assert(!InterpreterImpl::isAtomic(compoundState)); assert(!InterpreterImpl::isParallel(compoundState)); assert(InterpreterImpl::isCompound(compoundState)); - Node<std::string> parallelState = interpreter.getState("parallel"); + Node<std::string> parallelState = interpreter.getImpl()->getState("parallel"); assert(!InterpreterImpl::isAtomic(parallelState)); assert(InterpreterImpl::isParallel(parallelState)); assert(!InterpreterImpl::isCompound(parallelState)); // parallel states are not compound! @@ -34,12 +34,12 @@ int main(int argc, char** argv) { assert(initialState[0] == atomicState); NodeSet<std::string> childs = interpreter.getImpl()->getChildStates(compoundState); - Node<std::string> compoundChild1 = interpreter.getState("compoundChild1"); - Node<std::string> compoundChild2 = interpreter.getState("compoundChild2"); + Node<std::string> compoundChild1 = interpreter.getImpl()->getState("compoundChild1"); + Node<std::string> compoundChild2 = interpreter.getImpl()->getState("compoundChild2"); assert(childs.size() > 0); - assert(Interpreter::isMember(compoundChild1, childs)); - assert(Interpreter::isMember(compoundChild2, childs)); - assert(!Interpreter::isMember(compoundState, childs)); + assert(InterpreterImpl::isMember(compoundChild1, childs)); + assert(InterpreterImpl::isMember(compoundChild2, childs)); + assert(!InterpreterImpl::isMember(compoundState, childs)); assert(InterpreterImpl::isDescendant(compoundChild1, compoundState)); |