Added random number generators for Uint8, Sint8, Uint16, Sint16,
authorMarkus Kauppila <markus.kauppila@gmail.com>
Thu, 11 Aug 2011 12:48:45 +0300
changeset 5824 5205ba7c497c
parent 5823 6db8267b78f9
child 5825 9dd4fa61d5cc
Added random number generators for Uint8, Sint8, Uint16, Sint16, Uint64 and Sint64.
test/test-automation/src/libSDLtest/fuzzer/fuzzer.c
test/test-automation/src/libSDLtest/fuzzer/fuzzer.h
test/test-automation/tests/testdummy/testdummy.c
--- a/test/test-automation/src/libSDLtest/fuzzer/fuzzer.c	Wed Aug 10 20:59:42 2011 +0300
+++ b/test/test-automation/src/libSDLtest/fuzzer/fuzzer.c	Thu Aug 11 12:48:45 2011 +0300
@@ -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 @@
 
 }
 
+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 @@
 	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 @@
 	return retVal;
 }
 
+float RandomFloat() {
+	return (float) utl_randomInt(&rndContext) / UINT_MAX;
+}
+
 char *
 RandomAsciiString()
 {
@@ -521,7 +582,7 @@
 	}
 
 	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) {
--- a/test/test-automation/src/libSDLtest/fuzzer/fuzzer.h	Wed Aug 10 20:59:42 2011 +0300
+++ b/test/test-automation/src/libSDLtest/fuzzer/fuzzer.h	Thu Aug 11 12:48:45 2011 +0300
@@ -41,6 +41,36 @@
 
 
 /*!
+ * 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
  *
  * \returns Generated integer
@@ -55,6 +85,25 @@
  */
 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.
--- a/test/test-automation/tests/testdummy/testdummy.c	Wed Aug 10 20:59:42 2011 +0300
+++ b/test/test-automation/tests/testdummy/testdummy.c	Thu Aug 11 12:48:45 2011 +0300
@@ -100,6 +100,8 @@
 
 	//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));