Skip to content

Commit

Permalink
Update test_sdl_canvas
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sbc100 committed Feb 28, 2024
1 parent e25fa53 commit 5a532b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
19 changes: 9 additions & 10 deletions test/browser/test_sdl_canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,33 @@ int main(int argc, char **argv) {
SDL_Rect rect = { 200, 200, 175, 125 };
SDL_FillRect(screen, &rect, SDL_MapRGBA(screen->format, 0x22, 0x22, 0xff, 0xff));

SDL_Flip(screen);
SDL_Flip(screen);

SDL_LockSurface(screen);

int width, height;
emscripten_get_canvas_element_size("#canvas", &width, &height);

if (width != 600 && height != 450)
{
printf("error: wrong width/height\n");
abort();
}
assert(width == 600);
assert(height == 450);

int sum = 0;
int row_size = screen->w * 4;
// Sum the red components of each pixel on the diagonal.
for (int i = 0; i < screen->h; i++) {
sum += *((char*)screen->pixels + i*screen->w*4 + i*4 + 0);
sum += *((char*)screen->pixels + i*row_size + i*4 + 0);
}
printf("Sum: %d\n", sum);

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

SDL_UnlockSurface(screen);

SDL_Quit();

printf("done.\n");

assert(sum > 3000 && sum < 5000); // varies a little on different browsers, font differences?
// varies a little on different browsers, font differences?
assert(sum > 2000 && sum < 5000);

return 0;
}
Expand Down
14 changes: 7 additions & 7 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,13 +831,13 @@ def test_sdl_stb_image_cleanup(self):
shutil.copyfile(test_file('screenshot.jpg'), 'screenshot.not')
self.btest_exit('test_sdl_stb_image_cleanup.c', args=['-sSTB_IMAGE', '--preload-file', 'screenshot.not', '-lSDL', '-lGL', '--memoryprofiler'])

def test_sdl_canvas(self):
self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'])
# some extra coverage
self.clear()
self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-O0', '-sSAFE_HEAP', '-lSDL', '-lGL'])
self.clear()
self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-O2', '-sSAFE_HEAP', '-lSDL', '-lGL'])
@parameterized({
'': ([],),
'safe_heap': (['-sSAFE_HEAP'],),
'safe_heap_O2': (['-sSAFE_HEAP', '-O2'],),
})
def test_sdl_canvas(self, args):
self.btest_exit('test_sdl_canvas.c', args=['-sLEGACY_GL_EMULATION', '-lSDL', '-lGL'] + args)

def post_manual_reftest(self):
assert os.path.exists('reftest.js')
Expand Down

0 comments on commit 5a532b0

Please sign in to comment.