From a5b070ba2d91147aab9103b7b050aa02d4250a29 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 21 Sep 2025 20:25:10 -0700 Subject: [PATCH] Skip render_testLogicalSize() if we didn't get a window of the expected size We rely on that to validate the results of SDL_GetRenderLogicalPresentationRect() --- test/testautomation_render.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/test/testautomation_render.c b/test/testautomation_render.c index a35ce9b8e3..2ea88c7d45 100644 --- a/test/testautomation_render.c +++ b/test/testautomation_render.c @@ -9,6 +9,8 @@ /* ================= Test Case Implementation ================== */ +#define TESTRENDER_WINDOW_W 320 +#define TESTRENDER_WINDOW_H 240 #define TESTRENDER_SCREEN_W 80 #define TESTRENDER_SCREEN_H 60 @@ -46,10 +48,9 @@ static bool hasDrawColor(void); */ static void SDLCALL InitCreateRenderer(void **arg) { - int width = 320, height = 240; const char *renderer_name = NULL; renderer = NULL; - window = SDL_CreateWindow("render_testCreateRenderer", width, height, 0); + window = SDL_CreateWindow("render_testCreateRenderer", TESTRENDER_WINDOW_W, TESTRENDER_WINDOW_H, 0); SDLTest_AssertPass("SDL_CreateWindow()"); SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result"); if (window == NULL) { @@ -1395,12 +1396,18 @@ static int SDLCALL render_testLogicalSize(void *arg) SDL_Surface *referenceSurface; SDL_Rect viewport; SDL_FRect rect; - int w, h; + int w = 0, h = 0; int set_w, set_h; SDL_RendererLogicalPresentation set_presentation_mode; SDL_FRect set_rect; const int factor = 2; + SDL_GetWindowSize(window, &w, &h); + if (w != TESTRENDER_WINDOW_W || h != TESTRENDER_WINDOW_H) { + SDLTest_Log("Skipping test render_testLogicalSize: expected window %dx%d, got %dx%d", TESTRENDER_WINDOW_W, TESTRENDER_WINDOW_H, w, h); + return TEST_SKIPPED; + } + viewport.x = ((TESTRENDER_SCREEN_W / 4) / factor) * factor; viewport.y = ((TESTRENDER_SCREEN_H / 4) / factor) * factor; viewport.w = ((TESTRENDER_SCREEN_W / 2) / factor) * factor; @@ -1427,8 +1434,8 @@ static int SDLCALL render_testLogicalSize(void *arg) SDLTest_AssertCheck( set_rect.x == 0.0f && set_rect.y == 0.0f && - set_rect.w == 320.0f && - set_rect.h == 240.0f, + set_rect.w == (float)w && + set_rect.h == (float)h, "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h); CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE)) rect.x = (float)viewport.x / factor; @@ -1447,8 +1454,8 @@ static int SDLCALL render_testLogicalSize(void *arg) SDLTest_AssertCheck( set_rect.x == 0.0f && set_rect.y == 0.0f && - set_rect.w == 320.0f && - set_rect.h == 240.0f, + set_rect.w == (float)w && + set_rect.h == (float)h, "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h); /* Check to see if final image matches. */