aboutsummaryrefslogtreecommitdiff
path: root/tests/emscripten_fs_api_browser.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-12-31 11:56:53 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-12-31 11:56:53 -0800
commit2325baf34e144586d71251f31c01c7f2abfdb8b7 (patch)
tree6dec7e37e75040034d443786d4701e62b38a4d6d /tests/emscripten_fs_api_browser.cpp
parent8aa6919b7acf0b4034735ac7ee597e946fefaf4d (diff)
parenta55c2a24a50a93fcf9035eb2a809d13d3a8d3555 (diff)
Merge branch 'incoming' into asm_js
Conflicts: src/library_browser.js
Diffstat (limited to 'tests/emscripten_fs_api_browser.cpp')
-rw-r--r--tests/emscripten_fs_api_browser.cpp50
1 files changed, 47 insertions, 3 deletions
diff --git a/tests/emscripten_fs_api_browser.cpp b/tests/emscripten_fs_api_browser.cpp
index a2a82160..0355287a 100644
--- a/tests/emscripten_fs_api_browser.cpp
+++ b/tests/emscripten_fs_api_browser.cpp
@@ -9,13 +9,58 @@ extern "C" {
int result = 1;
int get_count = 0;
+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);
+ unsigned char *b = (unsigned char*)buffer;
+ assert(b[0] == 137);
+ assert(b[1122] == 128);
+ assert(b[1123] == 201);
+ assert(b[202125] == 218);
+ data_ok = 1;
+}
+
+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() {
+ if (counter++ == 60) {
+ printf("%d\n", get_count);
+ counter = 0;
+ }
+
if (get_count == 3) {
+ 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) {
@@ -23,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);
@@ -39,6 +82,7 @@ void onLoaded(const char* file) {
}
get_count++;
+ printf("onLoaded %s\n", file);
}
void onError(const char* file) {
@@ -46,8 +90,8 @@ void onError(const char* file) {
result = 0;
}
- printf("error: %s\n", file);
get_count++;
+ printf("onError %s\n", file);
}
int main() {