Fix bug 1789: SDL_IntersectRect intersection with empty rect does not set result to empty; add test coverage to Rect suite
--- a/src/video/SDL_rect.c Wed Apr 17 07:35:30 2013 -0700
+++ b/src/video/SDL_rect.c Wed Apr 17 08:09:11 2013 -0700
@@ -29,8 +29,13 @@
{
int Amin, Amax, Bmin, Bmax;
- if (!A || !B) {
- // TODO error message
+ if (!A) {
+ SDL_InvalidParamError("A");
+ return SDL_FALSE;
+ }
+
+ if (!B) {
+ SDL_InvalidParamError("B");
return SDL_FALSE;
}
@@ -71,13 +76,25 @@
{
int Amin, Amax, Bmin, Bmax;
- if (!A || !B || !result) {
- // TODO error message
+ if (!A) {
+ SDL_InvalidParamError("A");
+ return SDL_FALSE;
+ }
+
+ if (!B) {
+ SDL_InvalidParamError("B");
+ return SDL_FALSE;
+ }
+
+ if (!result) {
+ SDL_InvalidParamError("result");
return SDL_FALSE;
}
/* Special cases for empty rects */
if (SDL_RectEmpty(A) || SDL_RectEmpty(B)) {
+ result->w = 0;
+ result->h = 0;
return SDL_FALSE;
}
@@ -113,7 +130,18 @@
{
int Amin, Amax, Bmin, Bmax;
- if (!A || !B || !result) {
+ if (!A) {
+ SDL_InvalidParamError("A");
+ return;
+ }
+
+ if (!B) {
+ SDL_InvalidParamError("B");
+ return;
+ }
+
+ if (!result) {
+ SDL_InvalidParamError("result");
return;
}
@@ -171,12 +199,12 @@
int x, y, i;
if (!points) {
- /* TODO error message */
+ SDL_InvalidParamError("points");
return SDL_FALSE;
}
if (count < 1) {
- /* TODO error message */
+ SDL_InvalidParamError("count");
return SDL_FALSE;
}
@@ -298,8 +326,28 @@
int recty2;
int outcode1, outcode2;
- if (!rect || !X1 || !Y1 || !X2 || !Y2) {
- // TODO error message
+ if (!rect) {
+ SDL_InvalidParamError("rect");
+ return SDL_FALSE;
+ }
+
+ if (!X1) {
+ SDL_InvalidParamError("X1");
+ return SDL_FALSE;
+ }
+
+ if (!Y1) {
+ SDL_InvalidParamError("Y1");
+ return SDL_FALSE;
+ }
+
+ if (!X2) {
+ SDL_InvalidParamError("X2");
+ return SDL_FALSE;
+ }
+
+ if (!Y2) {
+ SDL_InvalidParamError("Y2");
return SDL_FALSE;
}
@@ -418,18 +466,28 @@
int span_y1, span_y2;
int rect_y1, rect_y2;
- if (width < 1 || height < 1) {
- // TODO error message
+ if (width < 1) {
+ SDL_InvalidParamError("width");
return SDL_FALSE;
}
- if (!rects || !span) {
- // TODO error message
+ if (height < 1) {
+ SDL_InvalidParamError("height");
+ return SDL_FALSE;
+ }
+
+ if (!rects) {
+ SDL_InvalidParamError("rects");
+ return SDL_FALSE;
+ }
+
+ if (!span) {
+ SDL_InvalidParamError("span");
return SDL_FALSE;
}
if (numrects < 1) {
- // TODO error message
+ SDL_InvalidParamError("numrects");
return SDL_FALSE;
}
--- a/test/testautomation_rect.c Wed Apr 17 07:35:30 2013 -0700
+++ b/test/testautomation_rect.c Wed Apr 17 08:09:11 2013 -0700
@@ -614,8 +614,11 @@
SDL_Rect rectB;
SDL_Rect result;
SDL_bool intersection;
+ SDL_bool empty;
// Rect A empty
+ result.w = SDLTest_RandomIntegerInRange(1, 100);
+ result.h = SDLTest_RandomIntegerInRange(1, 100);
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
@@ -627,8 +630,12 @@
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
-
+ empty = (SDL_bool)SDL_RectEmpty(&result);
+ SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
+
// Rect B empty
+ result.w = SDLTest_RandomIntegerInRange(1, 100);
+ result.h = SDLTest_RandomIntegerInRange(1, 100);
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
@@ -640,8 +647,12 @@
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
+ empty = (SDL_bool)SDL_RectEmpty(&result);
+ SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
// Rect A and B empty
+ result.w = SDLTest_RandomIntegerInRange(1, 100);
+ result.h = SDLTest_RandomIntegerInRange(1, 100);
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
@@ -655,8 +666,10 @@
rectB = refRectB;
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
+ empty = (SDL_bool)SDL_RectEmpty(&result);
+ SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
- return TEST_COMPLETED;
+ return TEST_COMPLETED;
}
/*!