diff --git a/run-tests.sh b/run-tests.sh index 8ec07c3..6278ca3 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -15,7 +15,7 @@ echo for t in $(ls tests/*.test); do num=$(echo $t | grep -Poe '\d+') echo -n "$num $t... " - if [ -f "tests/$num-input.graphml" ] + if [ -f "$t-input.graphml" ] then $t > "$t.txt" else @@ -28,7 +28,7 @@ for t in $(ls tests/*.test); do fi if [ -f "tests/$num-output.graphml" ] then - diff "$t.graphml" "tests/$num-output.graphml" >/dev/null + diff "$t.graphml" "tests/$num-output.graphml" if [ $? != 0 ] then echo "test failed: graphml file didn't match the pattern!" @@ -37,7 +37,7 @@ for t in $(ls tests/*.test); do fi if [ -f "tests/$num-output.txt" ] then - diff "$t.txt" "tests/$num-output.txt" >/dev/null + diff "$t.txt" "tests/$num-output.txt" if [ $? != 0 ] then echo "test failed: output didn't match the pattern!" diff --git a/tests/02-output.graphml b/tests/02-output.graphml index 5d1cfb3..cf10f80 100644 --- a/tests/02-output.graphml +++ b/tests/02-output.graphml @@ -30,7 +30,7 @@ transitionOrder/ transitionFirst -eventPropagation/ propagate +eventPropagation/ block diff --git a/tests/03-empty-doc-meta.cpp b/tests/03-empty-doc-meta.cpp new file mode 100644 index 0000000..72efc4b --- /dev/null +++ b/tests/03-empty-doc-meta.cpp @@ -0,0 +1,51 @@ +/* ----------------------------------------------------------------------------- + * 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" + +using namespace Cyberiada; +using namespace std; + +int main(int argc, char** argv) +{ + Document d; + d.new_state_machine("SM"); + d.meta().platform_name = "Berloga"; + d.meta().platform_version = "1.4"; + d.meta().platform_language = "script"; + d.meta().target_system = "Unit"; + d.meta().name = "Test document"; + d.meta().author = "Author"; + d.meta().contact = "platform@kruzhok.org"; + d.meta().description = "1\n2\n3"; + d.meta().version = "0.1"; + d.meta().date = "2024-04-14 11:22"; + d.meta().markup_language = "html"; + d.meta().transition_order_flag = true; // exit first + d.meta().event_propagation_flag = true; // propagate + try { + d.save(string(argv[0]) + ".graphml", formatCyberiada10); + } catch (const Cyberiada::Exception&) { + return 1; + } + return 0; +} diff --git a/tests/03-output.graphml b/tests/03-output.graphml new file mode 100644 index 0000000..d093897 --- /dev/null +++ b/tests/03-output.graphml @@ -0,0 +1,62 @@ + + + Cyberiada-GraphML-1.0 + + + + + + + + + + + + + + + + + + + + + + SM + + formal + CGML_META + standardVersion/ 1.0 + +platform/ Berloga + +platformVersion/ 1.4 + +platformLanguage/ script + +target/ Unit + +name/ Test document + +author/ Author + +contact/ platform@kruzhok.org + +description/ 1 +2 +3 + +version/ 0.1 + +date/ 2024-04-14 11:22 + +markupLanguage/ html + +transitionOrder/ exitFirst + +eventPropagation/ propagate + + + + + diff --git a/tests/04-output.txt b/tests/04-output.txt new file mode 100644 index 0000000..6c664a5 --- /dev/null +++ b/tests/04-output.txt @@ -0,0 +1,33 @@ +Document [Cyberiada-GraphML-1.0] {Element type: doc, id: '', name: 'Test document', meta: {standard version: '1.0', platform name: 'Berloga', platform version: '1.4', platform language: 'script', target system: 'Unit', name: 'Test document', author: 'Author', contact: 'platform@kruzhok.org', description: '1 +2 +3', version: '0.1', date: '2024-04-14 11:22', markup language: 'html', transition order: exit first, event propagation: propagate events}, elements: {State Machine {Element type: stm, id: 'G0', name: 'SM', elements: {Comment { formal, Element type: fco, id: 'nMeta', name: 'CGML_META', body: 'standardVersion/ 1.0 + +platform/ Berloga + +platformVersion/ 1.4 + +platformLanguage/ script + +target/ Unit + +name/ Test document + +author/ Author + +contact/ platform@kruzhok.org + +description/ 1 +2 +3 + +version/ 0.1 + +date/ 2024-04-14 11:22 + +markupLanguage/ html + +transitionOrder/ exitFirst + +eventPropagation/ propagate + +'}}}} diff --git a/tests/04-read-meta.cpp b/tests/04-read-meta.cpp new file mode 100644 index 0000000..d186c1c --- /dev/null +++ b/tests/04-read-meta.cpp @@ -0,0 +1,57 @@ +/* ----------------------------------------------------------------------------- + * 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" + +using namespace Cyberiada; +using namespace std; + +#define CYB_ASSERT(q) if (!(q)) { \ + throw AssertException(std::string(__FILE__) + ":" + std::to_string(__LINE__)); \ + } + +int main(int argc, char** argv) +{ + Document d; + try { + d.load(string(argv[0]) + "-input.graphml", formatCyberiada10); + CYB_ASSERT(d.get_state_machines().front()->get_name() == "SM"); + CYB_ASSERT(d.meta().platform_name == "Berloga"); + CYB_ASSERT(d.meta().platform_version == "1.4"); + CYB_ASSERT(d.meta().platform_language == "script"); + CYB_ASSERT(d.meta().target_system == "Unit"); + CYB_ASSERT(d.meta().name == "Test document"); + CYB_ASSERT(d.meta().author == "Author"); + CYB_ASSERT(d.meta().contact == "platform@kruzhok.org"); + CYB_ASSERT(d.meta().description == "1\n2\n3"); + CYB_ASSERT(d.meta().version == "0.1"); + CYB_ASSERT(d.meta().date == "2024-04-14 11:22"); + CYB_ASSERT(d.meta().markup_language == "html"); + CYB_ASSERT(d.meta().transition_order_flag); // exit first + CYB_ASSERT(d.meta().event_propagation_flag); // propagate + cout << d << endl; + } catch (const Cyberiada::Exception& e) { + cerr << e.str() << endl; + return 1; + } + return 0; +} diff --git a/tests/04-read-meta.test-input.graphml b/tests/04-read-meta.test-input.graphml new file mode 100644 index 0000000..d093897 --- /dev/null +++ b/tests/04-read-meta.test-input.graphml @@ -0,0 +1,62 @@ + + + Cyberiada-GraphML-1.0 + + + + + + + + + + + + + + + + + + + + + + SM + + formal + CGML_META + standardVersion/ 1.0 + +platform/ Berloga + +platformVersion/ 1.4 + +platformLanguage/ script + +target/ Unit + +name/ Test document + +author/ Author + +contact/ platform@kruzhok.org + +description/ 1 +2 +3 + +version/ 0.1 + +date/ 2024-04-14 11:22 + +markupLanguage/ html + +transitionOrder/ exitFirst + +eventPropagation/ propagate + + + + +