Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added audio test suite; minor code cleanups in test lib

  • Loading branch information
ferzkopp committed Dec 24, 2012
1 parent 6ed6a46 commit 40641481b66af6eac31f567920ed47382adcaa96
@@ -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.
@@ -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.
@@ -37,6 +37,7 @@
#define _SDL_test_compare_h

#include "SDL.h"

#include "SDL_test_images.h"

#include "begin_code.h"
@@ -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++ */
@@ -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
@@ -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];
@@ -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);
@@ -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;
@@ -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");
}

/*
@@ -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);
}
}

@@ -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);
@@ -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;
@@ -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;
@@ -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;
}
@@ -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) {
@@ -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;
@@ -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");
@@ -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);
}
@@ -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"

/*!
@@ -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);
@@ -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);
@@ -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);
@@ -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
@@ -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) {

0 comments on commit 4064148

Please sign in to comment.