testautomation_clipboard.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  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. char *charResult;
  379. int last_clipboard_update_count;
  380. SDL_AddEventWatch(ClipboardEventWatch, NULL);
  381. /* Empty clipboard text */
  382. last_clipboard_update_count = clipboard_update_count;
  383. boolResult = SDL_SetClipboardText(NULL);
  384. SDLTest_AssertCheck(
  385. boolResult == true,
  386. "Verify result from SDL_SetClipboardText(NULL), expected true, got %s",
  387. boolResult ? "true" : "false");
  388. charResult = SDL_GetClipboardText();
  389. SDLTest_AssertCheck(
  390. charResult && SDL_strcmp(charResult, "") == 0,
  391. "Verify SDL_GetClipboardText returned \"\", got %s",
  392. charResult);
  393. SDL_free(charResult);
  394. boolResult = SDL_HasClipboardText();
  395. SDLTest_AssertCheck(
  396. boolResult == false,
  397. "Verify SDL_HasClipboardText returned false, got %s",
  398. boolResult ? "true" : "false");
  399. SDLTest_AssertCheck(
  400. clipboard_update_count == last_clipboard_update_count + 1,
  401. "Verify clipboard update count incremented by 1, got %d",
  402. clipboard_update_count - last_clipboard_update_count);
  403. /* Set clipboard text */
  404. last_clipboard_update_count = clipboard_update_count;
  405. boolResult = SDL_SetClipboardText(text);
  406. SDLTest_AssertCheck(
  407. boolResult == true,
  408. "Verify result from SDL_SetClipboardText(%s), expected true, got %s", text,
  409. boolResult ? "true" : "false");
  410. SDLTest_AssertCheck(
  411. SDL_strcmp(textRef, text) == 0,
  412. "Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
  413. textRef, text);
  414. boolResult = SDL_HasClipboardText();
  415. SDLTest_AssertCheck(
  416. boolResult == true,
  417. "Verify SDL_HasClipboardText returned true, got %s",
  418. boolResult ? "true" : "false");
  419. charResult = SDL_GetClipboardText();
  420. SDLTest_AssertCheck(
  421. charResult && SDL_strcmp(textRef, charResult) == 0,
  422. "Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'",
  423. textRef, charResult);
  424. SDL_free(charResult);
  425. SDLTest_AssertCheck(
  426. clipboard_update_count == last_clipboard_update_count + 1,
  427. "Verify clipboard update count incremented by 1, got %d",
  428. clipboard_update_count - last_clipboard_update_count);
  429. /* Reset clipboard text */
  430. boolResult = SDL_SetClipboardText(NULL);
  431. SDLTest_AssertCheck(
  432. boolResult == true,
  433. "Verify result from SDL_SetClipboardText(NULL), expected true, got %s",
  434. boolResult ? "true" : "false");
  435. /* Cleanup */
  436. SDL_free(textRef);
  437. SDL_free(text);
  438. SDL_RemoveEventWatch(ClipboardEventWatch, NULL);
  439. return TEST_COMPLETED;
  440. }
  441. /**
  442. * End-to-end test of SDL_xyzPrimarySelectionText functions
  443. * \sa SDL_HasPrimarySelectionText
  444. * \sa SDL_GetPrimarySelectionText
  445. * \sa SDL_SetPrimarySelectionText
  446. */
  447. static int SDLCALL clipboard_testPrimarySelectionTextFunctions(void *arg)
  448. {
  449. char *textRef = SDLTest_RandomAsciiString();
  450. char *text = SDL_strdup(textRef);
  451. bool boolResult;
  452. char *charResult;
  453. int last_clipboard_update_count;
  454. SDL_AddEventWatch(ClipboardEventWatch, NULL);
  455. /* Empty primary selection */
  456. last_clipboard_update_count = clipboard_update_count;
  457. boolResult = SDL_SetPrimarySelectionText(NULL);
  458. SDLTest_AssertCheck(
  459. boolResult == true,
  460. "Verify result from SDL_SetPrimarySelectionText(NULL), expected true, got %s",
  461. boolResult ? "true" : "false");
  462. charResult = SDL_GetPrimarySelectionText();
  463. SDLTest_AssertCheck(
  464. charResult && SDL_strcmp(charResult, "") == 0,
  465. "Verify SDL_GetPrimarySelectionText returned \"\", got %s",
  466. charResult);
  467. SDL_free(charResult);
  468. boolResult = SDL_HasPrimarySelectionText();
  469. SDLTest_AssertCheck(
  470. boolResult == false,
  471. "Verify SDL_HasPrimarySelectionText returned false, got %s",
  472. boolResult ? "true" : "false");
  473. SDLTest_AssertCheck(
  474. clipboard_update_count == last_clipboard_update_count + 1,
  475. "Verify clipboard update count incremented by 1, got %d",
  476. clipboard_update_count - last_clipboard_update_count);
  477. /* Set primary selection */
  478. last_clipboard_update_count = clipboard_update_count;
  479. boolResult = SDL_SetPrimarySelectionText(text);
  480. SDLTest_AssertCheck(
  481. boolResult == true,
  482. "Verify result from SDL_SetPrimarySelectionText(%s), expected true, got %s", text,
  483. boolResult ? "true" : "false");
  484. SDLTest_AssertCheck(
  485. SDL_strcmp(textRef, text) == 0,
  486. "Verify SDL_SetPrimarySelectionText did not modify input string, expected '%s', got '%s'",
  487. textRef, text);
  488. boolResult = SDL_HasPrimarySelectionText();
  489. SDLTest_AssertCheck(
  490. boolResult == true,
  491. "Verify SDL_HasPrimarySelectionText returned true, got %s",
  492. boolResult ? "true" : "false");
  493. charResult = SDL_GetPrimarySelectionText();
  494. SDLTest_AssertCheck(
  495. charResult && SDL_strcmp(textRef, charResult) == 0,
  496. "Verify SDL_GetPrimarySelectionText returned correct string, expected '%s', got '%s'",
  497. textRef, charResult);
  498. SDL_free(charResult);
  499. SDLTest_AssertCheck(
  500. clipboard_update_count == last_clipboard_update_count + 1,
  501. "Verify clipboard update count incremented by 1, got %d",
  502. clipboard_update_count - last_clipboard_update_count);
  503. /* Reset primary selection */
  504. boolResult = SDL_SetPrimarySelectionText(NULL);
  505. SDLTest_AssertCheck(
  506. boolResult == true,
  507. "Verify result from SDL_SetPrimarySelectionText(NULL), expected true, got %s",
  508. boolResult ? "true" : "false");
  509. /* Cleanup */
  510. SDL_free(textRef);
  511. SDL_free(text);
  512. SDL_RemoveEventWatch(ClipboardEventWatch, NULL);
  513. return TEST_COMPLETED;
  514. }
  515. /* ================= Test References ================== */
  516. static const SDLTest_TestCaseReference clipboardTest1 = {
  517. clipboard_testClipboardDataFunctions, "clipboard_testClipboardDataFunctions", "End-to-end test of SDL_xyzClipboardData functions", TEST_ENABLED
  518. };
  519. static const SDLTest_TestCaseReference clipboardTest2 = {
  520. clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED
  521. };
  522. static const SDLTest_TestCaseReference clipboardTest3 = {
  523. clipboard_testPrimarySelectionTextFunctions, "clipboard_testPrimarySelectionTextFunctions", "End-to-end test of SDL_xyzPrimarySelectionText functions", TEST_ENABLED
  524. };
  525. /* Sequence of Clipboard test cases */
  526. static const SDLTest_TestCaseReference *clipboardTests[] = {
  527. &clipboardTest1, &clipboardTest2, &clipboardTest3, NULL
  528. };
  529. /* Clipboard test suite (global) */
  530. SDLTest_TestSuiteReference clipboardTestSuite = {
  531. "Clipboard",
  532. NULL,
  533. clipboardTests,
  534. NULL
  535. };