From 40641481b66af6eac31f567920ed47382adcaa96 Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Mon, 24 Dec 2012 14:43:57 -0800 Subject: [PATCH] Added audio test suite; minor code cleanups in test lib --- include/SDL_test_assert.h | 6 +- include/SDL_test_compare.h | 11 +- include/SDL_test_log.h | 4 +- src/test/SDL_test_assert.c | 21 ++-- src/test/SDL_test_compare.c | 18 ++- src/test/SDL_test_harness.c | 26 ++--- src/test/SDL_test_log.c | 14 ++- test/Makefile.in | 3 +- test/testautomation.c | 2 +- test/testautomation_audio.c | 209 +++++++++++++++++++++++++++++++++++ test/testautomation_rect.c | 56 +++++----- test/testautomation_render.c | 25 +++-- test/testautomation_suites.h | 4 +- 13 files changed, 313 insertions(+), 86 deletions(-) create mode 100644 test/testautomation_audio.c diff --git a/include/SDL_test_assert.h b/include/SDL_test_assert.h index 8648aa9c2..ad27fe7d4 100644 --- a/include/SDL_test_assert.h +++ b/include/SDL_test_assert.h @@ -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. diff --git a/include/SDL_test_compare.h b/include/SDL_test_compare.h index c22eb1bbd..f214e9cc3 100644 --- a/include/SDL_test_compare.h +++ b/include/SDL_test_compare.h @@ -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++ */ diff --git a/include/SDL_test_log.h b/include/SDL_test_log.h index e6b8d2b5c..5334eba97 100644 --- a/include/SDL_test_log.h +++ b/include/SDL_test_log.h @@ -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 diff --git a/src/test/SDL_test_assert.c b/src/test/SDL_test_assert.c index e0ea7f8d9..0d20a75a0 100644 --- a/src/test/SDL_test_assert.c +++ b/src/test/SDL_test_assert.c @@ -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,11 +91,10 @@ 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); @@ -104,9 +102,9 @@ void SDLTest_AssertPass(char *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); } } diff --git a/src/test/SDL_test_compare.c b/src/test/SDL_test_compare.c index d2e878d31..22ca6481e 100644 --- a/src/test/SDL_test_compare.c +++ b/src/test/SDL_test_compare.c @@ -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; jh; j++) { for (i=0; iw; 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); diff --git a/src/test/SDL_test_harness.c b/src/test/SDL_test_harness.c index bccdd0f3d..39424402b 100644 --- a/src/test/SDL_test_harness.c +++ b/src/test/SDL_test_harness.c @@ -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); } diff --git a/src/test/SDL_test_log.c b/src/test/SDL_test_log.c index 4c7579510..4279f1a96 100644 --- a/src/test/SDL_test_log.c +++ b/src/test/SDL_test_log.c @@ -31,10 +31,12 @@ #include "SDL_config.h" #include /* va_list */ -#include +#include #include #include +#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(©); 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); diff --git a/test/Makefile.in b/test/Makefile.in index 7f61ca060..c18be7637 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -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 diff --git a/test/testautomation.c b/test/testautomation.c index 19a4e6099..cfa384987 100644 --- a/test/testautomation.c +++ b/test/testautomation.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) { diff --git a/test/testautomation_audio.c b/test/testautomation_audio.c new file mode 100644 index 000000000..42d5a85dc --- /dev/null +++ b/test/testautomation_audio.c @@ -0,0 +1,209 @@ +/** + * Original code: automated SDL audio test written by Edgar Simo "bobbens" + * New/updated tests: aschiffler at ferzkopp dot net + */ + +#include + +#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; i0, "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; i0, "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 +}; diff --git a/test/testautomation_rect.c b/test/testautomation_rect.c index 0a3ba1a36..98ac8424f 100644 --- a/test/testautomation_rect.c +++ b/test/testautomation_rect.c @@ -951,12 +951,12 @@ int rect_testEnclosePoints(void *arg) SDL_Rect result; SDL_bool anyEnclosed; SDL_bool anyEnclosedNoResult; - - // Create input data, tracking result SDL_bool expectedEnclosed = SDL_TRUE; int newx, newy; - int minx, maxx, miny, maxy; + int minx = 0, maxx = 0, miny = 0, maxy = 0; int i; + + // Create input data, tracking result for (i=0; imaxx) maxx=newx; - if (newymaxy) maxy=newy; + if (newx < minx) minx = newx; + if (newx > maxx) maxx = newx; + if (newy < miny) miny = newy; + if (newy > maxy) maxy = newy; } } @@ -1020,12 +1022,12 @@ int rect_testEnclosePointsRepeatedInput(void *arg) SDL_Rect result; SDL_bool anyEnclosed; SDL_bool anyEnclosedNoResult; - - // Create input data, tracking result SDL_bool expectedEnclosed = SDL_TRUE; int newx, newy; - int minx, maxx, miny, maxy; + int minx = 0, maxx = 0, miny = 0, maxy = 0; int i; + + // Create input data, tracking result for (i=0; imaxx) maxx=newx; - if (newymaxy) maxy=newy; + if (newx < minx) minx = newx; + if (newx > maxx) maxx = newx; + if (newy < miny) miny = newy; + if (newy > maxy) maxy = newy; } } @@ -1097,7 +1101,7 @@ int rect_testEnclosePointsWithClipping(void *arg) SDL_bool anyEnclosedNoResult; SDL_bool expectedEnclosed = SDL_FALSE; int newx, newy; - int minx, maxx, miny, maxy; + int minx = 0, maxx = 0, miny = 0, maxy = 0; int i; // Setup clipping rectangle @@ -1117,13 +1121,15 @@ int rect_testEnclosePointsWithClipping(void *arg) if ((newx>=refClip.x) && (newx<(refClip.x + refClip.w)) && (newy>=refClip.y) && (newy<(refClip.y + refClip.h))) { if (expectedEnclosed==SDL_FALSE) { - minx=maxx=newx; - miny=maxy=newy; + minx = newx; + maxx = newx; + miny = newy; + maxy = newy; } else { - if (newxmaxx) maxx=newx; - if (newymaxy) maxy=newy; + if (newx < minx) minx = newx; + if (newx > maxx) maxx = newx; + if (newy < miny) miny = newy; + if (newy > maxy) maxy = newy; } expectedEnclosed = SDL_TRUE; } diff --git a/test/testautomation_render.c b/test/testautomation_render.c index 665c3f36e..74db37dca 100644 --- a/test/testautomation_render.c +++ b/test/testautomation_render.c @@ -690,7 +690,6 @@ render_testBlitBlend (void *arg) } - /** * @brief Checks to see if functionality is supported. Helper function. */ @@ -722,6 +721,7 @@ _hasDrawColor (void) ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a ); if (!_isSupported(ret)) fail = 1; + /* Restore natural. */ ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE ); if (!_isSupported(ret)) @@ -730,6 +730,7 @@ _hasDrawColor (void) /* Something failed, consider not available. */ if (fail) return 0; + /* Not set properly, consider failed. */ else if ((r != 100) || (g != 100) || (b != 100) || (a != 100)) return 0; @@ -839,7 +840,7 @@ _hasTexColor (void) /* Get test face. */ tface = _loadTestFace(); - if (tface == 0) + if (tface == NULL) return 0; /* See if supported. */ @@ -879,7 +880,7 @@ _hasTexAlpha(void) /* Get test face. */ tface = _loadTestFace(); - if (tface == 0) + if (tface == NULL) return 0; /* See if supported. */ @@ -901,7 +902,8 @@ _hasTexAlpha(void) 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. @@ -920,7 +922,7 @@ _compare(const char *msg, SDL_Surface *s, int allowable_error) { int ret; SDL_Rect rect; - Uint8 pix[4*80*60]; + Uint8 pix[4*TESTRENDER_SCREEN_W*TESTRENDER_SCREEN_H]; SDL_Surface *testsur; char imageFilename[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... */ rect.x = 0; rect.y = 0; - rect.w = 80; - rect.h = 60; + rect.w = TESTRENDER_SCREEN_W; + rect.h = TESTRENDER_SCREEN_H; 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); @@ -943,17 +945,18 @@ _compare(const char *msg, SDL_Surface *s, int allowable_error) ret = SDLTest_CompareSurfaces( testsur, s, allowable_error ); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); + /* Save source image and reference image for analysis */ _renderCompareCount++; 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_snprintf(referenceFilename, 127, "reference%i.bmp", _renderCompareCount); + SDL_snprintf(referenceFilename, 127, "compare%04d_ReferenceImage.bmp", _renderCompareCount); 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. */ - SDL_FreeSurface( testsur ); + SDL_FreeSurface(testsur); } /** diff --git a/test/testautomation_suites.h b/test/testautomation_suites.h index f2c6f9e10..d2ddac928 100644 --- a/test/testautomation_suites.h +++ b/test/testautomation_suites.h @@ -9,7 +9,7 @@ #include "SDL_test.h" // Test collections -//extern SDLTest_TestSuiteReference audioTestSuite; +extern SDLTest_TestSuiteReference audioTestSuite; extern SDLTest_TestSuiteReference clipboardTestSuite; //extern SDLTest_TestSuiteReference eventsTestSuite; //extern SDLTest_TestSuiteReference keyboardTestSuite; @@ -23,7 +23,7 @@ extern SDLTest_TestSuiteReference rwopsTestSuite; // All test suites SDLTest_TestSuiteReference *testSuites[] = { -// &audioTestSuite, + &audioTestSuite, &clipboardTestSuite, // &eventsTestSuite, // &keyboardTestSuite,