aboutsummaryrefslogtreecommitdiff
path: root/tests/file_db.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-08-30 11:21:48 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-08-30 11:21:48 -0700
commitb5b49215d4a40566380a769f47a9c1cce74a28b0 (patch)
tree68308b6059798a81f24f6a8a1ac28a0091c5d066 /tests/file_db.cpp
parent1cc28b8e9e94267041bc71afebfbbe3059db4a3f (diff)
parentb895cdc7df2085d324003c9df582a3dcc1927697 (diff)
Merge branch 'incoming'
Diffstat (limited to 'tests/file_db.cpp')
-rw-r--r--tests/file_db.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/file_db.cpp b/tests/file_db.cpp
new file mode 100644
index 00000000..ebb3bb30
--- /dev/null
+++ b/tests/file_db.cpp
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <emscripten.h>
+
+void later(void *) {}
+
+int main() {
+#if FIRST
+ FILE *f = fopen("waka.txt", "w");
+ fputc('a', f);
+ fputc('z', f);
+ fclose(f);
+
+ EM_ASM(
+ FS.saveFilesToDB(['waka.txt', 'moar.txt'], function() {
+ Module.print('save ok');
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', 'http://localhost:8888/report_result?1');
+ xhr.send();
+ setTimeout(function() { window.close() }, 1000);
+ }, function(e) {
+ abort('saving should succeed ' + e);
+ });
+ );
+#else
+ EM_ASM(
+ FS.loadFilesFromDB(['waka.txt', 'moar.txt'], function() {
+ function stringy(arr) {
+ return Array.prototype.map.call(arr, function(x) { return String.fromCharCode(x) }).join('');
+ }
+ assert(stringy(FS.analyzePath('waka.txt').object.contents) == 'az');
+ var secret = stringy(FS.analyzePath('moar.txt').object.contents);
+ Module.print('load: ' + secret);
+ var xhr = new XMLHttpRequest();
+ xhr.open('GET', 'http://localhost:8888/report_result?' + secret);
+ xhr.send();
+ setTimeout(function() { window.close() }, 1000);
+ }, function() {
+ abort('loading should succeed');
+ });
+ );
+#endif
+
+ emscripten_async_call(later, NULL, 100); // keep runtime alive
+
+ return 0;
+}
+