diff options
author | James Gregory <james@james.id.au> | 2013-08-19 16:40:37 -0700 |
---|---|---|
committer | James Gregory <james@james.id.au> | 2013-08-19 16:40:37 -0700 |
commit | 976aaf7c8aabc5a82aeed5485fb0fce7ad2e7409 (patch) | |
tree | 6212fbb790578729d9aca222d4e0e7ae7d14be73 | |
parent | afcdfff09f8557ce6810546628733f48d6c45408 (diff) |
Add test-case for touch-handling in glut.
-rw-r--r-- | tests/glut_touchevents.c | 64 | ||||
-rw-r--r-- | tests/test_browser.py | 3 |
2 files changed, 67 insertions, 0 deletions
diff --git a/tests/glut_touchevents.c b/tests/glut_touchevents.c new file mode 100644 index 00000000..1f097895 --- /dev/null +++ b/tests/glut_touchevents.c @@ -0,0 +1,64 @@ +#include <stdio.h> +#include <stdlib.h> +#include <GL/glut.h> +#include <EGL/egl.h> +#include <emscripten.h> + +#define MULTILINE(...) #__VA_ARGS__ + +int touch_started = 0; +int touch_ended = 0; + +int result = 0; + +void mouseCB(int button, int state, int x, int y) +{ + if(button == GLUT_LEFT_BUTTON) + { + if(state == GLUT_DOWN) + { + touch_started = 1; + } + else if(state == GLUT_UP) + { + touch_ended = 1; + } + } +} + +int main(int argc, char *argv[]) +{ + emscripten_run_script(MULTILINE( + Module.injectEvent = function(eventType, x, y) { + // Desktop browsers do not have the event types for touch events, + // so we fake them by creating a plain-vanilla UIEvent and then + // filling in the fields that we look for with appropriate values. + var touch = { + pageX: x, + pageY: y + }; + var touches = [ touch ]; + touches.item = function(i) { return this[i]; }; + + var event = document.createEvent('UIEvent'); + event.target = Module['canvas']; + event.button = 0; + event.touches = touches; + event.initUIEvent(eventType, true, true); + Module['canvas'].dispatchEvent(event); + } + )); + + // Fake a touch device so that glut sets up the appropriate event handlers. + emscripten_run_script("document.documentElement['ontouchstart'] = 1"); + glutInit(&argc, argv); + + glutMouseFunc(&mouseCB); + + emscripten_run_script("Module.injectEvent('touchend', 100, 100)"); + emscripten_run_script("Module.injectEvent('touchstart', 100, 100)"); + result = touch_started && touch_ended; + + REPORT_RESULT(); + return 0; +} diff --git a/tests/test_browser.py b/tests/test_browser.py index 2c5d65ee..7c387071 100644 --- a/tests/test_browser.py +++ b/tests/test_browser.py @@ -787,6 +787,9 @@ Press any key to continue.''' Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'sdl_mouse.c'), '-O2', '--minify', '0', '-o', 'sdl_mouse.js', '--pre-js', 'pre.js']).communicate() self.run_browser('page.html', '', '/report_result?600') + def test_glut_touchevents(self): + self.btest('glut_touchevents.c', '1') + def test_sdl_pumpevents(self): # key events should be detected using SDL_PumpEvents open(os.path.join(self.get_dir(), 'pre.js'), 'w').write(''' |