Add test cases for SDL_RectEmpty
authorAndreas Schiffler
Fri, 16 Sep 2011 08:26:20 -0700
changeset 594805e6bfac079f
parent 5947 2abc5a4210d5
child 5949 b2668bd8c9dc
Add test cases for SDL_RectEmpty
test/test-automation/tests/testrect/testrect.c
     1.1 --- a/test/test-automation/tests/testrect/testrect.c	Fri Sep 16 08:25:49 2011 -0700
     1.2 +++ b/test/test-automation/tests/testrect/testrect.c	Fri Sep 16 08:26:20 2011 -0700
     1.3 @@ -77,7 +77,13 @@
     1.4  static const TestCaseReference test21 =
     1.5  		(TestCaseReference){ "rect_testUnionRectParam", "Negative tests against SDL_UnionRect with invalid parameters", TEST_ENABLED, 0, 0 };
     1.6  
     1.7 -/* TODO: SDL_RectEmpty */
     1.8 +/* SDL_RectEmpty */
     1.9 +static const TestCaseReference test22 =
    1.10 +		(TestCaseReference){ "rect_testRectEmpty", "Tests SDL_RectEmpty with various inputs", TEST_ENABLED, 0, 0 };
    1.11 +
    1.12 +static const TestCaseReference test23 =
    1.13 +		(TestCaseReference){ "rect_testRectEmptyParam", "Negative tests against SDL_RectEmpty with invalid parameters", TEST_ENABLED, 0, 0 };
    1.14 +
    1.15  /* TODO: SDL_RectEquals */
    1.16  
    1.17  /*!
    1.18 @@ -88,7 +94,7 @@
    1.19   */
    1.20  extern const TestCaseReference *testSuite[] =  {
    1.21  	&test1, &test2, &test3, &test4, &test5, &test6, &test7, &test8, &test9, &test10, &test11, &test12, &test13, &test14, 
    1.22 -	&test15, &test16, &test17, &test18, &test19, &test20, &test21, NULL
    1.23 +	&test15, &test16, &test17, &test18, &test19, &test20, &test21, &test22, &test23, NULL
    1.24  };
    1.25  
    1.26  TestCaseReference **QueryTestSuite() {
    1.27 @@ -403,6 +409,24 @@
    1.28  }
    1.29  
    1.30  /*!
    1.31 + * \brief Private helper to check SDL_RectEmpty results
    1.32 + */
    1.33 +void _validateRectEmptyResults(
    1.34 +    SDL_bool empty, SDL_bool expectedEmpty, 
    1.35 +    SDL_Rect *rect, SDL_Rect *refRect)
    1.36 +{
    1.37 +    AssertTrue(empty == expectedEmpty, 
    1.38 +        "Incorrect empty result: expected %s, got %s testing (%d,%d,%d,%d)\n",
    1.39 +        (expectedEmpty == SDL_TRUE) ? "true" : "false",
    1.40 +        (empty == SDL_TRUE) ? "true" : "false",
    1.41 +        rect->x, rect->y, rect->w, rect->h);
    1.42 +    AssertTrue(rect->x == refRect->x && rect->y == refRect->y && rect->w == refRect->w && rect->h == refRect->h,
    1.43 +        "Source rectangle was modified: got (%d,%d,%d,%d) expected (%d,%d,%d,%d)",
    1.44 +        rect->x, rect->y, rect->w, rect->h,
    1.45 +        refRect->x, refRect->y, refRect->w, refRect->h);
    1.46 +}
    1.47 +
    1.48 +/*!
    1.49   * \brief Tests SDL_IntersectRect() with B fully inside A
    1.50   *
    1.51   * \sa
    1.52 @@ -1199,3 +1223,60 @@
    1.53      SDL_UnionRect((SDL_Rect *)NULL, (SDL_Rect *)NULL, (SDL_Rect *)NULL);
    1.54      AssertPass("Function did return when all parameters were NULL"); 
    1.55  }
    1.56 +
    1.57 +/*!
    1.58 + * \brief Tests SDL_RectEmpty() with various inputs
    1.59 + *
    1.60 + * \sa
    1.61 + * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
    1.62 + */
    1.63 +int rect_testRectEmpty(void *arg)
    1.64 +{
    1.65 +    SDL_Rect refRect;
    1.66 +    SDL_Rect rect;
    1.67 +    SDL_bool expectedResult;
    1.68 +    SDL_bool result;
    1.69 +    int w, h;
    1.70 +
    1.71 +    // Non-empty case
    1.72 +    refRect.x=RandomIntegerInRange(-1024, 1024);
    1.73 +    refRect.y=RandomIntegerInRange(-1024, 1024);
    1.74 +    refRect.w=RandomIntegerInRange(256, 1024);
    1.75 +    refRect.h=RandomIntegerInRange(256, 1024);
    1.76 +    expectedResult = SDL_FALSE;
    1.77 +    rect = refRect;
    1.78 +    result = SDL_RectEmpty((const SDL_Rect *)&rect);
    1.79 +    _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
    1.80 +    
    1.81 +    // Empty case
    1.82 +    for (w=-1; w<2; w++) {
    1.83 +        for (h=-1; h<2; h++) {
    1.84 +            if ((w != 1) || (h != 1)) {
    1.85 +                refRect.x=RandomIntegerInRange(-1024, 1024);
    1.86 +                refRect.y=RandomIntegerInRange(-1024, 1024);
    1.87 +                refRect.w=w;
    1.88 +                refRect.h=h;
    1.89 +                expectedResult = SDL_TRUE;
    1.90 +                rect = refRect;
    1.91 +                result = SDL_RectEmpty((const SDL_Rect *)&rect);
    1.92 +                _validateRectEmptyResults(result, expectedResult, &rect, &refRect);
    1.93 +            }
    1.94 +        }
    1.95 +    }
    1.96 +}
    1.97 +
    1.98 +/*!
    1.99 + * \brief Negative tests against SDL_RectEmpty() with invalid parameters
   1.100 + *
   1.101 + * \sa
   1.102 + * http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
   1.103 + */
   1.104 +int rect_testRectEmptyParam(void *arg)
   1.105 +{
   1.106 +    SDL_Rect rect;
   1.107 +    SDL_bool result;
   1.108 +
   1.109 +    // invalid parameter combinations
   1.110 +    result = SDL_RectEmpty((const SDL_Rect *)NULL);
   1.111 +    AssertTrue(result = SDL_TRUE, "Function did not return TRUE when 1st parameter was NULL"); 
   1.112 +}