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