Sfoglia il codice sorgente

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()
Sam Lantinga 2 settimane fa
parent
commit
a5b070ba2d
1 ha cambiato i file con 14 aggiunte e 7 eliminazioni
  1. 14 7
      test/testautomation_render.c

+ 14 - 7
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. */