diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-10-04 18:13:17 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-10-04 18:13:17 -0700 |
commit | 2be2720852b990937bfbe71a8f6b65b2f20cb33d (patch) | |
tree | 77dc7a0b7decbb31a2b246a3e0c252210061826b /tests | |
parent | 2ac61df97125086a0ecb6f00fdd08cf8d93f02c2 (diff) |
emscripten_async_prepare
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/runner.py | 5 | ||||
-rw-r--r-- | tests/sdl_image_prepare.c | 49 |
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/runner.py b/tests/runner.py index dc2dab6a..56f06db2 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -8339,6 +8339,11 @@ elif 'browser' in str(sys.argv): shutil.move(os.path.join(self.get_dir(), basename), basename + '.renamedsoitcannotbefound'); self.run_browser('page.html', '', '/report_result?' + str(width)) + def test_sdl_image_prepare(self): + # load an image file, get pixel data. Also O2 coverage for --preload-file + shutil.copyfile(path_from_root('tests', 'screenshot.jpg'), os.path.join(self.get_dir(), 'screenshot.not')) + self.btest('sdl_image_prepare.c', reference='screenshot.jpg', args=['--preload-file', 'screenshot.not']) + def test_sdl_canvas(self): open(os.path.join(self.get_dir(), 'sdl_canvas.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_canvas.c')).read())) diff --git a/tests/sdl_image_prepare.c b/tests/sdl_image_prepare.c new file mode 100644 index 00000000..1c4d7218 --- /dev/null +++ b/tests/sdl_image_prepare.c @@ -0,0 +1,49 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <SDL/SDL_image.h> +#include <assert.h> +#include <emscripten.h> + +SDL_Surface* screen; + +int testImage(const char* fileName) { + SDL_Surface *image = IMG_Load(fileName); + if (!image) + { + printf("IMG_Load: %s\n", IMG_GetError()); + return 0; + } + assert(image->format->BitsPerPixel == 32); + assert(image->format->BytesPerPixel == 4); + assert(image->pitch == 4*image->w); + int result = image->w; + + SDL_BlitSurface (image, NULL, screen, NULL); + SDL_FreeSurface (image); + + return result; +} + +void ready(const char *f) { + printf("ready!\n"); + + testImage("screenshot.jpg"); // relative path + + SDL_Flip(screen); +} + +int main() { + SDL_Init(SDL_INIT_VIDEO); + screen = SDL_SetVideoMode(600, 450, 32, SDL_SWSURFACE); + + printf("rename..\n"); + + rename("screenshot.not", "screenshot.jpg"); + + printf("prepare..\n"); + + assert(emscripten_async_prepare("screenshot.jpg", ready, NULL) == 0); + + return 0; +} + |