aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtests/runner.py29
-rw-r--r--tests/sdl_image.c6
-rw-r--r--tests/sdl_image_jpeg.c45
3 files changed, 23 insertions, 57 deletions
diff --git a/tests/runner.py b/tests/runner.py
index 2f215159..83d62946 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -13045,13 +13045,21 @@ Press any key to continue.'''
open(os.path.join(self.get_dir(), 'sdl_image.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_image.c')).read()))
for mem in [0, 1]:
- Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'sdl_image.c'), '-O2', '--preload-file', 'screenshot.jpg@/assets/screenshot.jpg', '-o', 'page.html', '--memory-init-file', str(mem)]).communicate()
- self.run_browser('page.html', '', '/report_result?600')
+ for dest, dirname, basename in [('screenshot.jpg', '/', 'screenshot.jpg'),
+ ('screenshot.jpg@/assets/screenshot.jpg', '/assets', 'screenshot.jpg')]:
+ Popen([
+ PYTHON, EMCC, os.path.join(self.get_dir(), 'sdl_image.c'), '-o', 'page.html', '-O2', '--memory-init-file', str(mem),
+ '--preload-file', dest, '-DSCREENSHOT_DIRNAME="' + dirname + '"', '-DSCREENSHOT_BASENAME="' + basename + '"'
+ ]).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()
+ open(os.path.join(self.get_dir(), 'sdl_image_jpeg.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_image.c')).read()))
+ Popen([
+ PYTHON, EMCC, os.path.join(self.get_dir(), 'sdl_image_jpeg.c'), '-o', 'page.html',
+ '--preload-file', 'screenshot.jpeg', '-DSCREENSHOT_DIRNAME="/"', '-DSCREENSHOT_BASENAME="screenshot.jpeg"'
+ ]).communicate()
self.run_browser('page.html', '', '/report_result?600')
def test_sdl_image_compressed(self):
@@ -13062,13 +13070,16 @@ Press any key to continue.'''
basename = os.path.basename(image)
shutil.copyfile(image, os.path.join(self.get_dir(), basename))
- open(os.path.join(self.get_dir(), 'sdl_image.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_image.c')).read()).replace('screenshot.jpg', basename))
+ open(os.path.join(self.get_dir(), 'sdl_image.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_image.c')).read()))
self.build_native_lzma()
- Popen([PYTHON, EMCC, os.path.join(self.get_dir(), 'sdl_image.c'), '--preload-file', basename + '@/assets/' + basename, '-o', 'page.html',
- '--compression', '%s,%s,%s' % (path_from_root('third_party', 'lzma.js', 'lzma-native'),
- path_from_root('third_party', 'lzma.js', 'lzma-decoder.js'),
- 'LZMA.decompress')]).communicate()
+ Popen([
+ PYTHON, EMCC, os.path.join(self.get_dir(), 'sdl_image.c'), '-o', 'page.html',
+ '--preload-file', basename, '-DSCREENSHOT_DIRNAME="/"', '-DSCREENSHOT_BASENAME="' + basename + '"',
+ '--compression', '%s,%s,%s' % (path_from_root('third_party', 'lzma.js', 'lzma-native'),
+ path_from_root('third_party', 'lzma.js', 'lzma-decoder.js'),
+ 'LZMA.decompress')
+ ]).communicate()
shutil.move(os.path.join(self.get_dir(), basename), basename + '.renamedsoitcannotbefound');
self.run_browser('page.html', '', '/report_result?' + str(width))
diff --git a/tests/sdl_image.c b/tests/sdl_image.c
index 12588ff6..523f8903 100644
--- a/tests/sdl_image.c
+++ b/tests/sdl_image.c
@@ -29,11 +29,11 @@ int main() {
int result = 0;
- result |= testImage(screen, "/assets/screenshot.jpg"); // absolute path
+ result |= testImage(screen, SCREENSHOT_DIRNAME "/" SCREENSHOT_BASENAME); // absolute path
assert(result != 0);
- chdir("/assets");
- result = testImage(screen, "./screenshot.jpg"); // relative path
+ chdir(SCREENSHOT_DIRNAME);
+ result = testImage(screen, "./" SCREENSHOT_BASENAME); // relative path
assert(result != 0);
SDL_Flip(screen);
diff --git a/tests/sdl_image_jpeg.c b/tests/sdl_image_jpeg.c
deleted file mode 100644
index 10619dad..00000000
--- a/tests/sdl_image_jpeg.c
+++ /dev/null
@@ -1,45 +0,0 @@
-#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;
-}
-