diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-04-09 22:51:16 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-04-09 22:51:16 (GMT) |
commit | 8a9b432d36e5748898abffe9f1607d93e45bab4b (patch) | |
tree | 0b95e832a9b3b2daf9ae45bf81084eda580752a0 /test | |
parent | 7d98ac1fd2e9da3162f3b6d38b22106f463edd9d (diff) | |
download | uscxml-8a9b432d36e5748898abffe9f1607d93e45bab4b.zip uscxml-8a9b432d36e5748898abffe9f1607d93e45bab4b.tar.gz uscxml-8a9b432d36e5748898abffe9f1607d93e45bab4b.tar.bz2 |
Started with promela datamodel
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 19 | ||||
-rw-r--r-- | test/samples/uscxml/chartToFSM/test-event-desc-merging.scxml | 17 | ||||
-rw-r--r-- | test/samples/uscxml/chartToFSM/test-event-set-conflict.scxml | 19 | ||||
-rw-r--r-- | test/samples/uscxml/chartToFSM/test-flattening.scxml | 35 | ||||
-rw-r--r-- | test/samples/uscxml/promela/test-simple-promela.scxml | 27 | ||||
-rw-r--r-- | test/samples/uscxml/test-java-datamodel.scxml | 1 | ||||
-rw-r--r-- | test/src/test-promela-parser.cpp | 44 | ||||
-rw-r--r-- | test/src/test-w3c.cpp | 89 |
8 files changed, 242 insertions, 9 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9d6c057..e4f2260 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -90,6 +90,10 @@ target_link_libraries(test-url uscxml) add_test(test-url ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-url) set_target_properties(test-url PROPERTIES FOLDER "Tests") +add_executable(test-promela-parser src/test-promela-parser.cpp) +target_link_libraries(test-promela-parser uscxml) +add_test(test-url ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-promela-parser) +set_target_properties(test-promela-parser PROPERTIES FOLDER "Tests") add_executable(test-cmdline-parsing src/test-cmdline-parsing.cpp) target_link_libraries(test-cmdline-parsing uscxml) @@ -139,6 +143,7 @@ foreach( W3C_TEST ${W3C_TESTS} ) if (NOT TEST_NAME MATCHES ".*sub.*") if (BUILD_TESTS_W3C_ECMA AND TEST_NAME MATCHES "^ecma\\/.*") add_test(${TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-w3c ${W3C_TEST}) + set_property(TEST ${TEST_NAME} PROPERTY LABELS ${TEST_NAME}) # set_tests_properties(${TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST FAILED") if (TEST_NAME STREQUAL "ecma/test250.scxml") set_tests_properties(${TEST_NAME} PROPERTIES @@ -147,11 +152,23 @@ foreach( W3C_TEST ${W3C_TESTS} ) set_tests_properties(${TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION "error in state") endif() - endif() + + if (BUILD_TESTS_FSM_ECMA AND TEST_NAME MATCHES "^ecma\\/.*") + add_test("fsm/${TEST_NAME}" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-w3c -f ${W3C_TEST}) + set_property(TEST "fsm/${TEST_NAME}" PROPERTY LABELS "fsm/${TEST_NAME}") + endif() + if (BUILD_TESTS_W3C_XPATH AND TEST_NAME MATCHES "^xpath\\/.*") add_test(${TEST_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-w3c ${W3C_TEST}) + set_property(TEST ${TEST_NAME} PROPERTY LABELS ${TEST_NAME}) # set_tests_properties(${TEST_NAME} PROPERTIES FAIL_REGULAR_EXPRESSION "TEST FAILED") endif() + + if (BUILD_TESTS_FSM_XPATH AND TEST_NAME MATCHES "^xpath\\/.*") + add_test("fsm/${TEST_NAME}" ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test-w3c -f ${W3C_TEST}) + set_property(TEST "fsm/${TEST_NAME}" PROPERTY LABELS "fsm/${TEST_NAME}") + endif() + endif() endforeach() diff --git a/test/samples/uscxml/chartToFSM/test-event-desc-merging.scxml b/test/samples/uscxml/chartToFSM/test-event-desc-merging.scxml new file mode 100644 index 0000000..7ab14db --- /dev/null +++ b/test/samples/uscxml/chartToFSM/test-event-desc-merging.scxml @@ -0,0 +1,17 @@ +<scxml> + <parallel id="s0"> + <state id="s01"> + <transition event="foo baz.bar.foo" /> + </state> + <state id="s02"> + <transition event="foo.bar baz.bar" /> + </state> + <state id="s03"> + <transition event="foo.bar.baz baz" /> + <transition event="bax" target="pass" /> + </state> + + </parallel> + <final id="pass" /> + <final id="fail" /> +</scxml>
\ No newline at end of file diff --git a/test/samples/uscxml/chartToFSM/test-event-set-conflict.scxml b/test/samples/uscxml/chartToFSM/test-event-set-conflict.scxml new file mode 100644 index 0000000..cc76238 --- /dev/null +++ b/test/samples/uscxml/chartToFSM/test-event-set-conflict.scxml @@ -0,0 +1,19 @@ +<scxml> + <state id="s0"> + <!-- These transitions all conflict, only the first one ought to be taken --> + <transition target="s1" /> + <transition target="s2" /> + <transition target="s3" /> + </state> + <state id="s1"> + <transition target="pass" /> + </state> + <state id="s2"> + <transition target="fail" /> + </state> + <state id="s3"> + <transition target="fail" /> + </state> + <final id="pass" /> + <final id="fail" /> +</scxml>
\ No newline at end of file diff --git a/test/samples/uscxml/chartToFSM/test-flattening.scxml b/test/samples/uscxml/chartToFSM/test-flattening.scxml new file mode 100644 index 0000000..7d2516e --- /dev/null +++ b/test/samples/uscxml/chartToFSM/test-flattening.scxml @@ -0,0 +1,35 @@ +<scxml> + <parallel id="s0"> + <state id="s01"> + <history id="h01" /> + <state id="s011"> + <state id="s0111"> + <transition target="s0112" event="s0112"/> + </state> + <state id="s0112"> + <transition target="s0113" event="s0113"/> + </state> + <state id="s0113"> + <transition target="s0114" event="s0114"/> + </state> + <state id="s0114"> + <transition target="s012" event="s012"/> + </state> + </state> + <state id="s012"> + </state> + <transition target="s02" /> + </state> + <state id="s02"> + <transition target="s1" /> + </state> + <state id="s03"> + <transition target="exit" /> + </state> + </parallel> + <state id="s1"> + </state> + <state id="s2"> + </state> + <final id="exit" /> +</scxml>
\ No newline at end of file diff --git a/test/samples/uscxml/promela/test-simple-promela.scxml b/test/samples/uscxml/promela/test-simple-promela.scxml new file mode 100644 index 0000000..4738a86 --- /dev/null +++ b/test/samples/uscxml/promela/test-simple-promela.scxml @@ -0,0 +1,27 @@ +<scxml datamodel="promela"> + <datamodel> + <data> + bit v1, v2, v3, v4, v5; + </data> + </datamodel> + <state id="init"> + <onentry> + <script> + v2=1; v3=1; + </script> + </onentry> + <transition target="pass" cond="v2==(v3==v4)"> + </transition> + <transition target="fail" /> + </state> + <final id="pass"> + <onentry> + <log label="Outcome" expr="'pass'"/> + </onentry> + </final> + <final id="fail"> + <onentry> + <log label="Outcome" expr="'fail'"/> + </onentry> + </final> +</scxml>
\ No newline at end of file diff --git a/test/samples/uscxml/test-java-datamodel.scxml b/test/samples/uscxml/test-java-datamodel.scxml index 05e9d21..4ec157c 100644 --- a/test/samples/uscxml/test-java-datamodel.scxml +++ b/test/samples/uscxml/test-java-datamodel.scxml @@ -1,4 +1,5 @@ <scxml datamodel="java" initial="comparison" binding="late"> + <!-- unimplemented --> <datamodel> <data id="year" expr="2008" /> <data id="CEO" expr="'Mr Big'" /> diff --git a/test/src/test-promela-parser.cpp b/test/src/test-promela-parser.cpp new file mode 100644 index 0000000..d89bb73 --- /dev/null +++ b/test/src/test-promela-parser.cpp @@ -0,0 +1,44 @@ +#include "uscxml/URL.h" +#include "uscxml/Message.h" +#include "uscxml/Interpreter.h" +#include "uscxml/plugins/datamodel/promela/PromelaDataModel.h" +#include "uscxml/plugins/datamodel/promela/PromelaParser.h" + +#include <assert.h> +#include <boost/algorithm/string.hpp> +#include <iostream> + +using namespace uscxml; +using namespace boost; + + +int main(int argc, char** argv) { + + { + PromelaParser ast("bit b;"); + ast.dump(); + } + + { + PromelaParser ast1("a + (1 << b)"); + PromelaParser ast2("(a + 1) << b"); + ast1.dump(); + ast2.dump(); + } + + { + PromelaParser ast("(b < N)"); + ast.dump(); + } + + { + PromelaParser ast("i+1"); + ast.dump(); + } + + { + PromelaParser ast("(mt+1)%MAX;"); + ast.dump(); + } + +}
\ No newline at end of file diff --git a/test/src/test-w3c.cpp b/test/src/test-w3c.cpp index df433b8..102487f 100644 --- a/test/src/test-w3c.cpp +++ b/test/src/test-w3c.cpp @@ -1,6 +1,7 @@ #include "uscxml/config.h" #include "uscxml/Interpreter.h" #include "uscxml/DOMUtils.h" +#include "uscxml/transform/ChartToFSM.h" #include <glog/logging.h> #include <boost/algorithm/string.hpp> @@ -20,6 +21,8 @@ #include "XGetopt.h" #endif +static bool withFlattening = false; +static std::string documentURI; #ifdef HAS_EXECINFO_H void printBacktrace(void** array, int size) { @@ -87,15 +90,72 @@ void customTerminate() { } class W3CStatusMonitor : public uscxml::InterpreterMonitor { + + void beforeTakingTransition(uscxml::Interpreter interpreter, const Arabica::DOM::Element<std::string>& transition, bool moreComing) { + std::cout << "Transition: " << uscxml::DOMUtils::xPathForNode(transition) << std::endl; + } + + void onStableConfiguration(uscxml::Interpreter interpreter) { + std::cout << "Config: {"; + printNodeSet(interpreter.getConfiguration()); + std::cout << "}" << std::endl; + } + + void beforeProcessingEvent(uscxml::Interpreter interpreter, const uscxml::Event& event) { + std::cout << "Event: " << event.name << std::endl; + } + + void beforeExitingState(uscxml::Interpreter interpreter, const Arabica::DOM::Element<std::string>& state, bool moreComing) { + exitingStates.push_back(state); + if (!moreComing) { + std::cout << "Exiting: {"; + printNodeSet(exitingStates); + std::cout << "}" << std::endl; + exitingStates = Arabica::XPath::NodeSet<std::string>(); + } + } + + void beforeEnteringState(uscxml::Interpreter interpreter, const Arabica::DOM::Element<std::string>& state, bool moreComing) { + enteringStates.push_back(state); + if (!moreComing) { + std::cout << "Entering: {"; + printNodeSet(enteringStates); + std::cout << "}" << std::endl; + enteringStates = Arabica::XPath::NodeSet<std::string>(); + } + + } + + void printNodeSet(const Arabica::XPath::NodeSet<std::string>& config) { + std::string seperator; + for (int i = 0; i < config.size(); i++) { + std::cout << seperator << ATTR(config[i], "id"); + seperator = ", "; + } + } + void beforeCompletion(uscxml::Interpreter interpreter) { Arabica::XPath::NodeSet<std::string> config = interpreter.getConfiguration(); - if (config.size() == 1 && boost::iequals(ATTR(config[0], "id"), "pass")) { - std::cout << "TEST SUCCEEDED" << std::endl; - exit(EXIT_SUCCESS); + if (config.size() == 1) { + if (withFlattening) { + std::cout << ATTR(config[0], "id") << std::endl; + if (boost::starts_with(ATTR(config[0], "id"), "active-pass")) { + std::cout << "TEST SUCCEEDED" << std::endl; + exit(EXIT_SUCCESS); + } + } else { + if (boost::iequals(ATTR(config[0], "id"), "pass")) { + std::cout << "TEST SUCCEEDED" << std::endl; + exit(EXIT_SUCCESS); + } + } } std::cout << "TEST FAILED" << std::endl; exit(EXIT_FAILURE); } + + Arabica::XPath::NodeSet<std::string> exitingStates; + Arabica::XPath::NodeSet<std::string> enteringStates; }; int main(int argc, char** argv) { @@ -116,12 +176,25 @@ int main(int argc, char** argv) { google::InitGoogleLogging(argv[0]); google::LogToStderr(); -// for (int i = 0; i < argc; i++) -// std::cout << argv[i] << std::endl; -// std::cout << optind << std::endl; + + for (int i = 1; i < argc; i++) { + if (std::string(argv[i]) == "-f") { + withFlattening = true; + } else { + documentURI = argv[i]; + } + } + + Interpreter interpreter; + LOG(INFO) << "Processing " << documentURI << (withFlattening ? " FSM converted" : ""); + if (withFlattening) { + Interpreter flatInterpreter = Interpreter::fromURI(documentURI); + interpreter = Interpreter::fromDOM(ChartToFSM::flatten(flatInterpreter.getDocument(), flatInterpreter.getNameSpaceInfo()), flatInterpreter.getNameSpaceInfo()); + interpreter.setNameSpaceInfo(interpreter.getNameSpaceInfo()); + } else { + interpreter = Interpreter::fromURI(documentURI); + } - LOG(INFO) << "Processing " << argv[1]; - Interpreter interpreter = Interpreter::fromURI(argv[1]); if (interpreter) { // interpreter.setCmdLineOptions(argc, argv); // interpreter->setCapabilities(Interpreter::CAN_NOTHING); |