diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-03-03 14:10:55 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-03-03 14:10:55 -0800 |
commit | 6ec190d3940cc2c115563ac924dc9a18325bf8c2 (patch) | |
tree | 59895b9a082e20d072510ad72f0a72b3c08999b2 /tests/worker_api_3_main.cpp | |
parent | aca0e4d8b27f797d8bf3338e2032aa758d3fde98 (diff) | |
parent | 168ec74a34743e3b2dc295ada9ccecbc689cf441 (diff) |
Merge branch 'allow_multiple_worker_responses' of github.com:virusdave/emscripten into incoming
Conflicts:
AUTHORS
Diffstat (limited to 'tests/worker_api_3_main.cpp')
-rw-r--r-- | tests/worker_api_3_main.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/worker_api_3_main.cpp b/tests/worker_api_3_main.cpp new file mode 100644 index 00000000..595f99b9 --- /dev/null +++ b/tests/worker_api_3_main.cpp @@ -0,0 +1,44 @@ +#include <stdio.h> +#include <assert.h> +#include <emscripten.h> + +int w1; + +bool sawCalls[] = { false, false, false, false }; + +void c1(char *data, int size, void *arg) { + assert((int)arg == 97); + assert(size >= sizeof(int)); + + int *x = (int*)data; + printf("c1: %d\n", x[0]); + + if (*x >= 0 && *x < 4) { + // Calls should have happened in order. + sawCalls[*x] = true; // Note the call with current param was made + for (int i = 0; i < *x - 1; ++i) { + if (!sawCalls[i]) { + // If we were called out of order, fail this and all following calls. + sawCalls[*x] = false; + break; + } + } + } else { + assert(*x == 4); + // This is the last call. All prior calls should have occurred. + int result = 1; // Final call occurred. + for (int i = 0; i < 4; ++i) + if (sawCalls[i]) result++; + REPORT_RESULT(); + } +} + +int main() { + w1 = emscripten_create_worker("worker.js"); + + int x[1] = { 0 }; + emscripten_call_worker(w1, "one", (char*)x, sizeof(x), c1, (void*)97); + + return 0; +} + |