test/testautomation_sdltest.c
author Andreas Schiffler <aschiffler@ferzkopp.net>
Fri, 08 Feb 2013 07:14:50 -0800
changeset 6839 2494f667555c
child 6872 2f4c95464651
permissions -rw-r--r--
Add SDL_test test suite; add fuzzer test cases; fix fuzzer bug; fix compiler warnings
     1 /**
     2  * SDL_test test suite
     3  */
     4 
     5 #include <stdio.h>
     6 #include <limits.h>
     7 #include <float.h>
     8 
     9 #include "SDL.h"
    10 #include "SDL_test.h"
    11 
    12 /* Test case functions */
    13 
    14 /**
    15  * @brief Calls to SDLTest_GetFuzzerInvocationCount()
    16  */
    17 int
    18 sdltest_getFuzzerInvocationCount(void *arg)
    19 {
    20   Uint8 result;
    21   int fuzzerCount1, fuzzerCount2;
    22  
    23   fuzzerCount1 = SDLTest_GetFuzzerInvocationCount();
    24   SDLTest_AssertPass("Call to SDLTest_GetFuzzerInvocationCount()");
    25   SDLTest_AssertCheck(fuzzerCount1 >= 0, "Verify returned value, expected: >=0, got: %d", fuzzerCount1);
    26      
    27   result = SDLTest_RandomUint8();
    28   SDLTest_AssertPass("Call to SDLTest_RandomUint8(), returned %d", result);
    29 
    30   fuzzerCount2 = SDLTest_GetFuzzerInvocationCount();
    31   SDLTest_AssertPass("Call to SDLTest_GetFuzzerInvocationCount()");
    32   SDLTest_AssertCheck(fuzzerCount2 > fuzzerCount1, "Verify returned value, expected: >%d, got: %d", fuzzerCount1, fuzzerCount2);
    33        
    34   return TEST_COMPLETED;
    35 }
    36 
    37 
    38 /**
    39  * @brief Calls to random number generators
    40  */
    41 int
    42 sdltest_randomNumber(void *arg)
    43 {
    44   Sint64 result;
    45   Uint64 uresult;
    46   double dresult;
    47   Uint64 umax;
    48   Sint64 min, max;
    49      
    50   result = (Sint64)SDLTest_RandomUint8();
    51   umax = (1 << 8) - 1;
    52   SDLTest_AssertPass("Call to SDLTest_RandomUint8");
    53   SDLTest_AssertCheck(result >= 0 && result <= umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
    54 
    55   result = (Sint64)SDLTest_RandomSint8();
    56   min = 1 - (1 << 7);
    57   max =     (1 << 7) - 1;
    58   SDLTest_AssertPass("Call to SDLTest_RandomSint8");
    59   SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
    60   
    61   result = (Sint64)SDLTest_RandomUint16();
    62   umax = (1 << 16) - 1;
    63   SDLTest_AssertPass("Call to SDLTest_RandomUint16");
    64   SDLTest_AssertCheck(result >= 0 && result <= umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
    65 
    66   result = (Sint64)SDLTest_RandomSint16();
    67   min = 1 - (1 << 15);
    68   max =     (1 << 15) - 1;
    69   SDLTest_AssertPass("Call to SDLTest_RandomSint16");
    70   SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
    71 
    72   result = (Sint64)SDLTest_RandomUint32();
    73   umax = ((Uint64)1 << 32) - 1;
    74   SDLTest_AssertPass("Call to SDLTest_RandomUint32");
    75   SDLTest_AssertCheck(result >= 0 && result <= umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
    76 
    77   result = (Sint64)SDLTest_RandomSint32();
    78   min = 1 - ((Sint64)1 << 31);
    79   max =     ((Sint64)1 << 31) - 1;
    80   SDLTest_AssertPass("Call to SDLTest_RandomSint32");
    81   SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
    82 
    83   result = (Sint64)SDLTest_RandomUint32();
    84   umax = ((Uint64)1 << 32) - 1;
    85   SDLTest_AssertPass("Call to SDLTest_RandomUint32");
    86   SDLTest_AssertCheck(result >= 0 && result <= umax, "Verify result value, expected: [0,%llu], got: %lld", umax, result);
    87 
    88   result = (Sint64)SDLTest_RandomSint32();
    89   min = 1 - ((Sint64)1 << 31);
    90   max =     ((Sint64)1 << 31) - 1;
    91   SDLTest_AssertPass("Call to SDLTest_RandomSint32");
    92   SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%lld,%lld], got: %lld", min, max, result);
    93 
    94   uresult = SDLTest_RandomUint64();
    95   SDLTest_AssertPass("Call to SDLTest_RandomUint64");
    96 
    97   result = SDLTest_RandomSint64();
    98   SDLTest_AssertPass("Call to SDLTest_RandomSint64");
    99 
   100   dresult = (double)SDLTest_RandomUnitFloat();
   101   SDLTest_AssertPass("Call to SDLTest_RandomUnitFloat");
   102   SDLTest_AssertCheck(dresult >= 0.0 && dresult < 1.0, "Verify result value, expected: [0.0,1.0[, got: %e", dresult);
   103     
   104   dresult = (double)SDLTest_RandomFloat();
   105   SDLTest_AssertPass("Call to SDLTest_RandomFloat");
   106   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);
   107 
   108   dresult = (double)SDLTest_RandomUnitDouble();
   109   SDLTest_AssertPass("Call to SDLTest_RandomUnitDouble");
   110   SDLTest_AssertCheck(dresult >= 0.0 && dresult < 1.0, "Verify result value, expected: [0.0,1.0[, got: %e", dresult);
   111 
   112   dresult = SDLTest_RandomDouble();
   113   SDLTest_AssertPass("Call to SDLTest_RandomDouble");
   114     
   115   return TEST_COMPLETED;
   116 }
   117 
   118 /* ================= Test References ================== */
   119 
   120 /* SDL_test test cases */
   121 static const SDLTest_TestCaseReference sdltestTest1 =
   122 		{ (SDLTest_TestCaseFp)sdltest_getFuzzerInvocationCount, "sdltest_getFuzzerInvocationCount", "Call to sdltest_GetFuzzerInvocationCount", TEST_ENABLED };
   123 
   124 static const SDLTest_TestCaseReference sdltestTest2 =
   125 		{ (SDLTest_TestCaseFp)sdltest_randomNumber, "sdltest_randomNumber", "Calls to random number generators", TEST_ENABLED };
   126 
   127 /* Sequence of SDL_test test cases */
   128 static const SDLTest_TestCaseReference *sdltestTests[] =  {
   129 	&sdltestTest1, &sdltestTest2, NULL
   130 };
   131 
   132 /* SDL_test test suite (global) */
   133 SDLTest_TestSuiteReference sdltestTestSuite = {
   134 	"SDLtest",
   135 	NULL,
   136 	sdltestTests,
   137 	NULL
   138 };