Commit 8e4d7085 authored by Markus Kauppila's avatar Markus Kauppila

Added random number generators for Uint8, Sint8, Uint16, Sint16,

Uint64 and Sint64.
parent 694dda2a
......@@ -26,6 +26,9 @@
#include "fuzzer.h"
/*!
* Note: doxygen documentation markup is in the header file.
*/
//! context for test-specific random number generator
static RND_CTX rndContext;
......@@ -105,6 +108,30 @@ DeinitFuzzer()
}
Uint8
RandomUint8()
{
return (Uint8) utl_randomInt(&rndContext) & 0x000000FF;
}
Sint8
RandomSint8()
{
return (Sint8) utl_randomInt(&rndContext) & 0x000000FF;
}
Uint16
RandomUint16()
{
return (Uint16) utl_randomInt(&rndContext) & 0x0000FFFF;
}
Sint16
RandomSint16()
{
return (Sint16) utl_randomInt(&rndContext) & 0x0000FFFF;
}
Sint32
RandomInteger()
{
......@@ -117,6 +144,36 @@ RandomPositiveInteger()
return (Uint32) utl_randomInt(&rndContext);
}
Uint64
RandomUint64()
{
Uint8 string[16];
int counter = 0;
for( ; counter < 16; ++counter) {
string[counter] = (Uint8) RandomIntegerInRange(0, 255);
}
Uint64 *value = (Uint64 *)string;
return value[0];
}
Sint64
RandomSint64()
{
Uint8 string[16];
int counter = 0;
for( ; counter < 16; ++counter) {
string[counter] = (Uint8) RandomIntegerInRange(0, 255);
}
Sint64 *value = (Sint64 *)string;
return value[0];
}
Sint32
RandomIntegerInRange(Sint32 pMin, Sint32 pMax)
{
......@@ -507,6 +564,10 @@ RandomSint64BoundaryValue(Sint64 boundary1, Sint64 boundary2, SDL_bool validDoma
return retVal;
}
float RandomFloat() {
return (float) utl_randomInt(&rndContext) / UINT_MAX;
}
char *
RandomAsciiString()
{
......@@ -521,7 +582,7 @@ RandomAsciiStringWithMaximumLength(int maxSize)
}
int size = (abs(RandomInteger()) % (maxSize + 1)) + 1;
char *string = SDL_malloc(size * sizeof(size));
char *string = SDL_malloc(size * sizeof(char));
int counter = 0;
for( ; counter < size; ++counter) {
......
......@@ -40,6 +40,36 @@ void InitFuzzer(Uint64 execKey);
void DeinitFuzzer();
/*!
* Returns a random Uint8
*
* \returns Generated integer
*/
Uint8 RandomUint8();
/*!
* Returns a random Sint8
*
* \returns Generated signed integer
*/
Sint8 RandomSint8();
/*!
* Returns a random Uint16
*
* \returns Generated integer
*/
Uint16 RandomUint16();
/*!
* Returns a random Sint16
*
* \returns Generated signed integer
*/
Sint16 RandomSint16();
/*!
* Returns a random integer
*
......@@ -55,6 +85,25 @@ Sint32 RandomInteger();
*/
Uint32 RandomPositiveInteger();
/*!
* Returns random Uint64.
*
* \returns Generated integer
*/
Uint64 RandomUint64();
/*!
* Returns random Sint64.
*
* \returns Generated signed integer
*/
Sint64 RandomSint64();
/*!
* Returns random float in range [0.0 - 1.0] (inclusive)
*/
float RandomFloat();
/*!
* Returns a random boundary value for Uint8 within the given boundaries.
......
......@@ -100,6 +100,8 @@ dummycase1(void *arg)
//Log(0, "uint8 (same value): %d", RandomUint8BoundaryValue(200, 200, SDL_TRUE));
for(; 01 ; )
printf("%d\n", RandomSint16());
for( ; 0 ; ) {
//Log(0, "sint8: %d", RandomSint8BoundaryValue(-11, 10, SDL_TRUE));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment