Mercurial > sdl-ios-xcode
diff test/automated/surface/surface.c @ 3724:48e2b67bb2de gsoc2009_unit_tests
Use testsur as a parameter.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Sat, 11 Jul 2009 17:57:49 +0000 |
parents | 1496cdbb6055 |
children | 97e9704fc267 |
line wrap: on
line diff
--- a/test/automated/surface/surface.c Thu Jul 09 15:01:38 2009 +0000 +++ b/test/automated/surface/surface.c Sat Jul 11 17:57:49 2009 +0000 @@ -96,13 +96,19 @@ /** * @brief Tests sprite loading. */ -static void surface_testLoad (void) +static void surface_testLoad( SDL_Surface *testsur ) { int ret; - SDL_Surface *face, *rface, *testsur; + SDL_Surface *face, *rface; SDL_ATbegin( "Load Test" ); + /* Clear surface. */ + ret = SDL_FillRect( testsur, NULL, + SDL_MapRGB( testsur->format, 0, 0, 0 ) ); + if (SDL_ATassert( "SDL_FillRect", ret == 0)) + return; + /* Create the blit surface. */ face = SDL_LoadBMP("../icon.bmp"); if (SDL_ATassert( "SDL_CreateLoadBmp", face != NULL)) @@ -116,12 +122,6 @@ return; } - /* Create the test surface. */ - testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, - RMASK, GMASK, BMASK, AMASK ); - if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) - return; - /* Convert to 32 bit to compare. */ rface = SDL_ConvertSurface( face, testsur->format, 0 ); if (SDL_ATassert( "SDL_ConvertSurface", rface != NULL)) @@ -133,7 +133,6 @@ return; /* Clean up. */ - SDL_FreeSurface( testsur ); SDL_FreeSurface( rface ); SDL_FreeSurface( face ); @@ -144,15 +143,20 @@ /** * @brief Tests the SDL primitives for rendering. */ -static void surface_testPrimitives (void) +static void surface_testPrimitives( SDL_Surface *testsur ) { int ret; int x, y; SDL_Rect rect; - SDL_Surface *testsur; SDL_ATbegin( "Primitives Test" ); + /* Clear surface. */ + ret = SDL_FillRect( testsur, NULL, + SDL_MapRGB( testsur->format, 0, 0, 0 ) ); + if (SDL_ATassert( "SDL_FillRect", ret == 0)) + return; + /* Create the surface. */ testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, RMASK, GMASK, BMASK, AMASK ); @@ -211,9 +215,6 @@ surface_compare( testsur, &img_primitives )==0 )) return; - /* Clean up. */ - SDL_FreeSurface( testsur ); - SDL_ATend(); } @@ -221,19 +222,18 @@ /** * @brief Tests the SDL primitives with alpha for rendering. */ -static void surface_testPrimitivesBlend (void) +static void surface_testPrimitivesBlend( SDL_Surface *testsur ) { int ret; int i, j; SDL_Rect rect; - SDL_Surface *testsur; SDL_ATbegin( "Primitives Blend Test" ); - /* Create the surface. */ - testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, - RMASK, GMASK, BMASK, AMASK ); - if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) + /* Clear surface. */ + ret = SDL_FillRect( testsur, NULL, + SDL_MapRGB( testsur->format, 0, 0, 0 ) ); + if (SDL_ATassert( "SDL_FillRect", ret == 0)) return; /* Create some rectangles for each blend mode. */ @@ -297,9 +297,6 @@ surface_compare( testsur, &img_blend )==0 )) return; - /* Clean up. */ - SDL_FreeSurface( testsur ); - SDL_ATend(); } @@ -307,15 +304,21 @@ /** * @brief Tests some blitting routines. */ -static void surface_testBlit (void) +static void surface_testBlit( SDL_Surface *testsur ) { int ret; SDL_Rect rect; - SDL_Surface *face, *testsur; + SDL_Surface *face; int i, j, ni, nj; SDL_ATbegin( "Blit Tests" ); + /* Clear surface. */ + ret = SDL_FillRect( testsur, NULL, + SDL_MapRGB( testsur->format, 0, 0, 0 ) ); + if (SDL_ATassert( "SDL_FillRect", ret == 0)) + return; + /* Create face surface. */ face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, img_face.width, img_face.height, 32, img_face.width*4, @@ -323,12 +326,6 @@ if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) return; - /* Create the test surface. */ - testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, - RMASK, GMASK, BMASK, AMASK ); - if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) - return; - /* Constant values. */ rect.w = face->w; rect.h = face->h; @@ -415,7 +412,6 @@ /* Clean up. */ SDL_FreeSurface( face ); - SDL_FreeSurface( testsur ); SDL_ATend(); } @@ -468,16 +464,22 @@ /** * @brief Tests some more blitting routines. */ -static void surface_testBlitBlend (void) +static void surface_testBlitBlend( SDL_Surface *testsur ) { int ret; SDL_Rect rect; - SDL_Surface *face, *testsur; + SDL_Surface *face; int i, j, ni, nj; int mode; SDL_ATbegin( "Blit Blending Tests" ); + /* Clear surface. */ + ret = SDL_FillRect( testsur, NULL, + SDL_MapRGB( testsur->format, 0, 0, 0 ) ); + if (SDL_ATassert( "SDL_FillRect", ret == 0)) + return; + /* Create the blit surface. */ face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, img_face.width, img_face.height, 32, img_face.width*4, @@ -485,12 +487,6 @@ if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) return; - /* Create the test surface. */ - testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, - RMASK, GMASK, BMASK, AMASK ); - if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) - return; - /* Set alpha mod. */ ret = SDL_SetSurfaceAlphaMod( face, 100 ); if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0)) @@ -585,7 +581,6 @@ /* Clean up. */ SDL_FreeSurface( face ); - SDL_FreeSurface( testsur ); SDL_ATend(); } @@ -598,17 +593,30 @@ { (void) argc; (void) argv; + SDL_Surface *testsur; SDL_ATinit( "SDL_Surface" ); /* Initializes the SDL subsystems. */ SDL_Init(0); - surface_testLoad(); - surface_testPrimitives(); - surface_testPrimitivesBlend(); - surface_testBlit(); - surface_testBlitBlend(); + SDL_ATbegin( "Creating Testsurface" ); + /* Create the test surface. */ + testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, + RMASK, GMASK, BMASK, AMASK ); + if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) + return -1; + SDL_ATend(); + + /* Software blitting. */ + surface_testLoad( testsur ); + surface_testPrimitives( testsur ); + surface_testPrimitivesBlend( testsur ); + surface_testBlit( testsur ); + surface_testBlitBlend( testsur ); + + /* Clean up. */ + SDL_FreeSurface( testsur ); /* Exit SDL. */ SDL_Quit();