test/testautomation_rect.c
author Jørgen P. Tjernø <jorgen@valvesoftware.com>
Wed, 03 Apr 2013 16:48:23 -0700
changeset 7056 a5699778d80f
parent 6772 5229a117ef97
child 7074 0545811b3543
permissions -rw-r--r--
Improve testgamecontroller output & robustness.
     1 /**
     2  * Original code: automated SDL rect test written by Edgar Simo "bobbens"
     3  * New/updated tests: aschiffler at ferzkopp dot net
     4  */
     5 
     6 #include <stdio.h>
     7 
     8 #include "SDL.h"
     9 #include "SDL_test.h"
    10 
    11 /* ================= Test Case Implementation ================== */
    12 
    13 /* Helper functions */
    14 
    15 /*!
    16  * \brief Private helper to check SDL_IntersectRectAndLine results
    17  */
    18 void _validateIntersectRectAndLineResults(
    19     SDL_bool intersection, SDL_bool expectedIntersection,
    20     SDL_Rect *rect, SDL_Rect * refRect,
    21     int x1, int y1, int x2, int y2,
    22     int x1Ref, int y1Ref, int x2Ref, int y2Ref)
    23 {
    24     SDLTest_AssertCheck(intersection == expectedIntersection, 
    25         "Check for correct intersection result: expected %s, got %s intersecting rect (%d,%d,%d,%d) with line (%d,%d - %d,%d)",
    26         (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
    27         (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
    28         refRect->x, refRect->y, refRect->w, refRect->h,
    29         x1Ref, y1Ref, x2Ref, y2Ref);
    30     SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
    31         "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
    32         rect->x, rect->y, rect->w, rect->h,
    33         refRect->x, refRect->y, refRect->w, refRect->h);
    34     SDLTest_AssertCheck(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref,
    35         "Check if line was incorrectly clipped or modified: got (%d,%d - %d,%d) expected (%d,%d - %d,%d)",
    36         x1, y1, x2, y2,
    37         x1Ref, y1Ref, x2Ref, y2Ref);
    38 }
    39 
    40 /* Test case functions */
    41 
    42 /*!
    43  * \brief Tests SDL_IntersectRectAndLine() clipping cases
    44  *
    45  * \sa
    46  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
    47  */
    48 int 
    49 rect_testIntersectRectAndLine (void *arg)
    50 {
    51     SDL_Rect refRect = { 0, 0, 32, 32 };
    52     SDL_Rect rect;
    53     int x1, y1;
    54     int x2, y2;
    55     SDL_bool intersected;
    56 
    57     int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w);
    58     int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
    59     int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
    60     int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h);
    61 
    62     x1 = xLeft;
    63     y1 = 15;
    64     x2 = xRight;
    65     y2 = 15;
    66     rect = refRect;
    67     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    68     _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 15, 31, 15);
    69 
    70     x1 = 15;
    71     y1 = yTop;
    72     x2 = 15;
    73     y2 = yBottom;
    74     rect = refRect;
    75     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    76     _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 15, 0, 15, 31);
    77 
    78     x1 = -refRect.w;
    79     y1 = -refRect.h;
    80     x2 = 2*refRect.w;
    81     y2 = 2*refRect.h;
    82     rect = refRect;
    83     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    84      _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 0, 31, 31);
    85 
    86     x1 = 2*refRect.w;
    87     y1 = 2*refRect.h;
    88     x2 = -refRect.w;
    89     y2 = -refRect.h;
    90     rect = refRect;
    91     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
    92     _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 31, 0, 0);
    93 
    94     x1 = -1;
    95     y1 = 32;
    96     x2 = 32;
    97     y2 = -1;
    98     rect = refRect;
    99     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   100     _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 31, 31, 0);
   101 
   102     x1 = 32;
   103     y1 = -1;
   104     x2 = -1;
   105     y2 = 32;
   106     rect = refRect;
   107     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   108     _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 0, 0, 31);
   109 
   110 	return TEST_COMPLETED;
   111 }
   112 
   113 /*!
   114  * \brief Tests SDL_IntersectRectAndLine() non-clipping case line inside
   115  *
   116  * \sa
   117  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
   118  */
   119 int 
   120 rect_testIntersectRectAndLineInside (void *arg)
   121 {
   122     SDL_Rect refRect = { 0, 0, 32, 32 };
   123     SDL_Rect rect;
   124     int x1, y1;
   125     int x2, y2;
   126     SDL_bool intersected;
   127 
   128     int xmin = refRect.x;
   129     int xmax = refRect.x + refRect.w - 1;
   130     int ymin = refRect.y;
   131     int ymax = refRect.y + refRect.h - 1;
   132     int x1Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
   133     int y1Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
   134     int x2Ref = SDLTest_RandomIntegerInRange(xmin + 1, xmax - 1);
   135     int y2Ref = SDLTest_RandomIntegerInRange(ymin + 1, ymax - 1);
   136 
   137     x1 = x1Ref;
   138     y1 = y1Ref;
   139     x2 = x2Ref;
   140     y2 = y2Ref;
   141     rect = refRect;
   142     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   143     _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
   144 
   145     x1 = x1Ref;
   146     y1 = y1Ref;
   147     x2 = xmax;
   148     y2 = ymax;
   149     rect = refRect;
   150     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   151     _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, xmax, ymax);
   152 
   153     x1 = xmin;
   154     y1 = ymin;
   155     x2 = x2Ref;
   156     y2 = y2Ref;
   157     rect = refRect;
   158     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   159     _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, x2Ref, y2Ref);
   160 
   161     x1 = xmin;
   162     y1 = ymin;
   163     x2 = xmax;
   164     y2 = ymax;
   165     rect = refRect;
   166     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   167     _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, xmax, ymax);
   168 
   169     x1 = xmin;
   170     y1 = ymax;
   171     x2 = xmax;
   172     y2 = ymin;
   173     rect = refRect;
   174     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   175     _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymax, xmax, ymin);
   176 
   177 	return TEST_COMPLETED;
   178 }
   179 
   180 /*!
   181  * \brief Tests SDL_IntersectRectAndLine() non-clipping cases outside
   182  *
   183  * \sa
   184  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
   185  */
   186 int 
   187 rect_testIntersectRectAndLineOutside (void *arg)
   188 {
   189     SDL_Rect refRect = { 0, 0, 32, 32 };
   190     SDL_Rect rect;
   191     int x1, y1;
   192     int x2, y2;
   193     SDL_bool intersected;
   194 
   195     int xLeft = -SDLTest_RandomIntegerInRange(1, refRect.w);
   196     int xRight = refRect.w + SDLTest_RandomIntegerInRange(1, refRect.w);
   197     int yTop = -SDLTest_RandomIntegerInRange(1, refRect.h);
   198     int yBottom = refRect.h + SDLTest_RandomIntegerInRange(1, refRect.h);
   199 
   200     x1 = xLeft;
   201     y1 = 0;
   202     x2 = xLeft;
   203     y2 = 31;
   204     rect = refRect;
   205     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   206     _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xLeft, 0, xLeft, 31);
   207 
   208     x1 = xRight;
   209     y1 = 0;
   210     x2 = xRight;
   211     y2 = 31;
   212     rect = refRect;
   213     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   214     _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xRight, 0, xRight, 31);
   215 
   216     x1 = 0;
   217     y1 = yTop;
   218     x2 = 31;
   219     y2 = yTop;
   220     rect = refRect;
   221     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   222     _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yTop, 31, yTop);
   223 
   224     x1 = 0;
   225     y1 = yBottom;
   226     x2 = 31;
   227     y2 = yBottom;
   228     rect = refRect;
   229     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   230     _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yBottom, 31, yBottom);
   231 
   232 	return TEST_COMPLETED;
   233 }
   234 
   235 /*!
   236  * \brief Tests SDL_IntersectRectAndLine() with empty rectangle
   237  *
   238  * \sa
   239  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
   240  */
   241 int 
   242 rect_testIntersectRectAndLineEmpty (void *arg)
   243 {
   244     SDL_Rect refRect;
   245     SDL_Rect rect;
   246     int x1, y1, x1Ref, y1Ref;
   247     int x2, y2, x2Ref, y2Ref;
   248     SDL_bool intersected;
   249         
   250     refRect.x = SDLTest_RandomIntegerInRange(1, 1024);
   251     refRect.y = SDLTest_RandomIntegerInRange(1, 1024);
   252     refRect.w = 0;
   253     refRect.h = 0;
   254     x1Ref = refRect.x;
   255     y1Ref = refRect.y;
   256     x2Ref = SDLTest_RandomIntegerInRange(1, 1024);
   257     y2Ref = SDLTest_RandomIntegerInRange(1, 1024);
   258 
   259     x1 = x1Ref;
   260     y1 = y1Ref;
   261     x2 = x2Ref;
   262     y2 = y2Ref;
   263     rect = refRect;
   264     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   265     _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
   266 
   267 	return TEST_COMPLETED;
   268 }
   269 
   270 /*!
   271  * \brief Negative tests against SDL_IntersectRectAndLine() with invalid parameters
   272  *
   273  * \sa
   274  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
   275  */
   276 int 
   277 rect_testIntersectRectAndLineParam (void *arg)
   278 {
   279     SDL_Rect rect = { 0, 0, 32, 32 };
   280     int x1 = rect.w / 2;
   281     int y1 = rect.h / 2;
   282     int x2 = x1;
   283     int y2 = 2 * rect.h;
   284     SDL_bool intersected;
   285     
   286     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
   287     SDLTest_AssertCheck(intersected == SDL_TRUE, "Check that intersection result was SDL_TRUE");
   288     
   289     intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, &x1, &y1, &x2, &y2);
   290     SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
   291     intersected = SDL_IntersectRectAndLine(&rect, (int *)NULL, &y1, &x2, &y2);
   292     SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
   293     intersected = SDL_IntersectRectAndLine(&rect, &x1, (int *)NULL, &x2, &y2);
   294     SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 3rd parameter is NULL");
   295     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, (int *)NULL, &y2);
   296     SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 4th parameter is NULL");
   297     intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, (int *)NULL);
   298     SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when 5th parameter is NULL");
   299     intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL);
   300     SDLTest_AssertCheck(intersected == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");
   301 
   302 	return TEST_COMPLETED;
   303 }
   304 
   305 /*!
   306  * \brief Private helper to check SDL_HasIntersection results
   307  */
   308 void _validateHasIntersectionResults(
   309     SDL_bool intersection, SDL_bool expectedIntersection, 
   310     SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
   311 {
   312     SDLTest_AssertCheck(intersection == expectedIntersection, 
   313         "Check intersection result: expected %s, got %s intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)",
   314         (expectedIntersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
   315         (intersection == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
   316         rectA->x, rectA->y, rectA->w, rectA->h, 
   317         rectB->x, rectB->y, rectB->w, rectB->h);
   318     SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
   319         "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   320         rectA->x, rectA->y, rectA->w, rectA->h,
   321         refRectA->x, refRectA->y, refRectA->w, refRectA->h);
   322     SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
   323         "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   324         rectB->x, rectB->y, rectB->w, rectB->h,
   325         refRectB->x, refRectB->y, refRectB->w, refRectB->h);
   326 }
   327 
   328 /*!
   329  * \brief Private helper to check SDL_IntersectRect results
   330  */
   331 void _validateIntersectRectResults(
   332     SDL_bool intersection, SDL_bool expectedIntersection, 
   333     SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB, 
   334     SDL_Rect *result, SDL_Rect *expectedResult)
   335 {
   336     _validateHasIntersectionResults(intersection, expectedIntersection, rectA, rectB, refRectA, refRectB);
   337     if (result && expectedResult) {
   338         SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
   339             "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)",
   340             rectA->x, rectA->y, rectA->w, rectA->h, 
   341             rectB->x, rectB->y, rectB->w, rectB->h,
   342             result->x, result->y, result->w, result->h,
   343             expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
   344     }
   345 }
   346 
   347 /*!
   348  * \brief Private helper to check SDL_UnionRect results
   349  */
   350 void _validateUnionRectResults(
   351     SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB, 
   352     SDL_Rect *result, SDL_Rect *expectedResult)
   353 {
   354     SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
   355         "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   356         rectA->x, rectA->y, rectA->w, rectA->h,
   357         refRectA->x, refRectA->y, refRectA->w, refRectA->h);
   358     SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
   359         "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   360         rectB->x, rectB->y, rectB->w, rectB->h,
   361         refRectB->x, refRectB->y, refRectB->w, refRectB->h);
   362     SDLTest_AssertCheck(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
   363         "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)",
   364         rectA->x, rectA->y, rectA->w, rectA->h, 
   365         rectB->x, rectB->y, rectB->w, rectB->h,
   366         result->x, result->y, result->w, result->h,
   367         expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
   368 }
   369 
   370 /*!
   371  * \brief Private helper to check SDL_RectEmpty results
   372  */
   373 void _validateRectEmptyResults(
   374     SDL_bool empty, SDL_bool expectedEmpty, 
   375     SDL_Rect *rect, SDL_Rect *refRect)
   376 {
   377     SDLTest_AssertCheck(empty == expectedEmpty, 
   378         "Check for correct empty result: expected %s, got %s testing (%d,%d,%d,%d)",
   379         (expectedEmpty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
   380         (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
   381         rect->x, rect->y, rect->w, rect->h);
   382     SDLTest_AssertCheck(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
   383         "Check that source rectangle was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   384         rect->x, rect->y, rect->w, rect->h,
   385         refRect->x, refRect->y, refRect->w, refRect->h);
   386 }
   387 
   388 /*!
   389  * \brief Private helper to check SDL_RectEquals results
   390  */
   391 void _validateRectEqualsResults(
   392     SDL_bool equals, SDL_bool expectedEquals, 
   393     SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
   394 {
   395     SDLTest_AssertCheck(equals == expectedEquals, 
   396         "Check for correct equals result: expected %s, got %s testing (%d,%d,%d,%d) and (%d,%d,%d,%d)",
   397         (expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
   398         (equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
   399         rectA->x, rectA->y, rectA->w, rectA->h,
   400         rectB->x, rectB->y, rectB->w, rectB->h);
   401     SDLTest_AssertCheck(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
   402         "Check that source rectangle A was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   403         rectA->x, rectA->y, rectA->w, rectA->h,
   404         refRectA->x, refRectA->y, refRectA->w, refRectA->h);
   405     SDLTest_AssertCheck(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
   406         "Check that source rectangle B was not modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
   407         rectB->x, rectB->y, rectB->w, rectB->h,
   408         refRectB->x, refRectB->y, refRectB->w, refRectB->h);
   409 }
   410 
   411 /*!
   412  * \brief Tests SDL_IntersectRect() with B fully inside A
   413  *
   414  * \sa
   415  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
   416  */
   417 int rect_testIntersectRectInside (void *arg)
   418 {
   419     SDL_Rect refRectA = { 0, 0, 32, 32 };
   420     SDL_Rect refRectB;
   421     SDL_Rect rectA;
   422     SDL_Rect rectB;
   423     SDL_Rect result;
   424     SDL_bool intersection;
   425 
   426     // rectB fully contained in rectA
   427     refRectB.x = 0;
   428     refRectB.y = 0;
   429     refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
   430     refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
   431     rectA = refRectA;
   432     rectB = refRectB;
   433     intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   434     _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectB);
   435 
   436 	return TEST_COMPLETED;
   437 }
   438 
   439 /*!
   440  * \brief Tests SDL_IntersectRect() with B fully outside A
   441  *
   442  * \sa
   443  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
   444  */
   445 int rect_testIntersectRectOutside (void *arg)
   446 {
   447     SDL_Rect refRectA = { 0, 0, 32, 32 };
   448     SDL_Rect refRectB;
   449     SDL_Rect rectA;
   450     SDL_Rect rectB;
   451     SDL_Rect result;
   452     SDL_bool intersection;
   453 
   454     // rectB fully outside of rectA
   455     refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
   456     refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
   457     refRectB.w = refRectA.w;
   458     refRectB.h = refRectA.h;
   459     rectA = refRectA;
   460     rectB = refRectB;
   461     intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   462     _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);    
   463 
   464 	return TEST_COMPLETED;
   465 }
   466 
   467 /*!
   468  * \brief Tests SDL_IntersectRect() with B partially intersecting A
   469  *
   470  * \sa
   471  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
   472  */
   473 int rect_testIntersectRectPartial (void *arg)
   474 {
   475     SDL_Rect refRectA = { 0, 0, 32, 32 };
   476     SDL_Rect refRectB;
   477     SDL_Rect rectA;
   478     SDL_Rect rectB;
   479     SDL_Rect result;
   480     SDL_Rect expectedResult;
   481     SDL_bool intersection;
   482 
   483     // rectB partially contained in rectA
   484     refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
   485     refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
   486     refRectB.w = refRectA.w;
   487     refRectB.h = refRectA.h;
   488     rectA = refRectA;
   489     rectB = refRectB;
   490     expectedResult.x = refRectB.x;
   491     expectedResult.y = refRectB.y;
   492     expectedResult.w = refRectA.w - refRectB.x;
   493     expectedResult.h = refRectA.h - refRectB.y;    
   494     intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   495     _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
   496 
   497     // rectB right edge
   498     refRectB.x = rectA.w - 1;
   499     refRectB.y = rectA.y;
   500     refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
   501     refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
   502     rectA = refRectA;
   503     rectB = refRectB;
   504     expectedResult.x = refRectB.x;
   505     expectedResult.y = refRectB.y;
   506     expectedResult.w = 1;
   507     expectedResult.h = refRectB.h;    
   508     intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   509     _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
   510 
   511     // rectB left edge
   512     refRectB.x = 1 - rectA.w;
   513     refRectB.y = rectA.y;
   514     refRectB.w = refRectA.w;
   515     refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
   516     rectA = refRectA;
   517     rectB = refRectB;
   518     expectedResult.x = 0;
   519     expectedResult.y = refRectB.y;
   520     expectedResult.w = 1;
   521     expectedResult.h = refRectB.h;    
   522     intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   523     _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
   524 
   525     // rectB bottom edge
   526     refRectB.x = rectA.x;
   527     refRectB.y = rectA.h - 1;
   528     refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
   529     refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
   530     rectA = refRectA;
   531     rectB = refRectB;
   532     expectedResult.x = refRectB.x;
   533     expectedResult.y = refRectB.y;
   534     expectedResult.w = refRectB.w;
   535     expectedResult.h = 1;    
   536     intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   537     _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
   538 
   539     // rectB top edge
   540     refRectB.x = rectA.x;
   541     refRectB.y = 1 - rectA.h;
   542     refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
   543     refRectB.h = rectA.h;
   544     rectA = refRectA;
   545     rectB = refRectB;
   546     expectedResult.x = refRectB.x;
   547     expectedResult.y = 0;
   548     expectedResult.w = refRectB.w;
   549     expectedResult.h = 1;    
   550     intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   551     _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
   552 
   553 	return TEST_COMPLETED;
   554 }
   555 
   556 /*!
   557  * \brief Tests SDL_IntersectRect() with 1x1 pixel sized rectangles
   558  *
   559  * \sa
   560  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
   561  */
   562 int rect_testIntersectRectPoint (void *arg)
   563 {
   564     SDL_Rect refRectA = { 0, 0, 1, 1 };
   565     SDL_Rect refRectB = { 0, 0, 1, 1 };
   566     SDL_Rect rectA;
   567     SDL_Rect rectB;
   568     SDL_Rect result;
   569     SDL_bool intersection;
   570     int offsetX, offsetY;
   571 
   572     // intersecting pixels
   573     refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   574     refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   575     refRectB.x = refRectA.x;
   576     refRectB.y = refRectA.y;
   577     rectA = refRectA;
   578     rectB = refRectB;
   579     intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   580     _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectA);
   581 
   582     // non-intersecting pixels cases
   583     for (offsetX = -1; offsetX <= 1; offsetX++) {
   584         for (offsetY = -1; offsetY <= 1; offsetY++) {
   585             if (offsetX != 0 || offsetY != 0) {
   586                 refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   587                 refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   588                 refRectB.x = refRectA.x;
   589                 refRectB.y = refRectA.y;    
   590                 refRectB.x += offsetX;
   591                 refRectB.y += offsetY;
   592                 rectA = refRectA;
   593                 rectB = refRectB;
   594                 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   595                 _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
   596             }
   597         }
   598     }
   599 
   600 	return TEST_COMPLETED;
   601 }
   602 
   603 /*!
   604  * \brief Tests SDL_IntersectRect() with empty rectangles
   605  *
   606  * \sa
   607  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
   608  */
   609 int rect_testIntersectRectEmpty (void *arg)
   610 {
   611     SDL_Rect refRectA;
   612     SDL_Rect refRectB;
   613     SDL_Rect rectA;
   614     SDL_Rect rectB;
   615     SDL_Rect result;
   616     SDL_bool intersection;
   617 
   618     // Rect A empty
   619     refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   620     refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   621     refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
   622     refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
   623     refRectB = refRectA;
   624     refRectA.w = 0;
   625     refRectA.h = 0;
   626     rectA = refRectA;
   627     rectB = refRectB;
   628     intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   629     _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
   630 
   631     // Rect B empty
   632     refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   633     refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   634     refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
   635     refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
   636     refRectB = refRectA;
   637     refRectB.w = 0;
   638     refRectB.h = 0;
   639     rectA = refRectA;
   640     rectB = refRectB;
   641     intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   642     _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
   643 
   644     // Rect A and B empty
   645     refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   646     refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   647     refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
   648     refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
   649     refRectB = refRectA;
   650     refRectA.w = 0;
   651     refRectA.h = 0;
   652     refRectB.w = 0;
   653     refRectB.h = 0;
   654     rectA = refRectA;
   655     rectB = refRectB;
   656     intersection = SDL_IntersectRect(&rectA, &rectB, &result);
   657     _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
   658 
   659 	return TEST_COMPLETED;
   660 }
   661 
   662 /*!
   663  * \brief Negative tests against SDL_IntersectRect() with invalid parameters
   664  *
   665  * \sa
   666  * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
   667  */
   668 int rect_testIntersectRectParam(void *arg)
   669 {
   670     SDL_Rect rectA;
   671     SDL_Rect rectB;
   672     SDL_Rect result;
   673     SDL_bool intersection;
   674 
   675     // invalid parameter combinations
   676     intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, &result);
   677     SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL"); 
   678     intersection = SDL_IntersectRect(&rectA, (SDL_Rect *)NULL, &result);
   679     SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL"); 
   680     intersection = SDL_IntersectRect(&rectA, &rectB, (SDL_Rect *)NULL);
   681     SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 3st parameter is NULL"); 
   682     intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, &result);
   683     SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameters are NULL"); 
   684     intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
   685     SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 3rd parameters are NULL "); 
   686     intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
   687     SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");     
   688 
   689 	return TEST_COMPLETED;
   690 }
   691 
   692 /*!
   693  * \brief Tests SDL_HasIntersection() with B fully inside A
   694  *
   695  * \sa
   696  * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
   697  */
   698 int rect_testHasIntersectionInside (void *arg)
   699 {
   700     SDL_Rect refRectA = { 0, 0, 32, 32 };
   701     SDL_Rect refRectB;
   702     SDL_Rect rectA;
   703     SDL_Rect rectB;
   704     SDL_bool intersection;
   705 
   706     // rectB fully contained in rectA
   707     refRectB.x = 0;
   708     refRectB.y = 0;
   709     refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
   710     refRectB.h = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
   711     rectA = refRectA;
   712     rectB = refRectB;
   713     intersection = SDL_HasIntersection(&rectA, &rectB);
   714     _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   715 
   716 	return TEST_COMPLETED;
   717 }
   718 
   719 /*!
   720  * \brief Tests SDL_HasIntersection() with B fully outside A
   721  *
   722  * \sa
   723  * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
   724  */
   725 int rect_testHasIntersectionOutside (void *arg)
   726 {
   727     SDL_Rect refRectA = { 0, 0, 32, 32 };
   728     SDL_Rect refRectB;
   729     SDL_Rect rectA;
   730     SDL_Rect rectB;
   731     SDL_bool intersection;
   732 
   733     // rectB fully outside of rectA
   734     refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
   735     refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
   736     refRectB.w = refRectA.w;
   737     refRectB.h = refRectA.h;
   738     rectA = refRectA;
   739     rectB = refRectB;
   740     intersection = SDL_HasIntersection(&rectA, &rectB);
   741     _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
   742 
   743 	return TEST_COMPLETED;
   744 }
   745 
   746 /*!
   747  * \brief Tests SDL_HasIntersection() with B partially intersecting A
   748  *
   749  * \sa
   750  * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
   751  */
   752 int rect_testHasIntersectionPartial (void *arg)
   753 {
   754     SDL_Rect refRectA = { 0, 0, 32, 32 };
   755     SDL_Rect refRectB;
   756     SDL_Rect rectA;
   757     SDL_Rect rectB;
   758     SDL_bool intersection;
   759 
   760     // rectB partially contained in rectA
   761     refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
   762     refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
   763     refRectB.w = refRectA.w;
   764     refRectB.h = refRectA.h;
   765     rectA = refRectA;
   766     rectB = refRectB;
   767     intersection = SDL_HasIntersection(&rectA, &rectB);
   768     _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   769 
   770     // rectB right edge
   771     refRectB.x = rectA.w - 1;
   772     refRectB.y = rectA.y;
   773     refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
   774     refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
   775     rectA = refRectA;
   776     rectB = refRectB;
   777     intersection = SDL_HasIntersection(&rectA, &rectB);
   778     _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   779 
   780     // rectB left edge
   781     refRectB.x = 1 - rectA.w;
   782     refRectB.y = rectA.y;
   783     refRectB.w = refRectA.w;
   784     refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
   785     rectA = refRectA;
   786     rectB = refRectB;
   787     intersection = SDL_HasIntersection(&rectA, &rectB);
   788     _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   789 
   790     // rectB bottom edge
   791     refRectB.x = rectA.x;
   792     refRectB.y = rectA.h - 1;
   793     refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
   794     refRectB.h = SDLTest_RandomIntegerInRange(1, refRectA.h - 1);
   795     rectA = refRectA;
   796     rectB = refRectB;
   797     intersection = SDL_HasIntersection(&rectA, &rectB);
   798     _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   799 
   800     // rectB top edge
   801     refRectB.x = rectA.x;
   802     refRectB.y = 1 - rectA.h;
   803     refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
   804     refRectB.h = rectA.h;
   805     rectA = refRectA;
   806     rectB = refRectB;
   807     intersection = SDL_HasIntersection(&rectA, &rectB);
   808     _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   809 
   810 	return TEST_COMPLETED;
   811 }
   812 
   813 /*!
   814  * \brief Tests SDL_HasIntersection() with 1x1 pixel sized rectangles
   815  *
   816  * \sa
   817  * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
   818  */
   819 int rect_testHasIntersectionPoint (void *arg)
   820 {
   821     SDL_Rect refRectA = { 0, 0, 1, 1 };
   822     SDL_Rect refRectB = { 0, 0, 1, 1 };
   823     SDL_Rect rectA;
   824     SDL_Rect rectB;
   825     SDL_bool intersection;
   826     int offsetX, offsetY;
   827 
   828     // intersecting pixels
   829     refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   830     refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   831     refRectB.x = refRectA.x;
   832     refRectB.y = refRectA.y;
   833     rectA = refRectA;
   834     rectB = refRectB;
   835     intersection = SDL_HasIntersection(&rectA, &rectB);
   836     _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
   837 
   838     // non-intersecting pixels cases
   839     for (offsetX = -1; offsetX <= 1; offsetX++) {
   840         for (offsetY = -1; offsetY <= 1; offsetY++) {
   841             if (offsetX != 0 || offsetY != 0) {
   842                 refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   843                 refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   844                 refRectB.x = refRectA.x;
   845                 refRectB.y = refRectA.y;    
   846                 refRectB.x += offsetX;
   847                 refRectB.y += offsetY;
   848                 rectA = refRectA;
   849                 rectB = refRectB;
   850                 intersection = SDL_HasIntersection(&rectA, &rectB);
   851                 _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
   852             }
   853         }
   854     }
   855 
   856 	return TEST_COMPLETED;
   857 }
   858 
   859 /*!
   860  * \brief Tests SDL_HasIntersection() with empty rectangles
   861  *
   862  * \sa
   863  * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
   864  */
   865 int rect_testHasIntersectionEmpty (void *arg)
   866 {
   867     SDL_Rect refRectA;
   868     SDL_Rect refRectB;
   869     SDL_Rect rectA;
   870     SDL_Rect rectB;
   871     SDL_bool intersection;
   872 
   873     // Rect A empty
   874     refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   875     refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   876     refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
   877     refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
   878     refRectB = refRectA;
   879     refRectA.w = 0;
   880     refRectA.h = 0;
   881     rectA = refRectA;
   882     rectB = refRectB;
   883     intersection = SDL_HasIntersection(&rectA, &rectB);
   884     _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
   885 
   886     // Rect B empty
   887     refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   888     refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   889     refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
   890     refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
   891     refRectB = refRectA;
   892     refRectB.w = 0;
   893     refRectB.h = 0;
   894     rectA = refRectA;
   895     rectB = refRectB;
   896     intersection = SDL_HasIntersection(&rectA, &rectB);
   897     _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
   898 
   899     // Rect A and B empty
   900     refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
   901     refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
   902     refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
   903     refRectA.h = SDLTest_RandomIntegerInRange(1, 100);
   904     refRectB = refRectA;
   905     refRectA.w = 0;
   906     refRectA.h = 0;
   907     refRectB.w = 0;
   908     refRectB.h = 0;
   909     rectA = refRectA;
   910     rectB = refRectB;
   911     intersection = SDL_HasIntersection(&rectA, &rectB);
   912     _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
   913 
   914 	return TEST_COMPLETED;
   915 }
   916 
   917 /*!
   918  * \brief Negative tests against SDL_HasIntersection() with invalid parameters
   919  *
   920  * \sa
   921  * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
   922  */
   923 int rect_testHasIntersectionParam(void *arg)
   924 {
   925     SDL_Rect rectA;
   926     SDL_Rect rectB;
   927     SDL_bool intersection;
   928 
   929     // invalid parameter combinations
   930     intersection = SDL_HasIntersection((SDL_Rect *)NULL, &rectB);
   931     SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL"); 
   932     intersection = SDL_HasIntersection(&rectA, (SDL_Rect *)NULL);
   933     SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 2st parameter is NULL"); 
   934     intersection = SDL_HasIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL);
   935     SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when all parameters are NULL");     
   936 
   937 	return TEST_COMPLETED;
   938 }
   939 
   940 /*!
   941  * \brief Test SDL_EnclosePoints() without clipping
   942  *
   943  * \sa
   944  * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
   945  */
   946 int rect_testEnclosePoints(void *arg)
   947 {
   948     const int numPoints = 16;
   949     SDL_Point refPoints[16];
   950     SDL_Point points[16];
   951     SDL_Rect result;
   952     SDL_bool anyEnclosed;
   953     SDL_bool anyEnclosedNoResult;
   954     SDL_bool expectedEnclosed = SDL_TRUE;
   955     int newx, newy;
   956     int minx = 0, maxx = 0, miny = 0, maxy = 0;
   957     int i;
   958 
   959     // Create input data, tracking result
   960     for (i=0; i<numPoints; i++) {
   961         newx = SDLTest_RandomIntegerInRange(-1024, 1024);
   962         newy = SDLTest_RandomIntegerInRange(-1024, 1024);
   963         refPoints[i].x = newx;
   964         refPoints[i].y = newy;
   965         points[i].x = newx;
   966         points[i].y = newy;
   967         if (i==0) {
   968             minx = newx;
   969             maxx = newx;
   970             miny = newy;
   971             maxy = newy;
   972         } else {
   973             if (newx < minx) minx = newx;
   974             if (newx > maxx) maxx = newx;
   975             if (newy < miny) miny = newy;
   976             if (newy > maxy) maxy = newy;
   977         }
   978     }
   979     
   980     // Call function and validate - special case: no result requested
   981     anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
   982     SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult, 
   983         "Check expected return value %s, got %s", 
   984         (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
   985 		(anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
   986     for (i=0; i<numPoints; i++) {
   987         SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
   988             "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 
   989             i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
   990     }
   991 
   992     // Call function and validate
   993     anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
   994     SDLTest_AssertCheck(expectedEnclosed==anyEnclosed, 
   995         "Check return value %s, got %s", 
   996         (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
   997 		(anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
   998     for (i=0; i<numPoints; i++) {
   999         SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
  1000             "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 
  1001             i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
  1002     }
  1003     SDLTest_AssertCheck(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
  1004         "Resulting enclosing rectangle incorrect: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
  1005         minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
  1006 
  1007 	return TEST_COMPLETED;
  1008 }
  1009 
  1010 /*!
  1011  * \brief Test SDL_EnclosePoints() with repeated input points
  1012  *
  1013  * \sa
  1014  * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
  1015  */
  1016 int rect_testEnclosePointsRepeatedInput(void *arg)
  1017 {
  1018     const int numPoints = 8;
  1019     const int halfPoints = 4;
  1020     SDL_Point refPoints[8];
  1021     SDL_Point points[8];
  1022     SDL_Rect result;
  1023     SDL_bool anyEnclosed;
  1024     SDL_bool anyEnclosedNoResult;
  1025     SDL_bool expectedEnclosed = SDL_TRUE;
  1026     int newx, newy;
  1027     int minx = 0, maxx = 0, miny = 0, maxy = 0;
  1028     int i;
  1029 
  1030     // Create input data, tracking result
  1031     for (i=0; i<numPoints; i++) {
  1032         if (i < halfPoints) {
  1033             newx = SDLTest_RandomIntegerInRange(-1024, 1024);
  1034             newy = SDLTest_RandomIntegerInRange(-1024, 1024);
  1035         } else {
  1036             newx = refPoints[i-halfPoints].x;
  1037             newy = refPoints[i-halfPoints].y;
  1038         }
  1039         refPoints[i].x = newx;
  1040         refPoints[i].y = newy;
  1041         points[i].x = newx;
  1042         points[i].y = newy;
  1043         if (i==0) {
  1044             minx = newx;
  1045             maxx = newx;
  1046             miny = newy;
  1047             maxy = newy;
  1048         } else {
  1049             if (newx < minx) minx = newx;
  1050             if (newx > maxx) maxx = newx;
  1051             if (newy < miny) miny = newy;
  1052             if (newy > maxy) maxy = newy;
  1053         }
  1054     }
  1055 
  1056     // Call function and validate - special case: no result requested
  1057     anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
  1058     SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult, 
  1059         "Check return value %s, got %s", 
  1060         (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
  1061 		(anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
  1062     for (i=0; i<numPoints; i++) {
  1063         SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
  1064             "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 
  1065             i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
  1066     }
  1067     
  1068     // Call function and validate
  1069     anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
  1070     SDLTest_AssertCheck(expectedEnclosed==anyEnclosed, 
  1071         "Check return value %s, got %s", 
  1072         (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
  1073 		(anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
  1074     for (i=0; i<numPoints; i++) {
  1075         SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
  1076             "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 
  1077             i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
  1078     }
  1079     SDLTest_AssertCheck(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
  1080         "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
  1081         minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
  1082 
  1083 	return TEST_COMPLETED;
  1084 }
  1085 
  1086 /*!
  1087  * \brief Test SDL_EnclosePoints() with clipping
  1088  *
  1089  * \sa
  1090  * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
  1091  */
  1092 int rect_testEnclosePointsWithClipping(void *arg)
  1093 {
  1094     const int numPoints = 16;
  1095     SDL_Point refPoints[16];
  1096     SDL_Point points[16];
  1097     SDL_Rect refClip;
  1098     SDL_Rect clip;
  1099     SDL_Rect result;
  1100     SDL_bool anyEnclosed;
  1101     SDL_bool anyEnclosedNoResult;
  1102     SDL_bool expectedEnclosed = SDL_FALSE;
  1103     int newx, newy;
  1104     int minx = 0, maxx = 0, miny = 0, maxy = 0;
  1105     int i;
  1106 
  1107     // Setup clipping rectangle
  1108     refClip.x = SDLTest_RandomIntegerInRange(-1024, 1024);
  1109     refClip.y = SDLTest_RandomIntegerInRange(-1024, 1024);
  1110     refClip.w = SDLTest_RandomIntegerInRange(1, 1024);
  1111     refClip.h = SDLTest_RandomIntegerInRange(1, 1024);
  1112 
  1113     // Create input data, tracking result
  1114     for (i=0; i<numPoints; i++) {
  1115         newx = SDLTest_RandomIntegerInRange(-1024, 1024);
  1116         newy = SDLTest_RandomIntegerInRange(-1024, 1024);
  1117         refPoints[i].x = newx;
  1118         refPoints[i].y = newy;
  1119         points[i].x = newx;
  1120         points[i].y = newy;
  1121         if ((newx>=refClip.x) && (newx<(refClip.x + refClip.w)) &&
  1122             (newy>=refClip.y) && (newy<(refClip.y + refClip.h))) {
  1123             if (expectedEnclosed==SDL_FALSE) {
  1124                 minx = newx;
  1125                 maxx = newx;
  1126                 miny = newy;
  1127                 maxy = newy;
  1128             } else {
  1129                 if (newx < minx) minx = newx;
  1130                 if (newx > maxx) maxx = newx;
  1131                 if (newy < miny) miny = newy;
  1132                 if (newy > maxy) maxy = newy;
  1133             }
  1134             expectedEnclosed = SDL_TRUE;
  1135         }
  1136     }
  1137 
  1138     // Call function and validate - special case: no result requested
  1139     clip = refClip;
  1140     anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, (SDL_Rect *)NULL);
  1141     SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult, 
  1142         "Expected return value %s, got %s", 
  1143         (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
  1144 		(anyEnclosedNoResult==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
  1145     for (i=0; i<numPoints; i++) {
  1146         SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
  1147             "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 
  1148             i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
  1149     }
  1150     SDLTest_AssertCheck(refClip.x==clip.x && refClip.y==clip.y && refClip.w==clip.w && refClip.h==clip.h,
  1151         "Check that source clipping rectangle was not modified");
  1152     
  1153     // Call function and validate
  1154     anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, &result);
  1155     SDLTest_AssertCheck(expectedEnclosed==anyEnclosed, 
  1156         "Check return value %s, got %s", 
  1157         (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
  1158 		(anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
  1159     for (i=0; i<numPoints; i++) {
  1160         SDLTest_AssertCheck(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
  1161             "Check that source point %i was not modified: expected (%i,%i) actual (%i,%i)", 
  1162             i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
  1163     }
  1164     SDLTest_AssertCheck(refClip.x==clip.x && refClip.y==clip.y && refClip.w==clip.w && refClip.h==clip.h,
  1165         "Check that source clipping rectangle was not modified");
  1166     if (expectedEnclosed==SDL_TRUE) {
  1167         SDLTest_AssertCheck(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
  1168             "Check resulting enclosing rectangle: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
  1169             minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
  1170     }    
  1171     
  1172     /* Empty clipping rectangle */
  1173     clip.w = 0;
  1174     clip.h = 0;
  1175     expectedEnclosed = SDL_FALSE;
  1176     anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, &result);
  1177     SDLTest_AssertCheck(expectedEnclosed==anyEnclosed, 
  1178         "Check return value %s, got %s", 
  1179         (expectedEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE", 
  1180 		(anyEnclosed==SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");    
  1181 
  1182 	return TEST_COMPLETED;
  1183 }
  1184 
  1185 /*!
  1186  * \brief Negative tests against SDL_EnclosePoints() with invalid parameters
  1187  *
  1188  * \sa
  1189  * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
  1190  */
  1191 int rect_testEnclosePointsParam(void *arg)
  1192 {
  1193     SDL_Point points[1];
  1194     int count;
  1195     SDL_Rect clip;
  1196     SDL_Rect result;
  1197     SDL_bool anyEnclosed;
  1198 
  1199     // invalid parameter combinations
  1200     anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 1, (const SDL_Rect *)&clip, &result);
  1201     SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL"); 
  1202     anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, 0, (const SDL_Rect *)&clip, &result);
  1203     SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 2nd parameter is 0");
  1204     count = SDLTest_RandomIntegerInRange(-100, -1);
  1205     anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, count, (const SDL_Rect *)&clip, &result);
  1206     SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 2nd parameter is %i (negative)", count); 
  1207     anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 0, (const SDL_Rect *)&clip, &result);
  1208     SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL and 2nd parameter was 0"); 
  1209 
  1210 	return TEST_COMPLETED;
  1211 }
  1212 
  1213 /*!
  1214  * \brief Tests SDL_UnionRect() where rect B is outside rect A
  1215  *
  1216  * \sa
  1217  * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
  1218  */
  1219 int rect_testUnionRectOutside(void *arg)
  1220 {
  1221     SDL_Rect refRectA, refRectB;
  1222     SDL_Rect rectA, rectB;
  1223     SDL_Rect expectedResult;
  1224     SDL_Rect result;
  1225     int minx, maxx, miny, maxy;
  1226     int dx, dy;
  1227     
  1228     /* Union 1x1 outside */
  1229     for (dx = -1; dx < 2; dx++) {     
  1230         for (dy = -1; dy < 2; dy++) {
  1231             if ((dx != 0) || (dy != 0)) {
  1232                 refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1233                 refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1234                 refRectA.w=1;
  1235                 refRectA.h=1;
  1236                 refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024) + dx*2048;
  1237                 refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024) + dx*2048;
  1238                 refRectB.w=1;
  1239                 refRectB.h=1;
  1240                 minx = (refRectA.x<refRectB.x) ? refRectA.x : refRectB.x;
  1241                 maxx = (refRectA.x>refRectB.x) ? refRectA.x : refRectB.x;
  1242                 miny = (refRectA.y<refRectB.y) ? refRectA.y : refRectB.y;
  1243                 maxy = (refRectA.y>refRectB.y) ? refRectA.y : refRectB.y;                
  1244                 expectedResult.x = minx;
  1245                 expectedResult.y = miny;
  1246                 expectedResult.w = maxx - minx + 1;
  1247                 expectedResult.h = maxy - miny + 1;
  1248                 rectA = refRectA;
  1249                 rectB = refRectB;
  1250                 SDL_UnionRect(&rectA, &rectB, &result);
  1251                 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  1252             }
  1253         }
  1254     }
  1255 
  1256     /* Union outside overlap */
  1257     for (dx = -1; dx < 2; dx++) {     
  1258         for (dy = -1; dy < 2; dy++) {
  1259             if ((dx != 0) || (dy != 0)) {
  1260                 refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1261                 refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1262                 refRectA.w=SDLTest_RandomIntegerInRange(256, 512);
  1263                 refRectA.h=SDLTest_RandomIntegerInRange(256, 512);
  1264                 refRectB.x=refRectA.x + 1 + dx*2;
  1265                 refRectB.y=refRectA.y + 1 + dy*2;
  1266                 refRectB.w=refRectA.w - 2;
  1267                 refRectB.h=refRectA.h - 2;
  1268                 expectedResult = refRectA;
  1269                 if (dx == -1) expectedResult.x--;
  1270                 if (dy == -1) expectedResult.y--;
  1271                 if ((dx == 1) || (dx == -1)) expectedResult.w++;
  1272                 if ((dy == 1) || (dy == -1)) expectedResult.h++;
  1273                 rectA = refRectA;
  1274                 rectB = refRectB;
  1275                 SDL_UnionRect(&rectA, &rectB, &result);
  1276                 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  1277             }
  1278         }
  1279     }
  1280 
  1281 	return TEST_COMPLETED;
  1282 }
  1283 
  1284 /*!
  1285  * \brief Tests SDL_UnionRect() where rect A or rect B are empty
  1286  *
  1287  * \sa
  1288  * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
  1289  */
  1290 int rect_testUnionRectEmpty(void *arg)
  1291 {
  1292     SDL_Rect refRectA, refRectB;
  1293     SDL_Rect rectA, rectB;
  1294     SDL_Rect expectedResult;
  1295     SDL_Rect result;
  1296 
  1297     /* A empty */    
  1298     refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1299     refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1300     refRectA.w=0;
  1301     refRectA.h=0;
  1302     refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1303     refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1304     refRectB.w=SDLTest_RandomIntegerInRange(1, 1024);
  1305     refRectB.h=SDLTest_RandomIntegerInRange(1, 1024);
  1306     expectedResult = refRectB;
  1307     rectA = refRectA;
  1308     rectB = refRectB;
  1309     SDL_UnionRect(&rectA, &rectB, &result);
  1310     _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  1311     
  1312     /* B empty */    
  1313     refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1314     refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1315     refRectA.w=SDLTest_RandomIntegerInRange(1, 1024);
  1316     refRectA.h=SDLTest_RandomIntegerInRange(1, 1024);
  1317     refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1318     refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1319     refRectB.w=0;
  1320     refRectB.h=0;
  1321     expectedResult = refRectA;
  1322     rectA = refRectA;
  1323     rectB = refRectB;
  1324     SDL_UnionRect(&rectA, &rectB, &result);
  1325     _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  1326 
  1327     /* A and B empty */    
  1328     refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1329     refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1330     refRectA.w=0;
  1331     refRectA.h=0;
  1332     refRectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1333     refRectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1334     refRectB.w=0;
  1335     refRectB.h=0;
  1336     result.x=0;
  1337     result.y=0;
  1338     result.w=0;
  1339     result.h=0;
  1340     expectedResult = result;
  1341     rectA = refRectA;
  1342     rectB = refRectB;
  1343     SDL_UnionRect(&rectA, &rectB, &result);
  1344     _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  1345 
  1346 	return TEST_COMPLETED;
  1347 }
  1348 
  1349 /*!
  1350  * \brief Tests SDL_UnionRect() where rect B is inside rect A
  1351  *
  1352  * \sa
  1353  * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
  1354  */
  1355 int rect_testUnionRectInside(void *arg)
  1356 {
  1357     SDL_Rect refRectA, refRectB;
  1358     SDL_Rect rectA, rectB;
  1359     SDL_Rect expectedResult;
  1360     SDL_Rect result;
  1361     int dx, dy;
  1362     
  1363     /* Union 1x1 with itself */
  1364     refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1365     refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1366     refRectA.w=1;
  1367     refRectA.h=1;
  1368     expectedResult = refRectA;
  1369     rectA = refRectA;
  1370     SDL_UnionRect(&rectA, &rectA, &result);
  1371     _validateUnionRectResults(&rectA, &rectA, &refRectA, &refRectA, &result, &expectedResult);
  1372 
  1373     /* Union 1x1 somewhere inside */
  1374     refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1375     refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1376     refRectA.w=SDLTest_RandomIntegerInRange(256, 1024);
  1377     refRectA.h=SDLTest_RandomIntegerInRange(256, 1024);
  1378     refRectB.x=refRectA.x + 1 + SDLTest_RandomIntegerInRange(1, refRectA.w - 2);
  1379     refRectB.y=refRectA.y + 1 + SDLTest_RandomIntegerInRange(1, refRectA.h - 2);
  1380     refRectB.w=1;
  1381     refRectB.h=1;
  1382     expectedResult = refRectA;
  1383     rectA = refRectA;
  1384     rectB = refRectB;
  1385     SDL_UnionRect(&rectA, &rectB, &result);
  1386     _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  1387 
  1388     /* Union inside with edges modified */
  1389     for (dx = -1; dx < 2; dx++) {     
  1390         for (dy = -1; dy < 2; dy++) {
  1391             if ((dx != 0) || (dy != 0)) {
  1392                 refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1393                 refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1394                 refRectA.w=SDLTest_RandomIntegerInRange(256, 1024);
  1395                 refRectA.h=SDLTest_RandomIntegerInRange(256, 1024);
  1396                 refRectB = refRectA;
  1397                 if (dx == -1) refRectB.x++;
  1398                 if ((dx == 1) || (dx == -1)) refRectB.w--;
  1399                 if (dy == -1) refRectB.y++;
  1400                 if ((dy == 1) || (dy == -1)) refRectB.h--;                
  1401                 expectedResult = refRectA;
  1402                 rectA = refRectA;
  1403                 rectB = refRectB;
  1404                 SDL_UnionRect(&rectA, &rectB, &result);
  1405                 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
  1406             }
  1407         }
  1408     }
  1409 
  1410 	return TEST_COMPLETED;
  1411 }
  1412 
  1413 /*!
  1414  * \brief Negative tests against SDL_UnionRect() with invalid parameters
  1415  *
  1416  * \sa
  1417  * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
  1418  */
  1419 int rect_testUnionRectParam(void *arg)
  1420 {
  1421     SDL_Rect rectA, rectB;
  1422     SDL_Rect result;
  1423 
  1424     // invalid parameter combinations
  1425     SDL_UnionRect((SDL_Rect *)NULL, &rectB, &result);
  1426     SDLTest_AssertPass("Check that function returns when 1st parameter is NULL"); 
  1427     SDL_UnionRect(&rectA, (SDL_Rect *)NULL, &result);
  1428     SDLTest_AssertPass("Check that function returns  when 2nd parameter is NULL"); 
  1429     SDL_UnionRect(&rectA, &rectB, (SDL_Rect *)NULL);
  1430     SDLTest_AssertPass("Check that function returns  when 3rd parameter is NULL"); 
  1431     SDL_UnionRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
  1432     SDLTest_AssertPass("Check that function returns  when 1st and 3rd parameter are NULL"); 
  1433     SDL_UnionRect(&rectA, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
  1434     SDLTest_AssertPass("Check that function returns  when 2nd and 3rd parameter are NULL"); 
  1435     SDL_UnionRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
  1436     SDLTest_AssertPass("Check that function returns  when all parameters are NULL"); 
  1437 
  1438 	return TEST_COMPLETED;
  1439 }
  1440 
  1441 /*!
  1442  * \brief Tests SDL_RectEmpty() with various inputs
  1443  *
  1444  * \sa
  1445  * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
  1446  */
  1447 int rect_testRectEmpty(void *arg)
  1448 {
  1449     SDL_Rect refRect;
  1450     SDL_Rect rect;
  1451     SDL_bool expectedResult;
  1452     SDL_bool result;
  1453     int w, h;
  1454 
  1455     // Non-empty case
  1456     refRect.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1457     refRect.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1458     refRect.w=SDLTest_RandomIntegerInRange(256, 1024);
  1459     refRect.h=SDLTest_RandomIntegerInRange(256, 1024);
  1460     expectedResult = SDL_FALSE;
  1461     rect = refRect;
  1462     result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)&rect);
  1463     _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
  1464     
  1465     // Empty case
  1466     for (w=-1; w<2; w++) {
  1467         for (h=-1; h<2; h++) {
  1468             if ((w != 1) || (h != 1)) {
  1469                 refRect.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1470                 refRect.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1471                 refRect.w=w;
  1472                 refRect.h=h;
  1473                 expectedResult = SDL_TRUE;
  1474                 rect = refRect;
  1475                 result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)&rect);
  1476                 _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
  1477             }
  1478         }
  1479     }
  1480 
  1481 	return TEST_COMPLETED;
  1482 }
  1483 
  1484 /*!
  1485  * \brief Negative tests against SDL_RectEmpty() with invalid parameters
  1486  *
  1487  * \sa
  1488  * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
  1489  */
  1490 int rect_testRectEmptyParam(void *arg)
  1491 {
  1492     SDL_bool result;
  1493 
  1494     // invalid parameter combinations
  1495     result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)NULL);
  1496     SDLTest_AssertCheck(result == SDL_TRUE, "Check that function returns TRUE when 1st parameter is NULL"); 
  1497 
  1498 	return TEST_COMPLETED;
  1499 }
  1500 
  1501 /*!
  1502  * \brief Tests SDL_RectEquals() with various inputs
  1503  *
  1504  * \sa
  1505  * http://wiki.libsdl.org/moin.cgi/SDL_RectEquals
  1506  */
  1507 int rect_testRectEquals(void *arg)
  1508 {
  1509     SDL_Rect refRectA;
  1510     SDL_Rect refRectB;
  1511     SDL_Rect rectA;
  1512     SDL_Rect rectB;
  1513     SDL_bool expectedResult;
  1514     SDL_bool result;
  1515 
  1516     // Equals
  1517     refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1518     refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1519     refRectA.w=SDLTest_RandomIntegerInRange(1, 1024);
  1520     refRectA.h=SDLTest_RandomIntegerInRange(1, 1024);
  1521     refRectB = refRectA;    
  1522     expectedResult = SDL_TRUE;
  1523     rectA = refRectA;
  1524     rectB = refRectB;
  1525     result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)&rectA, (const SDL_Rect *)&rectB);
  1526     _validateRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
  1527 
  1528 	return TEST_COMPLETED;
  1529 }
  1530 
  1531 /*!
  1532  * \brief Negative tests against SDL_RectEquals() with invalid parameters
  1533  *
  1534  * \sa
  1535  * http://wiki.libsdl.org/moin.cgi/SDL_RectEquals
  1536  */
  1537 int rect_testRectEqualsParam(void *arg)
  1538 {
  1539     SDL_Rect rectA;
  1540     SDL_Rect rectB;
  1541     SDL_bool result;
  1542 
  1543     /* data setup */
  1544     rectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1545     rectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1546     rectA.w=SDLTest_RandomIntegerInRange(1, 1024);
  1547     rectA.h=SDLTest_RandomIntegerInRange(1, 1024);
  1548     rectB.x=SDLTest_RandomIntegerInRange(-1024, 1024);
  1549     rectB.y=SDLTest_RandomIntegerInRange(-1024, 1024);
  1550     rectB.w=SDLTest_RandomIntegerInRange(1, 1024);
  1551     rectB.h=SDLTest_RandomIntegerInRange(1, 1024);
  1552 
  1553     // invalid parameter combinations
  1554     result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)NULL, (const SDL_Rect *)&rectB);
  1555     SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL"); 
  1556     result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)&rectA, (const SDL_Rect *)NULL);
  1557     SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL"); 
  1558     result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)NULL, (const SDL_Rect *)NULL);
  1559     SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL"); 
  1560 
  1561 	return TEST_COMPLETED;
  1562 }
  1563 
  1564 /* ================= Test References ================== */
  1565 
  1566 /* Rect test cases */
  1567 
  1568 /* SDL_IntersectRectAndLine */
  1569 static const SDLTest_TestCaseReference rectTest1 =
  1570 		{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLine,"rect_testIntersectRectAndLine",  "Tests SDL_IntersectRectAndLine clipping cases", TEST_ENABLED };
  1571 
  1572 static const SDLTest_TestCaseReference rectTest2 =
  1573 		{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLineInside, "rect_testIntersectRectAndLineInside", "Tests SDL_IntersectRectAndLine with line fully contained in rect", TEST_ENABLED };
  1574 
  1575 static const SDLTest_TestCaseReference rectTest3 =
  1576 		{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLineOutside, "rect_testIntersectRectAndLineOutside", "Tests SDL_IntersectRectAndLine with line fully outside of rect", TEST_ENABLED };
  1577 
  1578 static const SDLTest_TestCaseReference rectTest4 =
  1579 		{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLineEmpty, "rect_testIntersectRectAndLineEmpty", "Tests SDL_IntersectRectAndLine with empty rectangle ", TEST_ENABLED };
  1580 
  1581 static const SDLTest_TestCaseReference rectTest5 =
  1582 		{ (SDLTest_TestCaseFp)rect_testIntersectRectAndLineParam, "rect_testIntersectRectAndLineParam", "Negative tests against SDL_IntersectRectAndLine with invalid parameters", TEST_ENABLED };
  1583 
  1584 /* SDL_IntersectRect */
  1585 static const SDLTest_TestCaseReference rectTest6 =
  1586 		{ (SDLTest_TestCaseFp)rect_testIntersectRectInside, "rect_testIntersectRectInside", "Tests SDL_IntersectRect with B fully contained in A", TEST_ENABLED };
  1587 
  1588 static const SDLTest_TestCaseReference rectTest7 =
  1589 		{ (SDLTest_TestCaseFp)rect_testIntersectRectOutside, "rect_testIntersectRectOutside", "Tests SDL_IntersectRect with B fully outside of A", TEST_ENABLED };
  1590 
  1591 static const SDLTest_TestCaseReference rectTest8 =
  1592 		{ (SDLTest_TestCaseFp)rect_testIntersectRectPartial, "rect_testIntersectRectPartial", "Tests SDL_IntersectRect with B partially intersecting A", TEST_ENABLED };
  1593 
  1594 static const SDLTest_TestCaseReference rectTest9 =
  1595 		{ (SDLTest_TestCaseFp)rect_testIntersectRectPoint, "rect_testIntersectRectPoint", "Tests SDL_IntersectRect with 1x1 sized rectangles", TEST_ENABLED };
  1596 
  1597 static const SDLTest_TestCaseReference rectTest10 =
  1598 		{ (SDLTest_TestCaseFp)rect_testIntersectRectEmpty, "rect_testIntersectRectEmpty", "Tests SDL_IntersectRect with empty rectangles", TEST_ENABLED };
  1599 
  1600 static const SDLTest_TestCaseReference rectTest11 =
  1601 		{ (SDLTest_TestCaseFp)rect_testIntersectRectParam, "rect_testIntersectRectParam", "Negative tests against SDL_IntersectRect with invalid parameters", TEST_ENABLED };
  1602 
  1603 /* SDL_HasIntersection */
  1604 static const SDLTest_TestCaseReference rectTest12 =
  1605 		{ (SDLTest_TestCaseFp)rect_testHasIntersectionInside, "rect_testHasIntersectionInside", "Tests SDL_HasIntersection with B fully contained in A", TEST_ENABLED };
  1606 
  1607 static const SDLTest_TestCaseReference rectTest13 =
  1608 		{ (SDLTest_TestCaseFp)rect_testHasIntersectionOutside, "rect_testHasIntersectionOutside", "Tests SDL_HasIntersection with B fully outside of A", TEST_ENABLED };
  1609 
  1610 static const SDLTest_TestCaseReference rectTest14 =
  1611 		{ (SDLTest_TestCaseFp)rect_testHasIntersectionPartial,"rect_testHasIntersectionPartial",  "Tests SDL_HasIntersection with B partially intersecting A", TEST_ENABLED };
  1612 
  1613 static const SDLTest_TestCaseReference rectTest15 =
  1614 		{ (SDLTest_TestCaseFp)rect_testHasIntersectionPoint, "rect_testHasIntersectionPoint", "Tests SDL_HasIntersection with 1x1 sized rectangles", TEST_ENABLED };
  1615 
  1616 static const SDLTest_TestCaseReference rectTest16 =
  1617 		{ (SDLTest_TestCaseFp)rect_testHasIntersectionEmpty, "rect_testHasIntersectionEmpty", "Tests SDL_HasIntersection with empty rectangles", TEST_ENABLED };
  1618 
  1619 static const SDLTest_TestCaseReference rectTest17 =
  1620 		{ (SDLTest_TestCaseFp)rect_testHasIntersectionParam, "rect_testHasIntersectionParam", "Negative tests against SDL_HasIntersection with invalid parameters", TEST_ENABLED };
  1621 
  1622 /* SDL_EnclosePoints */
  1623 static const SDLTest_TestCaseReference rectTest18 =
  1624 		{ (SDLTest_TestCaseFp)rect_testEnclosePoints, "rect_testEnclosePoints", "Tests SDL_EnclosePoints without clipping", TEST_ENABLED };
  1625 
  1626 static const SDLTest_TestCaseReference rectTest19 =
  1627 		{ (SDLTest_TestCaseFp)rect_testEnclosePointsWithClipping, "rect_testEnclosePointsWithClipping", "Tests SDL_EnclosePoints with clipping", TEST_ENABLED };
  1628 
  1629 static const SDLTest_TestCaseReference rectTest20 =
  1630 		{ (SDLTest_TestCaseFp)rect_testEnclosePointsRepeatedInput, "rect_testEnclosePointsRepeatedInput", "Tests SDL_EnclosePoints with repeated input", TEST_ENABLED };
  1631 
  1632 static const SDLTest_TestCaseReference rectTest21 =
  1633 		{ (SDLTest_TestCaseFp)rect_testEnclosePointsParam, "rect_testEnclosePointsParam", "Negative tests against SDL_EnclosePoints with invalid parameters", TEST_ENABLED };
  1634 
  1635 /* SDL_UnionRect */
  1636 static const SDLTest_TestCaseReference rectTest22 =
  1637 		{ (SDLTest_TestCaseFp)rect_testUnionRectInside, "rect_testUnionRectInside", "Tests SDL_UnionRect where rect B is inside rect A", TEST_ENABLED };
  1638 
  1639 static const SDLTest_TestCaseReference rectTest23 =
  1640 		{ (SDLTest_TestCaseFp)rect_testUnionRectOutside, "rect_testUnionRectOutside", "Tests SDL_UnionRect where rect B is outside rect A", TEST_ENABLED };
  1641 
  1642 static const SDLTest_TestCaseReference rectTest24 =
  1643 		{ (SDLTest_TestCaseFp)rect_testUnionRectEmpty, "rect_testUnionRectEmpty", "Tests SDL_UnionRect where rect A or rect B are empty", TEST_ENABLED };
  1644 
  1645 static const SDLTest_TestCaseReference rectTest25 =
  1646 		{ (SDLTest_TestCaseFp)rect_testUnionRectParam, "rect_testUnionRectParam", "Negative tests against SDL_UnionRect with invalid parameters", TEST_ENABLED };
  1647 
  1648 /* SDL_RectEmpty */
  1649 static const SDLTest_TestCaseReference rectTest26 =
  1650 		{ (SDLTest_TestCaseFp)rect_testRectEmpty, "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED };
  1651 
  1652 static const SDLTest_TestCaseReference rectTest27 =
  1653 		{ (SDLTest_TestCaseFp)rect_testRectEmptyParam, "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED };
  1654 
  1655 /* SDL_RectEquals */
  1656 
  1657 static const SDLTest_TestCaseReference rectTest28 =
  1658 		{ (SDLTest_TestCaseFp)rect_testRectEquals, "rect_testRectEquals", "Tests SDL_RectEquals with various inputs", TEST_ENABLED };
  1659 
  1660 static const SDLTest_TestCaseReference rectTest29 =
  1661 		{ (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED };
  1662 
  1663 
  1664 /*!
  1665  * \brief Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
  1666  *
  1667  * \sa
  1668  * http://wiki.libsdl.org/moin.cgi/CategoryRect
  1669  */
  1670 static const SDLTest_TestCaseReference *rectTests[] =  {
  1671 	&rectTest1, &rectTest2, &rectTest3, &rectTest4, &rectTest5, &rectTest6, &rectTest7, &rectTest8, &rectTest9, &rectTest10, &rectTest11, &rectTest12, &rectTest13, &rectTest14, 
  1672 	&rectTest15, &rectTest16, &rectTest17, &rectTest18, &rectTest19, &rectTest20, &rectTest21, &rectTest22, &rectTest23, &rectTest24, &rectTest25, &rectTest26, &rectTest27,
  1673 	&rectTest28, &rectTest29, NULL
  1674 };
  1675 
  1676 
  1677 /* Rect test suite (global) */
  1678 SDLTest_TestSuiteReference rectTestSuite = {
  1679 	"Rect",
  1680 	NULL,
  1681 	rectTests,
  1682 	NULL
  1683 };