test/test-automation/tests/testrect/testrect.c
changeset 5948 05e6bfac079f
parent 5912 98471d04c8db
child 5951 b4c936b80652
equal deleted inserted replaced
5947:2abc5a4210d5 5948:05e6bfac079f
    75 		(TestCaseReference){ "rect_testUnionRectOutside", "Tests SDL_UnionRect where rect B is outside rect A", TEST_ENABLED, 0, 0 };
    75 		(TestCaseReference){ "rect_testUnionRectOutside", "Tests SDL_UnionRect where rect B is outside rect A", TEST_ENABLED, 0, 0 };
    76 
    76 
    77 static const TestCaseReference test21 =
    77 static const TestCaseReference test21 =
    78 		(TestCaseReference){ "rect_testUnionRectParam", "Negative tests against SDL_UnionRect with invalid parameters", TEST_ENABLED, 0, 0 };
    78 		(TestCaseReference){ "rect_testUnionRectParam", "Negative tests against SDL_UnionRect with invalid parameters", TEST_ENABLED, 0, 0 };
    79 
    79 
    80 /* TODO: SDL_RectEmpty */
    80 /* SDL_RectEmpty */
       
    81 static const TestCaseReference test22 =
       
    82 		(TestCaseReference){ "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED, 0, 0 };
       
    83 
       
    84 static const TestCaseReference test23 =
       
    85 		(TestCaseReference){ "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED, 0, 0 };
       
    86 
    81 /* TODO: SDL_RectEquals */
    87 /* TODO: SDL_RectEquals */
    82 
    88 
    83 /*!
    89 /*!
    84  * \brief Test suite for functions that handle simple rectangles including overlaps and merges.
    90  * \brief Test suite for functions that handle simple rectangles including overlaps and merges.
    85  *
    91  *
    86  * \sa
    92  * \sa
    87  * http://wiki.libsdl.org/moin.cgi/CategoryRect
    93  * http://wiki.libsdl.org/moin.cgi/CategoryRect
    88  */
    94  */
    89 extern const TestCaseReference *testSuite[] =  {
    95 extern const TestCaseReference *testSuite[] =  {
    90 	&test1, &test2, &test3, &test4, &test5, &test6, &test7, &test8, &test9, &test10, &test11, &test12, &test13, &test14, 
    96 	&test1, &test2, &test3, &test4, &test5, &test6, &test7, &test8, &test9, &test10, &test11, &test12, &test13, &test14, 
    91 	&test15, &test16, &test17, &test18, &test19, &test20, &test21, NULL
    97 	&test15, &test16, &test17, &test18, &test19, &test20, &test21, &test22, &test23, NULL
    92 };
    98 };
    93 
    99 
    94 TestCaseReference **QueryTestSuite() {
   100 TestCaseReference **QueryTestSuite() {
    95 	return (TestCaseReference **)testSuite;
   101 	return (TestCaseReference **)testSuite;
    96 }
   102 }
   398         "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)",
   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)",
   399         rectA->x, rectA->y, rectA->w, rectA->h, 
   405         rectA->x, rectA->y, rectA->w, rectA->h, 
   400         rectB->x, rectB->y, rectB->w, rectB->h,
   406         rectB->x, rectB->y, rectB->w, rectB->h,
   401         result->x, result->y, result->w, result->h,
   407         result->x, result->y, result->w, result->h,
   402         expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
   408         expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
       
   409 }
       
   410 
       
   411 /*!
       
   412  * \brief Private helper to check SDL_RectEmpty results
       
   413  */
       
   414 void _validateRectEmptyResults(
       
   415     SDL_bool empty, SDL_bool expectedEmpty, 
       
   416     SDL_Rect *rect, SDL_Rect *refRect)
       
   417 {
       
   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);
   403 }
   427 }
   404 
   428 
   405 /*!
   429 /*!
   406  * \brief Tests SDL_IntersectRect() with B fully inside A
   430  * \brief Tests SDL_IntersectRect() with B fully inside A
   407  *
   431  *
  1197     SDL_UnionRect(&rectA, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
  1221     SDL_UnionRect(&rectA, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
  1198     AssertPass("Function did return when 2nd and 3rd parameter were NULL"); 
  1222     AssertPass("Function did return when 2nd and 3rd parameter were NULL"); 
  1199     SDL_UnionRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
  1223     SDL_UnionRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
  1200     AssertPass("Function did return when all parameters were NULL"); 
  1224     AssertPass("Function did return when all parameters were NULL"); 
  1201 }
  1225 }
       
  1226 
       
  1227 /*!
       
  1228  * \brief Tests SDL_RectEmpty() with various inputs
       
  1229  *
       
  1230  * \sa
       
  1231  * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
       
  1232  */
       
  1233 int rect_testRectEmpty(void *arg)
       
  1234 {
       
  1235     SDL_Rect refRect;
       
  1236     SDL_Rect rect;
       
  1237     SDL_bool expectedResult;
       
  1238     SDL_bool result;
       
  1239     int w, h;
       
  1240 
       
  1241     // Non-empty case
       
  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;
       
  1247     rect = refRect;
       
  1248     result = SDL_RectEmpty((const SDL_Rect *)&rect);
       
  1249     _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
       
  1250     
       
  1251     // Empty case
       
  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);
       
  1257                 refRect.w=w;
       
  1258                 refRect.h=h;
       
  1259                 expectedResult = SDL_TRUE;
       
  1260                 rect = refRect;
       
  1261                 result = SDL_RectEmpty((const SDL_Rect *)&rect);
       
  1262                 _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
       
  1263             }
       
  1264         }
       
  1265     }
       
  1266 }
       
  1267 
       
  1268 /*!
       
  1269  * \brief Negative tests against SDL_RectEmpty() with invalid parameters
       
  1270  *
       
  1271  * \sa
       
  1272  * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
       
  1273  */
       
  1274 int rect_testRectEmptyParam(void *arg)
       
  1275 {
       
  1276     SDL_Rect rect;
       
  1277     SDL_bool result;
       
  1278 
       
  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"); 
       
  1282 }