diff --git a/tests/12-output.txt b/tests/12-output.txt new file mode 100644 index 0000000..d828a75 --- /dev/null +++ b/tests/12-output.txt @@ -0,0 +1,2 @@ +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: 'State 1', actions: {a {entry}, a {exit, behavior: 'exit();'}}, elements: {Simple State: {id: 'n0::n0', name: 'State 2', actions: {a {trigger: 'EVENT', guard: 'is_guard()', behavior: 'action();'}, a {trigger: 'EVENT', guard: 'is_guard() && is_second()', behavior: 'action1(); +action2();'}, a {trigger: 'EVENT', guard: 'else'}, a {entry, behavior: 'init();'}}}}}}}} diff --git a/tests/12-state-actions.cpp b/tests/12-state-actions.cpp new file mode 100644 index 0000000..799deda --- /dev/null +++ b/tests/12-state-actions.cpp @@ -0,0 +1,54 @@ +/* ----------------------------------------------------------------------------- + * 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* s1 = d.new_state(sm, "State 1"); + try { + // check empty action + s1->add_action(Action()); + } catch (const Cyberiada::ParametersException&){ + } + s1->add_action(Action(actionEntry)); + s1->add_action(Action(actionExit, "exit();")); + + State* s2 = d.new_state(s1, "State 2"); + s2->add_action(Action("EVENT", "is_guard()", "action();")); + s2->add_action(Action("EVENT", "is_guard() && is_second()", "action1();\naction2();")); + s2->add_action(Action("EVENT", "else")); + s2->add_action(Action(actionEntry, "init();")); + try { + cout << d << endl; + d.save(string(argv[0]) + ".graphml", formatCyberiada10); + } catch (const Cyberiada::Exception&) { + return 1; + } + return 0; +} diff --git a/tests/12-state-actions.test-output.graphml b/tests/12-state-actions.test-output.graphml new file mode 100644 index 0000000..671996d --- /dev/null +++ b/tests/12-state-actions.test-output.graphml @@ -0,0 +1,63 @@ + + + Cyberiada-GraphML-1.0 + + + + + + + + + + + + + + + + + + + + + + SM + + formal + CGML_META + standardVersion/ 1.0 + +transitionOrder/ transitionFirst + +eventPropagation/ block + + + + + State 1 + entry/ + +exit/ +exit(); + + + + State 2 + EVENT [is_guard()]/ +action(); + +EVENT [is_guard() && is_second()]/ +action1(); +action2(); + +EVENT [else]/ + +entry/ +init(); + + + + + +