mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-03-20 15:51:07 +01:00
tests: port failing SDL_Hint tests from pysdl2 to testautomation
(cherry picked from commit 177fb9cb6c)
This commit is contained in:
committed by
Anonymous Maarten
parent
366a5281b9
commit
39eed1d233
@@ -69,9 +69,19 @@ static int SDLCALL hints_getHint(void *arg)
|
|||||||
return TEST_COMPLETED;
|
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)
|
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;
|
const char *originalValue;
|
||||||
char *value;
|
char *value;
|
||||||
const char *testValue;
|
const char *testValue;
|
||||||
char *callbackValue;
|
HintCallbackContext callback_data;
|
||||||
bool result;
|
bool result;
|
||||||
int i, j;
|
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");
|
SDLTest_AssertPass("Call to SDL_GetHint() after saving and restoring hint");
|
||||||
originalValue = SDL_GetHint(testHint);
|
originalValue = SDL_GetHint(testHint);
|
||||||
value = (originalValue == NULL) ? NULL : SDL_strdup(originalValue);
|
value = (originalValue == NULL) ? NULL : SDL_strdup(originalValue);
|
||||||
SDL_SetHint(testHint, "temp");
|
result = SDL_SetHint(testHint, "temp");
|
||||||
SDL_SetHint(testHint, value);
|
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);
|
SDL_free(value);
|
||||||
testValue = SDL_GetHint(testHint);
|
testValue = SDL_GetHint(testHint);
|
||||||
SDLTest_AssertCheck(
|
SDLTest_AssertCheck(
|
||||||
@@ -143,7 +155,8 @@ static int SDLCALL hints_setHint(void *arg)
|
|||||||
testValue);
|
testValue);
|
||||||
|
|
||||||
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_DEFAULT)");
|
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);
|
testValue = SDL_GetHint(testHint);
|
||||||
SDLTest_AssertCheck(
|
SDLTest_AssertCheck(
|
||||||
testValue && SDL_strcmp(testValue, "original") == 0,
|
testValue && SDL_strcmp(testValue, "original") == 0,
|
||||||
@@ -151,7 +164,8 @@ static int SDLCALL hints_setHint(void *arg)
|
|||||||
testValue);
|
testValue);
|
||||||
|
|
||||||
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE)");
|
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);
|
testValue = SDL_GetHint(testHint);
|
||||||
SDLTest_AssertCheck(
|
SDLTest_AssertCheck(
|
||||||
testValue && SDL_strcmp(testValue, "temp") == 0,
|
testValue && SDL_strcmp(testValue, "temp") == 0,
|
||||||
@@ -159,7 +173,8 @@ static int SDLCALL hints_setHint(void *arg)
|
|||||||
testValue);
|
testValue);
|
||||||
|
|
||||||
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_OVERRIDE)");
|
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);
|
testValue = SDL_GetHint(testHint);
|
||||||
SDLTest_AssertCheck(
|
SDLTest_AssertCheck(
|
||||||
testValue == NULL,
|
testValue == NULL,
|
||||||
@@ -175,50 +190,83 @@ static int SDLCALL hints_setHint(void *arg)
|
|||||||
testValue);
|
testValue);
|
||||||
|
|
||||||
/* Make sure callback functionality works past a reset */
|
/* Make sure callback functionality works past a reset */
|
||||||
|
SDL_zero(callback_data);
|
||||||
SDLTest_AssertPass("Call to SDL_AddHintCallback()");
|
SDLTest_AssertPass("Call to SDL_AddHintCallback()");
|
||||||
callbackValue = NULL;
|
SDL_AddHintCallback(testHint, hints_testHintChanged, &callback_data);
|
||||||
SDL_AddHintCallback(testHint, hints_testHintChanged, &callbackValue);
|
|
||||||
SDLTest_AssertCheck(
|
SDLTest_AssertCheck(
|
||||||
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
|
callback_data.name && SDL_strcmp(callback_data.name, testHint) == 0,
|
||||||
"callbackValue = %s, expected \"original\"",
|
"callback_data.name = \"%s\", expected \"%s\"",
|
||||||
callbackValue);
|
callback_data.name, testHint);
|
||||||
SDL_free(callbackValue);
|
|
||||||
|
|
||||||
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback");
|
|
||||||
callbackValue = NULL;
|
|
||||||
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
|
|
||||||
SDLTest_AssertCheck(
|
SDLTest_AssertCheck(
|
||||||
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
|
callback_data.value && SDL_strcmp(callback_data.value, "original") == 0,
|
||||||
"callbackValue = %s, expected \"temp\"",
|
"callback_data.value = \"%s\", expected \"%s\"",
|
||||||
callbackValue);
|
callback_data.value, "original");
|
||||||
SDL_free(callbackValue);
|
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");
|
SDLTest_AssertPass("Call to SDL_ResetHint(), using callback");
|
||||||
callbackValue = NULL;
|
|
||||||
SDL_ResetHint(testHint);
|
SDL_ResetHint(testHint);
|
||||||
SDLTest_AssertCheck(
|
SDLTest_AssertCheck(
|
||||||
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
|
callback_data.value && SDL_strcmp(callback_data.value, "original") == 0,
|
||||||
"callbackValue = %s, expected \"original\"",
|
"callbackValue = %s, expected \"original\"",
|
||||||
callbackValue);
|
callback_data.value);
|
||||||
SDL_free(callbackValue);
|
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");
|
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback after reset");
|
||||||
callbackValue = NULL;
|
result = SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
|
||||||
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
|
SDLTest_AssertCheck(result, "SDL_SetHintWithPriority(\"%s\", \"temp\", SDL_HINT_OVERRIDE) should return true", testHint);
|
||||||
SDLTest_AssertCheck(
|
SDLTest_AssertCheck(
|
||||||
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
|
callback_data.value && SDL_strcmp(callback_data.value, "temp") == 0,
|
||||||
"callbackValue = %s, expected \"temp\"",
|
"callbackValue = %s, expected \"temp\"",
|
||||||
callbackValue);
|
callback_data.value);
|
||||||
SDL_free(callbackValue);
|
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");
|
SDLTest_AssertPass("Call to SDL_ResetHint(), after clearing callback");
|
||||||
callbackValue = NULL;
|
SDL_RemoveHintCallback(testHint, hints_testHintChanged, &callback_data);
|
||||||
SDL_RemoveHintCallback(testHint, hints_testHintChanged, &callbackValue);
|
|
||||||
SDL_ResetHint(testHint);
|
SDL_ResetHint(testHint);
|
||||||
SDLTest_AssertCheck(
|
SDLTest_AssertCheck(
|
||||||
callbackValue == NULL,
|
!callback_data.value,
|
||||||
"callbackValue = %s, expected \"(null)\"",
|
"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;
|
return TEST_COMPLETED;
|
||||||
}
|
}
|
||||||
@@ -226,17 +274,19 @@ static int SDLCALL hints_setHint(void *arg)
|
|||||||
/* ================= Test References ================== */
|
/* ================= Test References ================== */
|
||||||
|
|
||||||
/* Hints test cases */
|
/* Hints test cases */
|
||||||
static const SDLTest_TestCaseReference hintsTest1 = {
|
static const SDLTest_TestCaseReference hintsGetHint = {
|
||||||
hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED
|
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
|
hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Sequence of Hints test cases */
|
/* Sequence of Hints test cases */
|
||||||
static const SDLTest_TestCaseReference *hintsTests[] = {
|
static const SDLTest_TestCaseReference *hintsTests[] = {
|
||||||
&hintsTest1, &hintsTest2, NULL
|
&hintsGetHint,
|
||||||
|
&hintsSetHint,
|
||||||
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Hints test suite (global) */
|
/* Hints test suite (global) */
|
||||||
|
|||||||
Reference in New Issue
Block a user