Fixes in harness and fuzzer test lib components; improve harness driver; add rect test suite
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Sat, 15 Dec 2012 21:50:17 -0800
changeset 67579935f71c8c81
parent 6756 398073b195bb
child 6758 2a218048b45f
Fixes in harness and fuzzer test lib components; improve harness driver; add rect test suite
src/test/SDL_test_fuzzer.c
src/test/SDL_test_harness.c
test/testautomation.c
test/tests/testrect.c
test/tests/testsuites.h
     1.1 --- a/src/test/SDL_test_fuzzer.c	Fri Dec 14 23:05:34 2012 -0800
     1.2 +++ b/src/test/SDL_test_fuzzer.c	Sat Dec 15 21:50:17 2012 -0800
     1.3 @@ -38,7 +38,7 @@
     1.4  /** 
     1.5   *Counter for fuzzer invocations
     1.6   */
     1.7 -static int fuzzerInvocationCounter;
     1.8 +static int fuzzerInvocationCounter = 0;
     1.9  
    1.10  /**
    1.11   * Context for shared random number generator
    1.12 @@ -52,9 +52,11 @@
    1.13  void
    1.14  SDLTest_FuzzerInit(Uint64 execKey)
    1.15  {
    1.16 -	Uint32 a = (execKey >> 32)  & 0x00000000FFFFFFFF;
    1.17 +	Uint32 a = (execKey >> 32) & 0x00000000FFFFFFFF;
    1.18  	Uint32 b = execKey & 0x00000000FFFFFFFF;
    1.19 +	SDL_memset((void *)&rndContext, 0, sizeof(SDLTest_RandomContext));
    1.20  	SDLTest_RandomInit(&rndContext, a, b);
    1.21 +	fuzzerInvocationCounter = 0;
    1.22  }
    1.23  
    1.24  int
     2.1 --- a/src/test/SDL_test_harness.c	Fri Dec 14 23:05:34 2012 -0800
     2.2 +++ b/src/test/SDL_test_harness.c	Sat Dec 15 21:50:17 2012 -0800
     2.3 @@ -222,6 +222,7 @@
     2.4  {
     2.5  	SDL_TimerID timer = 0;
     2.6  	int testResult = 0;
     2.7 +	int fuzzerCount;
     2.8  
     2.9  	if (testSuite==NULL || testCase==NULL || testSuite->name==NULL || testCase->name==NULL)
    2.10  	{
    2.11 @@ -235,7 +236,7 @@
    2.12  		return TEST_RESULT_SKIPPED;
    2.13  	}
    2.14  
    2.15 -    // Initialize fuzzer
    2.16 +        // Initialize fuzzer
    2.17  	SDLTest_FuzzerInit(execKey);
    2.18  
    2.19  	// Reset assert tracker
    2.20 @@ -268,7 +269,10 @@
    2.21  	}
    2.22  
    2.23  	// Report on asserts and fuzzer usage
    2.24 -	SDLTest_Log("Fuzzer invocations: %d", SDLTest_GetFuzzerInvocationCount());
    2.25 +	fuzzerCount = SDLTest_GetFuzzerInvocationCount();
    2.26 +	if (fuzzerCount > 0) {
    2.27 +		SDLTest_Log("Fuzzer invocations: %d", fuzzerCount);
    2.28 +	}
    2.29  	SDLTest_LogAssertSummary();
    2.30  
    2.31  	return testResult;
    2.32 @@ -361,6 +365,8 @@
    2.33  			SDLTest_LogError("Generating a random seed failed");
    2.34  			return 2;
    2.35  		}
    2.36 +	} else {
    2.37 +		runSeed = userRunSeed;
    2.38  	}
    2.39  
    2.40  	// Reset per-run counters
    2.41 @@ -372,7 +378,7 @@
    2.42  	runStartSeconds = GetClock();
    2.43  
    2.44  	// Log run with fuzzer parameters
    2.45 -	SDLTest_Log("::::: Test Run '%s' started\n", runSeed);
    2.46 +	SDLTest_Log("::::: Test Run /w seed '%s' started\n", runSeed);
    2.47  
    2.48  	// Loop over all suites
    2.49  	suiteCounter = 0;
    2.50 @@ -390,7 +396,7 @@
    2.51  
    2.52  		// Log suite started
    2.53  		currentSuiteName = (char *)((testSuite->name) ? testSuite->name : SDLTest_InvalidNameFormat);
    2.54 -		SDLTest_Log("===== Test Suite %i: %s started\n", 
    2.55 +		SDLTest_Log("===== Test Suite %i: '%s' started\n", 
    2.56  			suiteCounter, 
    2.57  			currentSuiteName);
    2.58  
    2.59 @@ -406,25 +412,28 @@
    2.60  
    2.61  			// Log test started
    2.62  			currentTestName = (char *)((testCase->name) ? testCase->name : SDLTest_InvalidNameFormat);
    2.63 -			SDLTest_Log("----- Test Case %i: %s started", 
    2.64 +			SDLTest_Log("----- Test Case %i.%i: '%s' started",
    2.65 +			        suiteCounter,
    2.66  				testCounter, 
    2.67  				currentTestName);
    2.68 -			SDLTest_Log("Test Description: %s", 
    2.69 -				(testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
    2.70 -
    2.71 +			if (testCase->description != NULL && strlen(testCase->description)>0) {
    2.72 +				SDLTest_Log("Test Description: '%s'", 
    2.73 +					(testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
    2.74 +			}
    2.75 +			
    2.76  			// Loop over all iterations
    2.77  			iterationCounter = 0;
    2.78  			while(iterationCounter < testIterations)
    2.79  			{
    2.80  				iterationCounter++;
    2.81  
    2.82 -				if(userExecKey != 0) {
    2.83 +				if (userExecKey != 0) {
    2.84  					execKey = userExecKey;
    2.85  				} else {
    2.86  					execKey = SDLTest_GenerateExecKey(runSeed, testSuite->name, testCase->name, iterationCounter);
    2.87  				}
    2.88  
    2.89 -				SDLTest_Log("Test Iteration %i: execKey %d", iterationCounter, execKey);
    2.90 +				SDLTest_Log("Test Iteration %i: execKey %llu", iterationCounter, execKey);
    2.91  				testResult = SDLTest_RunTest(testSuite, testCase, execKey);
    2.92  
    2.93  				if (testResult == TEST_RESULT_PASSED) {
    2.94 @@ -442,10 +451,14 @@
    2.95  			// Take time - test end
    2.96  			testEndSeconds = GetClock();
    2.97  
    2.98 -			SDLTest_Log("Test Case %s ended", currentTestName);
    2.99 -
   2.100 -			// Log test runtime
   2.101 -			SDLTest_Log("Test runtime: %.1f sec", testEndSeconds - testStartSeconds);
   2.102 +			if (testIterations > 1) {
   2.103 +        			// Log test runtime
   2.104 +	        		SDLTest_Log("Runtime of %i iterations: %.1f sec", testIterations, testEndSeconds - testStartSeconds);
   2.105 +	        		SDLTest_Log("Test runtime: %.5f sec", (testEndSeconds - testStartSeconds) / (float)testIterations);
   2.106 +                        } else {
   2.107 +        			// Log test runtime
   2.108 +	        		SDLTest_Log("Test runtime: %.1f sec", testEndSeconds - testStartSeconds);
   2.109 +                        }
   2.110  
   2.111  			// Log final test result
   2.112  			switch (testResult) {
   2.113 @@ -468,7 +481,7 @@
   2.114  		SDLTest_Log("Suite runtime: %.1f sec", suiteEndSeconds - suiteStartSeconds);
   2.115  
   2.116  		// Log summary and final Suite result
   2.117 -	    countSum = testPassedCount + testFailedCount + testSkippedCount;
   2.118 +		countSum = testPassedCount + testFailedCount + testSkippedCount;
   2.119  		if (testFailedCount == 0)
   2.120  		{
   2.121  			SDLTest_Log(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
   2.122 @@ -493,14 +506,15 @@
   2.123  	{
   2.124  		runResult = 0;
   2.125  		SDLTest_Log(logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
   2.126 -		SDLTest_Log((char *)SDLTest_FinalResultFormat, "Run", runSeed, "Passed");
   2.127 +		SDLTest_Log((char *)SDLTest_FinalResultFormat, "Run /w seed", runSeed, "Passed");
   2.128  	} 
   2.129  	else 
   2.130  	{
   2.131  		runResult = 1;
   2.132  		SDLTest_LogError(logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
   2.133 -		SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Run", runSeed, "Failed");
   2.134 +		SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Run /w seed", runSeed, "Failed");
   2.135  	}
   2.136  
   2.137 +	SDLTest_Log("Exit code: %d", runResult);	
   2.138  	return runResult;
   2.139  }
     3.1 --- a/test/testautomation.c	Fri Dec 14 23:05:34 2012 -0800
     3.2 +++ b/test/testautomation.c	Sat Dec 15 21:50:17 2012 -0800
     3.3 @@ -34,6 +34,9 @@
     3.4  main(int argc, char *argv[])
     3.5  {
     3.6      int result;
     3.7 +    int testIterations = 1;
     3.8 +    Uint64 userExecKey = 0;
     3.9 +    char *userRunSeed = NULL;
    3.10      int i;
    3.11  
    3.12      /* Initialize test framework */
    3.13 @@ -52,27 +55,33 @@
    3.14          consumed = SDLTest_CommonArg(state, i);
    3.15          if (consumed == 0) {
    3.16              consumed = -1;
    3.17 -/* Parse additional parameters
    3.18 -
    3.19 -            if (SDL_strcasecmp(argv[i], "--BLAH") == 0) {
    3.20 +            if (SDL_strcasecmp(argv[i], "--iterations") == 0) {
    3.21                  if (argv[i + 1]) {
    3.22 -                    if (SDL_strcasecmp(argv[i + 1], "BLUB") == 0) {
    3.23 -                        blah = blub;
    3.24 -                        consumed = 2;
    3.25 -                    }
    3.26 +                    testIterations = SDL_atoi(argv[i + 1]);
    3.27 +                    if (testIterations < 1) testIterations = 1;
    3.28 +                    consumed = 2;                    
    3.29                  }
    3.30 -            } else if (SDL_strcasecmp(argv[i], "--BINGO") == 0) {
    3.31 -                bingo = SDL_TRUE;
    3.32 -                consumed = 1;
    3.33 -            }
    3.34 -*/
    3.35 +            } 
    3.36 +            else if (SDL_strcasecmp(argv[i], "--execKey") == 0) {
    3.37 +                if (argv[i + 1]) {
    3.38 +                    SDL_sscanf(argv[i + 1], "%llu", &userExecKey);
    3.39 +                    consumed = 2;                    
    3.40 +                }
    3.41 +            } 
    3.42 +            else if (SDL_strcasecmp(argv[i], "--seed") == 0) {
    3.43 +                if (argv[i + 1]) {
    3.44 +                    userRunSeed = SDL_strdup(argv[i + 1]);
    3.45 +                    consumed = 2;
    3.46 +                }
    3.47 +            } 
    3.48          }
    3.49          if (consumed < 0) {
    3.50              fprintf(stderr,
    3.51 -                    "Usage: %s %s [--BLAH BLUB --BINGO]\n",
    3.52 +                    "Usage: %s %s [--iterations #] [--execKey #] [--seed string]\n",
    3.53                      argv[0], SDLTest_CommonUsage(state));
    3.54              quit(1);
    3.55          }
    3.56 +        
    3.57          i += consumed;
    3.58      }
    3.59  
    3.60 @@ -89,10 +98,13 @@
    3.61      }
    3.62  
    3.63      /* Call Harness */
    3.64 -    // TODO: pass custom parameters
    3.65 -    result = SDLTest_RunSuites(testSuites, NULL, 0, 1);
    3.66 -//int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites, char *userRunSeed, Uint64 userExecKey, int testIterations);
    3.67 -    
    3.68 +    result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, testIterations);
    3.69 +
    3.70 +    /* Clean up */
    3.71 +    if (userRunSeed != NULL) {
    3.72 +        SDL_free(userRunSeed);
    3.73 +    }
    3.74 +        
    3.75      /* Shutdown everything */
    3.76      quit(result);        
    3.77      return(result);
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tests/testrect.c	Sat Dec 15 21:50:17 2012 -0800
     4.3 @@ -0,0 +1,1677 @@
     4.4 +/**
     4.5 + * Original code: automated SDL rect test written by Edgar Simo "bobbens"
     4.6 + * New/updated tests: aschiffler at ferzkopp dot net
     4.7 + */
     4.8 +
     4.9 +#include <stdio.h>
    4.10 +
    4.11 +#include "SDL.h"
    4.12 +#include "SDL_test.h"
    4.13 +
    4.14 +/* ================= Test Case Implementation ================== */
    4.15 +
    4.16 +/* Helper functions */
    4.17 +
    4.18 +/*!
    4.19 + * \brief Private helper to check SDL_IntersectRectAndLine results
    4.20 + */
    4.21 +void _validateIntersectRectAndLineResults(
    4.22 +    SDL_bool intersection, SDL_bool expectedIntersection,
    4.23 +    SDL_Rect *rect, SDL_Rect * refRect,
    4.24 +    int x1, int y1, int x2, int y2,
    4.25 +    int x1Ref, int y1Ref, int x2Ref, int y2Ref)
    4.26 +{
    4.27 +    SDLTest_AssertCheck(intersection == expectedIntersection, 
    4.28 +        "Check for correct intersection result: expected %s, got %s intersecting rect (%d,%d,%d,%d) with line (%d,%d - %d,%d)",
    4.29 +        (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
    4.30 +        (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
    4.31 +        refRect->x, refRect->y, refRect->w, refRect->h,
    4.32 +        x1Ref, y1Ref, x2Ref, y2Ref);
    4.33 +    SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
    4.34 +        "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
    4.35 +        rect->x, rect->y, rect->w, rect->h,
    4.36 +        refRect->x, refRect->y, refRect->w, refRect->h);
    4.37 +    SDLTest_AssertCheck(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref,
    4.38 +        "Check if line was incorrectly clipped or modified: got (%d,%d - %d,%d) expected (%d,%d - %d,%d)",
    4.39 +        x1, y1, x2, y2,
    4.40 +        x1Ref, y1Ref, x2Ref, y2Ref);
    4.41 +}
    4.42 +
    4.43 +/* Test case functions */
    4.44 +
    4.45 +/*!
    4.46 + * \brief Tests SDL_IntersectRectAndLine() clipping cases
    4.47 + *
    4.48 + * \sa
    4.49 + * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
    4.50 + */
    4.51 +int 
    4.52 +rect_testIntersectRectAndLine (void *arg)
    4.53 +{
    4.54 +    SDL_Rect refRect = { 0, 0, 32, 32 };
    4.55 +    SDL_Rect rect;
    4.56 +    int x1, y1;
    4.57 +    int x2, y2;
    4.58 +    SDL_bool intersected;
    4.59 +
    4.60 +    int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w);
    4.61 +    int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
    4.62 +    int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
    4.63 +    int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h);
    4.64 +
    4.65 +    x1 = xLeft;
    4.66 +    y1 = 15;
    4.67 +    x2 = xRight;
    4.68 +    y2 = 15;
    4.69 +    rect = refRect;
    4.70 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    4.71 +    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 15, 31, 15);
    4.72 +
    4.73 +    x1 = 15;
    4.74 +    y1 = yTop;
    4.75 +    x2 = 15;
    4.76 +    y2 = yBottom;
    4.77 +    rect = refRect;
    4.78 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    4.79 +    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 15, 0, 15, 31);
    4.80 +
    4.81 +    x1 = -refRect.w;
    4.82 +    y1 = -refRect.h;
    4.83 +    x2 = 2*refRect.w;
    4.84 +    y2 = 2*refRect.h;
    4.85 +    rect = refRect;
    4.86 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    4.87 +     _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 0, 31, 31);
    4.88 +
    4.89 +    x1 = 2*refRect.w;
    4.90 +    y1 = 2*refRect.h;
    4.91 +    x2 = -refRect.w;
    4.92 +    y2 = -refRect.h;
    4.93 +    rect = refRect;
    4.94 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    4.95 +    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 31, 0, 0);
    4.96 +
    4.97 +    x1 = -1;
    4.98 +    y1 = 32;
    4.99 +    x2 = 32;
   4.100 +    y2 = -1;
   4.101 +    rect = refRect;
   4.102 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.103 +    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 31, 31, 0);
   4.104 +
   4.105 +    x1 = 32;
   4.106 +    y1 = -1;
   4.107 +    x2 = -1;
   4.108 +    y2 = 32;
   4.109 +    rect = refRect;
   4.110 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.111 +    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 0, 0, 31);
   4.112 +
   4.113 +	return TEST_COMPLETED;
   4.114 +}
   4.115 +
   4.116 +/*!
   4.117 + * \brief Tests SDL_IntersectRectAndLine() non-clipping case line inside
   4.118 + *
   4.119 + * \sa
   4.120 + * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
   4.121 + */
   4.122 +int 
   4.123 +rect_testIntersectRectAndLineInside (void *arg)
   4.124 +{
   4.125 +    SDL_Rect refRect = { 0, 0, 32, 32 };
   4.126 +    SDL_Rect rect;
   4.127 +    int x1, y1;
   4.128 +    int x2, y2;
   4.129 +    SDL_bool intersected;
   4.130 +
   4.131 +    int xmin = refRect.x;
   4.132 +    int xmax = refRect.x + refRect.w - 1;
   4.133 +    int ymin = refRect.y;
   4.134 +    int ymax = refRect.y + refRect.h - 1;
   4.135 +    int x1Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
   4.136 +    int y1Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
   4.137 +    int x2Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
   4.138 +    int y2Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
   4.139 +
   4.140 +    x1 = x1Ref;
   4.141 +    y1 = y1Ref;
   4.142 +    x2 = x2Ref;
   4.143 +    y2 = y2Ref;
   4.144 +    rect = refRect;
   4.145 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.146 +    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
   4.147 +
   4.148 +    x1 = x1Ref;
   4.149 +    y1 = y1Ref;
   4.150 +    x2 = xmax;
   4.151 +    y2 = ymax;
   4.152 +    rect = refRect;
   4.153 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.154 +    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, xmax, ymax);
   4.155 +
   4.156 +    x1 = xmin;
   4.157 +    y1 = ymin;
   4.158 +    x2 = x2Ref;
   4.159 +    y2 = y2Ref;
   4.160 +    rect = refRect;
   4.161 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.162 +    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, x2Ref, y2Ref);
   4.163 +
   4.164 +    x1 = xmin;
   4.165 +    y1 = ymin;
   4.166 +    x2 = xmax;
   4.167 +    y2 = ymax;
   4.168 +    rect = refRect;
   4.169 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.170 +    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, xmax, ymax);
   4.171 +
   4.172 +    x1 = xmin;
   4.173 +    y1 = ymax;
   4.174 +    x2 = xmax;
   4.175 +    y2 = ymin;
   4.176 +    rect = refRect;
   4.177 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.178 +    _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymax, xmax, ymin);
   4.179 +
   4.180 +	return TEST_COMPLETED;
   4.181 +}
   4.182 +
   4.183 +/*!
   4.184 + * \brief Tests SDL_IntersectRectAndLine() non-clipping cases outside
   4.185 + *
   4.186 + * \sa
   4.187 + * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
   4.188 + */
   4.189 +int 
   4.190 +rect_testIntersectRectAndLineOutside (void *arg)
   4.191 +{
   4.192 +    SDL_Rect refRect = { 0, 0, 32, 32 };
   4.193 +    SDL_Rect rect;
   4.194 +    int x1, y1;
   4.195 +    int x2, y2;
   4.196 +    SDL_bool intersected;
   4.197 +
   4.198 +    int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w);
   4.199 +    int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
   4.200 +    int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
   4.201 +    int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h);
   4.202 +
   4.203 +    x1 = xLeft;
   4.204 +    y1 = 0;
   4.205 +    x2 = xLeft;
   4.206 +    y2 = 31;
   4.207 +    rect = refRect;
   4.208 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.209 +    _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xLeft, 0, xLeft, 31);
   4.210 +
   4.211 +    x1 = xRight;
   4.212 +    y1 = 0;
   4.213 +    x2 = xRight;
   4.214 +    y2 = 31;
   4.215 +    rect = refRect;
   4.216 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.217 +    _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xRight, 0, xRight, 31);
   4.218 +
   4.219 +    x1 = 0;
   4.220 +    y1 = yTop;
   4.221 +    x2 = 31;
   4.222 +    y2 = yTop;
   4.223 +    rect = refRect;
   4.224 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.225 +    _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yTop, 31, yTop);
   4.226 +
   4.227 +    x1 = 0;
   4.228 +    y1 = yBottom;
   4.229 +    x2 = 31;
   4.230 +    y2 = yBottom;
   4.231 +    rect = refRect;
   4.232 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.233 +    _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yBottom, 31, yBottom);
   4.234 +
   4.235 +	return TEST_COMPLETED;
   4.236 +}
   4.237 +
   4.238 +/*!
   4.239 + * \brief Tests SDL_IntersectRectAndLine() with empty rectangle
   4.240 + *
   4.241 + * \sa
   4.242 + * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
   4.243 + */
   4.244 +int 
   4.245 +rect_testIntersectRectAndLineEmpty (void *arg)
   4.246 +{
   4.247 +    SDL_Rect refRect;
   4.248 +    SDL_Rect rect;
   4.249 +    int x1, y1, x1Ref, y1Ref;
   4.250 +    int x2, y2, x2Ref, y2Ref;
   4.251 +    SDL_bool intersected;
   4.252 +        
   4.253 +    refRect.x = SDLTest_RandomIntegerInRange(1, 1024);
   4.254 +    refRect.y = SDLTest_RandomIntegerInRange(1, 1024);
   4.255 +    refRect.w = 0;
   4.256 +    refRect.h = 0;
   4.257 +    x1Ref = refRect.x;
   4.258 +    y1Ref = refRect.y;
   4.259 +    x2Ref = SDLTest_RandomIntegerInRange(1, 1024);
   4.260 +    y2Ref = SDLTest_RandomIntegerInRange(1, 1024);
   4.261 +
   4.262 +    x1 = x1Ref;
   4.263 +    y1 = y1Ref;
   4.264 +    x2 = x2Ref;
   4.265 +    y2 = y2Ref;
   4.266 +    rect = refRect;
   4.267 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.268 +    _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
   4.269 +
   4.270 +	return TEST_COMPLETED;
   4.271 +}
   4.272 +
   4.273 +/*!
   4.274 + * \brief Negative tests against SDL_IntersectRectAndLine() with invalid parameters
   4.275 + *
   4.276 + * \sa
   4.277 + * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
   4.278 + */
   4.279 +int 
   4.280 +rect_testIntersectRectAndLineParam (void *arg)
   4.281 +{
   4.282 +    SDL_Rect rect = { 0, 0, 32, 32 };
   4.283 +    int x1 = rect.w / 2;
   4.284 +    int y1 = rect.h / 2;
   4.285 +    int x2 = x1;
   4.286 +    int y2 = 2 * rect.h;
   4.287 +    SDL_bool intersected;
   4.288 +    
   4.289 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   4.290 +    SDLTest_AssertCheck(intersected == SDL_TRUE, "Check that intersection result was SDL_TRUE");
   4.291 +    
   4.292 +    intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, &x1, &y1, &x2, &y2);
   4.293 +    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
   4.294 +    intersected = SDL_IntersectRectAndLine(&rect, (int *)NULL, &y1, &x2, &y2);
   4.295 +    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
   4.296 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, (int *)NULL, &x2, &y2);
   4.297 +    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 3rd parameter is NULL");
   4.298 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, (int *)NULL, &y2);
   4.299 +    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 4th parameter is NULL");
   4.300 +    intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, (int *)NULL);
   4.301 +    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 5th parameter is NULL");
   4.302 +    intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL);
   4.303 +    SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
   4.304 +
   4.305 +	return TEST_COMPLETED;
   4.306 +}
   4.307 +
   4.308 +/*!
   4.309 + * \brief Private helper to check SDL_HasIntersection results
   4.310 + */
   4.311 +void _validateHasIntersectionResults(
   4.312 +    SDL_bool intersection, SDL_bool expectedIntersection, 
   4.313 +    SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
   4.314 +{
   4.315 +    SDLTest_AssertCheck(intersection == expectedIntersection, 
   4.316 +        "Check intersection result: expected %s, got %s intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)",
   4.317 +        (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
   4.318 +        (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
   4.319 +        rectA->x, rectA->y, rectA->w, rectA->h, 
   4.320 +        rectB->x, rectB->y, rectB->w, rectB->h);
   4.321 +    SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
   4.322 +        "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   4.323 +        rectA->x, rectA->y, rectA->w, rectA->h,
   4.324 +        refRectA->x, refRectA->y, refRectA->w, refRectA->h);
   4.325 +    SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
   4.326 +        "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   4.327 +        rectB->x, rectB->y, rectB->w, rectB->h,
   4.328 +        refRectB->x, refRectB->y, refRectB->w, refRectB->h);
   4.329 +}
   4.330 +
   4.331 +/*!
   4.332 + * \brief Private helper to check SDL_IntersectRect results
   4.333 + */
   4.334 +void _validateIntersectRectResults(
   4.335 +    SDL_bool intersection, SDL_bool expectedIntersection, 
   4.336 +    SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB, 
   4.337 +    SDL_Rect *result, SDL_Rect *expectedResult)
   4.338 +{
   4.339 +    _validateHasIntersectionResults(intersection, expectedIntersection, rectA, rectB, refRectA, refRectB);
   4.340 +    if (result && expectedResult) {
   4.341 +        SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
   4.342 +            "Check that intersection of rectangles A (%d,%d,%d,%d) and B (%d,%d,%d,%d) was correctly calculated, got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   4.343 +            rectA->x, rectA->y, rectA->w, rectA->h, 
   4.344 +            rectB->x, rectB->y, rectB->w, rectB->h,
   4.345 +            result->x, result->y, result->w, result->h,
   4.346 +            expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
   4.347 +    }
   4.348 +}
   4.349 +
   4.350 +/*!
   4.351 + * \brief Private helper to check SDL_UnionRect results
   4.352 + */
   4.353 +void _validateUnionRectResults(
   4.354 +    SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB, 
   4.355 +    SDL_Rect *result, SDL_Rect *expectedResult)
   4.356 +{
   4.357 +    SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
   4.358 +        "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   4.359 +        rectA->x, rectA->y, rectA->w, rectA->h,
   4.360 +        refRectA->x, refRectA->y, refRectA->w, refRectA->h);
   4.361 +    SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
   4.362 +        "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   4.363 +        rectB->x, rectB->y, rectB->w, rectB->h,
   4.364 +        refRectB->x, refRectB->y, refRectB->w, refRectB->h);
   4.365 +    SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
   4.366 +        "Check that union of rectangles A (%d,%d,%d,%d) and B (%d,%d,%d,%d) was correctly calculated, got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   4.367 +        rectA->x, rectA->y, rectA->w, rectA->h, 
   4.368 +        rectB->x, rectB->y, rectB->w, rectB->h,
   4.369 +        result->x, result->y, result->w, result->h,
   4.370 +        expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
   4.371 +}
   4.372 +
   4.373 +/*!
   4.374 + * \brief Private helper to check SDL_RectEmpty results
   4.375 + */
   4.376 +void _validateRectEmptyResults(
   4.377 +    SDL_bool empty, SDL_bool expectedEmpty, 
   4.378 +    SDL_Rect *rect, SDL_Rect *refRect)
   4.379 +{
   4.380 +    SDLTest_AssertCheck(empty == expectedEmpty, 
   4.381 +        "Check for correct empty result: expected %s, got %s testing (%d,%d,%d,%d)",
   4.382 +        (expectedEmpty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
   4.383 +        (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
   4.384 +        rect->x, rect->y, rect->w, rect->h);
   4.385 +    SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
   4.386 +        "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   4.387 +        rect->x, rect->y, rect->w, rect->h,
   4.388 +        refRect->x, refRect->y, refRect->w, refRect->h);
   4.389 +}
   4.390 +
   4.391 +/*!
   4.392 + * \brief Private helper to check SDL_RectEquals results
   4.393 + */
   4.394 +void _validateRectEqualsResults(
   4.395 +    SDL_bool equals, SDL_bool expectedEquals, 
   4.396 +    SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
   4.397 +{
   4.398 +    SDLTest_AssertCheck(equals == expectedEquals, 
   4.399 +        "Check for correct equals result: expected %s, got %s testing (%d,%d,%d,%d) and (%d,%d,%d,%d)",
   4.400 +        (expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
   4.401 +        (equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
   4.402 +        rectA->x, rectA->y, rectA->w, rectA->h,
   4.403 +        rectB->x, rectB->y, rectB->w, rectB->h);
   4.404 +    SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
   4.405 +        "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   4.406 +        rectA->x, rectA->y, rectA->w, rectA->h,
   4.407 +        refRectA->x, refRectA->y, refRectA->w, refRectA->h);
   4.408 +    SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
   4.409 +        "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   4.410 +        rectB->x, rectB->y, rectB->w, rectB->h,
   4.411 +        refRectB->x, refRectB->y, refRectB->w, refRectB->h);
   4.412 +}
   4.413 +
   4.414 +/*!
   4.415 + * \brief Tests SDL_IntersectRect() with B fully inside A
   4.416 + *
   4.417 + * \sa
   4.418 + * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
   4.419 + */
   4.420 +int rect_testIntersectRectInside (void *arg)
   4.421 +{
   4.422 +    SDL_Rect refRectA = { 0, 0, 32, 32 };
   4.423 +    SDL_Rect refRectB;
   4.424 +    SDL_Rect rectA;
   4.425 +    SDL_Rect rectB;
   4.426 +    SDL_Rect result;
   4.427 +    SDL_bool intersection;
   4.428 +
   4.429 +    // rectB fully contained in rectA
   4.430 +    refRectB.x = 0;
   4.431 +    refRectB.y = 0;
   4.432 +    refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
   4.433 +    refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
   4.434 +    rectA = refRectA;
   4.435 +    rectB = refRectB;
   4.436 +    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   4.437 +    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectB);
   4.438 +
   4.439 +	return TEST_COMPLETED;
   4.440 +}
   4.441 +
   4.442 +/*!
   4.443 + * \brief Tests SDL_IntersectRect() with B fully outside A
   4.444 + *
   4.445 + * \sa
   4.446 + * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
   4.447 + */
   4.448 +int rect_testIntersectRectOutside (void *arg)
   4.449 +{
   4.450 +    SDL_Rect refRectA = { 0, 0, 32, 32 };
   4.451 +    SDL_Rect refRectB;
   4.452 +    SDL_Rect rectA;
   4.453 +    SDL_Rect rectB;
   4.454 +    SDL_Rect result;
   4.455 +    SDL_bool intersection;
   4.456 +
   4.457 +    // rectB fully outside of rectA
   4.458 +    refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
   4.459 +    refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
   4.460 +    refRectB.w = refRectA.w;
   4.461 +    refRectB.h = refRectA.h;
   4.462 +    rectA = refRectA;
   4.463 +    rectB = refRectB;
   4.464 +    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   4.465 +    _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);    
   4.466 +
   4.467 +	return TEST_COMPLETED;
   4.468 +}
   4.469 +
   4.470 +/*!
   4.471 + * \brief Tests SDL_IntersectRect() with B partially intersecting A
   4.472 + *
   4.473 + * \sa
   4.474 + * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
   4.475 + */
   4.476 +int rect_testIntersectRectPartial (void *arg)
   4.477 +{
   4.478 +    SDL_Rect refRectA = { 0, 0, 32, 32 };
   4.479 +    SDL_Rect refRectB;
   4.480 +    SDL_Rect rectA;
   4.481 +    SDL_Rect rectB;
   4.482 +    SDL_Rect result;
   4.483 +    SDL_Rect expectedResult;
   4.484 +    SDL_bool intersection;
   4.485 +
   4.486 +    // rectB partially contained in rectA
   4.487 +    refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
   4.488 +    refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
   4.489 +    refRectB.w = refRectA.w;
   4.490 +    refRectB.h = refRectA.h;
   4.491 +    rectA = refRectA;
   4.492 +    rectB = refRectB;
   4.493 +    expectedResult.x = refRectB.x;
   4.494 +    expectedResult.y = refRectB.y;
   4.495 +    expectedResult.w = refRectA.w - refRectB.x;
   4.496 +    expectedResult.h = refRectA.h - refRectB.y;    
   4.497 +    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   4.498 +    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
   4.499 +
   4.500 +    // rectB right edge
   4.501 +    refRectB.x = rectA.w - 1;
   4.502 +    refRectB.y = rectA.y;
   4.503 +    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
   4.504 +    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
   4.505 +    rectA = refRectA;
   4.506 +    rectB = refRectB;
   4.507 +    expectedResult.x = refRectB.x;
   4.508 +    expectedResult.y = refRectB.y;
   4.509 +    expectedResult.w = 1;
   4.510 +    expectedResult.h = refRectB.h;    
   4.511 +    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   4.512 +    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
   4.513 +
   4.514 +    // rectB left edge
   4.515 +    refRectB.x = 1 - rectA.w;
   4.516 +    refRectB.y = rectA.y;
   4.517 +    refRectB.w = refRectA.w;
   4.518 +    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
   4.519 +    rectA = refRectA;
   4.520 +    rectB = refRectB;
   4.521 +    expectedResult.x = 0;
   4.522 +    expectedResult.y = refRectB.y;
   4.523 +    expectedResult.w = 1;
   4.524 +    expectedResult.h = refRectB.h;    
   4.525 +    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   4.526 +    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
   4.527 +
   4.528 +    // rectB bottom edge
   4.529 +    refRectB.x = rectA.x;
   4.530 +    refRectB.y = rectA.h - 1;
   4.531 +    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
   4.532 +    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
   4.533 +    rectA = refRectA;
   4.534 +    rectB = refRectB;
   4.535 +    expectedResult.x = refRectB.x;
   4.536 +    expectedResult.y = refRectB.y;
   4.537 +    expectedResult.w = refRectB.w;
   4.538 +    expectedResult.h = 1;    
   4.539 +    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   4.540 +    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
   4.541 +
   4.542 +    // rectB top edge
   4.543 +    refRectB.x = rectA.x;
   4.544 +    refRectB.y = 1 - rectA.h;
   4.545 +    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
   4.546 +    refRectB.h = rectA.h;
   4.547 +    rectA = refRectA;
   4.548 +    rectB = refRectB;
   4.549 +    expectedResult.x = refRectB.x;
   4.550 +    expectedResult.y = 0;
   4.551 +    expectedResult.w = refRectB.w;
   4.552 +    expectedResult.h = 1;    
   4.553 +    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   4.554 +    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
   4.555 +
   4.556 +	return TEST_COMPLETED;
   4.557 +}
   4.558 +
   4.559 +/*!
   4.560 + * \brief Tests SDL_IntersectRect() with 1x1 pixel sized rectangles
   4.561 + *
   4.562 + * \sa
   4.563 + * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
   4.564 + */
   4.565 +int rect_testIntersectRectPoint (void *arg)
   4.566 +{
   4.567 +    SDL_Rect refRectA = { 0, 0, 1, 1 };
   4.568 +    SDL_Rect refRectB = { 0, 0, 1, 1 };
   4.569 +    SDL_Rect rectA;
   4.570 +    SDL_Rect rectB;
   4.571 +    SDL_Rect result;
   4.572 +    SDL_bool intersection;
   4.573 +    int offsetX, offsetY;
   4.574 +
   4.575 +    // intersecting pixels
   4.576 +    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   4.577 +    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   4.578 +    refRectB.x = refRectA.x;
   4.579 +    refRectB.y = refRectA.y;
   4.580 +    rectA = refRectA;
   4.581 +    rectB = refRectB;
   4.582 +    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   4.583 +    _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectA);
   4.584 +
   4.585 +    // non-intersecting pixels cases
   4.586 +    for (offsetX = -1; offsetX <= 1; offsetX++) {
   4.587 +        for (offsetY = -1; offsetY <= 1; offsetY++) {
   4.588 +            if (offsetX != 0 || offsetY != 0) {
   4.589 +                refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   4.590 +                refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   4.591 +                refRectB.x = refRectA.x;
   4.592 +                refRectB.y = refRectA.y;    
   4.593 +                refRectB.x += offsetX;
   4.594 +                refRectB.y += offsetY;
   4.595 +                rectA = refRectA;
   4.596 +                rectB = refRectB;
   4.597 +                intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   4.598 +                _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
   4.599 +            }
   4.600 +        }
   4.601 +    }
   4.602 +
   4.603 +	return TEST_COMPLETED;
   4.604 +}
   4.605 +
   4.606 +/*!
   4.607 + * \brief Tests SDL_IntersectRect() with empty rectangles
   4.608 + *
   4.609 + * \sa
   4.610 + * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
   4.611 + */
   4.612 +int rect_testIntersectRectEmpty (void *arg)
   4.613 +{
   4.614 +    SDL_Rect refRectA;
   4.615 +    SDL_Rect refRectB;
   4.616 +    SDL_Rect rectA;
   4.617 +    SDL_Rect rectB;
   4.618 +    SDL_Rect result;
   4.619 +    SDL_bool intersection;
   4.620 +
   4.621 +    // Rect A empty
   4.622 +    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   4.623 +    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   4.624 +    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
   4.625 +    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
   4.626 +    refRectB = refRectA;
   4.627 +    refRectA.w = 0;
   4.628 +    refRectA.h = 0;
   4.629 +    rectA = refRectA;
   4.630 +    rectB = refRectB;
   4.631 +    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   4.632 +    _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
   4.633 +
   4.634 +    // Rect B empty
   4.635 +    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   4.636 +    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   4.637 +    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
   4.638 +    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
   4.639 +    refRectB = refRectA;
   4.640 +    refRectB.w = 0;
   4.641 +    refRectB.h = 0;
   4.642 +    rectA = refRectA;
   4.643 +    rectB = refRectB;
   4.644 +    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   4.645 +    _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
   4.646 +
   4.647 +    // Rect A and B empty
   4.648 +    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   4.649 +    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   4.650 +    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
   4.651 +    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
   4.652 +    refRectB = refRectA;
   4.653 +    refRectA.w = 0;
   4.654 +    refRectA.h = 0;
   4.655 +    refRectB.w = 0;
   4.656 +    refRectB.h = 0;
   4.657 +    rectA = refRectA;
   4.658 +    rectB = refRectB;
   4.659 +    intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   4.660 +    _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
   4.661 +
   4.662 +	return TEST_COMPLETED;
   4.663 +}
   4.664 +
   4.665 +/*!
   4.666 + * \brief Negative tests against SDL_IntersectRect() with invalid parameters
   4.667 + *
   4.668 + * \sa
   4.669 + * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
   4.670 + */
   4.671 +int rect_testIntersectRectParam(void *arg)
   4.672 +{
   4.673 +    SDL_Rect rectA;
   4.674 +    SDL_Rect rectB;
   4.675 +    SDL_Rect result;
   4.676 +    SDL_bool intersection;
   4.677 +
   4.678 +    // invalid parameter combinations
   4.679 +    intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, &result);
   4.680 +    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL"); 
   4.681 +    intersection = SDL_IntersectRect(&rectA, (SDL_Rect *)NULL, &result);
   4.682 +    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL"); 
   4.683 +    intersection = SDL_IntersectRect(&rectA, &rectB, (SDL_Rect *)NULL);
   4.684 +    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 3st parameter is NULL"); 
   4.685 +    intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, &result);
   4.686 +    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameters are NULL"); 
   4.687 +    intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
   4.688 +    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 3rd parameters are NULL "); 
   4.689 +    intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
   4.690 +    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");     
   4.691 +
   4.692 +	return TEST_COMPLETED;
   4.693 +}
   4.694 +
   4.695 +/*!
   4.696 + * \brief Tests SDL_HasIntersection() with B fully inside A
   4.697 + *
   4.698 + * \sa
   4.699 + * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
   4.700 + */
   4.701 +int rect_testHasIntersectionInside (void *arg)
   4.702 +{
   4.703 +    SDL_Rect refRectA = { 0, 0, 32, 32 };
   4.704 +    SDL_Rect refRectB;
   4.705 +    SDL_Rect rectA;
   4.706 +    SDL_Rect rectB;
   4.707 +    SDL_bool intersection;
   4.708 +
   4.709 +    // rectB fully contained in rectA
   4.710 +    refRectB.x = 0;
   4.711 +    refRectB.y = 0;
   4.712 +    refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
   4.713 +    refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
   4.714 +    rectA = refRectA;
   4.715 +    rectB = refRectB;
   4.716 +    intersection = SDL_HasIntersection(&rectA, &rectB);
   4.717 +    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   4.718 +
   4.719 +	return TEST_COMPLETED;
   4.720 +}
   4.721 +
   4.722 +/*!
   4.723 + * \brief Tests SDL_HasIntersection() with B fully outside A
   4.724 + *
   4.725 + * \sa
   4.726 + * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
   4.727 + */
   4.728 +int rect_testHasIntersectionOutside (void *arg)
   4.729 +{
   4.730 +    SDL_Rect refRectA = { 0, 0, 32, 32 };
   4.731 +    SDL_Rect refRectB;
   4.732 +    SDL_Rect rectA;
   4.733 +    SDL_Rect rectB;
   4.734 +    SDL_bool intersection;
   4.735 +
   4.736 +    // rectB fully outside of rectA
   4.737 +    refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
   4.738 +    refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
   4.739 +    refRectB.w = refRectA.w;
   4.740 +    refRectB.h = refRectA.h;
   4.741 +    rectA = refRectA;
   4.742 +    rectB = refRectB;
   4.743 +    intersection = SDL_HasIntersection(&rectA, &rectB);
   4.744 +    _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
   4.745 +
   4.746 +	return TEST_COMPLETED;
   4.747 +}
   4.748 +
   4.749 +/*!
   4.750 + * \brief Tests SDL_HasIntersection() with B partially intersecting A
   4.751 + *
   4.752 + * \sa
   4.753 + * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
   4.754 + */
   4.755 +int rect_testHasIntersectionPartial (void *arg)
   4.756 +{
   4.757 +    SDL_Rect refRectA = { 0, 0, 32, 32 };
   4.758 +    SDL_Rect refRectB;
   4.759 +    SDL_Rect rectA;
   4.760 +    SDL_Rect rectB;
   4.761 +    SDL_bool intersection;
   4.762 +
   4.763 +    // rectB partially contained in rectA
   4.764 +    refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
   4.765 +    refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
   4.766 +    refRectB.w = refRectA.w;
   4.767 +    refRectB.h = refRectA.h;
   4.768 +    rectA = refRectA;
   4.769 +    rectB = refRectB;
   4.770 +    intersection = SDL_HasIntersection(&rectA, &rectB);
   4.771 +    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   4.772 +
   4.773 +    // rectB right edge
   4.774 +    refRectB.x = rectA.w - 1;
   4.775 +    refRectB.y = rectA.y;
   4.776 +    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
   4.777 +    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
   4.778 +    rectA = refRectA;
   4.779 +    rectB = refRectB;
   4.780 +    intersection = SDL_HasIntersection(&rectA, &rectB);
   4.781 +    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   4.782 +
   4.783 +    // rectB left edge
   4.784 +    refRectB.x = 1 - rectA.w;
   4.785 +    refRectB.y = rectA.y;
   4.786 +    refRectB.w = refRectA.w;
   4.787 +    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
   4.788 +    rectA = refRectA;
   4.789 +    rectB = refRectB;
   4.790 +    intersection = SDL_HasIntersection(&rectA, &rectB);
   4.791 +    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   4.792 +
   4.793 +    // rectB bottom edge
   4.794 +    refRectB.x = rectA.x;
   4.795 +    refRectB.y = rectA.h - 1;
   4.796 +    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
   4.797 +    refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
   4.798 +    rectA = refRectA;
   4.799 +    rectB = refRectB;
   4.800 +    intersection = SDL_HasIntersection(&rectA, &rectB);
   4.801 +    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   4.802 +
   4.803 +    // rectB top edge
   4.804 +    refRectB.x = rectA.x;
   4.805 +    refRectB.y = 1 - rectA.h;
   4.806 +    refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
   4.807 +    refRectB.h = rectA.h;
   4.808 +    rectA = refRectA;
   4.809 +    rectB = refRectB;
   4.810 +    intersection = SDL_HasIntersection(&rectA, &rectB);
   4.811 +    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   4.812 +
   4.813 +	return TEST_COMPLETED;
   4.814 +}
   4.815 +
   4.816 +/*!
   4.817 + * \brief Tests SDL_HasIntersection() with 1x1 pixel sized rectangles
   4.818 + *
   4.819 + * \sa
   4.820 + * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
   4.821 + */
   4.822 +int rect_testHasIntersectionPoint (void *arg)
   4.823 +{
   4.824 +    SDL_Rect refRectA = { 0, 0, 1, 1 };
   4.825 +    SDL_Rect refRectB = { 0, 0, 1, 1 };
   4.826 +    SDL_Rect rectA;
   4.827 +    SDL_Rect rectB;
   4.828 +    SDL_bool intersection;
   4.829 +    int offsetX, offsetY;
   4.830 +
   4.831 +    // intersecting pixels
   4.832 +    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   4.833 +    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   4.834 +    refRectB.x = refRectA.x;
   4.835 +    refRectB.y = refRectA.y;
   4.836 +    rectA = refRectA;
   4.837 +    rectB = refRectB;
   4.838 +    intersection = SDL_HasIntersection(&rectA, &rectB);
   4.839 +    _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   4.840 +
   4.841 +    // non-intersecting pixels cases
   4.842 +    for (offsetX = -1; offsetX <= 1; offsetX++) {
   4.843 +        for (offsetY = -1; offsetY <= 1; offsetY++) {
   4.844 +            if (offsetX != 0 || offsetY != 0) {
   4.845 +                refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   4.846 +                refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   4.847 +                refRectB.x = refRectA.x;
   4.848 +                refRectB.y = refRectA.y;    
   4.849 +                refRectB.x += offsetX;
   4.850 +                refRectB.y += offsetY;
   4.851 +                rectA = refRectA;
   4.852 +                rectB = refRectB;
   4.853 +                intersection = SDL_HasIntersection(&rectA, &rectB);
   4.854 +                _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
   4.855 +            }
   4.856 +        }
   4.857 +    }
   4.858 +
   4.859 +	return TEST_COMPLETED;
   4.860 +}
   4.861 +
   4.862 +/*!
   4.863 + * \brief Tests SDL_HasIntersection() with empty rectangles
   4.864 + *
   4.865 + * \sa
   4.866 + * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
   4.867 + */
   4.868 +int rect_testHasIntersectionEmpty (void *arg)
   4.869 +{
   4.870 +    SDL_Rect refRectA;
   4.871 +    SDL_Rect refRectB;
   4.872 +    SDL_Rect rectA;
   4.873 +    SDL_Rect rectB;
   4.874 +    SDL_bool intersection;
   4.875 +
   4.876 +    // Rect A empty
   4.877 +    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   4.878 +    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   4.879 +    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
   4.880 +    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
   4.881 +    refRectB = refRectA;
   4.882 +    refRectA.w = 0;
   4.883 +    refRectA.h = 0;
   4.884 +    rectA = refRectA;
   4.885 +    rectB = refRectB;
   4.886 +    intersection = SDL_HasIntersection(&rectA, &rectB);
   4.887 +    _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
   4.888 +
   4.889 +    // Rect B empty
   4.890 +    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   4.891 +    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   4.892 +    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
   4.893 +    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
   4.894 +    refRectB = refRectA;
   4.895 +    refRectB.w = 0;
   4.896 +    refRectB.h = 0;
   4.897 +    rectA = refRectA;
   4.898 +    rectB = refRectB;
   4.899 +    intersection = SDL_HasIntersection(&rectA, &rectB);
   4.900 +    _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
   4.901 +
   4.902 +    // Rect A and B empty
   4.903 +    refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   4.904 +    refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   4.905 +    refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
   4.906 +    refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
   4.907 +    refRectB = refRectA;
   4.908 +    refRectA.w = 0;
   4.909 +    refRectA.h = 0;
   4.910 +    refRectB.w = 0;
   4.911 +    refRectB.h = 0;
   4.912 +    rectA = refRectA;
   4.913 +    rectB = refRectB;
   4.914 +    intersection = SDL_HasIntersection(&rectA, &rectB);
   4.915 +    _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
   4.916 +
   4.917 +	return TEST_COMPLETED;
   4.918 +}
   4.919 +
   4.920 +/*!
   4.921 + * \brief Negative tests against SDL_HasIntersection() with invalid parameters
   4.922 + *
   4.923 + * \sa
   4.924 + * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
   4.925 + */
   4.926 +int rect_testHasIntersectionParam(void *arg)
   4.927 +{
   4.928 +    SDL_Rect rectA;
   4.929 +    SDL_Rect rectB;
   4.930 +    SDL_bool intersection;
   4.931 +
   4.932 +    // invalid parameter combinations
   4.933 +    intersection = SDL_HasIntersection((SDL_Rect *)NULL, &rectB);
   4.934 +    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL"); 
   4.935 +    intersection = SDL_HasIntersection(&rectA, (SDL_Rect *)NULL);
   4.936 +    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL"); 
   4.937 +    intersection = SDL_HasIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL);
   4.938 +    SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");     
   4.939 +
   4.940 +	return TEST_COMPLETED;
   4.941 +}
   4.942 +
   4.943 +/*!
   4.944 + * \brief Test SDL_EnclosePoints() without clipping
   4.945 + *
   4.946 + * \sa
   4.947 + * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
   4.948 + */
   4.949 +int rect_testEnclosePoints(void *arg)
   4.950 +{
   4.951 +    const int numPoints = 16;
   4.952 +    SDL_Point refPoints[16];
   4.953 +    SDL_Point points[16];
   4.954 +    SDL_Rect result;
   4.955 +    SDL_bool anyEnclosed;
   4.956 +    SDL_bool anyEnclosedNoResult;
   4.957 +
   4.958 +    // Create input data, tracking result
   4.959 +    SDL_bool expectedEnclosed = SDL_TRUE;
   4.960 +    int newx, newy;
   4.961 +    int minx, maxx, miny, maxy;
   4.962 +    int i;
   4.963 +    for (i=0; i<numPoints; i++) {
   4.964 +        newx = SDLTest_RandomIntegerInRange(-1024, 1024);
   4.965 +        newy = SDLTest_RandomIntegerInRange(-1024, 1024);
   4.966 +        refPoints[i].x = newx;
   4.967 +        refPoints[i].y = newy;
   4.968 +        points[i].x = newx;
   4.969 +        points[i].y = newy;
   4.970 +        if (i==0) {
   4.971 +            minx=maxx=newx;
   4.972 +            miny=maxy=newy;
   4.973 +        } else {
   4.974 +            if (newx<minx) minx=newx;
   4.975 +            if (newx>maxx) maxx=newx;
   4.976 +            if (newy<miny) miny=newy;
   4.977 +            if (newy>maxy) maxy=newy;
   4.978 +        }
   4.979 +    }
   4.980 +    
   4.981 +    // Call function and validate - special case: no result requested
   4.982 +    anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
   4.983 +    SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult, 
   4.984 +        "Check expected return value %s, got %s", 
   4.985 +        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
   4.986 +		(anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
   4.987 +    for (i=0; i<numPoints; i++) {
   4.988 +        SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
   4.989 +            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 
   4.990 +            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
   4.991 +    }
   4.992 +
   4.993 +    // Call function and validate
   4.994 +    anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
   4.995 +    SDLTest_AssertCheck(expectedEnclosed==anyEnclosed, 
   4.996 +        "Check return value %s, got %s", 
   4.997 +        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
   4.998 +		(anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
   4.999 +    for (i=0; i<numPoints; i++) {
  4.1000 +        SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
  4.1001 +            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 
  4.1002 +            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
  4.1003 +    }
  4.1004 +    SDLTest_AssertCheck(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
  4.1005 +        "Resulting enclosing rectangle incorrect: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
  4.1006 +        minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
  4.1007 +
  4.1008 +	return TEST_COMPLETED;
  4.1009 +}
  4.1010 +
  4.1011 +/*!
  4.1012 + * \brief Test SDL_EnclosePoints() with repeated input points
  4.1013 + *
  4.1014 + * \sa
  4.1015 + * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
  4.1016 + */
  4.1017 +int rect_testEnclosePointsRepeatedInput(void *arg)
  4.1018 +{
  4.1019 +    const int numPoints = 8;
  4.1020 +    const int halfPoints = 4;
  4.1021 +    SDL_Point refPoints[8];
  4.1022 +    SDL_Point points[8];
  4.1023 +    SDL_Rect result;
  4.1024 +    SDL_bool anyEnclosed;
  4.1025 +    SDL_bool anyEnclosedNoResult;
  4.1026 +
  4.1027 +    // Create input data, tracking result
  4.1028 +    SDL_bool expectedEnclosed = SDL_TRUE;
  4.1029 +    int newx, newy;
  4.1030 +    int minx, maxx, miny, maxy;
  4.1031 +    int i;
  4.1032 +    for (i=0; i<numPoints; i++) {
  4.1033 +        if (i < halfPoints) {
  4.1034 +            newx = SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1035 +            newy = SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1036 +        } else {
  4.1037 +            newx = refPoints[i-halfPoints].x;
  4.1038 +            newy = refPoints[i-halfPoints].y;
  4.1039 +        }
  4.1040 +        refPoints[i].x = newx;
  4.1041 +        refPoints[i].y = newy;
  4.1042 +        points[i].x = newx;
  4.1043 +        points[i].y = newy;
  4.1044 +        if (i==0) {
  4.1045 +            minx=maxx=newx;
  4.1046 +            miny=maxy=newy;
  4.1047 +        } else {
  4.1048 +            if (newx<minx) minx=newx;
  4.1049 +            if (newx>maxx) maxx=newx;
  4.1050 +            if (newy<miny) miny=newy;
  4.1051 +            if (newy>maxy) maxy=newy;
  4.1052 +        }
  4.1053 +    }
  4.1054 +
  4.1055 +    // Call function and validate - special case: no result requested
  4.1056 +    anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
  4.1057 +    SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult, 
  4.1058 +        "Check return value %s, got %s", 
  4.1059 +        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
  4.1060 +		(anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
  4.1061 +    for (i=0; i<numPoints; i++) {
  4.1062 +        SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
  4.1063 +            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 
  4.1064 +            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
  4.1065 +    }
  4.1066 +    
  4.1067 +    // Call function and validate
  4.1068 +    anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
  4.1069 +    SDLTest_AssertCheck(expectedEnclosed==anyEnclosed, 
  4.1070 +        "Check return value %s, got %s", 
  4.1071 +        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
  4.1072 +		(anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
  4.1073 +    for (i=0; i<numPoints; i++) {
  4.1074 +        SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
  4.1075 +            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 
  4.1076 +            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
  4.1077 +    }
  4.1078 +    SDLTest_AssertCheck(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
  4.1079 +        "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
  4.1080 +        minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
  4.1081 +
  4.1082 +	return TEST_COMPLETED;
  4.1083 +}
  4.1084 +
  4.1085 +/*!
  4.1086 + * \brief Test SDL_EnclosePoints() with clipping
  4.1087 + *
  4.1088 + * \sa
  4.1089 + * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
  4.1090 + */
  4.1091 +int rect_testEnclosePointsWithClipping(void *arg)
  4.1092 +{
  4.1093 +    const int numPoints = 16;
  4.1094 +    SDL_Point refPoints[16];
  4.1095 +    SDL_Point points[16];
  4.1096 +    SDL_Rect refClip;
  4.1097 +    SDL_Rect clip;
  4.1098 +    SDL_Rect result;
  4.1099 +    SDL_bool anyEnclosed;
  4.1100 +    SDL_bool anyEnclosedNoResult;
  4.1101 +    SDL_bool expectedEnclosed = SDL_FALSE;
  4.1102 +    int newx, newy;
  4.1103 +    int minx, maxx, miny, maxy;
  4.1104 +    int i;
  4.1105 +
  4.1106 +    // Setup clipping rectangle
  4.1107 +    refClip.x = SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1108 +    refClip.y = SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1109 +    refClip.w = SDLTest_RandomIntegerInRange(1, 1024);
  4.1110 +    refClip.h = SDLTest_RandomIntegerInRange(1, 1024);
  4.1111 +
  4.1112 +    // Create input data, tracking result
  4.1113 +    for (i=0; i<numPoints; i++) {
  4.1114 +        newx = SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1115 +        newy = SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1116 +        refPoints[i].x = newx;
  4.1117 +        refPoints[i].y = newy;
  4.1118 +        points[i].x = newx;
  4.1119 +        points[i].y = newy;
  4.1120 +        if ((newx>=refClip.x) && (newx<(refClip.x + refClip.w)) &&
  4.1121 +            (newy>=refClip.y) && (newy<(refClip.y + refClip.h))) {
  4.1122 +            if (expectedEnclosed==SDL_FALSE) {
  4.1123 +                minx=maxx=newx;
  4.1124 +                miny=maxy=newy;
  4.1125 +            } else {
  4.1126 +                if (newx<minx) minx=newx;
  4.1127 +                if (newx>maxx) maxx=newx;
  4.1128 +                if (newy<miny) miny=newy;
  4.1129 +                if (newy>maxy) maxy=newy;
  4.1130 +            }
  4.1131 +            expectedEnclosed = SDL_TRUE;
  4.1132 +        }
  4.1133 +    }
  4.1134 +
  4.1135 +    // Call function and validate - special case: no result requested
  4.1136 +    clip = refClip;
  4.1137 +    anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, (SDL_Rect *)NULL);
  4.1138 +    SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult, 
  4.1139 +        "Expected return value %s, got %s", 
  4.1140 +        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
  4.1141 +		(anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
  4.1142 +    for (i=0; i<numPoints; i++) {
  4.1143 +        SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
  4.1144 +            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 
  4.1145 +            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
  4.1146 +    }
  4.1147 +    SDLTest_AssertCheck(refClip.x==clip.x && refClip.y==clip.y && refClip.w==clip.w && refClip.h==clip.h,
  4.1148 +        "Check that source clipping rectangle was not modified");
  4.1149 +    
  4.1150 +    // Call function and validate
  4.1151 +    anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, &result);
  4.1152 +    SDLTest_AssertCheck(expectedEnclosed==anyEnclosed, 
  4.1153 +        "Check return value %s, got %s", 
  4.1154 +        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
  4.1155 +		(anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
  4.1156 +    for (i=0; i<numPoints; i++) {
  4.1157 +        SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
  4.1158 +            "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 
  4.1159 +            i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
  4.1160 +    }
  4.1161 +    SDLTest_AssertCheck(refClip.x==clip.x && refClip.y==clip.y && refClip.w==clip.w && refClip.h==clip.h,
  4.1162 +        "Check that source clipping rectangle was not modified");
  4.1163 +    if (expectedEnclosed==SDL_TRUE) {
  4.1164 +        SDLTest_AssertCheck(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
  4.1165 +            "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
  4.1166 +            minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
  4.1167 +    }    
  4.1168 +    
  4.1169 +    /* Empty clipping rectangle */
  4.1170 +    clip.w = 0;
  4.1171 +    clip.h = 0;
  4.1172 +    expectedEnclosed = SDL_FALSE;
  4.1173 +    anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, &result);
  4.1174 +    SDLTest_AssertCheck(expectedEnclosed==anyEnclosed, 
  4.1175 +        "Check return value %s, got %s", 
  4.1176 +        (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
  4.1177 +		(anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");    
  4.1178 +
  4.1179 +	return TEST_COMPLETED;
  4.1180 +}
  4.1181 +
  4.1182 +/*!
  4.1183 + * \brief Negative tests against SDL_EnclosePoints() with invalid parameters
  4.1184 + *
  4.1185 + * \sa
  4.1186 + * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
  4.1187 + */
  4.1188 +int rect_testEnclosePointsParam(void *arg)
  4.1189 +{
  4.1190 +    SDL_Point points[1];
  4.1191 +    int count;
  4.1192 +    SDL_Rect clip;
  4.1193 +    SDL_Rect result;
  4.1194 +    SDL_bool anyEnclosed;
  4.1195 +
  4.1196 +    // invalid parameter combinations
  4.1197 +    anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 1, (const SDL_Rect *)&clip, &result);
  4.1198 +    SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL"); 
  4.1199 +    anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, 0, (const SDL_Rect *)&clip, &result);
  4.1200 +    SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 2nd parameter is 0");
  4.1201 +    count = SDLTest_RandomIntegerInRange(-100, -1);
  4.1202 +    anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, count, (const SDL_Rect *)&clip, &result);
  4.1203 +    SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 2nd parameter is %i (negative)", count); 
  4.1204 +    anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 0, (const SDL_Rect *)&clip, &result);
  4.1205 +    SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL and 2nd parameter was 0"); 
  4.1206 +
  4.1207 +	return TEST_COMPLETED;
  4.1208 +}
  4.1209 +
  4.1210 +/*!
  4.1211 + * \brief Tests SDL_UnionRect() where rect B is outside rect A
  4.1212 + *
  4.1213 + * \sa
  4.1214 + * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
  4.1215 + */
  4.1216 +int rect_testUnionRectOutside(void *arg)
  4.1217 +{
  4.1218 +    SDL_Rect refRectA, refRectB;
  4.1219 +    SDL_Rect rectA, rectB;
  4.1220 +    SDL_Rect expectedResult;
  4.1221 +    SDL_Rect result;
  4.1222 +    int minx, maxx, miny, maxy;
  4.1223 +    int dx, dy;
  4.1224 +    
  4.1225 +    /* Union 1x1 outside */
  4.1226 +    for (dx = -1; dx < 2; dx++) {     
  4.1227 +        for (dy = -1; dy < 2; dy++) {
  4.1228 +            if ((dx != 0) || (dy != 0)) {
  4.1229 +                refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1230 +                refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1231 +                refRectA.w=1;
  4.1232 +                refRectA.h=1;
  4.1233 +                refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024) + dx*2048;
  4.1234 +                refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024) + dx*2048;
  4.1235 +                refRectB.w=1;
  4.1236 +                refRectB.h=1;
  4.1237 +                minx = (refRectA.x<refRectB.x) ? refRectA.x : refRectB.x;
  4.1238 +                maxx = (refRectA.x>refRectB.x) ? refRectA.x : refRectB.x;
  4.1239 +                miny = (refRectA.y<refRectB.y) ? refRectA.y : refRectB.y;
  4.1240 +                maxy = (refRectA.y>refRectB.y) ? refRectA.y : refRectB.y;                
  4.1241 +                expectedResult.x = minx;
  4.1242 +                expectedResult.y = miny;
  4.1243 +                expectedResult.w = maxx - minx + 1;
  4.1244 +                expectedResult.h = maxy - miny + 1;
  4.1245 +                rectA = refRectA;
  4.1246 +                rectB = refRectB;
  4.1247 +                SDL_UnionRect(&rectA, &rectB, &result);
  4.1248 +                _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  4.1249 +            }
  4.1250 +        }
  4.1251 +    }
  4.1252 +
  4.1253 +    /* Union outside overlap */
  4.1254 +    for (dx = -1; dx < 2; dx++) {     
  4.1255 +        for (dy = -1; dy < 2; dy++) {
  4.1256 +            if ((dx != 0) || (dy != 0)) {
  4.1257 +                refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1258 +                refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1259 +                refRectA.w=SDLTest_RandomIntegerInRange(256, 512);
  4.1260 +                refRectA.h=SDLTest_RandomIntegerInRange(256, 512);
  4.1261 +                refRectB.x=refRectA.x + 1 + dx*2;
  4.1262 +                refRectB.y=refRectA.y + 1 + dy*2;
  4.1263 +                refRectB.w=refRectA.w - 2;
  4.1264 +                refRectB.h=refRectA.h - 2;
  4.1265 +                expectedResult = refRectA;
  4.1266 +                if (dx == -1) expectedResult.x--;
  4.1267 +                if (dy == -1) expectedResult.y--;
  4.1268 +                if ((dx == 1) || (dx == -1)) expectedResult.w++;
  4.1269 +                if ((dy == 1) || (dy == -1)) expectedResult.h++;
  4.1270 +                rectA = refRectA;
  4.1271 +                rectB = refRectB;
  4.1272 +                SDL_UnionRect(&rectA, &rectB, &result);
  4.1273 +                _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  4.1274 +            }
  4.1275 +        }
  4.1276 +    }
  4.1277 +
  4.1278 +	return TEST_COMPLETED;
  4.1279 +}
  4.1280 +
  4.1281 +/*!
  4.1282 + * \brief Tests SDL_UnionRect() where rect A or rect B are empty
  4.1283 + *
  4.1284 + * \sa
  4.1285 + * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
  4.1286 + */
  4.1287 +int rect_testUnionRectEmpty(void *arg)
  4.1288 +{
  4.1289 +    SDL_Rect refRectA, refRectB;
  4.1290 +    SDL_Rect rectA, rectB;
  4.1291 +    SDL_Rect expectedResult;
  4.1292 +    SDL_Rect result;
  4.1293 +
  4.1294 +    /* A empty */    
  4.1295 +    refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1296 +    refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1297 +    refRectA.w=0;
  4.1298 +    refRectA.h=0;
  4.1299 +    refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1300 +    refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1301 +    refRectB.w=SDLTest_RandomIntegerInRange(1, 1024);
  4.1302 +    refRectB.h=SDLTest_RandomIntegerInRange(1, 1024);
  4.1303 +    expectedResult = refRectB;
  4.1304 +    rectA = refRectA;
  4.1305 +    rectB = refRectB;
  4.1306 +    SDL_UnionRect(&rectA, &rectB, &result);
  4.1307 +    _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  4.1308 +    
  4.1309 +    /* B empty */    
  4.1310 +    refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1311 +    refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1312 +    refRectA.w=SDLTest_RandomIntegerInRange(1, 1024);
  4.1313 +    refRectA.h=SDLTest_RandomIntegerInRange(1, 1024);
  4.1314 +    refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1315 +    refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1316 +    refRectB.w=0;
  4.1317 +    refRectB.h=0;
  4.1318 +    expectedResult = refRectA;
  4.1319 +    rectA = refRectA;
  4.1320 +    rectB = refRectB;
  4.1321 +    SDL_UnionRect(&rectA, &rectB, &result);
  4.1322 +    _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  4.1323 +
  4.1324 +    /* A and B empty */    
  4.1325 +    refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1326 +    refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1327 +    refRectA.w=0;
  4.1328 +    refRectA.h=0;
  4.1329 +    refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1330 +    refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1331 +    refRectB.w=0;
  4.1332 +    refRectB.h=0;
  4.1333 +    result.x=0;
  4.1334 +    result.y=0;
  4.1335 +    result.w=0;
  4.1336 +    result.h=0;
  4.1337 +    expectedResult = result;
  4.1338 +    rectA = refRectA;
  4.1339 +    rectB = refRectB;
  4.1340 +    SDL_UnionRect(&rectA, &rectB, &result);
  4.1341 +    _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  4.1342 +
  4.1343 +	return TEST_COMPLETED;
  4.1344 +}
  4.1345 +
  4.1346 +/*!
  4.1347 + * \brief Tests SDL_UnionRect() where rect B is inside rect A
  4.1348 + *
  4.1349 + * \sa
  4.1350 + * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
  4.1351 + */
  4.1352 +int rect_testUnionRectInside(void *arg)
  4.1353 +{
  4.1354 +    SDL_Rect refRectA, refRectB;
  4.1355 +    SDL_Rect rectA, rectB;
  4.1356 +    SDL_Rect expectedResult;
  4.1357 +    SDL_Rect result;
  4.1358 +    int dx, dy;
  4.1359 +    
  4.1360 +    /* Union 1x1 with itself */
  4.1361 +    refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1362 +    refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1363 +    refRectA.w=1;
  4.1364 +    refRectA.h=1;
  4.1365 +    expectedResult = refRectA;
  4.1366 +    rectA = refRectA;
  4.1367 +    SDL_UnionRect(&rectA, &rectA, &result);
  4.1368 +    _validateUnionRectResults(&rectA, &rectA, &refRectA, &refRectA, &result, &expectedResult);
  4.1369 +
  4.1370 +    /* Union 1x1 somewhere inside */
  4.1371 +    refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1372 +    refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1373 +    refRectA.w=SDLTest_RandomIntegerInRange(256, 1024);
  4.1374 +    refRectA.h=SDLTest_RandomIntegerInRange(256, 1024);
  4.1375 +    refRectB.x=refRectA.x + 1 + SDLTest_RandomIntegerInRange(1, refRectA.w - 2);
  4.1376 +    refRectB.y=refRectA.y + 1 + SDLTest_RandomIntegerInRange(1, refRectA.h - 2);
  4.1377 +    refRectB.w=1;
  4.1378 +    refRectB.h=1;
  4.1379 +    expectedResult = refRectA;
  4.1380 +    rectA = refRectA;
  4.1381 +    rectB = refRectB;
  4.1382 +    SDL_UnionRect(&rectA, &rectB, &result);
  4.1383 +    _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  4.1384 +
  4.1385 +    /* Union inside with edges modified */
  4.1386 +    for (dx = -1; dx < 2; dx++) {     
  4.1387 +        for (dy = -1; dy < 2; dy++) {
  4.1388 +            if ((dx != 0) || (dy != 0)) {
  4.1389 +                refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1390 +                refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1391 +                refRectA.w=SDLTest_RandomIntegerInRange(256, 1024);
  4.1392 +                refRectA.h=SDLTest_RandomIntegerInRange(256, 1024);
  4.1393 +                refRectB = refRectA;
  4.1394 +                if (dx == -1) refRectB.x++;
  4.1395 +                if ((dx == 1) || (dx == -1)) refRectB.w--;
  4.1396 +                if (dy == -1) refRectB.y++;
  4.1397 +                if ((dy == 1) || (dy == -1)) refRectB.h--;                
  4.1398 +                expectedResult = refRectA;
  4.1399 +                rectA = refRectA;
  4.1400 +                rectB = refRectB;
  4.1401 +                SDL_UnionRect(&rectA, &rectB, &result);
  4.1402 +                _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  4.1403 +            }
  4.1404 +        }
  4.1405 +    }
  4.1406 +
  4.1407 +	return TEST_COMPLETED;
  4.1408 +}
  4.1409 +
  4.1410 +/*!
  4.1411 + * \brief Negative tests against SDL_UnionRect() with invalid parameters
  4.1412 + *
  4.1413 + * \sa
  4.1414 + * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
  4.1415 + */
  4.1416 +int rect_testUnionRectParam(void *arg)
  4.1417 +{
  4.1418 +    SDL_Rect rectA, rectB;
  4.1419 +    SDL_Rect result;
  4.1420 +
  4.1421 +    // invalid parameter combinations
  4.1422 +    SDL_UnionRect((SDL_Rect *)NULL, &rectB, &result);
  4.1423 +    SDLTest_AssertPass("Check that function returns when 1st parameter is NULL"); 
  4.1424 +    SDL_UnionRect(&rectA, (SDL_Rect *)NULL, &result);
  4.1425 +    SDLTest_AssertPass("Check that function returns  when 2nd parameter is NULL"); 
  4.1426 +    SDL_UnionRect(&rectA, &rectB, (SDL_Rect *)NULL);
  4.1427 +    SDLTest_AssertPass("Check that function returns  when 3rd parameter is NULL"); 
  4.1428 +    SDL_UnionRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
  4.1429 +    SDLTest_AssertPass("Check that function returns  when 1st and 3rd parameter are NULL"); 
  4.1430 +    SDL_UnionRect(&rectA, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
  4.1431 +    SDLTest_AssertPass("Check that function returns  when 2nd and 3rd parameter are NULL"); 
  4.1432 +    SDL_UnionRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
  4.1433 +    SDLTest_AssertPass("Check that function returns  when all parameters are NULL"); 
  4.1434 +
  4.1435 +	return TEST_COMPLETED;
  4.1436 +}
  4.1437 +
  4.1438 +/*!
  4.1439 + * \brief Tests SDL_RectEmpty() with various inputs
  4.1440 + *
  4.1441 + * \sa
  4.1442 + * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
  4.1443 + */
  4.1444 +int rect_testRectEmpty(void *arg)
  4.1445 +{
  4.1446 +    SDL_Rect refRect;
  4.1447 +    SDL_Rect rect;
  4.1448 +    SDL_bool expectedResult;
  4.1449 +    SDL_bool result;
  4.1450 +    int w, h;
  4.1451 +
  4.1452 +    // Non-empty case
  4.1453 +    refRect.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1454 +    refRect.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1455 +    refRect.w=SDLTest_RandomIntegerInRange(256, 1024);
  4.1456 +    refRect.h=SDLTest_RandomIntegerInRange(256, 1024);
  4.1457 +    expectedResult = SDL_FALSE;
  4.1458 +    rect = refRect;
  4.1459 +    result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)&rect);
  4.1460 +    _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
  4.1461 +    
  4.1462 +    // Empty case
  4.1463 +    for (w=-1; w<2; w++) {
  4.1464 +        for (h=-1; h<2; h++) {
  4.1465 +            if ((w != 1) || (h != 1)) {
  4.1466 +                refRect.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1467 +                refRect.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1468 +                refRect.w=w;
  4.1469 +                refRect.h=h;
  4.1470 +                expectedResult = SDL_TRUE;
  4.1471 +                rect = refRect;
  4.1472 +                result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)&rect);
  4.1473 +                _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
  4.1474 +            }
  4.1475 +        }
  4.1476 +    }
  4.1477 +
  4.1478 +	return TEST_COMPLETED;
  4.1479 +}
  4.1480 +
  4.1481 +/*!
  4.1482 + * \brief Negative tests against SDL_RectEmpty() with invalid parameters
  4.1483 + *
  4.1484 + * \sa
  4.1485 + * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
  4.1486 + */
  4.1487 +int rect_testRectEmptyParam(void *arg)
  4.1488 +{
  4.1489 +    SDL_bool result;
  4.1490 +
  4.1491 +    // invalid parameter combinations
  4.1492 +    result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)NULL);
  4.1493 +    SDLTest_AssertCheck(result == SDL_TRUE, "Check that function returns TRUE when 1st parameter is NULL"); 
  4.1494 +
  4.1495 +	return TEST_COMPLETED;
  4.1496 +}
  4.1497 +
  4.1498 +/*!
  4.1499 + * \brief Tests SDL_RectEquals() with various inputs
  4.1500 + *
  4.1501 + * \sa
  4.1502 + * http://wiki.libsdl.org/moin.cgi/SDL_RectEquals
  4.1503 + */
  4.1504 +int rect_testRectEquals(void *arg)
  4.1505 +{
  4.1506 +    SDL_Rect refRectA;
  4.1507 +    SDL_Rect refRectB;
  4.1508 +    SDL_Rect rectA;
  4.1509 +    SDL_Rect rectB;
  4.1510 +    SDL_bool expectedResult;
  4.1511 +    SDL_bool result;
  4.1512 +
  4.1513 +    // Equals
  4.1514 +    refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1515 +    refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1516 +    refRectA.w=SDLTest_RandomIntegerInRange(1, 1024);
  4.1517 +    refRectA.h=SDLTest_RandomIntegerInRange(1, 1024);
  4.1518 +    refRectB = refRectA;    
  4.1519 +    expectedResult = SDL_TRUE;
  4.1520 +    rectA = refRectA;
  4.1521 +    rectB = refRectB;
  4.1522 +    result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)&rectA, (const SDL_Rect *)&rectB);
  4.1523 +    _validateRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
  4.1524 +
  4.1525 +	return TEST_COMPLETED;
  4.1526 +}
  4.1527 +
  4.1528 +/*!
  4.1529 + * \brief Negative tests against SDL_RectEquals() with invalid parameters
  4.1530 + *
  4.1531 + * \sa
  4.1532 + * http://wiki.libsdl.org/moin.cgi/SDL_RectEquals
  4.1533 + */
  4.1534 +int rect_testRectEqualsParam(void *arg)
  4.1535 +{
  4.1536 +    SDL_Rect rectA;
  4.1537 +    SDL_Rect rectB;
  4.1538 +    SDL_bool result;
  4.1539 +
  4.1540 +    /* data setup */
  4.1541 +    rectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1542 +    rectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1543 +    rectA.w=SDLTest_RandomIntegerInRange(1, 1024);
  4.1544 +    rectA.h=SDLTest_RandomIntegerInRange(1, 1024);
  4.1545 +    rectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1546 +    rectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  4.1547 +    rectB.w=SDLTest_RandomIntegerInRange(1, 1024);
  4.1548 +    rectB.h=SDLTest_RandomIntegerInRange(1, 1024);
  4.1549 +
  4.1550 +    // invalid parameter combinations
  4.1551 +    result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)NULL, (const SDL_Rect *)&rectB);
  4.1552 +    SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL"); 
  4.1553 +    result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)&rectA, (const SDL_Rect *)NULL);
  4.1554 +    SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL"); 
  4.1555 +    result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)NULL, (const SDL_Rect *)NULL);
  4.1556 +    SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL"); 
  4.1557 +
  4.1558 +	return TEST_COMPLETED;
  4.1559 +}
  4.1560 +
  4.1561 +/* ================= Test References ================== */
  4.1562 +
  4.1563 +/* Rect test cases */
  4.1564 +
  4.1565 +/* SDL_IntersectRectAndLine */
  4.1566 +static const SDLTest_TestCaseReference rectTest1 =
  4.1567 +		{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLine,"rect_testIntersectRectAndLine",  "Tests SDL_IntersectRectAndLine clipping cases", TEST_ENABLED };
  4.1568 +
  4.1569 +static const SDLTest_TestCaseReference rectTest2 =
  4.1570 +		{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLineInside, "rect_testIntersectRectAndLineInside", "Tests SDL_IntersectRectAndLine with line fully contained in rect", TEST_ENABLED };
  4.1571 +
  4.1572 +static const SDLTest_TestCaseReference rectTest3 =
  4.1573 +		{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLineOutside, "rect_testIntersectRectAndLineOutside", "Tests SDL_IntersectRectAndLine with line fully outside of rect", TEST_ENABLED };
  4.1574 +
  4.1575 +static const SDLTest_TestCaseReference rectTest4 =
  4.1576 +		{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLineEmpty, "rect_testIntersectRectAndLineEmpty", "Tests SDL_IntersectRectAndLine with empty rectangle ", TEST_ENABLED };
  4.1577 +
  4.1578 +static const SDLTest_TestCaseReference rectTest5 =
  4.1579 +		{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLineParam, "rect_testIntersectRectAndLineParam", "Negative tests against SDL_IntersectRectAndLine with invalid parameters", TEST_ENABLED };
  4.1580 +
  4.1581 +/* SDL_IntersectRect */
  4.1582 +static const SDLTest_TestCaseReference rectTest6 =
  4.1583 +		{ (SDLTest_TestCaseFp)rect_testIntersectRectInside, "rect_testIntersectRectInside", "Tests SDL_IntersectRect with B fully contained in A", TEST_ENABLED };
  4.1584 +
  4.1585 +static const SDLTest_TestCaseReference rectTest7 =
  4.1586 +		{ (SDLTest_TestCaseFp)rect_testIntersectRectOutside, "rect_testIntersectRectOutside", "Tests SDL_IntersectRect with B fully outside of A", TEST_ENABLED };
  4.1587 +
  4.1588 +static const SDLTest_TestCaseReference rectTest8 =
  4.1589 +		{ (SDLTest_TestCaseFp)rect_testIntersectRectPartial, "rect_testIntersectRectPartial", "Tests SDL_IntersectRect with B partially intersecting A", TEST_ENABLED };
  4.1590 +
  4.1591 +static const SDLTest_TestCaseReference rectTest9 =
  4.1592 +		{ (SDLTest_TestCaseFp)rect_testIntersectRectPoint, "rect_testIntersectRectPoint", "Tests SDL_IntersectRect with 1x1 sized rectangles", TEST_ENABLED };
  4.1593 +
  4.1594 +static const SDLTest_TestCaseReference rectTest10 =
  4.1595 +		{ (SDLTest_TestCaseFp)rect_testIntersectRectEmpty, "rect_testIntersectRectEmpty", "Tests SDL_IntersectRect with empty rectangles", TEST_ENABLED };
  4.1596 +
  4.1597 +static const SDLTest_TestCaseReference rectTest11 =
  4.1598 +		{ (SDLTest_TestCaseFp)rect_testIntersectRectParam, "rect_testIntersectRectParam", "Negative tests against SDL_IntersectRect with invalid parameters", TEST_ENABLED };
  4.1599 +
  4.1600 +/* SDL_HasIntersection */
  4.1601 +static const SDLTest_TestCaseReference rectTest12 =
  4.1602 +		{ (SDLTest_TestCaseFp)rect_testHasIntersectionInside, "rect_testHasIntersectionInside", "Tests SDL_HasIntersection with B fully contained in A", TEST_ENABLED };
  4.1603 +
  4.1604 +static const SDLTest_TestCaseReference rectTest13 =
  4.1605 +		{ (SDLTest_TestCaseFp)rect_testHasIntersectionOutside, "rect_testHasIntersectionOutside", "Tests SDL_HasIntersection with B fully outside of A", TEST_ENABLED };
  4.1606 +
  4.1607 +static const SDLTest_TestCaseReference rectTest14 =
  4.1608 +		{ (SDLTest_TestCaseFp)rect_testHasIntersectionPartial,"rect_testHasIntersectionPartial",  "Tests SDL_HasIntersection with B partially intersecting A", TEST_ENABLED };
  4.1609 +
  4.1610 +static const SDLTest_TestCaseReference rectTest15 =
  4.1611 +		{ (SDLTest_TestCaseFp)rect_testHasIntersectionPoint, "rect_testHasIntersectionPoint", "Tests SDL_HasIntersection with 1x1 sized rectangles", TEST_ENABLED };
  4.1612 +
  4.1613 +static const SDLTest_TestCaseReference rectTest16 =
  4.1614 +		{ (SDLTest_TestCaseFp)rect_testHasIntersectionEmpty, "rect_testHasIntersectionEmpty", "Tests SDL_HasIntersection with empty rectangles", TEST_ENABLED };
  4.1615 +
  4.1616 +static const SDLTest_TestCaseReference rectTest17 =
  4.1617 +		{ (SDLTest_TestCaseFp)rect_testHasIntersectionParam, "rect_testHasIntersectionParam", "Negative tests against SDL_HasIntersection with invalid parameters", TEST_ENABLED };
  4.1618 +
  4.1619 +/* SDL_EnclosePoints */
  4.1620 +static const SDLTest_TestCaseReference rectTest18 =
  4.1621 +		{ (SDLTest_TestCaseFp)rect_testEnclosePoints, "rect_testEnclosePoints", "Tests SDL_EnclosePoints without clipping", TEST_ENABLED };
  4.1622 +
  4.1623 +static const SDLTest_TestCaseReference rectTest19 =
  4.1624 +		{ (SDLTest_TestCaseFp)rect_testEnclosePointsWithClipping, "rect_testEnclosePointsWithClipping", "Tests SDL_EnclosePoints with clipping", TEST_ENABLED };
  4.1625 +
  4.1626 +static const SDLTest_TestCaseReference rectTest20 =
  4.1627 +		{ (SDLTest_TestCaseFp)rect_testEnclosePointsRepeatedInput, "rect_testEnclosePointsRepeatedInput", "Tests SDL_EnclosePoints with repeated input", TEST_ENABLED };
  4.1628 +
  4.1629 +static const SDLTest_TestCaseReference rectTest21 =
  4.1630 +		{ (SDLTest_TestCaseFp)rect_testEnclosePointsParam, "rect_testEnclosePointsParam", "Negative tests against SDL_EnclosePoints with invalid parameters", TEST_ENABLED };
  4.1631 +
  4.1632 +/* SDL_UnionRect */
  4.1633 +static const SDLTest_TestCaseReference rectTest22 =
  4.1634 +		{ (SDLTest_TestCaseFp)rect_testUnionRectInside, "rect_testUnionRectInside", "Tests SDL_UnionRect where rect B is inside rect A", TEST_ENABLED };
  4.1635 +
  4.1636 +static const SDLTest_TestCaseReference rectTest23 =
  4.1637 +		{ (SDLTest_TestCaseFp)rect_testUnionRectOutside, "rect_testUnionRectOutside", "Tests SDL_UnionRect where rect B is outside rect A", TEST_ENABLED };
  4.1638 +
  4.1639 +static const SDLTest_TestCaseReference rectTest24 =
  4.1640 +		{ (SDLTest_TestCaseFp)rect_testUnionRectEmpty, "rect_testUnionRectEmpty", "Tests SDL_UnionRect where rect A or rect B are empty", TEST_ENABLED };
  4.1641 +
  4.1642 +static const SDLTest_TestCaseReference rectTest25 =
  4.1643 +		{ (SDLTest_TestCaseFp)rect_testUnionRectParam, "rect_testUnionRectParam", "Negative tests against SDL_UnionRect with invalid parameters", TEST_ENABLED };
  4.1644 +
  4.1645 +/* SDL_RectEmpty */
  4.1646 +static const SDLTest_TestCaseReference rectTest26 =
  4.1647 +		{ (SDLTest_TestCaseFp)rect_testRectEmpty, "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED };
  4.1648 +
  4.1649 +static const SDLTest_TestCaseReference rectTest27 =
  4.1650 +		{ (SDLTest_TestCaseFp)rect_testRectEmptyParam, "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED };
  4.1651 +
  4.1652 +/* SDL_RectEquals */
  4.1653 +
  4.1654 +static const SDLTest_TestCaseReference rectTest28 =
  4.1655 +		{ (SDLTest_TestCaseFp)rect_testRectEquals, "rect_testRectEquals", "Tests SDL_RectEquals with various inputs", TEST_ENABLED };
  4.1656 +
  4.1657 +static const SDLTest_TestCaseReference rectTest29 =
  4.1658 +		{ (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED };
  4.1659 +
  4.1660 +
  4.1661 +/*!
  4.1662 + * \brief Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
  4.1663 + *
  4.1664 + * \sa
  4.1665 + * http://wiki.libsdl.org/moin.cgi/CategoryRect
  4.1666 + */
  4.1667 +static const SDLTest_TestCaseReference *rectTests[] =  {
  4.1668 +	&rectTest1, &rectTest2, &rectTest3, &rectTest4, &rectTest5, &rectTest6, &rectTest7, &rectTest8, &rectTest9, &rectTest10, &rectTest11, &rectTest12, &rectTest13, &rectTest14, 
  4.1669 +	&rectTest15, &rectTest16, &rectTest17, &rectTest18, &rectTest19, &rectTest20, &rectTest21, &rectTest22, &rectTest23, &rectTest24, &rectTest25, &rectTest26, &rectTest27,
  4.1670 +	&rectTest28, &rectTest29, NULL
  4.1671 +};
  4.1672 +
  4.1673 +
  4.1674 +/* Rect test suite (global) */
  4.1675 +SDLTest_TestSuiteReference rectTestSuite = {
  4.1676 +	"Rect",
  4.1677 +	NULL,
  4.1678 +	rectTests,
  4.1679 +	NULL
  4.1680 +};
     5.1 --- a/test/tests/testsuites.h	Fri Dec 14 23:05:34 2012 -0800
     5.2 +++ b/test/tests/testsuites.h	Sat Dec 15 21:50:17 2012 -0800
     5.3 @@ -14,7 +14,7 @@
     5.4  //extern SDLTest_TestSuiteReference eventsTestSuite;
     5.5  //extern SDLTest_TestSuiteReference keyboardTestSuite;
     5.6  extern SDLTest_TestSuiteReference platformTestSuite;
     5.7 -//extern SDLTest_TestSuiteReference rectTestSuite;
     5.8 +extern SDLTest_TestSuiteReference rectTestSuite;
     5.9  //extern SDLTest_TestSuiteReference renderTestSuite;
    5.10  //extern SDLTest_TestSuiteReference rwopsTestSuite;
    5.11  //extern SDLTest_TestSuiteReference surfaceTestSuite;
    5.12 @@ -28,7 +28,7 @@
    5.13  //	&eventsTestSuite,
    5.14  //	&keyboardTestSuite,
    5.15  	&platformTestSuite,
    5.16 -//	&rectTestSuite,
    5.17 +	&rectTestSuite,
    5.18  //	&renderTestSuite,
    5.19  //	&rwopsTestSuite,
    5.20  //	&surfaceTestSuite,