SDL: Added an automated test to verify clip rect functionality

From 141497b14f1697c37116c92d30ddb497c99be2b6 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 25 Feb 2024 09:44:41 -0800
Subject: [PATCH] Added an automated test to verify clip rect functionality

---
 test/testautomation_render.c | 63 +++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/test/testautomation_render.c b/test/testautomation_render.c
index daa459d9a34e..82ac1e3b2892 100644
--- a/test/testautomation_render.c
+++ b/test/testautomation_render.c
@@ -859,6 +859,63 @@ static int render_testViewport(void *arg)
     return TEST_COMPLETED;
 }
 
+/**
+ * Test clip rect
+ */
+static int render_testClipRect(void *arg)
+{
+    SDL_Surface *referenceSurface;
+    SDL_Rect cliprect;
+
+    cliprect.x = TESTRENDER_SCREEN_W / 3;
+    cliprect.y = TESTRENDER_SCREEN_H / 3;
+    cliprect.w = TESTRENDER_SCREEN_W / 2;
+    cliprect.h = TESTRENDER_SCREEN_H / 2;
+
+    /* Create expected result */
+    referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
+    CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
+    CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &cliprect, RENDER_COLOR_GREEN))
+
+    /* Clear surface. */
+    clearScreen();
+
+    /* Set the cliprect and do a fill operation */
+    CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect))
+    CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
+    CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
+    CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL))
+
+    /* Check to see if final image matches. */
+    compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
+
+    /*
+     * Verify that clear ignores the cliprect
+     */
+
+    /* Create expected result */
+    CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_GREEN))
+
+    /* Clear surface. */
+    clearScreen();
+
+    /* Set the cliprect and do a clear operation */
+    CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect))
+    CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
+    CHECK_FUNC(SDL_RenderClear, (renderer))
+    CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL))
+
+    /* Check to see if final image matches. */
+    compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
+
+    /* Make current */
+    SDL_RenderPresent(renderer);
+
+    SDL_DestroySurface(referenceSurface);
+
+    return TEST_COMPLETED;
+}
+
 /**
  * Test logical size
  */
@@ -1319,6 +1376,10 @@ static const SDLTest_TestCaseReference renderTest9 = {
 };
 
 static const SDLTest_TestCaseReference renderTest10 = {
+    (SDLTest_TestCaseFp)render_testClipRect, "render_testClipRect", "Tests clip rect", TEST_ENABLED
+};
+
+static const SDLTest_TestCaseReference renderTest11 = {
     (SDLTest_TestCaseFp)render_testLogicalSize, "render_testLogicalSize", "Tests logical size", TEST_ENABLED
 };
 
@@ -1326,7 +1387,7 @@ static const SDLTest_TestCaseReference renderTest10 = {
 static const SDLTest_TestCaseReference *renderTests[] = {
     &renderTest1, &renderTest2, &renderTest3, &renderTest4,
     &renderTest5, &renderTest6, &renderTest7, &renderTest8,
-    &renderTest9, &renderTest10, NULL
+    &renderTest9, &renderTest10, &renderTest11, NULL
 };
 
 /* Render test suite (global) */