Use testsur as a parameter. gsoc2009_unit_tests
authorEdgar Simo <bobbens@gmail.com>
Sat, 11 Jul 2009 17:57:49 +0000
branchgsoc2009_unit_tests
changeset 372448e2b67bb2de
parent 3723 1496cdbb6055
child 3725 6eca2af6a86b
Use testsur as a parameter.
test/automated/surface/surface.c
     1.1 --- a/test/automated/surface/surface.c	Thu Jul 09 15:01:38 2009 +0000
     1.2 +++ b/test/automated/surface/surface.c	Sat Jul 11 17:57:49 2009 +0000
     1.3 @@ -96,13 +96,19 @@
     1.4  /**
     1.5   * @brief Tests sprite loading.
     1.6   */
     1.7 -static void surface_testLoad (void)
     1.8 +static void surface_testLoad( SDL_Surface *testsur )
     1.9  {
    1.10     int ret;
    1.11 -   SDL_Surface *face, *rface, *testsur;
    1.12 +   SDL_Surface *face, *rface;
    1.13  
    1.14     SDL_ATbegin( "Load Test" );
    1.15  
    1.16 +   /* Clear surface. */
    1.17 +   ret = SDL_FillRect( testsur, NULL,
    1.18 +         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
    1.19 +   if (SDL_ATassert( "SDL_FillRect", ret == 0))
    1.20 +      return;
    1.21 +
    1.22     /* Create the blit surface. */
    1.23     face = SDL_LoadBMP("../icon.bmp");
    1.24     if (SDL_ATassert( "SDL_CreateLoadBmp", face != NULL))
    1.25 @@ -116,12 +122,6 @@
    1.26           return;
    1.27     }
    1.28  
    1.29 -   /* Create the test surface. */
    1.30 -   testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
    1.31 -         RMASK, GMASK, BMASK, AMASK );
    1.32 -   if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
    1.33 -      return;
    1.34 -
    1.35     /* Convert to 32 bit to compare. */
    1.36     rface = SDL_ConvertSurface( face, testsur->format, 0 );
    1.37     if (SDL_ATassert( "SDL_ConvertSurface", rface != NULL))
    1.38 @@ -133,7 +133,6 @@
    1.39        return;
    1.40  
    1.41     /* Clean up. */
    1.42 -   SDL_FreeSurface( testsur );
    1.43     SDL_FreeSurface( rface );
    1.44     SDL_FreeSurface( face );
    1.45  
    1.46 @@ -144,15 +143,20 @@
    1.47  /**
    1.48   * @brief Tests the SDL primitives for rendering.
    1.49   */
    1.50 -static void surface_testPrimitives (void)
    1.51 +static void surface_testPrimitives( SDL_Surface *testsur )
    1.52  {
    1.53     int ret;
    1.54     int x, y;
    1.55     SDL_Rect rect;
    1.56 -   SDL_Surface *testsur;
    1.57  
    1.58     SDL_ATbegin( "Primitives Test" );
    1.59  
    1.60 +   /* Clear surface. */
    1.61 +   ret = SDL_FillRect( testsur, NULL,
    1.62 +         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
    1.63 +   if (SDL_ATassert( "SDL_FillRect", ret == 0))
    1.64 +      return;
    1.65 +
    1.66     /* Create the surface. */
    1.67     testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
    1.68           RMASK, GMASK, BMASK, AMASK );
    1.69 @@ -211,9 +215,6 @@
    1.70              surface_compare( testsur, &img_primitives )==0 ))
    1.71        return;
    1.72  
    1.73 -   /* Clean up. */
    1.74 -   SDL_FreeSurface( testsur );
    1.75 -
    1.76     SDL_ATend();
    1.77  }
    1.78  
    1.79 @@ -221,19 +222,18 @@
    1.80  /**
    1.81   * @brief Tests the SDL primitives with alpha for rendering.
    1.82   */
    1.83 -static void surface_testPrimitivesBlend (void)
    1.84 +static void surface_testPrimitivesBlend( SDL_Surface *testsur )
    1.85  {
    1.86     int ret;
    1.87     int i, j;
    1.88     SDL_Rect rect;
    1.89 -   SDL_Surface *testsur;
    1.90  
    1.91     SDL_ATbegin( "Primitives Blend Test" );
    1.92  
    1.93 -   /* Create the surface. */
    1.94 -   testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
    1.95 -         RMASK, GMASK, BMASK, AMASK );
    1.96 -   if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
    1.97 +   /* Clear surface. */
    1.98 +   ret = SDL_FillRect( testsur, NULL,
    1.99 +         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
   1.100 +   if (SDL_ATassert( "SDL_FillRect", ret == 0))
   1.101        return;
   1.102  
   1.103     /* Create some rectangles for each blend mode. */
   1.104 @@ -297,9 +297,6 @@
   1.105              surface_compare( testsur, &img_blend )==0 ))
   1.106        return;
   1.107  
   1.108 -   /* Clean up. */
   1.109 -   SDL_FreeSurface( testsur );
   1.110 -
   1.111     SDL_ATend();
   1.112  }
   1.113  
   1.114 @@ -307,15 +304,21 @@
   1.115  /**
   1.116   * @brief Tests some blitting routines.
   1.117   */
   1.118 -static void surface_testBlit (void)
   1.119 +static void surface_testBlit( SDL_Surface *testsur )
   1.120  {
   1.121     int ret;
   1.122     SDL_Rect rect;
   1.123 -   SDL_Surface *face, *testsur;
   1.124 +   SDL_Surface *face;
   1.125     int i, j, ni, nj;
   1.126  
   1.127     SDL_ATbegin( "Blit Tests" );
   1.128  
   1.129 +   /* Clear surface. */
   1.130 +   ret = SDL_FillRect( testsur, NULL,
   1.131 +         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
   1.132 +   if (SDL_ATassert( "SDL_FillRect", ret == 0))
   1.133 +      return;
   1.134 +
   1.135     /* Create face surface. */
   1.136     face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
   1.137           img_face.width, img_face.height, 32, img_face.width*4,
   1.138 @@ -323,12 +326,6 @@
   1.139     if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
   1.140        return;
   1.141  
   1.142 -   /* Create the test surface. */
   1.143 -   testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
   1.144 -         RMASK, GMASK, BMASK, AMASK );
   1.145 -   if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
   1.146 -      return;
   1.147 -
   1.148     /* Constant values. */
   1.149     rect.w = face->w;
   1.150     rect.h = face->h;
   1.151 @@ -415,7 +412,6 @@
   1.152  
   1.153     /* Clean up. */
   1.154     SDL_FreeSurface( face );
   1.155 -   SDL_FreeSurface( testsur );
   1.156  
   1.157     SDL_ATend();
   1.158  }
   1.159 @@ -468,16 +464,22 @@
   1.160  /**
   1.161   * @brief Tests some more blitting routines.
   1.162   */
   1.163 -static void surface_testBlitBlend (void)
   1.164 +static void surface_testBlitBlend( SDL_Surface *testsur )
   1.165  {
   1.166     int ret;
   1.167     SDL_Rect rect;
   1.168 -   SDL_Surface *face, *testsur;
   1.169 +   SDL_Surface *face;
   1.170     int i, j, ni, nj;
   1.171     int mode;
   1.172  
   1.173     SDL_ATbegin( "Blit Blending Tests" );
   1.174  
   1.175 +   /* Clear surface. */
   1.176 +   ret = SDL_FillRect( testsur, NULL,
   1.177 +         SDL_MapRGB( testsur->format, 0, 0, 0 ) );
   1.178 +   if (SDL_ATassert( "SDL_FillRect", ret == 0))
   1.179 +      return;
   1.180 +
   1.181     /* Create the blit surface. */
   1.182     face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
   1.183           img_face.width, img_face.height, 32, img_face.width*4,
   1.184 @@ -485,12 +487,6 @@
   1.185     if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
   1.186        return;
   1.187  
   1.188 -   /* Create the test surface. */
   1.189 -   testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
   1.190 -         RMASK, GMASK, BMASK, AMASK );
   1.191 -   if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
   1.192 -      return;
   1.193 -
   1.194     /* Set alpha mod. */
   1.195     ret = SDL_SetSurfaceAlphaMod( face, 100 );
   1.196     if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0))
   1.197 @@ -585,7 +581,6 @@
   1.198  
   1.199     /* Clean up. */
   1.200     SDL_FreeSurface( face );
   1.201 -   SDL_FreeSurface( testsur );
   1.202  
   1.203     SDL_ATend();
   1.204  }
   1.205 @@ -598,17 +593,30 @@
   1.206  {
   1.207     (void) argc;
   1.208     (void) argv;
   1.209 +   SDL_Surface *testsur;
   1.210  
   1.211     SDL_ATinit( "SDL_Surface" );
   1.212  
   1.213     /* Initializes the SDL subsystems. */
   1.214     SDL_Init(0);
   1.215  
   1.216 -   surface_testLoad();
   1.217 -   surface_testPrimitives();
   1.218 -   surface_testPrimitivesBlend();
   1.219 -   surface_testBlit();
   1.220 -   surface_testBlitBlend();
   1.221 +   SDL_ATbegin( "Creating Testsurface" );
   1.222 +   /* Create the test surface. */
   1.223 +   testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 
   1.224 +         RMASK, GMASK, BMASK, AMASK );
   1.225 +   if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
   1.226 +      return -1;
   1.227 +   SDL_ATend();
   1.228 +
   1.229 +   /* Software blitting. */
   1.230 +   surface_testLoad( testsur );
   1.231 +   surface_testPrimitives( testsur );
   1.232 +   surface_testPrimitivesBlend( testsur );
   1.233 +   surface_testBlit( testsur );
   1.234 +   surface_testBlitBlend( testsur );
   1.235 +
   1.236 +   /* Clean up. */
   1.237 +   SDL_FreeSurface( testsur );
   1.238  
   1.239     /* Exit SDL. */
   1.240     SDL_Quit();