aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/file_db.cpp47
-rw-r--r--tests/test_browser.py11
2 files changed, 58 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;
+}
+
diff --git a/tests/test_browser.py b/tests/test_browser.py
index 1c9cbfad..32b29966 100644
--- a/tests/test_browser.py
+++ b/tests/test_browser.py
@@ -794,6 +794,17 @@ If manually bisecting:
def test_glut_touchevents(self):
self.btest('glut_touchevents.c', '1')
+ def test_file_db(self):
+ secret = str(time.time())
+ open('moar.txt', 'w').write(secret)
+ self.btest('file_db.cpp', '1', args=['--preload-file', 'moar.txt', '-DFIRST'])
+ shutil.copyfile('test.html', 'first.html')
+ self.btest('file_db.cpp', secret)
+ shutil.copyfile('test.html', 'second.html')
+ open('moar.txt', 'w').write('aliantha')
+ self.btest('file_db.cpp', secret, args=['--preload-file', 'moar.txt']) # even with a file there, we load over it
+ shutil.move('test.html', 'third.html')
+
def test_sdl_pumpevents(self):
# key events should be detected using SDL_PumpEvents
open(os.path.join(self.get_dir(), 'pre.js'), 'w').write('''