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 68392494f667555c
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
     1.1 --- a/VisualC/tests/testautomation/testautomation_vs2010.vcxproj	Fri Feb 08 01:12:48 2013 -0800
     1.2 +++ b/VisualC/tests/testautomation/testautomation_vs2010.vcxproj	Fri Feb 08 07:14:50 2013 -0800
     1.3 @@ -188,6 +188,7 @@
     1.4      <ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
     1.5      <ClCompile Include="..\..\..\test\testautomation_video.c" />
     1.6      <ClCompile Include="..\..\..\test\testautomation_syswm.c" />
     1.7 +    <ClCompile Include="..\..\..\test\testautomation_sdltest.c" />
     1.8      <ClCompile Include="..\..\..\test\testautomation_mouse.c" />
     1.9      <ClCompile Include="..\..\..\test\testautomation_timer.c" />
    1.10    </ItemGroup>
     2.1 --- a/VisualC/tests/testautomation/testautomation_vs2012.vcxproj	Fri Feb 08 01:12:48 2013 -0800
     2.2 +++ b/VisualC/tests/testautomation/testautomation_vs2012.vcxproj	Fri Feb 08 07:14:50 2013 -0800
     2.3 @@ -192,6 +192,7 @@
     2.4      <ClCompile Include="..\..\..\test\testautomation_keyboard.c" />
     2.5      <ClCompile Include="..\..\..\test\testautomation_video.c" />
     2.6      <ClCompile Include="..\..\..\test\testautomation_syswm.c" />
     2.7 +    <ClCompile Include="..\..\..\test\testautomation_sdltest.c" />
     2.8      <ClCompile Include="..\..\..\test\testautomation_mouse.c" />
     2.9      <ClCompile Include="..\..\..\test\testautomation_timer.c" />
    2.10    </ItemGroup>
     3.1 --- a/src/test/SDL_test_fuzzer.c	Fri Feb 08 01:12:48 2013 -0800
     3.2 +++ b/src/test/SDL_test_fuzzer.c	Fri Feb 08 07:14:50 2013 -0800
     3.3 @@ -586,7 +586,7 @@
     3.4  float
     3.5  SDLTest_RandomFloat()
     3.6  {
     3.7 -        return (float) (FLT_MIN + SDLTest_RandomUnitDouble() * (FLT_MAX - FLT_MIN));
     3.8 +        return (float) (SDLTest_RandomUnitDouble() * (double)2.0 * (double)FLT_MAX - (double)(FLT_MAX));
     3.9  }
    3.10  
    3.11  double
     4.1 --- a/src/video/windows/SDL_windowswindow.c	Fri Feb 08 01:12:48 2013 -0800
     4.2 +++ b/src/video/windows/SDL_windowswindow.c	Fri Feb 08 07:14:50 2013 -0800
     4.3 @@ -557,7 +557,7 @@
     4.4  	{
     4.5  		HWND top;
     4.6  		SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     4.7 -		HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
     4.8 +		HWND hwnd = data->hwnd;
     4.9  		UINT flags = SWP_NOMOVE | SWP_NOSIZE;
    4.10  
    4.11  		if ( SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_INPUT_FOCUS ) ) {
     5.1 --- a/test/Makefile.in	Fri Feb 08 01:12:48 2013 -0800
     5.2 +++ b/test/Makefile.in	Fri Feb 08 07:14:50 2013 -0800
     5.3 @@ -80,6 +80,7 @@
     5.4  		      $(srcdir)/testautomation_keyboard.c \
     5.5  		      $(srcdir)/testautomation_video.c \
     5.6  		      $(srcdir)/testautomation_syswm.c \
     5.7 +		      $(srcdir)/testautomation_sdltest.c \
     5.8  		      $(srcdir)/testautomation_mouse.c \
     5.9  		      $(srcdir)/testautomation_timer.c
    5.10  	$(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS) 
     6.1 --- a/test/testautomation_audio.c	Fri Feb 08 01:12:48 2013 -0800
     6.2 +++ b/test/testautomation_audio.c	Fri Feb 08 07:14:50 2013 -0800
     6.3 @@ -612,7 +612,7 @@
     6.4   */
     6.5  int audio_openCloseAudioDeviceConnected()
     6.6  {
     6.7 -   int result;
     6.8 +   int result = -1;
     6.9     int i;
    6.10     int count;
    6.11     char *device;   
    6.12 @@ -641,7 +641,7 @@
    6.13         /* Open device */
    6.14         id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
    6.15         SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
    6.16 -       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
    6.17 +       SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >1, got: %i", id);
    6.18         if (id > 1) {
    6.19  
    6.20  /* TODO: enable test code when function is available in SDL2 */
    6.21 @@ -650,8 +650,8 @@
    6.22           /* Get connected status */
    6.23           result = SDL_AudioDeviceConnected(id);
    6.24           SDLTest_AssertPass("Call to SDL_AudioDeviceConnected()");
    6.25 -         SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 0; got: %i", result);
    6.26  #endif
    6.27 +         SDLTest_AssertCheck(result == 1, "Verify returned value; expected: 1; got: %i", result);
    6.28           
    6.29           /* Close device again */
    6.30           SDL_CloseAudioDevice(id);
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/test/testautomation_sdltest.c	Fri Feb 08 07:14:50 2013 -0800
     7.3 @@ -0,0 +1,138 @@
     7.4 +/**
     7.5 + * SDL_test test suite
     7.6 + */
     7.7 +
     7.8 +#include <stdio.h>
     7.9 +#include <limits.h>
    7.10 +#include <float.h>
    7.11 +
    7.12 +#include "SDL.h"
    7.13 +#include "SDL_test.h"
    7.14 +
    7.15 +/* Test case functions */
    7.16 +
    7.17 +/**
    7.18 + * @brief Calls to SDLTest_GetFuzzerInvocationCount()
    7.19 + */
    7.20 +int
    7.21 +sdltest_getFuzzerInvocationCount(void *arg)
    7.22 +{
    7.23 +  Uint8 result;
    7.24 +  int fuzzerCount1, fuzzerCount2;
    7.25 + 
    7.26 +  fuzzerCount1 = SDLTest_GetFuzzerInvocationCount();
    7.27 +  SDLTest_AssertPass("Call to SDLTest_GetFuzzerInvocationCount()");
    7.28 +  SDLTest_AssertCheck(fuzzerCount1 >= 0, "Verify returned value, expected: >=0, got: %d", fuzzerCount1);
    7.29 +     
    7.30 +  result = SDLTest_RandomUint8();
    7.31 +  SDLTest_AssertPass("Call to SDLTest_RandomUint8(), returned %d", result);
    7.32 +
    7.33 +  fuzzerCount2 = SDLTest_GetFuzzerInvocationCount();
    7.34 +  SDLTest_AssertPass("Call to SDLTest_GetFuzzerInvocationCount()");
    7.35 +  SDLTest_AssertCheck(fuzzerCount2 > fuzzerCount1, "Verify returned value, expected: >%d, got: %d", fuzzerCount1, fuzzerCount2);
    7.36 +       
    7.37 +  return TEST_COMPLETED;
    7.38 +}
    7.39 +
    7.40 +
    7.41 +/**
    7.42 + * @brief Calls to random number generators
    7.43 + */
    7.44 +int
    7.45 +sdltest_randomNumber(void *arg)
    7.46 +{
    7.47 +  Sint64 result;
    7.48 +  Uint64 uresult;
    7.49 +  double dresult;
    7.50 +  Uint64 umax;
    7.51 +  Sint64 min, max;
    7.52 +     
    7.53 +  result = (Sint64)SDLTest_RandomUint8();
    7.54 +  umax = (1 << 8) - 1;
    7.55 +  SDLTest_AssertPass("Call to SDLTest_RandomUint8");
    7.56 +  SDLTest_AssertCheck(result >= 0 && result <= umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
    7.57 +
    7.58 +  result = (Sint64)SDLTest_RandomSint8();
    7.59 +  min = 1 - (1 << 7);
    7.60 +  max =     (1 << 7) - 1;
    7.61 +  SDLTest_AssertPass("Call to SDLTest_RandomSint8");
    7.62 +  SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
    7.63 +  
    7.64 +  result = (Sint64)SDLTest_RandomUint16();
    7.65 +  umax = (1 << 16) - 1;
    7.66 +  SDLTest_AssertPass("Call to SDLTest_RandomUint16");
    7.67 +  SDLTest_AssertCheck(result >= 0 && result <= umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
    7.68 +
    7.69 +  result = (Sint64)SDLTest_RandomSint16();
    7.70 +  min = 1 - (1 << 15);
    7.71 +  max =     (1 << 15) - 1;
    7.72 +  SDLTest_AssertPass("Call to SDLTest_RandomSint16");
    7.73 +  SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
    7.74 +
    7.75 +  result = (Sint64)SDLTest_RandomUint32();
    7.76 +  umax = ((Uint64)1 << 32) - 1;
    7.77 +  SDLTest_AssertPass("Call to SDLTest_RandomUint32");
    7.78 +  SDLTest_AssertCheck(result >= 0 && result <= umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
    7.79 +
    7.80 +  result = (Sint64)SDLTest_RandomSint32();
    7.81 +  min = 1 - ((Sint64)1 << 31);
    7.82 +  max =     ((Sint64)1 << 31) - 1;
    7.83 +  SDLTest_AssertPass("Call to SDLTest_RandomSint32");
    7.84 +  SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
    7.85 +
    7.86 +  result = (Sint64)SDLTest_RandomUint32();
    7.87 +  umax = ((Uint64)1 << 32) - 1;
    7.88 +  SDLTest_AssertPass("Call to SDLTest_RandomUint32");
    7.89 +  SDLTest_AssertCheck(result >= 0 && result <= umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
    7.90 +
    7.91 +  result = (Sint64)SDLTest_RandomSint32();
    7.92 +  min = 1 - ((Sint64)1 << 31);
    7.93 +  max =     ((Sint64)1 << 31) - 1;
    7.94 +  SDLTest_AssertPass("Call to SDLTest_RandomSint32");
    7.95 +  SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
    7.96 +
    7.97 +  uresult = SDLTest_RandomUint64();
    7.98 +  SDLTest_AssertPass("Call to SDLTest_RandomUint64");
    7.99 +
   7.100 +  result = SDLTest_RandomSint64();
   7.101 +  SDLTest_AssertPass("Call to SDLTest_RandomSint64");
   7.102 +
   7.103 +  dresult = (double)SDLTest_RandomUnitFloat();
   7.104 +  SDLTest_AssertPass("Call to SDLTest_RandomUnitFloat");
   7.105 +  SDLTest_AssertCheck(dresult >= 0.0 && dresult < 1.0, "Verify result value, expected: [0.0,1.0[, got: %e", dresult);
   7.106 +    
   7.107 +  dresult = (double)SDLTest_RandomFloat();
   7.108 +  SDLTest_AssertPass("Call to SDLTest_RandomFloat");
   7.109 +  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);
   7.110 +
   7.111 +  dresult = (double)SDLTest_RandomUnitDouble();
   7.112 +  SDLTest_AssertPass("Call to SDLTest_RandomUnitDouble");
   7.113 +  SDLTest_AssertCheck(dresult >= 0.0 && dresult < 1.0, "Verify result value, expected: [0.0,1.0[, got: %e", dresult);
   7.114 +
   7.115 +  dresult = SDLTest_RandomDouble();
   7.116 +  SDLTest_AssertPass("Call to SDLTest_RandomDouble");
   7.117 +    
   7.118 +  return TEST_COMPLETED;
   7.119 +}
   7.120 +
   7.121 +/* ================= Test References ================== */
   7.122 +
   7.123 +/* SDL_test test cases */
   7.124 +static const SDLTest_TestCaseReference sdltestTest1 =
   7.125 +		{ (SDLTest_TestCaseFp)sdltest_getFuzzerInvocationCount, "sdltest_getFuzzerInvocationCount", "Call to sdltest_GetFuzzerInvocationCount", TEST_ENABLED };
   7.126 +
   7.127 +static const SDLTest_TestCaseReference sdltestTest2 =
   7.128 +		{ (SDLTest_TestCaseFp)sdltest_randomNumber, "sdltest_randomNumber", "Calls to random number generators", TEST_ENABLED };
   7.129 +
   7.130 +/* Sequence of SDL_test test cases */
   7.131 +static const SDLTest_TestCaseReference *sdltestTests[] =  {
   7.132 +	&sdltestTest1, &sdltestTest2, NULL
   7.133 +};
   7.134 +
   7.135 +/* SDL_test test suite (global) */
   7.136 +SDLTest_TestSuiteReference sdltestTestSuite = {
   7.137 +	"SDLtest",
   7.138 +	NULL,
   7.139 +	sdltestTests,
   7.140 +	NULL
   7.141 +};
     8.1 --- a/test/testautomation_suites.h	Fri Feb 08 01:12:48 2013 -0800
     8.2 +++ b/test/testautomation_suites.h	Fri Feb 08 07:14:50 2013 -0800
     8.3 @@ -19,6 +19,7 @@
     8.4  extern SDLTest_TestSuiteReference rwopsTestSuite;
     8.5  extern SDLTest_TestSuiteReference surfaceTestSuite;
     8.6  extern SDLTest_TestSuiteReference syswmTestSuite;
     8.7 +extern SDLTest_TestSuiteReference sdltestTestSuite;
     8.8  extern SDLTest_TestSuiteReference videoTestSuite;
     8.9  extern SDLTest_TestSuiteReference mouseTestSuite;
    8.10  extern SDLTest_TestSuiteReference timerTestSuite;
    8.11 @@ -35,6 +36,7 @@
    8.12  	&rwopsTestSuite,
    8.13  	&surfaceTestSuite,
    8.14  	&syswmTestSuite,
    8.15 +	&sdltestTestSuite,
    8.16  	&videoTestSuite,
    8.17  	&mouseTestSuite,
    8.18  	&timerTestSuite,