diff options
author | Jukka Jylänki <jujjyl@gmail.com> | 2014-03-06 20:46:56 +0200 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2014-03-06 20:46:56 +0200 |
commit | 2a7b7d2b5c71980516706dc7ae99b64b6d789fb5 (patch) | |
tree | f64413642611fb8154c17ad536a792c9c85b4ebf /tests | |
parent | 04e5ac40b052e6b3d33b50cc82bd0a09a0632b6e (diff) |
Added a (currently failing) interactive test for SDL_WM_ToggleFullScreen.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/sdl_wm_togglefullscreen.c | 73 | ||||
-rw-r--r-- | tests/test_interactive.py | 3 |
2 files changed, 76 insertions, 0 deletions
diff --git a/tests/sdl_wm_togglefullscreen.c b/tests/sdl_wm_togglefullscreen.c new file mode 100644 index 00000000..b8052988 --- /dev/null +++ b/tests/sdl_wm_togglefullscreen.c @@ -0,0 +1,73 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <SDL/SDL_ttf.h> +#include <assert.h> +#include <emscripten.h> + +int result = 1; + +SDL_Surface *screen = 0; + +int inFullscreen = 0; + +int wasFullscreen = 0; + +void mainloop() { + SDL_Event event; + int isInFullscreen = EM_ASM_INT_V(return !!(document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.msFullscreenElement)); + if (isInFullscreen && !wasFullscreen) { + printf("Successfully transitioned to fullscreen mode!\n"); + wasFullscreen = isInFullscreen; + } + + if (wasFullscreen && !isInFullscreen) { + printf("Exited fullscreen. Test succeeded.\n"); + result = 1; +#ifdef REPORT_RESULT + REPORT_RESULT(); +#endif + wasFullscreen = isInFullscreen; + emscripten_cancel_main_loop(); + return; + } + + int haveEvent = SDL_PollEvent(&event); + if (haveEvent) { + switch(event.type) { + case SDL_MOUSEBUTTONDOWN: { + SDL_WM_ToggleFullScreen(screen); + inFullscreen = 1 - inFullscreen; + if (inFullscreen == 0) { + result = wasFullscreen; + if (result) { + printf("Exited fullscreen. Test succeeded.\n"); + } else { + printf("Exited fullscreen. Test failed, fullscreen transition did not happen!\n"); + } +#ifdef REPORT_RESULT + REPORT_RESULT(); +#endif + emscripten_cancel_main_loop(); + return; + } else { + printf("Entering fullscreen...\n"); + } + break; + } + } + } +} + +int main() { + SDL_Init(SDL_INIT_VIDEO); + screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); + + SDL_Rect rect = { 0, 0, 600, 450 }; + SDL_FillRect(screen, &rect, 0xff00ffff); + + printf("You should see a yellow canvas.\n"); + printf("Click on the canvas to enter full screen, and then click on the canvas again to finish the test.\n"); + printf("When in full screen, you should see the whole screen filled yellow, and after exiting, the yellow canvas should be restored in the window.\n"); + emscripten_set_main_loop(mainloop, 0, 0); + return 0; +} diff --git a/tests/test_interactive.py b/tests/test_interactive.py index bbd047cd..715e7d6b 100644 --- a/tests/test_interactive.py +++ b/tests/test_interactive.py @@ -22,6 +22,9 @@ class interactive(BrowserCore): def test_html5_fullscreen(self): self.btest(path_from_root('tests', 'test_html5_fullscreen.c'), expected='0') + def test_sdl_wm_togglefullscreen(self): + self.btest('sdl_wm_togglefullscreen.c', expected='1', args=['-s', 'NO_EXIT_RUNTIME=1']) + def test_sdl_audio(self): shutil.copyfile(path_from_root('tests', 'sounds', 'alarmvictory_1.ogg'), os.path.join(self.get_dir(), 'sound.ogg')) shutil.copyfile(path_from_root('tests', 'sounds', 'alarmcreatemiltaryfoot_1.wav'), os.path.join(self.get_dir(), 'sound2.wav')) |