Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added audio test suite; minor code cleanups in test lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ferzkopp committed Dec 24, 2012
1 parent 6ed6a46 commit 4064148
Show file tree
Hide file tree
Showing 13 changed files with 313 additions and 86 deletions.
6 changes: 3 additions & 3 deletions include/SDL_test_assert.h
Expand Up @@ -60,7 +60,7 @@ extern "C" {
* \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
* \param assertDescription Message to log with the assert describing it.
*/
void SDLTest_Assert(int assertCondition, char *assertDescription, ...);
void SDLTest_Assert(int assertCondition, const char *assertDescription, ...);

/**
* \brief Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters.
Expand All @@ -70,14 +70,14 @@ void SDLTest_Assert(int assertCondition, char *assertDescription, ...);
*
* \returns Returns the assertCondition so it can be used to externally to break execution flow if desired.
*/
int SDLTest_AssertCheck(int assertCondition, char *assertDescription, ...);
int SDLTest_AssertCheck(int assertCondition, const char *assertDescription, ...);

/**
* \brief Explicitely pass without checking an assertion condition. Updates assertion counter.
*
* \param assertDescription Message to log with the assert describing it.
*/
void SDLTest_AssertPass(char *assertDescription, ...);
void SDLTest_AssertPass(const char *assertDescription, ...);

/**
* \brief Resets the assert summary counters to zero.
Expand Down
11 changes: 6 additions & 5 deletions include/SDL_test_compare.h
Expand Up @@ -37,6 +37,7 @@
#define _SDL_test_compare_h

#include "SDL.h"

#include "SDL_test_images.h"

#include "begin_code.h"
Expand All @@ -50,13 +51,13 @@ extern "C" {
/**
* \brief Compares a surface and with reference image data for equality
*
* \param sur Surface used in comparison
* \param img Test Surface used in comparison
* \param allowable_error Allowable difference in blending accuracy
* \param surface Surface used in comparison
* \param referenceSurface Test Surface used in comparison
* \param allowable_error Allowable difference (squared) in blending accuracy.
*
* \returns 0 if comparison succeeded, >0 (=number of pixels where comparison failed) if comparison failed, <0 for any other error.
* \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.
*/
int SDLTest_CompareSurfaces(SDL_Surface *sur, SDL_Surface *img, int allowable_error);
int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error);


