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