diff options
author | Stefan Radomski <sradomski@mintwerk.de> | 2016-04-22 10:21:14 (GMT) |
---|---|---|
committer | Stefan Radomski <sradomski@mintwerk.de> | 2016-04-22 10:21:14 (GMT) |
commit | c761e5f3931e4709f2736d5c3c0e11dc7b61ded5 (patch) | |
tree | 196e67745afb35f3fe76a85014160b53c0e21e57 /test/src | |
parent | a7cb1ba3d1c8e1d60387bc9a81ca5cded0c513d0 (diff) | |
download | uscxml-c761e5f3931e4709f2736d5c3c0e11dc7b61ded5.zip uscxml-c761e5f3931e4709f2736d5c3c0e11dc7b61ded5.tar.gz uscxml-c761e5f3931e4709f2736d5c3c0e11dc7b61ded5.tar.bz2 |
Minor bug-fixes and issue62 prepared
Diffstat (limited to 'test/src')
-rw-r--r-- | test/src/issues/test-issue62.cpp | 69 | ||||
-rw-r--r-- | test/src/test-c-inline.c | 201 | ||||
-rw-r--r-- | test/src/test-c-inline.c.scxml.c | 215 |
3 files changed, 396 insertions, 89 deletions
diff --git a/test/src/issues/test-issue62.cpp b/test/src/issues/test-issue62.cpp new file mode 100644 index 0000000..b75693c --- /dev/null +++ b/test/src/issues/test-issue62.cpp @@ -0,0 +1,69 @@ +#include "uscxml/Interpreter.h" +#include "glog/logging.h" + +using namespace uscxml; + +int main(int argc, char** argv) { + google::LogToStderr(); + google::InitGoogleLogging(argv[0]); + + const char* scxmlContent = + "<scxml datamodel=\"lua\" initial=\"init\" name=\"scxml_root\" version=\"1.0\" xmlns=\"http://www.w3.org/2005/07/scxml\"> " + " <state id=\"init\"> " + " <transition target=\"InvokeParent\"/> " + " </state> " + " <final id=\"FinalShape1\"/> " + " <state id=\"InvokeParent\"> " + " <invoke autoforward=\"true\" id=\"test_invoke\" type=\"scxml\"> " + " <content> " + " <scxml datamodel=\"lua\" initial=\"On\" name=\"ScxmlShape1\" version=\"1.0\" xmlns=\"http://www.w3.org/2005/07/scxml\"> " + " <state id=\"On\"> " + " <onentry> " + " <script>print('TEST LOGGING FROM INVOKE SOURCE')</script> " + " </onentry> " + " <transition target=\"Off\"/> " + " </state> " + " <state id=\"Off\"> " + " <transition event=\"inside_invoke\" target=\"End\"/> " + " </state> " + " <final id=\"End\"/> " + " </scxml> " + " </content> " + " </invoke> " + " <transition event=\"done.invoke.test_invoke\" target=\"FinalShape1\"/> " + " <transition event=\"move_here\" target=\"StateXXX\"/> " + " </state> " + " <state id=\"StateXXX\"> " + " <transition target=\"FinalShape1\"/> " + " </state> " + "</scxml> "; + + std::string msg; + + uscxml::Interpreter scxml = uscxml::Interpreter(uscxml::Interpreter::fromXML(scxmlContent, "")); + scxml.addMonitor(new StateTransitionMonitor()); + + uscxml::InterpreterState state; + + // assume initial stable configuration + do { + state = scxml.step(); + } while(state > 0); + + scxml.receive(Event("move_here")); + scxml.receive(Event("inside_invoke")); + + while(state != uscxml::USCXML_FINISHED) { + + do { + state = scxml.step(); + } while(state > 0); + + } + + std::cout << "************************************" << std::endl; + std::cout << "Successfully finished state machine!" << std::endl; + + return EXIT_SUCCESS; + +}
\ No newline at end of file diff --git a/test/src/test-c-inline.c b/test/src/test-c-inline.c index 659fcdf..7b375a9 100644 --- a/test/src/test-c-inline.c +++ b/test/src/test-c-inline.c @@ -1,60 +1,191 @@ -#include <stdlib.h> // EXIT_SUCCESS -#include <stdio.h> // printf +//#include <stdlib.h> // EXIT_SUCCESS +//#include <stdio.h> // printf #include <string.h> // memset +#undef ON_AVR + /** * Preprocess: - * uscxml-transform -tc -i ./test-c-inline.c -o ./test-c-inline.c.scxml.c + * uscxml-transform -tc -i ./gadget-inline-avr.c -o ./gadget-inline-avr.c.scxml.c */ /** INLINE SCXML BEGIN -<scxml name="test-inline" datamodel="native"> - <state id="foo"> - <transition target="done" cond="UD->foo == 3" /> - <onentry> - enteredFoo(); - </onentry> - </state> - <final id="done"> - <onentry> - enteredDone(); - </onentry> - </final> + +<scxml> + <parallel> + <onentry> + <raise event="blueHigh" /> + </onentry> + <!-- + 1 X X X X + ^ ^^^ ^^^ + | | | + | | Action + | Color + Here comes the signal! + + Colors: + blue 1,1 + red 1,0 + green 0,1 + ESC! 0,0 + + Actions: + dimUp: 0,1 + dimDown: 0,0 + turnOn: 1,1 + turnDown: 1,0 + + ESC!: + 0,0 All off + 1,1 All on + + IR emitter is either Color + Action or Special + --> + <state id="interaction"> + <transition event="blueHigh"> + <!-- Receiver beware, here it comes --> + <raise event="IROn" /> + + <!-- color blue --> + <raise event="IROn" /> + <raise event="IROn" /> + + <!-- action dimUp --> + <raise event="IROff" /> + <raise event="IROn" /> + + <!-- make sure to turn LED off --> + <raise event="IROff" /> + + </transition> + </state> + + <state id="periphery"> + <transition event="IROn" target="IRLedOn" type="internal" /> + <transition event="IROff" target="IRLedOff" type="internal" /> + + <!-- These are the lines we will connect to the IR emitter --> + <state id="IRLedOff"> + <onentry>ledOff();</onentry> + </state> + <state id="IRLedOn"> + <onentry>ledOn();</onentry> + </state> + </state> + </parallel> </scxml> INLINE SCXML END */ -/** - * These function can be called from within executable content - */ -void enteredFoo() { - printf("Entered Foo!\n"); -} +#define IQ_LENGTH 10 +#define EQ_LENGTH 10 + +const char* iQ[IQ_LENGTH]; +size_t iwPtr = 0; +size_t irPtr = 0; + +const char* eQ[EQ_LENGTH]; +size_t ewPtr = 0; +size_t erPtr = 0; + -void enteredDone() { - printf("Entered Done!\n"); +void ledOn() { + printf("Turned on LED!\n"); } -struct userData { - int foo; -}; +void ledOff() { + printf("Turned off LED!\n"); +} -#define UD ((struct userData*)ctx->user_data) #include "test-c-inline.c.scxml.c" +void* dequeue_internal(const uscxml_ctx* ctx) { + if (iwPtr != irPtr) { + size_t tmp = irPtr; + irPtr = (irPtr + 1 >= IQ_LENGTH ? 0 : irPtr + 1); + return iQ[tmp]; + } + return NULL; +} + +void* dequeue_external(const uscxml_ctx* ctx) { + if (ewPtr != erPtr) { + size_t tmp = erPtr; + irPtr = (erPtr + 1 >= EQ_LENGTH ? 0 : erPtr + 1); + return eQ[tmp]; + } + return NULL; +} + +int is_matched(const uscxml_ctx* ctx, const uscxml_transition* transition, const void* event) { + char* tPtr1 = (char*)event; + char* tPtr2 = (char*)transition->event; + while(*tPtr1 && *tPtr2) { + if (tPtr1 != tPtr2) + return 0; + tPtr1++; + tPtr2++; + } + return 1; +} + +int raise(const uscxml_ctx* ctx, const char* event) { + iQ[iwPtr] = event; + iwPtr = (iwPtr + 1 >= IQ_LENGTH ? 0 : iwPtr + 1); + return USCXML_ERR_OK; +} + +int send(const uscxml_ctx* ctx, const char* event) { + eQ[ewPtr] = event; + ewPtr = (ewPtr + 1 >= IQ_LENGTH ? 0 : ewPtr + 1); + return USCXML_ERR_OK; +} int main(int argc, char** argv) { - struct userData ud; - uscxml_ctx ctx; - int err = USCXML_ERR_OK; + +#ifdef ON_AVR + int ir_led = 9; + int blue_touch = 1; + int red_touch = 2; + int yellow_touch = 3; + pinMode(ir_led, OUTPUT); + pinMode(blue_touch, INPUT); + pinMode(red_touch, INPUT); + pinMode(yellow_touch, INPUT); + +#endif + + + uscxml_ctx ctx; + int err = USCXML_ERR_OK; + memset(&ctx, 0, sizeof(uscxml_ctx)); - ctx.machine = &USCXML_MACHINE_TEST_INLINE; - ctx.user_data = &ud; - ud.foo = 3; + ctx.machine = &USCXML_MACHINE; + + ctx.exec_content_raise = raise; + ctx.dequeue_internal = dequeue_internal; + ctx.dequeue_external = dequeue_external; + ctx.is_matched = is_matched; while(err != USCXML_ERR_DONE) { + err = uscxml_step(&ctx); +#ifdef ON_AVR + if (err == USCXML_IDLE) { + if (digitalRead(blue) == HIGH) { + send(ctx, "blueHigh"); + } + if (digitalRead(blue) == HIGH) { + send(ctx, "redHigh"); + } + if (digitalRead(blue) == HIGH) { + send(ctx, "greenHigh"); + } + } + delay(20); +#endif } - return EXIT_SUCCESS; -}
\ No newline at end of file + return 0; +} diff --git a/test/src/test-c-inline.c.scxml.c b/test/src/test-c-inline.c.scxml.c index 9bd1464..f3d8b01 100644 --- a/test/src/test-c-inline.c.scxml.c +++ b/test/src/test-c-inline.c.scxml.c @@ -116,6 +116,7 @@ #define USCXML_ERR_INVALID_TARGET 6 #define USCXML_ERR_INVALID_TYPE 7 #define USCXML_ERR_UNSUPPORTED 8 +#define USCXML_ERR_MACRO 9 #define USCXML_TRANS_SPONTANEOUS 0x01 #define USCXML_TRANS_TARGETLESS 0x02 @@ -368,11 +369,11 @@ struct uscxml_ctx { #endif /* forward declare machines to allow references */ -extern const uscxml_machine _uscxml_04E4C4CE_machine; +extern const uscxml_machine _uscxml_C4473F72_machine; #ifndef USCXML_NO_ELEM_INFO -static const uscxml_elem_donedata _uscxml_04E4C4CE_elem_donedatas[1] = { +static const uscxml_elem_donedata _uscxml_C4473F72_elem_donedatas[1] = { /* source, content, contentexpr, params */ { 0, NULL, NULL, NULL } }; @@ -385,73 +386,152 @@ static const uscxml_elem_donedata _uscxml_04E4C4CE_elem_donedatas[1] = { #ifndef USCXML_NO_EXEC_CONTENT -static int _uscxml_04E4C4CE_foo_on_entry_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { +static int _uscxml_C4473F72_scxml0_parallel0_on_entry_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { int err = USCXML_ERR_OK; - - enteredFoo(); - return USCXML_ERR_OK; + if likely(ctx->exec_content_raise != NULL) { + if unlikely((ctx->exec_content_raise(ctx, "blueHigh")) != USCXML_ERR_OK) return err; + } else { + return USCXML_ERR_MISSING_CALLBACK; + } + return USCXML_ERR_OK; } -static int _uscxml_04E4C4CE_foo_on_entry(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { - _uscxml_04E4C4CE_foo_on_entry_0(ctx, state, event); +static int _uscxml_C4473F72_scxml0_parallel0_on_entry(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { + _uscxml_C4473F72_scxml0_parallel0_on_entry_0(ctx, state, event); return USCXML_ERR_OK; } -static int _uscxml_04E4C4CE_done_on_entry_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { +static int _uscxml_C4473F72_IRLedOff_on_entry_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { int err = USCXML_ERR_OK; +ledOff(); return USCXML_ERR_OK; +} - enteredDone(); - return USCXML_ERR_OK; +static int _uscxml_C4473F72_IRLedOff_on_entry(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { + _uscxml_C4473F72_IRLedOff_on_entry_0(ctx, state, event); + return USCXML_ERR_OK; } -static int _uscxml_04E4C4CE_done_on_entry(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { - _uscxml_04E4C4CE_done_on_entry_0(ctx, state, event); +static int _uscxml_C4473F72_IRLedOn_on_entry_0(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { + int err = USCXML_ERR_OK; +ledOn(); return USCXML_ERR_OK; +} + +static int _uscxml_C4473F72_IRLedOn_on_entry(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { + _uscxml_C4473F72_IRLedOn_on_entry_0(ctx, state, event); return USCXML_ERR_OK; } -static int _uscxml_04E4C4CE_foo_transition0_is_enabled(const uscxml_ctx* ctx, const uscxml_transition* transition) { - return (UD->foo == 3); +static int _uscxml_C4473F72_interaction_transition0_on_trans(const uscxml_ctx* ctx, const uscxml_state* state, const void* event) { + int err = USCXML_ERR_OK; + if likely(ctx->exec_content_raise != NULL) { + if unlikely((ctx->exec_content_raise(ctx, "IROn")) != USCXML_ERR_OK) return err; + } else { + return USCXML_ERR_MISSING_CALLBACK; + } + if likely(ctx->exec_content_raise != NULL) { + if unlikely((ctx->exec_content_raise(ctx, "IROn")) != USCXML_ERR_OK) return err; + } else { + return USCXML_ERR_MISSING_CALLBACK; + } + if likely(ctx->exec_content_raise != NULL) { + if unlikely((ctx->exec_content_raise(ctx, "IROn")) != USCXML_ERR_OK) return err; + } else { + return USCXML_ERR_MISSING_CALLBACK; + } + if likely(ctx->exec_content_raise != NULL) { + if unlikely((ctx->exec_content_raise(ctx, "IROff")) != USCXML_ERR_OK) return err; + } else { + return USCXML_ERR_MISSING_CALLBACK; + } + if likely(ctx->exec_content_raise != NULL) { + if unlikely((ctx->exec_content_raise(ctx, "IROn")) != USCXML_ERR_OK) return err; + } else { + return USCXML_ERR_MISSING_CALLBACK; + } + if likely(ctx->exec_content_raise != NULL) { + if unlikely((ctx->exec_content_raise(ctx, "IROff")) != USCXML_ERR_OK) return err; + } else { + return USCXML_ERR_MISSING_CALLBACK; + } + return USCXML_ERR_OK; } + #endif #ifndef USCXML_NO_ELEM_INFO -static const uscxml_state _uscxml_04E4C4CE_states[3] = { +static const uscxml_state _uscxml_C4473F72_states[6] = { { /* state number 0 */ /* name */ NULL, /* parent */ 0, /* onentry */ NULL, /* onexit */ NULL, /* invoke */ NULL, - /* children */ { 0x06 /* 011 */ }, - /* completion */ { 0x02 /* 010 */ }, - /* ancestors */ { 0x00 /* 000 */ }, + /* children */ { 0x02 /* 010000 */ }, + /* completion */ { 0x02 /* 010000 */ }, + /* ancestors */ { 0x00 /* 000000 */ }, /* data */ NULL, /* type */ USCXML_STATE_COMPOUND, }, { /* state number 1 */ - /* name */ "foo", + /* name */ "0a3ff41d-98e6-40fe-b147-cf397c12eb55", /* parent */ 0, - /* onentry */ _uscxml_04E4C4CE_foo_on_entry, + /* onentry */ _uscxml_C4473F72_scxml0_parallel0_on_entry, /* onexit */ NULL, /* invoke */ NULL, - /* children */ { 0x00 /* 000 */ }, - /* completion */ { 0x00 /* 000 */ }, - /* ancestors */ { 0x01 /* 100 */ }, + /* children */ { 0x0c /* 001100 */ }, + /* completion */ { 0x0c /* 001100 */ }, + /* ancestors */ { 0x01 /* 100000 */ }, /* data */ NULL, - /* type */ USCXML_STATE_ATOMIC, + /* type */ USCXML_STATE_PARALLEL, }, { /* state number 2 */ - /* name */ "done", - /* parent */ 0, - /* onentry */ _uscxml_04E4C4CE_done_on_entry, + /* name */ "interaction", + /* parent */ 1, + /* onentry */ NULL, + /* onexit */ NULL, + /* invoke */ NULL, + /* children */ { 0x00 /* 000000 */ }, + /* completion */ { 0x00 /* 000000 */ }, + /* ancestors */ { 0x03 /* 110000 */ }, + /* data */ NULL, + /* type */ USCXML_STATE_ATOMIC, + }, + { /* state number 3 */ + /* name */ "periphery", + /* parent */ 1, + /* onentry */ NULL, + /* onexit */ NULL, + /* invoke */ NULL, + /* children */ { 0x30 /* 000011 */ }, + /* completion */ { 0x10 /* 000010 */ }, + /* ancestors */ { 0x03 /* 110000 */ }, + /* data */ NULL, + /* type */ USCXML_STATE_COMPOUND, + }, + { /* state number 4 */ + /* name */ "IRLedOff", + /* parent */ 3, + /* onentry */ _uscxml_C4473F72_IRLedOff_on_entry, + /* onexit */ NULL, + /* invoke */ NULL, + /* children */ { 0x00 /* 000000 */ }, + /* completion */ { 0x00 /* 000000 */ }, + /* ancestors */ { 0x0b /* 110100 */ }, + /* data */ NULL, + /* type */ USCXML_STATE_ATOMIC, + }, + { /* state number 5 */ + /* name */ "IRLedOn", + /* parent */ 3, + /* onentry */ _uscxml_C4473F72_IRLedOn_on_entry, /* onexit */ NULL, /* invoke */ NULL, - /* children */ { 0x00 /* 000 */ }, - /* completion */ { 0x00 /* 000 */ }, - /* ancestors */ { 0x01 /* 100 */ }, + /* children */ { 0x00 /* 000000 */ }, + /* completion */ { 0x00 /* 000000 */ }, + /* ancestors */ { 0x0b /* 110100 */ }, /* data */ NULL, - /* type */ USCXML_STATE_FINAL, + /* type */ USCXML_STATE_ATOMIC, } }; @@ -459,19 +539,45 @@ static const uscxml_state _uscxml_04E4C4CE_states[3] = { #ifndef USCXML_NO_ELEM_INFO -static const uscxml_transition _uscxml_04E4C4CE_transitions[1] = { +static const uscxml_transition _uscxml_C4473F72_transitions[3] = { { /* transition number 0 with priority 0 - target: done + target: + */ + /* source */ 2, + /* target */ { NULL }, + /* event */ "blueHigh", + /* condition */ NULL, + /* is_enabled */ NULL, + /* ontrans */ _uscxml_C4473F72_interaction_transition0_on_trans, + /* type */ USCXML_TRANS_TARGETLESS, + /* conflicts */ { 0x01 /* 100 */ }, + /* exit set */ { 0x00 /* 000000 */ } + }, + { /* transition number 1 with priority 1 + target: IRLedOn + */ + /* source */ 3, + /* target */ { 0x20 /* 000001 */ }, + /* event */ "IROn", + /* condition */ NULL, + /* is_enabled */ NULL, + /* ontrans */ NULL, + /* type */ USCXML_TRANS_INTERNAL, + /* conflicts */ { 0x06 /* 011 */ }, + /* exit set */ { 0x30 /* 000011 */ } + }, + { /* transition number 2 with priority 2 + target: IRLedOff */ - /* source */ 1, - /* target */ { 0x04 /* 001 */ }, - /* event */ NULL, - /* condition */ "UD->foo == 3", - /* is_enabled */ _uscxml_04E4C4CE_foo_transition0_is_enabled, + /* source */ 3, + /* target */ { 0x10 /* 000010 */ }, + /* event */ "IROff", + /* condition */ NULL, + /* is_enabled */ NULL, /* ontrans */ NULL, - /* type */ USCXML_TRANS_SPONTANEOUS, - /* conflicts */ { 0x01 /* 1 */ }, - /* exit set */ { 0x06 /* 011 */ } + /* type */ USCXML_TRANS_INTERNAL, + /* conflicts */ { 0x06 /* 011 */ }, + /* exit set */ { 0x30 /* 000011 */ } } }; @@ -480,22 +586,21 @@ static const uscxml_transition _uscxml_04E4C4CE_transitions[1] = { #ifndef USCXML_NO_ELEM_INFO #ifndef USCXML_MACHINE -# define USCXML_MACHINE _uscxml_04E4C4CE_machine +# define USCXML_MACHINE _uscxml_C4473F72_machine #endif -#define USCXML_MACHINE_0 _uscxml_04E4C4CE_machine -#define USCXML_MACHINE_TEST_INLINE _uscxml_04E4C4CE_machine +#define USCXML_MACHINE_0 _uscxml_C4473F72_machine -const uscxml_machine _uscxml_04E4C4CE_machine = { +const uscxml_machine _uscxml_C4473F72_machine = { /* flags */ 0, - /* nr_states */ 3, - /* nr_transitions */ 1, - /* name */ "test-inline", - /* datamodel */ "native", - /* uuid */ "04E4C4CEB25F6A7D5638FCE2C3213285", - /* states */ &_uscxml_04E4C4CE_states[0], - /* transitions */ &_uscxml_04E4C4CE_transitions[0], + /* nr_states */ 6, + /* nr_transitions */ 3, + /* name */ "", + /* datamodel */ "null", + /* uuid */ "C4473F72ECDBC2BBAE099A8F6849A804", + /* states */ &_uscxml_C4473F72_states[0], + /* transitions */ &_uscxml_C4473F72_transitions[0], /* parent */ NULL, - /* donedata */ &_uscxml_04E4C4CE_elem_donedatas[0], + /* donedata */ &_uscxml_C4473F72_elem_donedatas[0], /* script */ NULL }; @@ -659,6 +764,7 @@ int uscxml_step(uscxml_ctx* ctx) { goto ESTABLISH_ENTRY_SET; } +DEQUEUE_EVENT: if (ctx->flags & USCXML_CTX_SPONTANEOUS) { ctx->event = NULL; goto SELECT_TRANSITIONS; @@ -736,6 +842,7 @@ SELECT_TRANSITIONS: ctx->flags &= ~USCXML_CTX_TRANSITION_FOUND; } else { ctx->flags &= ~USCXML_CTX_SPONTANEOUS; + goto DEQUEUE_EVENT; } #ifdef USCXML_VERBOSE |