Added audio test suite; minor code cleanups in test lib

This commit is contained in:
Andreas Schiffler 2012-12-24 14:43:57 -08:00
parent 2e4dc511a0
commit d9a9083464
13 changed files with 313 additions and 86 deletions

View file

@ -60,7 +60,7 @@ extern "C" {
* \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0). * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
* \param assertDescription Message to log with the assert describing it. * \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. * \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. * \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. * \brief Explicitely pass without checking an assertion condition. Updates assertion counter.
* *
* \param assertDescription Message to log with the assert describing it. * \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. * \brief Resets the assert summary counters to zero.

View file

@ -37,6 +37,7 @@
#define _SDL_test_compare_h #define _SDL_test_compare_h
#include "SDL.h" #include "SDL.h"
#include "SDL_test_images.h" #include "SDL_test_images.h"
#include "begin_code.h" #include "begin_code.h"
@ -50,13 +51,13 @@ extern "C" {
/** /**
* \brief Compares a surface and with reference image data for equality * \brief Compares a surface and with reference image data for equality
* *
* \param sur Surface used in comparison * \param surface Surface used in comparison
* \param img Test Surface used in comparison * \param referenceSurface Test Surface used in comparison
* \param allowable_error Allowable difference in blending accuracy * \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++ */ /* Ends C function definitions when using C++ */

View file

@ -49,14 +49,14 @@ extern "C" {
* *
* \param fmt Message to be logged * \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. * \brief Prints given message with a timestamp in the TEST category and the ERROR priority.
* *
* \param fmt Message to be logged * \param fmt Message to be logged
*/ */
void SDLTest_LogError(char *fmt, ...); void SDLTest_LogError(const char *fmt, ...);
/* Ends C function definitions when using C++ */ /* Ends C function definitions when using C++ */
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -44,7 +44,7 @@ static Uint32 SDLTest_AssertsPassed = 0;
/* /*
* Assert that logs and break execution flow on failures (i.e. for harness errors). * 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; va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; 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). * 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; va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
char *logFormat = (char *)SDLTest_AssertCheckFormat;
// Print assert description into a buffer // Print assert description into a buffer
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH); SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
@ -78,12 +77,12 @@ int SDLTest_AssertCheck(int assertCondition, char *assertDescription, ...)
if (assertCondition == ASSERT_FAIL) if (assertCondition == ASSERT_FAIL)
{ {
SDLTest_AssertsFailed++; SDLTest_AssertsFailed++;
SDLTest_LogError(logFormat, logMessage, "Failed"); SDLTest_LogError(SDLTest_AssertCheckFormat, logMessage, "Failed");
} }
else else
{ {
SDLTest_AssertsPassed++; SDLTest_AssertsPassed++;
SDLTest_Log(logFormat, logMessage, "Passed"); SDLTest_Log(SDLTest_AssertCheckFormat, logMessage, "Passed");
} }
return assertCondition; return assertCondition;
@ -92,11 +91,10 @@ int SDLTest_AssertCheck(int assertCondition, char *assertDescription, ...)
/* /*
* Explicitly passing Assert that logs (i.e. for test cases). * Explicitly passing Assert that logs (i.e. for test cases).
*/ */
void SDLTest_AssertPass(char *assertDescription, ...) void SDLTest_AssertPass(const char *assertDescription, ...)
{ {
va_list list; va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
char *logFormat = (char *)SDLTest_AssertCheckFormat;
// Print assert description into a buffer // Print assert description into a buffer
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH); SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
@ -106,7 +104,7 @@ void SDLTest_AssertPass(char *assertDescription, ...)
// Log pass message // Log pass message
SDLTest_AssertsPassed++; SDLTest_AssertsPassed++;
SDLTest_Log(logFormat, logMessage, "Pass"); SDLTest_Log(SDLTest_AssertCheckFormat, logMessage, "Pass");
} }
/* /*
@ -124,15 +122,14 @@ void SDLTest_ResetAssertSummary()
*/ */
void SDLTest_LogAssertSummary() void SDLTest_LogAssertSummary()
{ {
char *logFormat = (char *)SDLTest_AssertSummaryFormat;
Uint32 totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed; Uint32 totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed;
if (SDLTest_AssertsFailed == 0) if (SDLTest_AssertsFailed == 0)
{ {
SDLTest_Log(logFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed); SDLTest_Log(SDLTest_AssertSummaryFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
} }
else else
{ {
SDLTest_LogError(logFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed); SDLTest_LogError(SDLTest_AssertSummaryFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
} }
} }

View file

@ -42,29 +42,37 @@ int SDLTest_CompareSurfaces( SDL_Surface *surface, SDL_Surface *referenceSurface
Uint8 R, G, B, A; Uint8 R, G, B, A;
Uint8 Rd, Gd, Bd, Ad; Uint8 Rd, Gd, Bd, Ad;
/* Make surfacee size is the same. */ /* Validate input surfaces */
if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h)) if (surface == NULL || referenceSurface == NULL) {
{
return -1; 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( surface );
SDL_LockSurface( referenceSurface ); SDL_LockSurface( referenceSurface );
ret = 0; ret = 0;
bpp = surface->format->BytesPerPixel; bpp = surface->format->BytesPerPixel;
bpp_reference = referenceSurface->format->BytesPerPixel; bpp_reference = referenceSurface->format->BytesPerPixel;
/* Compare image - should be same format. */ /* Compare image - should be same format. */
for (j=0; j<surface->h; j++) { for (j=0; j<surface->h; j++) {
for (i=0; i<surface->w; i++) { for (i=0; i<surface->w; i++) {
p = (Uint8 *)surface->pixels + j * surface->pitch + i * bpp; p = (Uint8 *)surface->pixels + j * surface->pitch + i * bpp;
p_reference = (Uint8 *)referenceSurface->pixels + j * referenceSurface->pitch + i * bpp_reference; 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, surface->format, &R, &G, &B, &A);
SDL_GetRGBA(*(Uint32*)p_reference, referenceSurface->format, &Rd, &Gd, &Bd, &Ad); SDL_GetRGBA(*(Uint32*)p_reference, referenceSurface->format, &Rd, &Gd, &Bd, &Ad);
dist = 0;
dist += (R-Rd)*(R-Rd); dist += (R-Rd)*(R-Rd);
dist += (G-Gd)*(G-Gd); dist += (G-Gd)*(G-Gd);
dist += (B-Bd)*(B-Bd); dist += (B-Bd)*(B-Bd);

View file

@ -109,17 +109,17 @@ Uint64
Uint32 entireStringLength; Uint32 entireStringLength;
char *buffer; char *buffer;
if (runSeed == NULL || strlen(runSeed)==0) { if (runSeed == NULL || SDL_strlen(runSeed)==0) {
SDLTest_LogError("Invalid runSeed string."); SDLTest_LogError("Invalid runSeed string.");
return -1; return -1;
} }
if (suiteName == NULL || strlen(suiteName)==0) { if (suiteName == NULL || SDL_strlen(suiteName)==0) {
SDLTest_LogError("Invalid suiteName string."); SDLTest_LogError("Invalid suiteName string.");
return -1; return -1;
} }
if (testName == NULL || strlen(testName)==0) { if (testName == NULL || SDL_strlen(testName)==0) {
SDLTest_LogError("Invalid testName string."); SDLTest_LogError("Invalid testName string.");
return -1; return -1;
} }
@ -130,14 +130,14 @@ Uint64
} }
// Convert iteration number into a string // 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); SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iteration);
// Combine the parameters into single string // Combine the parameters into single string
runSeedLength = strlen(runSeed); runSeedLength = SDL_strlen(runSeed);
suiteNameLength = strlen(suiteName); suiteNameLength = SDL_strlen(suiteName);
testNameLength = strlen(testName); testNameLength = SDL_strlen(testName);
iterationStringLength = strlen(iterationString); iterationStringLength = SDL_strlen(iterationString);
entireStringLength = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1; entireStringLength = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1;
buffer = (char *)SDL_malloc(entireStringLength); buffer = (char *)SDL_malloc(entireStringLength);
if (buffer == NULL) { if (buffer == NULL) {
@ -371,7 +371,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
} }
// Generate run see if we don't have one already // 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); runSeed = SDLTest_GenerateRunSeed(16);
if (runSeed == NULL) { if (runSeed == NULL) {
SDLTest_LogError("Generating a random seed failed"); SDLTest_LogError("Generating a random seed failed");
@ -488,7 +488,7 @@ int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], const char *user
suiteCounter, suiteCounter,
testCounter, testCounter,
currentTestName); currentTestName);
if (testCase->description != NULL && strlen(testCase->description)>0) { if (testCase->description != NULL && SDL_strlen(testCase->description)>0) {
SDLTest_Log("Test Description: '%s'", SDLTest_Log("Test Description: '%s'",
(testCase->description) ? testCase->description : SDLTest_InvalidNameFormat); (testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
} }

View file

@ -35,6 +35,8 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "SDL.h"
#include "SDL_test.h" #include "SDL_test.h"
/*! /*!
@ -54,7 +56,7 @@ char *SDLTest_TimestampToString(const time_t timestamp)
static char buffer[64]; static char buffer[64];
struct tm *local; struct tm *local;
memset(buffer, 0, sizeof(buffer));\ SDL_memset(buffer, 0, sizeof(buffer));\
copy = timestamp; copy = timestamp;
local = localtime(&copy); local = localtime(&copy);
strftime(buffer, sizeof(buffer), "%x %X", local); 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. * 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; va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
// Print log message into a buffer // 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); va_start(list, fmt);
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list); SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
va_end(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. * 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; va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH]; char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
// Print log message into a buffer // 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); va_start(list, fmt);
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list); SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
va_end(list); va_end(list);

View file

@ -73,7 +73,8 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
$(srcdir)/testautomation_platform.c \ $(srcdir)/testautomation_platform.c \
$(srcdir)/testautomation_rect.c \ $(srcdir)/testautomation_rect.c \
$(srcdir)/testautomation_render.c \ $(srcdir)/testautomation_render.c \
$(srcdir)/testautomation_rwops.c $(srcdir)/testautomation_rwops.c \
$(srcdir)/testautomation_audio.c
$(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS) $(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS)
testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c

View file

@ -101,7 +101,7 @@ main(int argc, char *argv[])
} }
/* Call Harness */ /* Call Harness */
result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, filter, testIterations); result = SDLTest_RunSuites(testSuites, (const char *)userRunSeed, userExecKey, (const char *)filter, testIterations);
/* Clean up */ /* Clean up */
if (userRunSeed != NULL) { if (userRunSeed != NULL) {

209
test/testautomation_audio.c Normal file
View file

@ -0,0 +1,209 @@
/**
* Original code: automated SDL audio test written by Edgar Simo "bobbens"
* New/updated tests: aschiffler at ferzkopp dot net
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
/* ================= Test Case Implementation ================== */
/* Fixture */
void
_audioSetUp(void *arg)
{
/* Start SDL audio subsystem */
int ret = SDL_InitSubSystem( SDL_INIT_AUDIO );
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)");
SDLTest_AssertCheck(ret==0, "Check result from SDL_InitSubSystem(SDL_INIT_AUDIO)");
if (ret != 0) {
SDLTest_LogError("%s", SDL_GetError());
}
}
/* Test case functions */
/**
* \brief Enumerate and name available audio devices (output and capture).
*
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
*/
int audio_enumerateAndNameAudioDevices()
{
int t, tt;
int i, n, nn;
const char *name, *nameAgain;
/* Iterate over types: t=0 output device, t=1 input/capture device */
for (t=0; t<2; t++) {
/* Get number of devices. */
n = SDL_GetNumAudioDevices(t);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(%i)", t);
SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "output" : "capture", n);
SDLTest_AssertCheck(n >= 0, "Validate result is >= 0, got: %i", n);
/* Variation of non-zero type */
if (t==1) {
tt = t + SDLTest_RandomIntegerInRange(1,10);
nn = SDL_GetNumAudioDevices(tt);
SDLTest_AssertCheck(n==nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", tt, n, nn);
nn = SDL_GetNumAudioDevices(-tt);
SDLTest_AssertCheck(n==nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", -tt, n, nn);
}
/* List devices. */
if (n>0) {
for (i=0; i<n; i++) {
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, t);
if (name != NULL) {
SDLTest_AssertCheck(SDL_strlen(name)>0, "verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, t, name);
if (t==1) {
/* Also try non-zero type */
tt = t + SDLTest_RandomIntegerInRange(1,10);
nameAgain = SDL_GetAudioDeviceName(i, tt);
SDLTest_AssertCheck(nameAgain != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, tt);
if (nameAgain != NULL) {
SDLTest_AssertCheck(SDL_strlen(nameAgain)>0, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, tt, nameAgain);
SDLTest_AssertCheck(SDL_strcmp(name, nameAgain)==0,
"Verify SDL_GetAudioDeviceName(%i, %i) and SDL_GetAudioDeviceName(%i %i) return the same string",
i, t, i, tt);
}
}
}
}
}
}
return TEST_COMPLETED;
}
/**
* \brief Negative tests around enumeration and naming of audio devices.
*
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
* \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
*/
int audio_enumerateAndNameAudioDevicesNegativeTests()
{
int t;
int i, j, no, nc;
const char *name;
/* Get number of devices. */
no = SDL_GetNumAudioDevices(0);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
nc = SDL_GetNumAudioDevices(1);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(1)");
/* Invalid device index when getting name */
for (t=0; t<2; t++) {
/* Negative device index */
i = SDLTest_RandomIntegerInRange(-10,-1);
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result NULL, expected NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
/* Device index past range */
for (j=0; j<3; j++) {
i = (t) ? nc+j : no+j;
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
}
/* Capture index past capture range but within output range */
if ((no>0) && (no>nc) && (t==1)) {
i = no-1;
name = SDL_GetAudioDeviceName(i, t);
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
}
}
return TEST_COMPLETED;
}
/**
* @brief Checks available audio driver names.
*/
int audio_printAudioDrivers()
{
int i, n;
const char *name;
/* Get number of drivers */
n = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(n>=0, "Verify number of audio drivers >= 0, got: %i", n);
/* List drivers. */
if (n>0)
{
for (i=0; i<n; i++) {
name = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%i)", i);
SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
if (name != NULL) {
SDLTest_AssertCheck(SDL_strlen(name)>0, "Verify returned name is not empty, got: '%s'", name);
}
}
}
return TEST_COMPLETED;
}
/**
* @brief Checks current audio driver name with initialized audio.
*/
int audio_printCurrentAudioDriver()
{
const char *name;
/* Check current audio driver */
name = SDL_GetCurrentAudioDriver();
SDLTest_AssertPass("Call to SDL_GetCurrentAudioDriver()");
SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
if (name != NULL) {
SDLTest_AssertCheck(SDL_strlen(name)>0, "Verify returned name is not empty, got: '%s'", name);
}
return TEST_COMPLETED;
}
/* ================= Test Case References ================== */
/* Audio test cases */
static const SDLTest_TestCaseReference audioTest1 =
{ (SDLTest_TestCaseFp)audio_enumerateAndNameAudioDevices, "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (output and capture)", TEST_ENABLED };
static const SDLTest_TestCaseReference audioTest2 =
{ (SDLTest_TestCaseFp)audio_enumerateAndNameAudioDevicesNegativeTests, "audio_enumerateAndNameAudioDevicesNegativeTests", "Negative tests around enumeration and naming of audio devices.", TEST_ENABLED };
static const SDLTest_TestCaseReference audioTest3 =
{ (SDLTest_TestCaseFp)audio_printAudioDrivers, "audio_printAudioDrivers", "Checks available audio driver names.", TEST_ENABLED };
static const SDLTest_TestCaseReference audioTest4 =
{ (SDLTest_TestCaseFp)audio_printCurrentAudioDriver, "audio_printCurrentAudioDriver", "Checks current audio driver name with initialized audio.", TEST_ENABLED };
/* Sequence of Audio test cases */
static const SDLTest_TestCaseReference *audioTests[] = {
&audioTest1, &audioTest2, &audioTest3, &audioTest4, NULL
};
/* Audio test suite (global) */
SDLTest_TestSuiteReference audioTestSuite = {
"Audio",
_audioSetUp,
audioTests,
NULL
};

View file

@ -951,12 +951,12 @@ int rect_testEnclosePoints(void *arg)
SDL_Rect result; SDL_Rect result;
SDL_bool anyEnclosed; SDL_bool anyEnclosed;
SDL_bool anyEnclosedNoResult; SDL_bool anyEnclosedNoResult;
// Create input data, tracking result
SDL_bool expectedEnclosed = SDL_TRUE; SDL_bool expectedEnclosed = SDL_TRUE;
int newx, newy; int newx, newy;
int minx, maxx, miny, maxy; int minx = 0, maxx = 0, miny = 0, maxy = 0;
int i; int i;
// Create input data, tracking result
for (i=0; i<numPoints; i++) { for (i=0; i<numPoints; i++) {
newx = SDLTest_RandomIntegerInRange(-1024, 1024); newx = SDLTest_RandomIntegerInRange(-1024, 1024);
newy = SDLTest_RandomIntegerInRange(-1024, 1024); newy = SDLTest_RandomIntegerInRange(-1024, 1024);
@ -965,8 +965,10 @@ int rect_testEnclosePoints(void *arg)
points[i].x = newx; points[i].x = newx;
points[i].y = newy; points[i].y = newy;
if (i==0) { if (i==0) {
minx=maxx=newx; minx = newx;
miny=maxy=newy; maxx = newx;
miny = newy;
maxy = newy;
} else { } else {
if (newx < minx) minx = newx; if (newx < minx) minx = newx;
if (newx > maxx) maxx = newx; if (newx > maxx) maxx = newx;
@ -1020,12 +1022,12 @@ int rect_testEnclosePointsRepeatedInput(void *arg)
SDL_Rect result; SDL_Rect result;
SDL_bool anyEnclosed; SDL_bool anyEnclosed;
SDL_bool anyEnclosedNoResult; SDL_bool anyEnclosedNoResult;
// Create input data, tracking result
SDL_bool expectedEnclosed = SDL_TRUE; SDL_bool expectedEnclosed = SDL_TRUE;
int newx, newy; int newx, newy;
int minx, maxx, miny, maxy; int minx = 0, maxx = 0, miny = 0, maxy = 0;
int i; int i;
// Create input data, tracking result
for (i=0; i<numPoints; i++) { for (i=0; i<numPoints; i++) {
if (i < halfPoints) { if (i < halfPoints) {
newx = SDLTest_RandomIntegerInRange(-1024, 1024); newx = SDLTest_RandomIntegerInRange(-1024, 1024);
@ -1039,8 +1041,10 @@ int rect_testEnclosePointsRepeatedInput(void *arg)
points[i].x = newx; points[i].x = newx;
points[i].y = newy; points[i].y = newy;
if (i==0) { if (i==0) {
minx=maxx=newx; minx = newx;
miny=maxy=newy; maxx = newx;
miny = newy;
maxy = newy;
} else { } else {
if (newx < minx) minx = newx; if (newx < minx) minx = newx;
if (newx > maxx) maxx = newx; if (newx > maxx) maxx = newx;
@ -1097,7 +1101,7 @@ int rect_testEnclosePointsWithClipping(void *arg)
SDL_bool anyEnclosedNoResult; SDL_bool anyEnclosedNoResult;
SDL_bool expectedEnclosed = SDL_FALSE; SDL_bool expectedEnclosed = SDL_FALSE;
int newx, newy; int newx, newy;
int minx, maxx, miny, maxy; int minx = 0, maxx = 0, miny = 0, maxy = 0;
int i; int i;
// Setup clipping rectangle // Setup clipping rectangle
@ -1117,8 +1121,10 @@ int rect_testEnclosePointsWithClipping(void *arg)
if ((newx>=refClip.x) && (newx<(refClip.x + refClip.w)) && if ((newx>=refClip.x) && (newx<(refClip.x + refClip.w)) &&
(newy>=refClip.y) && (newy<(refClip.y + refClip.h))) { (newy>=refClip.y) && (newy<(refClip.y + refClip.h))) {
if (expectedEnclosed==SDL_FALSE) { if (expectedEnclosed==SDL_FALSE) {
minx=maxx=newx; minx = newx;
miny=maxy=newy; maxx = newx;
miny = newy;
maxy = newy;
} else { } else {
if (newx < minx) minx = newx; if (newx < minx) minx = newx;
if (newx > maxx) maxx = newx; if (newx > maxx) maxx = newx;

View file

@ -690,7 +690,6 @@ render_testBlitBlend (void *arg)
} }
/** /**
* @brief Checks to see if functionality is supported. Helper function. * @brief Checks to see if functionality is supported. Helper function.
*/ */
@ -722,6 +721,7 @@ _hasDrawColor (void)
ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a ); ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a );
if (!_isSupported(ret)) if (!_isSupported(ret))
fail = 1; fail = 1;
/* Restore natural. */ /* Restore natural. */
ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE ); ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE );
if (!_isSupported(ret)) if (!_isSupported(ret))
@ -730,6 +730,7 @@ _hasDrawColor (void)
/* Something failed, consider not available. */ /* Something failed, consider not available. */
if (fail) if (fail)
return 0; return 0;
/* Not set properly, consider failed. */ /* Not set properly, consider failed. */
else if ((r != 100) || (g != 100) || (b != 100) || (a != 100)) else if ((r != 100) || (g != 100) || (b != 100) || (a != 100))
return 0; return 0;
@ -839,7 +840,7 @@ _hasTexColor (void)
/* Get test face. */ /* Get test face. */
tface = _loadTestFace(); tface = _loadTestFace();
if (tface == 0) if (tface == NULL)
return 0; return 0;
/* See if supported. */ /* See if supported. */
@ -879,7 +880,7 @@ _hasTexAlpha(void)
/* Get test face. */ /* Get test face. */
tface = _loadTestFace(); tface = _loadTestFace();
if (tface == 0) if (tface == NULL)
return 0; return 0;
/* See if supported. */ /* See if supported. */
@ -901,7 +902,8 @@ _hasTexAlpha(void)
return 1; return 1;
} }
static _renderCompareCount = 0; /* Counter for _compare calls use for filename creation when comparisons fail */
static int _renderCompareCount = 0;
/** /**
* @brief Compares screen pixels with image pixels. Helper function. * @brief Compares screen pixels with image pixels. Helper function.
@ -920,7 +922,7 @@ _compare(const char *msg, SDL_Surface *s, int allowable_error)
{ {
int ret; int ret;
SDL_Rect rect; SDL_Rect rect;
Uint8 pix[4*80*60]; Uint8 pix[4*TESTRENDER_SCREEN_W*TESTRENDER_SCREEN_H];
SDL_Surface *testsur; SDL_Surface *testsur;
char imageFilename[128]; char imageFilename[128];
char referenceFilename[128]; char referenceFilename[128];
@ -929,8 +931,8 @@ _compare(const char *msg, SDL_Surface *s, int allowable_error)
/* Explicitly specify the rect in case the window isn't expected size... */ /* Explicitly specify the rect in case the window isn't expected size... */
rect.x = 0; rect.x = 0;
rect.y = 0; rect.y = 0;
rect.w = 80; rect.w = TESTRENDER_SCREEN_W;
rect.h = 60; rect.h = TESTRENDER_SCREEN_H;
ret = SDL_RenderReadPixels(renderer, &rect, RENDER_COMPARE_FORMAT, pix, 80*4 ); ret = SDL_RenderReadPixels(renderer, &rect, RENDER_COMPARE_FORMAT, pix, 80*4 );
SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderReadPixels, expected: 0, got: %i", ret); SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderReadPixels, expected: 0, got: %i", ret);
@ -943,13 +945,14 @@ _compare(const char *msg, SDL_Surface *s, int allowable_error)
ret = SDLTest_CompareSurfaces( testsur, s, allowable_error ); ret = SDLTest_CompareSurfaces( testsur, s, allowable_error );
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Save source image and reference image for analysis */
_renderCompareCount++; _renderCompareCount++;
if (ret != 0) { if (ret != 0) {
SDL_snprintf(imageFilename, 127, "image%i.bmp", _renderCompareCount); SDL_snprintf(imageFilename, 127, "compare%04d_SourceImage.bmp", _renderCompareCount);
SDL_SaveBMP(testsur, imageFilename); SDL_SaveBMP(testsur, imageFilename);
SDL_snprintf(referenceFilename, 127, "reference%i.bmp", _renderCompareCount); SDL_snprintf(referenceFilename, 127, "compare%04d_ReferenceImage.bmp", _renderCompareCount);
SDL_SaveBMP(s, referenceFilename); SDL_SaveBMP(s, referenceFilename);
SDLTest_LogError("Surfaces from failed comparison saved as %s and %s", imageFilename, referenceFilename); SDLTest_LogError("Surfaces from failed comparison saved as '%s' and '%s'", imageFilename, referenceFilename);
} }
/* Clean up. */ /* Clean up. */

View file

@ -9,7 +9,7 @@
#include "SDL_test.h" #include "SDL_test.h"
// Test collections // Test collections
//extern SDLTest_TestSuiteReference audioTestSuite; extern SDLTest_TestSuiteReference audioTestSuite;
extern SDLTest_TestSuiteReference clipboardTestSuite; extern SDLTest_TestSuiteReference clipboardTestSuite;
//extern SDLTest_TestSuiteReference eventsTestSuite; //extern SDLTest_TestSuiteReference eventsTestSuite;
//extern SDLTest_TestSuiteReference keyboardTestSuite; //extern SDLTest_TestSuiteReference keyboardTestSuite;
@ -23,7 +23,7 @@ extern SDLTest_TestSuiteReference rwopsTestSuite;
// All test suites // All test suites
SDLTest_TestSuiteReference *testSuites[] = { SDLTest_TestSuiteReference *testSuites[] = {
// &audioTestSuite, &audioTestSuite,
&clipboardTestSuite, &clipboardTestSuite,
// &eventsTestSuite, // &eventsTestSuite,
// &keyboardTestSuite, // &keyboardTestSuite,