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

183 lines
5.7 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_GetClipboardText
  25. *
  26. * \sa
  27. * http://wiki.libsdl.org/SDL_GetClipboardText
  28. */
  29. int
  30. clipboard_testGetClipboardText(void *arg)
  31. {
  32. char *charResult;
  33. charResult = SDL_GetClipboardText();
  34. SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
  35. SDL_free(charResult);
  36. return TEST_COMPLETED;
  37. }
  38. /**
  39. * \brief Check call to SDL_SetClipboardText
  40. * \sa
  41. * http://wiki.libsdl.org/SDL_SetClipboardText
  42. */
  43. int
  44. clipboard_testSetClipboardText(void *arg)
  45. {
  46. char *textRef = SDLTest_RandomAsciiString();
  47. char *text = SDL_strdup(textRef);
  48. int result;
  49. result = SDL_SetClipboardText((const char *)text);
  50. SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
  51. SDLTest_AssertCheck(
  52. result == 0,
  53. "Validate SDL_SetClipboardText result, expected 0, got %i",
  54. result);
  55. SDLTest_AssertCheck(
  56. SDL_strcmp(textRef, text) == 0,
  57. "Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
  58. textRef, text);
  59. /* Cleanup */
  60. SDL_free(textRef);
  61. SDL_free(text);
  62. return TEST_COMPLETED;
  63. }
  64. /**
  65. * \brief End-to-end test of SDL_xyzClipboardText functions
  66. * \sa
  67. * http://wiki.libsdl.org/SDL_HasClipboardText
  68. * http://wiki.libsdl.org/SDL_GetClipboardText
  69. * http://wiki.libsdl.org/SDL_SetClipboardText
  70. */
  71. int
  72. clipboard_testClipboardTextFunctions(void *arg)
  73. {
  74. char *textRef = SDLTest_RandomAsciiString();
  75. char *text = SDL_strdup(textRef);
  76. SDL_bool boolResult;
  77. int intResult;
  78. char *charResult;
  79. /* Clear clipboard text state */
  80. boolResult = SDL_HasClipboardText();
  81. SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
  82. if (boolResult == SDL_TRUE) {
  83. intResult = SDL_SetClipboardText((const char *)NULL);
  84. SDLTest_AssertPass("Call to SDL_SetClipboardText(NULL) succeeded");
  85. SDLTest_AssertCheck(
  86. intResult == 0,
  87. "Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
  88. intResult);
  89. charResult = SDL_GetClipboardText();
  90. SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
  91. SDL_free(charResult);
  92. boolResult = SDL_HasClipboardText();
  93. SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
  94. SDLTest_AssertCheck(
  95. boolResult == SDL_FALSE,
  96. "Verify SDL_HasClipboardText returned SDL_FALSE, got %s",
  97. (boolResult) ? "SDL_TRUE" : "SDL_FALSE");
  98. }
  99. /* Empty clipboard */
  100. charResult = SDL_GetClipboardText();
  101. SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
  102. SDLTest_AssertCheck(
  103. charResult != NULL,
  104. "Verify SDL_GetClipboardText did not return NULL");
  105. SDLTest_AssertCheck(
  106. charResult[0] == '\0',
  107. "Verify SDL_GetClipboardText returned string with length 0, got length %i",
  108. (int) SDL_strlen(charResult));
  109. intResult = SDL_SetClipboardText((const char *)text);
  110. SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
  111. SDLTest_AssertCheck(
  112. intResult == 0,
  113. "Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
  114. intResult);
  115. SDLTest_AssertCheck(
  116. SDL_strcmp(textRef, text) == 0,
  117. "Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
  118. textRef, text);
  119. boolResult = SDL_HasClipboardText();
  120. SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
  121. SDLTest_AssertCheck(
  122. boolResult == SDL_TRUE,
  123. "Verify SDL_HasClipboardText returned SDL_TRUE, got %s",
  124. (boolResult) ? "SDL_TRUE" : "SDL_FALSE");
  125. SDL_free(charResult);
  126. charResult = SDL_GetClipboardText();
  127. SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
  128. SDLTest_AssertCheck(
  129. SDL_strcmp(textRef, charResult) == 0,
  130. "Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'",
  131. textRef, charResult);
  132. /* Cleanup */
  133. SDL_free(textRef);
  134. SDL_free(text);
  135. SDL_free(charResult);
  136. return TEST_COMPLETED;
  137. }
  138. /* ================= Test References ================== */
  139. /* Clipboard test cases */
  140. static const SDLTest_TestCaseReference clipboardTest1 =
  141. { (SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED };
  142. static const SDLTest_TestCaseReference clipboardTest2 =
  143. { (SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED };
  144. static const SDLTest_TestCaseReference clipboardTest3 =
  145. { (SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED };
  146. static const SDLTest_TestCaseReference clipboardTest4 =
  147. { (SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED };
  148. /* Sequence of Clipboard test cases */
  149. static const SDLTest_TestCaseReference *clipboardTests[] = {
  150. &clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, NULL
  151. };
  152. /* Clipboard test suite (global) */
  153. SDLTest_TestSuiteReference clipboardTestSuite = {
  154. "Clipboard",
  155. NULL,
  156. clipboardTests,
  157. NULL
  158. };