@@ -1576,6 +1576,57 @@ static int SDLCALL surface_testOverflow(void *arg)
15761576 return TEST_COMPLETED ;
15771577}
15781578
1579+ static int surface_testSetGetSurfaceClipRect (void * args )
1580+ {
1581+ const struct {
1582+ SDL_Rect r ;
1583+ bool clipsetval ;
1584+ bool cmpval ;
1585+ } rect_list [] = {
1586+ { { 0 , 0 , 0 , 0 }, false, true},
1587+ { { 2 , 2 , 0 , 0 }, false, true},
1588+ { { 2 , 2 , 5 , 1 }, true, true},
1589+ { { 6 , 5 , 10 , 3 }, true, false},
1590+ { { 0 , 0 , 10 , 10 }, true, true},
1591+ { { 0 , 0 , -10 , 10 }, false, true},
1592+ { { 0 , 0 , -10 , -10 }, false, true},
1593+ { { -10 , -10 , 10 , 10 }, false, false},
1594+ { { 10 , -10 , 10 , 10 }, false, false},
1595+ { { 10 , 10 , 10 , 10 }, true, false}
1596+ };
1597+ SDL_Surface * s ;
1598+ SDL_Rect r ;
1599+ int i ;
1600+ bool b ;
1601+
1602+ SDLTest_AssertPass ("About to call SDL_CreateSurface(15, 15, SDL_PIXELFORMAT_RGBA32)" );
1603+ s = SDL_CreateSurface (15 , 15 , SDL_PIXELFORMAT_RGBA32 );
1604+ SDLTest_AssertCheck (s != NULL , "SDL_CreateSurface returned non-null surface" );
1605+ SDL_zero (r );
1606+ b = SDL_GetSurfaceClipRect (s , & r );
1607+ SDLTest_AssertCheck (b , "SDL_GetSurfaceClipRect succeeded (%s)" , SDL_GetError ());
1608+ SDLTest_AssertCheck (r .x == 0 && r .y == 0 && r .w == 15 && r .h == 15 ,
1609+ "SDL_GetSurfaceClipRect of just-created surface. Got {%d, %d, %d, %d}. (Expected {%d, %d, %d, %d})" ,
1610+ r .x , r .y , r .w , r .h , 0 , 0 , 15 , 15 );
1611+
1612+ for (i = 0 ; i < SDL_arraysize (rect_list ); i ++ ) {
1613+ const SDL_Rect * r_in = & rect_list [i ].r ;
1614+ SDL_Rect r_out ;
1615+
1616+ SDLTest_AssertPass ("About to do SDL_SetClipRect({%d, %d, %d, %d})" , r_in -> x , r_in -> y , r_in -> w , r_in -> h );
1617+ b = SDL_SetSurfaceClipRect (s , r_in );
1618+ SDLTest_AssertCheck (b == rect_list [i ].clipsetval , "SDL_SetSurfaceClipRect returned %d (expected %d)" , b , rect_list [i ].clipsetval );
1619+ SDL_zero (r_out );
1620+ SDL_GetSurfaceClipRect (s , & r_out );
1621+ SDLTest_AssertPass ("SDL_GetSurfaceClipRect returned {%d, %d, %d, %d}" , r_out .x , r_out .y , r_out .w , r_out .h );
1622+ b = r_out .x == r_in -> x && r_out .y == r_in -> y && r_out .w == r_in -> w && r_out .h == r_in -> h ;
1623+ SDLTest_AssertCheck (b == rect_list [i ].cmpval , "Current clipping rect is identical to input clipping rect: %d (expected %d)" ,
1624+ b , rect_list [i ].cmpval );
1625+ }
1626+ SDL_DestroySurface (s );
1627+ return TEST_COMPLETED ;
1628+ };
1629+
15791630static int SDLCALL surface_testFlip (void * arg )
15801631{
15811632 SDL_Surface * surface ;
@@ -2147,6 +2198,10 @@ static const SDLTest_TestCaseReference surfaceTestOverflow = {
21472198 surface_testOverflow , "surface_testOverflow" , "Test overflow detection." , TEST_ENABLED
21482199};
21492200
2201+ static const SDLTest_TestCaseReference surfaceTestSetGetClipRect = {
2202+ surface_testSetGetSurfaceClipRect , "surface_testSetGetSurfaceClipRect" , "Test SDL_(Set|Get)SurfaceClipRect." , TEST_ENABLED
2203+ };
2204+
21502205static const SDLTest_TestCaseReference surfaceTestFlip = {
21512206 surface_testFlip , "surface_testFlip" , "Test surface flipping." , TEST_ENABLED
21522207};
@@ -2201,6 +2256,7 @@ static const SDLTest_TestCaseReference *surfaceTests[] = {
22012256 & surfaceTestBlitInvalid ,
22022257 & surfaceTestBlitsWithBadCoordinates ,
22032258 & surfaceTestOverflow ,
2259+ & surfaceTestSetGetClipRect ,
22042260 & surfaceTestFlip ,
22052261 & surfaceTestPalette ,
22062262 & surfaceTestPalettization ,
0 commit comments