Mercurial > sdl-ios-xcode
comparison test/automated/surface/surface.c @ 3728:97e9704fc267 gsoc2009_unit_tests
Using common infrastructure.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Sat, 11 Jul 2009 19:21:48 +0000 |
parents | 48e2b67bb2de |
children | b7590cd5969d |
comparison
equal
deleted
inserted
replaced
3727:51900b161948 | 3728:97e9704fc267 |
---|---|
6 * Released under Public Domain. | 6 * Released under Public Domain. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SDL.h" | 10 #include "SDL.h" |
11 #include "SDL_surface.h" | |
12 #include "SDL_video.h" | |
11 #include "SDL_at.h" | 13 #include "SDL_at.h" |
12 | 14 |
13 | 15 #include "common/common.h" |
14 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) | |
15 # define RMASK 0xff000000 /**< Red bit mask. */ | |
16 # define GMASK 0x00ff0000 /**< Green bit mask. */ | |
17 # define BMASK 0x0000ff00 /**< Blue bit mask. */ | |
18 # define AMASK 0x000000ff /**< Alpha bit mask. */ | |
19 #else | |
20 # define RMASK 0x000000ff /**< Red bit mask. */ | |
21 # define GMASK 0x0000ff00 /**< Green bit mask. */ | |
22 # define BMASK 0x00ff0000 /**< Blue bit mask. */ | |
23 # define AMASK 0xff000000 /**< Alpha bit mask. */ | |
24 #endif | |
25 | |
26 | |
27 typedef struct SurfaceImage_s { | |
28 int width; | |
29 int height; | |
30 unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ | |
31 const unsigned char pixel_data[]; | |
32 } SurfaceImage_t; | |
33 | 16 |
34 | 17 |
35 /* | 18 /* |
36 * Pull in images for testcases. | 19 * Pull in images for testcases. |
37 */ | 20 */ |
38 #include "primitives.c" | 21 #include "common/images.h" |
39 #include "blend.c" | 22 |
40 #include "face.c" | 23 |
41 #include "blit.c" | 24 /* |
42 #include "blitblend.c" | 25 * Prototypes. |
43 | 26 */ |
44 | 27 /* Testcases. */ |
45 /** | 28 static void surface_testLoad( SDL_Surface *testsur ); |
46 * @brief Compares a surface and a surface image for equality. | 29 static void surface_testPrimitives( SDL_Surface *testsur ); |
47 * | 30 static void surface_testPrimitivesBlend( SDL_Surface *testsur ); |
48 * @param sur Surface to compare. | 31 static void surface_testBlit( SDL_Surface *testsur ); |
49 * @param img Image to compare against. | 32 static int surface_testBlitBlendMode( SDL_Surface *testsur, SDL_Surface *face, int mode ); |
50 * @return 0 if they are the same, -1 on error and positive if different. | 33 static void surface_testBlitBlend( SDL_Surface *testsur ); |
51 */ | |
52 static int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img ) | |
53 { | |
54 int ret; | |
55 int i,j; | |
56 int bpp; | |
57 Uint8 *p, *pd; | |
58 | |
59 /* Make sure size is the same. */ | |
60 if ((sur->w != img->width) || (sur->h != img->height)) | |
61 return -1; | |
62 | |
63 SDL_LockSurface( sur ); | |
64 | |
65 ret = 0; | |
66 bpp = sur->format->BytesPerPixel; | |
67 | |
68 /* Compare image - should be same format. */ | |
69 for (j=0; j<sur->h; j++) { | |
70 for (i=0; i<sur->w; i++) { | |
71 p = (Uint8 *)sur->pixels + j * sur->pitch + i * bpp; | |
72 pd = (Uint8 *)img->pixel_data + (j*img->width + i) * img->bytes_per_pixel; | |
73 switch (bpp) { | |
74 case 1: | |
75 case 2: | |
76 case 3: | |
77 ret += 1; | |
78 printf("%d BPP not supported yet.\n",bpp); | |
79 break; | |
80 | |
81 case 4: | |
82 ret += !( (p[0] == pd[0]) && | |
83 (p[1] == pd[1]) && | |
84 (p[2] == pd[2]) ); | |
85 break; | |
86 } | |
87 } | |
88 } | |
89 | |
90 SDL_UnlockSurface( sur ); | |
91 | |
92 return ret; | |
93 } | |
94 | 34 |
95 | 35 |
96 /** | 36 /** |
97 * @brief Tests sprite loading. | 37 * @brief Tests sprite loading. |
98 */ | 38 */ |
585 SDL_ATend(); | 525 SDL_ATend(); |
586 } | 526 } |
587 | 527 |
588 | 528 |
589 /** | 529 /** |
530 * @brief Runs all the tests on the surface. | |
531 * | |
532 * @param testsur Surface to run tests on. | |
533 */ | |
534 void surface_runTests( SDL_Surface *testsur ) | |
535 { | |
536 /* Software surface blitting. */ | |
537 surface_testPrimitives( testsur ); | |
538 surface_testPrimitivesBlend( testsur ); | |
539 surface_testBlit( testsur ); | |
540 surface_testBlitBlend( testsur ); | |
541 } | |
542 | |
543 | |
544 /** | |
590 * @brief Entry point. | 545 * @brief Entry point. |
591 */ | 546 */ |
592 int main( int argc, const char *argv[] ) | 547 int main( int argc, const char *argv[] ) |
593 { | 548 { |
594 (void) argc; | 549 (void) argc; |
595 (void) argv; | 550 (void) argv; |
551 int ret; | |
596 SDL_Surface *testsur; | 552 SDL_Surface *testsur; |
597 | 553 |
598 SDL_ATinit( "SDL_Surface" ); | 554 SDL_ATinit( "SDL_Surface" ); |
599 | 555 |
556 SDL_ATbegin( "Initializing" ); | |
600 /* Initializes the SDL subsystems. */ | 557 /* Initializes the SDL subsystems. */ |
601 SDL_Init(0); | 558 ret = SDL_Init(0); |
602 | 559 if (SDL_ATassert( "SDL_Init(0)", ret == 0)) |
603 SDL_ATbegin( "Creating Testsurface" ); | 560 goto err; |
561 | |
562 /* Now run on the video mode. */ | |
563 ret = SDL_InitSubSystem( SDL_INIT_VIDEO ); | |
564 if (SDL_ATassert( "SDL_InitSubSystem( SDL_INIT_VIDEO )", ret == 0)) | |
565 goto err; | |
566 | |
567 /* | |
568 * Surface on surface tests. | |
569 */ | |
604 /* Create the test surface. */ | 570 /* Create the test surface. */ |
605 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, | 571 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, |
606 RMASK, GMASK, BMASK, AMASK ); | 572 RMASK, GMASK, BMASK, AMASK ); |
607 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) | 573 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) |
608 return -1; | 574 goto err; |
609 SDL_ATend(); | 575 SDL_ATend(); |
610 | 576 /* Run surface on surface tests. */ |
611 /* Software blitting. */ | |
612 surface_testLoad( testsur ); | 577 surface_testLoad( testsur ); |
613 surface_testPrimitives( testsur ); | 578 surface_runTests( testsur ); |
614 surface_testPrimitivesBlend( testsur ); | |
615 surface_testBlit( testsur ); | |
616 surface_testBlitBlend( testsur ); | |
617 | |
618 /* Clean up. */ | 579 /* Clean up. */ |
619 SDL_FreeSurface( testsur ); | 580 SDL_FreeSurface( testsur ); |
620 | 581 |
621 /* Exit SDL. */ | 582 /* Exit SDL. */ |
622 SDL_Quit(); | 583 SDL_Quit(); |
623 | 584 |
624 return SDL_ATfinish(1); | 585 return SDL_ATfinish(1); |
625 } | 586 |
587 err: | |
588 return SDL_ATfinish(1); | |
589 } | |
590 |