| 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/SDL_HasClipboardText |
| 20 |
*/ |
| 21 |
int clipboard_testHasClipboardText(void *arg) |
| 22 |
{ |
| 23 |
SDL_HasClipboardText(); |
| 24 |
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded"); |
| 25 |
|
| 26 |
return TEST_COMPLETED; |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* \brief Check call to SDL_HasPrimarySelectionText |
| 31 |
* |
| 32 |
* \sa |
| 33 |
* http://wiki.libsdl.org/SDL_HasPrimarySelectionText |
| 34 |
*/ |
| 35 |
int clipboard_testHasPrimarySelectionText(void *arg) |
| 36 |
{ |
| 37 |
SDL_HasPrimarySelectionText(); |
| 38 |
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded"); |
| 39 |
|
| 40 |
return TEST_COMPLETED; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* \brief Check call to SDL_GetClipboardText |
| 45 |
* |
| 46 |
* \sa |
| 47 |
* http://wiki.libsdl.org/SDL_GetClipboardText |
| 48 |
*/ |
| 49 |
int clipboard_testGetClipboardText(void *arg) |
| 50 |
{ |
| 51 |
char *charResult; |
| 52 |
charResult = SDL_GetClipboardText(); |
| 53 |
SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded"); |
| 54 |
|
| 55 |
SDL_free(charResult); |
| 56 |
|
| 57 |
return TEST_COMPLETED; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* \brief Check call to SDL_GetPrimarySelectionText |
| 62 |
* |
| 63 |
* \sa |
| 64 |
* http://wiki.libsdl.org/SDL_GetPrimarySelectionText |
| 65 |
*/ |
| 66 |
int clipboard_testGetPrimarySelectionText(void *arg) |
| 67 |
{ |
| 68 |
char *charResult; |
| 69 |
charResult = SDL_GetPrimarySelectionText(); |
| 70 |
SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded"); |
| 71 |
|
| 72 |
SDL_free(charResult); |
| 73 |
|
| 74 |
return TEST_COMPLETED; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* \brief Check call to SDL_SetClipboardText |
| 79 |
* \sa |
| 80 |
* http://wiki.libsdl.org/SDL_SetClipboardText |
| 81 |
*/ |
| 82 |
int clipboard_testSetClipboardText(void *arg) |
| 83 |
{ |
| 84 |
char *textRef = SDLTest_RandomAsciiString(); |
| 85 |
char *text = SDL_strdup(textRef); |
| 86 |
int result; |
| 87 |
result = SDL_SetClipboardText(text); |
| 88 |
SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded"); |
| 89 |
SDLTest_AssertCheck( |
| 90 |
result == 0, |
| 91 |
"Validate SDL_SetClipboardText result, expected 0, got %i", |
| 92 |
result); |
| 93 |
SDLTest_AssertCheck( |
| 94 |
SDL_strcmp(textRef, text) == 0, |
| 95 |
"Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'", |
| 96 |
textRef, text); |
| 97 |
|
| 98 |
/* Cleanup */ |
| 99 |
SDL_free(textRef); |
| 100 |
SDL_free(text); |
| 101 |
|
| 102 |
return TEST_COMPLETED; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* \brief Check call to SDL_SetPrimarySelectionText |
| 107 |
* \sa |
| 108 |
* http://wiki.libsdl.org/SDL_SetPrimarySelectionText |
| 109 |
*/ |
| 110 |
int clipboard_testSetPrimarySelectionText(void *arg) |
| 111 |
{ |
| 112 |
char *textRef = SDLTest_RandomAsciiString(); |
| 113 |
char *text = SDL_strdup(textRef); |
| 114 |
int result; |
| 115 |
result = SDL_SetPrimarySelectionText(text); |
| 116 |
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText succeeded"); |
| 117 |
SDLTest_AssertCheck( |
| 118 |
result == 0, |
| 119 |
"Validate SDL_SetPrimarySelectionText result, expected 0, got %i", |
| 120 |
result); |
| 121 |
SDLTest_AssertCheck( |
| 122 |
SDL_strcmp(textRef, text) == 0, |
| 123 |
"Verify SDL_SetPrimarySelectionText did not modify input string, expected '%s', got '%s'", |
| 124 |
textRef, text); |
| 125 |
|
| 126 |
/* Cleanup */ |
| 127 |
SDL_free(textRef); |
| 128 |
SDL_free(text); |
| 129 |
|
| 130 |
return TEST_COMPLETED; |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* \brief End-to-end test of SDL_xyzClipboardText functions |
| 135 |
* \sa |
| 136 |
* http://wiki.libsdl.org/SDL_HasClipboardText |
| 137 |
* http://wiki.libsdl.org/SDL_GetClipboardText |
| 138 |
* http://wiki.libsdl.org/SDL_SetClipboardText |
| 139 |
*/ |
| 140 |
int clipboard_testClipboardTextFunctions(void *arg) |
| 141 |
{ |
| 142 |
char *textRef = SDLTest_RandomAsciiString(); |
| 143 |
char *text = SDL_strdup(textRef); |
| 144 |
SDL_bool boolResult; |
| 145 |
int intResult; |
| 146 |
char *charResult; |
| 147 |
|
| 148 |
/* Clear clipboard text state */ |
| 149 |
boolResult = SDL_HasClipboardText(); |
| 150 |
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded"); |
| 151 |
if (boolResult == SDL_TRUE) { |
| 152 |
intResult = SDL_SetClipboardText(NULL); |
| 153 |
SDLTest_AssertPass("Call to SDL_SetClipboardText(NULL) succeeded"); |
| 154 |
SDLTest_AssertCheck( |
| 155 |
intResult == 0, |
| 156 |
"Verify result from SDL_SetClipboardText(NULL), expected 0, got %i", |
| 157 |
intResult); |
| 158 |
charResult = SDL_GetClipboardText(); |
| 159 |
SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded"); |
| 160 |
SDL_free(charResult); |
| 161 |
boolResult = SDL_HasClipboardText(); |
| 162 |
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded"); |
| 163 |
SDLTest_AssertCheck( |
| 164 |
boolResult == SDL_FALSE, |
| 165 |
"Verify SDL_HasClipboardText returned SDL_FALSE, got %s", |
| 166 |
(boolResult) ? "SDL_TRUE" : "SDL_FALSE"); |
| 167 |
} |
| 168 |
|
| 169 |
/* Empty clipboard */ |
| 170 |
charResult = SDL_GetClipboardText(); |
| 171 |
SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded"); |
| 172 |
SDLTest_Assert( |
| 173 |
charResult != NULL, |
| 174 |
"Verify SDL_GetClipboardText did not return NULL"); |
| 175 |
SDLTest_AssertCheck( |
| 176 |
charResult[0] == '\0', /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */ |
| 177 |
"Verify SDL_GetClipboardText returned string with length 0, got length %i", |
| 178 |
(int)SDL_strlen(charResult)); |
| 179 |
intResult = SDL_SetClipboardText(text); |
| 180 |
SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded"); |
| 181 |
SDLTest_AssertCheck( |
| 182 |
intResult == 0, |
| 183 |
"Verify result from SDL_SetClipboardText(NULL), expected 0, got %i", |
| 184 |
intResult); |
| 185 |
SDLTest_AssertCheck( |
| 186 |
SDL_strcmp(textRef, text) == 0, |
| 187 |
"Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'", |
| 188 |
textRef, text); |
| 189 |
boolResult = SDL_HasClipboardText(); |
| 190 |
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded"); |
| 191 |
SDLTest_AssertCheck( |
| 192 |
boolResult == SDL_TRUE, |
| 193 |
"Verify SDL_HasClipboardText returned SDL_TRUE, got %s", |
| 194 |
(boolResult) ? "SDL_TRUE" : "SDL_FALSE"); |
| 195 |
SDL_free(charResult); |
| 196 |
charResult = SDL_GetClipboardText(); |
| 197 |
SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded"); |
| 198 |
SDLTest_AssertCheck( |
| 199 |
SDL_strcmp(textRef, charResult) == 0, |
| 200 |
"Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'", |
| 201 |
textRef, charResult); |
| 202 |
|
| 203 |
/* Cleanup */ |
| 204 |
SDL_free(textRef); |
| 205 |
SDL_free(text); |
| 206 |
SDL_free(charResult); |
| 207 |
|
| 208 |
return TEST_COMPLETED; |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* \brief End-to-end test of SDL_xyzPrimarySelectionText functions |
| 213 |
* \sa |
| 214 |
* http://wiki.libsdl.org/SDL_HasPrimarySelectionText |
| 215 |
* http://wiki.libsdl.org/SDL_GetPrimarySelectionText |
| 216 |
* http://wiki.libsdl.org/SDL_SetPrimarySelectionText |
| 217 |
*/ |
| 218 |
int clipboard_testPrimarySelectionTextFunctions(void *arg) |
| 219 |
{ |
| 220 |
char *textRef = SDLTest_RandomAsciiString(); |
| 221 |
char *text = SDL_strdup(textRef); |
| 222 |
SDL_bool boolResult; |
| 223 |
int intResult; |
| 224 |
char *charResult; |
| 225 |
|
| 226 |
/* Clear primary selection text state */ |
| 227 |
boolResult = SDL_HasPrimarySelectionText(); |
| 228 |
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded"); |
| 229 |
if (boolResult == SDL_TRUE) { |
| 230 |
intResult = SDL_SetPrimarySelectionText(NULL); |
| 231 |
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText(NULL) succeeded"); |
| 232 |
SDLTest_AssertCheck( |
| 233 |
intResult == 0, |
| 234 |
"Verify result from SDL_SetPrimarySelectionText(NULL), expected 0, got %i", |
| 235 |
intResult); |
| 236 |
charResult = SDL_GetPrimarySelectionText(); |
| 237 |
SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded"); |
| 238 |
SDL_free(charResult); |
| 239 |
boolResult = SDL_HasPrimarySelectionText(); |
| 240 |
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded"); |
| 241 |
SDLTest_AssertCheck( |
| 242 |
boolResult == SDL_FALSE, |
| 243 |
"Verify SDL_HasPrimarySelectionText returned SDL_FALSE, got %s", |
| 244 |
(boolResult) ? "SDL_TRUE" : "SDL_FALSE"); |
| 245 |
} |
| 246 |
|
| 247 |
/* Empty primary selection */ |
| 248 |
charResult = SDL_GetPrimarySelectionText(); |
| 249 |
SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded"); |
| 250 |
SDLTest_Assert( |
| 251 |
charResult != NULL, |
| 252 |
"Verify SDL_GetPrimarySelectionText did not return NULL"); |
| 253 |
SDLTest_AssertCheck( |
| 254 |
charResult[0] == '\0', /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */ |
| 255 |
"Verify SDL_GetPrimarySelectionText returned string with length 0, got length %i", |
| 256 |
(int)SDL_strlen(charResult)); |
| 257 |
intResult = SDL_SetPrimarySelectionText(text); |
| 258 |
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText succeeded"); |
| 259 |
SDLTest_AssertCheck( |
| 260 |
intResult == 0, |
| 261 |
"Verify result from SDL_SetPrimarySelectionText(NULL), expected 0, got %i", |
| 262 |
intResult); |
| 263 |
SDLTest_AssertCheck( |
| 264 |
SDL_strcmp(textRef, text) == 0, |
| 265 |
"Verify SDL_SetPrimarySelectionText did not modify input string, expected '%s', got '%s'", |
| 266 |
textRef, text); |
| 267 |
boolResult = SDL_HasPrimarySelectionText(); |
| 268 |
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded"); |
| 269 |
SDLTest_AssertCheck( |
| 270 |
boolResult == SDL_TRUE, |
| 271 |
"Verify SDL_HasPrimarySelectionText returned SDL_TRUE, got %s", |
| 272 |
(boolResult) ? "SDL_TRUE" : "SDL_FALSE"); |
| 273 |
SDL_free(charResult); |
| 274 |
charResult = SDL_GetPrimarySelectionText(); |
| 275 |
SDLTest_AssertPass("Call to SDL_GetPrimarySelectionText succeeded"); |
| 276 |
SDLTest_AssertCheck( |
| 277 |
SDL_strcmp(textRef, charResult) == 0, |
| 278 |
"Verify SDL_GetPrimarySelectionText returned correct string, expected '%s', got '%s'", |
| 279 |
textRef, charResult); |
| 280 |
|
| 281 |
/* Cleanup */ |
| 282 |
SDL_free(textRef); |
| 283 |
SDL_free(text); |
| 284 |
SDL_free(charResult); |
| 285 |
|
| 286 |
return TEST_COMPLETED; |
| 287 |
} |
| 288 |
|
| 289 |
/* ================= Test References ================== */ |
| 290 |
|
| 291 |
/* Clipboard test cases */ |
| 292 |
static const SDLTest_TestCaseReference clipboardTest1 = { |
| 293 |
(SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED |
| 294 |
}; |
| 295 |
|
| 296 |
static const SDLTest_TestCaseReference clipboardTest2 = { |
| 297 |
(SDLTest_TestCaseFp)clipboard_testHasPrimarySelectionText, "clipboard_testHasPrimarySelectionText", "Check call to SDL_HasPrimarySelectionText", TEST_ENABLED |
| 298 |
}; |
| 299 |
|
| 300 |
static const SDLTest_TestCaseReference clipboardTest3 = { |
| 301 |
(SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED |
| 302 |
}; |
| 303 |
|
| 304 |
static const SDLTest_TestCaseReference clipboardTest4 = { |
| 305 |
(SDLTest_TestCaseFp)clipboard_testGetPrimarySelectionText, "clipboard_testGetPrimarySelectionText", "Check call to SDL_GetPrimarySelectionText", TEST_ENABLED |
| 306 |
}; |
| 307 |
|
| 308 |
static const SDLTest_TestCaseReference clipboardTest5 = { |
| 309 |
(SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED |
| 310 |
}; |
| 311 |
|
| 312 |
static const SDLTest_TestCaseReference clipboardTest6 = { |
| 313 |
(SDLTest_TestCaseFp)clipboard_testSetPrimarySelectionText, "clipboard_testSetPrimarySelectionText", "Check call to SDL_SetPrimarySelectionText", TEST_ENABLED |
| 314 |
}; |
| 315 |
|
| 316 |
static const SDLTest_TestCaseReference clipboardTest7 = { |
| 317 |
(SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED |
| 318 |
}; |
| 319 |
|
| 320 |
static const SDLTest_TestCaseReference clipboardTest8 = { |
| 321 |
(SDLTest_TestCaseFp)clipboard_testPrimarySelectionTextFunctions, "clipboard_testPrimarySelectionTextFunctions", "End-to-end test of SDL_xyzPrimarySelectionText functions", TEST_ENABLED |
| 322 |
}; |
| 323 |
|
| 324 |
/* Sequence of Clipboard test cases */ |
| 325 |
static const SDLTest_TestCaseReference *clipboardTests[] = { |
| 326 |
&clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, &clipboardTest5, &clipboardTest6, &clipboardTest7, &clipboardTest8, NULL |
| 327 |
}; |
| 328 |
|
| 329 |
/* Clipboard test suite (global) */ |
| 330 |
SDLTest_TestSuiteReference clipboardTestSuite = { |
| 331 |
"Clipboard", |
| 332 |
NULL, |
| 333 |
clipboardTests, |
| 334 |
NULL |
| 335 |
}; |