diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-12-31 11:38:39 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-12-31 11:38:39 -0800 |
commit | a55c2a24a50a93fcf9035eb2a809d13d3a8d3555 (patch) | |
tree | 757ce2be8671f2b24838b9dd5da58740ffe7fba3 /tests/emscripten_fs_api_browser.cpp | |
parent | 3b2510764a224afc4e9f06c9e3dd92dad131ed55 (diff) |
make browser fs api test robust
Diffstat (limited to 'tests/emscripten_fs_api_browser.cpp')
-rw-r--r-- | tests/emscripten_fs_api_browser.cpp | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/tests/emscripten_fs_api_browser.cpp b/tests/emscripten_fs_api_browser.cpp index ba5bf0a5..0355287a 100644 --- a/tests/emscripten_fs_api_browser.cpp +++ b/tests/emscripten_fs_api_browser.cpp @@ -13,6 +13,7 @@ int data_ok = 0; int data_bad = 0; void onLoadedData(void *arg, void *buffer, int size) { + printf("onLoadedData %d\n", (int)arg); get_count++; assert(size == 329895); assert((int)arg == 135); @@ -25,31 +26,41 @@ void onLoadedData(void *arg, void *buffer, int size) { } void onErrorData(void *arg) { + printf("onErrorData %d\n", (int)arg); get_count++; assert((int)arg == 246); data_bad = 1; } +int counter = 0; void wait_wgets() { - printf("%d\n", get_count); + if (counter++ == 60) { + printf("%d\n", get_count); + counter = 0; + } if (get_count == 3) { - emscripten_async_wget_data( - "http://localhost:8888/screenshot.png", - (void*)135, - onLoadedData, - onErrorData); - emscripten_async_wget_data( - "http://localhost:8888/fail_me", - (void*)246, - onLoadedData, - onErrorData); + static bool fired = false; + if (!fired) { + fired = true; + emscripten_async_wget_data( + "http://localhost:8888/screenshot.png", + (void*)135, + onLoadedData, + onErrorData); + emscripten_async_wget_data( + "http://localhost:8888/fail_me", + (void*)246, + onLoadedData, + onErrorData); + } } else if (get_count == 5) { assert(IMG_Load("/tmp/screen_shot.png")); assert(data_ok == 1 && data_bad == 1); emscripten_cancel_main_loop(); REPORT_RESULT(); } + assert(get_count <= 5); } void onLoaded(const char* file) { @@ -57,8 +68,6 @@ void onLoaded(const char* file) { result = 0; } - printf("loaded: %s\n", file); - if (FILE * f = fopen(file, "r")) { printf("exists: %s\n", file); int c = fgetc (f); @@ -73,6 +82,7 @@ void onLoaded(const char* file) { } get_count++; + printf("onLoaded %s\n", file); } void onError(const char* file) { @@ -80,8 +90,8 @@ void onError(const char* file) { result = 0; } - printf("error: %s\n", file); get_count++; + printf("onError %s\n", file); } int main() { @@ -103,7 +113,7 @@ int main() { onLoaded, onError); - emscripten_set_main_loop(wait_wgets, 1000, 0); + emscripten_set_main_loop(wait_wgets, 0, 0); return 0; } |