2 * Original code: automated SDL rect test written by Edgar Simo "bobbens"
3 * New/updated tests: aschiffler at ferzkopp dot net
10 #include "../../include/SDL_test.h"
12 /* SDL_IntersectRectAndLine */
13 static const TestCaseReference test1 =
14 (TestCaseReference){ "rect_testIntersectRectAndLine", "Tests SDL_IntersectRectAndLine clipping cases", TEST_ENABLED, 0, 0 };
16 static const TestCaseReference test2 =
17 (TestCaseReference){ "rect_testIntersectRectAndLineInside", "Tests SDL_IntersectRectAndLine with line fully contained in rect", TEST_ENABLED, 0, 0 };
19 static const TestCaseReference test3 =
20 (TestCaseReference){ "rect_testIntersectRectAndLineOutside", "Tests SDL_IntersectRectAndLine with line fully contained in rect", TEST_ENABLED, 0, 0 };
22 static const TestCaseReference test4 =
23 (TestCaseReference){ "rect_testIntersectRectAndLineParam", "Negative tests against SDL_IntersectRectAndLine with invalid parameters", TEST_ENABLED, 0, 0 };
25 /* SDL_IntersectRect */
26 static const TestCaseReference test5 =
27 (TestCaseReference){ "rect_testIntersectRectInside", "Tests SDL_IntersectRect with B fully contained in A", TEST_ENABLED, 0, 0 };
29 static const TestCaseReference test6 =
30 (TestCaseReference){ "rect_testIntersectRectOutside", "Tests SDL_IntersectRect with B fully outside of A", TEST_ENABLED, 0, 0 };
32 static const TestCaseReference test7 =
33 (TestCaseReference){ "rect_testIntersectRectPartial", "Tests SDL_IntersectRect with B partially intersecting A", TEST_ENABLED, 0, 0 };
35 static const TestCaseReference test8 =
36 (TestCaseReference){ "rect_testIntersectRectPoint", "Tests SDL_IntersectRect with 1x1 sized rectangles", TEST_ENABLED, 0, 0 };
38 static const TestCaseReference test9 =
39 (TestCaseReference){ "rect_testIntersectRectParam", "Negative tests against SDL_IntersectRect with invalid parameters", TEST_ENABLED, 0, 0 };
41 /* SDL_HasIntersection */
42 static const TestCaseReference test10 =
43 (TestCaseReference){ "rect_testHasIntersectionInside", "Tests SDL_HasIntersection with B fully contained in A", TEST_ENABLED, 0, 0 };
45 static const TestCaseReference test11 =
46 (TestCaseReference){ "rect_testHasIntersectionOutside", "Tests SDL_HasIntersection with B fully outside of A", TEST_ENABLED, 0, 0 };
48 static const TestCaseReference test12 =
49 (TestCaseReference){ "rect_testHasIntersectionPartial", "Tests SDL_HasIntersection with B partially intersecting A", TEST_ENABLED, 0, 0 };
51 static const TestCaseReference test13 =
52 (TestCaseReference){ "rect_testHasIntersectionPoint", "Tests SDL_HasIntersection with 1x1 sized rectangles", TEST_ENABLED, 0, 0 };
54 static const TestCaseReference test14 =
55 (TestCaseReference){ "rect_testHasIntersectionParam", "Negative tests against SDL_HasIntersection with invalid parameters", TEST_ENABLED, 0, 0 };
57 /* SDL_EnclosePoints */
58 static const TestCaseReference test15 =
59 (TestCaseReference){ "rect_testEnclosePoints", "Tests SDL_EnclosePoints without clipping", TEST_ENABLED, 0, 0 };
61 static const TestCaseReference test16 =
62 (TestCaseReference){ "rect_testEnclosePointsWithClipping", "Tests SDL_EnclosePoints with clipping", TEST_ENABLED, 0, 0 };
64 static const TestCaseReference test17 =
65 (TestCaseReference){ "rect_testEnclosePointsRepeatedInput", "Tests SDL_EnclosePoints with repeated input", TEST_ENABLED, 0, 0 };
67 static const TestCaseReference test18 =
68 (TestCaseReference){ "rect_testEnclosePointsParam", "Negative tests against SDL_EnclosePoints with invalid parameters", TEST_ENABLED, 0, 0 };
71 static const TestCaseReference test19 =
72 (TestCaseReference){ "rect_testUnionRectInside", "Tests SDL_UnionRect where rect B is inside rect A", TEST_ENABLED, 0, 0 };
74 static const TestCaseReference test20 =
75 (TestCaseReference){ "rect_testUnionRectOutside", "Tests SDL_UnionRect where rect B is outside rect A", TEST_ENABLED, 0, 0 };
77 static const TestCaseReference test21 =
78 (TestCaseReference){ "rect_testUnionRectParam", "Negative tests against SDL_UnionRect with invalid parameters", TEST_ENABLED, 0, 0 };
81 static const TestCaseReference test22 =
82 (TestCaseReference){ "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED, 0, 0 };
84 static const TestCaseReference test23 =
85 (TestCaseReference){ "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED, 0, 0 };
87 /* TODO: SDL_RectEquals */
90 * \brief Test suite for functions that handle simple rectangles including overlaps and merges.
93 * http://wiki.libsdl.org/moin.cgi/CategoryRect
95 extern const TestCaseReference *testSuite[] = {
96 &test1, &test2, &test3, &test4, &test5, &test6, &test7, &test8, &test9, &test10, &test11, &test12, &test13, &test14,
97 &test15, &test16, &test17, &test18, &test19, &test20, &test21, &test22, &test23, NULL
100 TestCaseReference **QueryTestSuite() {
101 return (TestCaseReference **)testSuite;
105 * \brief Private helper to check SDL_IntersectRectAndLine results
107 void _validateIntersectRectAndLineResults(
108 SDL_bool intersection, SDL_bool expectedIntersection,
109 SDL_Rect *rect, SDL_Rect * refRect,
110 int x1, int y1, int x2, int y2,
111 int x1Ref, int y1Ref, int x2Ref, int y2Ref)
113 AssertTrue(intersection == expectedIntersection,
114 "Incorrect intersection result: expected %s, got %s intersecting rect (%d,%d,%d,%d) with line (%d,%d - %d,%d)\n",
115 (expectedIntersection == SDL_TRUE) ? "true" : "false",
116 (intersection == SDL_TRUE) ? "true" : "false",
117 refRect->x, refRect->y, refRect->w, refRect->h,
118 x1Ref, y1Ref, x2Ref, y2Ref);
119 AssertTrue(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
120 "Source rectangle was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
121 rect->x, rect->y, rect->w, rect->h,
122 refRect->x, refRect->y, refRect->w, refRect->h);
123 AssertTrue(x1 == x1Ref && y1 == y1Ref && x2 == x2Ref && y2 == y2Ref,
124 "Line was incorrectly clipped or modified: got (%d,%d - %d,%d) expected (%d,%d - %d,%d)",
126 x1Ref, y1Ref, x2Ref, y2Ref);
130 * \brief Tests SDL_IntersectRectAndLine() clipping cases
133 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
135 int rect_testIntersectRectAndLine (void *arg)
137 SDL_Rect refRect = { 0, 0, 32, 32 };
141 SDL_bool intersected;
143 int xLeft = -RandomIntegerInRange(1, refRect.w);
144 int xRight = refRect.w + RandomIntegerInRange(1, refRect.w);
145 int yTop = -RandomIntegerInRange(1, refRect.h);
146 int yBottom = refRect.h + RandomIntegerInRange(1, refRect.h);
153 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
154 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 15, 31, 15);
161 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
162 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 15, 0, 15, 31);
169 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
170 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 0, 31, 31);
177 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
178 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 31, 0, 0);
185 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
186 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 0, 31, 31, 0);
193 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
194 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, 31, 0, 0, 31);
198 * \brief Tests SDL_IntersectRectAndLine() non-clipping case line inside
201 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
203 int rect_testIntersectRectAndLineInside (void *arg)
205 SDL_Rect refRect = { 0, 0, 32, 32 };
209 SDL_bool intersected;
211 int xmin = refRect.x;
212 int xmax = refRect.x + refRect.w - 1;
213 int ymin = refRect.y;
214 int ymax = refRect.y + refRect.h - 1;
215 int x1Ref = RandomIntegerInRange(xmin + 1, xmax - 1);
216 int y1Ref = RandomIntegerInRange(ymin + 1, ymax - 1);
217 int x2Ref = RandomIntegerInRange(xmin + 1, xmax - 1);
218 int y2Ref = RandomIntegerInRange(ymin + 1, ymax - 1);
225 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
226 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, x2Ref, y2Ref);
233 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
234 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, x1Ref, y1Ref, xmax, ymax);
241 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
242 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, x2Ref, y2Ref);
249 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
250 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymin, xmax, ymax);
257 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
258 _validateIntersectRectAndLineResults(intersected, SDL_TRUE, &rect, &refRect, x1, y1, x2, y2, xmin, ymax, xmax, ymin);
263 * \brief Tests SDL_IntersectRectAndLine() non-clipping cases outside
266 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
268 int rect_testIntersectRectAndLineOutside (void *arg)
270 SDL_Rect refRect = { 0, 0, 32, 32 };
274 SDL_bool intersected;
276 int xLeft = -RandomIntegerInRange(1, refRect.w);
277 int xRight = refRect.w + RandomIntegerInRange(1, refRect.w);
278 int yTop = -RandomIntegerInRange(1, refRect.h);
279 int yBottom = refRect.h + RandomIntegerInRange(1, refRect.h);
286 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
287 _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xLeft, 0, xLeft, 31);
294 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
295 _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, xRight, 0, xRight, 31);
302 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
303 _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yTop, 31, yTop);
310 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
311 _validateIntersectRectAndLineResults(intersected, SDL_FALSE, &rect, &refRect, x1, y1, x2, y2, 0, yBottom, 31, yBottom);
315 * \brief Negative tests against SDL_IntersectRectAndLine() with invalid parameters
318 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
320 int rect_testIntersectRectAndLineParam (void *arg)
322 SDL_Rect rect = { 0, 0, 32, 32 };
327 SDL_bool intersected;
329 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, &y2);
330 AssertTrue(intersected == SDL_TRUE, "Test variables not intersected as expected");
332 intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, &x1, &y1, &x2, &y2);
333 AssertTrue(intersected == SDL_FALSE, "Incorrect intersected result when 1st parameter is NULL");
334 intersected = SDL_IntersectRectAndLine(&rect, (int *)NULL, &y1, &x2, &y2);
335 AssertTrue(intersected == SDL_FALSE, "Incorrect intersected result when 2nd parameter is NULL");
336 intersected = SDL_IntersectRectAndLine(&rect, &x1, (int *)NULL, &x2, &y2);
337 AssertTrue(intersected == SDL_FALSE, "Incorrect intersected result when 3rd parameter is NULL");
338 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, (int *)NULL, &y2);
339 AssertTrue(intersected == SDL_FALSE, "Incorrect intersected result when 4th parameter is NULL");
340 intersected = SDL_IntersectRectAndLine(&rect, &x1, &y1, &x2, (int *)NULL);
341 AssertTrue(intersected == SDL_FALSE, "Incorrect intersected result when 5th parameter is NULL");
342 intersected = SDL_IntersectRectAndLine((SDL_Rect *)NULL, (int *)NULL, (int *)NULL, (int *)NULL, (int *)NULL);
343 AssertTrue(intersected == SDL_FALSE, "Incorrect intersected result when all parameters are NULL");
347 * \brief Private helper to check SDL_HasIntersection results
349 void _validateHasIntersectionResults(
350 SDL_bool intersection, SDL_bool expectedIntersection,
351 SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB)
353 AssertTrue(intersection == expectedIntersection,
354 "Incorrect intersection result: expected %s, got %s intersecting A (%d,%d,%d,%d) with B (%d,%d,%d,%d)\n",
355 (expectedIntersection == SDL_TRUE) ? "true" : "false",
356 (intersection == SDL_TRUE) ? "true" : "false",
357 rectA->x, rectA->y, rectA->w, rectA->h,
358 rectB->x, rectB->y, rectB->w, rectB->h);
359 AssertTrue(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
360 "Source rectangle A was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
361 rectA->x, rectA->y, rectA->w, rectA->h,
362 refRectA->x, refRectA->y, refRectA->w, refRectA->h);
363 AssertTrue(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
364 "Source rectangle B was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
365 rectB->x, rectB->y, rectB->w, rectB->h,
366 refRectB->x, refRectB->y, refRectB->w, refRectB->h);
370 * \brief Private helper to check SDL_IntersectRect results
372 void _validateIntersectRectResults(
373 SDL_bool intersection, SDL_bool expectedIntersection,
374 SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
375 SDL_Rect *result, SDL_Rect *expectedResult)
377 _validateHasIntersectionResults(intersection, expectedIntersection, rectA, rectB, refRectA, refRectB);
378 if (result && expectedResult) {
379 AssertTrue(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
380 "Intersection of rectangles A (%d,%d,%d,%d) and B (%d,%d,%d,%d) was incorrectly calculated, got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
381 rectA->x, rectA->y, rectA->w, rectA->h,
382 rectB->x, rectB->y, rectB->w, rectB->h,
383 result->x, result->y, result->w, result->h,
384 expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
389 * \brief Private helper to check SDL_UnionRect results
391 void _validateUnionRectResults(
392 SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
393 SDL_Rect *result, SDL_Rect *expectedResult)
395 AssertTrue(rectA->x == refRectA->x && rectA->y == refRectA->y && rectA->w == refRectA->w && rectA->h == refRectA->h,
396 "Source rectangle A was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
397 rectA->x, rectA->y, rectA->w, rectA->h,
398 refRectA->x, refRectA->y, refRectA->w, refRectA->h);
399 AssertTrue(rectB->x == refRectB->x && rectB->y == refRectB->y && rectB->w == refRectB->w && rectB->h == refRectB->h,
400 "Source rectangle B was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
401 rectB->x, rectB->y, rectB->w, rectB->h,
402 refRectB->x, refRectB->y, refRectB->w, refRectB->h);
403 AssertTrue(result->x == expectedResult->x && result->y == expectedResult->y && result->w == expectedResult->w && result->h == expectedResult->h,
404 "Union of rectangles A (%d,%d,%d,%d) and B (%d,%d,%d,%d) was incorrectly calculated, got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
405 rectA->x, rectA->y, rectA->w, rectA->h,
406 rectB->x, rectB->y, rectB->w, rectB->h,
407 result->x, result->y, result->w, result->h,
408 expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
412 * \brief Private helper to check SDL_RectEmpty results
414 void _validateRectEmptyResults(
415 SDL_bool empty, SDL_bool expectedEmpty,
416 SDL_Rect *rect, SDL_Rect *refRect)
418 AssertTrue(empty == expectedEmpty,
419 "Incorrect empty result: expected %s, got %s testing (%d,%d,%d,%d)\n",
420 (expectedEmpty == SDL_TRUE) ? "true" : "false",
421 (empty == SDL_TRUE) ? "true" : "false",
422 rect->x, rect->y, rect->w, rect->h);
423 AssertTrue(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
424 "Source rectangle was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
425 rect->x, rect->y, rect->w, rect->h,
426 refRect->x, refRect->y, refRect->w, refRect->h);
430 * \brief Tests SDL_IntersectRect() with B fully inside A
433 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
435 int rect_testIntersectRectInside (void *arg)
437 SDL_Rect refRectA = { 0, 0, 32, 32 };
442 SDL_bool intersection;
444 // rectB fully contained in rectA
447 refRectB.w = RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
448 refRectB.h = RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
451 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
452 _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectB);
456 * \brief Tests SDL_IntersectRect() with B fully outside A
459 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
461 int rect_testIntersectRectOutside (void *arg)
463 SDL_Rect refRectA = { 0, 0, 32, 32 };
468 SDL_bool intersection;
470 // rectB fully outside of rectA
471 refRectB.x = refRectA.x + refRectA.w + RandomIntegerInRange(1, 10);
472 refRectB.y = refRectA.y + refRectA.h + RandomIntegerInRange(1, 10);
473 refRectB.w = refRectA.w;
474 refRectB.h = refRectA.h;
477 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
478 _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
482 * \brief Tests SDL_IntersectRect() with B partially intersecting A
485 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
487 int rect_testIntersectRectPartial (void *arg)
489 SDL_Rect refRectA = { 0, 0, 32, 32 };
494 SDL_Rect expectedResult;
495 SDL_bool intersection;
497 // rectB partially contained in rectA
498 refRectB.x = RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
499 refRectB.y = RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
500 refRectB.w = refRectA.w;
501 refRectB.h = refRectA.h;
504 expectedResult.x = refRectB.x;
505 expectedResult.y = refRectB.y;
506 expectedResult.w = refRectA.w - refRectB.x;
507 expectedResult.h = refRectA.h - refRectB.y;
508 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
509 _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
512 refRectB.x = rectA.w - 1;
513 refRectB.y = rectA.y;
514 refRectB.w = RandomIntegerInRange(1, refRectA.w - 1);
515 refRectB.h = RandomIntegerInRange(1, refRectA.h - 1);
518 expectedResult.x = refRectB.x;
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);
526 refRectB.x = 1 - rectA.w;
527 refRectB.y = rectA.y;
528 refRectB.w = refRectA.w;
529 refRectB.h = RandomIntegerInRange(1, refRectA.h - 1);
532 expectedResult.x = 0;
533 expectedResult.y = refRectB.y;
534 expectedResult.w = 1;
535 expectedResult.h = refRectB.h;
536 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
537 _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
540 refRectB.x = rectA.x;
541 refRectB.y = rectA.h - 1;
542 refRectB.w = RandomIntegerInRange(1, refRectA.w - 1);
543 refRectB.h = RandomIntegerInRange(1, refRectA.h - 1);
546 expectedResult.x = refRectB.x;
547 expectedResult.y = refRectB.y;
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);
554 refRectB.x = rectA.x;
555 refRectB.y = 1 - rectA.h;
556 refRectB.w = RandomIntegerInRange(1, refRectA.w - 1);
557 refRectB.h = rectA.h;
560 expectedResult.x = refRectB.x;
561 expectedResult.y = 0;
562 expectedResult.w = refRectB.w;
563 expectedResult.h = 1;
564 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
565 _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
569 * \brief Tests SDL_IntersectRect() with 1x1 pixel sized rectangles
572 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
574 int rect_testIntersectRectPoint (void *arg)
576 SDL_Rect refRectA = { 0, 0, 1, 1 };
577 SDL_Rect refRectB = { 0, 0, 1, 1 };
581 SDL_bool intersection;
582 int offsetX, offsetY;
584 // intersecting pixels
585 refRectA.x = RandomIntegerInRange(1, 100);
586 refRectA.y = RandomIntegerInRange(1, 100);
587 refRectB.x = refRectA.x;
588 refRectB.y = refRectA.y;
591 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
592 _validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectA);
594 // non-intersecting pixels cases
595 for (offsetX = -1; offsetX <= 1; offsetX++) {
596 for (offsetY = -1; offsetY <= 1; offsetY++) {
597 if (offsetX != 0 || offsetY != 0) {
598 refRectA.x = RandomIntegerInRange(1, 100);
599 refRectA.y = RandomIntegerInRange(1, 100);
600 refRectB.x = refRectA.x;
601 refRectB.y = refRectA.y;
602 refRectB.x += offsetX;
603 refRectB.y += offsetY;
606 intersection = SDL_IntersectRect(&rectA, &rectB, &result);
607 _validateIntersectRectResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
614 * \brief Negative tests against SDL_IntersectRect() with invalid parameters
617 * http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
619 int rect_testIntersectRectParam(void *arg)
624 SDL_bool intersection;
626 // invalid parameter combinations
627 intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, &result);
628 AssertTrue(intersection == SDL_FALSE, "Function did not return false when 1st parameter was NULL");
629 intersection = SDL_IntersectRect(&rectA, (SDL_Rect *)NULL, &result);
630 AssertTrue(intersection == SDL_FALSE, "Function did not return false when 2st parameter was NULL");
631 intersection = SDL_IntersectRect(&rectA, &rectB, (SDL_Rect *)NULL);
632 AssertTrue(intersection == SDL_FALSE, "Function did not return false when 3st parameter was NULL");
633 intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, &result);
634 AssertTrue(intersection == SDL_FALSE, "Function did not return false when 1st and 2nd parameters were NULL");
635 intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
636 AssertTrue(intersection == SDL_FALSE, "Function did not return false when 1st and 3rd parameters were NULL ");
637 intersection = SDL_IntersectRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
638 AssertTrue(intersection == SDL_FALSE, "Function did not return false when all parameters were NULL");
642 * \brief Tests SDL_HasIntersection() with B fully inside A
645 * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
647 int rect_testHasIntersectionInside (void *arg)
649 SDL_Rect refRectA = { 0, 0, 32, 32 };
653 SDL_bool intersection;
655 // rectB fully contained in rectA
658 refRectB.w = RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
659 refRectB.h = RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
662 intersection = SDL_HasIntersection(&rectA, &rectB);
663 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
667 * \brief Tests SDL_HasIntersection() with B fully outside A
670 * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
672 int rect_testHasIntersectionOutside (void *arg)
674 SDL_Rect refRectA = { 0, 0, 32, 32 };
678 SDL_bool intersection;
680 // rectB fully outside of rectA
681 refRectB.x = refRectA.x + refRectA.w + RandomIntegerInRange(1, 10);
682 refRectB.y = refRectA.y + refRectA.h + RandomIntegerInRange(1, 10);
683 refRectB.w = refRectA.w;
684 refRectB.h = refRectA.h;
687 intersection = SDL_HasIntersection(&rectA, &rectB);
688 _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
692 * \brief Tests SDL_HasIntersection() with B partially intersecting A
695 * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
697 int rect_testHasIntersectionPartial (void *arg)
699 SDL_Rect refRectA = { 0, 0, 32, 32 };
703 SDL_bool intersection;
705 // rectB partially contained in rectA
706 refRectB.x = RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
707 refRectB.y = RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
708 refRectB.w = refRectA.w;
709 refRectB.h = refRectA.h;
712 intersection = SDL_HasIntersection(&rectA, &rectB);
713 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
716 refRectB.x = rectA.w - 1;
717 refRectB.y = rectA.y;
718 refRectB.w = RandomIntegerInRange(1, refRectA.w - 1);
719 refRectB.h = RandomIntegerInRange(1, refRectA.h - 1);
722 intersection = SDL_HasIntersection(&rectA, &rectB);
723 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
726 refRectB.x = 1 - rectA.w;
727 refRectB.y = rectA.y;
728 refRectB.w = refRectA.w;
729 refRectB.h = RandomIntegerInRange(1, refRectA.h - 1);
732 intersection = SDL_HasIntersection(&rectA, &rectB);
733 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
736 refRectB.x = rectA.x;
737 refRectB.y = rectA.h - 1;
738 refRectB.w = RandomIntegerInRange(1, refRectA.w - 1);
739 refRectB.h = RandomIntegerInRange(1, refRectA.h - 1);
742 intersection = SDL_HasIntersection(&rectA, &rectB);
743 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
746 refRectB.x = rectA.x;
747 refRectB.y = 1 - rectA.h;
748 refRectB.w = RandomIntegerInRange(1, refRectA.w - 1);
749 refRectB.h = rectA.h;
752 intersection = SDL_HasIntersection(&rectA, &rectB);
753 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
757 * \brief Tests SDL_HasIntersection() with 1x1 pixel sized rectangles
760 * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
762 int rect_testHasIntersectionPoint (void *arg)
764 SDL_Rect refRectA = { 0, 0, 1, 1 };
765 SDL_Rect refRectB = { 0, 0, 1, 1 };
769 SDL_bool intersection;
770 int offsetX, offsetY;
772 // intersecting pixels
773 refRectA.x = RandomIntegerInRange(1, 100);
774 refRectA.y = RandomIntegerInRange(1, 100);
775 refRectB.x = refRectA.x;
776 refRectB.y = refRectA.y;
779 intersection = SDL_HasIntersection(&rectA, &rectB);
780 _validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
782 // non-intersecting pixels cases
783 for (offsetX = -1; offsetX <= 1; offsetX++) {
784 for (offsetY = -1; offsetY <= 1; offsetY++) {
785 if (offsetX != 0 || offsetY != 0) {
786 refRectA.x = RandomIntegerInRange(1, 100);
787 refRectA.y = RandomIntegerInRange(1, 100);
788 refRectB.x = refRectA.x;
789 refRectB.y = refRectA.y;
790 refRectB.x += offsetX;
791 refRectB.y += offsetY;
794 intersection = SDL_HasIntersection(&rectA, &rectB);
795 _validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
802 * \brief Negative tests against SDL_HasIntersection() with invalid parameters
805 * http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
807 int rect_testHasIntersectionParam(void *arg)
811 SDL_bool intersection;
813 // invalid parameter combinations
814 intersection = SDL_HasIntersection((SDL_Rect *)NULL, &rectB);
815 AssertTrue(intersection == SDL_FALSE, "Function did not return false when 1st parameter was NULL");
816 intersection = SDL_HasIntersection(&rectA, (SDL_Rect *)NULL);
817 AssertTrue(intersection == SDL_FALSE, "Function did not return false when 2st parameter was NULL");
818 intersection = SDL_HasIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL);
819 AssertTrue(intersection == SDL_FALSE, "Function did not return false when all parameters were NULL");
823 * \brief Test SDL_EnclosePoints() without clipping
826 * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
828 int rect_testEnclosePoints(void *arg)
830 const int numPoints = 16;
831 SDL_Point refPoints[numPoints];
832 SDL_Point points[numPoints];
835 SDL_bool anyEnclosed;
836 SDL_bool anyEnclosedNoResult;
838 // Create input data, tracking result
839 SDL_bool expectedEnclosed = SDL_TRUE;
841 int minx, maxx, miny, maxy;
843 for (i=0; i<numPoints; i++) {
844 newx = RandomIntegerInRange(-1024, 1024);
845 newy = RandomIntegerInRange(-1024, 1024);
846 refPoints[i].x = newx;
847 refPoints[i].y = newy;
854 if (newx<minx) minx=newx;
855 if (newx>maxx) maxx=newx;
856 if (newy<miny) miny=newy;
857 if (newy>maxy) maxy=newy;
861 // Call function and validate - special case: no result requested
862 anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
863 AssertTrue(expectedEnclosed==anyEnclosedNoResult,
864 "Expected return value %s, got %s",
865 (expectedEnclosed==SDL_TRUE) ? "true" : "false", (anyEnclosedNoResult==SDL_TRUE) ? "true" : "false");
866 for (i=0; i<numPoints; i++) {
867 AssertTrue(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
868 "Source point %i was incorrectly modified: expected (%i,%i) actual (%i,%i)",
869 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
872 // Call function and validate
873 anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
874 AssertTrue(expectedEnclosed==anyEnclosed,
875 "Expected return value %s, got %s",
876 (expectedEnclosed==SDL_TRUE) ? "true" : "false", (anyEnclosed==SDL_TRUE) ? "true" : "false");
877 for (i=0; i<numPoints; i++) {
878 AssertTrue(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
879 "Source point %i was incorrectly modified: expected (%i,%i) actual (%i,%i)",
880 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
882 AssertTrue(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
883 "Resulting enclosing rectangle incorrect: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
884 minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
888 * \brief Test SDL_EnclosePoints() with repeated input points
891 * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
893 int rect_testEnclosePointsRepeatedInput(void *arg)
895 const int numPoints = 8;
896 const int halfPoints = numPoints/2;
897 SDL_Point refPoints[numPoints];
898 SDL_Point points[numPoints];
901 SDL_bool anyEnclosed;
902 SDL_bool anyEnclosedNoResult;
904 // Create input data, tracking result
905 SDL_bool expectedEnclosed = SDL_TRUE;
907 int minx, maxx, miny, maxy;
909 for (i=0; i<numPoints; i++) {
910 if (i < halfPoints) {
911 newx = RandomIntegerInRange(-1024, 1024);
912 newy = RandomIntegerInRange(-1024, 1024);
914 newx = refPoints[i-halfPoints].x;
915 newy = refPoints[i-halfPoints].y;
917 refPoints[i].x = newx;
918 refPoints[i].y = newy;
925 if (newx<minx) minx=newx;
926 if (newx>maxx) maxx=newx;
927 if (newy<miny) miny=newy;
928 if (newy>maxy) maxy=newy;
932 // Call function and validate - special case: no result requested
933 anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
934 AssertTrue(expectedEnclosed==anyEnclosedNoResult,
935 "Expected return value %s, got %s",
936 (expectedEnclosed==SDL_TRUE) ? "true" : "false", (anyEnclosedNoResult==SDL_TRUE) ? "true" : "false");
937 for (i=0; i<numPoints; i++) {
938 AssertTrue(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
939 "Source point %i was incorrectly modified: expected (%i,%i) actual (%i,%i)",
940 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
943 // Call function and validate
944 anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
945 AssertTrue(expectedEnclosed==anyEnclosed,
946 "Expected return value %s, got %s",
947 (expectedEnclosed==SDL_TRUE) ? "true" : "false", (anyEnclosed==SDL_TRUE) ? "true" : "false");
948 for (i=0; i<numPoints; i++) {
949 AssertTrue(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
950 "Source point %i was incorrectly modified: expected (%i,%i) actual (%i,%i)",
951 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
953 AssertTrue(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
954 "Resulting enclosing rectangle incorrect: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
955 minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
959 * \brief Test SDL_EnclosePoints() with clipping
962 * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
964 int rect_testEnclosePointsWithClipping(void *arg)
966 const int numPoints = 16;
967 SDL_Point refPoints[numPoints];
968 SDL_Point points[numPoints];
973 SDL_bool anyEnclosed;
974 SDL_bool anyEnclosedNoResult;
976 // Setup clipping rectangle
977 refClip.x = RandomIntegerInRange(-1024, 1024);
978 refClip.y = RandomIntegerInRange(-1024, 1024);
979 refClip.w = RandomIntegerInRange(1, 1024);
980 refClip.h = RandomIntegerInRange(1, 1024);
982 // Create input data, tracking result
983 SDL_bool expectedEnclosed = SDL_FALSE;
985 int minx, maxx, miny, maxy;
987 for (i=0; i<numPoints; i++) {
988 newx = RandomIntegerInRange(-1024, 1024);
989 newy = RandomIntegerInRange(-1024, 1024);
990 refPoints[i].x = newx;
991 refPoints[i].y = newy;
994 if ((newx>=refClip.x) && (newx<(refClip.x + refClip.w)) &&
995 (newy>=refClip.y) && (newy<(refClip.y + refClip.h))) {
996 if (expectedEnclosed==SDL_FALSE) {
1000 if (newx<minx) minx=newx;
1001 if (newx>maxx) maxx=newx;
1002 if (newy<miny) miny=newy;
1003 if (newy>maxy) maxy=newy;
1005 expectedEnclosed = SDL_TRUE;
1009 // Call function and validate - special case: no result requested
1011 anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, (SDL_Rect *)NULL);
1012 AssertTrue(expectedEnclosed==anyEnclosedNoResult,
1013 "Expected return value %s, got %s",
1014 (expectedEnclosed==SDL_TRUE) ? "true" : "false", (anyEnclosedNoResult==SDL_TRUE) ? "true" : "false");
1015 for (i=0; i<numPoints; i++) {
1016 AssertTrue(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
1017 "Source point %i was incorrectly modified: expected (%i,%i) actual (%i,%i)",
1018 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1020 AssertTrue(refClip.x==clip.x && refClip.y==clip.y && refClip.w==clip.w && refClip.h==clip.h,
1021 "Source clipping rectangle was incorrectly modified");
1023 // Call function and validate
1024 anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, &result);
1025 AssertTrue(expectedEnclosed==anyEnclosed,
1026 "Expected return value %s, got %s",
1027 (expectedEnclosed==SDL_TRUE) ? "true" : "false", (anyEnclosed==SDL_TRUE) ? "true" : "false");
1028 for (i=0; i<numPoints; i++) {
1029 AssertTrue(refPoints[i].x==points[i].x && refPoints[i].y==points[i].y,
1030 "Source point %i was incorrectly modified: expected (%i,%i) actual (%i,%i)",
1031 i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
1033 AssertTrue(refClip.x==clip.x && refClip.y==clip.y && refClip.w==clip.w && refClip.h==clip.h,
1034 "Source clipping rectangle was incorrectly modified");
1035 if (expectedEnclosed==SDL_TRUE) {
1036 AssertTrue(result.x==minx && result.y==miny && result.w==(maxx - minx + 1) && result.h==(maxy - miny + 1),
1037 "Resulting enclosing rectangle incorrect: expected (%i,%i - %i,%i), actual (%i,%i - %i,%i)",
1038 minx, miny, maxx, maxy, result.x, result.y, result.x + result.w - 1, result.y + result.h - 1);
1043 * \brief Negative tests against SDL_EnclosePoints() with invalid parameters
1046 * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
1048 int rect_testEnclosePointsParam(void *arg)
1050 SDL_Point points[1];
1054 SDL_bool anyEnclosed;
1056 // invalid parameter combinations
1057 anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 1, (const SDL_Rect *)&clip, &result);
1058 AssertTrue(anyEnclosed == SDL_FALSE, "Function did not return false when 1st parameter was NULL");
1059 anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, 0, (const SDL_Rect *)&clip, &result);
1060 AssertTrue(anyEnclosed == SDL_FALSE, "Function did not return false when 2nd parameter was 0");
1061 count = RandomIntegerInRange(-100, -1);
1062 anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, count, (const SDL_Rect *)&clip, &result);
1063 AssertTrue(anyEnclosed == SDL_FALSE, "Function did not return false when 2nd parameter was %i", count);
1064 anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 0, (const SDL_Rect *)&clip, &result);
1065 AssertTrue(anyEnclosed == SDL_FALSE, "Function did not return false when 1st parameter was NULL and 2nd parameter was 0");
1070 * \brief Tests SDL_UnionRect() where rect B is outside rect A
1073 * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
1075 int rect_testUnionRectOutside(void *arg)
1077 SDL_Rect refRectA, refRectB;
1078 SDL_Rect rectA, rectB;
1079 SDL_Rect expectedResult;
1081 int minx, maxx, miny, maxy;
1084 /* Union 1x1 outside */
1085 for (dx = -1; dx < 2; dx++) {
1086 for (dy = -1; dy < 2; dy++) {
1087 if ((dx != 0) || (dy != 0)) {
1088 refRectA.x=RandomIntegerInRange(-1024, 1024);
1089 refRectA.y=RandomIntegerInRange(-1024, 1024);
1092 refRectB.x=RandomIntegerInRange(-1024, 1024) + dx*2048;
1093 refRectB.y=RandomIntegerInRange(-1024, 1024) + dx*2048;
1096 minx = (refRectA.x<refRectB.x) ? refRectA.x : refRectB.x;
1097 maxx = (refRectA.x>refRectB.x) ? refRectA.x : refRectB.x;
1098 miny = (refRectA.y<refRectB.y) ? refRectA.y : refRectB.y;
1099 maxy = (refRectA.y>refRectB.y) ? refRectA.y : refRectB.y;
1100 expectedResult.x = minx;
1101 expectedResult.y = miny;
1102 expectedResult.w = maxx - minx + 1;
1103 expectedResult.h = maxy - miny + 1;
1106 SDL_UnionRect(&rectA, &rectB, &result);
1107 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1112 /* Union outside overlap */
1113 for (dx = -1; dx < 2; dx++) {
1114 for (dy = -1; dy < 2; dy++) {
1115 if ((dx != 0) || (dy != 0)) {
1116 refRectA.x=RandomIntegerInRange(-1024, 1024);
1117 refRectA.y=RandomIntegerInRange(-1024, 1024);
1118 refRectA.w=RandomIntegerInRange(256, 512);
1119 refRectA.h=RandomIntegerInRange(256, 512);
1120 refRectB.x=refRectA.x + 1 + dx*2;
1121 refRectB.y=refRectA.y + 1 + dy*2;
1122 refRectB.w=refRectA.w - 2;
1123 refRectB.h=refRectA.h - 2;
1124 expectedResult = refRectA;
1125 if (dx == -1) expectedResult.x--;
1126 if (dy == -1) expectedResult.y--;
1127 if ((dx == 1) || (dx == -1)) expectedResult.w++;
1128 if ((dy == 1) || (dy == -1)) expectedResult.h++;
1131 SDL_UnionRect(&rectA, &rectB, &result);
1132 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1139 * \brief Tests SDL_UnionRect() where rect B is inside rect A
1142 * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
1144 int rect_testUnionRectInside(void *arg)
1146 SDL_Rect refRectA, refRectB;
1147 SDL_Rect rectA, rectB;
1148 SDL_Rect expectedResult;
1150 int minx, maxx, miny, maxy;
1153 /* Union 1x1 with itself */
1154 refRectA.x=RandomIntegerInRange(-1024, 1024);
1155 refRectA.y=RandomIntegerInRange(-1024, 1024);
1158 expectedResult = refRectA;
1160 SDL_UnionRect(&rectA, &rectA, &result);
1161 _validateUnionRectResults(&rectA, &rectA, &refRectA, &refRectA, &result, &expectedResult);
1163 /* Union 1x1 somewhere inside */
1164 refRectA.x=RandomIntegerInRange(-1024, 1024);
1165 refRectA.y=RandomIntegerInRange(-1024, 1024);
1166 refRectA.w=RandomIntegerInRange(256, 1024);
1167 refRectA.h=RandomIntegerInRange(256, 1024);
1168 refRectB.x=refRectA.x + 1 + RandomIntegerInRange(1, refRectA.w - 2);
1169 refRectB.y=refRectA.y + 1 + RandomIntegerInRange(1, refRectA.h - 2);
1172 expectedResult = refRectA;
1175 SDL_UnionRect(&rectA, &rectB, &result);
1176 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1178 /* Union inside with edges modified */
1179 for (dx = -1; dx < 2; dx++) {
1180 for (dy = -1; dy < 2; dy++) {
1181 if ((dx != 0) || (dy != 0)) {
1182 refRectA.x=RandomIntegerInRange(-1024, 1024);
1183 refRectA.y=RandomIntegerInRange(-1024, 1024);
1184 refRectA.w=RandomIntegerInRange(256, 1024);
1185 refRectA.h=RandomIntegerInRange(256, 1024);
1186 refRectB = refRectA;
1187 if (dx == -1) refRectB.x++;
1188 if ((dx == 1) || (dx == -1)) refRectB.w--;
1189 if (dy == -1) refRectB.y++;
1190 if ((dy == 1) || (dy == -1)) refRectB.h--;
1191 expectedResult = refRectA;
1194 SDL_UnionRect(&rectA, &rectB, &result);
1195 _validateUnionRectResults(&rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
1202 * \brief Negative tests against SDL_UnionRect() with invalid parameters
1205 * http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
1207 int rect_testUnionRectParam(void *arg)
1209 SDL_Rect rectA, rectB;
1212 // invalid parameter combinations
1213 SDL_UnionRect((SDL_Rect *)NULL, &rectB, &result);
1214 AssertPass("Function did return when 1st parameter was NULL");
1215 SDL_UnionRect(&rectA, (SDL_Rect *)NULL, &result);
1216 AssertPass("Function did return when 2nd parameter was NULL");
1217 SDL_UnionRect(&rectA, &rectB, (SDL_Rect *)NULL);
1218 AssertPass("Function did return when 3rd parameter was NULL");
1219 SDL_UnionRect((SDL_Rect *)NULL, &rectB, (SDL_Rect *)NULL);
1220 AssertPass("Function did return when 1st and 3rd parameter were NULL");
1221 SDL_UnionRect(&rectA, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
1222 AssertPass("Function did return when 2nd and 3rd parameter were NULL");
1223 SDL_UnionRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
1224 AssertPass("Function did return when all parameters were NULL");
1228 * \brief Tests SDL_RectEmpty() with various inputs
1231 * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
1233 int rect_testRectEmpty(void *arg)
1237 SDL_bool expectedResult;
1242 refRect.x=RandomIntegerInRange(-1024, 1024);
1243 refRect.y=RandomIntegerInRange(-1024, 1024);
1244 refRect.w=RandomIntegerInRange(256, 1024);
1245 refRect.h=RandomIntegerInRange(256, 1024);
1246 expectedResult = SDL_FALSE;
1248 result = SDL_RectEmpty((const SDL_Rect *)&rect);
1249 _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
1252 for (w=-1; w<2; w++) {
1253 for (h=-1; h<2; h++) {
1254 if ((w != 1) || (h != 1)) {
1255 refRect.x=RandomIntegerInRange(-1024, 1024);
1256 refRect.y=RandomIntegerInRange(-1024, 1024);
1259 expectedResult = SDL_TRUE;
1261 result = SDL_RectEmpty((const SDL_Rect *)&rect);
1262 _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
1269 * \brief Negative tests against SDL_RectEmpty() with invalid parameters
1272 * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
1274 int rect_testRectEmptyParam(void *arg)
1279 // invalid parameter combinations
1280 result = SDL_RectEmpty((const SDL_Rect *)NULL);
1281 AssertTrue(result = SDL_TRUE, "Function did not return TRUE when 1st parameter was NULL");