testautomation_clipboard.c 21 KB

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