tests: port failing SDL_Hint tests from pysdl2 to testautomation

(cherry picked from commit 177fb9cb6c)
This commit is contained in:
Anonymous Maarten
2025-03-14 00:43:32 +01:00
committed by Anonymous Maarten
parent 366a5281b9
commit 39eed1d233

View File

@@ -69,9 +69,19 @@ static int SDLCALL hints_getHint(void *arg)
return TEST_COMPLETED;
}
typedef struct {
char *name;
char *value;
char *oldValue;
} HintCallbackContext;
static void SDLCALL hints_testHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
*(char **)userdata = hint ? SDL_strdup(hint) : NULL;
HintCallbackContext *context = userdata;
context->name = name ? SDL_strdup(name) : NULL;
context->value = hint ? SDL_strdup(hint) : NULL;
context->oldValue = oldValue ? SDL_strdup(oldValue) : NULL;
}
/**
@@ -83,7 +93,7 @@ static int SDLCALL hints_setHint(void *arg)
const char *originalValue;
char *value;
const char *testValue;
char *callbackValue;
HintCallbackContext callback_data;
bool result;
int i, j;
@@ -133,8 +143,10 @@ static int SDLCALL hints_setHint(void *arg)
SDLTest_AssertPass("Call to SDL_GetHint() after saving and restoring hint");
originalValue = SDL_GetHint(testHint);
value = (originalValue == NULL) ? NULL : SDL_strdup(originalValue);
SDL_SetHint(testHint, "temp");
SDL_SetHint(testHint, value);
result = SDL_SetHint(testHint, "temp");
SDLTest_AssertCheck(!result, "SDL_SetHint(\"%s\", \"temp\") should return false", testHint);
result = SDL_SetHint(testHint, value);
SDLTest_AssertCheck(!result, "SDL_SetHint(\"%s\", \"%s\" should return false", testHint, value);
SDL_free(value);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
@@ -143,7 +155,8 @@ static int SDLCALL hints_setHint(void *arg)
testValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_DEFAULT)");
SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_DEFAULT);
result = SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_DEFAULT);
SDLTest_AssertCheck(!result, "SDL_SetHintWithPriority(\"%s\", NULL, SDL_HINT_DEFAULT) should return false", testHint);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "original") == 0,
@@ -151,7 +164,8 @@ static int SDLCALL hints_setHint(void *arg)
testValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE)");
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
result = SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
SDLTest_AssertCheck(result, "SDL_SetHintWithPriority(\"%s\", \"temp\", SDL_HINT_OVERRIDE) should return true", testHint);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue && SDL_strcmp(testValue, "temp") == 0,
@@ -159,7 +173,8 @@ static int SDLCALL hints_setHint(void *arg)
testValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_OVERRIDE)");
SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_OVERRIDE);
result = SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_OVERRIDE);
SDLTest_AssertCheck(result, "SDL_SetHintWithPriority(\"%s\", NULL, SDL_HINT_OVERRIDE) should return true", testHint);
testValue = SDL_GetHint(testHint);
SDLTest_AssertCheck(
testValue == NULL,
@@ -175,50 +190,83 @@ static int SDLCALL hints_setHint(void *arg)
testValue);
/* Make sure callback functionality works past a reset */
SDL_zero(callback_data);
SDLTest_AssertPass("Call to SDL_AddHintCallback()");
callbackValue = NULL;
SDL_AddHintCallback(testHint, hints_testHintChanged, &callbackValue);
SDL_AddHintCallback(testHint, hints_testHintChanged, &callback_data);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
"callbackValue = %s, expected \"original\"",
callbackValue);
SDL_free(callbackValue);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback");
callbackValue = NULL;
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
callback_data.name && SDL_strcmp(callback_data.name, testHint) == 0,
"callback_data.name = \"%s\", expected \"%s\"",
callback_data.name, testHint);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
"callbackValue = %s, expected \"temp\"",
callbackValue);
SDL_free(callbackValue);
callback_data.value && SDL_strcmp(callback_data.value, "original") == 0,
"callback_data.value = \"%s\", expected \"%s\"",
callback_data.value, "original");
SDL_free(callback_data.name);
SDL_free(callback_data.value);
SDL_free(callback_data.oldValue);
SDL_zero(callback_data);
SDLTest_AssertPass("Call to SDL_ResetHint(), using callback");
callbackValue = NULL;
SDL_ResetHint(testHint);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
callback_data.value && SDL_strcmp(callback_data.value, "original") == 0,
"callbackValue = %s, expected \"original\"",
callbackValue);
SDL_free(callbackValue);
callback_data.value);
SDL_free(callback_data.name);
SDL_free(callback_data.value);
SDL_free(callback_data.oldValue);
SDL_zero(callback_data);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback after reset");
callbackValue = NULL;
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
result = SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
SDLTest_AssertCheck(result, "SDL_SetHintWithPriority(\"%s\", \"temp\", SDL_HINT_OVERRIDE) should return true", testHint);
SDLTest_AssertCheck(
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
callback_data.value && SDL_strcmp(callback_data.value, "temp") == 0,
"callbackValue = %s, expected \"temp\"",
callbackValue);
SDL_free(callbackValue);
callback_data.value);
SDL_free(callback_data.name);
SDL_free(callback_data.value);
SDL_free(callback_data.oldValue);
SDL_zero(callback_data);
SDLTest_AssertPass("Call to SDL_ResetHint(), after clearing callback");
callbackValue = NULL;
SDL_RemoveHintCallback(testHint, hints_testHintChanged, &callbackValue);
SDL_RemoveHintCallback(testHint, hints_testHintChanged, &callback_data);
SDL_ResetHint(testHint);
SDLTest_AssertCheck(
callbackValue == NULL,
!callback_data.value,
"callbackValue = %s, expected \"(null)\"",
callbackValue);
callback_data.value);
SDL_free(callback_data.name);
SDL_free(callback_data.value);
SDL_free(callback_data.oldValue);
SDL_zero(callback_data);
/* Make sure callback functionality work with hint renamed in sdl3 */
SDLTest_AssertPass("Call to SDL_AddHintCallback()");
SDL_AddHintCallback(SDL_HINT_WINDOW_ALLOW_TOPMOST, hints_testHintChanged, &callback_data);
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback");
SDLTest_AssertCheck(callback_data.name && SDL_strcmp(callback_data.name, SDL_HINT_WINDOW_ALLOW_TOPMOST) == 0, "callback was called with name \"%s\" (expected \"%s\")", callback_data.name, SDL_HINT_WINDOW_ALLOW_TOPMOST);
SDLTest_AssertCheck(!callback_data.value, "callback was called with null value, was %s", callback_data.value);
SDLTest_AssertCheck(!callback_data.oldValue, "callback was called with null oldvalue, was %s", callback_data.oldValue);
SDL_free(callback_data.name);
SDL_free(callback_data.value);
SDL_free(callback_data.oldValue);
SDL_zero(callback_data);
result = SDL_SetHintWithPriority(SDL_HINT_WINDOW_ALLOW_TOPMOST, "temp", SDL_HINT_OVERRIDE);
SDLTest_AssertCheck(result, "SDL_SetHintWithPriority(\"%s\", \"temp\", SDL_HINT_OVERRIDE) should return true", testHint);
SDLTest_AssertCheck(
callback_data.name && SDL_strcmp(callback_data.name, SDL_HINT_WINDOW_ALLOW_TOPMOST) == 0,
"callback_data.name = \"%s\", expected \"%s\"",
callback_data.name, SDL_HINT_WINDOW_ALLOW_TOPMOST);
SDLTest_AssertCheck(
callback_data.value && SDL_strcmp(callback_data.value, "temp") == 0,
"callback_data.value = \"%s\", expected \"%s\"",
callback_data.value, "temp");
SDL_free(callback_data.name);
SDL_free(callback_data.value);
SDL_free(callback_data.oldValue);
SDL_zero(callback_data);
SDL_ResetHint(testHint);
return TEST_COMPLETED;
}
@@ -226,17 +274,19 @@ static int SDLCALL hints_setHint(void *arg)
/* ================= Test References ================== */
/* Hints test cases */
static const SDLTest_TestCaseReference hintsTest1 = {
static const SDLTest_TestCaseReference hintsGetHint = {
hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED
};
static const SDLTest_TestCaseReference hintsTest2 = {
static const SDLTest_TestCaseReference hintsSetHint = {
hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED
};
/* Sequence of Hints test cases */
static const SDLTest_TestCaseReference *hintsTests[] = {
&hintsTest1, &hintsTest2, NULL
&hintsGetHint,
&hintsSetHint,
NULL
};
/* Hints test suite (global) */