diff options
Diffstat (limited to 'src/contrib/SDL-3.2.20/test/testautomation_clipboard.c')
-rw-r--r-- | src/contrib/SDL-3.2.20/test/testautomation_clipboard.c | 596 |
1 files changed, 596 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/test/testautomation_clipboard.c b/src/contrib/SDL-3.2.20/test/testautomation_clipboard.c new file mode 100644 index 0000000..3a70d31 --- /dev/null +++ b/src/contrib/SDL-3.2.20/test/testautomation_clipboard.c | |||
@@ -0,0 +1,596 @@ | |||
1 | /** | ||
2 | * New/updated tests: aschiffler at ferzkopp dot net | ||
3 | */ | ||
4 | #include <SDL3/SDL.h> | ||
5 | #include <SDL3/SDL_test.h> | ||
6 | #include "testautomation_suites.h" | ||
7 | |||
8 | /* ================= Test Case Implementation ================== */ | ||
9 | |||
10 | static int clipboard_update_count; | ||
11 | |||
12 | static bool SDLCALL ClipboardEventWatch(void *userdata, SDL_Event *event) | ||
13 | { | ||
14 | if (event->type == SDL_EVENT_CLIPBOARD_UPDATE) { | ||
15 | ++clipboard_update_count; | ||
16 | } | ||
17 | return true; | ||
18 | } | ||
19 | |||
20 | enum | ||
21 | { | ||
22 | TEST_MIME_TYPE_TEXT, | ||
23 | TEST_MIME_TYPE_CUSTOM_TEXT, | ||
24 | TEST_MIME_TYPE_DATA, | ||
25 | NUM_TEST_MIME_TYPES | ||
26 | }; | ||
27 | static const char *test_mime_types[] = { | ||
28 | "text/plain;charset=utf-8", | ||
29 | "test/text", | ||
30 | "test/data" | ||
31 | }; | ||
32 | SDL_COMPILE_TIME_ASSERT(test_mime_types, SDL_arraysize(test_mime_types) == NUM_TEST_MIME_TYPES); | ||
33 | |||
34 | typedef struct | ||
35 | { | ||
36 | const void *data; | ||
37 | size_t data_size; | ||
38 | } TestClipboardData; | ||
39 | |||
40 | static int clipboard_callback_count; | ||
41 | |||
42 | static const void * SDLCALL ClipboardDataCallback(void *userdata, const char *mime_type, size_t *length) | ||
43 | { | ||
44 | TestClipboardData *test_data = (TestClipboardData *)userdata; | ||
45 | |||
46 | ++clipboard_callback_count; | ||
47 | |||
48 | if (SDL_strcmp(mime_type, test_mime_types[TEST_MIME_TYPE_TEXT]) == 0) { | ||
49 | /* We're returning the string "TEST", with no termination */ | ||
50 | static const char *test_text = "XXX TEST XXX"; | ||
51 | *length = 4; | ||
52 | return test_text + 4; | ||
53 | } | ||
54 | if (SDL_strcmp(mime_type, test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT]) == 0) { | ||
55 | /* We're returning the string "CUSTOM", with no termination */ | ||
56 | static const char *custom_text = "XXX CUSTOM XXX"; | ||
57 | *length = 6; | ||
58 | return custom_text + 4; | ||
59 | } | ||
60 | if (SDL_strcmp(mime_type, test_mime_types[TEST_MIME_TYPE_DATA]) == 0) { | ||
61 | *length = test_data->data_size; | ||
62 | return test_data->data; | ||
63 | } | ||
64 | return NULL; | ||
65 | } | ||
66 | |||
67 | static int clipboard_cleanup_count; | ||
68 | |||
69 | static void SDLCALL ClipboardCleanupCallback(void *userdata) | ||
70 | { | ||
71 | ++clipboard_cleanup_count; | ||
72 | } | ||
73 | |||
74 | /* Test case functions */ | ||
75 | |||
76 | /** | ||
77 | * End-to-end test of SDL_xyzClipboardData functions | ||
78 | * \sa SDL_HasClipboardData | ||
79 | * \sa SDL_GetClipboardData | ||
80 | * \sa SDL_SetClipboardData | ||
81 | */ | ||
82 | static int SDLCALL clipboard_testClipboardDataFunctions(void *arg) | ||
83 | { | ||
84 | int result = -1; | ||
85 | bool boolResult; | ||
86 | int last_clipboard_update_count; | ||
87 | int last_clipboard_callback_count; | ||
88 | int last_clipboard_cleanup_count; | ||
89 | void *data; | ||
90 | size_t size; | ||
91 | char *text; | ||
92 | const char *expected_text; | ||
93 | |||
94 | TestClipboardData test_data1 = { | ||
95 | &test_data1, | ||
96 | sizeof(test_data1) | ||
97 | }; | ||
98 | TestClipboardData test_data2 = { | ||
99 | &last_clipboard_callback_count, | ||
100 | sizeof(last_clipboard_callback_count) | ||
101 | }; | ||
102 | |||
103 | SDL_AddEventWatch(ClipboardEventWatch, NULL); | ||
104 | |||
105 | /* Test clearing clipboard data */ | ||
106 | result = SDL_ClearClipboardData(); | ||
107 | SDLTest_AssertCheck( | ||
108 | result == true, | ||
109 | "Validate SDL_ClearClipboardData result, expected true, got %i", | ||
110 | result); | ||
111 | expected_text = ""; | ||
112 | text = SDL_GetClipboardText(); | ||
113 | SDLTest_AssertCheck( | ||
114 | text && SDL_strcmp(text, expected_text) == 0, | ||
115 | "Verify clipboard text, expected \"%s\", got \"%s\"", | ||
116 | expected_text, text); | ||
117 | SDL_free(text); | ||
118 | |||
119 | /* Test clearing clipboard data when it's already clear */ | ||
120 | last_clipboard_update_count = clipboard_update_count; | ||
121 | result = SDL_ClearClipboardData(); | ||
122 | SDLTest_AssertCheck( | ||
123 | result == true, | ||
124 | "Validate SDL_ClearClipboardData result, expected true, got %i", | ||
125 | result); | ||
126 | SDLTest_AssertCheck( | ||
127 | clipboard_update_count != last_clipboard_update_count, | ||
128 | "Verify clipboard update count changed, got %d", | ||
129 | clipboard_update_count - last_clipboard_update_count); | ||
130 | |||
131 | /* Validate error handling */ | ||
132 | last_clipboard_update_count = clipboard_update_count; | ||
133 | result = SDL_SetClipboardData(NULL, NULL, NULL, test_mime_types, SDL_arraysize(test_mime_types)); | ||
134 | SDLTest_AssertCheck( | ||
135 | result == false, | ||
136 | "Validate SDL_SetClipboardData(invalid) result, expected false, got %i", | ||
137 | result); | ||
138 | SDLTest_AssertCheck( | ||
139 | clipboard_update_count == last_clipboard_update_count, | ||
140 | "Verify clipboard update count unchanged, got %d", | ||
141 | clipboard_update_count - last_clipboard_update_count); | ||
142 | |||
143 | last_clipboard_update_count = clipboard_update_count; | ||
144 | result = SDL_SetClipboardData(ClipboardDataCallback, ClipboardCleanupCallback, NULL, NULL, 0); | ||
145 | SDLTest_AssertCheck( | ||
146 | result == false, | ||
147 | "Validate SDL_SetClipboardData(invalid) result, expected false, got %i", | ||
148 | result); | ||
149 | SDLTest_AssertCheck( | ||
150 | clipboard_update_count == last_clipboard_update_count, | ||
151 | "Verify clipboard update count unchanged, got %d", | ||
152 | clipboard_update_count - last_clipboard_update_count); | ||
153 | |||
154 | /* Test setting and getting clipboard data */ | ||
155 | last_clipboard_update_count = clipboard_update_count; | ||
156 | last_clipboard_callback_count = clipboard_callback_count; | ||
157 | last_clipboard_cleanup_count = clipboard_cleanup_count; | ||
158 | result = SDL_SetClipboardData(ClipboardDataCallback, ClipboardCleanupCallback, &test_data1, test_mime_types, SDL_arraysize(test_mime_types)); | ||
159 | SDLTest_AssertCheck( | ||
160 | result == true, | ||
161 | "Validate SDL_SetClipboardData(test_data1) result, expected true, got %i", | ||
162 | result); | ||
163 | SDLTest_AssertCheck( | ||
164 | clipboard_update_count == last_clipboard_update_count + 1, | ||
165 | "Verify clipboard update count incremented by 1, got %d", | ||
166 | clipboard_update_count - last_clipboard_update_count); | ||
167 | SDLTest_AssertCheck( | ||
168 | clipboard_cleanup_count == last_clipboard_cleanup_count, | ||
169 | "Verify clipboard cleanup count unchanged, got %d", | ||
170 | clipboard_cleanup_count - last_clipboard_cleanup_count); | ||
171 | |||
172 | expected_text = "TEST"; | ||
173 | text = SDL_GetClipboardText(); | ||
174 | SDLTest_AssertCheck( | ||
175 | text && SDL_strcmp(text, expected_text) == 0, | ||
176 | "Verify clipboard text, expected \"%s\", got \"%s\"", | ||
177 | expected_text, text); | ||
178 | SDL_free(text); | ||
179 | |||
180 | boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT]); | ||
181 | SDLTest_AssertCheck( | ||
182 | boolResult, | ||
183 | "Verify has test text data, expected true, got false"); | ||
184 | text = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT], &size); | ||
185 | SDLTest_AssertCheck( | ||
186 | text != NULL, | ||
187 | "Verify has test text data, expected valid result, got NULL"); | ||
188 | if (text) { | ||
189 | SDLTest_AssertCheck( | ||
190 | text[size] == '\0', | ||
191 | "Verify test text data, expected null termination, got %c", | ||
192 | text[size]); | ||
193 | SDLTest_AssertCheck( | ||
194 | SDL_strcmp(text, expected_text) == 0, | ||
195 | "Verify test text data, expected \"%s\", got \"%s\"", | ||
196 | expected_text, text); | ||
197 | } | ||
198 | SDLTest_AssertCheck( | ||
199 | size == SDL_strlen(expected_text), | ||
200 | "Verify test text size, expected %d, got %d", | ||
201 | (int)SDL_strlen(expected_text), (int)size); | ||
202 | SDL_free(text); | ||
203 | |||
204 | expected_text = "CUSTOM"; | ||
205 | boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT]); | ||
206 | SDLTest_AssertCheck( | ||
207 | boolResult, | ||
208 | "Verify has test text data, expected true, got false"); | ||
209 | text = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT], &size); | ||
210 | SDLTest_AssertCheck( | ||
211 | text != NULL, | ||
212 | "Verify has test text data, expected valid result, got NULL"); | ||
213 | if (text) { | ||
214 | SDLTest_AssertCheck( | ||
215 | text[size] == '\0', | ||
216 | "Verify test text data, expected null termination, got %c", | ||
217 | text[size]); | ||
218 | SDLTest_AssertCheck( | ||
219 | SDL_strcmp(text, expected_text) == 0, | ||
220 | "Verify test text data, expected \"%s\", got \"%s\"", | ||
221 | expected_text, text); | ||
222 | } | ||
223 | SDLTest_AssertCheck( | ||
224 | size == SDL_strlen(expected_text), | ||
225 | "Verify test text size, expected %d, got %d", | ||
226 | (int)SDL_strlen(expected_text), (int)size); | ||
227 | SDL_free(text); | ||
228 | |||
229 | boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_DATA]); | ||
230 | SDLTest_AssertCheck( | ||
231 | boolResult, | ||
232 | "Verify has test text data, expected true, got false"); | ||
233 | data = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_DATA], &size); | ||
234 | SDLTest_AssertCheck( | ||
235 | data && SDL_memcmp(data, test_data1.data, test_data1.data_size) == 0, | ||
236 | "Verify test data"); | ||
237 | SDLTest_AssertCheck( | ||
238 | size == test_data1.data_size, | ||
239 | "Verify test data size, expected %d, got %d", | ||
240 | (int)test_data1.data_size, (int)size); | ||
241 | SDL_free(data); | ||
242 | |||
243 | boolResult = SDL_HasClipboardData("test/invalid"); | ||
244 | SDLTest_AssertCheck( | ||
245 | !boolResult, | ||
246 | "Verify has test text data, expected false, got true"); | ||
247 | data = SDL_GetClipboardData("test/invalid", &size); | ||
248 | SDLTest_AssertCheck( | ||
249 | data == NULL, | ||
250 | "Verify invalid data, expected NULL, got %p", | ||
251 | data); | ||
252 | SDLTest_AssertCheck( | ||
253 | size == 0, | ||
254 | "Verify invalid data size, expected 0, got %d", | ||
255 | (int)size); | ||
256 | SDL_free(data); | ||
257 | |||
258 | #if 0 /* There's no guarantee how or when the callback is called */ | ||
259 | SDLTest_AssertCheck( | ||
260 | (clipboard_callback_count == last_clipboard_callback_count + 3) || | ||
261 | (clipboard_callback_count == last_clipboard_callback_count + 4), | ||
262 | "Verify clipboard callback count incremented by 3 or 4, got %d", | ||
263 | clipboard_callback_count - last_clipboard_callback_count); | ||
264 | #endif | ||
265 | |||
266 | /* Test setting and getting clipboard data again */ | ||
267 | last_clipboard_update_count = clipboard_update_count; | ||
268 | last_clipboard_callback_count = clipboard_callback_count; | ||
269 | last_clipboard_cleanup_count = clipboard_cleanup_count; | ||
270 | result = SDL_SetClipboardData(ClipboardDataCallback, ClipboardCleanupCallback, &test_data2, test_mime_types, SDL_arraysize(test_mime_types)); | ||
271 | SDLTest_AssertCheck( | ||
272 | result == true, | ||
273 | "Validate SDL_SetClipboardData(test_data2) result, expected true, got %i", | ||
274 | result); | ||
275 | SDLTest_AssertCheck( | ||
276 | clipboard_update_count == last_clipboard_update_count + 1, | ||
277 | "Verify clipboard update count incremented by 1, got %d", | ||
278 | clipboard_update_count - last_clipboard_update_count); | ||
279 | SDLTest_AssertCheck( | ||
280 | clipboard_cleanup_count == last_clipboard_cleanup_count + 1, | ||
281 | "Verify clipboard cleanup count incremented by 1, got %d", | ||
282 | clipboard_cleanup_count - last_clipboard_cleanup_count); | ||
283 | |||
284 | expected_text = "TEST"; | ||
285 | text = SDL_GetClipboardText(); | ||
286 | SDLTest_AssertCheck( | ||
287 | text && SDL_strcmp(text, expected_text) == 0, | ||
288 | "Verify clipboard text, expected \"%s\", got \"%s\"", | ||
289 | expected_text, text); | ||
290 | SDL_free(text); | ||
291 | |||
292 | boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT]); | ||
293 | SDLTest_AssertCheck( | ||
294 | boolResult, | ||
295 | "Verify has test text data, expected true, got false"); | ||
296 | text = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT], &size); | ||
297 | SDLTest_AssertCheck( | ||
298 | text != NULL, | ||
299 | "Verify has test text data, expected valid result, got NULL"); | ||
300 | if (text) { | ||
301 | SDLTest_AssertCheck( | ||
302 | text[size] == '\0', | ||
303 | "Verify test text data, expected null termination, got %c", | ||
304 | text[size]); | ||
305 | SDLTest_AssertCheck( | ||
306 | SDL_strcmp(text, expected_text) == 0, | ||
307 | "Verify test text data, expected \"%s\", got \"%s\"", | ||
308 | expected_text, text); | ||
309 | } | ||
310 | SDLTest_AssertCheck( | ||
311 | size == SDL_strlen(expected_text), | ||
312 | "Verify test text size, expected %d, got %d", | ||
313 | (int)SDL_strlen(expected_text), (int)size); | ||
314 | SDL_free(text); | ||
315 | |||
316 | expected_text = "CUSTOM"; | ||
317 | boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT]); | ||
318 | SDLTest_AssertCheck( | ||
319 | boolResult, | ||
320 | "Verify has test text data, expected true, got false"); | ||
321 | text = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT], &size); | ||
322 | SDLTest_AssertCheck( | ||
323 | text != NULL, | ||
324 | "Verify has test text data, expected valid result, got NULL"); | ||
325 | if (text) { | ||
326 | SDLTest_AssertCheck( | ||
327 | text[size] == '\0', | ||
328 | "Verify test text data, expected null termination, got %c", | ||
329 | text[size]); | ||
330 | SDLTest_AssertCheck( | ||
331 | SDL_strcmp(text, expected_text) == 0, | ||
332 | "Verify test text data, expected \"%s\", got \"%s\"", | ||
333 | expected_text, text); | ||
334 | } | ||
335 | SDLTest_AssertCheck( | ||
336 | size == SDL_strlen(expected_text), | ||
337 | "Verify test text size, expected %d, got %d", | ||
338 | (int)SDL_strlen(expected_text), (int)size); | ||
339 | SDL_free(text); | ||
340 | |||
341 | data = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_DATA], &size); | ||
342 | SDLTest_AssertCheck( | ||
343 | data && SDL_memcmp(data, test_data2.data, test_data2.data_size) == 0, | ||
344 | "Verify test data"); | ||
345 | SDLTest_AssertCheck( | ||
346 | size == test_data2.data_size, | ||
347 | "Verify test data size, expected %d, got %d", | ||
348 | (int)test_data2.data_size, (int)size); | ||
349 | SDL_free(data); | ||
350 | |||
351 | data = SDL_GetClipboardData("test/invalid", &size); | ||
352 | SDLTest_AssertCheck( | ||
353 | data == NULL, | ||
354 | "Verify invalid data, expected NULL, got %p", | ||
355 | data); | ||
356 | SDLTest_AssertCheck( | ||
357 | size == 0, | ||
358 | "Verify invalid data size, expected 0, got %d", | ||
359 | (int)size); | ||
360 | SDL_free(data); | ||
361 | |||
362 | #if 0 /* There's no guarantee how or when the callback is called */ | ||
363 | SDLTest_AssertCheck( | ||
364 | (clipboard_callback_count == last_clipboard_callback_count + 3) || | ||
365 | (clipboard_callback_count == last_clipboard_callback_count + 4), | ||
366 | "Verify clipboard callback count incremented by 3 or 4, got %d", | ||
367 | clipboard_callback_count - last_clipboard_callback_count); | ||
368 | #endif | ||
369 | |||
370 | /* Test clearing clipboard data when has data */ | ||
371 | last_clipboard_update_count = clipboard_update_count; | ||
372 | last_clipboard_cleanup_count = clipboard_cleanup_count; | ||
373 | result = SDL_ClearClipboardData(); | ||
374 | SDLTest_AssertCheck( | ||
375 | result == true, | ||
376 | "Validate SDL_ClearClipboardData result, expected true, got %i", | ||
377 | result); | ||
378 | SDLTest_AssertCheck( | ||
379 | clipboard_update_count == last_clipboard_update_count + 1, | ||
380 | "Verify clipboard update count incremented by 1, got %d", | ||
381 | clipboard_update_count - last_clipboard_update_count); | ||
382 | SDLTest_AssertCheck( | ||
383 | clipboard_cleanup_count == last_clipboard_cleanup_count + 1, | ||
384 | "Verify clipboard cleanup count incremented by 1, got %d", | ||
385 | clipboard_cleanup_count - last_clipboard_cleanup_count); | ||
386 | boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT]); | ||
387 | SDLTest_AssertCheck( | ||
388 | !boolResult, | ||
389 | "Verify has test text data, expected false, got true"); | ||
390 | boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_DATA]); | ||
391 | SDLTest_AssertCheck( | ||
392 | !boolResult, | ||
393 | "Verify has test text data, expected false, got true"); | ||
394 | boolResult = SDL_HasClipboardData("test/invalid"); | ||
395 | SDLTest_AssertCheck( | ||
396 | !boolResult, | ||
397 | "Verify has test text data, expected false, got true"); | ||
398 | |||
399 | SDL_RemoveEventWatch(ClipboardEventWatch, NULL); | ||
400 | |||
401 | return TEST_COMPLETED; | ||
402 | } | ||
403 | |||
404 | /** | ||
405 | * End-to-end test of SDL_xyzClipboardText functions | ||
406 | * \sa SDL_HasClipboardText | ||
407 | * \sa SDL_GetClipboardText | ||
408 | * \sa SDL_SetClipboardText | ||
409 | */ | ||
410 | static int SDLCALL clipboard_testClipboardTextFunctions(void *arg) | ||
411 | { | ||
412 | char *textRef = SDLTest_RandomAsciiString(); | ||
413 | char *text = SDL_strdup(textRef); | ||
414 | bool boolResult; | ||
415 | int intResult; | ||
416 | char *charResult; | ||
417 | int last_clipboard_update_count; | ||
418 | |||
419 | SDL_AddEventWatch(ClipboardEventWatch, NULL); | ||
420 | |||
421 | /* Empty clipboard text */ | ||
422 | last_clipboard_update_count = clipboard_update_count; | ||
423 | intResult = SDL_SetClipboardText(NULL); | ||
424 | SDLTest_AssertCheck( | ||
425 | intResult == true, | ||
426 | "Verify result from SDL_SetClipboardText(NULL), expected true, got %i", | ||
427 | intResult); | ||
428 | charResult = SDL_GetClipboardText(); | ||
429 | SDLTest_AssertCheck( | ||
430 | charResult && SDL_strcmp(charResult, "") == 0, | ||
431 | "Verify SDL_GetClipboardText returned \"\", got %s", | ||
432 | charResult); | ||
433 | SDL_free(charResult); | ||
434 | boolResult = SDL_HasClipboardText(); | ||
435 | SDLTest_AssertCheck( | ||
436 | boolResult == false, | ||
437 | "Verify SDL_HasClipboardText returned false, got %s", | ||
438 | (boolResult) ? "true" : "false"); | ||
439 | SDLTest_AssertCheck( | ||
440 | clipboard_update_count == last_clipboard_update_count + 1, | ||
441 | "Verify clipboard update count incremented by 1, got %d", | ||
442 | clipboard_update_count - last_clipboard_update_count); | ||
443 | |||
444 | |||
445 | /* Set clipboard text */ | ||
446 | last_clipboard_update_count = clipboard_update_count; | ||
447 | intResult = SDL_SetClipboardText(text); | ||
448 | SDLTest_AssertCheck( | ||
449 | intResult == true, | ||
450 | "Verify result from SDL_SetClipboardText(%s), expected true, got %i", text, | ||
451 | intResult); | ||
452 | SDLTest_AssertCheck( | ||
453 | SDL_strcmp(textRef, text) == 0, | ||
454 | "Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'", | ||
455 | textRef, text); | ||
456 | boolResult = SDL_HasClipboardText(); | ||
457 | SDLTest_AssertCheck( | ||
458 | boolResult == true, | ||
459 | "Verify SDL_HasClipboardText returned true, got %s", | ||
460 | (boolResult) ? "true" : "false"); | ||
461 | charResult = SDL_GetClipboardText(); | ||
462 | SDLTest_AssertCheck( | ||
463 | charResult && SDL_strcmp(textRef, charResult) == 0, | ||
464 | "Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'", | ||
465 | textRef, charResult); | ||
466 | SDL_free(charResult); | ||
467 | SDLTest_AssertCheck( | ||
468 | clipboard_update_count == last_clipboard_update_count + 1, | ||
469 | "Verify clipboard update count incremented by 1, got %d", | ||
470 | clipboard_update_count - last_clipboard_update_count); | ||
471 | |||
472 | /* Reset clipboard text */ | ||
473 | intResult = SDL_SetClipboardText(NULL); | ||
474 | SDLTest_AssertCheck( | ||
475 | intResult == true, | ||
476 | "Verify result from SDL_SetClipboardText(NULL), expected true, got %i", | ||
477 | intResult); | ||
478 | |||
479 | /* Cleanup */ | ||
480 | SDL_free(textRef); | ||
481 | SDL_free(text); | ||
482 | |||
483 | SDL_RemoveEventWatch(ClipboardEventWatch, NULL); | ||
484 | |||
485 | return TEST_COMPLETED; | ||
486 | } | ||
487 | |||
488 | /** | ||
489 | * End-to-end test of SDL_xyzPrimarySelectionText functions | ||
490 | * \sa SDL_HasPrimarySelectionText | ||
491 | * \sa SDL_GetPrimarySelectionText | ||
492 | * \sa SDL_SetPrimarySelectionText | ||
493 | */ | ||
494 | static int SDLCALL clipboard_testPrimarySelectionTextFunctions(void *arg) | ||
495 | { | ||
496 | char *textRef = SDLTest_RandomAsciiString(); | ||
497 | char *text = SDL_strdup(textRef); | ||
498 | bool boolResult; | ||
499 | int intResult; | ||
500 | char *charResult; | ||
501 | int last_clipboard_update_count; | ||
502 | |||
503 | SDL_AddEventWatch(ClipboardEventWatch, NULL); | ||
504 | |||
505 | /* Empty primary selection */ | ||
506 | last_clipboard_update_count = clipboard_update_count; | ||
507 | intResult = SDL_SetPrimarySelectionText(NULL); | ||
508 | SDLTest_AssertCheck( | ||
509 | intResult == true, | ||
510 | "Verify result from SDL_SetPrimarySelectionText(NULL), expected true, got %i", | ||
511 | intResult); | ||
512 | charResult = SDL_GetPrimarySelectionText(); | ||
513 | SDLTest_AssertCheck( | ||
514 | charResult && SDL_strcmp(charResult, "") == 0, | ||
515 | "Verify SDL_GetPrimarySelectionText returned \"\", got %s", | ||
516 | charResult); | ||
517 | SDL_free(charResult); | ||
518 | boolResult = SDL_HasPrimarySelectionText(); | ||
519 | SDLTest_AssertCheck( | ||
520 | boolResult == false, | ||
521 | "Verify SDL_HasPrimarySelectionText returned false, got %s", | ||
522 | (boolResult) ? "true" : "false"); | ||
523 | SDLTest_AssertCheck( | ||
524 | clipboard_update_count == last_clipboard_update_count + 1, | ||
525 | "Verify clipboard update count incremented by 1, got %d", | ||
526 | clipboard_update_count - last_clipboard_update_count); | ||
527 | |||
528 | /* Set primary selection */ | ||
529 | last_clipboard_update_count = clipboard_update_count; | ||
530 | intResult = SDL_SetPrimarySelectionText(text); | ||
531 | SDLTest_AssertCheck( | ||
532 | intResult == true, | ||
533 | "Verify result from SDL_SetPrimarySelectionText(%s), expected true, got %i", text, | ||
534 | intResult); | ||
535 | SDLTest_AssertCheck( | ||
536 | SDL_strcmp(textRef, text) == 0, | ||
537 | "Verify SDL_SetPrimarySelectionText did not modify input string, expected '%s', got '%s'", | ||
538 | textRef, text); | ||
539 | boolResult = SDL_HasPrimarySelectionText(); | ||
540 | SDLTest_AssertCheck( | ||
541 | boolResult == true, | ||
542 | "Verify SDL_HasPrimarySelectionText returned true, got %s", | ||
543 | (boolResult) ? "true" : "false"); | ||
544 | charResult = SDL_GetPrimarySelectionText(); | ||
545 | SDLTest_AssertCheck( | ||
546 | charResult && SDL_strcmp(textRef, charResult) == 0, | ||
547 | "Verify SDL_GetPrimarySelectionText returned correct string, expected '%s', got '%s'", | ||
548 | textRef, charResult); | ||
549 | SDL_free(charResult); | ||
550 | SDLTest_AssertCheck( | ||
551 | clipboard_update_count == last_clipboard_update_count + 1, | ||
552 | "Verify clipboard update count incremented by 1, got %d", | ||
553 | clipboard_update_count - last_clipboard_update_count); | ||
554 | |||
555 | /* Reset primary selection */ | ||
556 | intResult = SDL_SetPrimarySelectionText(NULL); | ||
557 | SDLTest_AssertCheck( | ||
558 | intResult == true, | ||
559 | "Verify result from SDL_SetPrimarySelectionText(NULL), expected true, got %i", | ||
560 | intResult); | ||
561 | |||
562 | /* Cleanup */ | ||
563 | SDL_free(textRef); | ||
564 | SDL_free(text); | ||
565 | |||
566 | SDL_RemoveEventWatch(ClipboardEventWatch, NULL); | ||
567 | |||
568 | return TEST_COMPLETED; | ||
569 | } | ||
570 | |||
571 | /* ================= Test References ================== */ | ||
572 | |||
573 | static const SDLTest_TestCaseReference clipboardTest1 = { | ||
574 | clipboard_testClipboardDataFunctions, "clipboard_testClipboardDataFunctions", "End-to-end test of SDL_xyzClipboardData functions", TEST_ENABLED | ||
575 | }; | ||
576 | |||
577 | static const SDLTest_TestCaseReference clipboardTest2 = { | ||
578 | clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED | ||
579 | }; | ||
580 | |||
581 | static const SDLTest_TestCaseReference clipboardTest3 = { | ||
582 | clipboard_testPrimarySelectionTextFunctions, "clipboard_testPrimarySelectionTextFunctions", "End-to-end test of SDL_xyzPrimarySelectionText functions", TEST_ENABLED | ||
583 | }; | ||
584 | |||
585 | /* Sequence of Clipboard test cases */ | ||
586 | static const SDLTest_TestCaseReference *clipboardTests[] = { | ||
587 | &clipboardTest1, &clipboardTest2, &clipboardTest3, NULL | ||
588 | }; | ||
589 | |||
590 | /* Clipboard test suite (global) */ | ||
591 | SDLTest_TestSuiteReference clipboardTestSuite = { | ||
592 | "Clipboard", | ||
593 | NULL, | ||
594 | clipboardTests, | ||
595 | NULL | ||
596 | }; | ||