SDL: Make main_testSetError test more verbose

From c66a09ce2642bb018194d42bb94de1f324fe5ceb Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Fri, 21 Jun 2024 15:43:19 +0200
Subject: [PATCH] Make main_testSetError test more verbose

---
 test/testautomation_main.c | 37 ++++++++++++++++++++++++++-----------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/test/testautomation_main.c b/test/testautomation_main.c
index 01276ac3f80d7..99d39478d3acd 100644
--- a/test/testautomation_main.c
+++ b/test/testautomation_main.c
@@ -93,18 +93,33 @@ static int
 main_testSetError(void *arg)
 {
     size_t i;
-    char error[1024];
-
-    error[0] = '\0';
-    SDL_SetError("");
-    SDLTest_AssertCheck(SDL_strcmp(error, SDL_GetError()) == 0, "SDL_SetError(\"\")");
-
-    for (i = 0; i < (sizeof(error) - 1); ++i) {
-        error[i] = 'a' + (i % 26);
+    char error_input[1024];
+    int result;
+    const char *error;
+
+    SDLTest_AssertPass("SDL_SetError(NULL)");
+    result = SDL_SetError(NULL);
+    SDLTest_AssertCheck(result == -1, "SDL_SetError(NULL) -> %d (expected %d)", result, -1);
+    error = SDL_GetError();
+    SDLTest_AssertCheck(SDL_strcmp(error, "") == 0, "SDL_GetError() -> \"%s\" (expected \"%s\")", error, "");
+
+    SDLTest_AssertPass("SDL_SetError(\"\")");
+    result = SDL_SetError("");
+    SDLTest_AssertCheck(result == -1, "SDL_SetError(\"\") -> %d (expected %d)", result, -1);
+    error = SDL_GetError();
+    SDLTest_AssertCheck(SDL_strcmp(error, "") == 0, "SDL_GetError() -> \"%s\" (expected \"%s\")", error, "");
+
+    error_input[0] = '\0';
+    for (i = 0; i < (sizeof(error_input) - 1); ++i) {
+        error_input[i] = 'a' + (i % 26);
     }
-    error[i] = '\0';
-    SDL_SetError("%s", error);
-    SDLTest_AssertCheck(SDL_strcmp(error, SDL_GetError()) == 0, "SDL_SetError(\"abc...1023\")");
+    error_input[i] = '\0';
+    SDLTest_AssertPass("SDL_SetError(\"abc...\")");
+    result = SDL_SetError("%s", error_input);
+    SDLTest_AssertCheck(result == -1, "SDL_SetError(\"abc...\") -> %d (expected %d)", result, -1);
+    error = SDL_GetError();
+    SDLTest_AssertPass("Verify SDL error is identical to the input error");
+    SDLTest_CompareMemory(error, SDL_strlen(error), error_input, SDL_strlen(error_input));
 
     return TEST_COMPLETED;
 }