pineapple/externals/SDL/test/testautomation_hints.c

171 lines
5 KiB
C
Raw Normal View History

2021-04-18 05:35:25 +02:00
/**
* Hints test suite
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
2021-12-07 02:20:09 +01:00
const char* _HintsEnum[] =
2021-04-18 05:35:25 +02:00
{
SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
SDL_HINT_FRAMEBUFFER_ACCELERATION,
SDL_HINT_GAMECONTROLLERCONFIG,
SDL_HINT_GRAB_KEYBOARD,
SDL_HINT_IDLE_TIMER_DISABLED,
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_HIGHDPI_DISABLED,
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,
};
2021-12-07 02:20:09 +01:00
const char* _HintsVerbose[] =
2021-04-18 05:35:25 +02:00
{
2021-12-07 02:20:09 +01:00
"SDL_ACCELEROMETER_AS_JOYSTICK",
"SDL_FRAMEBUFFER_ACCELERATION",
"SDL_GAMECONTROLLERCONFIG",
"SDL_GRAB_KEYBOARD",
"SDL_IDLE_TIMER_DISABLED",
"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_HIGHDPI_DISABLED",
"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"
2021-04-18 05:35:25 +02:00
};
2022-07-15 04:00:50 +02:00
SDL_COMPILE_TIME_ASSERT(HintsEnum, SDL_arraysize(_HintsEnum) == SDL_arraysize(_HintsVerbose));
const int _numHintsEnum = SDL_arraysize(_HintsEnum);
2021-04-18 05:35:25 +02:00
/* Test case functions */
/**
* @brief Call to SDL_GetHint
*/
int
hints_getHint(void *arg)
{
2021-12-07 02:20:09 +01:00
const char *result1;
const char *result2;
2021-04-18 05:35:25 +02:00
int i;
2021-12-07 02:20:09 +01:00
2021-04-18 05:35:25 +02:00
for (i=0; i<_numHintsEnum; i++) {
2021-12-07 02:20:09 +01:00
result1 = SDL_GetHint(_HintsEnum[i]);
2021-04-18 05:35:25 +02:00
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
2021-12-07 02:20:09 +01:00
result2 = SDL_GetHint(_HintsVerbose[i]);
2021-04-18 05:35:25 +02:00
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
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-12-07 02:20:09 +01:00
2021-04-18 05:35:25 +02:00
return TEST_COMPLETED;
}
/**
* @brief Call to SDL_SetHint
*/
int
hints_setHint(void *arg)
{
2021-12-07 02:20:09 +01:00
const char *originalValue;
const char *value;
const char *testValue;
2021-04-18 05:35:25 +02:00
SDL_bool result;
int i, j;
2021-12-07 02:20:09 +01:00
/* Create random values to set */
2021-04-18 05:35:25 +02:00
value = SDLTest_RandomAsciiStringOfSize(10);
2021-12-07 02:20:09 +01:00
2021-04-18 05:35:25 +02:00
for (i=0; i<_numHintsEnum; i++) {
/* Capture current value */
2021-12-07 02:20:09 +01:00
originalValue = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s)", _HintsEnum[i]);
/* Copy the original value, since it will be freed when we set it again */
originalValue = originalValue ? SDL_strdup(originalValue) : NULL;
2021-04-18 05:35:25 +02:00
/* Set value (twice) */
for (j=1; j<=2; j++) {
2021-12-07 02:20:09 +01:00
result = SDL_SetHint(_HintsEnum[i], value);
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", _HintsEnum[i], value, j);
2021-04-18 05:35:25 +02:00
SDLTest_AssertCheck(
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
2021-12-07 02:20:09 +01:00
testValue = SDL_GetHint(_HintsEnum[i]);
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", _HintsVerbose[i]);
2021-04-18 05:35:25 +02:00
SDLTest_AssertCheck(
(SDL_strcmp(value, testValue) == 0),
"Verify returned value equals set value; got: testValue='%s' value='%s",
(testValue == NULL) ? "null" : testValue,
value);
}
2021-12-07 02:20:09 +01:00
2021-04-18 05:35:25 +02:00
/* Reset original value */
2021-12-07 02:20:09 +01:00
result = SDL_SetHint(_HintsEnum[i], originalValue);
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", _HintsEnum[i]);
2021-04-18 05:35:25 +02:00
SDLTest_AssertCheck(
result == SDL_TRUE || result == SDL_FALSE,
"Verify valid result was returned, got: %i",
(int)result);
2021-12-07 02:20:09 +01:00
SDL_free((void *)originalValue);
2021-04-18 05:35:25 +02:00
}
2021-12-07 02:20:09 +01:00
SDL_free((void *)value);
2021-04-18 05:35:25 +02:00
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Hints test cases */
static const SDLTest_TestCaseReference hintsTest1 =
{ (SDLTest_TestCaseFp)hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED };
static const SDLTest_TestCaseReference hintsTest2 =
{ (SDLTest_TestCaseFp)hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED };
/* Sequence of Hints test cases */
static const SDLTest_TestCaseReference *hintsTests[] = {
&hintsTest1, &hintsTest2, NULL
};
/* Hints test suite (global) */
SDLTest_TestSuiteReference hintsTestSuite = {
"Hints",
NULL,
hintsTests,
NULL
};