🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

336 lines
11 KiB

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