Fix assert format strings/parameters in testautomation modules; improve output of SDL_CompareSurfaces to aid debugging; update platform_testSetErrorInvalidInput for SDL changes
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Sun, 30 Nov 2014 20:55:27 -0800
changeset 9254 6c469ea796e4
parent 9253 4b7c962ae015
child 9255 c2ef0d8d6da0
Fix assert format strings/parameters in testautomation modules; improve output of SDL_CompareSurfaces to aid debugging; update platform_testSetErrorInvalidInput for SDL changes
include/SDL_test_compare.h
src/test/SDL_test_compare.c
test/testautomation_platform.c
test/testautomation_render.c
test/testautomation_rwops.c
test/testautomation_sdltest.c
test/testautomation_timer.c
test/testautomation_video.c
--- a/include/SDL_test_compare.h	Sun Nov 30 22:17:12 2014 +0100
+++ b/include/SDL_test_compare.h	Sun Nov 30 20:55:27 2014 -0800
@@ -51,9 +51,9 @@
  *
  * \param surface Surface used in comparison
  * \param referenceSurface Test Surface used in comparison
- * \param allowable_error Allowable difference (squared) in blending accuracy.
+ * \param allowable_error Allowable difference (=sum of squared difference for each RGB component) in blending accuracy.
  *
- * \returns 0 if comparison succeeded, >0 (=number of pixels where comparison failed) if comparison failed, -1 if any of the surfaces were NULL, -2 if the surface sizes differ.
+ * \returns 0 if comparison succeeded, >0 (=number of pixels for which the comparison failed) if comparison failed, -1 if any of the surfaces were NULL, -2 if the surface sizes differ.
  */
 int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error);
 
--- a/src/test/SDL_test_compare.c	Sun Nov 30 22:17:12 2014 +0100
+++ b/src/test/SDL_test_compare.c	Sun Nov 30 20:55:27 2014 -0800
@@ -43,6 +43,7 @@
    int bpp, bpp_reference;
    Uint8 *p, *p_reference;
    int dist;
+   int sampleErrorX, sampleErrorY, sampleDist;
    Uint8 R, G, B, A;
    Uint8 Rd, Gd, Bd, Ad;
    char imageFilename[128];
@@ -86,6 +87,11 @@
          /* Allow some difference in blending accuracy */
          if (dist > allowable_error) {
             ret++;
+            if (ret == 1) {
+               sampleErrorX = i;
+               sampleErrorY = j;
+               sampleDist = dist;
+            }
          }
       }
    }
@@ -96,6 +102,8 @@
    /* Save test image and reference for analysis on failures */
    _CompareSurfaceCount++;
    if (ret != 0) {
+      SDLTest_LogError("Comparison of pixels with allowable error of %i failed %i times.", allowable_error, ret);
+      SDLTest_LogError("First detected occurrence at position %i,%i with a squared RGB-difference of %i.", sampleErrorX, sampleErrorY, sampleDist); 
       SDL_snprintf(imageFilename, 127, "CompareSurfaces%04d_TestOutput.bmp", _CompareSurfaceCount);
       SDL_SaveBMP(surface, imageFilename);
       SDL_snprintf(referenceFilename, 127, "CompareSurfaces%04d_Reference.bmp", _CompareSurfaceCount);
--- a/test/testautomation_platform.c	Sun Nov 30 22:17:12 2014 +0100
+++ b/test/testautomation_platform.c	Sun Nov 30 20:55:27 2014 -0800
@@ -34,16 +34,16 @@
    int ret;
 
    ret = _compareSizeOfType( sizeof(Uint8), 1 );
-   SDLTest_AssertCheck( ret == 0, "sizeof(Uint8) = %lu, expected  1", sizeof(Uint8) );
+   SDLTest_AssertCheck( ret == 0, "sizeof(Uint8) = %lu, expected  1", (unsigned long)sizeof(Uint8) );
 
    ret = _compareSizeOfType( sizeof(Uint16), 2 );
-   SDLTest_AssertCheck( ret == 0, "sizeof(Uint16) = %lu, expected 2", sizeof(Uint16) );
+   SDLTest_AssertCheck( ret == 0, "sizeof(Uint16) = %lu, expected 2", (unsigned long)sizeof(Uint16) );
 
    ret = _compareSizeOfType( sizeof(Uint32), 4 );
-   SDLTest_AssertCheck( ret == 0, "sizeof(Uint32) = %lu, expected 4", sizeof(Uint32) );
+   SDLTest_AssertCheck( ret == 0, "sizeof(Uint32) = %lu, expected 4", (unsigned long)sizeof(Uint32) );
 
    ret = _compareSizeOfType( sizeof(Uint64), 8 );
-   SDLTest_AssertCheck( ret == 0, "sizeof(Uint64) = %lu, expected 8", sizeof(Uint64) );
+   SDLTest_AssertCheck( ret == 0, "sizeof(Uint64) = %lu, expected 8", (unsigned long)sizeof(Uint64) );
 
    return TEST_COMPLETED;
 }
