diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-07-01 22:51:30 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-07-01 22:51:30 (GMT) |
commit | 945160d0539ad119ffc986fac712db76c7203e84 (patch) | |
tree | c43e4a7db898026bc62cc20af5061d07736f847e /embedding/java/src/org/uscxml/tests/TestLifecycle.java | |
parent | c70d02010ea99e6c8e35da3b767f41f1ee5dce56 (diff) | |
download | uscxml-945160d0539ad119ffc986fac712db76c7203e84.zip uscxml-945160d0539ad119ffc986fac712db76c7203e84.tar.gz uscxml-945160d0539ad119ffc986fac712db76c7203e84.tar.bz2 |
More polishing for bindings C# and Java
Diffstat (limited to 'embedding/java/src/org/uscxml/tests/TestLifecycle.java')
-rw-r--r-- | embedding/java/src/org/uscxml/tests/TestLifecycle.java | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/embedding/java/src/org/uscxml/tests/TestLifecycle.java b/embedding/java/src/org/uscxml/tests/TestLifecycle.java new file mode 100644 index 0000000..9278cbe --- /dev/null +++ b/embedding/java/src/org/uscxml/tests/TestLifecycle.java @@ -0,0 +1,124 @@ +package org.uscxml.tests; + +import org.uscxml.Interpreter; +import org.uscxml.InterpreterException; +import org.uscxml.InterpreterState; + +public class TestLifecycle { + public static void main(String[] args) { + System.load("/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava64.jnilib"); + + // syntactic xml parse error -> throws + try { + String xml = "<invalid"; + Interpreter interpreter = Interpreter.fromXML(xml); + throw new RuntimeException(""); + } catch (InterpreterException e) { + System.err.println(e); + } + + // semantic xml parse error -> throws + try { + String xml = "<invalid />"; + Interpreter interpreter = Interpreter.fromXML(xml); + if (interpreter.getState() != InterpreterState.USCXML_INSTANTIATED) throw new RuntimeException(""); + interpreter.step(); + throw new RuntimeException(""); + } catch (InterpreterException e) { + System.err.println(e); + } + + // request unknown datamodel -> throws + try { + String xml = + "<scxml datamodel=\"invalid\">" + + " <state id=\"start\">" + + " <transition target=\"done\" />" + + " </state>" + + " <final id=\"done\" />" + + "</scxml>"; + Interpreter interpreter = Interpreter.fromXML(xml); + if (interpreter.getState() != InterpreterState.USCXML_INSTANTIATED) throw new RuntimeException(""); + interpreter.step(); + throw new RuntimeException(""); + + } catch (InterpreterException e) { + System.err.println(e); + } + + try { + // two microsteps + String xml = + "<scxml>" + + " <state id=\"start\">" + + " <transition target=\"s2\" />" + + " </state>" + + " <state id=\"s2\">" + + " <transition target=\"done\" />" + + " </state>" + + " <final id=\"done\" />" + + "</scxml>"; + + Interpreter interpreter = Interpreter.fromXML(xml); + + if (interpreter.getState() != InterpreterState.USCXML_INSTANTIATED) throw new RuntimeException(""); + if (interpreter.step() != InterpreterState.USCXML_MICROSTEPPED) throw new RuntimeException(""); + if (interpreter.step() != InterpreterState.USCXML_MICROSTEPPED) throw new RuntimeException(""); + if (interpreter.step() != InterpreterState.USCXML_FINISHED) throw new RuntimeException(""); + + } catch (InterpreterException e) { + System.err.println(e); + } + + try { + // single macrostep, multiple runs + String xml = + "<scxml>" + + " <state id=\"start\">" + + " <transition target=\"done\" />" + + " </state>" + + " <final id=\"done\" />" + + "</scxml>"; + + Interpreter interpreter = Interpreter.fromXML(xml); + if (interpreter.getState() != InterpreterState.USCXML_INSTANTIATED) throw new RuntimeException(""); + if (interpreter.step() != InterpreterState.USCXML_MICROSTEPPED) throw new RuntimeException(""); + if (interpreter.step() != InterpreterState.USCXML_FINISHED) throw new RuntimeException(""); + interpreter.reset(); + + if (interpreter.getState() != InterpreterState.USCXML_INSTANTIATED) throw new RuntimeException(""); + if (interpreter.step() != InterpreterState.USCXML_MICROSTEPPED) throw new RuntimeException(""); + if (interpreter.step() != InterpreterState.USCXML_FINISHED) throw new RuntimeException(""); + + } catch (InterpreterException e) { + System.err.println(e); + } + + try { + // macrostep in between + String 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); + if (interpreter.getState() != InterpreterState.USCXML_INSTANTIATED) throw new RuntimeException(""); + if (interpreter.step() != InterpreterState.USCXML_IDLE) throw new RuntimeException(""); + if (interpreter.step(true) != InterpreterState.USCXML_MACROSTEPPED) throw new RuntimeException(""); + if (interpreter.step() != InterpreterState.USCXML_MICROSTEPPED) throw new RuntimeException(""); + if (interpreter.step() != InterpreterState.USCXML_FINISHED) throw new RuntimeException(""); + + } catch (InterpreterException e) { + System.err.println(e); + } + } +} |