1 /** 2 * SDL_test test suite 3 */ 4 5 /* Visual Studio 2008 doesn't have stdint.h */ 6 #if defined(_MSC_VER) && _MSC_VER <= 1500 7 #define UINT8_MAX ~(Uint8)0 8 #define UINT16_MAX ~(Uint16)0 9 #define UINT32_MAX ~(Uint32)0 10 #define UINT64_MAX ~(Uint64)0 11 #else 12 #include <stdint.h> 13 #endif 14 #include <stdio.h> 15 #include <limits.h> 16 #include <float.h> 17 #include <ctype.h> 18 19 #include "SDL.h" 20 #include "SDL_test.h" 21 22 /* Test case functions */ 23 24 /* Forward declarations for internal harness functions */ 25 extern char *SDLTest_GenerateRunSeed(const int length); 26 27 /** 28 * @brief Calls to SDLTest_GenerateRunSeed() 29 */ 30 int 31 sdltest_generateRunSeed(void *arg) 32 { 33 char* result; 34 int i, l; 35 36 for (i = 1; i <= 10; i += 3) { 37 result = SDLTest_GenerateRunSeed((const int)i); 38 SDLTest_AssertPass("Call to SDLTest_GenerateRunSeed()"); 39 SDLTest_AssertCheck(result != NULL, "Verify returned value is not NULL"); 40 if (result != NULL) { 41 l = SDL_strlen(result); 42 SDLTest_AssertCheck(l == i, "Verify length of returned value is %d, got: %d", i, l); 43 SDL_free(result); 44 } 45 } 46 47 /* Negative cases */ 48 for (i = -2; i <= 0; i++) { 49 result = SDLTest_GenerateRunSeed((const int)i); 50 SDLTest_AssertPass("Call to SDLTest_GenerateRunSeed()"); 51 SDLTest_AssertCheck(result == NULL, "Verify returned value is not NULL"); 52 } 53 54 return TEST_COMPLETED; 55 } 56 57 /** 58 * @brief Calls to SDLTest_GetFuzzerInvocationCount() 59 */ 60 int 61 sdltest_getFuzzerInvocationCount(void *arg) 62 { 63 Uint8 result; 64 int fuzzerCount1, fuzzerCount2; 65 66 fuzzerCount1 = SDLTest_GetFuzzerInvocationCount(); 67 SDLTest_AssertPass("Call to SDLTest_GetFuzzerInvocationCount()"); 68 SDLTest_AssertCheck(fuzzerCount1 >= 0, "Verify returned value, expected: >=0, got: %d", fuzzerCount1); 69 70 result = SDLTest_RandomUint8(); 71 SDLTest_AssertPass("Call to SDLTest_RandomUint8(), returned %d", result); 72 73 fuzzerCount2 = SDLTest_GetFuzzerInvocationCount(); 74 SDLTest_AssertPass("Call to SDLTest_GetFuzzerInvocationCount()"); 75 SDLTest_AssertCheck(fuzzerCount2 > fuzzerCount1, "Verify returned value, expected: >%d, got: %d", fuzzerCount1, fuzzerCount2); 76 77 return TEST_COMPLETED; 78 } 79 80 81 /** 82 * @brief Calls to random number generators 83 */ 84 int 85 sdltest_randomNumber(void *arg) 86 { 87 Sint64 result; 88 Uint64 uresult; 89 double dresult; 90 Uint64 umax; 91 Sint64 min, max; 92 93 result = (Sint64)SDLTest_RandomUint8(); 94 umax = (1 << 8) - 1; 95 SDLTest_AssertPass("Call to SDLTest_RandomUint8"); 96 SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result); 97 98 result = (Sint64)SDLTest_RandomSint8(); 99 min = 0 - (1 << 7); 100 max = (1 << 7) - 1; 101 SDLTest_AssertPass("Call to SDLTest_RandomSint8"); 102 SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result); 103 104 result = (Sint64)SDLTest_RandomUint16(); 105 umax = (1 << 16) - 1; 106 SDLTest_AssertPass("Call to SDLTest_RandomUint16"); 107 SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result); 108 109 result = (Sint64)SDLTest_RandomSint16(); 110 min = 0 - (1 << 15); 111 max = (1 << 15) - 1; 112 SDLTest_AssertPass("Call to SDLTest_RandomSint16"); 113 SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result); 114 115 result = (Sint64)SDLTest_RandomUint32(); 116 umax = ((Uint64)1 << 32) - 1; 117 SDLTest_AssertPass("Call to SDLTest_RandomUint32"); 118 SDLTest_AssertCheck(result >= 0 && result <= (Sint64)umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result); 119 120 result = (Sint64)SDLTest_RandomSint32(); 121 min = 0 - ((Sint64)1 << 31); 122 max = ((Sint64)1 << 31) - 1; 123 SDLTest_AssertPass("Call to SDLTest_RandomSint32"); 124 SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result); 125 126 uresult = SDLTest_RandomUint64(); 127 SDLTest_AssertPass("Call to SDLTest_RandomUint64"); 128 129 result = SDLTest_RandomSint64(); 130 SDLTest_AssertPass("Call to SDLTest_RandomSint64"); 131 132 dresult = (double)SDLTest_RandomUnitFloat(); 133 SDLTest_AssertPass("Call to SDLTest_RandomUnitFloat"); 134 SDLTest_AssertCheck(dresult >= 0.0 && dresult < 1.0, "Verify result value, expected: [0.0,1.0[, got: %e", dresult); 135 136 dresult = (double)SDLTest_RandomFloat(); 137 SDLTest_AssertPass("Call to SDLTest_RandomFloat"); 138 SDLTest_AssertCheck(dresult >= (double)(-FLT_MAX) && dresult <= (double)FLT_MAX, "Verify result value, expected: [%e,%e], got: %e", (double)(-FLT_MAX), (double)FLT_MAX, dresult); 139 140 dresult = (double)SDLTest_RandomUnitDouble(); 141 SDLTest_AssertPass("Call to SDLTest_RandomUnitDouble"); 142 SDLTest_AssertCheck(dresult >= 0.0 && dresult < 1.0, "Verify result value, expected: [0.0,1.0[, got: %e", dresult); 143 144 dresult = SDLTest_RandomDouble(); 145 SDLTest_AssertPass("Call to SDLTest_RandomDouble"); 146 147 return TEST_COMPLETED; 148 } 149 150 /* 151 * @brief Calls to random boundary number generators for Uint8 152 */ 153 int 154 sdltest_randomBoundaryNumberUint8(void *arg) 155 { 156 const char *expectedError = "That operation is not supported"; 157 char *lastError; 158 Uint64 uresult; 159 160 /* Clean error messages */ 161 SDL_ClearError(); 162 SDLTest_AssertPass("SDL_ClearError()"); 163 164 /* RandomUintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */ 165 uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 10, SDL_TRUE); 166 SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue"); 167 SDLTest_AssertCheck( 168 uresult == 10, 169 "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", uresult); 170 171 /* RandomUintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */ 172 uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 11, SDL_TRUE); 173 SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue"); 174 SDLTest_AssertCheck( 175 uresult == 10 || uresult == 11, 176 "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", uresult); 177 178 /* RandomUintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */ 179 uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 12, SDL_TRUE); 180 SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue"); 181 SDLTest_AssertCheck( 182 uresult == 10 || uresult == 11 || uresult == 12, 183 "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", uresult); 184 185 /* RandomUintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */ 186 uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 13, SDL_TRUE); 187 SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue"); 188 SDLTest_AssertCheck( 189 uresult == 10 || uresult == 11 || uresult == 12 || uresult == 13, 190 "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", uresult); 191 192 /* RandomUintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */ 193 uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(10, 20, SDL_TRUE); 194 SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue"); 195 SDLTest_AssertCheck( 196 uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20, 197 "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult); 198 199 /* RandomUintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */ 200 uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(20, 10, SDL_TRUE); 201 SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue"); 202 SDLTest_AssertCheck( 203 uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20, 204 "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult); 205 206 /* RandomUintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */ 207 uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(1, 20, SDL_FALSE); 208 SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue"); 209 SDLTest_AssertCheck( 210 uresult == 0 || uresult == 21, 211 "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", uresult); 212 213 /* RandomUintXBoundaryValue(0, 99, SDL_FALSE) returns 100 */ 214 uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(0, 99, SDL_FALSE); 215 SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue"); 216 SDLTest_AssertCheck( 217 uresult == 100, 218 "Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %lld", uresult); 219 220 /* RandomUintXBoundaryValue(1, 0xff, SDL_FALSE) returns 0 (no error) */ 221 uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(1, 255, SDL_FALSE); 222 SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue"); 223 SDLTest_AssertCheck( 224 uresult == 0, 225 "Validate result value for parameters (1,255,SDL_FALSE); expected: 0, got: %lld", uresult); 226 lastError = (char *)SDL_GetError(); 227 SDLTest_AssertPass("SDL_GetError()"); 228 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 229 230 /* RandomUintXBoundaryValue(0, 0xfe, SDL_FALSE) returns 0xff (no error) */ 231 uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(0, 254, SDL_FALSE); 232 SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue"); 233 SDLTest_AssertCheck( 234 uresult == 0xff, 235 "Validate result value for parameters (0,254,SDL_FALSE); expected: 0xff, got: %lld", uresult); 236 lastError = (char *)SDL_GetError(); 237 SDLTest_AssertPass("SDL_GetError()"); 238 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 239 240 /* RandomUintXBoundaryValue(0, 0xff, SDL_FALSE) returns 0 (sets error) */ 241 uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(0, 255, SDL_FALSE); 242 SDLTest_AssertPass("Call to SDLTest_RandomUint8BoundaryValue"); 243 SDLTest_AssertCheck( 244 uresult == 0, 245 "Validate result value for parameters(0,255,SDL_FALSE); expected: 0, got: %lld", uresult); 246 lastError = (char *)SDL_GetError(); 247 SDLTest_AssertPass("SDL_GetError()"); 248 SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0, 249 "SDL_GetError(): expected message '%s', was message: '%s'", 250 expectedError, 251 lastError); 252 253 /* Clear error messages */ 254 SDL_ClearError(); 255 SDLTest_AssertPass("SDL_ClearError()"); 256 257 return TEST_COMPLETED; 258 } 259 260 /* 261 * @brief Calls to random boundary number generators for Uint16 262 */ 263 int 264 sdltest_randomBoundaryNumberUint16(void *arg) 265 { 266 const char *expectedError = "That operation is not supported"; 267 char *lastError; 268 Uint64 uresult; 269 270 /* Clean error messages */ 271 SDL_ClearError(); 272 SDLTest_AssertPass("SDL_ClearError()"); 273 274 /* RandomUintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */ 275 uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 10, SDL_TRUE); 276 SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue"); 277 SDLTest_AssertCheck( 278 uresult == 10, 279 "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", uresult); 280 281 /* RandomUintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */ 282 uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 11, SDL_TRUE); 283 SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue"); 284 SDLTest_AssertCheck( 285 uresult == 10 || uresult == 11, 286 "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", uresult); 287 288 /* RandomUintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */ 289 uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 12, SDL_TRUE); 290 SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue"); 291 SDLTest_AssertCheck( 292 uresult == 10 || uresult == 11 || uresult == 12, 293 "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", uresult); 294 295 /* RandomUintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */ 296 uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 13, SDL_TRUE); 297 SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue"); 298 SDLTest_AssertCheck( 299 uresult == 10 || uresult == 11 || uresult == 12 || uresult == 13, 300 "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", uresult); 301 302 /* RandomUintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */ 303 uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(10, 20, SDL_TRUE); 304 SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue"); 305 SDLTest_AssertCheck( 306 uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20, 307 "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult); 308 309 /* RandomUintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */ 310 uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(20, 10, SDL_TRUE); 311 SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue"); 312 SDLTest_AssertCheck( 313 uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20, 314 "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult); 315 316 /* RandomUintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */ 317 uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(1, 20, SDL_FALSE); 318 SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue"); 319 SDLTest_AssertCheck( 320 uresult == 0 || uresult == 21, 321 "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", uresult); 322 323 /* RandomUintXBoundaryValue(0, 99, SDL_FALSE) returns 100 */ 324 uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(0, 99, SDL_FALSE); 325 SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue"); 326 SDLTest_AssertCheck( 327 uresult == 100, 328 "Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %lld", uresult); 329 330 /* RandomUintXBoundaryValue(1, 0xffff, SDL_FALSE) returns 0 (no error) */ 331 uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(1, 0xffff, SDL_FALSE); 332 SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue"); 333 SDLTest_AssertCheck( 334 uresult == 0, 335 "Validate result value for parameters (1,0xffff,SDL_FALSE); expected: 0, got: %lld", uresult); 336 lastError = (char *)SDL_GetError(); 337 SDLTest_AssertPass("SDL_GetError()"); 338 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 339 340 /* RandomUintXBoundaryValue(0, 0xfffe, SDL_FALSE) returns 0xffff (no error) */ 341 uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(0, 0xfffe, SDL_FALSE); 342 SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue"); 343 SDLTest_AssertCheck( 344 uresult == 0xffff, 345 "Validate result value for parameters (0,0xfffe,SDL_FALSE); expected: 0xffff, got: %lld", uresult); 346 lastError = (char *)SDL_GetError(); 347 SDLTest_AssertPass("SDL_GetError()"); 348 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 349 350 /* RandomUintXBoundaryValue(0, 0xffff, SDL_FALSE) returns 0 (sets error) */ 351 uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(0, 0xffff, SDL_FALSE); 352 SDLTest_AssertPass("Call to SDLTest_RandomUint16BoundaryValue"); 353 SDLTest_AssertCheck( 354 uresult == 0, 355 "Validate result value for parameters(0,0xffff,SDL_FALSE); expected: 0, got: %lld", uresult); 356 lastError = (char *)SDL_GetError(); 357 SDLTest_AssertPass("SDL_GetError()"); 358 SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0, 359 "SDL_GetError(): expected message '%s', was message: '%s'", 360 expectedError, 361 lastError); 362 363 /* Clear error messages */ 364 SDL_ClearError(); 365 SDLTest_AssertPass("SDL_ClearError()"); 366 367 return TEST_COMPLETED; 368 } 369 370 /* 371 * @brief Calls to random boundary number generators for Uint32 372 */ 373 int 374 sdltest_randomBoundaryNumberUint32(void *arg) 375 { 376 const char *expectedError = "That operation is not supported"; 377 char *lastError; 378 Uint64 uresult; 379 380 /* Clean error messages */ 381 SDL_ClearError(); 382 SDLTest_AssertPass("SDL_ClearError()"); 383 384 /* RandomUintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */ 385 uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 10, SDL_TRUE); 386 SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue"); 387 SDLTest_AssertCheck( 388 uresult == 10, 389 "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", uresult); 390 391 /* RandomUintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */ 392 uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 11, SDL_TRUE); 393 SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue"); 394 SDLTest_AssertCheck( 395 uresult == 10 || uresult == 11, 396 "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", uresult); 397 398 /* RandomUintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */ 399 uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 12, SDL_TRUE); 400 SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue"); 401 SDLTest_AssertCheck( 402 uresult == 10 || uresult == 11 || uresult == 12, 403 "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", uresult); 404 405 /* RandomUintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */ 406 uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 13, SDL_TRUE); 407 SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue"); 408 SDLTest_AssertCheck( 409 uresult == 10 || uresult == 11 || uresult == 12 || uresult == 13, 410 "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", uresult); 411 412 /* RandomUintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */ 413 uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(10, 20, SDL_TRUE); 414 SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue"); 415 SDLTest_AssertCheck( 416 uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20, 417 "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult); 418 419 /* RandomUintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */ 420 uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(20, 10, SDL_TRUE); 421 SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue"); 422 SDLTest_AssertCheck( 423 uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20, 424 "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult); 425 426 /* RandomUintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */ 427 uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(1, 20, SDL_FALSE); 428 SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue"); 429 SDLTest_AssertCheck( 430 uresult == 0 || uresult == 21, 431 "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", uresult); 432 433 /* RandomUintXBoundaryValue(0, 99, SDL_FALSE) returns 100 */ 434 uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(0, 99, SDL_FALSE); 435 SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue"); 436 SDLTest_AssertCheck( 437 uresult == 100, 438 "Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %lld", uresult); 439 440 /* RandomUintXBoundaryValue(1, 0xffffffff, SDL_FALSE) returns 0 (no error) */ 441 uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(1, 0xffffffff, SDL_FALSE); 442 SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue"); 443 SDLTest_AssertCheck( 444 uresult == 0, 445 "Validate result value for parameters (1,0xffffffff,SDL_FALSE); expected: 0, got: %lld", uresult); 446 lastError = (char *)SDL_GetError(); 447 SDLTest_AssertPass("SDL_GetError()"); 448 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 449 450 /* RandomUintXBoundaryValue(0, 0xfffffffe, SDL_FALSE) returns 0xffffffff (no error) */ 451 uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(0, 0xfffffffe, SDL_FALSE); 452 SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue"); 453 SDLTest_AssertCheck( 454 uresult == 0xffffffff, 455 "Validate result value for parameters (0,0xfffffffe,SDL_FALSE); expected: 0xffffffff, got: %lld", uresult); 456 lastError = (char *)SDL_GetError(); 457 SDLTest_AssertPass("SDL_GetError()"); 458 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 459 460 /* RandomUintXBoundaryValue(0, 0xffffffff, SDL_FALSE) returns 0 (sets error) */ 461 uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(0, 0xffffffff, SDL_FALSE); 462 SDLTest_AssertPass("Call to SDLTest_RandomUint32BoundaryValue"); 463 SDLTest_AssertCheck( 464 uresult == 0, 465 "Validate result value for parameters(0,0xffffffff,SDL_FALSE); expected: 0, got: %lld", uresult); 466 lastError = (char *)SDL_GetError(); 467 SDLTest_AssertPass("SDL_GetError()"); 468 SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0, 469 "SDL_GetError(): expected message '%s', was message: '%s'", 470 expectedError, 471 lastError); 472 473 /* Clear error messages */ 474 SDL_ClearError(); 475 SDLTest_AssertPass("SDL_ClearError()"); 476 477 return TEST_COMPLETED; 478 } 479 480 /* 481 * @brief Calls to random boundary number generators for Uint64 482 */ 483 int 484 sdltest_randomBoundaryNumberUint64(void *arg) 485 { 486 const char *expectedError = "That operation is not supported"; 487 char *lastError; 488 Uint64 uresult; 489 490 /* Clean error messages */ 491 SDL_ClearError(); 492 SDLTest_AssertPass("SDL_ClearError()"); 493 494 /* RandomUintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */ 495 uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 10, SDL_TRUE); 496 SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue"); 497 SDLTest_AssertCheck( 498 uresult == 10, 499 "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", uresult); 500 501 /* RandomUintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */ 502 uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 11, SDL_TRUE); 503 SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue"); 504 SDLTest_AssertCheck( 505 uresult == 10 || uresult == 11, 506 "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", uresult); 507 508 /* RandomUintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */ 509 uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 12, SDL_TRUE); 510 SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue"); 511 SDLTest_AssertCheck( 512 uresult == 10 || uresult == 11 || uresult == 12, 513 "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", uresult); 514 515 /* RandomUintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */ 516 uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 13, SDL_TRUE); 517 SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue"); 518 SDLTest_AssertCheck( 519 uresult == 10 || uresult == 11 || uresult == 12 || uresult == 13, 520 "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", uresult); 521 522 /* RandomUintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */ 523 uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(10, 20, SDL_TRUE); 524 SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue"); 525 SDLTest_AssertCheck( 526 uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20, 527 "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult); 528 529 /* RandomUintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */ 530 uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(20, 10, SDL_TRUE); 531 SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue"); 532 SDLTest_AssertCheck( 533 uresult == 10 || uresult == 11 || uresult == 19 || uresult == 20, 534 "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", uresult); 535 536 /* RandomUintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */ 537 uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(1, 20, SDL_FALSE); 538 SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue"); 539 SDLTest_AssertCheck( 540 uresult == 0 || uresult == 21, 541 "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", uresult); 542 543 /* RandomUintXBoundaryValue(0, 99, SDL_FALSE) returns 100 */ 544 uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(0, 99, SDL_FALSE); 545 SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue"); 546 SDLTest_AssertCheck( 547 uresult == 100, 548 "Validate result value for parameters (0,99,SDL_FALSE); expected: 100, got: %lld", uresult); 549 550 /* RandomUintXBoundaryValue(1, 0xffffffffffffffff, SDL_FALSE) returns 0 (no error) */ 551 uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(1, (Uint64)0xffffffffffffffffULL, SDL_FALSE); 552 SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue"); 553 SDLTest_AssertCheck( 554 uresult == 0, 555 "Validate result value for parameters (1,0xffffffffffffffff,SDL_FALSE); expected: 0, got: %lld", uresult); 556 lastError = (char *)SDL_GetError(); 557 SDLTest_AssertPass("SDL_GetError()"); 558 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 559 560 /* RandomUintXBoundaryValue(0, 0xfffffffffffffffe, SDL_FALSE) returns 0xffffffffffffffff (no error) */ 561 uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(0, (Uint64)0xfffffffffffffffeULL, SDL_FALSE); 562 SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue"); 563 SDLTest_AssertCheck( 564 uresult == (Uint64)0xffffffffffffffffULL, 565 "Validate result value for parameters (0,0xfffffffffffffffe,SDL_FALSE); expected: 0xffffffffffffffff, got: %lld", uresult); 566 lastError = (char *)SDL_GetError(); 567 SDLTest_AssertPass("SDL_GetError()"); 568 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 569 570 /* RandomUintXBoundaryValue(0, 0xffffffffffffffff, SDL_FALSE) returns 0 (sets error) */ 571 uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(0, (Uint64)0xffffffffffffffffULL, SDL_FALSE); 572 SDLTest_AssertPass("Call to SDLTest_RandomUint64BoundaryValue"); 573 SDLTest_AssertCheck( 574 uresult == 0, 575 "Validate result value for parameters(0,0xffffffffffffffff,SDL_FALSE); expected: 0, got: %lld", uresult); 576 lastError = (char *)SDL_GetError(); 577 SDLTest_AssertPass("SDL_GetError()"); 578 SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0, 579 "SDL_GetError(): expected message '%s', was message: '%s'", 580 expectedError, 581 lastError); 582 583 /* Clear error messages */ 584 SDL_ClearError(); 585 SDLTest_AssertPass("SDL_ClearError()"); 586 587 return TEST_COMPLETED; 588 } 589 590 /* 591 * @brief Calls to random boundary number generators for Sint8 592 */ 593 int 594 sdltest_randomBoundaryNumberSint8(void *arg) 595 { 596 const char *expectedError = "That operation is not supported"; 597 char *lastError; 598 Sint64 sresult; 599 600 /* Clean error messages */ 601 SDL_ClearError(); 602 SDLTest_AssertPass("SDL_ClearError()"); 603 604 /* RandomSintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */ 605 sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 10, SDL_TRUE); 606 SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue"); 607 SDLTest_AssertCheck( 608 sresult == 10, 609 "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", sresult); 610 611 /* RandomSintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */ 612 sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 11, SDL_TRUE); 613 SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue"); 614 SDLTest_AssertCheck( 615 sresult == 10 || sresult == 11, 616 "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", sresult); 617 618 /* RandomSintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */ 619 sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 12, SDL_TRUE); 620 SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue"); 621 SDLTest_AssertCheck( 622 sresult == 10 || sresult == 11 || sresult == 12, 623 "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", sresult); 624 625 /* RandomSintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */ 626 sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 13, SDL_TRUE); 627 SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue"); 628 SDLTest_AssertCheck( 629 sresult == 10 || sresult == 11 || sresult == 12 || sresult == 13, 630 "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", sresult); 631 632 /* RandomSintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */ 633 sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(10, 20, SDL_TRUE); 634 SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue"); 635 SDLTest_AssertCheck( 636 sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20, 637 "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult); 638 639 /* RandomSintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */ 640 sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(20, 10, SDL_TRUE); 641 SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue"); 642 SDLTest_AssertCheck( 643 sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20, 644 "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult); 645 646 /* RandomSintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */ 647 sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(1, 20, SDL_FALSE); 648 SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue"); 649 SDLTest_AssertCheck( 650 sresult == 0 || sresult == 21, 651 "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", sresult); 652 653 /* RandomSintXBoundaryValue(SCHAR_MIN, 99, SDL_FALSE) returns 100 */ 654 sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(SCHAR_MIN, 99, SDL_FALSE); 655 SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue"); 656 SDLTest_AssertCheck( 657 sresult == 100, 658 "Validate result value for parameters (SCHAR_MIN,99,SDL_FALSE); expected: 100, got: %lld", sresult); 659 660 /* RandomSintXBoundaryValue(SCHAR_MIN + 1, SCHAR_MAX, SDL_FALSE) returns SCHAR_MIN (no error) */ 661 sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(SCHAR_MIN + 1, SCHAR_MAX, SDL_FALSE); 662 SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue"); 663 SDLTest_AssertCheck( 664 sresult == SCHAR_MIN, 665 "Validate result value for parameters (SCHAR_MIN + 1,SCHAR_MAX,SDL_FALSE); expected: %d, got: %lld", SCHAR_MIN, sresult); 666 lastError = (char *)SDL_GetError(); 667 SDLTest_AssertPass("SDL_GetError()"); 668 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 669 670 /* RandomSintXBoundaryValue(SCHAR_MIN, SCHAR_MAX - 1, SDL_FALSE) returns SCHAR_MAX (no error) */ 671 sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(SCHAR_MIN, SCHAR_MAX -1, SDL_FALSE); 672 SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue"); 673 SDLTest_AssertCheck( 674 sresult == SCHAR_MAX, 675 "Validate result value for parameters (SCHAR_MIN,SCHAR_MAX - 1,SDL_FALSE); expected: %d, got: %lld", SCHAR_MAX, sresult); 676 lastError = (char *)SDL_GetError(); 677 SDLTest_AssertPass("SDL_GetError()"); 678 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 679 680 /* RandomSintXBoundaryValue(SCHAR_MIN, SCHAR_MAX, SDL_FALSE) returns SCHAR_MIN (sets error) */ 681 sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(SCHAR_MIN, SCHAR_MAX, SDL_FALSE); 682 SDLTest_AssertPass("Call to SDLTest_RandomSint8BoundaryValue"); 683 SDLTest_AssertCheck( 684 sresult == SCHAR_MIN, 685 "Validate result value for parameters(SCHAR_MIN,SCHAR_MAX,SDL_FALSE); expected: %d, got: %lld", SCHAR_MIN, sresult); 686 lastError = (char *)SDL_GetError(); 687 SDLTest_AssertPass("SDL_GetError()"); 688 SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0, 689 "SDL_GetError(): expected message '%s', was message: '%s'", 690 expectedError, 691 lastError); 692 693 /* Clear error messages */ 694 SDL_ClearError(); 695 SDLTest_AssertPass("SDL_ClearError()"); 696 697 return TEST_COMPLETED; 698 } 699 700 /* 701 * @brief Calls to random boundary number generators for Sint16 702 */ 703 int 704 sdltest_randomBoundaryNumberSint16(void *arg) 705 { 706 const char *expectedError = "That operation is not supported"; 707 char *lastError; 708 Sint64 sresult; 709 710 /* Clean error messages */ 711 SDL_ClearError(); 712 SDLTest_AssertPass("SDL_ClearError()"); 713 714 /* RandomSintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */ 715 sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 10, SDL_TRUE); 716 SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue"); 717 SDLTest_AssertCheck( 718 sresult == 10, 719 "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", sresult); 720 721 /* RandomSintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */ 722 sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 11, SDL_TRUE); 723 SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue"); 724 SDLTest_AssertCheck( 725 sresult == 10 || sresult == 11, 726 "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", sresult); 727 728 /* RandomSintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */ 729 sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 12, SDL_TRUE); 730 SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue"); 731 SDLTest_AssertCheck( 732 sresult == 10 || sresult == 11 || sresult == 12, 733 "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", sresult); 734 735 /* RandomSintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */ 736 sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 13, SDL_TRUE); 737 SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue"); 738 SDLTest_AssertCheck( 739 sresult == 10 || sresult == 11 || sresult == 12 || sresult == 13, 740 "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", sresult); 741 742 /* RandomSintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */ 743 sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(10, 20, SDL_TRUE); 744 SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue"); 745 SDLTest_AssertCheck( 746 sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20, 747 "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult); 748 749 /* RandomSintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */ 750 sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(20, 10, SDL_TRUE); 751 SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue"); 752 SDLTest_AssertCheck( 753 sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20, 754 "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult); 755 756 /* RandomSintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */ 757 sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(1, 20, SDL_FALSE); 758 SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue"); 759 SDLTest_AssertCheck( 760 sresult == 0 || sresult == 21, 761 "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", sresult); 762 763 /* RandomSintXBoundaryValue(SHRT_MIN, 99, SDL_FALSE) returns 100 */ 764 sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(SHRT_MIN, 99, SDL_FALSE); 765 SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue"); 766 SDLTest_AssertCheck( 767 sresult == 100, 768 "Validate result value for parameters (SHRT_MIN,99,SDL_FALSE); expected: 100, got: %lld", sresult); 769 770 /* RandomSintXBoundaryValue(SHRT_MIN + 1, SHRT_MAX, SDL_FALSE) returns SHRT_MIN (no error) */ 771 sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(SHRT_MIN + 1, SHRT_MAX, SDL_FALSE); 772 SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue"); 773 SDLTest_AssertCheck( 774 sresult == SHRT_MIN, 775 "Validate result value for parameters (SHRT_MIN+1,SHRT_MAX,SDL_FALSE); expected: %d, got: %lld", SHRT_MIN, sresult); 776 lastError = (char *)SDL_GetError(); 777 SDLTest_AssertPass("SDL_GetError()"); 778 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 779 780 /* RandomSintXBoundaryValue(SHRT_MIN, SHRT_MAX - 1, SDL_FALSE) returns SHRT_MAX (no error) */ 781 sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(SHRT_MIN, SHRT_MAX - 1, SDL_FALSE); 782 SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue"); 783 SDLTest_AssertCheck( 784 sresult == SHRT_MAX, 785 "Validate result value for parameters (SHRT_MIN,SHRT_MAX - 1,SDL_FALSE); expected: %d, got: %lld", SHRT_MAX, sresult); 786 lastError = (char *)SDL_GetError(); 787 SDLTest_AssertPass("SDL_GetError()"); 788 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 789 790 /* RandomSintXBoundaryValue(SHRT_MIN, SHRT_MAX, SDL_FALSE) returns 0 (sets error) */ 791 sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(SHRT_MIN, SHRT_MAX, SDL_FALSE); 792 SDLTest_AssertPass("Call to SDLTest_RandomSint16BoundaryValue"); 793 SDLTest_AssertCheck( 794 sresult == SHRT_MIN, 795 "Validate result value for parameters(SHRT_MIN,SHRT_MAX,SDL_FALSE); expected: %d, got: %lld", SHRT_MIN, sresult); 796 lastError = (char *)SDL_GetError(); 797 SDLTest_AssertPass("SDL_GetError()"); 798 SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0, 799 "SDL_GetError(): expected message '%s', was message: '%s'", 800 expectedError, 801 lastError); 802 803 /* Clear error messages */ 804 SDL_ClearError(); 805 SDLTest_AssertPass("SDL_ClearError()"); 806 807 return TEST_COMPLETED; 808 } 809 810 /* 811 * @brief Calls to random boundary number generators for Sint32 812 */ 813 int 814 sdltest_randomBoundaryNumberSint32(void *arg) 815 { 816 const char *expectedError = "That operation is not supported"; 817 char *lastError; 818 Sint64 sresult; 819 #if ((ULONG_MAX) == (UINT_MAX)) 820 Sint32 long_min = LONG_MIN; 821 Sint32 long_max = LONG_MAX; 822 #else 823 Sint32 long_min = INT_MIN; 824 Sint32 long_max = INT_MAX; 825 #endif 826 827 /* Clean error messages */ 828 SDL_ClearError(); 829 SDLTest_AssertPass("SDL_ClearError()"); 830 831 /* RandomSintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */ 832 sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 10, SDL_TRUE); 833 SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue"); 834 SDLTest_AssertCheck( 835 sresult == 10, 836 "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", sresult); 837 838 /* RandomSintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */ 839 sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 11, SDL_TRUE); 840 SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue"); 841 SDLTest_AssertCheck( 842 sresult == 10 || sresult == 11, 843 "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", sresult); 844 845 /* RandomSintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */ 846 sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 12, SDL_TRUE); 847 SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue"); 848 SDLTest_AssertCheck( 849 sresult == 10 || sresult == 11 || sresult == 12, 850 "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", sresult); 851 852 /* RandomSintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */ 853 sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 13, SDL_TRUE); 854 SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue"); 855 SDLTest_AssertCheck( 856 sresult == 10 || sresult == 11 || sresult == 12 || sresult == 13, 857 "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", sresult); 858 859 /* RandomSintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */ 860 sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(10, 20, SDL_TRUE); 861 SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue"); 862 SDLTest_AssertCheck( 863 sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20, 864 "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult); 865 866 /* RandomSintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */ 867 sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(20, 10, SDL_TRUE); 868 SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue"); 869 SDLTest_AssertCheck( 870 sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20, 871 "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult); 872 873 /* RandomSintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */ 874 sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(1, 20, SDL_FALSE); 875 SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue"); 876 SDLTest_AssertCheck( 877 sresult == 0 || sresult == 21, 878 "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", sresult); 879 880 /* RandomSintXBoundaryValue(LONG_MIN, 99, SDL_FALSE) returns 100 */ 881 sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(long_min, 99, SDL_FALSE); 882 SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue"); 883 SDLTest_AssertCheck( 884 sresult == 100, 885 "Validate result value for parameters (LONG_MIN,99,SDL_FALSE); expected: 100, got: %lld", sresult); 886 887 /* RandomSintXBoundaryValue(LONG_MIN + 1, LONG_MAX, SDL_FALSE) returns LONG_MIN (no error) */ 888 sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(long_min + 1, long_max, SDL_FALSE); 889 SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue"); 890 SDLTest_AssertCheck( 891 sresult == long_min, 892 "Validate result value for parameters (LONG_MIN+1,LONG_MAX,SDL_FALSE); expected: %d, got: %lld", long_min, sresult); 893 lastError = (char *)SDL_GetError(); 894 SDLTest_AssertPass("SDL_GetError()"); 895 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 896 897 /* RandomSintXBoundaryValue(LONG_MIN, LONG_MAX - 1, SDL_FALSE) returns LONG_MAX (no error) */ 898 sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(long_min, long_max - 1, SDL_FALSE); 899 SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue"); 900 SDLTest_AssertCheck( 901 sresult == long_max, 902 "Validate result value for parameters (LONG_MIN,LONG_MAX - 1,SDL_FALSE); expected: %d, got: %lld", long_max, sresult); 903 lastError = (char *)SDL_GetError(); 904 SDLTest_AssertPass("SDL_GetError()"); 905 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 906 907 /* RandomSintXBoundaryValue(LONG_MIN, LONG_MAX, SDL_FALSE) returns 0 (sets error) */ 908 sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(long_min, long_max, SDL_FALSE); 909 SDLTest_AssertPass("Call to SDLTest_RandomSint32BoundaryValue"); 910 SDLTest_AssertCheck( 911 sresult == long_min, 912 "Validate result value for parameters(LONG_MIN,LONG_MAX,SDL_FALSE); expected: %d, got: %lld", long_min, sresult); 913 lastError = (char *)SDL_GetError(); 914 SDLTest_AssertPass("SDL_GetError()"); 915 SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0, 916 "SDL_GetError(): expected message '%s', was message: '%s'", 917 expectedError, 918 lastError); 919 920 /* Clear error messages */ 921 SDL_ClearError(); 922 SDLTest_AssertPass("SDL_ClearError()"); 923 924 return TEST_COMPLETED; 925 } 926 927 /* 928 * @brief Calls to random boundary number generators for Sint64 929 */ 930 int 931 sdltest_randomBoundaryNumberSint64(void *arg) 932 { 933 const char *expectedError = "That operation is not supported"; 934 char *lastError; 935 Sint64 sresult; 936 937 /* Clean error messages */ 938 SDL_ClearError(); 939 SDLTest_AssertPass("SDL_ClearError()"); 940 941 /* RandomSintXBoundaryValue(10, 10, SDL_TRUE) returns 10 */ 942 sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 10, SDL_TRUE); 943 SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue"); 944 SDLTest_AssertCheck( 945 sresult == 10, 946 "Validate result value for parameters (10,10,SDL_TRUE); expected: 10, got: %lld", sresult); 947 948 /* RandomSintXBoundaryValue(10, 11, SDL_TRUE) returns 10, 11 */ 949 sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 11, SDL_TRUE); 950 SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue"); 951 SDLTest_AssertCheck( 952 sresult == 10 || sresult == 11, 953 "Validate result value for parameters (10,11,SDL_TRUE); expected: 10|11, got: %lld", sresult); 954 955 /* RandomSintXBoundaryValue(10, 12, SDL_TRUE) returns 10, 11, 12 */ 956 sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 12, SDL_TRUE); 957 SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue"); 958 SDLTest_AssertCheck( 959 sresult == 10 || sresult == 11 || sresult == 12, 960 "Validate result value for parameters (10,12,SDL_TRUE); expected: 10|11|12, got: %lld", sresult); 961 962 /* RandomSintXBoundaryValue(10, 13, SDL_TRUE) returns 10, 11, 12, 13 */ 963 sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 13, SDL_TRUE); 964 SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue"); 965 SDLTest_AssertCheck( 966 sresult == 10 || sresult == 11 || sresult == 12 || sresult == 13, 967 "Validate result value for parameters (10,13,SDL_TRUE); expected: 10|11|12|13, got: %lld", sresult); 968 969 /* RandomSintXBoundaryValue(10, 20, SDL_TRUE) returns 10, 11, 19 or 20 */ 970 sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(10, 20, SDL_TRUE); 971 SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue"); 972 SDLTest_AssertCheck( 973 sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20, 974 "Validate result value for parameters (10,20,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult); 975 976 /* RandomSintXBoundaryValue(20, 10, SDL_TRUE) returns 10, 11, 19 or 20 */ 977 sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(20, 10, SDL_TRUE); 978 SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue"); 979 SDLTest_AssertCheck( 980 sresult == 10 || sresult == 11 || sresult == 19 || sresult == 20, 981 "Validate result value for parameters (20,10,SDL_TRUE); expected: 10|11|19|20, got: %lld", sresult); 982 983 /* RandomSintXBoundaryValue(1, 20, SDL_FALSE) returns 0, 21 */ 984 sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(1, 20, SDL_FALSE); 985 SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue"); 986 SDLTest_AssertCheck( 987 sresult == 0 || sresult == 21, 988 "Validate result value for parameters (1,20,SDL_FALSE); expected: 0|21, got: %lld", sresult); 989 990 /* RandomSintXBoundaryValue(LLONG_MIN, 99, SDL_FALSE) returns 100 */ 991 sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN, 99, SDL_FALSE); 992 SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue"); 993 SDLTest_AssertCheck( 994 sresult == 100, 995 "Validate result value for parameters (LLONG_MIN,99,SDL_FALSE); expected: 100, got: %lld", sresult); 996 997 /* RandomSintXBoundaryValue(LLONG_MIN + 1, LLONG_MAX, SDL_FALSE) returns LLONG_MIN (no error) */ 998 sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN + 1, LLONG_MAX, SDL_FALSE); 999 SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue"); 1000 SDLTest_AssertCheck( 1001 sresult == LLONG_MIN, 1002 "Validate result value for parameters (LLONG_MIN+1,LLONG_MAX,SDL_FALSE); expected: %lld, got: %lld", LLONG_MIN, sresult); 1003 lastError = (char *)SDL_GetError(); 1004 SDLTest_AssertPass("SDL_GetError()"); 1005 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 1006 1007 /* RandomSintXBoundaryValue(LLONG_MIN, LLONG_MAX - 1, SDL_FALSE) returns LLONG_MAX (no error) */ 1008 sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN, LLONG_MAX - 1, SDL_FALSE); 1009 SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue"); 1010 SDLTest_AssertCheck( 1011 sresult == LLONG_MAX, 1012 "Validate result value for parameters (LLONG_MIN,LLONG_MAX - 1,SDL_FALSE); expected: %lld, got: %lld", LLONG_MAX, sresult); 1013 lastError = (char *)SDL_GetError(); 1014 SDLTest_AssertPass("SDL_GetError()"); 1015 SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set"); 1016 1017 /* RandomSintXBoundaryValue(LLONG_MIN, LLONG_MAX, SDL_FALSE) returns 0 (sets error) */ 1018 sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN, LLONG_MAX, SDL_FALSE); 1019 SDLTest_AssertPass("Call to SDLTest_RandomSint64BoundaryValue"); 1020 SDLTest_AssertCheck( 1021 sresult == LLONG_MIN, 1022 "Validate result value for parameters(LLONG_MIN,LLONG_MAX,SDL_FALSE); expected: %lld, got: %lld", LLONG_MIN, sresult); 1023 lastError = (char *)SDL_GetError(); 1024 SDLTest_AssertPass("SDL_GetError()"); 1025 SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0, 1026 "SDL_GetError(): expected message '%s', was message: '%s'", 1027 expectedError, 1028 lastError); 1029 1030 /* Clear error messages */ 1031 SDL_ClearError(); 1032 SDLTest_AssertPass("SDL_ClearError()"); 1033 1034 return TEST_COMPLETED; 1035 } 1036 1037 /** 1038 * @brief Calls to SDLTest_RandomIntegerInRange 1039 */ 1040 int 1041 sdltest_randomIntegerInRange(void *arg) 1042 { 1043 Sint32 min, max; 1044 Sint32 result; 1045 #if ((ULONG_MAX) == (UINT_MAX)) 1046 Sint32 long_min = LONG_MIN; 1047 Sint32 long_max = LONG_MAX; 1048 #else 1049 Sint32 long_min = INT_MIN; 1050 Sint32 long_max = INT_MAX; 1051 #endif 1052 1053 /* Standard range */ 1054 min = (Sint32)SDLTest_RandomSint16(); 1055 max = min + (Sint32)SDLTest_RandomUint8() + 2; 1056 result = SDLTest_RandomIntegerInRange(min, max); 1057 SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(min,max)"); 1058 SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result); 1059 1060 /* One Range */ 1061 min = (Sint32)SDLTest_RandomSint16(); 1062 max = min + 1; 1063 result = SDLTest_RandomIntegerInRange(min, max); 1064 SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(min,min+1)"); 1065 SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result); 1066 1067 /* Zero range */ 1068 min = (Sint32)SDLTest_RandomSint16(); 1069 max = min; 1070 result = SDLTest_RandomIntegerInRange(min, max); 1071 SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(min,min)"); 1072 SDLTest_AssertCheck(min == result, "Validated returned value; expected: %d, got: %d", min, result); 1073 1074 /* Zero range at zero */ 1075 min = 0; 1076 max = 0; 1077 result = SDLTest_RandomIntegerInRange(min, max); 1078 SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(0,0)"); 1079 SDLTest_AssertCheck(result == 0, "Validated returned value; expected: 0, got: %d", min, max, result); 1080 1081 /* Swapped min-max */ 1082 min = (Sint32)SDLTest_RandomSint16(); 1083 max = min + (Sint32)SDLTest_RandomUint8() + 2; 1084 result = SDLTest_RandomIntegerInRange(max, min); 1085 SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(max,min)"); 1086 SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result); 1087 1088 /* Range with min at integer limit */ 1089 min = long_min; 1090 max = long_max + (Sint32)SDLTest_RandomSint16(); 1091 result = SDLTest_RandomIntegerInRange(min, max); 1092 SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(SINT32_MIN,...)"); 1093 SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result); 1094 1095 /* Range with max at integer limit */ 1096 min = long_min - (Sint32)SDLTest_RandomSint16();; 1097 max = long_max; 1098 result = SDLTest_RandomIntegerInRange(min, max); 1099 SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(...,SINT32_MAX)"); 1100 SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result); 1101 1102 /* Full integer range */ 1103 min = long_min; 1104 max = long_max; 1105 result = SDLTest_RandomIntegerInRange(min, max); 1106 SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(SINT32_MIN,SINT32_MAX)"); 1107 SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result); 1108 1109 return TEST_COMPLETED; 1110 } 1111 1112 /** 1113 * @brief Calls to SDLTest_RandomAsciiString 1114 */ 1115 int 1116 sdltest_randomAsciiString(void *arg) 1117 { 1118 char* result; 1119 int len; 1120 int nonAsciiCharacters; 1121 int i; 1122 1123 result = SDLTest_RandomAsciiString(); 1124 SDLTest_AssertPass("Call to SDLTest_RandomAsciiString()"); 1125 SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL"); 1126 if (result != NULL) { 1127 len = SDL_strlen(result); 1128 SDLTest_AssertCheck(len >= 0 && len <= 255, "Validate that result length; expected: len=[1,255], got: %d", len); 1129 nonAsciiCharacters = 0; 1130 for (i=0; i<len; i++) { 1131 if (iscntrl(result[i])) { 1132 nonAsciiCharacters++; 1133 } 1134 } 1135 SDLTest_AssertCheck(nonAsciiCharacters == 0, "Validate that result does not contain non-Ascii characters, got: %d", nonAsciiCharacters); 1136 if (nonAsciiCharacters) { 1137 SDLTest_LogError("Invalid result from generator: '%s'", result); 1138 } 1139 SDL_free(result); 1140 } 1141 1142 return TEST_COMPLETED; 1143 } 1144 1145 1146 /** 1147 * @brief Calls to SDLTest_RandomAsciiStringWithMaximumLength 1148 */ 1149 int 1150 sdltest_randomAsciiStringWithMaximumLength(void *arg) 1151 { 1152 const char* expectedError = "Parameter 'maxLength' is invalid"; 1153 char* lastError; 1154 char* result; 1155 int targetLen; 1156 int len; 1157 int nonAsciiCharacters; 1158 int i; 1159 1160 targetLen = 16 + SDLTest_RandomUint8(); 1161 result = SDLTest_RandomAsciiStringWithMaximumLength(targetLen); 1162 SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringWithMaximumLength(%d)", targetLen); 1163 SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL"); 1164 if (result != NULL) { 1165 len = SDL_strlen(result); 1166 SDLTest_AssertCheck(len >= 0 && len <= targetLen, "Validate that result length; expected: len=[1,%d], got: %d", targetLen, len); 1167 nonAsciiCharacters = 0; 1168 for (i=0; i<len; i++) { 1169 if (iscntrl(result[i])) { 1170 nonAsciiCharacters++; 1171 } 1172 } 1173 SDLTest_AssertCheck(nonAsciiCharacters == 0, "Validate that result does not contain non-Ascii characters, got: %d", nonAsciiCharacters); 1174 if (nonAsciiCharacters) { 1175 SDLTest_LogError("Invalid result from generator: '%s'", result); 1176 } 1177 SDL_free(result); 1178 } 1179 1180 /* Negative test */ 1181 targetLen = 0; 1182 result = SDLTest_RandomAsciiStringWithMaximumLength(targetLen); 1183 SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringWithMaximumLength(%d)", targetLen); 1184 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); 1185 lastError = (char *)SDL_GetError(); 1186 SDLTest_AssertPass("SDL_GetError()"); 1187 SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0, 1188 "SDL_GetError(): expected message '%s', was message: '%s'", 1189 expectedError, 1190 lastError); 1191 1192 /* Clear error messages */ 1193 SDL_ClearError(); 1194 SDLTest_AssertPass("SDL_ClearError()"); 1195 1196 return TEST_COMPLETED; 1197 } 1198 1199 /** 1200 * @brief Calls to SDLTest_RandomAsciiStringOfSize 1201 */ 1202 int 1203 sdltest_randomAsciiStringOfSize(void *arg) 1204 { 1205 const char* expectedError = "Parameter 'size' is invalid"; 1206 char* lastError; 1207 char* result; 1208 int targetLen; 1209 int len; 1210 int nonAsciiCharacters; 1211 int i; 1212 1213 /* Positive test */ 1214 targetLen = 16 + SDLTest_RandomUint8(); 1215 result = SDLTest_RandomAsciiStringOfSize(targetLen); 1216 SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringOfSize(%d)", targetLen); 1217 SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL"); 1218 if (result != NULL) { 1219 len = SDL_strlen(result); 1220 SDLTest_AssertCheck(len == targetLen, "Validate that result length; expected: len=%d, got: %d", targetLen, len); 1221 nonAsciiCharacters = 0; 1222 for (i=0; i<len; i++) { 1223 if (iscntrl(result[i])) { 1224 nonAsciiCharacters++; 1225 } 1226 } 1227 SDLTest_AssertCheck(nonAsciiCharacters == 0, "Validate that result does not contain non-ASCII characters, got: %d", nonAsciiCharacters); 1228 if (nonAsciiCharacters) { 1229 SDLTest_LogError("Invalid result from generator: '%s'", result); 1230 } 1231 SDL_free(result); 1232 } 1233 1234 /* Negative test */ 1235 targetLen = 0; 1236 result = SDLTest_RandomAsciiStringOfSize(targetLen); 1237 SDLTest_AssertPass("Call to SDLTest_RandomAsciiStringOfSize(%d)", targetLen); 1238 SDLTest_AssertCheck(result == NULL, "Validate that result is NULL"); 1239 lastError = (char *)SDL_GetError(); 1240 SDLTest_AssertPass("SDL_GetError()"); 1241 SDLTest_AssertCheck(lastError != NULL && SDL_strcmp(lastError, expectedError) == 0, 1242 "SDL_GetError(): expected message '%s', was message: '%s'", 1243 expectedError, 1244 lastError); 1245 1246 /* Clear error messages */ 1247 SDL_ClearError(); 1248 SDLTest_AssertPass("SDL_ClearError()"); 1249 1250 return TEST_COMPLETED; 1251 } 1252 1253 1254 /* ================= Test References ================== */ 1255 1256 /* SDL_test test cases */ 1257 static const SDLTest_TestCaseReference sdltestTest1 = 1258 { (SDLTest_TestCaseFp)sdltest_getFuzzerInvocationCount, "sdltest_getFuzzerInvocationCount", "Call to sdltest_GetFuzzerInvocationCount", TEST_ENABLED }; 1259 1260 static const SDLTest_TestCaseReference sdltestTest2 = 1261 { (SDLTest_TestCaseFp)sdltest_randomNumber, "sdltest_randomNumber", "Calls to random number generators", TEST_ENABLED }; 1262 1263 static const SDLTest_TestCaseReference sdltestTest3 = 1264 { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberUint8, "sdltest_randomBoundaryNumberUint8", "Calls to random boundary number generators for Uint8", TEST_ENABLED }; 1265 1266 static const SDLTest_TestCaseReference sdltestTest4 = 1267 { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberUint16, "sdltest_randomBoundaryNumberUint16", "Calls to random boundary number generators for Uint16", TEST_ENABLED }; 1268 1269 static const SDLTest_TestCaseReference sdltestTest5 = 1270 { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberUint32, "sdltest_randomBoundaryNumberUint32", "Calls to random boundary number generators for Uint32", TEST_ENABLED }; 1271 1272 static const SDLTest_TestCaseReference sdltestTest6 = 1273 { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberUint64, "sdltest_randomBoundaryNumberUint64", "Calls to random boundary number generators for Uint64", TEST_ENABLED }; 1274 1275 static const SDLTest_TestCaseReference sdltestTest7 = 1276 { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberSint8, "sdltest_randomBoundaryNumberSint8", "Calls to random boundary number generators for Sint8", TEST_ENABLED }; 1277 1278 static const SDLTest_TestCaseReference sdltestTest8 = 1279 { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberSint16, "sdltest_randomBoundaryNumberSint16", "Calls to random boundary number generators for Sint16", TEST_ENABLED }; 1280 1281 static const SDLTest_TestCaseReference sdltestTest9 = 1282 { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberSint32, "sdltest_randomBoundaryNumberSint32", "Calls to random boundary number generators for Sint32", TEST_ENABLED }; 1283 1284 static const SDLTest_TestCaseReference sdltestTest10 = 1285 { (SDLTest_TestCaseFp)sdltest_randomBoundaryNumberSint64, "sdltest_randomBoundaryNumberSint64", "Calls to random boundary number generators for Sint64", TEST_ENABLED }; 1286 1287 static const SDLTest_TestCaseReference sdltestTest11 = 1288 { (SDLTest_TestCaseFp)sdltest_randomIntegerInRange, "sdltest_randomIntegerInRange", "Calls to ranged random number generator", TEST_ENABLED }; 1289 1290 static const SDLTest_TestCaseReference sdltestTest12 = 1291 { (SDLTest_TestCaseFp)sdltest_randomAsciiString, "sdltest_randomAsciiString", "Calls to default ASCII string generator", TEST_ENABLED }; 1292 1293 static const SDLTest_TestCaseReference sdltestTest13 = 1294 { (SDLTest_TestCaseFp)sdltest_randomAsciiStringWithMaximumLength, "sdltest_randomAsciiStringWithMaximumLength", "Calls to random maximum length ASCII string generator", TEST_ENABLED }; 1295 1296 static const SDLTest_TestCaseReference sdltestTest14 = 1297 { (SDLTest_TestCaseFp)sdltest_randomAsciiStringOfSize, "sdltest_randomAsciiStringOfSize", "Calls to fixed size ASCII string generator", TEST_ENABLED }; 1298 1299 static const SDLTest_TestCaseReference sdltestTest15 = 1300 { (SDLTest_TestCaseFp)sdltest_generateRunSeed, "sdltest_generateRunSeed", "Checks internal harness function SDLTest_GenerateRunSeed", TEST_ENABLED }; 1301 1302 /* Sequence of SDL_test test cases */ 1303 static const SDLTest_TestCaseReference *sdltestTests[] = { 1304 &sdltestTest1, &sdltestTest2, &sdltestTest3, &sdltestTest4, &sdltestTest5, &sdltestTest6, 1305 &sdltestTest7, &sdltestTest8, &sdltestTest9, &sdltestTest10, &sdltestTest11, &sdltestTest12, 1306 &sdltestTest13, &sdltestTest14, &sdltestTest15, NULL 1307 }; 1308 1309 /* SDL_test test suite (global) */ 1310 SDLTest_TestSuiteReference sdltestTestSuite = { 1311 "SDLtest", 1312 NULL, 1313 sdltestTests, 1314 NULL 1315 }; 1316