Fix assert format strings/parameters in testautomation modules; improve output of SDL_CompareSurfaces to aid debugging; update platform_testSetErrorInvalidInput for SDL changes

This commit is contained in:
Andreas Schiffler 2014-11-30 20:55:27 -08:00
parent 0d38073a54
commit 52760dcdf1
8 changed files with 83 additions and 36 deletions

View File

@ -51,9 +51,9 @@ extern "C" {
*
* \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);

View File

@ -43,6 +43,7 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface,
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 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface,
/* Allow some difference in blending accuracy */
if (dist > allowable_error) {
ret++;
if (ret == 1) {
sampleErrorX = i;
sampleErrorY = j;
sampleDist = dist;
}
}
}
}
@ -96,6 +102,8 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface,
/* 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);

View File

@ -34,16 +34,16 @@ int platform_testTypes(void *arg)
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 @@ int platform_testSetErrorInvalidInput(void *arg)
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 @@ int platform_testSetErrorInvalidInput(void *arg)
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 */

View File

@ -113,6 +113,9 @@ int render_testPrimitives (void *arg)
int checkFailCount1;
int checkFailCount2;
/* Clear surface. */
_clearScreen();
/* Need drawcolor or just skip test. */
SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor");
@ -184,7 +187,10 @@ int render_testPrimitives (void *arg)
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 render_testPrimitivesBlend (void *arg)
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 @@ int render_testPrimitivesBlend (void *arg)
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 @@ render_testBlit(void *arg)
int i, j, ni, nj;
int checkFailCount1;
/* Clear surface. */
_clearScreen();
/* Need drawcolor or just skip test. */
SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor)");
@ -390,6 +404,9 @@ render_testBlit(void *arg)
}
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 @@ render_testBlitColor (void *arg)
int checkFailCount1;
int checkFailCount2;
/* Clear surface. */
_clearScreen();
/* Create face surface. */
tface = _loadTestFace();
SDLTest_AssertCheck(tface != NULL, "Verify _loadTestFace() result");
@ -458,6 +478,9 @@ render_testBlitColor (void *arg)
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 @@ render_testBlitAlpha (void *arg)
int checkFailCount1;
int checkFailCount2;
/* Clear surface. */
_clearScreen();
/* Need alpha or just skip test. */
SDLTest_AssertCheck(_hasTexAlpha(), "_hasTexAlpha");
@ -529,6 +555,9 @@ render_testBlitAlpha (void *arg)
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 @@ render_testBlitBlend (void *arg)
/* 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 @@ render_testBlitBlend (void *arg)
/* 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 @@ render_testBlitBlend (void *arg)
/* 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 @@ render_testBlitBlend (void *arg)
/* 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 @@ render_testBlitBlend (void *arg)
/* 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 @@ _compare(SDL_Surface *referenceSurface, int allowable_error)
*
* \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 @@ _clearScreen(void)
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 );

View File

@ -105,7 +105,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
/* 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 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
/* 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 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
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 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
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 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
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 @@ rwops_testFileWriteReadEndian(void)
/* 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);

View File

@ -1076,7 +1076,7 @@ sdltest_randomIntegerInRange(void *arg)
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();

View File

@ -42,7 +42,7 @@ timer_getPerformanceCounter(void *arg)
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 @@ timer_getPerformanceFrequency(void *arg)
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;
}

View File

@ -740,7 +740,7 @@ video_getWindowGammaRampNegative(void *arg)
/* 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 @@ video_getSetWindowData(void *arg)
/* 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 @@ video_getSetWindowData(void *arg)
/* 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);