aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-08-30 14:49:12 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-08-30 14:49:12 -0700
commit249e75b46f07ebca6cce1b648b5d34bc4a75792c (patch)
treeef2889dc90b6347d7e9d58f6c46f678e302af5ec /tests
parent2a193932e89d6371913d6fdcbb55a072508a8140 (diff)
support for SDL_QUIT event
Diffstat (limited to 'tests')
-rwxr-xr-xtests/runner.py21
-rw-r--r--tests/sdl_quit.c33
2 files changed, 46 insertions, 8 deletions
diff --git a/tests/runner.py b/tests/runner.py
index 72eb2e7c..ec2f290f 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -7649,15 +7649,17 @@ elif 'browser' in str(sys.argv):
print '(moving on..)'
def with_report_result(self, code):
- return code.replace('REPORT_RESULT();', '''
- char output[1000];
- sprintf(output,
- "xhr = new XMLHttpRequest();"
- "xhr.open('GET', 'http://localhost:8888/report_result?%d');"
- "xhr.send();", result);
- emscripten_run_script(output);
+ return '''
+ #define REPORT_RESULT_INTERNAL(sync) \
+ char output[1000]; \
+ sprintf(output, \
+ "xhr = new XMLHttpRequest();" \
+ "xhr.open('GET', 'http://localhost:8888/report_result?%d'%s);" \
+ "xhr.send();", result, sync ? ", false" : ""); \
+ emscripten_run_script(output); \
emscripten_run_script("setTimeout(function() { window.close() }, 1000)");
-''')
+ #define REPORT_RESULT() REPORT_RESULT_INTERNAL(0)
+''' + code
def reftest(self, expected):
basename = os.path.basename(expected)
@@ -8157,6 +8159,9 @@ elif 'browser' in str(sys.argv):
shutil.copyfile(path_from_root('tests', 'screenshot.png'), os.path.join(self.get_dir(), 'screenshot.png')) # preloaded *after* run
self.btest('emscripten_fs_api_browser.cpp', '1')
+ def test_sdl_quit(self):
+ self.btest('sdl_quit.c', '1')
+
def test_gc(self):
self.btest('browser_gc.cpp', '1')
diff --git a/tests/sdl_quit.c b/tests/sdl_quit.c
new file mode 100644
index 00000000..1a07526f
--- /dev/null
+++ b/tests/sdl_quit.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_ttf.h>
+#include <assert.h>
+#include <emscripten.h>
+
+int result = 0;
+
+void one() {
+ SDL_Event event;
+ while (SDL_PollEvent(&event)) {
+ switch(event.type) {
+ case SDL_QUIT: {
+ if (!result) { // prevent infinite recursion since REPORT_RESULT does window.close too.
+ result = 1;
+ REPORT_RESULT_INTERNAL(1);
+ }
+ }
+ }
+ }
+}
+
+void main_2();
+
+int main() {
+ SDL_Init(SDL_INIT_VIDEO);
+ SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE);
+
+ emscripten_set_main_loop(one, 0);
+
+ emscripten_run_script("setTimeout(function() { window.close() }, 2000)");
+}
+