diff options
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/runner.py | 10 | ||||
-rw-r--r-- | tests/sdl_image_jpeg.c | 45 |
2 files changed, 53 insertions, 2 deletions
diff --git a/tests/runner.py b/tests/runner.py index 71035b02..ee710fc9 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -10030,6 +10030,12 @@ elif 'browser' in str(sys.argv): Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'sdl_image.c'), '-O2', '--preload-file', 'screenshot.jpg', '-o', 'page.html']).communicate() self.run_browser('page.html', '', '/report_result?600') + def test_sdl_image_jpeg(self): + shutil.copyfile(path_from_root('tests', 'screenshot.jpg'), os.path.join(self.get_dir(), 'screenshot.jpeg')) + open(os.path.join(self.get_dir(), 'sdl_image_jpeg.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_image_jpeg.c')).read())) + Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'sdl_image_jpeg.c'), '--preload-file', 'screenshot.jpeg', '-o', 'page.html']).communicate() + self.run_browser('page.html', '', '/report_result?600') + def test_sdl_image_compressed(self): for image, width in [(path_from_root('tests', 'screenshot2.png'), 300), (path_from_root('tests', 'screenshot.jpg'), 600)]: @@ -10049,12 +10055,12 @@ elif 'browser' in str(sys.argv): 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 + # load an image file, get pixel data. 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_image_prepare_data(self): - # load an image file, get pixel data. Also O2 coverage for --preload-file + # load an image file, get pixel data. shutil.copyfile(path_from_root('tests', 'screenshot.jpg'), os.path.join(self.get_dir(), 'screenshot.not')) self.btest('sdl_image_prepare_data.c', reference='screenshot.jpg', args=['--preload-file', 'screenshot.not']) diff --git a/tests/sdl_image_jpeg.c b/tests/sdl_image_jpeg.c new file mode 100644 index 00000000..10619dad --- /dev/null +++ b/tests/sdl_image_jpeg.c @@ -0,0 +1,45 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <SDL/SDL_image.h> +#include <assert.h> +#include <emscripten.h> + +int testImage(SDL_Surface* screen, 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; +} + +int main() { + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_SWSURFACE); + + int result = 0; + result = testImage(screen, "screenshot.jpeg"); // relative path + assert(result != 0); + result |= testImage(screen, "/screenshot.jpeg"); // absolute path + assert(result != 0); + + SDL_Flip(screen); + + printf("you should see an image.\n"); + + SDL_Quit(); + + REPORT_RESULT(); + + return 0; +} + |