1.1 --- a/src/test/SDL_test_compare.c Mon Dec 24 14:43:57 2012 -0800
1.2 +++ b/src/test/SDL_test_compare.c Wed Dec 26 22:26:44 2012 -0800
1.3 @@ -32,7 +32,11 @@
1.4 #include "SDL_test.h"
1.5
1.6
1.7 -int SDLTest_CompareSurfaces( SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error )
1.8 +/* Counter for _CompareSurface calls; used for filename creation when comparisons fail */
1.9 +static int _CompareSurfaceCount = 0;
1.10 +
1.11 +/* Compare surfaces */
1.12 +int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error)
1.13 {
1.14 int ret;
1.15 int i,j;
1.16 @@ -41,18 +45,20 @@
1.17 int dist;
1.18 Uint8 R, G, B, A;
1.19 Uint8 Rd, Gd, Bd, Ad;
1.20 + char imageFilename[128];
1.21 + char referenceFilename[128];
1.22
1.23 /* Validate input surfaces */
1.24 if (surface == NULL || referenceSurface == NULL) {
1.25 return -1;
1.26 }
1.27
1.28 - /* Make surface size is the same. */
1.29 + /* Make sure surface size is the same. */
1.30 if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h)) {
1.31 return -2;
1.32 }
1.33
1.34 - /* Sanitize input */
1.35 + /* Sanitize input value */
1.36 if (allowable_error<0) {
1.37 allowable_error = 0;
1.38 }
1.39 @@ -87,5 +93,15 @@
1.40 SDL_UnlockSurface( surface );
1.41 SDL_UnlockSurface( referenceSurface );
1.42
1.43 + /* Save test image and reference for analysis on failures */
1.44 + _CompareSurfaceCount++;
1.45 + if (ret != 0) {
1.46 + SDL_snprintf(imageFilename, 127, "CompareSurfaces%04d_TestOutput.bmp", _CompareSurfaceCount);
1.47 + SDL_SaveBMP(surface, imageFilename);
1.48 + SDL_snprintf(referenceFilename, 127, "CompareSurfaces%04d_Reference.bmp", _CompareSurfaceCount);
1.49 + SDL_SaveBMP(referenceSurface, referenceFilename);
1.50 + SDLTest_LogError("Surfaces from failed comparison saved as '%s' and '%s'", imageFilename, referenceFilename);
1.51 + }
1.52 +
1.53 return ret;
1.54 }