testautomation_clipboard.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. 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. 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. charResult = SDL_GetClipboardText();
  126. SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
  127. SDLTest_AssertCheck(
  128. SDL_strcmp(textRef, charResult) == 0,
  129. "Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'",
  130. textRef, charResult);
  131. /* Cleanup */
  132. SDL_free(textRef);
  133. SDL_free(text);
  134. SDL_free(charResult);
  135. return TEST_COMPLETED;
  136. }
  137. /* ================= Test References ================== */
  138. /* Clipboard test cases */
  139. static const SDLTest_TestCaseReference clipboardTest1 =
  140. { (SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED };
  141. static const SDLTest_TestCaseReference clipboardTest2 =
  142. { (SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED };
  143. static const SDLTest_TestCaseReference clipboardTest3 =
  144. { (SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED };
  145. static const SDLTest_TestCaseReference clipboardTest4 =
  146. { (SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED };
  147. /* Sequence of Clipboard test cases */
  148. static const SDLTest_TestCaseReference *clipboardTests[] = {
  149. &clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, NULL
  150. };
  151. /* Clipboard test suite (global) */
  152. SDLTest_TestSuiteReference clipboardTestSuite = {
  153. "Clipboard",
  154. NULL,
  155. clipboardTests,
  156. NULL
  157. };