diff --git a/include/SDL_test_fuzzer.h b/include/SDL_test_fuzzer.h index 178f26e82..e759c0244 100644 --- a/include/SDL_test_fuzzer.h +++ b/include/SDL_test_fuzzer.h @@ -323,7 +323,10 @@ Sint64 SDLTest_RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL * If Max in smaller tham min, then the values are swapped. * Min and max are the same value, that value will be returned. * - * \returns Generated integer + * \param min Minimum inclusive value of returned random number + * \param max Maximum inclusive value of returned random number + * + * \returns Generated random integer in range */ Sint32 SDLTest_RandomIntegerInRange(Sint32 min, Sint32 max); diff --git a/test/testautomation_sdltest.c b/test/testautomation_sdltest.c index 108b65b77..fc9a13c86 100644 --- a/test/testautomation_sdltest.c +++ b/test/testautomation_sdltest.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "SDL.h" #include "SDL_test.h" @@ -984,6 +985,216 @@ sdltest_randomBoundaryNumberSint64(void *arg) return TEST_COMPLETED; } +/** + * @brief Calls to SDLTest_RandomIntegerInRange + */ +int +sdltest_randomIntegerInRange(void *arg) +{ + Sint32 min, max; + Sint32 result; + + /* Standard range */ + min = (Sint32)SDLTest_RandomSint16(); + max = min + (Sint32)SDLTest_RandomUint8() + 2; + result = SDLTest_RandomIntegerInRange(min, max); + SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(min,max)"); + SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result); + + /* One Range */ + min = (Sint32)SDLTest_RandomSint16(); + max = min + 1; + result = SDLTest_RandomIntegerInRange(min, max); + SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(min,min+1)"); + SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result); + + /* Zero range */ + min = (Sint32)SDLTest_RandomSint16(); + max = min; + result = SDLTest_RandomIntegerInRange(min, max); + SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(min,min)"); + SDLTest_AssertCheck(min == result, "Validated returned value; expected: %d, got: %d", min, result); + + /* Zero range at zero */ + min = 0; + max = 0; + result = SDLTest_RandomIntegerInRange(min, max); + SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(0,0)"); + SDLTest_AssertCheck(result == 0, "Validated returned value; expected: 0, got: %d", min, max, result); + + /* Swapped min-max */ + min = (Sint32)SDLTest_RandomSint16(); + max = min + (Sint32)SDLTest_RandomUint8() + 2; + result = SDLTest_RandomIntegerInRange(max, min); + SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(max,min)"); + SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result); + + + /* Range with min at integer limit */ + min = LONG_MIN; + max = LONG_MIN + (Sint32)SDLTest_RandomSint16(); + result = SDLTest_RandomIntegerInRange(min, max); + SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(SINT32_MIN,...)"); + SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result); + + /* Range with max at integer limit */ + min = LONG_MAX - (Sint32)SDLTest_RandomSint16();; + max = LONG_MAX; + result = SDLTest_RandomIntegerInRange(min, max); + SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(...,SINT32_MAX)"); + SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result); + + /* Full integer range */ + min = LONG_MIN; + max = LONG_MAX; + result = SDLTest_RandomIntegerInRange(min, max); + SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(SINT32_MIN,SINT32_MAX)"); + SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%d,%d], got: %d", min, max, result); + + return TEST_COMPLETED; +} + +/** + * @brief Calls to SDLTest_RandomAsciiString + */ +int +sdltest_randomAsciiString(void *arg) +{ + char* result; + int len; + int nonAsciiCharacters; + int i; + + result = SDLTest_RandomAsciiString(); + SDLTest_AssertPass("Call to SDLTest_RandomAsciiString()"); + SDLTest_AssertCheck(result != NULL, "Validate that result is not NULL"); + if (result != NULL) { + len = SDL_strlen(result); + SDLTest_AssertCheck(len >= 0 && len <= 255, "Validate that result length; expected: len=[1,255], got: %d", len); + nonAsciiCharacters = 0; + for (i=0; i= 0 && len <= targetLen, "Validate that result length; expected: len=[1,%d], got: %d", targetLen, len); + nonAsciiCharacters = 0; + for (i=0; i