diff options
Diffstat (limited to 'src/contrib/SDL-3.2.20/test/testautomation_hints.c')
-rw-r--r-- | src/contrib/SDL-3.2.20/test/testautomation_hints.c | 248 |
1 files changed, 248 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/test/testautomation_hints.c b/src/contrib/SDL-3.2.20/test/testautomation_hints.c new file mode 100644 index 0000000..e2c158b --- /dev/null +++ b/src/contrib/SDL-3.2.20/test/testautomation_hints.c | |||
@@ -0,0 +1,248 @@ | |||
1 | /** | ||
2 | * Hints test suite | ||
3 | */ | ||
4 | |||
5 | #include <SDL3/SDL.h> | ||
6 | #include <SDL3/SDL_test.h> | ||
7 | #include "testautomation_suites.h" | ||
8 | |||
9 | static const char *HintsEnum[] = { | ||
10 | SDL_HINT_FRAMEBUFFER_ACCELERATION, | ||
11 | SDL_HINT_GAMECONTROLLERCONFIG, | ||
12 | SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, | ||
13 | SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, | ||
14 | SDL_HINT_ORIENTATIONS, | ||
15 | SDL_HINT_RENDER_DIRECT3D_THREADSAFE, | ||
16 | SDL_HINT_RENDER_VSYNC, | ||
17 | SDL_HINT_TIMER_RESOLUTION, | ||
18 | SDL_HINT_VIDEO_ALLOW_SCREENSAVER, | ||
19 | SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, | ||
20 | SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, | ||
21 | SDL_HINT_VIDEO_WIN_D3DCOMPILER, | ||
22 | SDL_HINT_VIDEO_X11_XRANDR, | ||
23 | SDL_HINT_XINPUT_ENABLED, | ||
24 | }; | ||
25 | static const char *HintsVerbose[] = { | ||
26 | "SDL_FRAMEBUFFER_ACCELERATION", | ||
27 | "SDL_GAMECONTROLLERCONFIG", | ||
28 | "SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", | ||
29 | "SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK", | ||
30 | "SDL_ORIENTATIONS", | ||
31 | "SDL_RENDER_DIRECT3D_THREADSAFE", | ||
32 | "SDL_RENDER_VSYNC", | ||
33 | "SDL_TIMER_RESOLUTION", | ||
34 | "SDL_VIDEO_ALLOW_SCREENSAVER", | ||
35 | "SDL_VIDEO_MAC_FULLSCREEN_SPACES", | ||
36 | "SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS", | ||
37 | "SDL_VIDEO_WIN_D3DCOMPILER", | ||
38 | "SDL_VIDEO_X11_XRANDR", | ||
39 | "SDL_XINPUT_ENABLED" | ||
40 | }; | ||
41 | |||
42 | SDL_COMPILE_TIME_ASSERT(HintsEnum, SDL_arraysize(HintsEnum) == SDL_arraysize(HintsVerbose)); | ||
43 | |||
44 | static const int numHintsEnum = SDL_arraysize(HintsEnum); | ||
45 | |||
46 | /* Test case functions */ | ||
47 | |||
48 | /** | ||
49 | * Call to SDL_GetHint | ||
50 | */ | ||
51 | static int SDLCALL hints_getHint(void *arg) | ||
52 | { | ||
53 | const char *result1; | ||
54 | const char *result2; | ||
55 | int i; | ||
56 | |||
57 | for (i = 0; i < numHintsEnum; i++) { | ||
58 | result1 = SDL_GetHint(HintsEnum[i]); | ||
59 | SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char *)HintsEnum[i]); | ||
60 | result2 = SDL_GetHint(HintsVerbose[i]); | ||
61 | SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char *)HintsVerbose[i]); | ||
62 | SDLTest_AssertCheck( | ||
63 | (result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0), | ||
64 | "Verify returned values are equal; got: result1='%s' result2='%s", | ||
65 | (result1 == NULL) ? "null" : result1, | ||
66 | (result2 == NULL) ? "null" : result2); | ||
67 | } | ||
68 | |||
69 | return TEST_COMPLETED; | ||
70 | } | ||
71 | |||
72 | static void SDLCALL hints_testHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint) | ||
73 | { | ||
74 | *(char **)userdata = hint ? SDL_strdup(hint) : NULL; | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * Call to SDL_SetHint | ||
79 | */ | ||
80 | static int SDLCALL hints_setHint(void *arg) | ||
81 | { | ||
82 | const char *testHint = "SDL_AUTOMATED_TEST_HINT"; | ||
83 | const char *originalValue; | ||
84 | char *value; | ||
85 | const char *testValue; | ||
86 | char *callbackValue; | ||
87 | bool result; | ||
88 | int i, j; | ||
89 | |||
90 | /* Create random values to set */ | ||
91 | value = SDLTest_RandomAsciiStringOfSize(10); | ||
92 | |||
93 | for (i = 0; i < numHintsEnum; i++) { | ||
94 | /* Capture current value */ | ||
95 | originalValue = SDL_GetHint(HintsEnum[i]); | ||
96 | SDLTest_AssertPass("Call to SDL_GetHint(%s)", HintsEnum[i]); | ||
97 | |||
98 | /* Copy the original value, since it will be freed when we set it again */ | ||
99 | originalValue = originalValue ? SDL_strdup(originalValue) : NULL; | ||
100 | |||
101 | /* Set value (twice) */ | ||
102 | for (j = 1; j <= 2; j++) { | ||
103 | result = SDL_SetHint(HintsEnum[i], value); | ||
104 | SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", HintsEnum[i], value, j); | ||
105 | SDLTest_AssertCheck( | ||
106 | result == true || result == false, | ||
107 | "Verify valid result was returned, got: %i", | ||
108 | (int)result); | ||
109 | testValue = SDL_GetHint(HintsEnum[i]); | ||
110 | SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", HintsVerbose[i]); | ||
111 | SDLTest_AssertCheck( | ||
112 | (SDL_strcmp(value, testValue) == 0), | ||
113 | "Verify returned value equals set value; got: testValue='%s' value='%s", | ||
114 | (testValue == NULL) ? "null" : testValue, | ||
115 | value); | ||
116 | } | ||
117 | |||
118 | /* Reset original value */ | ||
119 | result = SDL_SetHint(HintsEnum[i], originalValue); | ||
120 | SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", HintsEnum[i]); | ||
121 | SDLTest_AssertCheck( | ||
122 | result == true || result == false, | ||
123 | "Verify valid result was returned, got: %i", | ||
124 | (int)result); | ||
125 | SDL_free((void *)originalValue); | ||
126 | } | ||
127 | |||
128 | SDL_free(value); | ||
129 | |||
130 | /* Set default value in environment */ | ||
131 | SDL_SetEnvironmentVariable(SDL_GetEnvironment(), testHint, "original", 1); | ||
132 | |||
133 | SDLTest_AssertPass("Call to SDL_GetHint() after saving and restoring hint"); | ||
134 | originalValue = SDL_GetHint(testHint); | ||
135 | value = (originalValue == NULL) ? NULL : SDL_strdup(originalValue); | ||
136 | SDL_SetHint(testHint, "temp"); | ||
137 | SDL_SetHint(testHint, value); | ||
138 | SDL_free(value); | ||
139 | testValue = SDL_GetHint(testHint); | ||
140 | SDLTest_AssertCheck( | ||
141 | testValue && SDL_strcmp(testValue, "original") == 0, | ||
142 | "testValue = %s, expected \"original\"", | ||
143 | testValue); | ||
144 | |||
145 | SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_DEFAULT)"); | ||
146 | SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_DEFAULT); | ||
147 | testValue = SDL_GetHint(testHint); | ||
148 | SDLTest_AssertCheck( | ||
149 | testValue && SDL_strcmp(testValue, "original") == 0, | ||
150 | "testValue = %s, expected \"original\"", | ||
151 | testValue); | ||
152 | |||
153 | SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE)"); | ||
154 | SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE); | ||
155 | testValue = SDL_GetHint(testHint); | ||
156 | SDLTest_AssertCheck( | ||
157 | testValue && SDL_strcmp(testValue, "temp") == 0, | ||
158 | "testValue = %s, expected \"temp\"", | ||
159 | testValue); | ||
160 | |||
161 | SDLTest_AssertPass("Call to SDL_SetHintWithPriority(NULL, SDL_HINT_OVERRIDE)"); | ||
162 | SDL_SetHintWithPriority(testHint, NULL, SDL_HINT_OVERRIDE); | ||
163 | testValue = SDL_GetHint(testHint); | ||
164 | SDLTest_AssertCheck( | ||
165 | testValue == NULL, | ||
166 | "testValue = %s, expected NULL", | ||
167 | testValue); | ||
168 | |||
169 | SDLTest_AssertPass("Call to SDL_ResetHint()"); | ||
170 | SDL_ResetHint(testHint); | ||
171 | testValue = SDL_GetHint(testHint); | ||
172 | SDLTest_AssertCheck( | ||
173 | testValue && SDL_strcmp(testValue, "original") == 0, | ||
174 | "testValue = %s, expected \"original\"", | ||
175 | testValue); | ||
176 | |||
177 | /* Make sure callback functionality works past a reset */ | ||
178 | SDLTest_AssertPass("Call to SDL_AddHintCallback()"); | ||
179 | callbackValue = NULL; | ||
180 | SDL_AddHintCallback(testHint, hints_testHintChanged, &callbackValue); | ||
181 | SDLTest_AssertCheck( | ||
182 | callbackValue && SDL_strcmp(callbackValue, "original") == 0, | ||
183 | "callbackValue = %s, expected \"original\"", | ||
184 | callbackValue); | ||
185 | SDL_free(callbackValue); | ||
186 | |||
187 | SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback"); | ||
188 | callbackValue = NULL; | ||
189 | SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE); | ||
190 | SDLTest_AssertCheck( | ||
191 | callbackValue && SDL_strcmp(callbackValue, "temp") == 0, | ||
192 | "callbackValue = %s, expected \"temp\"", | ||
193 | callbackValue); | ||
194 | SDL_free(callbackValue); | ||
195 | |||
196 | SDLTest_AssertPass("Call to SDL_ResetHint(), using callback"); | ||
197 | callbackValue = NULL; | ||
198 | SDL_ResetHint(testHint); | ||
199 | SDLTest_AssertCheck( | ||
200 | callbackValue && SDL_strcmp(callbackValue, "original") == 0, | ||
201 | "callbackValue = %s, expected \"original\"", | ||
202 | callbackValue); | ||
203 | SDL_free(callbackValue); | ||
204 | |||
205 | SDLTest_AssertPass("Call to SDL_SetHintWithPriority(\"temp\", SDL_HINT_OVERRIDE), using callback after reset"); | ||
206 | callbackValue = NULL; | ||
207 | SDL_SetHintWithPriority(testHint, "temp", SDL_HINT_OVERRIDE); | ||
208 | SDLTest_AssertCheck( | ||
209 | callbackValue && SDL_strcmp(callbackValue, "temp") == 0, | ||
210 | "callbackValue = %s, expected \"temp\"", | ||
211 | callbackValue); | ||
212 | SDL_free(callbackValue); | ||
213 | |||
214 | SDLTest_AssertPass("Call to SDL_ResetHint(), after clearing callback"); | ||
215 | callbackValue = NULL; | ||
216 | SDL_RemoveHintCallback(testHint, hints_testHintChanged, &callbackValue); | ||
217 | SDL_ResetHint(testHint); | ||
218 | SDLTest_AssertCheck( | ||
219 | callbackValue == NULL, | ||
220 | "callbackValue = %s, expected \"(null)\"", | ||
221 | callbackValue); | ||
222 | |||
223 | return TEST_COMPLETED; | ||
224 | } | ||
225 | |||
226 | /* ================= Test References ================== */ | ||
227 | |||
228 | /* Hints test cases */ | ||
229 | static const SDLTest_TestCaseReference hintsTest1 = { | ||
230 | hints_getHint, "hints_getHint", "Call to SDL_GetHint", TEST_ENABLED | ||
231 | }; | ||
232 | |||
233 | static const SDLTest_TestCaseReference hintsTest2 = { | ||
234 | hints_setHint, "hints_setHint", "Call to SDL_SetHint", TEST_ENABLED | ||
235 | }; | ||
236 | |||
237 | /* Sequence of Hints test cases */ | ||
238 | static const SDLTest_TestCaseReference *hintsTests[] = { | ||
239 | &hintsTest1, &hintsTest2, NULL | ||
240 | }; | ||
241 | |||
242 | /* Hints test suite (global) */ | ||
243 | SDLTest_TestSuiteReference hintsTestSuite = { | ||
244 | "Hints", | ||
245 | NULL, | ||
246 | hintsTests, | ||
247 | NULL | ||
248 | }; | ||