testautomation_clipboard.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /**
  2. * New/updated tests: aschiffler at ferzkopp dot net
  3. */
  4. #include <SDL3/SDL.h>
  5. #include <SDL3/SDL_test.h>
  6. /* ================= Test Case Implementation ================== */
  7. /* Test case functions */
  8. /**
  9. * \brief Check call to SDL_HasClipboardText
  10. *
  11. * \sa
  12. * http://wiki.libsdl.org/SDL_HasClipboardText
  13. */
  14. int
  15. clipboard_testHasClipboardText(void *arg)
  16. {
  17. SDL_HasClipboardText();
  18. SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
  19. return TEST_COMPLETED;
  20. }
  21. /**
  22. * \brief Check call to SDL_HasPrimarySelectionText
  23. *
  24. * \sa
  25. * http://wiki.libsdl.org/SDL_HasPrimarySelectionText
  26. */
  27. int
  28. clipboard_testHasPrimarySelectionText(void *arg)
  29. {
  30. SDL_HasPrimarySelectionText();
  31. SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
  32. return TEST_COMPLETED;
  33. }
  34. /**
  35. * \brief Check call to SDL_GetClipboardText
  36. *
  37. * \sa
  38. * http://wiki.libsdl.org/SDL_GetClipboardText
  39. */
  40. int
  41. clipboard_testGetClipboardText(void *arg)
  42. {
  43. char *charResult;
  44. charResult = SDL_GetClipboardText();
  45. SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
  46. SDL_free(charResult);
  47. return TEST_COMPLETED;
  48. }
  49. /**
  50. * \brief Check call to SDL_GetPrimarySelectionText
  51. *
  52. * \sa
  53. * http://wiki.libsdl.org/SDL_GetPrimarySelectionText
  54. */
  55. int
  56. clipboard_testGetPrimarySelectionText(void *arg)
  57. {
  58. char *charResult;
  59. charResult = SDL_GetPrimarySelectionText();
  60. SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded");
  61. SDL_free(charResult);
  62. return TEST_COMPLETED;
  63. }
  64. /**
  65. * \brief Check call to SDL_SetClipboardText
  66. * \sa
  67. * http://wiki.libsdl.org/SDL_SetClipboardText
  68. */
  69. int
  70. clipboard_testSetClipboardText(void *arg)
  71. {
  72. char *textRef = SDLTest_RandomAsciiString();
  73. char *text = SDL_strdup(textRef);
  74. int result;
  75. result = SDL_SetClipboardText((const char *)text);
  76. SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
  77. SDLTest_AssertCheck(
  78. result == 0,
  79. "Validate SDL_SetClipboardText result, expected 0, got %i",
  80. result);
  81. SDLTest_AssertCheck(
  82. SDL_strcmp(textRef, text) == 0,
  83. "Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
  84. textRef, text);
  85. /* Cleanup */
  86. SDL_free(textRef);
  87. SDL_free(text);
  88. return TEST_COMPLETED;
  89. }
  90. /**
  91. * \brief Check call to SDL_SetPrimarySelectionText
  92. * \sa
  93. * http://wiki.libsdl.org/SDL_SetPrimarySelectionText
  94. */
  95. int
  96. clipboard_testSetPrimarySelectionText(void *arg)
  97. {
  98. char *textRef = SDLTest_RandomAsciiString();
  99. char *text = SDL_strdup(textRef);
  100. int result;
  101. result = SDL_SetPrimarySelectionText((const char *)text);
  102. SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText succeeded");
  103. SDLTest_AssertCheck(
  104. result == 0,
  105. "Validate SDL_SetPrimarySelectionText result, expected 0, got %i",
  106. result);
  107. SDLTest_AssertCheck(
  108. SDL_strcmp(textRef, text) == 0,
  109. "Verify SDL_SetPrimarySelectionText did not modify input string, expected '%s', got '%s'",
  110. textRef, text);
  111. /* Cleanup */
  112. SDL_free(textRef);
  113. SDL_free(text);
  114. return TEST_COMPLETED;
  115. }
  116. /**
  117. * \brief End-to-end test of SDL_xyzClipboardText functions
  118. * \sa
  119. * http://wiki.libsdl.org/SDL_HasClipboardText
  120. * http://wiki.libsdl.org/SDL_GetClipboardText
  121. * http://wiki.libsdl.org/SDL_SetClipboardText
  122. */
  123. int
  124. clipboard_testClipboardTextFunctions(void *arg)
  125. {
  126. char *textRef = SDLTest_RandomAsciiString();
  127. char *text = SDL_strdup(textRef);
  128. SDL_bool boolResult;
  129. int intResult;
  130. char *charResult;
  131. /* Clear clipboard text state */
  132. boolResult = SDL_HasClipboardText();
  133. SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
  134. if (boolResult == SDL_TRUE) {
  135. intResult = SDL_SetClipboardText((const char *)NULL);
  136. SDLTest_AssertPass("Call to SDL_SetClipboardText(NULL) succeeded");
  137. SDLTest_AssertCheck(
  138. intResult == 0,
  139. "Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
  140. intResult);
  141. charResult = SDL_GetClipboardText();
  142. SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
  143. SDL_free(charResult);
  144. boolResult = SDL_HasClipboardText();
  145. SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
  146. SDLTest_AssertCheck(
  147. boolResult == SDL_FALSE,
  148. "Verify SDL_HasClipboardText returned SDL_FALSE, got %s",
  149. (boolResult) ? "SDL_TRUE" : "SDL_FALSE");
  150. }
  151. /* Empty clipboard */
  152. charResult = SDL_GetClipboardText();
  153. SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
  154. SDLTest_AssertCheck(
  155. charResult != NULL,
  156. "Verify SDL_GetClipboardText did not return NULL");
  157. SDLTest_AssertCheck(
  158. charResult[0] == '\0',
  159. "Verify SDL_GetClipboardText returned string with length 0, got length %i",
  160. (int) SDL_strlen(charResult));
  161. intResult = SDL_SetClipboardText((const char *)text);
  162. SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
  163. SDLTest_AssertCheck(
  164. intResult == 0,
  165. "Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
  166. intResult);
  167. SDLTest_AssertCheck(
  168. SDL_strcmp(textRef, text) == 0,
  169. "Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
  170. textRef, text);
  171. boolResult = SDL_HasClipboardText();
  172. SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
  173. SDLTest_AssertCheck(
  174. boolResult == SDL_TRUE,
  175. "Verify SDL_HasClipboardText returned SDL_TRUE, got %s",
  176. (boolResult) ? "SDL_TRUE" : "SDL_FALSE");
  177. SDL_free(charResult);
  178. charResult = SDL_GetClipboardText();
  179. SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
  180. SDLTest_AssertCheck(
  181. SDL_strcmp(textRef, charResult) == 0,
  182. "Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'",
  183. textRef, charResult);
  184. /* Cleanup */
  185. SDL_free(textRef);
  186. SDL_free(text);
  187. SDL_free(charResult);
  188. return TEST_COMPLETED;
  189. }
  190. /**
  191. * \brief End-to-end test of SDL_xyzPrimarySelectionText functions
  192. * \sa
  193. * http://wiki.libsdl.org/SDL_HasPrimarySelectionText
  194. * http://wiki.libsdl.org/SDL_GetPrimarySelectionText
  195. * http://wiki.libsdl.org/SDL_SetPrimarySelectionText
  196. */
  197. int
  198. clipboard_testPrimarySelectionTextFunctions(void *arg)
  199. {
  200. char *textRef = SDLTest_RandomAsciiString();
  201. char *text = SDL_strdup(textRef);
  202. SDL_bool boolResult;
  203. int intResult;
  204. char *charResult;
  205. /* Clear primary selection text state */
  206. boolResult = SDL_HasPrimarySelectionText();
  207. SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
  208. if (boolResult == SDL_TRUE) {
  209. intResult = SDL_SetPrimarySelectionText((const char *)NULL);
  210. SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText(NULL) succeeded");
  211. SDLTest_AssertCheck(
  212. intResult == 0,
  213. "Verify result from SDL_SetPrimarySelectionText(NULL), expected 0, got %i",
  214. intResult);
  215. charResult = SDL_GetPrimarySelectionText();
  216. SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded");
  217. SDL_free(charResult);
  218. boolResult = SDL_HasPrimarySelectionText();
  219. SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
  220. SDLTest_AssertCheck(
  221. boolResult == SDL_FALSE,
  222. "Verify SDL_HasPrimarySelectionText returned SDL_FALSE, got %s",
  223. (boolResult) ? "SDL_TRUE" : "SDL_FALSE");
  224. }
  225. /* Empty primary selection */
  226. charResult = SDL_GetPrimarySelectionText();
  227. SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded");
  228. SDLTest_AssertCheck(
  229. charResult != NULL,
  230. "Verify SDL_GetPrimarySelectionText did not return NULL");
  231. SDLTest_AssertCheck(
  232. charResult[0] == '\0',
  233. "Verify SDL_GetPrimarySelectionText returned string with length 0, got length %i",
  234. (int) SDL_strlen(charResult));
  235. intResult = SDL_SetPrimarySelectionText((const char *)text);
  236. SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText succeeded");
  237. SDLTest_AssertCheck(
  238. intResult == 0,
  239. "Verify result from SDL_SetPrimarySelectionText(NULL), expected 0, got %i",
  240. intResult);
  241. SDLTest_AssertCheck(
  242. SDL_strcmp(textRef, text) == 0,
  243. "Verify SDL_SetPrimarySelectionText did not modify input string, expected '%s', got '%s'",
  244. textRef, text);
  245. boolResult = SDL_HasPrimarySelectionText();
  246. SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
  247. SDLTest_AssertCheck(
  248. boolResult == SDL_TRUE,
  249. "Verify SDL_HasPrimarySelectionText returned SDL_TRUE, got %s",
  250. (boolResult) ? "SDL_TRUE" : "SDL_FALSE");
  251. SDL_free(charResult);
  252. charResult = SDL_GetPrimarySelectionText();
  253. SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded");
  254. SDLTest_AssertCheck(
  255. SDL_strcmp(textRef, charResult) == 0,
  256. "Verify SDL_GetPrimarySelectionText returned correct string, expected '%s', got '%s'",
  257. textRef, charResult);
  258. /* Cleanup */
  259. SDL_free(textRef);
  260. SDL_free(text);
  261. SDL_free(charResult);
  262. return TEST_COMPLETED;
  263. }
  264. /* ================= Test References ================== */
  265. /* Clipboard test cases */
  266. static const SDLTest_TestCaseReference clipboardTest1 =
  267. { (SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED };
  268. static const SDLTest_TestCaseReference clipboardTest2 =
  269. { (SDLTest_TestCaseFp)clipboard_testHasPrimarySelectionText, "clipboard_testHasPrimarySelectionText", "Check call to SDL_HasPrimarySelectionText", TEST_ENABLED };
  270. static const SDLTest_TestCaseReference clipboardTest3 =
  271. { (SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED };
  272. static const SDLTest_TestCaseReference clipboardTest4 =
  273. { (SDLTest_TestCaseFp)clipboard_testGetPrimarySelectionText, "clipboard_testGetPrimarySelectionText", "Check call to SDL_GetPrimarySelectionText", TEST_ENABLED };
  274. static const SDLTest_TestCaseReference clipboardTest5 =
  275. { (SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED };
  276. static const SDLTest_TestCaseReference clipboardTest6 =
  277. { (SDLTest_TestCaseFp)clipboard_testSetPrimarySelectionText, "clipboard_testSetPrimarySelectionText", "Check call to SDL_SetPrimarySelectionText", TEST_ENABLED };
  278. static const SDLTest_TestCaseReference clipboardTest7 =
  279. { (SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED };
  280. static const SDLTest_TestCaseReference clipboardTest8 =
  281. { (SDLTest_TestCaseFp)clipboard_testPrimarySelectionTextFunctions, "clipboard_testPrimarySelectionTextFunctions", "End-to-end test of SDL_xyzPrimarySelectionText functions", TEST_ENABLED };
  282. /* Sequence of Clipboard test cases */
  283. static const SDLTest_TestCaseReference *clipboardTests[] = {
  284. &clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, &clipboardTest5, &clipboardTest6, &clipboardTest7, &clipboardTest8, NULL
  285. };
  286. /* Clipboard test suite (global) */
  287. SDLTest_TestSuiteReference clipboardTestSuite = {
  288. "Clipboard",
  289. NULL,
  290. clipboardTests,
  291. NULL
  292. };
  293. /* vi: set ts=4 sw=4 expandtab: */