#define protected public #include "uscxml/Interpreter.h" #undef protected #include int main(int argc, char** argv) { try { using namespace uscxml; using namespace Arabica::DOM; using namespace Arabica::XPath; const char* xml = "" " " " " " " " " " " " " " " ""; Interpreter interpreter = Interpreter::fromXML(xml, ""); assert(interpreter); interpreter.getImpl()->init(); Element atomicState = interpreter.getImpl()->getState("atomic"); assert(InterpreterImpl::isAtomic(atomicState)); assert(!InterpreterImpl::isParallel(atomicState)); assert(!InterpreterImpl::isCompound(atomicState)); Element compoundState = interpreter.getImpl()->getState("compound"); assert(!InterpreterImpl::isAtomic(compoundState)); assert(!InterpreterImpl::isParallel(compoundState)); assert(InterpreterImpl::isCompound(compoundState)); Element parallelState = interpreter.getImpl()->getState("parallel"); assert(!InterpreterImpl::isAtomic(parallelState)); assert(InterpreterImpl::isParallel(parallelState)); assert(!InterpreterImpl::isCompound(parallelState)); // parallel states are not compound! NodeSet initialState = interpreter.getImpl()->getInitialStates(); assert(initialState[0] == atomicState); NodeSet childs = interpreter.getImpl()->getChildStates(compoundState); Node compoundChild1 = interpreter.getImpl()->getState("compoundChild1"); Node 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 tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); assert(tokenizedIdrefs.size() == 1); assert(tokenizedIdrefs.front().compare("id1") == 0); } { std::string idrefs(" id1"); std::list tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); assert(tokenizedIdrefs.size() == 1); assert(tokenizedIdrefs.front().compare("id1") == 0); } { std::string idrefs(" id1 "); std::list tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); assert(tokenizedIdrefs.size() == 1); assert(tokenizedIdrefs.front().compare("id1") == 0); } { std::string idrefs(" \tid1\n "); std::list tokenizedIdrefs = InterpreterImpl::tokenizeIdRefs(idrefs); assert(tokenizedIdrefs.size() == 1); assert(tokenizedIdrefs.front().compare("id1") == 0); } { std::string idrefs("id1 id2 id3"); std::list 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 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 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; } }