diff options
author | Stefan Radomski <github@mintwerk.de> | 2016-10-25 11:59:18 (GMT) |
---|---|---|
committer | Stefan Radomski <github@mintwerk.de> | 2016-10-25 11:59:18 (GMT) |
commit | 954a1eb75f2abc81da1e09701d700674f0baddfb (patch) | |
tree | 873eb6412e958ecd53214ddbd6a3e17465da5100 /test/src | |
parent | 1a1513c6497e8818eb2a92a8fbf77d4c60bc911e (diff) | |
download | uscxml-954a1eb75f2abc81da1e09701d700674f0baddfb.zip uscxml-954a1eb75f2abc81da1e09701d700674f0baddfb.tar.gz uscxml-954a1eb75f2abc81da1e09701d700674f0baddfb.tar.bz2 |
Worked on PROMELA transformation
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/test-bindings.cpp | 2 | ||||
-rw-r--r-- | test/src/test-c89-parser.cpp | 182 | ||||
-rw-r--r-- | test/src/test-promela-parser.cpp | 323 | ||||
-rw-r--r-- | test/src/test-stress.cpp | 44 |
4 files changed, 437 insertions, 114 deletions
diff --git a/test/src/test-bindings.cpp b/test/src/test-bindings.cpp index 6932f67..61ed2d4 100644 --- a/test/src/test-bindings.cpp +++ b/test/src/test-bindings.cpp @@ -7,5 +7,5 @@ int main() { - return 0; + return 0; }
\ No newline at end of file diff --git a/test/src/test-c89-parser.cpp b/test/src/test-c89-parser.cpp index 9a4d570..11a1564 100644 --- a/test/src/test-c89-parser.cpp +++ b/test/src/test-c89-parser.cpp @@ -13,104 +13,104 @@ void testC89Parser() { c89_debug = 0; - std::list<std::string> localTest = { - "int main() { a = 10; }" - }; - - for (auto test : localTest) { - try { - C89Parser ast(test); - ast.dump(); - } catch (Event e) { - std::cerr << e << std::endl; - } - } + std::list<std::string> localTest = { + "int main() { a = 10; }" + }; - assert(false); - - std::list<URL> remoteTests = { - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/00_assignment.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/01_comment.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/02_printf.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/03_struct.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/04_for.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/05_array.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/06_case.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/07_function.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/08_while.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/09_do_while.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/10_pointer.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/11_precedence.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/12_hashdefine.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/13_integer_literals.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/14_if.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/15_recursion.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/16_nesting.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/17_enum.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/18_include.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/19_pointer_arithmetic.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/20_pointer_comparison.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/21_char_array.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/22_floating_point.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/23_type_coercion.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/24_math_library.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/25_quicksort.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/26_character_constants.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/27_sizeof.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/28_strings.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/29_array_address.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/30_hanoi.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/31_args.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/32_led.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/33_ternary_op.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/34_array_assignment.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/35_sizeof.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/36_array_initialisers.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/37_sprintf.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/38_multiple_array_index.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/39_typedef.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/40_stdio.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/41_hashif.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/42_function_pointer.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/43_void_param.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/44_scoped_declarations.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/45_empty_for.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/46_grep.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/47_switch_return.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/48_nested_break.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/49_bracket_evaluation.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/50_logical_second_arg.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/51_static.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/52_unnamed_enum.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/54_goto.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/55_array_initialiser.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/56_cross_structure.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/57_macro_bug.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/58_return_outside.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/59_break_before_loop.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/60_local_vars.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/61_initializers.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/62_float.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/63_typedef.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/64_double_prefix_op.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/65_typeless.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/66_printf_undefined.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/67_macro_crash.c"), - URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/68_return.c") - }; - - for (auto testURL : remoteTests) { + for (auto test : localTest) { try { - std::cout << std::endl << "'" << (std::string)testURL << "':" << std::endl; - std::cout << testURL.getInContent() << std::endl; - + C89Parser ast(test); + ast.dump(); + } catch (Event e) { + std::cerr << e << std::endl; + } + } + + assert(false); + + std::list<URL> remoteTests = { + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/00_assignment.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/01_comment.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/02_printf.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/03_struct.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/04_for.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/05_array.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/06_case.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/07_function.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/08_while.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/09_do_while.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/10_pointer.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/11_precedence.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/12_hashdefine.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/13_integer_literals.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/14_if.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/15_recursion.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/16_nesting.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/17_enum.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/18_include.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/19_pointer_arithmetic.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/20_pointer_comparison.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/21_char_array.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/22_floating_point.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/23_type_coercion.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/24_math_library.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/25_quicksort.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/26_character_constants.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/27_sizeof.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/28_strings.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/29_array_address.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/30_hanoi.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/31_args.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/32_led.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/33_ternary_op.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/34_array_assignment.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/35_sizeof.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/36_array_initialisers.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/37_sprintf.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/38_multiple_array_index.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/39_typedef.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/40_stdio.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/41_hashif.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/42_function_pointer.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/43_void_param.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/44_scoped_declarations.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/45_empty_for.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/46_grep.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/47_switch_return.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/48_nested_break.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/49_bracket_evaluation.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/50_logical_second_arg.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/51_static.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/52_unnamed_enum.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/54_goto.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/55_array_initialiser.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/56_cross_structure.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/57_macro_bug.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/58_return_outside.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/59_break_before_loop.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/60_local_vars.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/61_initializers.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/62_float.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/63_typedef.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/64_double_prefix_op.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/65_typeless.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/66_printf_undefined.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/67_macro_crash.c"), + URL("https://raw.githubusercontent.com/zsaleeba/picoc/master/tests/68_return.c") + }; + + for (auto testURL : remoteTests) { + try { + std::cout << std::endl << "'" << (std::string)testURL << "':" << std::endl; + std::cout << testURL.getInContent() << std::endl; + C89Parser ast(testURL.getInContent()); ast.dump(); - + } catch (Event e) { std::cerr << e << std::endl; } - std::this_thread::sleep_for(std::chrono::seconds(10)); + std::this_thread::sleep_for(std::chrono::seconds(10)); } } diff --git a/test/src/test-promela-parser.cpp b/test/src/test-promela-parser.cpp new file mode 100644 index 0000000..f0a019e --- /dev/null +++ b/test/src/test-promela-parser.cpp @@ -0,0 +1,323 @@ +#define protected public +#include "uscxml/util/URL.h" +#include "uscxml/Interpreter.h" +#include "uscxml/plugins/datamodel/promela/PromelaDataModel.h" +#include "uscxml/plugins/datamodel/promela/PromelaParser.h" +#include "uscxml/transform/ChartToPromela.h" +#include "uscxml/util/DOM.h" +#include "uscxml/util/Predicates.h" + +#include <xercesc/util/PlatformUtils.hpp> +#include <xercesc/dom/DOM.hpp> + +#include <assert.h> +#include <boost/algorithm/string.hpp> +#include <iostream> + +using namespace uscxml; +using namespace XERCESC_NS; + +extern int promela_debug; + +void testInlinePromela() { + + + DOMImplementation *implementation = DOMImplementationRegistry::getDOMImplementation(X("LS")); + DOMDocument* document = implementation->createDocument(); + + { + std::string test = "\ + promela-code This is foo!\ + "; + + DOMComment* comment = document->createComment(X(test)); + PromelaInline inl(comment); + assert(inl.type == PromelaInline::PROMELA_CODE); + assert(inl.content == "This is foo!"); + } + + { + std::string test = "\ + promela-code\n \ + This is foo!\ + "; + + DOMComment* comment = document->createComment(X(test)); + PromelaInline inl(comment); + assert(inl.type == PromelaInline::PROMELA_CODE); + assert(inl.content == "This is foo!"); + } + + { + std::string test = "\ + promela-event\n \ + [{\"name\": \"e1\", \"data\": { \"foo\": \"some string\" }}, \ + {\"name\": \"e1\", \"data\": { \"bar\": 12 }}]"; + + DOMComment* comment = document->createComment(X(test)); + PromelaInline inl(comment); + assert(inl.type == PromelaInline::PROMELA_EVENT_ONLY); + + PromelaEventSource es(inl); + assert(es.events.array.size() == 2); + + } + + { + Interpreter interpreter = Interpreter::fromURL("/Users/sradomski/Documents/TK/Code/uscxml/test/uscxml/promela/test-event-source-auto.scxml"); + assert(interpreter); + PromelaInlines inls(interpreter.getImpl()->getDocument()->getDocumentElement()); + + assert(inls.getAllOfType(PromelaInline::PROMELA_EVENT_ONLY).size() == 2); + assert(inls.getAllOfType(PromelaInline::PROMELA_EVENT_ALL_BUT).size() == 1); + } + +#if 0 + { + std::string test = "\ + #promela-inline:\n \ + This is foo!\ + "; + PromelaInlines prmInls = PromelaInlines::fromString(test); + assert(prmInls.nrAcceptLabels == 0 && + prmInls.nrCodes == 1 && + prmInls.nrEventSources == 0 && + prmInls.nrEndLabels == 0 && + prmInls.nrAcceptLabels == 0 && + prmInls.nrProgressLabels == 0); + assert(prmInls.code.size() == 1); + assert(prmInls.code.front().type == PromelaInline::PROMELA_CODE); + assert(boost::trim_copy(prmInls.code.front().content) == "This is foo!"); + } + + { + std::string test = "#promela-progress"; + PromelaInlines prmInls = PromelaInlines::fromString(test); + assert(prmInls.nrAcceptLabels == 0 && + prmInls.nrCodes == 0 && + prmInls.nrEventSources == 0 && + prmInls.nrEndLabels == 0 && + prmInls.nrProgressLabels == 1); + assert(prmInls.code.size() == 1); + assert(prmInls.code.front().type == PromelaInline::PROMELA_PROGRESS_LABEL); + } + + { + std::string test = "#promela-accept and then some"; + PromelaInlines prmInls = PromelaInlines::fromString(test); + assert(prmInls.nrAcceptLabels == 1 && + prmInls.nrCodes == 0 && + prmInls.nrEventSources == 0 && + prmInls.nrEndLabels == 0 && + prmInls.nrProgressLabels == 0); + assert(prmInls.code.size() == 1); + assert(prmInls.code.front().type == PromelaInline::PROMELA_ACCEPT_LABEL); + } + + { + std::string test = "#promela-end and then some"; + PromelaInlines prmInls = PromelaInlines::fromString(test); + assert(prmInls.nrAcceptLabels == 0 && + prmInls.nrCodes == 0 && + prmInls.nrEventSources == 0 && + prmInls.nrEndLabels == 1 && + prmInls.nrProgressLabels == 0); + assert(prmInls.code.size() == 1); + assert(prmInls.code.front().type == PromelaInline::PROMELA_END_LABEL); + } + + { + std::string test = "\ + #promela-event-source:\n \ + This is foo!\ + "; + PromelaInlines prmInls = PromelaInlines::fromString(test); + assert(prmInls.nrAcceptLabels == 0 && + prmInls.nrCodes == 0 && + prmInls.nrEventSources == 1 && + prmInls.nrEndLabels == 0 && + prmInls.nrProgressLabels == 0); + assert(prmInls.code.size() == 1); + assert(prmInls.code.front().type == PromelaInline::PROMELA_EVENT_SOURCE); + + PromelaEventSource pmlES(prmInls.code.front()); + assert(pmlES.sequences.size() == 1); + std::list<std::list<std::string> >::iterator seqsIter = pmlES.sequences.begin(); + std::list<std::string>::iterator seqIter = seqsIter->begin(); + assert(*seqIter++ == "This"); + assert(*seqIter++ == "is"); + assert(*seqIter++ == "foo!"); + assert(seqIter == seqsIter->end()); + seqsIter++; + assert(seqsIter == pmlES.sequences.end()); + } + + { + std::string test = "\ + #promela-event-source:\n \ + This is foo!\n \ + This is bar!\n \ + "; + PromelaInlines prmInls = PromelaInlines::fromString(test); + assert(prmInls.nrAcceptLabels == 0 && + prmInls.nrCodes == 0 && + prmInls.nrEventSources == 1 && + prmInls.nrEndLabels == 0 && + prmInls.nrProgressLabels == 0); + assert(prmInls.code.size() == 1); + assert(prmInls.code.front().type == PromelaInline::PROMELA_EVENT_SOURCE); + + PromelaEventSource pmlES(prmInls.code.front()); + + assert(pmlES.sequences.size() == 2); + std::list<std::list<std::string> >::iterator seqsIter = pmlES.sequences.begin(); + std::list<std::string>::iterator seqIter = seqsIter->begin(); + assert(*seqIter++ == "This"); + assert(*seqIter++ == "is"); + assert(*seqIter++ == "foo!"); + assert(seqIter == seqsIter->end()); + seqsIter++; + seqIter = seqsIter->begin(); + assert(*seqIter++ == "This"); + assert(*seqIter++ == "is"); + assert(*seqIter++ == "bar!"); + assert(seqIter == seqsIter->end()); + seqsIter++; + assert(seqsIter == pmlES.sequences.end()); + } + + { + std::string test = "\ + #promela-event-source-custom:\n \ + This is foo!\ + "; + PromelaInlines prmInls = PromelaInlines::fromString(test); + assert(prmInls.nrAcceptLabels == 0 && + prmInls.nrCodes == 0 && + prmInls.nrEventSources == 1 && + prmInls.nrEndLabels == 0 && + prmInls.nrProgressLabels == 0); + assert(prmInls.code.size() == 1); + assert(prmInls.code.front().type == PromelaInline::PROMELA_EVENT_SOURCE_CUSTOM); + + PromelaEventSource pmlES(prmInls.code.front()); + + assert(pmlES.sequences.size() == 0); + assert(boost::trim_copy(pmlES.source.content) == "This is foo!"); + } + + { + std::string test = "\ + #promela-event-source-custom:\n \ + This is foo! \n\ + #promela-progress\ + "; + PromelaInlines prmInls = PromelaInlines::fromString(test); + assert(prmInls.nrAcceptLabels == 0 && + prmInls.nrCodes == 0 && + prmInls.nrEventSources == 1 && + prmInls.nrEndLabels == 0 && + prmInls.nrProgressLabels == 1); + assert(prmInls.code.size() == 2); + assert(prmInls.code.front().type == PromelaInline::PROMELA_EVENT_SOURCE_CUSTOM); + + PromelaEventSource pmlES(prmInls.code.front()); + + assert(pmlES.sequences.size() == 0); + assert(boost::trim_copy(pmlES.source.content) == "This is foo!"); + } +#endif +} + +void checkTokenLocations(const std::string& expr, PromelaParserNode* ast) { + if (ast->loc != NULL) { + assert(expr.substr(ast->loc->firstCol, ast->loc->lastCol - ast->loc->firstCol) == ast->value); + } + for (std::list<PromelaParserNode*>::iterator opIter = ast->operands.begin(); opIter != ast->operands.end(); opIter++) { + checkTokenLocations(expr, *opIter); + } +} + +void testPromelaParser() { + + promela_debug = 0; +#if 1 + std::list<std::string> expressions; + /* declarations */ + expressions.push_back("bool b1"); + expressions.push_back("bool b1;"); + expressions.push_back("bool b1, b2, b3"); + expressions.push_back("bool b1, b2, b3;"); + expressions.push_back("bool b1, b2 = 3 + 4, b3, b4, b5;"); + expressions.push_back("bool b1; bool b2; bool b3; bool b4;"); + expressions.push_back("bool b1; bool b2; bool b3, b4, b5;"); + expressions.push_back("bit b = 1;"); + expressions.push_back("byte state = 1;"); + expressions.push_back("bool b1, b2 = 1, b3;"); + expressions.push_back("bool busy[3];"); + expressions.push_back("bool busy[3], us[4];"); + expressions.push_back("mtype = {\nred, white, blue,\nabort, accept, ack, sync_ack, close, connect,\ncreate, data, eof, open, reject, sync, transfer,\nFATAL, NON_FATAL, COMPLETE\n}"); + expressions.push_back("typedef D { short f; byte g }; "); + expressions.push_back("x = 1"); + expressions.push_back("x = foo.bar[2].baz; "); + expressions.push_back("_event.data[1].aParam.key1.key2[1].key3.key4"); + expressions.push_back("_event.data.aParam"); + expressions.push_back("_event.data"); + expressions.push_back("_event"); + expressions.push_back("states"); + expressions.push_back("states[1]"); + expressions.push_back("_x.states[1]"); + expressions.push_back("_x.states[1].foo"); + expressions.push_back("_event.data[1].aParam.key1.key2[1].key3.key4"); + expressions.push_back("\n\n\n\n int foo = 3;\n\nint bar = 5;"); + + + /* expressions */ + expressions.push_back("i+1"); + expressions.push_back("(x == false || t == Bturn);"); + expressions.push_back("a + (1 << b)"); + expressions.push_back("(a + 1) << b"); + expressions.push_back("(b < N)"); + expressions.push_back("(mt+1)%MAX;"); + expressions.push_back("state[0] = state[3] + 5 * state[3*2/n]"); + + /* statements */ + expressions.push_back("t = Bturn;"); + expressions.push_back("c++"); + expressions.push_back("state = state - 1"); + expressions.push_back("printf(\"hello world\\n\")"); + expressions.push_back("printf(\"result %d: %d\\n\", id, res, foo, bar)"); + expressions.push_back("printf(\"x = %d\\n\", x)"); + expressions.push_back("(n <= 1)"); + expressions.push_back("res = (a*a+b)/2*a;"); + expressions.push_back("assert(0) /* a forced stop, (Chapter 6) */"); + expressions.push_back("assert(count == 0 || count == 1)"); + expressions.push_back("busy[4 - 3] = 1;"); + + for (std::list<std::string>::iterator exprIter = expressions.begin(); + exprIter != expressions.end(); + exprIter++) { + try { + std::cout << std::endl << "'" << *exprIter << "':" << std::endl; + PromelaParser ast(*exprIter); + ast.dump(); + if (!boost::contains(*exprIter, "\n")) + checkTokenLocations(*exprIter, ast.ast); + } catch (Event e) { + std::cerr << e << std::endl; + } + } +#endif + +} + +int main(int argc, char** argv) { + try { + ::xercesc_3_1::XMLPlatformUtils::Initialize(); + } catch (const XERCESC_NS::XMLException& toCatch) { + ERROR_PLATFORM_THROW("Cannot initialize XercesC: " + X(toCatch.getMessage()).str()); + } + + testInlinePromela(); + testPromelaParser(); +}
\ No newline at end of file diff --git a/test/src/test-stress.cpp b/test/src/test-stress.cpp index 87000c8..d3209e2 100644 --- a/test/src/test-stress.cpp +++ b/test/src/test-stress.cpp @@ -24,21 +24,21 @@ class StatusMonitor : public uscxml::InterpreterMonitor { }; void printUsageAndExit() { - printf("test-stress version " USCXML_VERSION " (" CMAKE_BUILD_TYPE " build - " CMAKE_COMPILER_STRING ")\n"); - printf("Usage\n"); - printf("\ttest-stress"); + printf("test-stress version " USCXML_VERSION " (" CMAKE_BUILD_TYPE " build - " CMAKE_COMPILER_STRING ")\n"); + printf("Usage\n"); + printf("\ttest-stress"); #ifdef BUILD_AS_PLUGINS - printf(" [-p pluginPath]"); + printf(" [-p pluginPath]"); #endif - printf(" <PATH>\n"); - printf("\n"); - exit(1); + printf(" <PATH>\n"); + printf("\n"); + exit(1); } int main(int argc, char** argv) { using namespace uscxml; - if (argc < 2) { + if (argc < 2) { printUsageAndExit(); } @@ -62,7 +62,7 @@ int main(int argc, char** argv) { DirectoryWatch* watcher = new DirectoryWatch(argv[optind], true); watcher->updateEntries(true); - + std::map<std::string, struct stat> entries = watcher->getAllEntries(); StatusMonitor vm; @@ -77,27 +77,27 @@ int main(int argc, char** argv) { startedAt = time(NULL); lastTransitionAt = time(NULL); - Interpreter interpreter = Interpreter::fromURL(std::string(argv[optind]) + PATH_SEPERATOR + entryIter->first); + Interpreter interpreter = Interpreter::fromURL(std::string(argv[optind]) + PATH_SEPERATOR + entryIter->first); // Interpreter interpreter = Interpreter::fromURL("/Users/sradomski/Documents/TK/Code/uscxml/test/w3c/ecma/test422.scxml"); - LOG(INFO) << "Processing " << interpreter.getImpl()->getBaseURL(); + LOG(INFO) << "Processing " << interpreter.getImpl()->getBaseURL(); if (interpreter) { interpreter.addMonitor(&vm); - InterpreterState state = InterpreterState::USCXML_UNDEF; - int now = time(NULL); + InterpreterState state = InterpreterState::USCXML_UNDEF; + int now = time(NULL); - try { - while(state != USCXML_FINISHED && now - startedAt < 20 && now - lastTransitionAt < 2) { + try { + while(state != USCXML_FINISHED && now - startedAt < 20 && now - lastTransitionAt < 2) { // while(state != USCXML_FINISHED) { - state = interpreter.step(200); - now = time(NULL); - } - } catch (...) {} + state = interpreter.step(200); + now = time(NULL); + } + } catch (...) {} } entryIter++; - - // forever + + // forever // if (entryIter == entries.end()) { // entryIter = entries.begin(); // } @@ -105,5 +105,5 @@ int main(int argc, char** argv) { delete watcher; - return EXIT_SUCCESS; + return EXIT_SUCCESS; }
\ No newline at end of file |