From 2f4b2df595904bfb9c931cbc287ddbdc51a9bc04 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sun, 1 Sep 2024 17:51:04 +0200
Subject: [PATCH] SDL_test: pass data pointer to unit tests
---
include/SDL3/SDL_test_harness.h | 2 +-
src/test/SDL_test_harness.c | 7 ++++---
test/testautomation_audio.c | 2 +-
test/testautomation_blit.c | 2 +-
test/testautomation_iostream.c | 2 +-
test/testautomation_render.c | 2 +-
test/testautomation_subsystems.c | 2 +-
test/testautomation_surface.c | 2 +-
test/testautomation_timer.c | 2 +-
9 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/include/SDL3/SDL_test_harness.h b/include/SDL3/SDL_test_harness.h
index 3023889049623..54dc2dc829fdd 100644
--- a/include/SDL3/SDL_test_harness.h
+++ b/include/SDL3/SDL_test_harness.h
@@ -63,7 +63,7 @@ extern "C" {
#define TEST_RESULT_SETUP_FAILURE 4
/* !< Function pointer to a test case setup function (run before every test) */
-typedef void (*SDLTest_TestCaseSetUpFp)(void *arg);
+typedef void (*SDLTest_TestCaseSetUpFp)(void **arg);
/* !< Function pointer to a test case function */
typedef int (*SDLTest_TestCaseFp)(void *arg);
diff --git a/src/test/SDL_test_harness.c b/src/test/SDL_test_harness.c
index 1347bbf547026..f1fc68f921636 100644
--- a/src/test/SDL_test_harness.c
+++ b/src/test/SDL_test_harness.c
@@ -237,6 +237,7 @@ static int SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_
int testCaseResult = 0;
int testResult = 0;
int fuzzerCount;
+ void *data = NULL;
if (!testSuite || !testCase || !testSuite->name || !testCase->name) {
SDLTest_LogError("Setup failure: testSuite or testCase references NULL");
@@ -259,7 +260,7 @@ static int SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_
/* Maybe run suite initializer function */
if (testSuite->testSetUp) {
- testSuite->testSetUp(0x0);
+ testSuite->testSetUp(&data);
if (SDLTest_AssertSummaryToTestResult() == TEST_RESULT_FAILED) {
SDLTest_LogError(SDLTEST_FINAL_RESULT_FORMAT, "Suite Setup", testSuite->name, COLOR_RED "Failed" COLOR_END);
return TEST_RESULT_SETUP_FAILURE;
@@ -267,7 +268,7 @@ static int SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_
}
/* Run test case function */
- testCaseResult = testCase->testCase(0x0);
+ testCaseResult = testCase->testCase(data);
/* Convert test execution result into harness result */
if (testCaseResult == TEST_SKIPPED) {
@@ -286,7 +287,7 @@ static int SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, const SDLTest_
/* Maybe run suite cleanup function (ignore failed asserts) */
if (testSuite->testTearDown) {
- testSuite->testTearDown(0x0);
+ testSuite->testTearDown(data);
}
/* Cancel timeout timer */
diff --git a/test/testautomation_audio.c b/test/testautomation_audio.c
index 5eed89d9b15f4..10c3a748a63b8 100644
--- a/test/testautomation_audio.c
+++ b/test/testautomation_audio.c
@@ -19,7 +19,7 @@
/* Fixture */
-static void audioSetUp(void *arg)
+static void audioSetUp(void **arg)
{
/* Start SDL audio subsystem */
SDL_bool ret = SDL_InitSubSystem(SDL_INIT_AUDIO);
diff --git a/test/testautomation_blit.c b/test/testautomation_blit.c
index 76515f45d5b81..ff41a95659dda 100644
--- a/test/testautomation_blit.c
+++ b/test/testautomation_blit.c
@@ -40,7 +40,7 @@ Uint32 getRandomUint32() {
/*
* Resets PRNG state to initialize tests using PRNG
*/
-void blitSetUp(void *arg) {
+void blitSetUp(void **arg) {
rngState[0] = 1;
rngState[1] = 2;
}
diff --git a/test/testautomation_iostream.c b/test/testautomation_iostream.c
index 1ba45ced2cbe5..782d643b046e8 100644
--- a/test/testautomation_iostream.c
+++ b/test/testautomation_iostream.c
@@ -32,7 +32,7 @@ static const char IOStreamAlphabetString[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/* Fixture */
-static void IOStreamSetUp(void *arg)
+static void IOStreamSetUp(void **arg)
{
size_t fileLen;
FILE *handle;
diff --git a/test/testautomation_render.c b/test/testautomation_render.c
index 1c823a185a304..b9ae089cb95e6 100644
--- a/test/testautomation_render.c
+++ b/test/testautomation_render.c
@@ -44,7 +44,7 @@ static SDL_bool hasDrawColor(void);
/**
* Create software renderer for tests
*/
-static void InitCreateRenderer(void *arg)
+static void InitCreateRenderer(void **arg)
{
int width = 320, height = 240;
const char *renderer_name = NULL;
diff --git a/test/testautomation_subsystems.c b/test/testautomation_subsystems.c
index 626c202e043b2..ab92bcaa8b973 100644
--- a/test/testautomation_subsystems.c
+++ b/test/testautomation_subsystems.c
@@ -9,7 +9,7 @@
/* Fixture */
-static void subsystemsSetUp(void *arg)
+static void subsystemsSetUp(void **arg)
{
/* Reset each one of the SDL subsystems */
/* CHECKME: can we use SDL_Quit here, or this will break the flow of tests? */
diff --git a/test/testautomation_surface.c b/test/testautomation_surface.c
index 4e5334daf3adf..c0b49d88ab8bd 100644
--- a/test/testautomation_surface.c
+++ b/test/testautomation_surface.c
@@ -41,7 +41,7 @@ static SDL_Surface *testSurface = NULL;
/* Fixture */
/* Create a 32-bit writable surface for blitting tests */
-static void surfaceSetUp(void *arg)
+static void surfaceSetUp(void **arg)
{
int result;
SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
diff --git a/test/testautomation_timer.c b/test/testautomation_timer.c
index d04979efad0da..f8dc7138e5c61 100644
--- a/test/testautomation_timer.c
+++ b/test/testautomation_timer.c
@@ -20,7 +20,7 @@ static int g_timerCallbackCalled = 0;
/* Fixture */
-static void timerSetUp(void *arg)
+static void timerSetUp(void **arg)
{
/* Start SDL timer subsystem */
SDL_bool ret = SDL_InitSubSystem(SDL_INIT_TIMER);