Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test_sdl_canvas. NFC #21453

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading