diff options
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/test-apache-commons.cpp | 128 | ||||
-rw-r--r-- | test/src/test-communication.cpp | 26 | ||||
-rw-r--r-- | test/src/test-communication.scxml | 35 | ||||
-rw-r--r-- | test/src/test-ecmascript-v8.cpp | 44 | ||||
-rw-r--r-- | test/src/test-ecmascript.scxml | 112 | ||||
-rw-r--r-- | test/src/test-eventdelay.cpp | 39 | ||||
-rw-r--r-- | test/src/test-execution.cpp | 16 | ||||
-rw-r--r-- | test/src/test-execution.scxml | 56 | ||||
-rw-r--r-- | test/src/test-predicates.cpp | 60 | ||||
-rw-r--r-- | test/src/test-predicates.scxml | 9 |
10 files changed, 525 insertions, 0 deletions
diff --git a/test/src/test-apache-commons.cpp b/test/src/test-apache-commons.cpp new file mode 100644 index 0000000..51c275d --- /dev/null +++ b/test/src/test-apache-commons.cpp @@ -0,0 +1,128 @@ +#include "uscxml/Interpreter.h" +#include <glog/logging.h> + +using namespace uscxml; +using namespace Arabica::DOM; +using namespace Arabica::XPath; + +static std::string path; + +bool testEvents1() { + LOG(INFO) << "---- testEvent1 "; + Interpreter* interpreter = new Interpreter(path + "/eventdata-01.xml"); + interpreter->start(); + interpreter->waitForStabilization(); + assert(interpreter->getConfiguration().size() == 1); + assert(Interpreter::isMember(interpreter->getState("state1"), interpreter->getConfiguration())); + + Event eventFoo; + eventFoo.name = "event.foo"; + eventFoo.atom = "3"; + interpreter->receive(eventFoo); + interpreter->waitForStabilization(); + assert(interpreter->getConfiguration().size() == 1); + assert(Interpreter::isMember(interpreter->getState("state3"), interpreter->getConfiguration())); + + Event eventBar; + eventBar.name = "event.bar"; + eventBar.atom = "6"; + interpreter->receive(eventBar); + interpreter->waitForStabilization(); + assert(interpreter->getConfiguration().size() == 1); + assert(Interpreter::isMember(interpreter->getState("state6"), interpreter->getConfiguration())); + + Event eventBaz; + eventBaz.name = "event.baz"; + eventBaz.atom = "7"; + interpreter->receive(eventBaz); + + delete interpreter; + return true; +} + +bool testEvents2() { + LOG(INFO) << "---- testEvent2 "; + Interpreter* interpreter = new Interpreter(path + "/eventdata-02.xml"); + interpreter->start(); + interpreter->waitForStabilization(); + assert(interpreter->getConfiguration().size() == 1); + assert(Interpreter::isMember(interpreter->getState("state0"), interpreter->getConfiguration())); + + Event eventConnAlert; + eventConnAlert.name = "connection.alerting"; + eventConnAlert.atom = "'line2'"; + interpreter->receive(eventConnAlert); + interpreter->waitForStabilization(); + assert(interpreter->getConfiguration().size() == 1); + assert(Interpreter::isMember(interpreter->getState("state2"), interpreter->getConfiguration())); + + Event eventConnAlert2; + eventConnAlert2.name = "connection.alerting"; + eventConnAlert2.compound["line"] = Data(std::string("4")); + interpreter->receive(eventConnAlert2); + + delete interpreter; + return true; +} + +//bool testEvents3() { +// LOG(INFO) << "---- testEvent3 "; +// Interpreter* Interpreter = new Interpreter(path + "/eventdata-03.xml"); +// interpreter->start(); +// interpreter->waitForStabilization(); +// Thread::sleepMs(200); +// assert(interpreter->getConfiguration().size() == 1); +// assert(Interpreter::isMember(interpreter->getState("state0"), interpreter->getConfiguration())); +// +// Event eventConnAlert; +// eventConnAlert.name = "connection.alerting"; +// eventConnAlert.atom = "'line2'"; +// interpreter->receive(eventConnAlert); +// Thread::sleepMs(200); +// assert(interpreter->getConfiguration().size() == 1); +// assert(Interpreter::isMember(interpreter->getState("state2"), interpreter->getConfiguration())); +// +// Event eventConnAlert2; +// eventConnAlert2.name = "connection.alerting"; +// eventConnAlert2.compound["line"] = Data(std::string("4")); +// interpreter->receive(eventConnAlert2); +// Thread::sleepMs(200); +// assert(interpreter->getConfiguration().size() == 1); +// assert(Interpreter::isMember(interpreter->getState("state4"), interpreter->getConfiguration())); +// +// delete Interpreter; +// return true; +//} + + +int main(int argc, char** argv) { + if (argc != 2) { + std::cerr << "Expected path to scxml file from apache commons distribution" << std::endl; + exit(EXIT_FAILURE); + } + + path = "file://"; + path += argv[1]; + + if (!testEvents1()) + return EXIT_FAILURE; + if (!testEvents2()) + return EXIT_FAILURE; +// if (!testEvents3()) +// return EXIT_FAILURE; + +// +// Interpreter* scxmlInterpreter = new Interpreter(path + "/tie-breaker-01.xml"); +// SCXMLRunner* scxmlRun = new SCXMLRunner(scxmlInterpreter); +// scxmlRun->start(); +// +// Thread::sleepMs(100); +// assert(Interpreter::isMember(scxmlinterpreter->getState("ten"), scxmlinterpreter->getConfiguration())); +// +// boost::shared_ptr<Event> event = boost::shared_ptr<Event>(new Event()); +// event->name = "ten.done"; +// scxmlinterpreter->receive(event); +// scxmlRun->join(); +// scxmlinterpreter->receive(event); + +}
\ No newline at end of file diff --git a/test/src/test-communication.cpp b/test/src/test-communication.cpp new file mode 100644 index 0000000..97584b8 --- /dev/null +++ b/test/src/test-communication.cpp @@ -0,0 +1,26 @@ +#include "uscxml/Interpreter.h" +#include <DOM/io/Stream.hpp> + +int main(int argc, char** argv) { + if (argc != 2) { + std::cerr << "Expected path to test-communication.scxml" << std::endl; + exit(EXIT_FAILURE); + } + + + using namespace uscxml; + std::list<Interpreter*> _interpreters; + +// Event e; +// e.compound["foo"] = Data("bar", Data::VERBATIM); +// e.compound["foo2"] = Data("bar2", Data::VERBATIM); +// std::cout << e.toDocument() << std::endl; + + for (int i = 0; i < 1; i++) { + _interpreters.push_back(new Interpreter(argv[1])); + _interpreters.back()->start(); + } + + tthread::this_thread::sleep_for(tthread::chrono::milliseconds(100000)); + +}
\ No newline at end of file diff --git a/test/src/test-communication.scxml b/test/src/test-communication.scxml new file mode 100644 index 0000000..cc3f577 --- /dev/null +++ b/test/src/test-communication.scxml @@ -0,0 +1,35 @@ +<scxml datamodel="ecmascript" initial="start" binding="late" name="foo"> + <state id="start"> + <datamodel> + <data id="foo" expr="'this is the foo data'" /> + <data id="bar" expr="'this is the bar data'" /> + </datamodel> + <onentry> + <log expr="'basichttp listening as ' + _ioprocessors['basichttp']" /> + <log expr="'Entered step1'" /> + <log expr="'Sending ourself an event'" /> + <send targetexpr="_ioprocessors['basichttp']" namelist="foo" type="basichttp" event="transitionToNext"> + <param name="bar" expr="'b' + 'ar'" /> + <content> +<![CDATA[ +This is some content you got there dude! +]]> + </content> + </send> + </onentry> + <transition event="transitionToNext" target="step1" /> + </state> + <state id="step1"> + <onentry> + <log expr="'Entered step1'" /> + <log expr="'Sending ourself a 2s delayed event'" /> + <send delay="2s" targetexpr="_ioprocessors['basichttp']" type="basichttp" event="transitionToNext" /> + </onentry> + <transition event="transitionToNext" target="final" /> + </state> + <final id="final"> + <onentry> + <log expr="'Finished!'" /> + </onentry> + </final> +</scxml>
\ No newline at end of file diff --git a/test/src/test-ecmascript-v8.cpp b/test/src/test-ecmascript-v8.cpp new file mode 100644 index 0000000..d0b69ba --- /dev/null +++ b/test/src/test-ecmascript-v8.cpp @@ -0,0 +1,44 @@ +#include "uscxml/Interpreter.h" +#include "uscxml/datamodel/ecmascript/v8/V8DataModel.h" + +int main(int argc, char** argv) { + if (argc != 2) { + std::cerr << "Expected path to test-ecmascript.scxml" << std::endl; + exit(EXIT_FAILURE); + } + + using namespace uscxml; + using namespace Arabica::DOM; + using namespace Arabica::XPath; + +// class SCXMLRunner : public Thread { +// public: +// SCXMLRunner(Runtime* runtime) : _runtime(runtime) {} +// void run() { +// _runtime->interpret(); +// } +// +// Runtime* _runtime; +// }; + +// boost::shared_ptr<V8DataModel> v8 = boost::static_pointer_cast<V8DataModel>(Factory::create("datamodel:ecmascript", Arabica::DOM::Node<std::string>())); +// v8->eval("var x = 4;"); +// assert(v8->evalAsBool("x == 4")); +// assert(!v8->evalAsBool("x == 5")); + + Interpreter* scxml = new Interpreter(argv[1]); + scxml->dump(); +// scxml->interpret(); + scxml->start(); + scxml->waitForStabilization(); + + Event event1; + event1.name = "event1"; + scxml->receive(event1); + scxml->waitForStabilization(); + tthread::this_thread::sleep_for(tthread::chrono::milliseconds(200)); + +// SCXMLRunner* scxmlRun = new SCXMLRunner(scxmlRuntime); +// scxmlRun->start(); + +}
\ No newline at end of file diff --git a/test/src/test-ecmascript.scxml b/test/src/test-ecmascript.scxml new file mode 100644 index 0000000..aa88f17 --- /dev/null +++ b/test/src/test-ecmascript.scxml @@ -0,0 +1,112 @@ +<scxml datamodel="ecmascript" initial="comparison" binding="late"> + <datamodel> + <data id="year" expr="2008" /> + <data id="CEO" expr="'Mr Big'" /> + <data id="profitable" /> + <data id="json"> + { + "id": 1, + "name": "Foo", + "price": 123, + "tags": [ "Bar", "Eek" ], + "stock": { + "warehouse": 300, + "retail": 20, + } + } + </data> + </datamodel> + <script> + var x = 4; + var a = ["a", "b", "c"]; + var b = [10,20,30]; + </script> + <script> + var y; + if (x > 10) { + y = 'true'; + } else { + y = 'false'; + } + </script> + <state id="comparison"> + <onentry> + <log expr="'-- Testing comparisons'" /> + <log expr="'x is ' + x + ', y is ' + y" /> + </onentry> + <transition cond="x >= 2" target="builtin"> + <log expr="'x is greater or equal to 2'" /> + </transition> + <transition cond="x < 2" target="builtin"> + <log expr="'x is smaller than 2'" /> + </transition> + </state> + <state id="builtin"> + <onentry> + <log expr="'-- Testing built ins'" /> + <if cond="In('builtin')"> + <log expr="'We are in state builtin'" /> + <else> + <log expr="'We are not in state builtin'" /> + </else> + </if> + </onentry> + <transition target="conditionals" /> + </state> + <state id="conditionals"> + <onentry> + <log expr="'-- Testing conditionals'" /> + <if cond="y == true"> + <log expr="'x is great and y is'" /> + <elseif cond="x > 3"> + <log expr="'x is somewhat great and y is not'" /> + </elseif> + <else> + <log expr="'x is great and y is not'" /> + </else> + </if> + </onentry> + <transition target="foreach" /> + </state> + <state id="foreach"> + <onentry> + <log expr="'-- Testing loops'" /> + <foreach array="a" item="itemA" index="indexA"> + <foreach array="b" item="itemB" index="indexB"> + <log expr="indexA + '.' + indexB + ' = ' + itemA + '.' + itemB" /> + </foreach> + </foreach> + </onentry> + <transition target="externalEvents" /> + </state> + <state id="externalEvents"> + <onentry> + <log expr="'-- External Events'" /> + </onentry> + <transition target="datamodels" event="event1" cond="_event.name == 'event1'" /> + </state> + <state id="datamodels"> + <datamodel> + <data id="bar" expr="'yeah, bar!'"/> + </datamodel> + <onentry> + <log expr="'-- DataModels'" /> + <log expr="'year = ' + year" /> + <log expr="'bar = ' + bar" /> + <log expr="'json.stock.warehouse = ' + json.stock.warehouse" /> + </onentry> + <transition target="syntaxerror" /> + </state> + <state id="syntaxerror"> + <onentry> + <log expr="'-- Syntax Error'" /> + <log expr="year = ' + year" /> + </onentry> + <transition event="error.execution" target="final" /> + </state> + <final id="final"> + <onentry> + <log expr="'Finished!'" /> + </onentry> + </final> +</scxml>
\ No newline at end of file diff --git a/test/src/test-eventdelay.cpp b/test/src/test-eventdelay.cpp new file mode 100644 index 0000000..6a28e44 --- /dev/null +++ b/test/src/test-eventdelay.cpp @@ -0,0 +1,39 @@ +#include "uscxml/concurrency/eventqueue/libevent/DelayedEventQueue.h" + +int eventCalled = 0; + +#include <sstream> + +static void callback(void* userData, const std::string eventId) { +// std::cout << eventId << ": " << (const char*)userData << std::endl; + std::cout << eventId << std::endl << std::flush; + eventCalled++; +} + +int main(int argc, char** argv) { + + using namespace uscxml; + DelayedEventQueue* eq = new DelayedEventQueue(); + + std::cout << "Starting" << std::endl; + eq->start(); + tthread::this_thread::sleep_for(tthread::chrono::milliseconds(10)); + +// eq->addEvent("foo", callback, 200, (void*)"event foo"); +// eq->addEvent("bar", callback, 400, (void*)"event bar"); +// eq->addEvent("bar", callback, 600, (void*)"event bar"); +// eq->cancelEvent("bar"); +// eq->addEvent("bar", callback, 300, (void*)"event bar"); +// eq->addEvent("baz", callback, 400, (void*)"event baz"); + + for (unsigned int i = 0; i <= 5000; i += 500) { +// eq->stop(); + std::stringstream ss; + ss << i; + eq->addEvent(ss.str(), callback, i, NULL); + std::cout << "Added " << i << std::endl; +// eq->start(); + } + tthread::this_thread::sleep_for(tthread::chrono::milliseconds(20000)); + +}
\ No newline at end of file diff --git a/test/src/test-execution.cpp b/test/src/test-execution.cpp new file mode 100644 index 0000000..e484eb4 --- /dev/null +++ b/test/src/test-execution.cpp @@ -0,0 +1,16 @@ +#include "uscxml/Interpreter.h" + +int main(int argc, char** argv) { + if (argc != 2) { + std::cerr << "Expected path to test-execution.scxml" << std::endl; + exit(EXIT_FAILURE); + } + + using namespace uscxml; + using namespace Arabica::DOM; + using namespace Arabica::XPath; + + Interpreter* interpreter = new Interpreter(argv[1]); + interpreter->dump(); + interpreter->interpret(); +}
\ No newline at end of file diff --git a/test/src/test-execution.scxml b/test/src/test-execution.scxml new file mode 100644 index 0000000..ada1a17 --- /dev/null +++ b/test/src/test-execution.scxml @@ -0,0 +1,56 @@ +<scxml initial="step2"> + <state id="start"> + <onentry> + <log expr="'Entered State: start'" /> + </onentry> + <transition target="step1"> + <log expr="'Transition start -> step1'" /> + </transition> + <onexit> + <log expr="'Exited State: start'" /> + </onexit> + </state> + <state id="step1"> + <onentry> + <log expr="'Entered State: step1'" /> + </onentry> + <transition target="step2"> + <log expr="'Transition step1 -> step2'" /> + </transition> + <onexit> + <log expr="'Exited State: step1'" /> + </onexit> + </state> + <parallel id="step2"> + <state id="parallel1"> + <onentry> + <log expr="'Entered State: parallel1'" /> + </onentry> + <transition target="step3"> + <log expr="'Transition parallel1 -> step3'" /> + </transition> + <onexit> + <log expr="'Exited State: parallel1'" /> + </onexit> + </state> + <state id="parallel2"> + <onentry> + <log expr="'Entered State: parallel2'" /> + </onentry> + <transition target="step3"> + <log expr="'Transition parallel2 -> step3'" /> + </transition> + <onexit> + <log expr="'Exited State: parallel2'" /> + </onexit> + </state> + </parallel> + <final id="step3"> + <onentry> + <log expr="'Entered Final State: step3'" /> + </onentry> + <onexit> + <log expr="'Exited Final State: step3'" /> + </onexit> + </final> +</scxml>
\ No newline at end of file diff --git a/test/src/test-predicates.cpp b/test/src/test-predicates.cpp new file mode 100644 index 0000000..73c37dc --- /dev/null +++ b/test/src/test-predicates.cpp @@ -0,0 +1,60 @@ +#define protected public +#include "uscxml/Interpreter.h" +#undef protected + +int main(int argc, char** argv) { + if (argc != 2) { + std::cerr << "Expected path to test-predicates.scxml" << std::endl; + exit(EXIT_FAILURE); + } + + using namespace uscxml; + using namespace Arabica::DOM; + using namespace Arabica::XPath; + + Interpreter* interpreter = new Interpreter(argv[1]); + + 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"); + assert(!Interpreter::isAtomic(compoundState)); + assert(!Interpreter::isParallel(compoundState)); + assert(Interpreter::isCompound(compoundState)); + + Node<std::string> parallelState = interpreter->getState("parallel"); + assert(!Interpreter::isAtomic(parallelState)); + assert(Interpreter::isParallel(parallelState)); + assert(!Interpreter::isCompound(parallelState)); // parallel states are not compound! + + Node<std::string> initialState = interpreter->getInitialState(); + assert(initialState == atomicState); + + 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)); + assert(!Interpreter::isMember(compoundState, childs)); + + assert(Interpreter::isDescendant(compundChild1, compoundState)); + + std::string transEvents; + transEvents = "error"; + assert(Interpreter::nameMatch(transEvents, "error")); + assert(!Interpreter::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")); +}
\ No newline at end of file diff --git a/test/src/test-predicates.scxml b/test/src/test-predicates.scxml new file mode 100644 index 0000000..98848a2 --- /dev/null +++ b/test/src/test-predicates.scxml @@ -0,0 +1,9 @@ +<scxml> + <state id="atomic" /> + <state id="compound"> + <state id="compundChild1" /> + <state id="compundChild2" /> + </state> + <parallel id="parallel"> + </parallel> +</scxml>
\ No newline at end of file |