Skip to content

Commit bb006fa

Browse files
committed
Update test_sdl_canvas
When I run this test locally in firefox I was getting 2785 as the sum value. I believe this is because the test includes SDL1 font rendering which can depend on the system fonts you have installed.
1 parent 1b3950d commit bb006fa

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

test/browser/test_sdl_canvas.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,33 @@ int main(int argc, char **argv) {
5050
SDL_Rect rect = { 200, 200, 175, 125 };
5151
SDL_FillRect(screen, &rect, SDL_MapRGBA(screen->format, 0x22, 0x22, 0xff, 0xff));
5252

53-
SDL_Flip(screen);
53+
SDL_Flip(screen);
5454

5555
SDL_LockSurface(screen);
5656

5757
int width, height;
5858
emscripten_get_canvas_element_size("#canvas", &width, &height);
59-
60-
if (width != 600 && height != 450)
61-
{
62-
printf("error: wrong width/height\n");
63-
abort();
64-
}
59+
assert(width == 600);
60+
assert(height == 450);
6561

6662
int sum = 0;
63+
int row_size = screen->w * 4;
64+
// Sum the red componenets of each pixel on the diagonal.
6765
for (int i = 0; i < screen->h; i++) {
68-
sum += *((char*)screen->pixels + i*screen->w*4 + i*4 + 0);
66+
sum += *((char*)screen->pixels + i*row_size + i*4 + 0);
6967
}
7068
printf("Sum: %d\n", sum);
7169

7270
printf("you should see two lines of text in different colors and a blue rectangle\n");
7371

7472
SDL_UnlockSurface(screen);
75-
73+
7674
SDL_Quit();
7775

7876
printf("done.\n");
7977

80-
assert(sum > 3000 && sum < 5000); // varies a little on different browsers, font differences?
78+
// varies a little on different browsers, font differences?
79+
assert(sum > 2000 && sum < 5000);
8180

8281
return 0;
8382
}

test/test_browser.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -838,13 +838,13 @@ def test_sdl_stb_image_cleanup(self):
838838
shutil.copyfile(test_file('screenshot.jpg'), 'screenshot.not')
839839
self.btest_exit('test_sdl_stb_image_cleanup.c', args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL', '--memoryprofiler'])
840840

841-
def test_sdl_canvas(self):
842-
self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'])
843-
# some extra coverage
844-
self.clear()
845-
self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-O0', '-sSAFE_HEAP', '-lSDL', '-lGL'])
846-
self.clear()
847-
self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-O2', '-sSAFE_HEAP', '-lSDL', '-lGL'])
841+
@parameterized({
842+
'': ([],),
843+
'_safe_heap': (['-sSAFE_HEAP'],),
844+
'_safe_heap_O2': (['-sSAFE_HEAP', '-O2'],),
845+
})
846+
def test_sdl_canvas(self, args):
847+
self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args)
848848

849849
def post_manual_reftest(self):
850850
assert os.path.exists('reftest.js')

0 commit comments

Comments
 (0)