@@ -395,21 +395,17 @@
      len = SDL_strlen(lastError);
      SDLTest_AssertCheck(len == 0,
              "SDL_GetError(): expected message len 0, was len: %i",
-             0,
              len);
-     SDLTest_AssertCheck(SDL_strcmp(lastError, "") == 0,
-             "SDL_GetError(): expected message '', was message: '%s'",
-             lastError);
    }
 
    /* Set */
    result = SDL_SetError(probeError);
-   SDLTest_AssertPass("SDL_SetError()");
+   SDLTest_AssertPass("SDL_SetError('%s')", probeError);
    SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
 
    /* Check for no-op */
    result = SDL_SetError(invalidError);
-   SDLTest_AssertPass("SDL_SetError()");
+   SDLTest_AssertPass("SDL_SetError(NULL)");
    SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result);
    lastError = (char *)SDL_GetError();
    SDLTest_AssertCheck(lastError != NULL,
@@ -417,14 +413,9 @@
    if (lastError != NULL)
    {
      len = SDL_strlen(lastError);
-     SDLTest_AssertCheck(len == SDL_strlen(probeError),
-             "SDL_GetError(): expected message len %i, was len: %i",
-             SDL_strlen(probeError),
+     SDLTest_AssertCheck(len == 0,
+             "SDL_GetError(): expected message len 0, was len: %i",
              len);
-     SDLTest_AssertCheck(SDL_strcmp(lastError, probeError) == 0,
-             "SDL_GetError(): expected message '%s', was message: '%s'",
-             probeError,
-             lastError);
    }
 
    /* Reset */
--- a/test/testautomation_render.c	Sun Nov 30 22:17:12 2014 +0100
+++ b/test/testautomation_render.c	Sun Nov 30 20:55:27 2014 -0800
@@ -113,6 +113,9 @@
    int checkFailCount1;
    int checkFailCount2;
 
+   /* Clear surface. */
+   _clearScreen();
+
    /* Need drawcolor or just skip test. */
    SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor");
 
@@ -184,7 +187,10 @@
 
    ret = SDL_RenderDrawLine(renderer, 79, 59, 50, 30 );
    SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
-
+   
+   /* Make current */
+   SDL_RenderPresent(renderer);
+   
    /* See if it's the same. */
    referenceSurface = SDLTest_ImagePrimitives();
    _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
@@ -214,6 +220,9 @@
    int checkFailCount2;
    int checkFailCount3;
 
+   /* Clear surface. */
+   _clearScreen();
+
    /* Need drawcolor and blendmode or just skip test. */
    SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor");
    SDLTest_AssertCheck(_hasBlendModes(), "_hasBlendModes");
@@ -326,6 +335,9 @@
    SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
    SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_RenderDrawPoint, expected: 0, got: %i", checkFailCount3);
 
+   /* Make current */
+   SDL_RenderPresent(renderer);
+
    /* See if it's the same. */
    referenceSurface = SDLTest_ImagePrimitivesBlend();
    _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
@@ -358,6 +370,8 @@
    int i, j, ni, nj;
    int checkFailCount1;
 
+   /* Clear surface. */
+   _clearScreen();
 
    /* Need drawcolor or just skip test. */
    SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor)");
@@ -390,6 +404,9 @@
    }
    SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount1);
 
+   /* Make current */
+   SDL_RenderPresent(renderer);
+
    /* See if it's the same */
    referenceSurface = SDLTest_ImageBlit();
    _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
@@ -424,6 +441,9 @@
    int checkFailCount1;
    int checkFailCount2;
 
+   /* Clear surface. */
+   _clearScreen();
+
    /* Create face surface. */
    tface = _loadTestFace();
    SDLTest_AssertCheck(tface != NULL, "Verify _loadTestFace() result");
@@ -458,6 +478,9 @@
    SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
    SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
 
+   /* Make current */
+   SDL_RenderPresent(renderer);
+
    /* See if it's the same. */
    referenceSurface = SDLTest_ImageBlitColor();
    _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
@@ -492,6 +515,9 @@
    int checkFailCount1;
    int checkFailCount2;
 
