Skip to content

Commit

Permalink
make browser fs api test robust
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Dec 31, 2012
1 parent 3b25107 commit a55c2a2
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions tests/emscripten_fs_api_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -25,40 +26,48 @@ 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) {
if (strcmp(file, "/tmp/test.html") && strcmp(file, "/tmp/screen_shot.png")) {
result = 0;
}

printf("loaded: %s\n", file);

if (FILE * f = fopen(file, "r")) {
printf("exists: %s\n", file);
int c = fgetc (f);
Expand All @@ -73,15 +82,16 @@ void onLoaded(const char* file) {
}

get_count++;
printf("onLoaded %s\n", file);
}

void onError(const char* file) {
if (strcmp(file, "/tmp/null")) {
result = 0;
}

printf("error: %s\n", file);
get_count++;
printf("onError %s\n", file);
}

int main() {
Expand All @@ -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;
}
Expand Down

0 comments on commit a55c2a2

Please sign in to comment.