Fix bug 1789: SDL_IntersectRect intersection with empty rect does not set result to empty; add test coverage to Rect suite
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Wed, 17 Apr 2013 08:09:11 -0700
changeset 70740545811b3543
parent 7073 873715d91f83
child 7075 f4a3c5a68119
Fix bug 1789: SDL_IntersectRect intersection with empty rect does not set result to empty; add test coverage to Rect suite
src/video/SDL_rect.c
test/testautomation_rect.c
     1.1 --- a/src/video/SDL_rect.c	Wed Apr 17 07:35:30 2013 -0700
     1.2 +++ b/src/video/SDL_rect.c	Wed Apr 17 08:09:11 2013 -0700
     1.3 @@ -29,8 +29,13 @@
     1.4  {
     1.5      int Amin, Amax, Bmin, Bmax;
     1.6  
     1.7 -    if (!A || !B) {
     1.8 -        // TODO error message
     1.9 +    if (!A) {
    1.10 +        SDL_InvalidParamError("A");
    1.11 +        return SDL_FALSE;
    1.12 +    }
    1.13 +
    1.14 +    if (!B) {
    1.15 +        SDL_InvalidParamError("B");
    1.16          return SDL_FALSE;
    1.17      }
    1.18  
    1.19 @@ -71,13 +76,25 @@
    1.20  {
    1.21      int Amin, Amax, Bmin, Bmax;
    1.22  
    1.23 -    if (!A || !B || !result) {
    1.24 -        // TODO error message
    1.25 +    if (!A) {
    1.26 +        SDL_InvalidParamError("A");
    1.27 +        return SDL_FALSE;
    1.28 +    }
    1.29 +
    1.30 +    if (!B) {
    1.31 +        SDL_InvalidParamError("B");
    1.32 +        return SDL_FALSE;
    1.33 +    }
    1.34 +    
    1.35 +    if (!result) {
    1.36 +        SDL_InvalidParamError("result");
    1.37          return SDL_FALSE;
    1.38      }
    1.39  
    1.40      /* Special cases for empty rects */
    1.41      if (SDL_RectEmpty(A) || SDL_RectEmpty(B)) {
    1.42 +        result->w = 0;
    1.43 +        result->h = 0;
    1.44          return SDL_FALSE;
    1.45      }
    1.46      
    1.47 @@ -113,7 +130,18 @@
    1.48  {
    1.49      int Amin, Amax, Bmin, Bmax;
    1.50  
    1.51 -    if (!A || !B || !result) {
    1.52 +    if (!A) {
    1.53 +        SDL_InvalidParamError("A");
    1.54 +        return;
    1.55 +    }
    1.56 +
    1.57 +    if (!B) {
    1.58 +        SDL_InvalidParamError("B");
    1.59 +        return;
    1.60 +    }
    1.61 +    
    1.62 +    if (!result) {
    1.63 +        SDL_InvalidParamError("result");
    1.64          return;
    1.65      }
    1.66  
    1.67 @@ -171,12 +199,12 @@
    1.68      int x, y, i;
    1.69  
    1.70      if (!points) {
    1.71 -        /* TODO error message */
    1.72 +        SDL_InvalidParamError("points");
    1.73          return SDL_FALSE;
    1.74      }
    1.75  
    1.76      if (count < 1) {
    1.77 -        /* TODO error message */
    1.78 +        SDL_InvalidParamError("count");
    1.79          return SDL_FALSE;
    1.80      }
    1.81  
    1.82 @@ -298,8 +326,28 @@
    1.83      int recty2;
    1.84      int outcode1, outcode2;
    1.85  
    1.86 -    if (!rect || !X1 || !Y1 || !X2 || !Y2) {
    1.87 -        // TODO error message
    1.88 +    if (!rect) {
    1.89 +        SDL_InvalidParamError("rect");
    1.90 +        return SDL_FALSE;
    1.91 +    }
    1.92 +    
    1.93 +    if (!X1) {
    1.94 +        SDL_InvalidParamError("X1");
    1.95 +        return SDL_FALSE;
    1.96 +    }
    1.97 +    
    1.98 +    if (!Y1) {
    1.99 +        SDL_InvalidParamError("Y1");
   1.100 +        return SDL_FALSE;
   1.101 +    }
   1.102 +    
   1.103 +    if (!X2) {
   1.104 +        SDL_InvalidParamError("X2");
   1.105 +        return SDL_FALSE;
   1.106 +    }
   1.107 +    
   1.108 +    if (!Y2) {
   1.109 +        SDL_InvalidParamError("Y2");
   1.110          return SDL_FALSE;
   1.111      }
   1.112  
   1.113 @@ -418,18 +466,28 @@
   1.114      int span_y1, span_y2;
   1.115      int rect_y1, rect_y2;
   1.116  
   1.117 -    if (width < 1 || height < 1) {
   1.118 -        // TODO error message
   1.119 +    if (width < 1) {
   1.120 +        SDL_InvalidParamError("width");
   1.121          return SDL_FALSE;
   1.122      }
   1.123  
   1.124 -    if (!rects || !span) {
   1.125 -        // TODO error message
   1.126 +    if (height < 1) {
   1.127 +        SDL_InvalidParamError("height");
   1.128 +        return SDL_FALSE;
   1.129 +    }
   1.130 +
   1.131 +    if (!rects) {
   1.132 +        SDL_InvalidParamError("rects");
   1.133 +        return SDL_FALSE;
   1.134 +    }
   1.135 +
   1.136 +    if (!span) {
   1.137 +        SDL_InvalidParamError("span");
   1.138          return SDL_FALSE;
   1.139      }
   1.140  
   1.141      if (numrects < 1) {
   1.142 -        // TODO error message
   1.143 +        SDL_InvalidParamError("numrects");
   1.144          return SDL_FALSE;
   1.145      }
   1.146  
     2.1 --- a/test/testautomation_rect.c	Wed Apr 17 07:35:30 2013 -0700
     2.2 +++ b/test/testautomation_rect.c	Wed Apr 17 08:09:11 2013 -0700
     2.3 @@ -614,8 +614,11 @@
     2.4      SDL_Rect rectB;
     2.5      SDL_Rect result;
     2.6      SDL_bool intersection;
     2.7 +    SDL_bool empty;
     2.8  
     2.9      // Rect A empty
    2.10 +    result.w = SDLTest_RandomIntegerInRange(1, 100);
    2.11 +    result.h = SDLTest_RandomIntegerInRange(1, 100);
    2.12      refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
    2.13      refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
    2.14      refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
    2.15 @@ -627,8 +630,12 @@
    2.16      rectB = refRectB;
    2.17      intersection = SDL_IntersectRect(&rectA, &rectB, &result);
    2.18      _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
    2.19 -
    2.20 +    empty = (SDL_bool)SDL_RectEmpty(&result);
    2.21 +    SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
    2.22 +    
    2.23      // Rect B empty
    2.24 +    result.w = SDLTest_RandomIntegerInRange(1, 100);
    2.25 +    result.h = SDLTest_RandomIntegerInRange(1, 100);
    2.26      refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
    2.27      refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
    2.28      refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
    2.29 @@ -640,8 +647,12 @@
    2.30      rectB = refRectB;
    2.31      intersection = SDL_IntersectRect(&rectA, &rectB, &result);
    2.32      _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
    2.33 +    empty = (SDL_bool)SDL_RectEmpty(&result);
    2.34 +    SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
    2.35  
    2.36      // Rect A and B empty
    2.37 +    result.w = SDLTest_RandomIntegerInRange(1, 100);
    2.38 +    result.h = SDLTest_RandomIntegerInRange(1, 100);
    2.39      refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
    2.40      refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
    2.41      refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
    2.42 @@ -655,8 +666,10 @@
    2.43      rectB = refRectB;
    2.44      intersection = SDL_IntersectRect(&rectA, &rectB, &result);
    2.45      _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
    2.46 +    empty = (SDL_bool)SDL_RectEmpty(&result);
    2.47 +    SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
    2.48  
    2.49 -	return TEST_COMPLETED;
    2.50 +    return TEST_COMPLETED;
    2.51  }
    2.52  
    2.53  /*!