test/testautomation_surface.c
changeset 6811 60d95fcfaf3c
parent 6780 111b37940b35
child 6822 18f6818ba281
equal deleted inserted replaced
6810:b5609445aa4c 6811:60d95fcfaf3c
    25 #define TEST_SURFACE_WIDTH testSurface->w
    25 #define TEST_SURFACE_WIDTH testSurface->w
    26 #define TEST_SURFACE_HEIGHT testSurface->h
    26 #define TEST_SURFACE_HEIGHT testSurface->h
    27 
    27 
    28 /* Fixture */
    28 /* Fixture */
    29 
    29 
    30 /* Create a 32-bit writable surface for screen tests */
    30 /* Create a 32-bit writable surface for blitting tests */
    31 void
    31 void
    32 _surfaceSetUp(void *arg)
    32 _surfaceSetUp(void *arg)
    33 {
    33 {
       
    34     int result;
       
    35     SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
       
    36     SDL_BlendMode currentBlendMode;
    34     Uint32 rmask, gmask, bmask, amask;
    37     Uint32 rmask, gmask, bmask, amask;
    35 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
    38 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
    36     rmask = 0xff000000;
    39     rmask = 0xff000000;
    37     gmask = 0x00ff0000;
    40     gmask = 0x00ff0000;
    38     bmask = 0x0000ff00;
    41     bmask = 0x0000ff00;
    42     gmask = 0x0000ff00;
    45     gmask = 0x0000ff00;
    43     bmask = 0x00ff0000;
    46     bmask = 0x00ff0000;
    44     amask = 0xff000000;
    47     amask = 0xff000000;
    45 #endif
    48 #endif
    46 
    49 
    47 	referenceSurface = SDLTest_ImageBlit(); /* For size info */
    50     referenceSurface = SDLTest_ImageBlit(); /* For size info */
    48 	testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
    51     testSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask);
    49     SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
    52     SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
       
    53     if (testSurface != NULL) {
       
    54       /* Disable blend mode for target surface */
       
    55       result = SDL_SetSurfaceBlendMode(testSurface, blendMode);
       
    56       SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result);
       
    57       result = SDL_GetSurfaceBlendMode(testSurface, &currentBlendMode);
       
    58       SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result);
       
    59       SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %i, got: %i", blendMode, currentBlendMode);      
       
    60     }
    50 }
    61 }
    51 
    62 
    52 void
    63 void
    53 _surfaceTearDown(void *arg)
    64 _surfaceTearDown(void *arg)
    54 {
    65 {
    67  */
    78  */
    68 void _clearTestSurface()
    79 void _clearTestSurface()
    69 {
    80 {
    70 	int ret;
    81 	int ret;
    71 	Uint32 color;
    82 	Uint32 color;
    72 	
    83 
    73 	/* Clear surface. */
    84 	/* Clear surface. */
    74 	color = SDL_MapRGB( testSurface->format, 0, 0, 0);
    85 	color = SDL_MapRGBA( testSurface->format, 0, 0, 0, 0);
    75 	SDLTest_AssertPass("Call to SDL_MapRGB()");
    86 	SDLTest_AssertPass("Call to SDL_MapRGBA()");
    76 	ret = SDL_FillRect( testSurface, NULL, color);
    87 	ret = SDL_FillRect( testSurface, NULL, color);
    77 	SDLTest_AssertPass("Call to SDL_FillRect()");
    88 	SDLTest_AssertPass("Call to SDL_FillRect()");
    78 	SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
    89 	SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillRect, expected: 0, got: %i", ret);
    79 }
    90 }
    80 
    91 
   100 	
   111 	
   101 	/* Create sample surface */
   112 	/* Create sample surface */
   102 	face = SDLTest_ImageFace();
   113 	face = SDLTest_ImageFace();
   103 	SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
   114 	SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
   104 	if (face == NULL) return;
   115 	if (face == NULL) return;
       
   116 
       
   117         /* Reset alpha modulation */	
       
   118 	ret = SDL_SetSurfaceAlphaMod(face, 255);
       
   119 	SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()");
       
   120 	SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 0, got: %i", ret);
       
   121 
       
   122         /* Reset color modulation */	
       
   123 	ret = SDL_SetSurfaceColorMod(face, 255, 255, 255);
       
   124 	SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()");
       
   125 	SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorMod(), expected: 0, got: %i", ret);
       
   126 
       
   127         /* Reset color key */	
       
   128 	ret = SDL_SetColorKey(face, SDL_FALSE, 0);
       
   129 	SDLTest_AssertPass("Call to SDL_SetColorKey()");
       
   130 	SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetColorKey(), expected: 0, got: %i", ret);
   105 
   131 
   106 	/* Clear the test surface */
   132 	/* Clear the test surface */
   107         _clearTestSurface();
   133         _clearTestSurface();
   108         
   134         
   109 	/* Target rect size */
   135 	/* Target rect size */
   139 			if (ret != 0) checkFailCount3++;
   165 			if (ret != 0) checkFailCount3++;
   140 		}
   166 		}
   141 		else if (mode == -4) {
   167 		else if (mode == -4) {
   142 			/* Crazy blending mode magic. */
   168 			/* Crazy blending mode magic. */
   143 			nmode = (i/4*j/4) % 4;
   169 			nmode = (i/4*j/4) % 4;
   144 			if (nmode==0) bmode = SDL_BLENDMODE_NONE;
   170 			if (nmode==0) {
   145 			else if (nmode==1) bmode = SDL_BLENDMODE_BLEND;
   171 				bmode = SDL_BLENDMODE_NONE;
   146 			else if (nmode==2) bmode = SDL_BLENDMODE_ADD;
   172 			} else if (nmode==1) {
   147 			else if (nmode==3) bmode = SDL_BLENDMODE_MOD;
   173 				bmode = SDL_BLENDMODE_BLEND;
   148 			ret = SDL_SetSurfaceBlendMode( face, bmode );		
   174 			} else if (nmode==2) {
       
   175 				bmode = SDL_BLENDMODE_ADD;				
       
   176 			} else if (nmode==3) {
       
   177 				bmode = SDL_BLENDMODE_MOD;
       
   178 			}
       
   179 			ret = SDL_SetSurfaceBlendMode( face, bmode );
   149 			if (ret != 0) checkFailCount4++;
   180 			if (ret != 0) checkFailCount4++;
   150 		}
   181 		}
   151 
   182 
   152 		 /* Blitting. */
   183 		 /* Blitting. */
   153 		 rect.x = i;
   184 		 rect.x = i;
   471 surface_testBlitBlendLoop(void *arg) {
   502 surface_testBlitBlendLoop(void *arg) {
   472 
   503 
   473    int ret;
   504    int ret;
   474    SDL_Surface *referenceSurface;
   505    SDL_Surface *referenceSurface;
   475 
   506 
   476    /* All blitting */ 
   507    /* All blitting modes */ 
   477    _testBlitBlendMode(-4);
   508    _testBlitBlendMode(-4);
   478    
   509    
   479    /* Verify result by comparing surfaces */
   510    /* Verify result by comparing surfaces */
   480    referenceSurface = SDLTest_ImageBlitBlendAll();
   511    referenceSurface = SDLTest_ImageBlitBlendAll();
   481    ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 );
   512    ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, 0 );