/* Ends C function definitions when using C++ */
Expand Down
4 changes: 2 additions & 2 deletions include/SDL_test_log.h
Expand Up @@ -49,14 +49,14 @@ extern "C" {
*
* \param fmt Message to be logged
*/
void SDLTest_Log(char *fmt, ...);
void SDLTest_Log(const char *fmt, ...);

/**
* \brief Prints given message with a timestamp in the TEST category and the ERROR priority.
*
* \param fmt Message to be logged
*/
void SDLTest_LogError(char *fmt, ...);
void SDLTest_LogError(const char *fmt, ...);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
Expand Down
21 changes: 9 additions & 12 deletions src/test/SDL_test_assert.c
Expand Up @@ -44,7 +44,7 @@ static Uint32 SDLTest_AssertsPassed = 0;
/*
* Assert that logs and break execution flow on failures (i.e. for harness errors).
*/
void SDLTest_Assert(int assertCondition, char *assertDescription, ...)
void SDLTest_Assert(int assertCondition, const char *assertDescription, ...)
{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
Expand All @@ -62,11 +62,10 @@ void SDLTest_Assert(int assertCondition, char *assertDescription, ...)
/*
* Assert that logs but does not break execution flow on failures (i.e. for test cases).
*/
int SDLTest_AssertCheck(int assertCondition, char *assertDescription, ...)
int SDLTest_AssertCheck(int assertCondition, const char *assertDescription, ...)
{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
char *logFormat = (char *)SDLTest_AssertCheckFormat;

// Print assert description into a buffer
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
Expand All @@ -78,12 +77,12 @@ int SDLTest_AssertCheck(int assertCondition, char *assertDescription, ...)
if (assertCondition == ASSERT_FAIL)
{
SDLTest_AssertsFailed++;
SDLTest_LogError(logFormat, logMessage, "Failed");
SDLTest_LogError(SDLTest_AssertCheckFormat, logMessage, "Failed");
}
else
{
SDLTest_AssertsPassed++;
SDLTest_Log(logFormat, logMessage, "Passed");
SDLTest_Log(SDLTest_AssertCheckFormat, logMessage, "Passed");
}

return assertCondition;
Expand All @@ -92,21 +91,20 @@ int SDLTest_AssertCheck(int assertCondition, char *assertDescription, ...)
/*
* Explicitly passing Assert that logs (i.e. for test cases).
*/
void SDLTest_AssertPass(char *assertDescription, ...)
void SDLTest_AssertPass(const char *assertDescription, ...)
{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
char *logFormat = (char *)SDLTest_AssertCheckFormat;

// Print assert description into a buffer
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
va_start(list, assertDescription);
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
va_end(list);

// Log pass message
// Log pass message
SDLTest_AssertsPassed++;
SDLTest_Log(logFormat, logMessage, "Pass");
SDLTest_Log(SDLTest_AssertCheckFormat, logMessage, "Pass");
}

/*
Expand All @@ -124,15 +122,14 @@ void SDLTest_ResetAssertSummary()
*/
void SDLTest_LogAssertSummary()
{
char *logFormat = (char *)SDLTest_AssertSummaryFormat;
Uint32 totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed;
if (SDLTest_AssertsFailed == 0)
{
SDLTest_Log(logFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
SDLTest_Log(SDLTest_AssertSummaryFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
}
else
{
SDLTest_LogError(logFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
SDLTest_LogError(SDLTest_AssertSummaryFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
}
}

Expand Down
18 changes: 13 additions & 5 deletions src/test/SDL_test_compare.c
Expand Up @@ -42,29 +42,37 @@ int SDLTest_CompareSurfaces( SDL_Surface *surface, SDL_Surface *referenceSurface
Uint8 R, G, B, A;
Uint8 Rd, Gd, Bd, Ad;

/* Make surfacee size is the same. */
if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h))
{
/* Validate input surfaces */
if (surface == NULL || referenceSurface == NULL) {
return -1;
}

/* Make surface size is the same. */
if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h)) {
return -2;
}

/* Sanitize input */
if (allowable_error<0) {
allowable_error = 0;
}

SDL_LockSurface( surface );
SDL_LockSurface( referenceSurface );

ret = 0;
bpp = surface->format->BytesPerPixel;
bpp_reference = referenceSurface->format->BytesPerPixel;

/* Compare image - should be same format. */
for (j=0; j<surface->h; j++) {
for (i=0; i<surface->w; i++) {
p = (Uint8 *)surface->pixels + j * surface->pitch + i * bpp;
p_reference = (Uint8 *)referenceSurface->pixels + j * referenceSurface->pitch + i * bpp_reference;
dist = 0;

SDL_GetRGBA(*(Uint32*)p, surface->format, &R, &G, &B, &A);
SDL_GetRGBA(*(Uint32*)p_reference, referenceSurface->format, &Rd, &Gd, &Bd, &Ad);

dist = 0;
dist += (R-Rd)*(R-Rd);
dist += (G-Gd)*(G-Gd);
dist += (B-Bd)*(B-Bd);
Expand Down
26 changes: 13 additions & 13 deletions src/test/SDL_test_harness.c
Expand Up @@ -51,7 +51,7 @@ static Uint32 SDLTest_TestCaseTimeout = 3600;
* \returns The generated seed string
*/
char *
SDLTest_GenerateRunSeed(const int length)
SDLTest_GenerateRunSeed(const int length)
{
char *seed = NULL;
SDLTest_RandomContext randomContext;
Expand Down Expand Up @@ -97,7 +97,7 @@ char *
*
*/
Uint64
SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iteration)
SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iteration)
{
SDLTest_Md5Context md5Context;
Uint64 *keys;
Expand All @@ -109,17 +109,17 @@ Uint64
Uint32 entireStringLength;
char *buffer;

if (runSeed == NULL || strlen(runSeed)==0) {
if (runSeed == NULL || SDL_strlen(runSeed)==0) {
SDLTest_LogError("Invalid runSeed string.");
return -1;
}

if (suiteName == NULL || strlen(suiteName)==0) {
if (suiteName == NULL || SDL_strlen(suiteName)==0) {
SDLTest_LogError("Invalid suiteName string.");
return -1;
}

if (testName == NULL || strlen(testName)==0) {
if (testName == NULL || SDL_strlen(testName)==0) {
SDLTest_LogError("Invalid testName string.");
return -1;
}
Expand All @@ -130,14 +130,14 @@ Uint64
}

// Convert iteration number into a string
memset(iterationString, 0, sizeof(iterationString));
SDL_memset(iterationString, 0, sizeof(iterationString));
SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iteration);

// Combine the parameters into single string
runSeedLength = strlen(runSeed);
suiteNameLength = strlen(suiteName);
testNameLength = strlen(testName);
iterationStringLength = strlen(iterationString);
runSeedLength = SDL_strlen(runSeed);
suiteNameLength = SDL_strlen(suiteName);
testNameLength = SDL_strlen(testName);
iterationStringLength = SDL_strlen(iterationString);
entireStringLength = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1;
buffer = (char *)SDL_malloc(entireStringLength);
if (buffer == NULL) {
Expand Down Expand Up @@ -167,7 +167,7 @@ Uint64
* \return Timer id or -1 on failure.
*/
SDL_TimerID
SDLTest_SetTestTimeout(int timeout, void (*callback)())
SDLTest_SetTestTimeout(int timeout, void (*callback)())
{
Uint32 timeoutInMilliseconds;
SDL_TimerID timerID;
Expand Down Expand Up @@ -371,7 +371,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
}

// Generate run see if we don't have one already
if (userRunSeed == NULL || strlen(userRunSeed) == 0) {
if (userRunSeed == NULL || SDL_strlen(userRunSeed) == 0) {
runSeed = SDLTest_GenerateRunSeed(16);
if (runSeed == NULL) {
SDLTest_LogError("Generating a random seed failed");
Expand Down Expand Up @@ -488,7 +488,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
suiteCounter,
testCounter,
currentTestName);
if (testCase->description != NULL && strlen(testCase->description)>0) {
if (testCase->description != NULL && SDL_strlen(testCase->description)>0) {
SDLTest_Log("Test Description: '%s'",
(testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
}
Expand Down
14 changes: 8 additions & 6 deletions src/test/SDL_test_log.c
Expand Up @@ -31,10 +31,12 @@
#include "SDL_config.h"

#include <stdarg.h> /* va_list */
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

#include "SDL.h"

#include "SDL_test.h"

/*!
Expand All @@ -54,7 +56,7 @@ char *SDLTest_TimestampToString(const time_t timestamp)
static char buffer[64];
struct tm *local;

memset(buffer, 0, sizeof(buffer));\
SDL_memset(buffer, 0, sizeof(buffer));\
copy = timestamp;
local = localtime(&copy);
strftime(buffer, sizeof(buffer), "%x %X", local);
Expand All @@ -65,13 +67,13 @@ char *SDLTest_TimestampToString(const time_t timestamp)
/*
* Prints given message with a timestamp in the TEST category and INFO priority.
*/
void SDLTest_Log(char *fmt, ...)
void SDLTest_Log(const char *fmt, ...)
{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];

// Print log message into a buffer
memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
va_start(list, fmt);
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
va_end(list);
Expand All @@ -83,13 +85,13 @@ void SDLTest_Log(char *fmt, ...)
/*
* Prints given message with a timestamp in the TEST category and the ERROR priority.
*/
void SDLTest_LogError(char *fmt, ...)
void SDLTest_LogError(const char *fmt, ...)
{
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];

// Print log message into a buffer
memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
va_start(list, fmt);
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
va_end(list);
Expand Down
3 changes: 2 additions & 1 deletion test/Makefile.in
Expand Up @@ -73,7 +73,8 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
$(srcdir)/testautomation_platform.c \
$(srcdir)/testautomation_rect.c \
$(srcdir)/testautomation_render.c \
$(srcdir)/testautomation_rwops.c
$(srcdir)/testautomation_rwops.c \
$(srcdir)/testautomation_audio.c
$(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS)

testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c
Expand Down
2 changes: 1 addition & 1 deletion test/testautomation.c
Expand Up @@ -101,7 +101,7 @@ main(int argc, char *argv[])
}

/* Call Harness */
result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, filter, testIterations);
result = SDLTest_RunSuites(testSuites, (const char *)userRunSeed, userExecKey, (const char *)filter, testIterations);

/* Clean up */
if (userRunSeed != NULL) {
Expand Down

0 comments on commit 4064148

Please sign in to comment.