+   /* Clear surface. */
+   _clearScreen();
+
    /* Need alpha or just skip test. */
    SDLTest_AssertCheck(_hasTexAlpha(), "_hasTexAlpha");
 
@@ -529,6 +555,9 @@
    SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", checkFailCount1);
    SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
 
+   /* Make current */
+   SDL_RenderPresent(renderer);
+
    /* See if it's the same. */
    referenceSurface = SDLTest_ImageBlitAlpha();
    _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
@@ -644,6 +673,9 @@
    /* Test None. */
    _testBlitBlendMode( tface, SDL_BLENDMODE_NONE );
    referenceSurface = SDLTest_ImageBlitBlendNone();
+
+   /* Make current and compare */
+   SDL_RenderPresent(renderer);
    _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
    SDL_FreeSurface(referenceSurface);
    referenceSurface = NULL;
@@ -651,6 +683,9 @@
    /* Test Blend. */
    _testBlitBlendMode( tface, SDL_BLENDMODE_BLEND );
    referenceSurface = SDLTest_ImageBlitBlend();
+
+   /* Make current and compare */
+   SDL_RenderPresent(renderer);
    _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
    SDL_FreeSurface(referenceSurface);
    referenceSurface = NULL;
@@ -658,6 +693,9 @@
    /* Test Add. */
    _testBlitBlendMode( tface, SDL_BLENDMODE_ADD );
    referenceSurface = SDLTest_ImageBlitBlendAdd();
+
+   /* Make current and compare */
+   SDL_RenderPresent(renderer);
    _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
    SDL_FreeSurface(referenceSurface);
    referenceSurface = NULL;
@@ -665,6 +703,9 @@
    /* Test Mod. */
    _testBlitBlendMode( tface, SDL_BLENDMODE_MOD);
    referenceSurface = SDLTest_ImageBlitBlendMod();
+
+   /* Make current and compare */
+   SDL_RenderPresent(renderer);
    _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
    SDL_FreeSurface(referenceSurface);
    referenceSurface = NULL;
@@ -712,6 +753,9 @@
    /* Clean up. */
    SDL_DestroyTexture( tface );
 
+   /* Make current */
+   SDL_RenderPresent(renderer);
+
    /* Check to see if final image matches. */
    referenceSurface = SDLTest_ImageBlitBlendAll();
    _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
@@ -984,7 +1028,8 @@
  *
  * \sa
  * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
- * http://wiki.libsdl.org/moin.cgi/SDL_RenderFillRect
+ * http://wiki.libsdl.org/moin.cgi/SDL_RenderClear
+ * http://wiki.libsdl.org/moin.cgi/SDL_RenderPresent
  * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode
  */
 static int
@@ -997,8 +1042,11 @@
    SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
 
    /* Clear screen. */
-   ret = SDL_RenderFillRect(renderer, NULL );
-   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
+   ret = SDL_RenderClear(renderer);
+   SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderClear, expected: 0, got: %i", ret);
+
+   /* Make current */
+   SDL_RenderPresent(renderer);
 
    /* Set defaults. */
    ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE );
--- a/test/testautomation_rwops.c	Sun Nov 30 22:17:12 2014 +0100
+++ b/test/testautomation_rwops.c	Sun Nov 30 20:55:27 2014 -0800
@@ -105,7 +105,7 @@
    /* Set to start. */
    i = SDL_RWseek(rw, 0, RW_SEEK_SET );
    SDLTest_AssertPass("Call to SDL_RWseek succeeded");
-   SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);
+   SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %lli", i);
 
    /* Test write. */
    s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1);
@@ -120,12 +120,12 @@
    /* Test seek to random position */
    i = SDL_RWseek( rw, seekPos, RW_SEEK_SET );
    SDLTest_AssertPass("Call to SDL_RWseek succeeded");
-   SDLTest_AssertCheck(i == (Sint64)seekPos, "Verify seek to %i with SDL_RWseek (RW_SEEK_SET), expected %i, got %i", seekPos, seekPos, i);
+   SDLTest_AssertCheck(i == (Sint64)seekPos, "Verify seek to %i with SDL_RWseek (RW_SEEK_SET), expected %i, got %lli", seekPos, seekPos, i);
 
    /* Test seek back to start */
    i = SDL_RWseek(rw, 0, RW_SEEK_SET );
    SDLTest_AssertPass("Call to SDL_RWseek succeeded");
-   SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);
+   SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %lli", i);
 
    /* Test read */
    s = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 );
