Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix assert format strings/parameters in testautomation modules; impro…
…ve output of SDL_CompareSurfaces to aid debugging; update platform_testSetErrorInvalidInput for SDL changes
  • Loading branch information
ferzkopp committed Dec 1, 2014
1 parent 0d38073 commit 52760dc
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 36 deletions.
4 changes: 2 additions & 2 deletions include/SDL_test_compare.h
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions src/test/SDL_test_compare.c
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
}
}
}
}
Expand All @@ -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);
Expand Down
25 changes: 8 additions & 17 deletions test/testautomation_platform.c
Expand Up @@ -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;
}
Expand Down Expand Up @@ -395,36 +395,27 @@ 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,
"SDL_GetError() != NULL");
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 */
Expand Down
56 changes: 52 additions & 4 deletions test/testautomation_render.c
Expand Up @@ -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");

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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)");
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -644,27 +673,39 @@ 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;

/* 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;

/* 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;

/* 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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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 );
Expand Down
14 changes: 7 additions & 7 deletions test/testautomation_rwops.c
Expand Up @@ -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);
Expand All @@ -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 );
Expand All @@ -144,15 +144,15 @@ _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);

i = SDL_RWseek( rw, -1, RW_SEEK_END );
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);

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/testautomation_sdltest.c
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test/testautomation_timer.c
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions test/testautomation_video.c
Expand Up @@ -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;
Expand Down Expand Up @@ -1619,15 +1619,15 @@ 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);
SDLTest_AssertCheck(SDL_strcmp(referenceUserdata2, userdata2) == 0, "Validate that userdata2 was not changed, expected: %s, got: %s", referenceUserdata2, userdata2);

/* 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);
Expand Down

0 comments on commit 52760dc

Please sign in to comment.