diff --git a/test/test-automation/tests/testrect/testrect.c b/test/test-automation/tests/testrect/testrect.c index fb27bf900..6e19c8c6f 100644 --- a/test/test-automation/tests/testrect/testrect.c +++ b/test/test-automation/tests/testrect/testrect.c @@ -51,10 +51,23 @@ static const TestCaseReference test13 = static const TestCaseReference test14 = (TestCaseReference){ "rect_testHasIntersectionParam", "Negative tests against SDL_HasIntersection with invalid parameters", TEST_ENABLED, 0, 0 }; +static const TestCaseReference test15 = + (TestCaseReference){ "rect_testEnclosePoints", "Tests SDL_EnclosePoints without clipping", TEST_ENABLED, 0, 0 }; + +static const TestCaseReference test16 = + (TestCaseReference){ "rect_testEnclosePointsWithClipping", "Tests SDL_EnclosePoints with clipping", TEST_ENABLED, 0, 0 }; + +static const TestCaseReference test17 = + (TestCaseReference){ "rect_testEnclosePointsRepeatedInput", "Tests SDL_EnclosePoints with repeated input", TEST_ENABLED, 0, 0 }; + +static const TestCaseReference test18 = + (TestCaseReference){ "rect_testEnclosePointsParam", "Negative tests against SDL_EnclosePoints with invalid parameters", TEST_ENABLED, 0, 0 }; + /* Test suite */ extern const TestCaseReference *testSuite[] = { - &test1, &test2, &test3, &test4, &test5, &test6, &test7, &test8, &test9, &test10, &test11, &test12, &test13, &test14, NULL + &test1, &test2, &test3, &test4, &test5, &test6, &test7, &test8, &test9, &test10, &test11, &test12, &test13, &test14, + &test15, &test16, &test17, &test18, NULL }; TestCaseReference **QueryTestSuite() { @@ -737,3 +750,249 @@ int rect_testHasIntersectionParam(void *arg) intersection = SDL_HasIntersection((SDL_Rect *)NULL, (SDL_Rect *)NULL); AssertTrue(intersection == SDL_FALSE, "Function did not return false when all parameters were NULL"); } + +/*! + * \brief Test SDL_EnclosePoints() without clipping + * + * \sa + * http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints + */ +int rect_testEnclosePoints(void *arg) +{ + const int numPoints = 16; + SDL_Point refPoints[numPoints]; + SDL_Point points[numPoints]; + int count; + SDL_Rect result; + SDL_bool anyEnclosed; + SDL_bool anyEnclosedNoResult; + + // Create input data, tracking result + SDL_bool expectedEnclosed = SDL_TRUE; + int newx, newy; + int minx, maxx, miny, maxy; + int i; + for (i=0; imaxx) maxx=newx; + if (newymaxy) maxy=newy; + } + } + + // Call function and validate - special case: no result requested + anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL); + AssertTrue(expectedEnclosed==anyEnclosedNoResult, + "Expected return value %s, got %s", + (expectedEnclosed==SDL_TRUE) ? "true" : "false", (anyEnclosedNoResult==SDL_TRUE) ? "true" : "false"); + for (i=0; imaxx) maxx=newx; + if (newymaxy) maxy=newy; + } + } + + // Call function and validate - special case: no result requested + anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL); + AssertTrue(expectedEnclosed==anyEnclosedNoResult, + "Expected return value %s, got %s", + (expectedEnclosed==SDL_TRUE) ? "true" : "false", (anyEnclosedNoResult==SDL_TRUE) ? "true" : "false"); + for (i=0; i=refClip.x) && (newx<(refClip.x + refClip.w)) && + (newy>=refClip.y) && (newy<(refClip.y + refClip.h))) { + if (expectedEnclosed==SDL_FALSE) { + minx=maxx=newx; + miny=maxy=newy; + } else { + if (newxmaxx) maxx=newx; + if (newymaxy) maxy=newy; + } + expectedEnclosed = SDL_TRUE; + } + } + + // Call function and validate - special case: no result requested + clip = refClip; + anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, (SDL_Rect *)NULL); + AssertTrue(expectedEnclosed==anyEnclosedNoResult, + "Expected return value %s, got %s", + (expectedEnclosed==SDL_TRUE) ? "true" : "false", (anyEnclosedNoResult==SDL_TRUE) ? "true" : "false"); + for (i=0; i