@@ -144,7 +144,7 @@
    SDLTest_AssertPass("Call to SDL_RWseek(...,-4,RW_SEEK_CUR) succeeded");
    SDLTest_AssertCheck(
        i == (Sint64)(sizeof(RWopsHelloWorldTestString)-5),
-       "Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected %i, got %i",
+       "Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected %i, got %lli",
        sizeof(RWopsHelloWorldTestString)-5,
        i);
 
@@ -152,7 +152,7 @@
    SDLTest_AssertPass("Call to SDL_RWseek(...,-1,RW_SEEK_END) succeeded");
    SDLTest_AssertCheck(
        i == (Sint64)(sizeof(RWopsHelloWorldTestString)-2),
-       "Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %i",
+       "Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %lli",
        sizeof(RWopsHelloWorldTestString)-2,
        i);
 
@@ -161,7 +161,7 @@
    SDLTest_AssertPass("Call to SDL_RWseek(...,0,invalid_whence) succeeded");
    SDLTest_AssertCheck(
        i == (Sint64)(-1),
-       "Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %i",
+       "Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %lli",
        i);
 }
 
@@ -668,7 +668,7 @@
      /* Test seek to start */
      result = SDL_RWseek( rw, 0, RW_SEEK_SET );
      SDLTest_AssertPass("Call to SDL_RWseek succeeded");
-     SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %i", result);
+     SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %lli", result);
 
      /* Read test data */
      BE16test = SDL_ReadBE16(rw);
--- a/test/testautomation_sdltest.c	Sun Nov 30 22:17:12 2014 +0100
+++ b/test/testautomation_sdltest.c	Sun Nov 30 20:55:27 2014 -0800
@@ -1076,7 +1076,7 @@
   max = 0;
   result = SDLTest_RandomIntegerInRange(min, max);
   SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(0,0)");
-  SDLTest_AssertCheck(result == 0, "Validated returned value; expected: 0, got: %d", min, max, result);
+  SDLTest_AssertCheck(result == 0, "Validated returned value; expected: 0, got: %d", result);
 
   /* Swapped min-max */
   min = (Sint32)SDLTest_RandomSint16();
--- a/test/testautomation_timer.c	Sun Nov 30 22:17:12 2014 +0100
+++ b/test/testautomation_timer.c	Sun Nov 30 20:55:27 2014 -0800
@@ -42,7 +42,7 @@
 
   result = SDL_GetPerformanceCounter();
   SDLTest_AssertPass("Call to SDL_GetPerformanceCounter()");
-  SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %lu", result);
+  SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %llu", result);
 
   return TEST_COMPLETED;
 }
@@ -57,7 +57,7 @@
 
   result = SDL_GetPerformanceFrequency();
   SDLTest_AssertPass("Call to SDL_GetPerformanceFrequency()");
-  SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %lu", result);
+  SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %llu", result);
 
   return TEST_COMPLETED;
 }
--- a/test/testautomation_video.c	Sun Nov 30 22:17:12 2014 +0100
+++ b/test/testautomation_video.c	Sun Nov 30 20:55:27 2014 -0800
@@ -740,7 +740,7 @@
   /* Call against invalid window */
   result = SDL_GetWindowGammaRamp(NULL, red, green, blue);
   SDLTest_AssertPass("Call to SDL_GetWindowGammaRamp(window=NULL,r,g,b)");
-  SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %f", result);
+  SDLTest_AssertCheck(result == -1, "Validate result value; expected: -1, got: %i", result);
   _checkInvalidWindowError();
 
   return TEST_COMPLETED;
@@ -1619,7 +1619,7 @@
 
   /* Set data with NULL to clear */
   result = (char *)SDL_SetWindowData(window, name, NULL);
-  SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name, userdata);
+  SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL)", name);
   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, result) == 0, "Validate that correct result was returned; expected: %s, got: %s", referenceUserdata2, result);
   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);
@@ -1627,7 +1627,7 @@
 
   /* Set data with NULL to clear again */
   result = (char *)SDL_SetWindowData(window, name, NULL);
-  SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name, userdata);
+  SDLTest_AssertPass("Call to SDL_SetWindowData(...%s,NULL) [again]", name);
   SDLTest_AssertCheck(result == NULL, "Validate that result is NULL");
   SDLTest_AssertCheck(SDL_strcmp(referenceName, name) == 0, "Validate that name was not changed, expected: %s, got: %s", referenceName, name);
   SDLTest_AssertCheck(SDL_strcmp(referenceUserdata, userdata) == 0, "Validate that userdata was not changed, expected: %s, got: %s", referenceUserdata, userdata);