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 = " throws try { String xml = ""; 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 = "" + " " + " " + " " + " " + ""; 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 = "" + " " + " " + " " + " " + " " + " " + " " + ""; 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 = "" + " " + " " + " " + " " + ""; 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 = "" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + ""; 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); } } }