Add SDL_test test suite; add fuzzer test cases; fix fuzzer bug; fix compiler warnings
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Fri, 08 Feb 2013 07:14:50 -0800
changeset 6839 2494f667555c
parent 6838 abd1407af1f9
child 6840 9fb970f83002
Add SDL_test test suite; add fuzzer test cases; fix fuzzer bug; fix compiler warnings
VisualC/tests/testautomation/testautomation_vs2010.vcxproj
VisualC/tests/testautomation/testautomation_vs2012.vcxproj
src/test/SDL_test_fuzzer.c
src/video/windows/SDL_windowswindow.c
test/Makefile.in
test/testautomation_audio.c
test/testautomation_sdltest.c
test/testautomation_suites.h
--- a/VisualC/tests/testautomation/testautomation_vs2010.vcxproj	Fri Feb 08 01:12:48 2013 -0800
+++ b/VisualC/tests/testautomation/testautomation_vs2010.vcxproj	Fri Feb 08 07:14:50 2013 -0800
@@ -188,6 +188,7 @@
     <ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
     <ClCompile Include="..\..\..\test\testautomation_video.c" />
     <ClCompile Include="..\..\..\test\testautomation_syswm.c" />
+    <ClCompile Include="..\..\..\test\testautomation_sdltest.c" />
     <ClCompile Include="..\..\..\test\testautomation_mouse.c" />
     <ClCompile Include="..\..\..\test\testautomation_timer.c" />
   </ItemGroup>
--- a/VisualC/tests/testautomation/testautomation_vs2012.vcxproj	Fri Feb 08 01:12:48 2013 -0800
+++ b/VisualC/tests/testautomation/testautomation_vs2012.vcxproj	Fri Feb 08 07:14:50 2013 -0800
@@ -192,6 +192,7 @@
     <ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
     <ClCompile Include="..\..\..\test\testautomation_video.c" />
     <ClCompile Include="..\..\..\test\testautomation_syswm.c" />
+    <ClCompile Include="..\..\..\test\testautomation_sdltest.c" />
     <ClCompile Include="..\..\..\test\testautomation_mouse.c" />
     <ClCompile Include="..\..\..\test\testautomation_timer.c" />
   </ItemGroup>
--- a/src/test/SDL_test_fuzzer.c	Fri Feb 08 01:12:48 2013 -0800
+++ b/src/test/SDL_test_fuzzer.c	Fri Feb 08 07:14:50 2013 -0800
@@ -586,7 +586,7 @@
 float
 SDLTest_RandomFloat()
 {
-        return (float) (FLT_MIN + SDLTest_RandomUnitDouble() * (FLT_MAX - FLT_MIN));
+        return (float) (SDLTest_RandomUnitDouble() * (double)2.0 * (double)FLT_MAX - (double)(FLT_MAX));
 }
 
 double
