Atlas - testautomation_clipboard.c

Home / ext / SDL2 / test Lines: 1 | Size: 5958 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
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 SDL_free(charResult); 107 boolResult = SDL_HasClipboardText(); 108 SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded"); 109 SDLTest_AssertCheck( 110 boolResult == SDL_FALSE, 111 "Verify SDL_HasClipboardText returned SDL_FALSE, got %s", 112 (boolResult) ? "SDL_TRUE" : "SDL_FALSE"); 113 } 114 115 /* Empty clipboard */ 116 charResult = SDL_GetClipboardText(); 117 SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded"); 118 SDLTest_AssertCheck( 119 charResult != NULL, 120 "Verify SDL_GetClipboardText did not return NULL"); 121 SDLTest_AssertCheck( 122 charResult[0] == '\0', 123 "Verify SDL_GetClipboardText returned string with length 0, got length %i", 124 (int) SDL_strlen(charResult)); 125 intResult = SDL_SetClipboardText((const char *)text); 126 SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded"); 127 SDLTest_AssertCheck( 128 intResult == 0, 129 "Verify result from SDL_SetClipboardText(NULL), expected 0, got %i", 130 intResult); 131 SDLTest_AssertCheck( 132 SDL_strcmp(textRef, text) == 0, 133 "Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'", 134 textRef, text); 135 boolResult = SDL_HasClipboardText(); 136 SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded"); 137 SDLTest_AssertCheck( 138 boolResult == SDL_TRUE, 139 "Verify SDL_HasClipboardText returned SDL_TRUE, got %s", 140 (boolResult) ? "SDL_TRUE" : "SDL_FALSE"); 141 SDL_free(charResult); 142 charResult = SDL_GetClipboardText(); 143 SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded"); 144 SDLTest_AssertCheck( 145 SDL_strcmp(textRef, charResult) == 0, 146 "Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'", 147 textRef, charResult); 148 149 /* Cleanup */ 150 SDL_free(textRef); 151 SDL_free(text); 152 SDL_free(charResult); 153 154 return TEST_COMPLETED; 155} 156 157 158/* ================= Test References ================== */ 159 160/* Clipboard test cases */ 161static const SDLTest_TestCaseReference clipboardTest1 = 162 { (SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED }; 163 164static const SDLTest_TestCaseReference clipboardTest2 = 165 { (SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED }; 166 167static const SDLTest_TestCaseReference clipboardTest3 = 168 { (SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED }; 169 170static const SDLTest_TestCaseReference clipboardTest4 = 171 { (SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED }; 172 173/* Sequence of Clipboard test cases */ 174static const SDLTest_TestCaseReference *clipboardTests[] = { 175 &clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, NULL 176}; 177 178/* Clipboard test suite (global) */ 179SDLTest_TestSuiteReference clipboardTestSuite = { 180 "Clipboard", 181 NULL, 182 clipboardTests, 183 NULL 184}; 185
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.