aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2014-04-14 01:22:19 +0300
committerJukka Jylänki <jujjyl@gmail.com>2014-04-14 01:22:19 +0300
commit2faa69a865c3d6046d7d5202f2dc747dea3229f1 (patch)
tree99f3fa6eca209e2786eeaecc40b4656ee1d109b9 /tests
parent43ddbe9ecd05afac7674a25097b2799be1f7b6ce (diff)
Add interactive and automated testing for SDL touch events.
Diffstat (limited to 'tests')
-rw-r--r--tests/sdl_touch.c78
-rw-r--r--tests/test_browser.py5
-rw-r--r--tests/test_interactive.py3
3 files changed, 86 insertions, 0 deletions
diff --git a/tests/sdl_touch.c b/tests/sdl_touch.c
new file mode 100644
index 00000000..1fce1df1
--- /dev/null
+++ b/tests/sdl_touch.c
@@ -0,0 +1,78 @@
+#include <stdio.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_ttf.h>
+#include <assert.h>
+#include <emscripten.h>
+
+int result = 1;
+
+static char *TouchFingerTypeToString(int type) {
+ if (type == SDL_FINGERMOTION) return "SDL_FINGERMOTION";
+ if (type == SDL_FINGERDOWN) return "SDL_FINGERDOWN";
+ if (type == SDL_FINGERUP) return "SDL_FINGERUP";
+ return "UNKNOWN";
+}
+
+int got_down = 0;
+int got_move = 0;
+int got_up = 0;
+
+void progress() {
+ if (!got_down) printf("Hold down a finger to generate a touch down event.\n");
+ else if (!got_move) printf("Drag a finger to generate a touch move event.\n");
+ else if (!got_up) printf("Release a finger to generate a touch up event.\n");
+ else
+ {
+ int result = 0;
+#ifdef REPORT_RESULT
+ REPORT_RESULT();
+#endif
+ }
+}
+
+void loop() {
+ SDL_Event event;
+ while (SDL_PollEvent(&event)) {
+ switch(event.type) {
+ case SDL_FINGERMOTION:
+ case SDL_FINGERDOWN:
+ case SDL_FINGERUP: {
+ SDL_TouchFingerEvent *t = (SDL_TouchFingerEvent*)&event;
+ printf("type: %s, timestamp: %u, touchId: %llu, fingerId: %llu, x: %f, y: %f, dx: %f, dy: %f, pressure: %f\n",
+ TouchFingerTypeToString(event.type), t->timestamp, t->touchId, t->fingerId, t->x, t->y, t->dx, t->dy, t->pressure);
+
+ if (t->timestamp != 0 && t->x >= 0.f && t->x <= 1.f && t->y >= 0.f && t->y <= 1.f && t->pressure >= 0.f && t->pressure <= 1.f) {
+ if (event.type == SDL_FINGERDOWN) { got_down = 1; progress(); }
+ if (event.type == SDL_FINGERMOTION) { got_move = 1; progress(); }
+ if (event.type == SDL_FINGERDOWN) { got_up = 1; progress(); }
+ }
+ break;
+ }
+ }
+ }
+}
+
+int main() {
+ SDL_Init(SDL_INIT_VIDEO);
+ SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE);
+
+ progress();
+
+#ifdef AUTOMATE_SUCCESS
+ EM_ASM(
+ function sendEvent(type, data) {
+ var event = document.createEvent('Event');
+ event.initEvent(type, true, true);
+ for(var d in data) event[d] = data[d];
+ Module['canvas'].dispatchEvent(event);
+ }
+ sendEvent('touchstart', { touches: [ { pageX: 300, pageY: 400, deviceID: 1, identifier: 1, force: 1 } ] });
+ sendEvent('touchmove', { touches: [ { pageX: 350, pageY: 400, deviceID: 1, identifier: 1, force: 1 } ] });
+ sendEvent('touchend', { changedTouches: [ { pageX: 350, pageY: 400, deviceID: 1, identifier: 1, force: 1 } ] });
+ );
+#endif
+
+ emscripten_set_main_loop(loop, 0, 0);
+
+ return 0;
+}
diff --git a/tests/test_browser.py b/tests/test_browser.py
index cf893eb5..c06f11ac 100644
--- a/tests/test_browser.py
+++ b/tests/test_browser.py
@@ -1793,6 +1793,11 @@ Module["preRun"].push(function () {
print opts
self.btest(path_from_root('tests', 'test_html5.c'), args=opts, expected='0')
+ def test_sdl_touch(self):
+ for opts in [[], ['-O2', '-g1', '--closure', '1']]:
+ print opts
+ self.btest(path_from_root('tests', 'sdl_touch.c'), args=opts + ['-DAUTOMATE_SUCCESS=1'], expected='0')
+
def test_html5_mouse(self):
for opts in [[], ['-O2', '-g1', '--closure', '1']]:
print opts
diff --git a/tests/test_interactive.py b/tests/test_interactive.py
index 4ac52f55..aa1d96af 100644
--- a/tests/test_interactive.py
+++ b/tests/test_interactive.py
@@ -25,6 +25,9 @@ class interactive(BrowserCore):
def test_html5_mouse(self):
self.btest(path_from_root('tests', 'test_html5_mouse.c'), expected='0')
+ def test_sdl_touch(self):
+ self.btest(path_from_root('tests', 'sdl_touch.c'), args=['-O2', '-g1', '--closure', '1'], expected='0')
+
def test_sdl_wm_togglefullscreen(self):
self.btest('sdl_wm_togglefullscreen.c', expected='1', args=['-s', 'NO_EXIT_RUNTIME=1'])