🛠️🐜 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.

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