diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-04-06 21:17:13 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-04-06 21:17:13 (GMT) |
commit | 1e6ba139ac12c688f025745812d381915775b1fb (patch) | |
tree | 1d49070eddd4502ec6aa25a769ab7c47d04a1c30 /test/src | |
parent | 139439f0675ec05e936fd4297086462037cd618e (diff) | |
download | uscxml-1e6ba139ac12c688f025745812d381915775b1fb.zip uscxml-1e6ba139ac12c688f025745812d381915775b1fb.tar.gz uscxml-1e6ba139ac12c688f025745812d381915775b1fb.tar.bz2 |
See detailled log
Added new revised W3C tests
Hide Interpreter via PIMPL
Implemented SCXMLIOProcessor
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/scxml-test-framework-client.cpp | 55 | ||||
-rw-r--r-- | test/src/test-predicates.cpp | 39 | ||||
-rw-r--r-- | test/src/test-url.cpp | 5 | ||||
-rw-r--r-- | test/src/test-w3c.cpp | 13 |
4 files changed, 54 insertions, 58 deletions
diff --git a/test/src/scxml-test-framework-client.cpp b/test/src/scxml-test-framework-client.cpp index 73df8ce..0441c0e 100644 --- a/test/src/scxml-test-framework-client.cpp +++ b/test/src/scxml-test-framework-client.cpp @@ -25,21 +25,21 @@ public: static int lastToken; static bool alreadyAnswered; // we need this for delayed events - static std::map<std::string, std::pair<uscxml::Interpreter*, uscxml::HTTPServer::Request> > _interpreters; + static std::map<std::string, std::pair<uscxml::Interpreter, uscxml::HTTPServer::Request> > _interpreters; TestIOProcessor() {} - virtual void beforeCompletion(uscxml::Interpreter* interpreter) { + virtual void beforeCompletion(uscxml::Interpreter interpreter) { onStableConfiguration(interpreter); } - virtual void afterCompletion(uscxml::Interpreter* interpreter) { - _interpreters[interpreter->getName()].second.curlReq = NULL; + virtual void afterCompletion(uscxml::Interpreter interpreter) { + _interpreters[interpreter.getName()].second.curlReq = NULL; } - virtual void beforeMicroStep(uscxml::Interpreter* interpreter) {} - virtual void beforeTakingTransitions(uscxml::Interpreter* interpreter, const Arabica::XPath::NodeSet<std::string>& transitions) {} + virtual void beforeMicroStep(uscxml::Interpreter interpreter) {} + virtual void beforeTakingTransitions(uscxml::Interpreter interpreter, const Arabica::XPath::NodeSet<std::string>& transitions) {} - virtual void beforeEnteringStates(uscxml::Interpreter* interpreter, const Arabica::XPath::NodeSet<std::string>& statesToEnter) { + virtual void beforeEnteringStates(uscxml::Interpreter interpreter, const Arabica::XPath::NodeSet<std::string>& statesToEnter) { std::cout << "Entering states: "; for (int i = 0; i < statesToEnter.size(); i++) { std::cout << ATTR(statesToEnter[i], "id") << ", "; @@ -47,18 +47,18 @@ public: std::cout << std::endl; } - virtual void afterEnteringStates(uscxml::Interpreter* interpreter) { + virtual void afterEnteringStates(uscxml::Interpreter interpreter) { std::cout << "After entering states: "; - for (int i = 0; i < interpreter->getConfiguration().size(); i++) { - std::cout << ATTR(interpreter->getConfiguration()[i], "id") << ", "; + for (int i = 0; i < interpreter.getConfiguration().size(); i++) { + std::cout << ATTR(interpreter.getConfiguration()[i], "id") << ", "; } std::cout << std::endl; } - virtual void beforeExitingStates(uscxml::Interpreter* interpreter, const Arabica::XPath::NodeSet<std::string>& statesToExit) { + virtual void beforeExitingStates(uscxml::Interpreter interpreter, const Arabica::XPath::NodeSet<std::string>& statesToExit) { std::cout << "Configuration: "; - for (int i = 0; i < interpreter->getConfiguration().size(); i++) { - std::cout << ATTR(interpreter->getConfiguration()[i], "id") << ", "; + for (int i = 0; i < interpreter.getConfiguration().size(); i++) { + std::cout << ATTR(interpreter.getConfiguration()[i], "id") << ", "; } std::cout << std::endl; std::cout << "Exiting states: "; @@ -68,22 +68,22 @@ public: std::cout << std::endl; } - virtual void afterExitingStates(uscxml::Interpreter* interpreter) { + virtual void afterExitingStates(uscxml::Interpreter interpreter) { std::cout << "After exiting states: "; - for (int i = 0; i < interpreter->getConfiguration().size(); i++) { - std::cout << ATTR(interpreter->getConfiguration()[i], "id") << ", "; + for (int i = 0; i < interpreter.getConfiguration().size(); i++) { + std::cout << ATTR(interpreter.getConfiguration()[i], "id") << ", "; } std::cout << std::endl; } - virtual void onStableConfiguration(uscxml::Interpreter* interpreter) { + virtual void onStableConfiguration(uscxml::Interpreter interpreter) { if (alreadyAnswered) return; - Arabica::XPath::NodeSet<std::string> configuration = interpreter->getConfiguration(); + Arabica::XPath::NodeSet<std::string> configuration = interpreter.getConfiguration(); uscxml::Data reply; - reply.compound["sessionToken"] = uscxml::Data(interpreter->getName()); + reply.compound["sessionToken"] = uscxml::Data(interpreter.getName()); std::string seperator; for (size_t i = 0; i < configuration.size(); i++) { if (uscxml::Interpreter::isAtomic(configuration[i])) @@ -98,7 +98,7 @@ public: alreadyAnswered = true; - uscxml::HTTPServer::Request httpRequest = _interpreters[interpreter->getName()].second; + uscxml::HTTPServer::Request httpRequest = _interpreters[interpreter.getName()].second; uscxml::HTTPServer::Reply httpReply(httpRequest); httpReply.content = replyString.str(); uscxml::HTTPServer::reply(httpReply); @@ -125,10 +125,9 @@ public: std::cout << "Starting Interpreter with " << filename << std::endl; alreadyAnswered = false; - std::map<std::string, std::pair<uscxml::Interpreter*, uscxml::HTTPServer::Request> >::iterator interpreterIter = _interpreters.begin(); + std::map<std::string, std::pair<uscxml::Interpreter, uscxml::HTTPServer::Request> >::iterator interpreterIter = _interpreters.begin(); while(interpreterIter != _interpreters.end()) { // if (interpreterIter->second.second.curlReq == NULL) { - delete interpreterIter->second.first; _interpreters.erase(interpreterIter++); // } else { // interpreterIter++; @@ -136,14 +135,14 @@ public: } - uscxml::Interpreter* interpreter = uscxml::Interpreter::fromURI(filename); + uscxml::Interpreter interpreter = uscxml::Interpreter::fromURI(filename); if (interpreter) { std::string token = uscxml::toStr(lastToken++); assert(_interpreters.find(token) == _interpreters.end()); - interpreter->setName(token); - interpreter->addMonitor(this); + interpreter.setName(token); + interpreter.addMonitor(this); _interpreters[token] = std::make_pair(interpreter, request); - interpreter->start(); + interpreter.start(); } return; } @@ -159,7 +158,7 @@ public: // evhttp_request_free(_interpreters[token].second); alreadyAnswered = false; _interpreters[token].second = request; - _interpreters[token].first->receive(event); + _interpreters[token].first.receive(event); } } @@ -171,7 +170,7 @@ public: int TestIOProcessor::lastToken; bool TestIOProcessor::alreadyAnswered; -std::map<std::string, std::pair<uscxml::Interpreter*, uscxml::HTTPServer::Request> > TestIOProcessor::_interpreters; +std::map<std::string, std::pair<uscxml::Interpreter, uscxml::HTTPServer::Request> > TestIOProcessor::_interpreters; int main(int argc, char** argv) { TestIOProcessor* testServer = new TestIOProcessor(); diff --git a/test/src/test-predicates.cpp b/test/src/test-predicates.cpp index 58faffb..954afb2 100644 --- a/test/src/test-predicates.cpp +++ b/test/src/test-predicates.cpp @@ -12,31 +12,30 @@ int main(int argc, char** argv) { using namespace Arabica::DOM; using namespace Arabica::XPath; - Interpreter* interpreter = Interpreter::fromURI(argv[1]); - interpreter->init(); + Interpreter interpreter = Interpreter::fromURI(argv[1]); assert(interpreter); - Node<std::string> atomicState = interpreter->getState("atomic"); + Node<std::string> atomicState = interpreter.getState("atomic"); assert(Interpreter::isAtomic(atomicState)); assert(!Interpreter::isParallel(atomicState)); assert(!Interpreter::isCompound(atomicState)); - Node<std::string> compoundState = interpreter->getState("compound"); + Node<std::string> compoundState = interpreter.getState("compound"); assert(!Interpreter::isAtomic(compoundState)); assert(!Interpreter::isParallel(compoundState)); assert(Interpreter::isCompound(compoundState)); - Node<std::string> parallelState = interpreter->getState("parallel"); + Node<std::string> parallelState = interpreter.getState("parallel"); assert(!Interpreter::isAtomic(parallelState)); assert(Interpreter::isParallel(parallelState)); assert(!Interpreter::isCompound(parallelState)); // parallel states are not compound! - NodeSet<std::string> initialState = interpreter->getInitialStates(); + NodeSet<std::string> initialState = interpreter.getInitialStates(); assert(initialState[0] == atomicState); - NodeSet<std::string> childs = interpreter->getChildStates(compoundState); - Node<std::string> compundChild1 = interpreter->getState("compundChild1"); - Node<std::string> compundChild2 = interpreter->getState("compundChild2"); + NodeSet<std::string> childs = interpreter.getChildStates(compoundState); + Node<std::string> compundChild1 = interpreter.getState("compundChild1"); + Node<std::string> compundChild2 = interpreter.getState("compundChild2"); assert(childs.size() > 0); assert(Interpreter::isMember(compundChild1, childs)); assert(Interpreter::isMember(compundChild2, childs)); @@ -46,17 +45,17 @@ int main(int argc, char** argv) { std::string transEvents; transEvents = "error"; - assert(Interpreter::nameMatch(transEvents, "error")); - assert(!Interpreter::nameMatch(transEvents, "foo")); + assert(InterpreterImpl::nameMatch(transEvents, "error")); + assert(!InterpreterImpl::nameMatch(transEvents, "foo")); transEvents = "error foo"; - assert(Interpreter::nameMatch(transEvents, "error")); - assert(Interpreter::nameMatch(transEvents, "error.send")); - assert(Interpreter::nameMatch(transEvents, "error.send.failed")); - assert(Interpreter::nameMatch(transEvents, "foo")); - assert(Interpreter::nameMatch(transEvents, "foo.bar")); - assert(!Interpreter::nameMatch(transEvents, "errors.my.custom")); - assert(!Interpreter::nameMatch(transEvents, "errorhandler.mistake")); - assert(!Interpreter::nameMatch(transEvents, "errOr.send")); - assert(!Interpreter::nameMatch(transEvents, "foobar")); + 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")); + assert(!InterpreterImpl::nameMatch(transEvents, "errOr.send")); + assert(!InterpreterImpl::nameMatch(transEvents, "foobar")); }
\ No newline at end of file diff --git a/test/src/test-url.cpp b/test/src/test-url.cpp index 3165a20..5e8ea02 100644 --- a/test/src/test-url.cpp +++ b/test/src/test-url.cpp @@ -29,10 +29,9 @@ public: int main(int argc, char** argv) { { - Interpreter* interpreter = Interpreter::fromURI("https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-execution.scxml"); + Interpreter interpreter = Interpreter::fromURI("https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-execution.scxml"); assert(interpreter); - interpreter->interpret(); - delete interpreter; + interpreter.interpret(); } { diff --git a/test/src/test-w3c.cpp b/test/src/test-w3c.cpp index 8dc3e17..70c8b80 100644 --- a/test/src/test-w3c.cpp +++ b/test/src/test-w3c.cpp @@ -96,7 +96,7 @@ void printUsageAndExit() { } class W3CStatusMonitor : public uscxml::InterpreterMonitor { - void beforeCompletion(uscxml::Interpreter* interpreter) { + void beforeCompletion(uscxml::InterpreterImpl* interpreter) { Arabica::XPath::NodeSet<std::string> config = interpreter->getConfiguration(); if (config.size() == 1 && boost::iequals(ATTR(config[0], "id"), "pass")) exit(EXIT_SUCCESS); @@ -145,18 +145,17 @@ int main(int argc, char** argv) { // std::cout << optind << std::endl; LOG(INFO) << "Processing " << argv[optind]; - Interpreter* interpreter = Interpreter::fromURI(argv[optind]); + Interpreter interpreter = Interpreter::fromURI(argv[optind]); if (interpreter) { - interpreter->setCmdLineOptions(argc, argv); + interpreter.setCmdLineOptions(argc, argv); // interpreter->setCapabilities(Interpreter::CAN_NOTHING); // interpreter->setCapabilities(Interpreter::CAN_BASIC_HTTP | Interpreter::CAN_GENERIC_HTTP); W3CStatusMonitor* vm = new W3CStatusMonitor(); - interpreter->addMonitor(vm); + interpreter.addMonitor(vm); - interpreter->start(); - while(interpreter->runOnMainThread(25)); - delete interpreter; + interpreter.start(); + while(interpreter.runOnMainThread(25)); } return EXIT_SUCCESS; |