testautomation_clipboard.c 5.8 KB

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