2015-06-21 09:33:46 -06:00
|
|
|
/**
|
|
|
|
* Hints test suite
|
|
|
|
*/
|
|
|
|
|
2022-11-26 21:43:38 -07:00
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <SDL3/SDL_test.h>
|
2023-03-08 08:12:45 -07:00
|
|
|
#include "testautomation_suites.h"
|
2015-06-21 09:33:46 -06:00
|
|
|
|
2023-03-08 08:12:45 -07:00
|
|
|
static const char *HintsEnum[] = {
|
2015-06-21 09:33:46 -06:00
|
|
|
SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
|
|
|
|
SDL_HINT_FRAMEBUFFER_ACCELERATION,
|
|
|
|
SDL_HINT_GAMECONTROLLERCONFIG,
|
|
|
|
SDL_HINT_GRAB_KEYBOARD,
|
|
|
|
SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
|
|
|
|
SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK,
|
|
|
|
SDL_HINT_MOUSE_RELATIVE_MODE_WARP,
|
|
|
|
SDL_HINT_ORIENTATIONS,
|
|
|
|
SDL_HINT_RENDER_DIRECT3D_THREADSAFE,
|
|
|
|
SDL_HINT_RENDER_DRIVER,
|
|
|
|
SDL_HINT_RENDER_OPENGL_SHADERS,
|
|
|
|
SDL_HINT_RENDER_SCALE_QUALITY,
|
|
|
|
SDL_HINT_RENDER_VSYNC,
|
|
|
|
SDL_HINT_TIMER_RESOLUTION,
|
|
|
|
SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
|
|
|
|
SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES,
|
|
|
|
SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
|
|
|
|
SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
|
|
|
|
SDL_HINT_VIDEO_WIN_D3DCOMPILER,
|
|
|
|
SDL_HINT_VIDEO_X11_XRANDR,
|
|
|
|
SDL_HINT_XINPUT_ENABLED,
|
2022-11-30 13:51:59 -07:00
|
|
|
};
|
2023-03-08 08:12:45 -07:00
|
|
|
static const char *HintsVerbose[] = {
|
2021-09-22 10:49:41 -06:00
|
|
|
"SDL_ACCELEROMETER_AS_JOYSTICK",
|
|
|
|
"SDL_FRAMEBUFFER_ACCELERATION",
|
|
|
|
"SDL_GAMECONTROLLERCONFIG",
|
|
|
|
"SDL_GRAB_KEYBOARD",
|
|
|
|
"SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS",
|
|
|
|
"SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK",
|
|
|
|
"SDL_MOUSE_RELATIVE_MODE_WARP",
|
|
|
|
"SDL_ORIENTATIONS",
|
|
|
|
"SDL_RENDER_DIRECT3D_THREADSAFE",
|
|
|
|
"SDL_RENDER_DRIVER",
|
|
|
|
"SDL_RENDER_OPENGL_SHADERS",
|
|
|
|
"SDL_RENDER_SCALE_QUALITY",
|
|
|
|
"SDL_RENDER_VSYNC",
|
|
|
|
"SDL_TIMER_RESOLUTION",
|
|
|
|
"SDL_VIDEO_ALLOW_SCREENSAVER",
|
|
|
|
"SDL_VIDEO_MAC_FULLSCREEN_SPACES",
|
|
|
|
"SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
|
|
|
|
"SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
|
|
|
|
"SDL_VIDEO_WIN_D3DCOMPILER",
|
|
|
|
"SDL_VIDEO_X11_XRANDR",
|
|
|
|
"SDL_XINPUT_ENABLED"
|
2022-11-30 13:51:59 -07:00
|
|
|
};
|
2015-06-21 09:33:46 -06:00
|
|
|
|
2022-12-29 14:58:16 -07:00
|
|
|
SDL_COMPILE_TIME_ASSERT(HintsEnum, SDL_arraysize(HintsEnum) == SDL_arraysize(HintsVerbose));
|
2022-04-28 12:57:20 -06:00
|
|
|
|
2023-03-08 08:12:45 -07:00
|
|
|
static const int numHintsEnum = SDL_arraysize(HintsEnum);
|
2015-06-21 09:33:46 -06:00
|
|
|
|
|
|
|
/* Test case functions */
|
|
|
|
|
|
|
|
/**
|
2023-11-06 08:26:06 -07:00
|
|
|
* Call to SDL_GetHint
|
2015-06-21 09:33:46 -06:00
|
|
|
*/
|
2023-03-08 08:12:45 -07:00
|
|
|
static int hints_getHint(void *arg)
|
2015-06-21 09:33:46 -06:00
|
|
|
{
|
2022-11-30 13:51:59 -07:00
|
|
|
const char *result1;
|
|
|
|
const char *result2;
|
|
|
|
int i;
|
|
|
|
|
2022-12-29 14:58:16 -07:00
|
|
|
for (i = 0; i < numHintsEnum; i++) {
|
|
|
|
result1 = SDL_GetHint(HintsEnum[i]);
|
|
|
|
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char *)HintsEnum[i]);
|
|
|
|
result2 = SDL_GetHint(HintsVerbose[i]);
|
|
|
|
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char *)HintsVerbose[i]);
|
2022-11-30 13:51:59 -07:00
|
|
|
SDLTest_AssertCheck(
|
|
|
|
(result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
|
|
|
|
"Verify returned values are equal; got: result1='%s' result2='%s",
|
|
|
|
(result1 == NULL) ? "null" : result1,
|
|
|
|
(result2 == NULL) ? "null" : result2);
|
|
|
|
}
|
2021-11-19 15:02:02 -07:00
|
|
|
|
2022-11-30 13:51:59 -07:00
|
|
|
return TEST_COMPLETED;
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
|
|
|
|
2022-10-02 18:17:31 -06:00
|
|
|
static void SDLCALL hints_testHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
|
|
|
{
|
2022-11-30 13:51:59 -07:00
|
|
|
*(char **)userdata = hint ? SDL_strdup(hint) : NULL;
|
2022-10-02 18:17:31 -06:00
|
|
|
}
|
|
|
|
|
2015-06-21 09:33:46 -06:00
|
|
|
/**
|
2023-11-06 08:26:06 -07:00
|
|
|
* Call to SDL_SetHint
|
2015-06-21 09:33:46 -06:00
|
|
|
*/
|
2023-03-08 08:12:45 -07:00
|
|
|
static int hints_setHint(void *arg)
|
2015-06-21 09:33:46 -06:00
|
|
|
{
|
2022-11-30 13:51:59 -07:00
|
|
|
const char *testHint = "SDL_AUTOMATED_TEST_HINT";
|
|
|
|
const char *originalValue;
|
|
|
|
char *value;
|
|
|
|
const char *testValue;
|
|
|
|
char *callbackValue;
|
|
|
|
SDL_bool result;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
/* Create random values to set */
|
|
|
|
value = SDLTest_RandomAsciiStringOfSize(10);
|
|
|
|
|
2022-12-29 14:58:16 -07:00
|
|
|
for (i = 0; i < numHintsEnum; i++) {
|
2022-11-30 13:51:59 -07:00
|
|
|
/* Capture current value */
|
2022-12-29 14:58:16 -07:00
|
|
|
originalValue = SDL_GetHint(HintsEnum[i]);
|
|
|
|
SDLTest_AssertPass("Call to SDL_GetHint(%s)", HintsEnum[i]);
|
2022-11-30 13:51:59 -07:00
|
|
|
|
|
|
|
/* Copy the original value, since it will be freed when we set it again */
|
|
|
|
originalValue = originalValue ? SDL_strdup(originalValue) : NULL;
|
|
|
|
|
|
|
|
/* Set value (twice) */
|
|
|
|
for (j = 1; j <= 2; j++) {
|
2022-12-29 14:58:16 -07:00
|
|
|
result = SDL_SetHint(HintsEnum[i], value);
|
|
|
|
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", HintsEnum[i], value, j);
|
2022-11-30 13:51:59 -07:00
|
|
|
SDLTest_AssertCheck(
|
|
|
|
result == SDL_TRUE || result == SDL_FALSE,
|
|
|
|
"Verify valid result was returned, got: %i",
|
|
|
|
(int)result);
|
2022-12-29 14:58:16 -07:00
|
|
|
testValue = SDL_GetHint(HintsEnum[i]);
|
|
|
|
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", HintsVerbose[i]);
|
2022-11-30 13:51:59 -07:00
|
|
|
SDLTest_AssertCheck(
|
|
|
|
(SDL_strcmp(value, testValue) == 0),
|
|
|
|
"Verify returned value equals set value; got: testValue='%s' value='%s",
|
|
|
|
(testValue == NULL) ? "null" : testValue,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset original value */
|
2022-12-29 14:58:16 -07:00
|
|
|
result = SDL_SetHint(HintsEnum[i], originalValue);
|
|
|
|
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", HintsEnum[i]);
|
2022-11-30 13:51:59 -07:00
|
|
|
SDLTest_AssertCheck(
|
|
|
|
result == SDL_TRUE || result == SDL_FALSE,
|
|
|
|
"Verify valid result was returned, got: %i",
|
|
|
|
(int)result);
|
|
|
|
SDL_free((void *)originalValue);
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
2021-11-19 15:02:02 -07:00
|
|
|
|
2022-11-30 13:51:59 -07:00
|
|
|
SDL_free(value);
|
|
|
|
|
|
|
|
/* Set default value in environment */
|
|
|
|
SDL_setenv(testHint, "original", 1);
|
|
|
|
|
|
|
|
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);
|
|
|
|
SDL_free(value);
|
|
|
|
testValue = SDL_GetHint(testHint);
|
|
|
|
SDLTest_AssertCheck(
|
|
|
|
testValue && SDL_strcmp(testValue, "original") == 0,
|
|
|
|
"testValue = %s, expected \"original\"",
|
|
|
|
testValue);
|
|
|
|
|
|
|
|
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_DEFAULT)");
|
|
|
|
SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_DEFAULT);
|
|
|
|
testValue = SDL_GetHint(testHint);
|
|
|
|
SDLTest_AssertCheck(
|
|
|
|
testValue && SDL_strcmp(testValue, "original") == 0,
|
|
|
|
"testValue = %s, expected \"original\"",
|
|
|
|
testValue);
|
|
|
|
|
|
|
|
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE)");
|
|
|
|
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
|
|
|
|
testValue = SDL_GetHint(testHint);
|
|
|
|
SDLTest_AssertCheck(
|
|
|
|
testValue && SDL_strcmp(testValue, "temp") == 0,
|
|
|
|
"testValue = %s, expected \"temp\"",
|
|
|
|
testValue);
|
|
|
|
|
|
|
|
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_OVERRIDE)");
|
|
|
|
SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_OVERRIDE);
|
|
|
|
testValue = SDL_GetHint(testHint);
|
|
|
|
SDLTest_AssertCheck(
|
|
|
|
testValue == NULL,
|
|
|
|
"testValue = %s, expected NULL",
|
|
|
|
testValue);
|
|
|
|
|
|
|
|
SDLTest_AssertPass("Call to SDL_ResetHint()");
|
|
|
|
SDL_ResetHint(testHint);
|
|
|
|
testValue = SDL_GetHint(testHint);
|
|
|
|
SDLTest_AssertCheck(
|
|
|
|
testValue && SDL_strcmp(testValue, "original") == 0,
|
|
|
|
"testValue = %s, expected \"original\"",
|
|
|
|
testValue);
|
|
|
|
|
|
|
|
/* Make sure callback functionality works past a reset */
|
|
|
|
SDLTest_AssertPass("Call to SDL_AddHintCallback()");
|
|
|
|
callbackValue = NULL;
|
|
|
|
SDL_AddHintCallback(testHint, hints_testHintChanged, &callbackValue);
|
|
|
|
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);
|
|
|
|
SDLTest_AssertCheck(
|
|
|
|
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
|
|
|
|
"callbackValue = %s, expected \"temp\"",
|
|
|
|
callbackValue);
|
|
|
|
SDL_free(callbackValue);
|
|
|
|
|
|
|
|
SDLTest_AssertPass("Call to SDL_ResetHint(), using callback");
|
|
|
|
callbackValue = NULL;
|
|
|
|
SDL_ResetHint(testHint);
|
|
|
|
SDLTest_AssertCheck(
|
|
|
|
callbackValue && SDL_strcmp(callbackValue, "original") == 0,
|
|
|
|
"callbackValue = %s, expected \"original\"",
|
|
|
|
callbackValue);
|
2023-06-13 15:10:29 -06:00
|
|
|
SDL_free(callbackValue);
|
2022-11-30 13:51:59 -07:00
|
|
|
|
|
|
|
SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback after reset");
|
|
|
|
callbackValue = NULL;
|
|
|
|
SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE);
|
|
|
|
SDLTest_AssertCheck(
|
|
|
|
callbackValue && SDL_strcmp(callbackValue, "temp") == 0,
|
|
|
|
"callbackValue = %s, expected \"temp\"",
|
|
|
|
callbackValue);
|
|
|
|
SDL_free(callbackValue);
|
|
|
|
|
|
|
|
SDLTest_AssertPass("Call to SDL_ResetHint(), after clearing callback");
|
|
|
|
callbackValue = NULL;
|
|
|
|
SDL_DelHintCallback(testHint, hints_testHintChanged, &callbackValue);
|
|
|
|
SDL_ResetHint(testHint);
|
2015-06-21 09:33:46 -06:00
|
|
|
SDLTest_AssertCheck(
|
2022-11-30 13:51:59 -07:00
|
|
|
callbackValue == NULL,
|
|
|
|
"callbackValue = %s, expected \"(null)\"",
|
|
|
|
callbackValue);
|
|
|
|
|
|
|
|
return TEST_COMPLETED;
|
2015-06-21 09:33:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ================= Test References ================== */
|
|
|
|
|
|
|
|
/* Hints test cases */
|
2022-11-30 13:51:59 -07:00
|
|
|
static const SDLTest_TestCaseReference hintsTest1 = {
|
|
|
|
(SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED
|
|
|
|
};
|
2015-06-21 09:33:46 -06:00
|
|
|
|
2022-11-30 13:51:59 -07:00
|
|
|
static const SDLTest_TestCaseReference hintsTest2 = {
|
|
|
|
(SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED
|
|
|
|
};
|
2015-06-21 09:33:46 -06:00
|
|
|
|
|
|
|
/* Sequence of Hints test cases */
|
2022-11-30 13:51:59 -07:00
|
|
|
static const SDLTest_TestCaseReference *hintsTests[] = {
|
2015-06-21 09:33:46 -06:00
|
|
|
&hintsTest1, &hintsTest2, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Hints test suite (global) */
|
|
|
|
SDLTest_TestSuiteReference hintsTestSuite = {
|
|
|
|
"Hints",
|
|
|
|
NULL,
|
|
|
|
hintsTests,
|
|
|
|
NULL
|
|
|
|
};
|