diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/test/testautomation_main.c | |
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/test/testautomation_main.c')
| -rw-r--r-- | contrib/SDL-3.2.8/test/testautomation_main.c | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/test/testautomation_main.c b/contrib/SDL-3.2.8/test/testautomation_main.c new file mode 100644 index 0000000..89991c0 --- /dev/null +++ b/contrib/SDL-3.2.8/test/testautomation_main.c | |||
| @@ -0,0 +1,172 @@ | |||
| 1 | /** | ||
| 2 | * Automated SDL subsystems management test. | ||
| 3 | * | ||
| 4 | * Written by J�rgen Tjern� "jorgenpt" | ||
| 5 | * | ||
| 6 | * Released under Public Domain. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include <SDL3/SDL.h> | ||
| 10 | #include <SDL3/SDL_test.h> | ||
| 11 | #include "testautomation_suites.h" | ||
| 12 | #ifdef HAVE_BUILD_CONFIG | ||
| 13 | #include "SDL_build_config.h" | ||
| 14 | #endif | ||
| 15 | |||
| 16 | /** | ||
| 17 | * Tests SDL_InitSubSystem() and SDL_QuitSubSystem() | ||
| 18 | * \sa SDL_Init | ||
| 19 | * \sa SDL_Quit | ||
| 20 | */ | ||
| 21 | static int SDLCALL main_testInitQuitSubSystem(void *arg) | ||
| 22 | { | ||
| 23 | int i; | ||
| 24 | int subsystems[] = { SDL_INIT_JOYSTICK, SDL_INIT_HAPTIC, SDL_INIT_GAMEPAD }; | ||
| 25 | |||
| 26 | for (i = 0; i < SDL_arraysize(subsystems); ++i) { | ||
| 27 | int initialized_system; | ||
| 28 | int subsystem = subsystems[i]; | ||
| 29 | |||
| 30 | SDLTest_AssertCheck((SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) before init should be false", subsystem); | ||
| 31 | SDLTest_AssertCheck(SDL_InitSubSystem(subsystem), "SDL_InitSubSystem(%x)", subsystem); | ||
| 32 | |||
| 33 | initialized_system = SDL_WasInit(subsystem); | ||
| 34 | SDLTest_AssertCheck((initialized_system & subsystem) != 0, "SDL_WasInit(%x) should be true (%x)", subsystem, initialized_system); | ||
| 35 | |||
| 36 | SDL_QuitSubSystem(subsystem); | ||
| 37 | |||
| 38 | SDLTest_AssertCheck((SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) after shutdown should be false", subsystem); | ||
| 39 | } | ||
| 40 | |||
| 41 | return TEST_COMPLETED; | ||
| 42 | } | ||
| 43 | |||
| 44 | static const int joy_and_controller = SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD; | ||
| 45 | static int SDLCALL main_testImpliedJoystickInit(void *arg) | ||
| 46 | { | ||
| 47 | int initialized_system; | ||
| 48 | |||
| 49 | /* First initialize the controller */ | ||
| 50 | SDLTest_AssertCheck((SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller"); | ||
| 51 | SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMEPAD), "SDL_InitSubSystem(SDL_INIT_GAMEPAD)"); | ||
| 52 | |||
| 53 | /* Then make sure this implicitly initialized the joystick subsystem */ | ||
| 54 | initialized_system = SDL_WasInit(joy_and_controller); | ||
| 55 | SDLTest_AssertCheck((initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system); | ||
| 56 | |||
| 57 | /* Then quit the controller, and make sure that implicitly also quits the */ | ||
| 58 | /* joystick subsystem */ | ||
| 59 | SDL_QuitSubSystem(SDL_INIT_GAMEPAD); | ||
| 60 | initialized_system = SDL_WasInit(joy_and_controller); | ||
| 61 | SDLTest_AssertCheck((initialized_system & joy_and_controller) == 0, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system); | ||
| 62 | |||
| 63 | return TEST_COMPLETED; | ||
| 64 | } | ||
| 65 | |||
| 66 | static int SDLCALL main_testImpliedJoystickQuit(void *arg) | ||
| 67 | { | ||
| 68 | int initialized_system; | ||
| 69 | |||
| 70 | /* First initialize the controller and the joystick (explicitly) */ | ||
| 71 | SDLTest_AssertCheck((SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller"); | ||
| 72 | SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_JOYSTICK), "SDL_InitSubSystem(SDL_INIT_JOYSTICK)"); | ||
| 73 | SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMEPAD), "SDL_InitSubSystem(SDL_INIT_GAMEPAD)"); | ||
| 74 | |||
| 75 | /* Then make sure they're both initialized properly */ | ||
| 76 | initialized_system = SDL_WasInit(joy_and_controller); | ||
| 77 | SDLTest_AssertCheck((initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system); | ||
| 78 | |||
| 79 | /* Then quit the controller, and make sure that it does NOT quit the */ | ||
| 80 | /* explicitly initialized joystick subsystem. */ | ||
| 81 | SDL_QuitSubSystem(SDL_INIT_GAMEPAD); | ||
| 82 | initialized_system = SDL_WasInit(joy_and_controller); | ||
| 83 | SDLTest_AssertCheck((initialized_system & joy_and_controller) == SDL_INIT_JOYSTICK, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system); | ||
| 84 | |||
| 85 | SDL_QuitSubSystem(SDL_INIT_JOYSTICK); | ||
| 86 | |||
| 87 | return TEST_COMPLETED; | ||
| 88 | } | ||
| 89 | |||
| 90 | #if defined(__GNUC__) || defined(__clang__) | ||
| 91 | #pragma GCC diagnostic push | ||
| 92 | #pragma GCC diagnostic ignored "-Wformat-zero-length" | ||
| 93 | #endif | ||
| 94 | |||
| 95 | static int SDLCALL | ||
| 96 | main_testSetError(void *arg) | ||
| 97 | { | ||
| 98 | size_t i; | ||
| 99 | char error_input[1024]; | ||
| 100 | int result; | ||
| 101 | const char *error; | ||
| 102 | size_t expected_len; | ||
| 103 | |||
| 104 | SDLTest_AssertPass("SDL_SetError(NULL)"); | ||
| 105 | result = SDL_SetError(NULL); | ||
| 106 | SDLTest_AssertCheck(result == false, "SDL_SetError(NULL) -> %d (expected %d)", result, false); | ||
| 107 | error = SDL_GetError(); | ||
| 108 | SDLTest_AssertCheck(SDL_strcmp(error, "") == 0, "SDL_GetError() -> \"%s\" (expected \"%s\")", error, ""); | ||
| 109 | |||
| 110 | SDLTest_AssertPass("SDL_SetError(\"\")"); | ||
| 111 | result = SDL_SetError(""); | ||
| 112 | SDLTest_AssertCheck(result == false, "SDL_SetError(\"\") -> %d (expected %d)", result, false); | ||
| 113 | error = SDL_GetError(); | ||
| 114 | SDLTest_AssertCheck(SDL_strcmp(error, "") == 0, "SDL_GetError() -> \"%s\" (expected \"%s\")", error, ""); | ||
| 115 | |||
| 116 | error_input[0] = '\0'; | ||
| 117 | for (i = 0; i < (sizeof(error_input) - 1); ++i) { | ||
| 118 | error_input[i] = 'a' + (i % 26); | ||
| 119 | } | ||
| 120 | error_input[i] = '\0'; | ||
| 121 | SDLTest_AssertPass("SDL_SetError(\"abc...\")"); | ||
| 122 | result = SDL_SetError("%s", error_input); | ||
| 123 | SDLTest_AssertCheck(result == false, "SDL_SetError(\"abc...\") -> %d (expected %d)", result, false); | ||
| 124 | error = SDL_GetError(); | ||
| 125 | |||
| 126 | #ifdef SDL_THREADS_DISABLED | ||
| 127 | expected_len = 128 - 1; | ||
| 128 | #else | ||
| 129 | expected_len = sizeof(error_input) - 1; | ||
| 130 | #endif | ||
| 131 | SDLTest_AssertPass("Verify SDL error is identical to the input error"); | ||
| 132 | SDLTest_CompareMemory(error, SDL_strlen(error), error_input, expected_len); | ||
| 133 | |||
| 134 | return TEST_COMPLETED; | ||
| 135 | } | ||
| 136 | |||
| 137 | #if defined(__GNUC__) || defined(__clang__) | ||
| 138 | #pragma GCC diagnostic pop | ||
| 139 | #endif | ||
| 140 | |||
| 141 | static const SDLTest_TestCaseReference mainTest1 = { | ||
| 142 | main_testInitQuitSubSystem, "main_testInitQuitSubSystem", "Tests SDL_InitSubSystem/QuitSubSystem", TEST_ENABLED | ||
| 143 | }; | ||
| 144 | |||
| 145 | static const SDLTest_TestCaseReference mainTest2 = { | ||
| 146 | main_testImpliedJoystickInit, "main_testImpliedJoystickInit", "Tests that init for gamecontroller properly implies joystick", TEST_ENABLED | ||
| 147 | }; | ||
| 148 | |||
| 149 | static const SDLTest_TestCaseReference mainTest3 = { | ||
| 150 | main_testImpliedJoystickQuit, "main_testImpliedJoystickQuit", "Tests that quit for gamecontroller doesn't quit joystick if you inited it explicitly", TEST_ENABLED | ||
| 151 | }; | ||
| 152 | |||
| 153 | static const SDLTest_TestCaseReference mainTest4 = { | ||
| 154 | main_testSetError, "main_testSetError", "Tests that SDL_SetError() handles arbitrarily large strings", TEST_ENABLED | ||
| 155 | }; | ||
| 156 | |||
| 157 | /* Sequence of Main test cases */ | ||
| 158 | static const SDLTest_TestCaseReference *mainTests[] = { | ||
| 159 | &mainTest1, | ||
| 160 | &mainTest2, | ||
| 161 | &mainTest3, | ||
| 162 | &mainTest4, | ||
| 163 | NULL | ||
| 164 | }; | ||
| 165 | |||
| 166 | /* Main test suite (global) */ | ||
| 167 | SDLTest_TestSuiteReference mainTestSuite = { | ||
| 168 | "Main", | ||
| 169 | NULL, | ||
| 170 | mainTests, | ||
| 171 | NULL | ||
| 172 | }; | ||
