comparison 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
comparison
equal deleted inserted replaced
3723:1496cdbb6055 3724:48e2b67bb2de
94 94
95 95
96 /** 96 /**
97 * @brief Tests sprite loading. 97 * @brief Tests sprite loading.
98 */ 98 */
99 static void surface_testLoad (void) 99 static void surface_testLoad( SDL_Surface *testsur )
100 { 100 {
101 int ret; 101 int ret;
102 SDL_Surface *face, *rface, *testsur; 102 SDL_Surface *face, *rface;
103 103
104 SDL_ATbegin( "Load Test" ); 104 SDL_ATbegin( "Load Test" );
105
106 /* Clear surface. */
107 ret = SDL_FillRect( testsur, NULL,
108 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
109 if (SDL_ATassert( "SDL_FillRect", ret == 0))
110 return;
105 111
106 /* Create the blit surface. */ 112 /* Create the blit surface. */
107 face = SDL_LoadBMP("../icon.bmp"); 113 face = SDL_LoadBMP("../icon.bmp");
108 if (SDL_ATassert( "SDL_CreateLoadBmp", face != NULL)) 114 if (SDL_ATassert( "SDL_CreateLoadBmp", face != NULL))
109 return; 115 return;
114 *(Uint8 *) face->pixels); 120 *(Uint8 *) face->pixels);
115 if (SDL_ATassert( "SDL_SetColorKey", ret == 0)) 121 if (SDL_ATassert( "SDL_SetColorKey", ret == 0))
116 return; 122 return;
117 } 123 }
118 124
119 /* Create the test surface. */
120 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32,
121 RMASK, GMASK, BMASK, AMASK );
122 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
123 return;
124
125 /* Convert to 32 bit to compare. */ 125 /* Convert to 32 bit to compare. */
126 rface = SDL_ConvertSurface( face, testsur->format, 0 ); 126 rface = SDL_ConvertSurface( face, testsur->format, 0 );
127 if (SDL_ATassert( "SDL_ConvertSurface", rface != NULL)) 127 if (SDL_ATassert( "SDL_ConvertSurface", rface != NULL))
128 return; 128 return;
129 129
131 if (SDL_ATassert( "Primitives output not the same.", 131 if (SDL_ATassert( "Primitives output not the same.",
132 surface_compare( rface, &img_face)==0 )) 132 surface_compare( rface, &img_face)==0 ))
133 return; 133 return;
134 134
135 /* Clean up. */ 135 /* Clean up. */
136 SDL_FreeSurface( testsur );
137 SDL_FreeSurface( rface ); 136 SDL_FreeSurface( rface );
138 SDL_FreeSurface( face ); 137 SDL_FreeSurface( face );
139 138
140 SDL_ATend(); 139 SDL_ATend();
141 } 140 }
142 141
143 142
144 /** 143 /**
145 * @brief Tests the SDL primitives for rendering. 144 * @brief Tests the SDL primitives for rendering.
146 */ 145 */
147 static void surface_testPrimitives (void) 146 static void surface_testPrimitives( SDL_Surface *testsur )
148 { 147 {
149 int ret; 148 int ret;
150 int x, y; 149 int x, y;
151 SDL_Rect rect; 150 SDL_Rect rect;
152 SDL_Surface *testsur;
153 151
154 SDL_ATbegin( "Primitives Test" ); 152 SDL_ATbegin( "Primitives Test" );
153
154 /* Clear surface. */
155 ret = SDL_FillRect( testsur, NULL,
156 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
157 if (SDL_ATassert( "SDL_FillRect", ret == 0))
158 return;
155 159
156 /* Create the surface. */ 160 /* Create the surface. */
157 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 161 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32,
158 RMASK, GMASK, BMASK, AMASK ); 162 RMASK, GMASK, BMASK, AMASK );
159 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) 163 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
209 /* See if it's the same. */ 213 /* See if it's the same. */
210 if (SDL_ATassert( "Primitives output not the same.", 214 if (SDL_ATassert( "Primitives output not the same.",
211 surface_compare( testsur, &img_primitives )==0 )) 215 surface_compare( testsur, &img_primitives )==0 ))
212 return; 216 return;
213 217
214 /* Clean up. */
215 SDL_FreeSurface( testsur );
216
217 SDL_ATend(); 218 SDL_ATend();
218 } 219 }
219 220
220 221
221 /** 222 /**
222 * @brief Tests the SDL primitives with alpha for rendering. 223 * @brief Tests the SDL primitives with alpha for rendering.
223 */ 224 */
224 static void surface_testPrimitivesBlend (void) 225 static void surface_testPrimitivesBlend( SDL_Surface *testsur )
225 { 226 {
226 int ret; 227 int ret;
227 int i, j; 228 int i, j;
228 SDL_Rect rect; 229 SDL_Rect rect;
229 SDL_Surface *testsur;
230 230
231 SDL_ATbegin( "Primitives Blend Test" ); 231 SDL_ATbegin( "Primitives Blend Test" );
232 232
233 /* Create the surface. */ 233 /* Clear surface. */
234 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 234 ret = SDL_FillRect( testsur, NULL,
235 RMASK, GMASK, BMASK, AMASK ); 235 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
236 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) 236 if (SDL_ATassert( "SDL_FillRect", ret == 0))
237 return; 237 return;
238 238
239 /* Create some rectangles for each blend mode. */ 239 /* Create some rectangles for each blend mode. */
240 ret = SDL_BlendRect( testsur, NULL, SDL_BLENDMODE_NONE, 255, 255, 255, 0 ); 240 ret = SDL_BlendRect( testsur, NULL, SDL_BLENDMODE_NONE, 255, 255, 255, 0 );
241 if (SDL_ATassert( "SDL_BlendRect", ret == 0)) 241 if (SDL_ATassert( "SDL_BlendRect", ret == 0))
295 /* See if it's the same. */ 295 /* See if it's the same. */
296 if (SDL_ATassert( "Primitives output not the same.", 296 if (SDL_ATassert( "Primitives output not the same.",
297 surface_compare( testsur, &img_blend )==0 )) 297 surface_compare( testsur, &img_blend )==0 ))
298 return; 298 return;
299 299
300 /* Clean up. */
301 SDL_FreeSurface( testsur );
302
303 SDL_ATend(); 300 SDL_ATend();
304 } 301 }
305 302
306 303
307 /** 304 /**
308 * @brief Tests some blitting routines. 305 * @brief Tests some blitting routines.
309 */ 306 */
310 static void surface_testBlit (void) 307 static void surface_testBlit( SDL_Surface *testsur )
311 { 308 {
312 int ret; 309 int ret;
313 SDL_Rect rect; 310 SDL_Rect rect;
314 SDL_Surface *face, *testsur; 311 SDL_Surface *face;
315 int i, j, ni, nj; 312 int i, j, ni, nj;
316 313
317 SDL_ATbegin( "Blit Tests" ); 314 SDL_ATbegin( "Blit Tests" );
315
316 /* Clear surface. */
317 ret = SDL_FillRect( testsur, NULL,
318 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
319 if (SDL_ATassert( "SDL_FillRect", ret == 0))
320 return;
318 321
319 /* Create face surface. */ 322 /* Create face surface. */
320 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, 323 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
321 img_face.width, img_face.height, 32, img_face.width*4, 324 img_face.width, img_face.height, 32, img_face.width*4,
322 RMASK, GMASK, BMASK, AMASK ); 325 RMASK, GMASK, BMASK, AMASK );
323 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) 326 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
324 return;
325
326 /* Create the test surface. */
327 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32,
328 RMASK, GMASK, BMASK, AMASK );
329 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
330 return; 327 return;
331 328
332 /* Constant values. */ 329 /* Constant values. */
333 rect.w = face->w; 330 rect.w = face->w;
334 rect.h = face->h; 331 rect.h = face->h;
413 surface_compare( testsur, &img_blitAlpha )==0 )) 410 surface_compare( testsur, &img_blitAlpha )==0 ))
414 return; 411 return;
415 412
416 /* Clean up. */ 413 /* Clean up. */
417 SDL_FreeSurface( face ); 414 SDL_FreeSurface( face );
418 SDL_FreeSurface( testsur );
419 415
420 SDL_ATend(); 416 SDL_ATend();
421 } 417 }
422 418
423 419
466 462
467 463
468 /** 464 /**
469 * @brief Tests some more blitting routines. 465 * @brief Tests some more blitting routines.
470 */ 466 */
471 static void surface_testBlitBlend (void) 467 static void surface_testBlitBlend( SDL_Surface *testsur )
472 { 468 {
473 int ret; 469 int ret;
474 SDL_Rect rect; 470 SDL_Rect rect;
475 SDL_Surface *face, *testsur; 471 SDL_Surface *face;
476 int i, j, ni, nj; 472 int i, j, ni, nj;
477 int mode; 473 int mode;
478 474
479 SDL_ATbegin( "Blit Blending Tests" ); 475 SDL_ATbegin( "Blit Blending Tests" );
476
477 /* Clear surface. */
478 ret = SDL_FillRect( testsur, NULL,
479 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
480 if (SDL_ATassert( "SDL_FillRect", ret == 0))
481 return;
480 482
481 /* Create the blit surface. */ 483 /* Create the blit surface. */
482 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, 484 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
483 img_face.width, img_face.height, 32, img_face.width*4, 485 img_face.width, img_face.height, 32, img_face.width*4,
484 RMASK, GMASK, BMASK, AMASK ); 486 RMASK, GMASK, BMASK, AMASK );
485 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) 487 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
486 return;
487
488 /* Create the test surface. */
489 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32,
490 RMASK, GMASK, BMASK, AMASK );
491 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
492 return; 488 return;
493 489
494 /* Set alpha mod. */ 490 /* Set alpha mod. */
495 ret = SDL_SetSurfaceAlphaMod( face, 100 ); 491 ret = SDL_SetSurfaceAlphaMod( face, 100 );
496 if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0)) 492 if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0))
583 surface_compare( testsur, &img_blendAll )==0 )) 579 surface_compare( testsur, &img_blendAll )==0 ))
584 return; 580 return;
585 581
586 /* Clean up. */ 582 /* Clean up. */
587 SDL_FreeSurface( face ); 583 SDL_FreeSurface( face );
588 SDL_FreeSurface( testsur );
589 584
590 SDL_ATend(); 585 SDL_ATend();
591 } 586 }
592 587
593 588
596 */ 591 */
597 int main( int argc, const char *argv[] ) 592 int main( int argc, const char *argv[] )
598 { 593 {
599 (void) argc; 594 (void) argc;
600 (void) argv; 595 (void) argv;
596 SDL_Surface *testsur;
601 597
602 SDL_ATinit( "SDL_Surface" ); 598 SDL_ATinit( "SDL_Surface" );
603 599
604 /* Initializes the SDL subsystems. */ 600 /* Initializes the SDL subsystems. */
605 SDL_Init(0); 601 SDL_Init(0);
606 602
607 surface_testLoad(); 603 SDL_ATbegin( "Creating Testsurface" );
608 surface_testPrimitives(); 604 /* Create the test surface. */
609 surface_testPrimitivesBlend(); 605 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32,
610 surface_testBlit(); 606 RMASK, GMASK, BMASK, AMASK );
611 surface_testBlitBlend(); 607 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
608 return -1;
609 SDL_ATend();
610
611 /* Software blitting. */
612 surface_testLoad( testsur );
613 surface_testPrimitives( testsur );
614 surface_testPrimitivesBlend( testsur );
615 surface_testBlit( testsur );
616 surface_testBlitBlend( testsur );
617
618 /* Clean up. */
619 SDL_FreeSurface( testsur );
612 620
613 /* Exit SDL. */ 621 /* Exit SDL. */
614 SDL_Quit(); 622 SDL_Quit();
615 623
616 return SDL_ATfinish(1); 624 return SDL_ATfinish(1);