From 76e79a0bc060272a7995ddb1eb788d368ff8bca8 Mon Sep 17 00:00:00 2001 From: Alexey Fedoseev Date: Thu, 25 Apr 2024 09:30:25 +0300 Subject: [PATCH] add transitions test --- tests/13-output.graphml | 71 ++++++++++++++++++++++++++++++++++++++++ tests/13-output.txt | 1 + tests/13-transitions.cpp | 69 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 tests/13-output.graphml create mode 100644 tests/13-output.txt create mode 100644 tests/13-transitions.cpp diff --git a/tests/13-output.graphml b/tests/13-output.graphml new file mode 100644 index 0000000..b09df62 --- /dev/null +++ b/tests/13-output.graphml @@ -0,0 +1,71 @@ + + + Cyberiada-GraphML-1.0 + + + + + + + + + + + + + + + + + + + + + + SM + + formal + CGML_META + standardVersion/ 1.0 + +transitionOrder/ transitionFirst + +eventPropagation/ block + + + + + Parent 0 + + + State 0 + + + State 1 + + + + + Parent 1 + + + + + A/ + + + IDLE/ + + + INSIDE/ + + + OUTSIDE/ + + + EVENT [guard()]/ +action(); + + + + diff --git a/tests/13-output.txt b/tests/13-output.txt new file mode 100644 index 0000000..1c502f7 --- /dev/null +++ b/tests/13-output.txt @@ -0,0 +1 @@ +Document: {id: '', name: '', format: 'Cyberiada-GraphML-1.0', meta: {standard version: '1.0', transition order: transition first, event propagation: block events}, elements: {State Machine: {id: 'G0', name: 'SM', elements: {Composite State: {id: 'n0', name: 'Parent 0', elements: {Simple State: {id: 'n0::n0', name: 'State 0'}, Simple State: {id: 'n0::n1', name: 'State 1'}}}, Simple State: {id: 'n1', name: 'Parent 1'}, Transition: {id: 'n0::n0-n0::n1', source: 'n0::n0', target: 'n0::n1'}, Transition: {id: 'n0::n0-n0::n1#0', source: 'n0::n0', target: 'n0::n1', action: {trigger: 'A'}}, Transition: {id: 'n0::n0-n0::n0', source: 'n0::n0', target: 'n0::n0', action: {trigger: 'IDLE'}}, Transition: {id: 'n0-n0::n0', source: 'n0', target: 'n0::n0', action: {trigger: 'INSIDE'}}, Transition: {id: 'n0::n1-n0', source: 'n0::n1', target: 'n0', action: {trigger: 'OUTSIDE'}}, Transition: {id: 'n0::n1-n1', source: 'n0::n1', target: 'n1', action: {trigger: 'EVENT', guard: 'guard()', behavior: 'action();'}}}}} diff --git a/tests/13-transitions.cpp b/tests/13-transitions.cpp new file mode 100644 index 0000000..56a6860 --- /dev/null +++ b/tests/13-transitions.cpp @@ -0,0 +1,69 @@ +/* ----------------------------------------------------------------------------- + * The Cyberiada GraphML C++ library implemention + * + * The test + * + * Copyright (C) 2024 Alexey Fedoseev + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see https://www.gnu.org/licenses/ + * ----------------------------------------------------------------------------- */ + +#include +#include "cyberiadamlpp.h" +#include "testutils.h" + +using namespace Cyberiada; +using namespace std; + +int main(int argc, char** argv) +{ + Document d; + StateMachine* sm = d.new_state_machine("SM"); + State* parent1 = d.new_state(sm, "Parent 0"); + State* s1 = d.new_state(parent1, "State 0"); + State* s2 = d.new_state(parent1, "State 1"); + d.new_transition(sm, s1, s2, Action()); + d.new_transition(sm, s1, s2, Action("A")); + try { + // check id uniqueness + d.new_transition(sm, "n0::n0-n0::n1", s1, s2, Action()); + } catch (const Cyberiada::ParametersException&){ + } + try { + // check sm-related transition + d.new_transition(sm, sm, s1, Action()); + } catch (const Cyberiada::ParametersException&){ + } + + d.new_transition(sm, s1, s1, Action("IDLE")); + d.new_transition(sm, parent1, s1, Action("INSIDE")); + d.new_transition(sm, s2, parent1, Action("OUTSIDE")); + + try { + // check transition action + d.new_transition(sm, s1, s2, Action(actionEntry, "init();")); + } catch (const Cyberiada::ParametersException&){ + } + + State* parent2 = d.new_state(sm, "Parent 1"); + d.new_transition(sm, s2, parent2, Action("EVENT", "guard()", "action();")); + + try { + cout << d << endl; + d.save(string(argv[0]) + ".graphml", formatCyberiada10); + } catch (const Cyberiada::Exception&) { + return 1; + } + return 0; +}