test/testautomation_render.c
changeset 6773 5ebc5a9e35b4
parent 6772 5229a117ef97
child 6822 18f6818ba281
     1.1 --- a/test/testautomation_render.c	Mon Dec 24 14:43:57 2012 -0800
     1.2 +++ b/test/testautomation_render.c	Wed Dec 26 22:26:44 2012 -0800
     1.3 @@ -22,13 +22,14 @@
     1.4  #define ALLOWABLE_ERROR_OPAQUE	0
     1.5  #define ALLOWABLE_ERROR_BLENDED	64
     1.6  
     1.7 +/* Test window and renderer */
     1.8  SDL_Window *window = NULL;
     1.9  SDL_Renderer *renderer = NULL;
    1.10  
    1.11  /* Prototypes for helper functions */
    1.12  
    1.13  static int _clearScreen (void);
    1.14 -static void _compare(const char *msg, SDL_Surface *s, int allowable_error);
    1.15 +static void _compare(SDL_Surface *reference, int allowable_error);
    1.16  static int _hasTexAlpha(void);
    1.17  static int _hasTexColor(void);
    1.18  static SDL_Texture *_loadTestFace(void);
    1.19 @@ -53,7 +54,7 @@
    1.20    renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    1.21    SDLTest_AssertPass("SDL_CreateRenderer()");
    1.22    SDLTest_AssertCheck(renderer != 0, "Check SDL_CreateRenderer result");
    1.23 -  if (renderer == 0) {
    1.24 +  if (renderer == NULL) {
    1.25        SDL_DestroyWindow(window);
    1.26        return;
    1.27    }
    1.28 @@ -66,11 +67,13 @@
    1.29  {
    1.30    if (renderer != NULL) {  
    1.31       SDL_DestroyRenderer(renderer);
    1.32 +     renderer = NULL;
    1.33       SDLTest_AssertPass("SDL_DestroyRenderer()");
    1.34    }
    1.35    
    1.36    if (window != NULL) {  
    1.37       SDL_DestroyWindow(window);
    1.38 +     window = NULL;
    1.39       SDLTest_AssertPass("SDL_DestroyWindow");
    1.40    }
    1.41  }
    1.42 @@ -106,6 +109,7 @@
    1.43     int ret;
    1.44     int x, y;
    1.45     SDL_Rect rect;
    1.46 +   SDL_Surface *referenceSurface = NULL;
    1.47     int checkFailCount1;
    1.48     int checkFailCount2;
    1.49  
    1.50 @@ -182,7 +186,14 @@
    1.51     SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
    1.52  
    1.53     /* See if it's the same. */
    1.54 -   _compare( "Primitives output not the same.", SDLTest_ImagePrimitives(), ALLOWABLE_ERROR_OPAQUE );
    1.55 +   referenceSurface = SDLTest_ImagePrimitives();
    1.56 +   _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
    1.57 +
    1.58 +   /* Clean up. */
    1.59 +   if (referenceSurface != NULL) {
    1.60 +      SDL_FreeSurface(referenceSurface);
    1.61 +      referenceSurface = NULL;
    1.62 +   }
    1.63  
    1.64     return TEST_COMPLETED;
    1.65  }
    1.66 @@ -200,6 +211,7 @@
    1.67     int ret;
    1.68     int i, j;
    1.69     SDL_Rect rect;
    1.70 +   SDL_Surface *referenceSurface = NULL;
    1.71     int checkFailCount1;
    1.72     int checkFailCount2;
    1.73     int checkFailCount3;
    1.74 @@ -317,9 +329,16 @@
    1.75     SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_RenderDrawPoint, expected: 0, got: %i", checkFailCount3);
    1.76  
    1.77     /* See if it's the same. */
    1.78 -   _compare( "Blended primitives output not the same.", SDLTest_ImagePrimitivesBlend(), ALLOWABLE_ERROR_BLENDED );
    1.79 +   referenceSurface = SDLTest_ImagePrimitivesBlend();
    1.80 +   _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
    1.81  
    1.82 -    return TEST_COMPLETED;
    1.83 +   /* Clean up. */
    1.84 +   if (referenceSurface != NULL) {
    1.85 +      SDL_FreeSurface(referenceSurface);
    1.86 +      referenceSurface = NULL;
    1.87 +   }
    1.88 +
    1.89 +   return TEST_COMPLETED;
    1.90  }
    1.91  
    1.92  
    1.93 @@ -337,6 +356,7 @@
    1.94     int ret;
    1.95     SDL_Rect rect;
    1.96     SDL_Texture *tface;
    1.97 +   SDL_Surface *referenceSurface = NULL;
    1.98     Uint32 tformat;
    1.99     int taccess, tw, th;
   1.100     int i, j, ni, nj;
   1.101 @@ -374,11 +394,16 @@
   1.102     }
   1.103     SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount1);
   1.104  
   1.105 +   /* See if it's the same */
   1.106 +   referenceSurface = SDLTest_ImageBlit();
   1.107 +   _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
   1.108 +
   1.109     /* Clean up. */
   1.110     SDL_DestroyTexture( tface );
   1.111 -
   1.112 -   /* See if it's the same */
   1.113 -   _compare( "Blit output not the same.", SDLTest_ImageBlit(), ALLOWABLE_ERROR_OPAQUE );
   1.114 +   if (referenceSurface != NULL) {
   1.115 +      SDL_FreeSurface(referenceSurface);
   1.116 +      referenceSurface = NULL;
   1.117 +   }
   1.118  
   1.119     return TEST_COMPLETED;
   1.120  }
   1.121 @@ -398,6 +423,7 @@
   1.122     int ret;
   1.123     SDL_Rect rect;
   1.124     SDL_Texture *tface;
   1.125 +   SDL_Surface *referenceSurface = NULL;
   1.126     Uint32 tformat;
   1.127     int taccess, tw, th;
   1.128     int i, j, ni, nj;
   1.129 @@ -438,12 +464,16 @@
   1.130     SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
   1.131     SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
   1.132  
   1.133 +   /* See if it's the same. */
   1.134 +   referenceSurface = SDLTest_ImageBlitColor();
   1.135 +   _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
   1.136 +
   1.137     /* Clean up. */
   1.138     SDL_DestroyTexture( tface );
   1.139 -
   1.140 -   /* See if it's the same. */
   1.141 -   _compare( "Blit output not the same (using SDL_SetTextureColorMod).",
   1.142 -            SDLTest_ImageBlitColor(), ALLOWABLE_ERROR_OPAQUE );
   1.143 +   if (referenceSurface != NULL) {
   1.144 +      SDL_FreeSurface(referenceSurface);
   1.145 +      referenceSurface = NULL;
   1.146 +   }
   1.147  
   1.148     return TEST_COMPLETED;
   1.149  }
   1.150 @@ -463,13 +493,13 @@
   1.151     int ret;
   1.152     SDL_Rect rect;
   1.153     SDL_Texture *tface;
   1.154 +   SDL_Surface *referenceSurface = NULL;
   1.155     Uint32 tformat;
   1.156     int taccess, tw, th;
   1.157     int i, j, ni, nj;
   1.158     int checkFailCount1;
   1.159     int checkFailCount2;
   1.160  
   1.161 -
   1.162     /* Need alpha or just skip test. */
   1.163     SDLTest_AssertCheck(_hasTexAlpha(), "_hasTexAlpha");
   1.164  
   1.165 @@ -507,12 +537,16 @@
   1.166     SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", checkFailCount1);
   1.167     SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
   1.168  
   1.169 +   /* See if it's the same. */
   1.170 +   referenceSurface = SDLTest_ImageBlitAlpha();
   1.171 +   _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
   1.172 +
   1.173     /* Clean up. */
   1.174     SDL_DestroyTexture( tface );
   1.175 -
   1.176 -   /* See if it's the same. */
   1.177 -   _compare( "Blit output not the same (using SDL_SetSurfaceAlphaMod).",
   1.178 -            SDLTest_ImageBlitAlpha(), ALLOWABLE_ERROR_BLENDED );
   1.179 +   if (referenceSurface != NULL) {
   1.180 +      SDL_FreeSurface(referenceSurface);
   1.181 +      referenceSurface = NULL;
   1.182 +   }
   1.183  
   1.184     return TEST_COMPLETED;
   1.185  }
   1.186 @@ -584,6 +618,7 @@
   1.187     int ret;
   1.188     SDL_Rect rect;
   1.189     SDL_Texture *tface;
   1.190 +   SDL_Surface *referenceSurface = NULL;
   1.191     Uint32 tformat;
   1.192     int taccess, tw, th;
   1.193     int i, j, ni, nj;
   1.194 @@ -618,26 +653,39 @@
   1.195  
   1.196     /* Test None. */
   1.197     _testBlitBlendMode( tface, SDL_BLENDMODE_NONE );
   1.198 -   /* See if it's the same. */
   1.199 -   _compare( "Blit blending output not the same (using SDL_BLENDMODE_NONE).",
   1.200 -            SDLTest_ImageBlitBlendNone(), ALLOWABLE_ERROR_OPAQUE ); 
   1.201 -
   1.202 -
   1.203 +   referenceSurface = SDLTest_ImageBlitBlendNone();
   1.204 +   _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE ); 
   1.205 +   if (referenceSurface != NULL) {
   1.206 +      SDL_FreeSurface(referenceSurface);
   1.207 +      referenceSurface = NULL;
   1.208 +   }
   1.209 +   
   1.210     /* Test Blend. */
   1.211     _testBlitBlendMode( tface, SDL_BLENDMODE_BLEND );
   1.212 -   _compare( "Blit blending output not the same (using SDL_BLENDMODE_BLEND).",
   1.213 -            SDLTest_ImageBlitBlend(), ALLOWABLE_ERROR_BLENDED );
   1.214 -
   1.215 +   referenceSurface = SDLTest_ImageBlitBlend();
   1.216 +   _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
   1.217 +   if (referenceSurface != NULL) {
   1.218 +      SDL_FreeSurface(referenceSurface);
   1.219 +      referenceSurface = NULL;
   1.220 +   }
   1.221  
   1.222     /* Test Add. */
   1.223     _testBlitBlendMode( tface, SDL_BLENDMODE_ADD );
   1.224 -   _compare( "Blit blending output not the same (using SDL_BLENDMODE_ADD).",
   1.225 -            SDLTest_ImageBlitBlendAdd(), ALLOWABLE_ERROR_BLENDED );
   1.226 +   referenceSurface = SDLTest_ImageBlitBlendAdd();
   1.227 +   _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
   1.228 +   if (referenceSurface != NULL) {
   1.229 +      SDL_FreeSurface(referenceSurface);
   1.230 +      referenceSurface = NULL;
   1.231 +   }
   1.232  
   1.233     /* Test Mod. */
   1.234     _testBlitBlendMode( tface, SDL_BLENDMODE_MOD);
   1.235 -   _compare( "Blit blending output not the same (using SDL_BLENDMODE_MOD).",
   1.236 -            SDLTest_ImageBlitBlendMod(), ALLOWABLE_ERROR_BLENDED );
   1.237 +   referenceSurface = SDLTest_ImageBlitBlendMod();
   1.238 +   _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
   1.239 +   if (referenceSurface != NULL) {
   1.240 +      SDL_FreeSurface(referenceSurface);
   1.241 +      referenceSurface = NULL;
   1.242 +   }
   1.243  
   1.244     /* Clear surface. */
   1.245     _clearScreen();
   1.246 @@ -682,9 +730,13 @@
   1.247     /* Clean up. */
   1.248     SDL_DestroyTexture( tface );
   1.249  
   1.250 -   /* Check to see if matches. */
   1.251 -   _compare( "Blit blending output not the same (using SDL_BLENDMODE_*).",
   1.252 -            SDLTest_ImageBlitBlendAll(), ALLOWABLE_ERROR_BLENDED);
   1.253 +   /* Check to see if final image matches. */
   1.254 +   referenceSurface = SDLTest_ImageBlitBlendAll();
   1.255 +   _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
   1.256 +   if (referenceSurface != NULL) {
   1.257 +      SDL_FreeSurface(referenceSurface);
   1.258 +      referenceSurface = NULL;
   1.259 +   }
   1.260  
   1.261     return TEST_COMPLETED;
   1.262  }
   1.263 @@ -902,9 +954,6 @@
   1.264     return 1;
   1.265  }
   1.266  
   1.267 -/* Counter for _compare calls use for filename creation when comparisons fail */
   1.268 -static int _renderCompareCount = 0;
   1.269 -
   1.270  /**
   1.271   * @brief Compares screen pixels with image pixels. Helper function.
   1.272   *
   1.273 @@ -918,17 +967,15 @@
   1.274   * http://wiki.libsdl.org/moin.cgi/SDL_FreeSurface
   1.275   */
   1.276  static void
   1.277 -_compare(const char *msg, SDL_Surface *s, int allowable_error)
   1.278 +_compare(SDL_Surface *referenceSurface, int allowable_error)
   1.279  {
   1.280     int ret;
   1.281     SDL_Rect rect;
   1.282     Uint8 pix[4*TESTRENDER_SCREEN_W*TESTRENDER_SCREEN_H];
   1.283 -   SDL_Surface *testsur;
   1.284 -   char imageFilename[128];
   1.285 -   char referenceFilename[128];
   1.286 +   SDL_Surface *testSurface;
   1.287  
   1.288     /* Read pixels. */
   1.289 -   /* Explicitly specify the rect in case the window isn't expected size... */
   1.290 +   /* Explicitly specify the rect in case the window isn't the expected size... */
   1.291     rect.x = 0;
   1.292     rect.y = 0;
   1.293     rect.w = TESTRENDER_SCREEN_W;
   1.294 @@ -937,26 +984,18 @@
   1.295     SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderReadPixels, expected: 0, got: %i", ret);
   1.296  
   1.297     /* Create surface. */
   1.298 -   testsur = SDL_CreateRGBSurfaceFrom( pix, TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, 32, TESTRENDER_SCREEN_W*4,
   1.299 +   testSurface = SDL_CreateRGBSurfaceFrom( pix, TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, 32, TESTRENDER_SCREEN_W*4,
   1.300                                         RENDER_COMPARE_RMASK, RENDER_COMPARE_GMASK, RENDER_COMPARE_BMASK, RENDER_COMPARE_AMASK);
   1.301 -   SDLTest_AssertCheck(testsur != NULL, "Verify result from SDL_CreateRGBSurfaceFrom");
   1.302 +   SDLTest_AssertCheck(testSurface != NULL, "Verify result from SDL_CreateRGBSurfaceFrom");
   1.303  
   1.304     /* Compare surface. */
   1.305 -   ret = SDLTest_CompareSurfaces( testsur, s, allowable_error );
   1.306 +   ret = SDLTest_CompareSurfaces( testSurface, referenceSurface, allowable_error );
   1.307     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   1.308  
   1.309 -   /* Save source image and reference image for analysis */
   1.310 -   _renderCompareCount++;
   1.311 -   if (ret != 0) {
   1.312 -      SDL_snprintf(imageFilename, 127, "compare%04d_SourceImage.bmp", _renderCompareCount);
   1.313 -      SDL_SaveBMP(testsur, imageFilename);
   1.314 -      SDL_snprintf(referenceFilename, 127, "compare%04d_ReferenceImage.bmp", _renderCompareCount);
   1.315 -      SDL_SaveBMP(s, referenceFilename);
   1.316 -      SDLTest_LogError("Surfaces from failed comparison saved as '%s' and '%s'", imageFilename, referenceFilename);
   1.317 +   /* Clean up. */
   1.318 +   if (testSurface != NULL) {
   1.319 +       SDL_FreeSurface(testSurface);
   1.320     }
   1.321 -
   1.322 -   /* Clean up. */
   1.323 -   SDL_FreeSurface(testsur);
   1.324  }
   1.325  
   1.326  /**