diff options
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/test-lifecycle.cpp | 102 | ||||
-rw-r--r-- | test/src/test-predicates.cpp | 248 |
2 files changed, 132 insertions, 218 deletions
diff --git a/test/src/test-lifecycle.cpp b/test/src/test-lifecycle.cpp index 7cbb68b..22c724a 100644 --- a/test/src/test-lifecycle.cpp +++ b/test/src/test-lifecycle.cpp @@ -410,108 +410,6 @@ int main(int argc, char** argv) { assert(interpreter.step() == USCXML_MICROSTEPPED); assert(interpreter.step() == USCXML_FINISHED); } - -#if 0 - - - 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)); - - } -#endif } return EXIT_SUCCESS; }
\ No newline at end of file diff --git a/test/src/test-predicates.cpp b/test/src/test-predicates.cpp index 3e3c278..d672577 100644 --- a/test/src/test-predicates.cpp +++ b/test/src/test-predicates.cpp @@ -1,123 +1,139 @@ #define protected public #include "uscxml/Interpreter.h" #undef protected +#include <iostream> int main(int argc, char** argv) { - if (argc != 2) { - std::cerr << "Expected path to test-predicates.scxml" << std::endl; - exit(EXIT_FAILURE); + try { + using namespace uscxml; + using namespace Arabica::DOM; + using namespace Arabica::XPath; + + const char* xml = + "<scxml>" + " <state id=\"atomic\" />" + " <state id=\"compound\">" + " <state id=\"compoundChild1\" />" + " <state id=\"compoundChild2\" />" + " </state>" + " <parallel id=\"parallel\">" + " </parallel>" + "</scxml>"; + + Interpreter interpreter = Interpreter::fromXML(xml); + assert(interpreter); + interpreter.getImpl()->init(); + + 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.getImpl()->getState("compound"); + assert(!InterpreterImpl::isAtomic(compoundState)); + assert(!InterpreterImpl::isParallel(compoundState)); + assert(InterpreterImpl::isCompound(compoundState)); + + 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! + + NodeSet<std::string> initialState = interpreter.getImpl()->getInitialStates(); + assert(initialState[0] == atomicState); + + NodeSet<std::string> childs = interpreter.getImpl()->getChildStates(compoundState); + Node<std::string> compoundChild1 = interpreter.getImpl()->getState("compoundChild1"); + Node<std::string> compoundChild2 = interpreter.getImpl()->getState("compoundChild2"); + assert(childs.size() > 0); + assert(InterpreterImpl::isMember(compoundChild1, childs)); + assert(InterpreterImpl::isMember(compoundChild2, childs)); + assert(!InterpreterImpl::isMember(compoundState, childs)); + + assert(InterpreterImpl::isDescendant(compoundChild1, compoundState)); + + { + std::string idrefs("id1"); + std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + assert(tokenizedIdrefs.size() == 1); + assert(tokenizedIdrefs.front().compare("id1") == 0); + } + + { + std::string idrefs(" id1"); + std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + assert(tokenizedIdrefs.size() == 1); + assert(tokenizedIdrefs.front().compare("id1") == 0); + } + + { + std::string idrefs(" id1 "); + std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + assert(tokenizedIdrefs.size() == 1); + assert(tokenizedIdrefs.front().compare("id1") == 0); + } + + { + std::string idrefs(" \tid1\n "); + std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + assert(tokenizedIdrefs.size() == 1); + assert(tokenizedIdrefs.front().compare("id1") == 0); + } + + { + std::string idrefs("id1 id2 id3"); + std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + assert(tokenizedIdrefs.size() == 3); + assert(tokenizedIdrefs.front().compare("id1") == 0); + tokenizedIdrefs.pop_front(); + assert(tokenizedIdrefs.front().compare("id2") == 0); + tokenizedIdrefs.pop_front(); + assert(tokenizedIdrefs.front().compare("id3") == 0); + } + + { + std::string idrefs("\t id1 \nid2\n\n id3\t"); + std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + assert(tokenizedIdrefs.size() == 3); + assert(tokenizedIdrefs.front().compare("id1") == 0); + tokenizedIdrefs.pop_front(); + assert(tokenizedIdrefs.front().compare("id2") == 0); + tokenizedIdrefs.pop_front(); + assert(tokenizedIdrefs.front().compare("id3") == 0); + } + + { + std::string idrefs("id1 \nid2 \tid3"); + std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); + assert(tokenizedIdrefs.size() == 3); + assert(tokenizedIdrefs.front().compare("id1") == 0); + tokenizedIdrefs.pop_front(); + assert(tokenizedIdrefs.front().compare("id2") == 0); + tokenizedIdrefs.pop_front(); + assert(tokenizedIdrefs.front().compare("id3") == 0); + } + + std::string transEvents; + transEvents = "error"; + assert(InterpreterImpl::nameMatch(transEvents, "error")); + assert(!InterpreterImpl::nameMatch(transEvents, "foo")); + + transEvents = "error foo"; + assert(InterpreterImpl::nameMatch(transEvents, "error")); + assert(InterpreterImpl::nameMatch(transEvents, "error.send")); + assert(InterpreterImpl::nameMatch(transEvents, "error.send.failed")); + assert(InterpreterImpl::nameMatch(transEvents, "foo")); + assert(InterpreterImpl::nameMatch(transEvents, "foo.bar")); + assert(!InterpreterImpl::nameMatch(transEvents, "errors.my.custom")); + assert(!InterpreterImpl::nameMatch(transEvents, "errorhandler.mistake")); + // is the event name case sensitive? + // assert(!InterpreterImpl::nameMatch(transEvents, "errOr.send")); + assert(!InterpreterImpl::nameMatch(transEvents, "foobar")); + } catch(std::exception e) { + std::cout << e.what(); + return false; + } catch(uscxml::Event e) { + std::cout << e; + return false; } - - using namespace uscxml; - using namespace Arabica::DOM; - using namespace Arabica::XPath; - - Interpreter interpreter = Interpreter::fromURI(argv[1]); - assert(interpreter); - - 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.getImpl()->getState("compound"); - assert(!InterpreterImpl::isAtomic(compoundState)); - assert(!InterpreterImpl::isParallel(compoundState)); - assert(InterpreterImpl::isCompound(compoundState)); - - 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! - - NodeSet<std::string> initialState = interpreter.getImpl()->getInitialStates(); - assert(initialState[0] == atomicState); - - NodeSet<std::string> childs = interpreter.getImpl()->getChildStates(compoundState); - Node<std::string> compoundChild1 = interpreter.getImpl()->getState("compoundChild1"); - Node<std::string> compoundChild2 = interpreter.getImpl()->getState("compoundChild2"); - assert(childs.size() > 0); - assert(InterpreterImpl::isMember(compoundChild1, childs)); - assert(InterpreterImpl::isMember(compoundChild2, childs)); - assert(!InterpreterImpl::isMember(compoundState, childs)); - - assert(InterpreterImpl::isDescendant(compoundChild1, compoundState)); - - { - std::string idrefs("id1"); - std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); - assert(tokenizedIdrefs.size() == 1); - assert(tokenizedIdrefs.front().compare("id1") == 0); - } - - { - std::string idrefs(" id1"); - std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); - assert(tokenizedIdrefs.size() == 1); - assert(tokenizedIdrefs.front().compare("id1") == 0); - } - - { - std::string idrefs(" id1 "); - std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); - assert(tokenizedIdrefs.size() == 1); - assert(tokenizedIdrefs.front().compare("id1") == 0); - } - - { - std::string idrefs(" \tid1\n "); - std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); - assert(tokenizedIdrefs.size() == 1); - assert(tokenizedIdrefs.front().compare("id1") == 0); - } - - { - std::string idrefs("id1 id2 id3"); - std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); - assert(tokenizedIdrefs.size() == 3); - assert(tokenizedIdrefs.front().compare("id1") == 0); - tokenizedIdrefs.pop_front(); - assert(tokenizedIdrefs.front().compare("id2") == 0); - tokenizedIdrefs.pop_front(); - assert(tokenizedIdrefs.front().compare("id3") == 0); - } - - { - std::string idrefs("\t id1 \nid2\n\n id3\t"); - std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); - assert(tokenizedIdrefs.size() == 3); - assert(tokenizedIdrefs.front().compare("id1") == 0); - tokenizedIdrefs.pop_front(); - assert(tokenizedIdrefs.front().compare("id2") == 0); - tokenizedIdrefs.pop_front(); - assert(tokenizedIdrefs.front().compare("id3") == 0); - } - - { - std::string idrefs("id1 \nid2 \tid3"); - std::list<std::string> tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); - assert(tokenizedIdrefs.size() == 3); - assert(tokenizedIdrefs.front().compare("id1") == 0); - tokenizedIdrefs.pop_front(); - assert(tokenizedIdrefs.front().compare("id2") == 0); - tokenizedIdrefs.pop_front(); - assert(tokenizedIdrefs.front().compare("id3") == 0); - } - - std::string transEvents; - transEvents = "error"; - assert(InterpreterImpl::nameMatch(transEvents, "error")); - assert(!InterpreterImpl::nameMatch(transEvents, "foo")); - - transEvents = "error foo"; - assert(InterpreterImpl::nameMatch(transEvents, "error")); - assert(InterpreterImpl::nameMatch(transEvents, "error.send")); - assert(InterpreterImpl::nameMatch(transEvents, "error.send.failed")); - assert(InterpreterImpl::nameMatch(transEvents, "foo")); - assert(InterpreterImpl::nameMatch(transEvents, "foo.bar")); - assert(!InterpreterImpl::nameMatch(transEvents, "errors.my.custom")); - assert(!InterpreterImpl::nameMatch(transEvents, "errorhandler.mistake")); - // is the event name case sensitive? - // assert(!InterpreterImpl::nameMatch(transEvents, "errOr.send")); - assert(!InterpreterImpl::nameMatch(transEvents, "foobar")); }
\ No newline at end of file |