test/testautomation_surface.c
changeset 6779 c3b579c78059
parent 6773 5ebc5a9e35b4
child 6780 111b37940b35
     1.1 --- a/test/testautomation_surface.c	Sun Dec 30 09:58:03 2012 -0800
     1.2 +++ b/test/testautomation_surface.c	Sun Dec 30 10:58:18 2012 -0800
     1.3 @@ -11,34 +11,53 @@
     1.4  
     1.5  /* ================= Test Case Implementation ================== */
     1.6  
     1.7 -
     1.8  /* Shared test surface */
     1.9  
    1.10 -static SDL_Surface *testsurface = NULL;
    1.11 +static SDL_Surface *referenceSurface = NULL;
    1.12 +static SDL_Surface *testSurface = NULL;
    1.13 +
    1.14 +/* Helper functions for the test cases */
    1.15 +
    1.16 +#define TEST_SURFACE_WIDTH testSurface->w
    1.17 +#define TEST_SURFACE_HEIGHT testSurface->h
    1.18  
    1.19  /* Fixture */
    1.20  
    1.21 +/* Create a 32-bit writable surface for screen tests */
    1.22  void
    1.23  _surfaceSetUp(void *arg)
    1.24  {
    1.25 -   testsurface = SDLTest_ImageBlit();
    1.26 -   SDLTest_AssertCheck(testsurface != NULL, "Check that testsurface is not NULL");
    1.27 +    Uint32 rmask, gmask, bmask, amask;
    1.28 +#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    1.29 +    rmask = 0xff000000;
    1.30 +    gmask = 0x00ff0000;
    1.31 +    bmask = 0x0000ff00;
    1.32 +    amask = 0x000000ff;
    1.33 +#else
    1.34 +    rmask = 0x000000ff;
    1.35 +    gmask = 0x0000ff00;
    1.36 +    bmask = 0x00ff0000;
    1.37 +    amask = 0xff000000;
    1.38 +#endif
    1.39 +
    1.40 +	referenceSurface = SDLTest_ImageBlit(); /* For size info */
    1.41 +	testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
    1.42 +    SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
    1.43  }
    1.44  
    1.45  void
    1.46  _surfaceTearDown(void *arg)
    1.47  {
    1.48 -	if (testsurface != NULL) {
    1.49 -		SDL_FreeSurface(testsurface);
    1.50 -		testsurface = NULL;
    1.51 +	if (referenceSurface != NULL) {
    1.52 +		SDL_FreeSurface(referenceSurface);
    1.53 +		referenceSurface = NULL;
    1.54 +	}
    1.55 +	if (testSurface != NULL) {
    1.56 +		SDL_FreeSurface(testSurface);
    1.57 +		testSurface = NULL;
    1.58  	}
    1.59  }
    1.60  
    1.61 -/* Helper functions for the test cases */
    1.62 -
    1.63 -#define TEST_SURFACE_WIDTH testsurface->w
    1.64 -#define TEST_SURFACE_HEIGHT testsurface->h
    1.65 -
    1.66  /**
    1.67   * Helper that clears the test surface
    1.68   */
    1.69 @@ -48,9 +67,9 @@
    1.70  	Uint32 color;
    1.71  	
    1.72  	/* Clear surface. */
    1.73 -	color = SDL_MapRGB( testsurface->format, 0, 0, 0);
    1.74 +	color = SDL_MapRGB( testSurface->format, 0, 0, 0);
    1.75  	SDLTest_AssertPass("Call to SDL_MapRGB()");
    1.76 -	ret = SDL_FillRect( testsurface, NULL, color);
    1.77 +	ret = SDL_FillRect( testSurface, NULL, color);
    1.78  	SDLTest_AssertPass("Call to SDL_FillRect()");
    1.79  	SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
    1.80  }
    1.81 @@ -64,16 +83,16 @@
    1.82  	int i, j, ni, nj;
    1.83  	SDL_Surface *face;
    1.84  	SDL_Rect rect;
    1.85 -	Uint32 color;
    1.86  	int nmode;
    1.87 +	SDL_BlendMode bmode;
    1.88  	int checkFailCount1;
    1.89  	int checkFailCount2;
    1.90  	int checkFailCount3;
    1.91  	int checkFailCount4;
    1.92  
    1.93  	/* Check test surface */
    1.94 -	SDLTest_AssertCheck(testsurface != NULL, "Verify testsurface is not NULL");
    1.95 -	if (testsurface == NULL) return;
    1.96 +	SDLTest_AssertCheck(testSurface != NULL, "Verify testSurface is not NULL");
    1.97 +	if (testSurface == NULL) return;
    1.98  	
    1.99  	/* Create sample surface */
   1.100  	face = SDLTest_ImageFace();
   1.101 @@ -88,8 +107,8 @@
   1.102  	rect.h = face->h;
   1.103  	
   1.104  	/* Steps to take */
   1.105 -	ni = testsurface->w - face->w;
   1.106 -	nj = testsurface->h - face->h;
   1.107 +	ni = testSurface->w - face->w;
   1.108 +	nj = testSurface->h - face->h;
   1.109  
   1.110  	/* Optionally set blend mode. */
   1.111  	if (mode >= 0) {
   1.112 @@ -118,18 +137,18 @@
   1.113  		else if (mode == -4) {
   1.114  			/* Crazy blending mode magic. */
   1.115  			nmode = (i/4*j/4) % 4;
   1.116 -			if (nmode==0) nmode = SDL_BLENDMODE_NONE;
   1.117 -			else if (nmode==1) nmode = SDL_BLENDMODE_BLEND;
   1.118 -			else if (nmode==2) nmode = SDL_BLENDMODE_ADD;
   1.119 -			else if (nmode==3) nmode = SDL_BLENDMODE_MOD;
   1.120 -			ret = SDL_SetSurfaceBlendMode( face, nmode );		
   1.121 +			if (nmode==0) bmode = SDL_BLENDMODE_NONE;
   1.122 +			else if (nmode==1) bmode = SDL_BLENDMODE_BLEND;
   1.123 +			else if (nmode==2) bmode = SDL_BLENDMODE_ADD;
   1.124 +			else if (nmode==3) bmode = SDL_BLENDMODE_MOD;
   1.125 +			ret = SDL_SetSurfaceBlendMode( face, bmode );		
   1.126  			if (ret != 0) checkFailCount4++;
   1.127  		}
   1.128  
   1.129  		 /* Blitting. */
   1.130  		 rect.x = i;
   1.131  		 rect.y = j;
   1.132 -		 ret = SDL_BlitSurface( face, NULL, testsurface, &rect );
   1.133 +		 ret = SDL_BlitSurface( face, NULL, testSurface, &rect );
   1.134  		 if (ret != 0) checkFailCount1++;
   1.135  	  }
   1.136  	}
   1.137 @@ -172,7 +191,7 @@
   1.138      /* Create sample surface */
   1.139      face = SDLTest_ImageFace();
   1.140      SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
   1.141 -    if (face == NULL) return;
   1.142 +    if (face == NULL) return TEST_ABORTED;
   1.143  
   1.144      /* Delete test file; ignore errors */
   1.145      unlink(sampleFilename);
   1.146 @@ -231,7 +250,7 @@
   1.147  	}
   1.148  
   1.149  	/* Convert to 32 bit to compare. */
   1.150 -	rface = SDL_ConvertSurface( face, testsurface->format, 0 );
   1.151 +	rface = SDL_ConvertSurface( face, testSurface->format, 0 );
   1.152  	SDLTest_AssertPass("Call to SDL_ConvertSurface()");
   1.153  	SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
   1.154  
   1.155 @@ -279,7 +298,7 @@
   1.156     
   1.157     /* Verify result by comparing surfaces */
   1.158     referenceSurface = SDLTest_ImageBlit();
   1.159 -   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
   1.160 +   ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 );
   1.161     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   1.162     
   1.163     /* Clean up. */
   1.164 @@ -304,7 +323,7 @@
   1.165     
   1.166     /* Verify result by comparing surfaces */
   1.167     referenceSurface = SDLTest_ImageBlitColor();
   1.168 -   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
   1.169 +   ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 );
   1.170     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   1.171     
   1.172     /* Clean up. */
   1.173 @@ -329,7 +348,7 @@
   1.174     
   1.175     /* Verify result by comparing surfaces */
   1.176     referenceSurface = SDLTest_ImageBlitAlpha();
   1.177 -   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
   1.178 +   ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 );
   1.179     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   1.180     
   1.181     /* Clean up. */
   1.182 @@ -355,7 +374,7 @@
   1.183     
   1.184     /* Verify result by comparing surfaces */
   1.185     referenceSurface = SDLTest_ImageBlitBlendNone();
   1.186 -   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
   1.187 +   ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 );
   1.188     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   1.189     
   1.190     /* Clean up. */
   1.191 @@ -380,7 +399,7 @@
   1.192     
   1.193     /* Verify result by comparing surfaces */
   1.194     referenceSurface = SDLTest_ImageBlitBlend();
   1.195 -   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
   1.196 +   ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 );
   1.197     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   1.198     
   1.199     /* Clean up. */
   1.200 @@ -405,7 +424,7 @@
   1.201     
   1.202     /* Verify result by comparing surfaces */
   1.203     referenceSurface = SDLTest_ImageBlitBlendAdd();
   1.204 -   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
   1.205 +   ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 );
   1.206     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   1.207     
   1.208     /* Clean up. */
   1.209 @@ -430,7 +449,7 @@
   1.210     
   1.211     /* Verify result by comparing surfaces */
   1.212     referenceSurface = SDLTest_ImageBlitBlendMod();
   1.213 -   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
   1.214 +   ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 );
   1.215     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   1.216     
   1.217     /* Clean up. */
   1.218 @@ -455,7 +474,7 @@
   1.219     
   1.220     /* Verify result by comparing surfaces */
   1.221     referenceSurface = SDLTest_ImageBlitBlendAll();
   1.222 -   ret = SDLTest_CompareSurfaces( testsurface, referenceSurface, 0 );
   1.223 +   ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 );
   1.224     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   1.225     
   1.226     /* Clean up. */