testautomation_clipboard.c 21 KB

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