aboutsummaryrefslogtreecommitdiff
path: root/tests/emscripten_fs_api_browser.cpp
diff options
context:
space:
mode:
authorAleksander Guryanov <caiiiycuk@gmail.com>2012-06-20 22:20:04 +0700
committerAleksander Guryanov <caiiiycuk@gmail.com>2012-06-21 20:38:01 +0700
commit2c86cbf25bead7607256ef9bb8f36bfe07047cee (patch)
tree98f4ea7699d6d7474dd80b4ab4037e8ff5dd3a96 /tests/emscripten_fs_api_browser.cpp
parent6d34633796954f2edb225c66e62ab5a188d59bb0 (diff)
Implementation for emscripten_async_wget
Diffstat (limited to 'tests/emscripten_fs_api_browser.cpp')
-rw-r--r--tests/emscripten_fs_api_browser.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/emscripten_fs_api_browser.cpp b/tests/emscripten_fs_api_browser.cpp
new file mode 100644
index 00000000..07469f34
--- /dev/null
+++ b/tests/emscripten_fs_api_browser.cpp
@@ -0,0 +1,69 @@
+#include<stdio.h>
+#include<emscripten.h>
+#include<assert.h>
+#include <string.h>
+
+extern "C" {
+
+int result = 1;
+int get_count = 0;
+
+void wait_wgets() {
+ if (get_count == 2) {
+ emscripten_cancel_main_loop();
+ REPORT_RESULT();
+ }
+}
+
+void onLoaded(const char* file) {
+ if (strcmp(file, "/tmp/test.html")) {
+ result = 0;
+ }
+
+ printf("loaded: %s\n", file);
+
+ if (FILE * f = fopen(file, "r")) {
+ printf("exists: %s\n", file);
+ int c = fgetc (f);
+ if (c == EOF) {
+ printf("file empty: %s\n", file);
+ result = 0;
+ }
+ fclose(f);
+ } else {
+ result = 0;
+ printf("!exists: %s\n", file);
+ }
+
+ get_count++;
+}
+
+void onError(const char* file) {
+ if (strcmp(file, "/tmp/null")) {
+ result = 0;
+ }
+
+ printf("error: %s\n", file);
+ get_count++;
+}
+
+int main() {
+ emscripten_async_wget(
+ "http://localhost:8888/this_is_not_a_file",
+ "/tmp/null",
+ onLoaded,
+ onError);
+
+ emscripten_async_wget(
+ "http://localhost:8888/test.html",
+ "/tmp/test.html",
+ onLoaded,
+ onError);
+
+ emscripten_set_main_loop(wait_wgets, 0);
+
+ return 0;
+}
+
+}
+