--- a/src/video/windows/SDL_windowswindow.c	Fri Feb 08 01:12:48 2013 -0800
+++ b/src/video/windows/SDL_windowswindow.c	Fri Feb 08 07:14:50 2013 -0800
@@ -557,7 +557,7 @@
 	{
 		HWND top;
 		SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
-		HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
+		HWND hwnd = data->hwnd;
 		UINT flags = SWP_NOMOVE | SWP_NOSIZE;
 
 		if ( SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS ) ) {
--- a/test/Makefile.in	Fri Feb 08 01:12:48 2013 -0800
+++ b/test/Makefile.in	Fri Feb 08 07:14:50 2013 -0800
@@ -80,6 +80,7 @@
 		      $(srcdir)/testautomation_keyboard.c \
 		      $(srcdir)/testautomation_video.c \
 		      $(srcdir)/testautomation_syswm.c \
+		      $(srcdir)/testautomation_sdltest.c \
 		      $(srcdir)/testautomation_mouse.c \
 		      $(srcdir)/testautomation_timer.c
 	$(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS) 
--- a/test/testautomation_audio.c	Fri Feb 08 01:12:48 2013 -0800
+++ b/test/testautomation_audio.c	Fri Feb 08 07:14:50 2013 -0800
@@ -612,7 +612,7 @@
  */
 int audio_openCloseAudioDeviceConnected()
 {
-   int result;
+   int result = -1;
    int i;
    int count;
    char *device;   
@@ -641,7 +641,7 @@
        /* Open device */
        id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
        SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
-       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
+       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >1, got: %i", id);
        if (id > 1) {
 
 /* TODO: enable test code when function is available in SDL2 */
@@ -650,8 +650,8 @@
          /* Get connected status */
          result = SDL_AudioDeviceConnected(id);
          SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
-         SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 0; got: %i", result);
 #endif
+         SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 1; got: %i", result);
          
          /* Close device again */
          SDL_CloseAudioDevice(id);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/testautomation_sdltest.c	Fri Feb 08 07:14:50 2013 -0800
@@ -0,0 +1,138 @@
+/**
+ * SDL_test test suite
+ */
+
+#include <stdio.h>
+#include <limits.h>
+#include <float.h>
+
+#include "SDL.h"
+#include "SDL_test.h"
+
+/* Test case functions */
+
+/**
+ * @brief Calls to SDLTest_GetFuzzerInvocationCount()
+ */
+int
+sdltest_getFuzzerInvocationCount(void *arg)
+{
+  Uint8 result;
+  int fuzzerCount1, fuzzerCount2;
+ 
+  fuzzerCount1 = SDLTest_GetFuzzerInvocationCount();
+  SDLTest_AssertPass("Call to SDLTest_GetFuzzerInvocationCount()");
+  SDLTest_AssertCheck(fuzzerCount1 >= 0, "Verify returned value, expected: >=0, got: %d", fuzzerCount1);
+     
+  result = SDLTest_RandomUint8();
+  SDLTest_AssertPass("Call to SDLTest_RandomUint8(), returned %d", result);
+
+  fuzzerCount2 = SDLTest_GetFuzzerInvocationCount();
+  SDLTest_AssertPass("Call to SDLTest_GetFuzzerInvocationCount()");
+  SDLTest_AssertCheck(fuzzerCount2 > fuzzerCount1, "Verify returned value, expected: >%d, got: %d", fuzzerCount1, fuzzerCount2);
+       
+  return TEST_COMPLETED;
+}
+
+
+/**
+ * @brief Calls to random number generators
+ */
+int
+sdltest_randomNumber(void *arg)
+{
+  Sint64 result;
+  Uint64 uresult;
+  double dresult;
+  Uint64 umax;
+  Sint64 min, max;
+     
+  result = (Sint64)SDLTest_RandomUint8();
+  umax = (1 << 8) - 1;
+  SDLTest_AssertPass("Call to SDLTest_RandomUint8");
+  SDLTest_AssertCheck(result >= 0 && result <= umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
+
+  result = (Sint64)SDLTest_RandomSint8();
+  min = 1 - (1 << 7);
+  max =     (1 << 7) - 1;
+  SDLTest_AssertPass("Call to SDLTest_RandomSint8");
+  SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
+  
+  result = (Sint64)SDLTest_RandomUint16();
+  umax = (1 << 16) - 1;
+  SDLTest_AssertPass("Call to SDLTest_RandomUint16");
+  SDLTest_AssertCheck(result >= 0 && result <= umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
+
+  result = (Sint64)SDLTest_RandomSint16();
+  min = 1 - (1 << 15);
+  max =     (1 << 15) - 1;
+  SDLTest_AssertPass("Call to SDLTest_RandomSint16");
+  SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
+
+  result = (Sint64)SDLTest_RandomUint32();
+  umax = ((Uint64)1 << 32) - 1;
+  SDLTest_AssertPass("Call to SDLTest_RandomUint32");
+  SDLTest_AssertCheck(result >= 0 && result <= umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
+
+  result = (Sint64)SDLTest_RandomSint32();
+  min = 1 - ((Sint64)1 << 31);
+  max =     ((Sint64)1 << 31) - 1;
+  SDLTest_AssertPass("Call to SDLTest_RandomSint32");
+  SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
+
+  result = (Sint64)SDLTest_RandomUint32();
+  umax = ((Uint64)1 << 32) - 1;
+  SDLTest_AssertPass("Call to SDLTest_RandomUint32");
+  SDLTest_AssertCheck(result >= 0 && result <= umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
+
+  result = (Sint64)SDLTest_RandomSint32();
+  min = 1 - ((Sint64)1 << 31);
+  max =     ((Sint64)1 << 31) - 1;
+  SDLTest_AssertPass("Call to SDLTest_RandomSint32");
+  SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
+
+  uresult = SDLTest_RandomUint64();
+  SDLTest_AssertPass("Call to SDLTest_RandomUint64");
+
+  result = SDLTest_RandomSint64();
+  SDLTest_AssertPass("Call to SDLTest_RandomSint64");
+
+  dresult = (double)SDLTest_RandomUnitFloat();
+  SDLTest_AssertPass("Call to SDLTest_RandomUnitFloat");
+  SDLTest_AssertCheck(dresult >= 0.0 && dresult < 1.0, "Verify result value, expected: [0.0,1.0[, got: %e", dresult);
+    
+  dresult = (double)SDLTest_RandomFloat();
+  SDLTest_AssertPass("Call to SDLTest_RandomFloat");
+  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);
+
+  dresult = (double)SDLTest_RandomUnitDouble();
+  SDLTest_AssertPass("Call to SDLTest_RandomUnitDouble");
+  SDLTest_AssertCheck(dresult >= 0.0 && dresult < 1.0, "Verify result value, expected: [0.0,1.0[, got: %e", dresult);
+
+  dresult = SDLTest_RandomDouble();
+  SDLTest_AssertPass("Call to SDLTest_RandomDouble");
+    
+  return TEST_COMPLETED;
+}
+
+/* ================= Test References ================== */
+
+/* SDL_test test cases */
+static const SDLTest_TestCaseReference sdltestTest1 =
+		{ (SDLTest_TestCaseFp)sdltest_getFuzzerInvocationCount, "sdltest_getFuzzerInvocationCount", "Call to sdltest_GetFuzzerInvocationCount", TEST_ENABLED };
+
+static const SDLTest_TestCaseReference sdltestTest2 =
+		{ (SDLTest_TestCaseFp)sdltest_randomNumber, "sdltest_randomNumber", "Calls to random number generators", TEST_ENABLED };
+
+/* Sequence of SDL_test test cases */
+static const SDLTest_TestCaseReference *sdltestTests[] =  {
+	&sdltestTest1, &sdltestTest2, NULL
+};
+
+/* SDL_test test suite (global) */
+SDLTest_TestSuiteReference sdltestTestSuite = {
+	"SDLtest",
+	NULL,
+	sdltestTests,
+	NULL
+};
--- a/test/testautomation_suites.h	Fri Feb 08 01:12:48 2013 -0800
+++ b/test/testautomation_suites.h	Fri Feb 08 07:14:50 2013 -0800
@@ -19,6 +19,7 @@
 extern SDLTest_TestSuiteReference rwopsTestSuite;
 extern SDLTest_TestSuiteReference surfaceTestSuite;
 extern SDLTest_TestSuiteReference syswmTestSuite;
+extern SDLTest_TestSuiteReference sdltestTestSuite;
 extern SDLTest_TestSuiteReference videoTestSuite;
 extern SDLTest_TestSuiteReference mouseTestSuite;
 extern SDLTest_TestSuiteReference timerTestSuite;
@@ -35,6 +36,7 @@
 	&rwopsTestSuite,
 	&surfaceTestSuite,
 	&syswmTestSuite,
+	&sdltestTestSuite,
 	&videoTestSuite,
 	&mouseTestSuite,
 	&timerTestSuite,