From 8436ce98b4a32336506e909520db9f16b6fb0f72 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sat, 15 Mar 2025 20:01:51 +0100
Subject: [PATCH] tests: port failing SDL_Renderer test from pysdl2 to
testautomation
---
test/testautomation_render.c | 96 +++++++++++++++++++++++++++++++++++-
1 file changed, 95 insertions(+), 1 deletion(-)
diff --git a/test/testautomation_render.c b/test/testautomation_render.c
index 835ac9b950292..62e62f17e59a6 100644
--- a/test/testautomation_render.c
+++ b/test/testautomation_render.c
@@ -811,6 +811,96 @@ int render_testBlitBlend(void *arg)
return TEST_COMPLETED;
}
+static Uint32 read_surface_pixel32(SDL_Surface *surface, int x, int y) {
+ Uint32 result;
+
+ if (x >= surface->w || y >= surface->h) {
+ SDLTest_AssertCheck(x < surface->w, "x (%d) < surface->w (%d)", x, surface->w);
+ SDLTest_AssertCheck(y < surface->h, "y (%d) < surface->h (%d)", y, surface->h);
+ result = 0xdeadbabe;
+ } else {
+ SDL_memcpy(&result, (Uint8 *)surface->pixels + surface->pitch * y + surface->format->BytesPerPixel * x, sizeof(Uint32));
+ }
+ return result;
+}
+
+static int render_testRGBSurfaceNoAlpha(void* arg)
+{
+ SDL_Surface *surface;
+ SDL_Renderer *software_renderer;
+ SDL_Surface *surface2;
+ SDL_Texture *texture2;
+ int result;
+ SDL_Rect dest_rect;
+ SDL_Point point;
+ Uint32 pixel;
+
+ SDLTest_AssertPass("About to call SDL_CreateRGBSurface(0, 128, 128, 32, 0xff0000, 0xff00, 0xff, 0)");
+ surface = SDL_CreateRGBSurface(0, 128, 128, 32, 0xff0000, 0xff00, 0xff, 0);
+ SDLTest_AssertCheck(surface != NULL, "Returned surface must be not NULL");
+
+ SDLTest_AssertCheck(surface->format->BitsPerPixel == 32, "surface->format->BitsPerPixel should be 32, actual value is %d", surface->format->BitsPerPixel);
+ SDLTest_AssertCheck(surface->format->BytesPerPixel == 4, "surface->format->BytesPerPixels should be 4, actual value is %d", surface->format->BytesPerPixel);
+
+ SDLTest_AssertPass("About to call SDL_CreateSoftwareRenderer(surface)");
+ software_renderer = SDL_CreateSoftwareRenderer(surface);
+ SDLTest_AssertCheck(software_renderer != NULL, "Returned renderer must be not NULL");
+
+ SDLTest_AssertPass("About to call SDL_CreateRGBSurface(0, 16, 16, 32, 0xff0000, 0xff00, 0xff, 0)");
+ surface2 = SDL_CreateRGBSurface(0, 16, 16, 32, 0xff0000, 0xff00, 0xff, 0);
+ SDLTest_AssertCheck(surface2 != NULL, "Returned surface must be not NULL");
+
+ SDLTest_AssertPass("About to call SDL_FillRect(surface2, NULL, 0)");
+ result = SDL_FillRect(surface2, NULL, SDL_MapRGB(surface2->format, 0, 0, 0));
+ SDLTest_AssertCheck(result == 0, "Result should be 0, actual value is %d", result);
+
+ SDLTest_AssertPass("About to call SDL_CreateTextureFromSurface(software_renderer, surface2)");
+ texture2 = SDL_CreateTextureFromSurface(software_renderer, surface2);
+ SDLTest_AssertCheck(texture2 != NULL, "Returned texture is not NULL");
+
+ SDLTest_AssertPass("About to call SDL_SetRenderDrawColor(renderer, 0xaa, 0xbb, 0xcc, 0x0)");
+ result = SDL_SetRenderDrawColor(software_renderer, 0xaa, 0xbb, 0xcc, 0x0);
+
+ SDLTest_AssertPass("About to call SDL_RenderClear(renderer)");
+ result = SDL_RenderClear(software_renderer);
+ SDLTest_AssertCheck(result == 0, "Result should be 0, actual value is %d", result);
+
+ SDLTest_AssertPass("About to call SDL_SetRenderDrawColor(renderer, 0x0, 0x0, 0x0, 0x0)");
+ result = SDL_SetRenderDrawColor(software_renderer, 0x0, 0x0, 0x0, 0x0);
+ SDLTest_AssertCheck(result == 0, "Result should be 0, actual value is %d", result);
+
+ dest_rect.x = 32;
+ dest_rect.y = 32;
+ dest_rect.w = surface2->w;
+ dest_rect.h = surface2->h;
+ point.x = 0;
+ point.y = 0;
+ SDLTest_AssertPass("About to call SDL_RenderCopy(software_renderer, texture, NULL, &{%d, %d, %d, %d})",
+ dest_rect.x, dest_rect.h, dest_rect.w, dest_rect.h);
+ result = SDL_RenderCopyEx(software_renderer, texture2, NULL, &dest_rect, 180, &point, SDL_FLIP_NONE);
+ SDLTest_AssertCheck(result == 0, "Result should be 0, actual value is %d", result);
+
+ SDLTest_AssertPass("About to call SDL_RenderPresent(software_renderer)");
+ SDL_RenderPresent(software_renderer);
+
+ pixel = read_surface_pixel32(surface, 0, 0);
+ SDLTest_AssertCheck(pixel == 0xAABBCCu, "Pixel at (0, 0) should be 0x%08x, actual value is 0x%08" SDL_PRIx32, 0xAABBCCu, pixel);
+ pixel = read_surface_pixel32(surface, 15, 15);
+ SDLTest_AssertCheck(pixel == 0xAABBCCu, "Pixel at (15, 15) should be 0x%08x, actual value is 0x%08" SDL_PRIx32, 0xAABBCCu, pixel);
+ pixel = read_surface_pixel32(surface, 16, 16);
+ SDLTest_AssertCheck(pixel == 0xFF000000u, "Pixel at (16, 16) should be 0x%08x, actual value is 0x%08" SDL_PRIx32, 0xFF000000u, pixel);
+ pixel = read_surface_pixel32(surface, 31, 31);
+ SDLTest_AssertCheck(pixel == 0xFF000000u, "Pixel at (31, 31) should be 0x%08x, actual value is 0x%08" SDL_PRIx32, 0xFF000000u, pixel);
+ pixel = read_surface_pixel32(surface, 32, 32);
+ SDLTest_AssertCheck(pixel == 0xAABBCCu, "Pixel at (32, 32) should be 0x%08x, actual value is 0x%08" SDL_PRIx32, 0xAABBCCu, pixel);
+
+ SDL_DestroyTexture(texture2);
+ SDL_FreeSurface(surface2);
+ SDL_DestroyRenderer(software_renderer);
+ SDL_FreeSurface(surface);
+ return TEST_COMPLETED;
+}
+
/**
* @brief Tests setting and getting texture scale mode.
*
@@ -1205,9 +1295,13 @@ static const SDLTest_TestCaseReference renderTest8 = {
(SDLTest_TestCaseFp)render_testGetSetTextureScaleMode, "render_testGetSetTextureScaleMode", "Tests setting/getting texture scale mode", TEST_ENABLED
};
+static const SDLTest_TestCaseReference renderTest9 = {
+ (SDLTest_TestCaseFp)render_testRGBSurfaceNoAlpha, "render_testRGBSurfaceNoAlpha", "Tests RGB surface with no alpha using software renderer", TEST_ENABLED
+};
+
/* Sequence of Render test cases */
static const SDLTest_TestCaseReference *renderTests[] = {
- &renderTest1, &renderTest2, &renderTest3, &renderTest4, &renderTest5, &renderTest6, &renderTest7, &renderTest8, NULL
+ &renderTest1, &renderTest2, &renderTest3, &renderTest4, &renderTest5, &renderTest6, &renderTest7, &renderTest8, &renderTest9, NULL
};
/* Render test suite (global) */