Added audio test suite; minor code cleanups in test lib
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Mon, 24 Dec 2012 14:43:57 -0800
changeset 67725229a117ef97
parent 6771 55337ff4256f
child 6773 5ebc5a9e35b4
Added audio test suite; minor code cleanups in test lib
include/SDL_test_assert.h
include/SDL_test_compare.h
include/SDL_test_log.h
src/test/SDL_test_assert.c
src/test/SDL_test_compare.c
src/test/SDL_test_harness.c
src/test/SDL_test_log.c
test/Makefile.in
test/testautomation.c
test/testautomation_audio.c
test/testautomation_rect.c
test/testautomation_render.c
test/testautomation_suites.h
     1.1 --- a/include/SDL_test_assert.h	Sat Dec 22 20:43:51 2012 -0800
     1.2 +++ b/include/SDL_test_assert.h	Mon Dec 24 14:43:57 2012 -0800
     1.3 @@ -60,7 +60,7 @@
     1.4   * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
     1.5   * \param assertDescription Message to log with the assert describing it.
     1.6   */
     1.7 -void SDLTest_Assert(int assertCondition, char *assertDescription, ...);
     1.8 +void SDLTest_Assert(int assertCondition, const char *assertDescription, ...);
     1.9  
    1.10  /**
    1.11   * \brief Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters.
    1.12 @@ -70,14 +70,14 @@
    1.13   *
    1.14   * \returns Returns the assertCondition so it can be used to externally to break execution flow if desired.
    1.15   */
    1.16 -int SDLTest_AssertCheck(int assertCondition, char *assertDescription, ...);
    1.17 +int SDLTest_AssertCheck(int assertCondition, const char *assertDescription, ...);
    1.18  
    1.19  /**
    1.20   * \brief Explicitely pass without checking an assertion condition. Updates assertion counter.
    1.21   *
    1.22   * \param assertDescription Message to log with the assert describing it.
    1.23   */
    1.24 -void SDLTest_AssertPass(char *assertDescription, ...);
    1.25 +void SDLTest_AssertPass(const char *assertDescription, ...);
    1.26  
    1.27  /**
    1.28   * \brief Resets the assert summary counters to zero.
     2.1 --- a/include/SDL_test_compare.h	Sat Dec 22 20:43:51 2012 -0800
     2.2 +++ b/include/SDL_test_compare.h	Mon Dec 24 14:43:57 2012 -0800
     2.3 @@ -37,6 +37,7 @@
     2.4  #define _SDL_test_compare_h
     2.5  
     2.6  #include "SDL.h"
     2.7 +
     2.8  #include "SDL_test_images.h"
     2.9  
    2.10  #include "begin_code.h"
    2.11 @@ -50,13 +51,13 @@
    2.12  /**
    2.13   * \brief Compares a surface and with reference image data for equality
    2.14   *
    2.15 - * \param sur Surface used in comparison
    2.16 - * \param img Test Surface used in comparison
    2.17 - * \param allowable_error Allowable difference in blending accuracy
    2.18 + * \param surface Surface used in comparison
    2.19 + * \param referenceSurface Test Surface used in comparison
    2.20 + * \param allowable_error Allowable difference (squared) in blending accuracy.
    2.21   *
    2.22 - * \returns 0 if comparison succeeded, >0 (=number of pixels where comparison failed) if comparison failed, <0 for any other error.
    2.23 + * \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.
    2.24   */
    2.25 -int SDLTest_CompareSurfaces(SDL_Surface *sur, SDL_Surface *img, int allowable_error);
    2.26 +int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error);
    2.27        
    2.28  
    2.29  /* Ends C function definitions when using C++ */
     3.1 --- a/include/SDL_test_log.h	Sat Dec 22 20:43:51 2012 -0800
     3.2 +++ b/include/SDL_test_log.h	Mon Dec 24 14:43:57 2012 -0800
     3.3 @@ -49,14 +49,14 @@
     3.4   *
     3.5   * \param fmt Message to be logged
     3.6   */
     3.7 -void SDLTest_Log(char *fmt, ...);
     3.8 +void SDLTest_Log(const char *fmt, ...);
     3.9  
    3.10  /**
    3.11   * \brief Prints given message with a timestamp in the TEST category and the ERROR priority.
    3.12   *
    3.13   * \param fmt Message to be logged
    3.14   */
    3.15 -void SDLTest_LogError(char *fmt, ...);
    3.16 +void SDLTest_LogError(const char *fmt, ...);
    3.17  
    3.18  /* Ends C function definitions when using C++ */
    3.19  #ifdef __cplusplus
     4.1 --- a/src/test/SDL_test_assert.c	Sat Dec 22 20:43:51 2012 -0800
     4.2 +++ b/src/test/SDL_test_assert.c	Mon Dec 24 14:43:57 2012 -0800
     4.3 @@ -44,7 +44,7 @@
     4.4  /*
     4.5   *  Assert that logs and break execution flow on failures (i.e. for harness errors).
     4.6   */
     4.7 -void SDLTest_Assert(int assertCondition, char *assertDescription, ...)
     4.8 +void SDLTest_Assert(int assertCondition, const char *assertDescription, ...)
     4.9  {
    4.10          va_list list;
    4.11  	char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
    4.12 @@ -62,11 +62,10 @@
    4.13  /*
    4.14   * Assert that logs but does not break execution flow on failures (i.e. for test cases).
    4.15   */
    4.16 -int SDLTest_AssertCheck(int assertCondition, char *assertDescription, ...)
    4.17 +int SDLTest_AssertCheck(int assertCondition, const char *assertDescription, ...)
    4.18  {
    4.19      va_list list;
    4.20  	char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
    4.21 -	char *logFormat = (char *)SDLTest_AssertCheckFormat;
    4.22                  
    4.23  	// Print assert description into a buffer
    4.24  	SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
    4.25 @@ -78,12 +77,12 @@
    4.26  	if (assertCondition == ASSERT_FAIL)
    4.27  	{
    4.28  		SDLTest_AssertsFailed++;
    4.29 -		SDLTest_LogError(logFormat, logMessage, "Failed");
    4.30 +		SDLTest_LogError(SDLTest_AssertCheckFormat, logMessage, "Failed");
    4.31  	} 
    4.32  	else 
    4.33  	{
    4.34  		SDLTest_AssertsPassed++;
    4.35 -		SDLTest_Log(logFormat, logMessage, "Passed");
    4.36 +		SDLTest_Log(SDLTest_AssertCheckFormat, logMessage, "Passed");
    4.37  	}
    4.38  
    4.39  	return assertCondition;
    4.40 @@ -92,11 +91,10 @@
    4.41  /*
    4.42   * Explicitly passing Assert that logs (i.e. for test cases).
    4.43   */
    4.44 -void SDLTest_AssertPass(char *assertDescription, ...)
    4.45 +void SDLTest_AssertPass(const char *assertDescription, ...)
    4.46  {
    4.47      va_list list;
    4.48  	char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
    4.49 -	char *logFormat = (char *)SDLTest_AssertCheckFormat;
    4.50                  
    4.51  	// Print assert description into a buffer
    4.52  	SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
    4.53 @@ -104,9 +102,9 @@
    4.54  	SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
    4.55  	va_end(list);
    4.56                              
    4.57 -    // Log pass message                            
    4.58 +        // Log pass message                            
    4.59  	SDLTest_AssertsPassed++;
    4.60 -	SDLTest_Log(logFormat, logMessage, "Pass");
    4.61 +	SDLTest_Log(SDLTest_AssertCheckFormat, logMessage, "Pass");
    4.62  }
    4.63  
    4.64  /*
    4.65 @@ -124,15 +122,14 @@
    4.66   */
    4.67  void SDLTest_LogAssertSummary()
    4.68  {
    4.69 -	char *logFormat = (char *)SDLTest_AssertSummaryFormat;
    4.70  	Uint32 totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed;
    4.71  	if (SDLTest_AssertsFailed == 0)
    4.72  	{
    4.73 -		SDLTest_Log(logFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
    4.74 +		SDLTest_Log(SDLTest_AssertSummaryFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
    4.75  	} 
    4.76  	else 
    4.77  	{
    4.78 -		SDLTest_LogError(logFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
    4.79 +		SDLTest_LogError(SDLTest_AssertSummaryFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
    4.80  	}
    4.81  }
    4.82  
     5.1 --- a/src/test/SDL_test_compare.c	Sat Dec 22 20:43:51 2012 -0800
     5.2 +++ b/src/test/SDL_test_compare.c	Mon Dec 24 14:43:57 2012 -0800
     5.3 @@ -42,29 +42,37 @@
     5.4     Uint8 R, G, B, A;
     5.5     Uint8 Rd, Gd, Bd, Ad;
     5.6  
     5.7 -   /* Make surfacee size is the same. */
     5.8 -   if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h))
     5.9 -   {
    5.10 +   /* Validate input surfaces */
    5.11 +   if (surface == NULL || referenceSurface == NULL) {
    5.12        return -1;
    5.13     }
    5.14  
    5.15 +   /* Make surface size is the same. */
    5.16 +   if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h)) {
    5.17 +      return -2;
    5.18 +   }
    5.19 +
    5.20 +   /* Sanitize input */
    5.21 +   if (allowable_error<0) {
    5.22 +      allowable_error = 0;
    5.23 +   }
    5.24 +   
    5.25     SDL_LockSurface( surface );
    5.26     SDL_LockSurface( referenceSurface );
    5.27  
    5.28     ret = 0;
    5.29     bpp = surface->format->BytesPerPixel;
    5.30     bpp_reference = referenceSurface->format->BytesPerPixel;
    5.31 -
    5.32     /* Compare image - should be same format. */
    5.33     for (j=0; j<surface->h; j++) {
    5.34        for (i=0; i<surface->w; i++) {
    5.35           p  = (Uint8 *)surface->pixels + j * surface->pitch + i * bpp;
    5.36           p_reference = (Uint8 *)referenceSurface->pixels + j * referenceSurface->pitch + i * bpp_reference;
    5.37 -         dist = 0;
    5.38  
    5.39           SDL_GetRGBA(*(Uint32*)p, surface->format, &R, &G, &B, &A);
    5.40           SDL_GetRGBA(*(Uint32*)p_reference, referenceSurface->format, &Rd, &Gd, &Bd, &Ad);
    5.41  
    5.42 +         dist = 0;
    5.43           dist += (R-Rd)*(R-Rd);
    5.44           dist += (G-Gd)*(G-Gd);
    5.45           dist += (B-Bd)*(B-Bd);
     6.1 --- a/src/test/SDL_test_harness.c	Sat Dec 22 20:43:51 2012 -0800
     6.2 +++ b/src/test/SDL_test_harness.c	Mon Dec 24 14:43:57 2012 -0800
     6.3 @@ -51,7 +51,7 @@
     6.4  * \returns The generated seed string
     6.5  */
     6.6  char *
     6.7 -	SDLTest_GenerateRunSeed(const int length)
     6.8 +SDLTest_GenerateRunSeed(const int length)
     6.9  {
    6.10  	char *seed = NULL;
    6.11  	SDLTest_RandomContext randomContext;
    6.12 @@ -97,7 +97,7 @@
    6.13  *
    6.14  */
    6.15  Uint64
    6.16 -	SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iteration)
    6.17 +SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iteration)
    6.18  {
    6.19  	SDLTest_Md5Context md5Context;
    6.20  	Uint64 *keys;
    6.21 @@ -109,17 +109,17 @@
    6.22  	Uint32 entireStringLength;
    6.23  	char *buffer;
    6.24  
    6.25 -	if (runSeed == NULL || strlen(runSeed)==0) {
    6.26 +	if (runSeed == NULL || SDL_strlen(runSeed)==0) {
    6.27  		SDLTest_LogError("Invalid runSeed string.");
    6.28  		return -1;
    6.29  	}
    6.30  
    6.31 -	if (suiteName == NULL || strlen(suiteName)==0) {
    6.32 +	if (suiteName == NULL || SDL_strlen(suiteName)==0) {
    6.33  		SDLTest_LogError("Invalid suiteName string.");
    6.34  		return -1;
    6.35  	}
    6.36  
    6.37 -	if (testName == NULL || strlen(testName)==0) {
    6.38 +	if (testName == NULL || SDL_strlen(testName)==0) {
    6.39  		SDLTest_LogError("Invalid testName string.");
    6.40  		return -1;
    6.41  	}
    6.42 @@ -130,14 +130,14 @@
    6.43  	}
    6.44  
    6.45  	// Convert iteration number into a string
    6.46 -	memset(iterationString, 0, sizeof(iterationString));
    6.47 +	SDL_memset(iterationString, 0, sizeof(iterationString));
    6.48  	SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iteration);
    6.49  
    6.50  	// Combine the parameters into single string
    6.51 -	runSeedLength = strlen(runSeed);
    6.52 -	suiteNameLength = strlen(suiteName);
    6.53 -	testNameLength = strlen(testName);
    6.54 -	iterationStringLength = strlen(iterationString);
    6.55 +	runSeedLength = SDL_strlen(runSeed);
    6.56 +	suiteNameLength = SDL_strlen(suiteName);
    6.57 +	testNameLength = SDL_strlen(testName);
    6.58 +	iterationStringLength = SDL_strlen(iterationString);
    6.59  	entireStringLength  = runSeedLength + suiteNameLength + testNameLength + iterationStringLength + 1;
    6.60  	buffer = (char *)SDL_malloc(entireStringLength);
    6.61  	if (buffer == NULL) {
    6.62 @@ -167,7 +167,7 @@
    6.63  * \return Timer id or -1 on failure.
    6.64  */
    6.65  SDL_TimerID
    6.66 -	SDLTest_SetTestTimeout(int timeout, void (*callback)())
    6.67 +SDLTest_SetTestTimeout(int timeout, void (*callback)())
    6.68  {
    6.69  	Uint32 timeoutInMilliseconds;
    6.70  	SDL_TimerID timerID;
    6.71 @@ -371,7 +371,7 @@
    6.72  	}
    6.73  
    6.74  	// Generate run see if we don't have one already
    6.75 -	if (userRunSeed == NULL || strlen(userRunSeed) == 0) {
    6.76 +	if (userRunSeed == NULL || SDL_strlen(userRunSeed) == 0) {
    6.77  		runSeed = SDLTest_GenerateRunSeed(16);
    6.78  		if (runSeed == NULL) {
    6.79  			SDLTest_LogError("Generating a random seed failed");
    6.80 @@ -488,7 +488,7 @@
    6.81  						suiteCounter,
    6.82  						testCounter, 
    6.83  						currentTestName);
    6.84 -					if (testCase->description != NULL && strlen(testCase->description)>0) {
    6.85 +					if (testCase->description != NULL && SDL_strlen(testCase->description)>0) {
    6.86  						SDLTest_Log("Test Description: '%s'", 
    6.87  							(testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
    6.88  					}
     7.1 --- a/src/test/SDL_test_log.c	Sat Dec 22 20:43:51 2012 -0800
     7.2 +++ b/src/test/SDL_test_log.c	Mon Dec 24 14:43:57 2012 -0800
     7.3 @@ -31,10 +31,12 @@
     7.4  #include "SDL_config.h"
     7.5  
     7.6  #include <stdarg.h> /* va_list */
     7.7 -#include <stdio.h>
     7.8 +#include <stdio.h>
     7.9  #include <string.h>
    7.10  #include <time.h>
    7.11  
    7.12 +#include "SDL.h"
    7.13 +
    7.14  #include "SDL_test.h"
    7.15  
    7.16  /*!
    7.17 @@ -54,7 +56,7 @@
    7.18  	static char buffer[64];
    7.19  	struct tm *local;
    7.20  
    7.21 -	memset(buffer, 0, sizeof(buffer));\
    7.22 +	SDL_memset(buffer, 0, sizeof(buffer));\
    7.23  	copy = timestamp;
    7.24  	local = localtime(&copy);
    7.25  	strftime(buffer, sizeof(buffer), "%x %X", local);
    7.26 @@ -65,13 +67,13 @@
    7.27  /*
    7.28   * Prints given message with a timestamp in the TEST category and INFO priority.
    7.29   */
    7.30 -void SDLTest_Log(char *fmt, ...)
    7.31 +void SDLTest_Log(const char *fmt, ...)
    7.32  {
    7.33  	va_list list;
    7.34  	char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
    7.35  
    7.36  	// Print log message into a buffer
    7.37 -	memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
    7.38 +	SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
    7.39  	va_start(list, fmt);
    7.40  	SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
    7.41  	va_end(list);
    7.42 @@ -83,13 +85,13 @@
    7.43  /*
    7.44   * Prints given message with a timestamp in the TEST category and the ERROR priority.
    7.45   */
    7.46 -void SDLTest_LogError(char *fmt, ...)
    7.47 +void SDLTest_LogError(const char *fmt, ...)
    7.48  {
    7.49  	va_list list;
    7.50  	char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
    7.51  
    7.52  	// Print log message into a buffer
    7.53 -	memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
    7.54 +	SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
    7.55  	va_start(list, fmt);
    7.56  	SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
    7.57  	va_end(list);
     8.1 --- a/test/Makefile.in	Sat Dec 22 20:43:51 2012 -0800
     8.2 +++ b/test/Makefile.in	Mon Dec 24 14:43:57 2012 -0800
     8.3 @@ -73,7 +73,8 @@
     8.4  		      $(srcdir)/testautomation_platform.c \
     8.5  		      $(srcdir)/testautomation_rect.c \
     8.6  		      $(srcdir)/testautomation_render.c \
     8.7 -		      $(srcdir)/testautomation_rwops.c
     8.8 +		      $(srcdir)/testautomation_rwops.c \
     8.9 +		      $(srcdir)/testautomation_audio.c
    8.10  	$(CC) -o $@ $^ $(CFLAGS) -lSDL2_test $(LIBS) 
    8.11  
    8.12  testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c
     9.1 --- a/test/testautomation.c	Sat Dec 22 20:43:51 2012 -0800
     9.2 +++ b/test/testautomation.c	Mon Dec 24 14:43:57 2012 -0800
     9.3 @@ -101,7 +101,7 @@
     9.4      }
     9.5  
     9.6      /* Call Harness */
     9.7 -    result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, filter, testIterations);
     9.8 +    result = SDLTest_RunSuites(testSuites, (const char *)userRunSeed, userExecKey, (const char *)filter, testIterations);
     9.9  
    9.10      /* Clean up */
    9.11      if (userRunSeed != NULL) {
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/testautomation_audio.c	Mon Dec 24 14:43:57 2012 -0800
    10.3 @@ -0,0 +1,209 @@
    10.4 +/**
    10.5 + * Original code: automated SDL audio test written by Edgar Simo "bobbens"
    10.6 + * New/updated tests: aschiffler at ferzkopp dot net
    10.7 + */
    10.8 +
    10.9 +#include <stdio.h>
   10.10 +
   10.11 +#include "SDL.h"
   10.12 +#include "SDL_test.h"
   10.13 +
   10.14 +/* ================= Test Case Implementation ================== */
   10.15 +
   10.16 +/* Fixture */
   10.17 +
   10.18 +void
   10.19 +_audioSetUp(void *arg)
   10.20 +{
   10.21 +	/* Start SDL audio subsystem */
   10.22 +	int ret = SDL_InitSubSystem( SDL_INIT_AUDIO );
   10.23 +        SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)");
   10.24 +	SDLTest_AssertCheck(ret==0, "Check result from SDL_InitSubSystem(SDL_INIT_AUDIO)");
   10.25 +	if (ret != 0) {
   10.26 +           SDLTest_LogError("%s", SDL_GetError());
   10.27 +        }
   10.28 +}
   10.29 +
   10.30 +
   10.31 +/* Test case functions */
   10.32 +
   10.33 +/**
   10.34 + * \brief Enumerate and name available audio devices (output and capture).
   10.35 + * 
   10.36 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
   10.37 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
   10.38 + */
   10.39 +int audio_enumerateAndNameAudioDevices()
   10.40 +{
   10.41 +   int t, tt;
   10.42 +   int i, n, nn;
   10.43 +   const char *name, *nameAgain;
   10.44 +
   10.45 +   /* Iterate over types: t=0 output device, t=1 input/capture device */
   10.46 +   for (t=0; t<2; t++) {
   10.47 +   
   10.48 +      /* Get number of devices. */
   10.49 +      n = SDL_GetNumAudioDevices(t);
   10.50 +      SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(%i)", t);
   10.51 +      SDLTest_Log("Number of %s devices < 0, reported as %i", (t) ? "output" : "capture", n);
   10.52 +      SDLTest_AssertCheck(n >= 0, "Validate result is >= 0, got: %i", n);
   10.53 +
   10.54 +      /* Variation of non-zero type */
   10.55 +      if (t==1) {
   10.56 +         tt = t + SDLTest_RandomIntegerInRange(1,10);
   10.57 +         nn = SDL_GetNumAudioDevices(tt);
   10.58 +         SDLTest_AssertCheck(n==nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", tt, n, nn);
   10.59 +         nn = SDL_GetNumAudioDevices(-tt);
   10.60 +         SDLTest_AssertCheck(n==nn, "Verify result from SDL_GetNumAudioDevices(%i), expected same number of audio devices %i, got %i", -tt, n, nn);
   10.61 +      } 
   10.62 +   
   10.63 +      /* List devices. */
   10.64 +      if (n>0) {
   10.65 +         for (i=0; i<n; i++) {
   10.66 +            name = SDL_GetAudioDeviceName(i, t);
   10.67 +            SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
   10.68 +            SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, t);
   10.69 +            if (name != NULL) {
   10.70 +              SDLTest_AssertCheck(SDL_strlen(name)>0, "verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, t, name);
   10.71 +              if (t==1) {
   10.72 +                  /* Also try non-zero type */
   10.73 +                  tt = t + SDLTest_RandomIntegerInRange(1,10);
   10.74 +                  nameAgain = SDL_GetAudioDeviceName(i, tt);
   10.75 +                  SDLTest_AssertCheck(nameAgain != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, tt);
   10.76 +                  if (nameAgain != NULL) {
   10.77 +                    SDLTest_AssertCheck(SDL_strlen(nameAgain)>0, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, tt, nameAgain);
   10.78 +                    SDLTest_AssertCheck(SDL_strcmp(name, nameAgain)==0, 
   10.79 +                      "Verify SDL_GetAudioDeviceName(%i, %i) and SDL_GetAudioDeviceName(%i %i) return the same string", 
   10.80 +                      i, t, i, tt);
   10.81 +                  }
   10.82 +               }
   10.83 +            }
   10.84 +         }
   10.85 +      }
   10.86 +   }
   10.87 +   
   10.88 +   return TEST_COMPLETED;
   10.89 +}
   10.90 +
   10.91 +/**
   10.92 + * \brief Negative tests around enumeration and naming of audio devices.
   10.93 + * 
   10.94 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetNumAudioDevices
   10.95 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_GetAudioDeviceName
   10.96 + */
   10.97 +int audio_enumerateAndNameAudioDevicesNegativeTests()
   10.98 +{
   10.99 +   int t;
  10.100 +   int i, j, no, nc;
  10.101 +   const char *name;
  10.102 +      
  10.103 +   /* Get number of devices. */
  10.104 +   no = SDL_GetNumAudioDevices(0);
  10.105 +   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(0)");
  10.106 +   nc = SDL_GetNumAudioDevices(1);
  10.107 +   SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(1)");
  10.108 +   
  10.109 +   /* Invalid device index when getting name */
  10.110 +   for (t=0; t<2; t++) {
  10.111 +      /* Negative device index */
  10.112 +      i = SDLTest_RandomIntegerInRange(-10,-1);
  10.113 +      name = SDL_GetAudioDeviceName(i, t);
  10.114 +      SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
  10.115 +      SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result NULL, expected NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
  10.116 +      
  10.117 +      /* Device index past range */
  10.118 +      for (j=0; j<3; j++) {
  10.119 +         i = (t) ? nc+j : no+j;
  10.120 +         name = SDL_GetAudioDeviceName(i, t);
  10.121 +         SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
  10.122 +         SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
  10.123 +      }
  10.124 +      
  10.125 +      /* Capture index past capture range but within output range */
  10.126 +      if ((no>0) && (no>nc) && (t==1)) {
  10.127 +         i = no-1;
  10.128 +         name = SDL_GetAudioDeviceName(i, t);
  10.129 +         SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
  10.130 +         SDLTest_AssertCheck(name == NULL, "Check SDL_GetAudioDeviceName(%i, %i) result, expected: NULL, got: %s", i, t, (name == NULL) ? "NULL" : name);
  10.131 +      }
  10.132 +   }
  10.133 +
  10.134 +   return TEST_COMPLETED;
  10.135 +}
  10.136 +
  10.137 +
  10.138 +/**
  10.139 + * @brief Checks available audio driver names.
  10.140 + */
  10.141 +int audio_printAudioDrivers()
  10.142 +{
  10.143 +   int i, n;
  10.144 +   const char *name;
  10.145 +
  10.146 +   /* Get number of drivers */
  10.147 +   n = SDL_GetNumAudioDrivers();
  10.148 +   SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
  10.149 +   SDLTest_AssertCheck(n>=0, "Verify number of audio drivers >= 0, got: %i", n);
  10.150 +   
  10.151 +   /* List drivers. */
  10.152 +   if (n>0)
  10.153 +   {
  10.154 +      for (i=0; i<n; i++) {
  10.155 +         name = SDL_GetAudioDriver(i);
  10.156 +         SDLTest_AssertPass("Call to SDL_GetAudioDriver(%i)", i);
  10.157 +         SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
  10.158 +         if (name != NULL) {
  10.159 +            SDLTest_AssertCheck(SDL_strlen(name)>0, "Verify returned name is not empty, got: '%s'", name);
  10.160 +         }
  10.161 +      }
  10.162 +   }
  10.163 +
  10.164 +   return TEST_COMPLETED;
  10.165 +}
  10.166 +
  10.167 +
  10.168 +/**
  10.169 + * @brief Checks current audio driver name with initialized audio.
  10.170 + */
  10.171 +int audio_printCurrentAudioDriver()
  10.172 +{
  10.173 +   const char *name;
  10.174 +
  10.175 +   /* Check current audio driver */
  10.176 +   name = SDL_GetCurrentAudioDriver();
  10.177 +   SDLTest_AssertPass("Call to SDL_GetCurrentAudioDriver()");
  10.178 +   SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
  10.179 +   if (name != NULL) {
  10.180 +      SDLTest_AssertCheck(SDL_strlen(name)>0, "Verify returned name is not empty, got: '%s'", name);
  10.181 +   }
  10.182 +
  10.183 +   return TEST_COMPLETED;
  10.184 +}
  10.185 +
  10.186 +/* ================= Test Case References ================== */
  10.187 +
  10.188 +/* Audio test cases */
  10.189 +static const SDLTest_TestCaseReference audioTest1 =
  10.190 +		{ (SDLTest_TestCaseFp)audio_enumerateAndNameAudioDevices, "audio_enumerateAndNameAudioDevices", "Enumerate and name available audio devices (output and capture)", TEST_ENABLED };
  10.191 +
  10.192 +static const SDLTest_TestCaseReference audioTest2 =
  10.193 +		{ (SDLTest_TestCaseFp)audio_enumerateAndNameAudioDevicesNegativeTests, "audio_enumerateAndNameAudioDevicesNegativeTests", "Negative tests around enumeration and naming of audio devices.", TEST_ENABLED };
  10.194 +
  10.195 +static const SDLTest_TestCaseReference audioTest3 =
  10.196 +		{ (SDLTest_TestCaseFp)audio_printAudioDrivers, "audio_printAudioDrivers", "Checks available audio driver names.", TEST_ENABLED };
  10.197 +
  10.198 +static const SDLTest_TestCaseReference audioTest4 =
  10.199 +		{ (SDLTest_TestCaseFp)audio_printCurrentAudioDriver, "audio_printCurrentAudioDriver", "Checks current audio driver name with initialized audio.", TEST_ENABLED };
  10.200 +
  10.201 +/* Sequence of Audio test cases */
  10.202 +static const SDLTest_TestCaseReference *audioTests[] =  {
  10.203 +	&audioTest1, &audioTest2, &audioTest3, &audioTest4, NULL
  10.204 +};
  10.205 +
  10.206 +/* Audio test suite (global) */
  10.207 +SDLTest_TestSuiteReference audioTestSuite = {
  10.208 +	"Audio",
  10.209 +	_audioSetUp,
  10.210 +	audioTests,
  10.211 +	NULL
  10.212 +};
    11.1 --- a/test/testautomation_rect.c	Sat Dec 22 20:43:51 2012 -0800
    11.2 +++ b/test/testautomation_rect.c	Mon Dec 24 14:43:57 2012 -0800
    11.3 @@ -951,12 +951,12 @@
    11.4      SDL_Rect result;
    11.5      SDL_bool anyEnclosed;
    11.6      SDL_bool anyEnclosedNoResult;
    11.7 +    SDL_bool expectedEnclosed = SDL_TRUE;
    11.8 +    int newx, newy;
    11.9 +    int minx = 0, maxx = 0, miny = 0, maxy = 0;
   11.10 +    int i;
   11.11  
   11.12      // Create input data, tracking result
   11.13 -    SDL_bool expectedEnclosed = SDL_TRUE;
   11.14 -    int newx, newy;
   11.15 -    int minx, maxx, miny, maxy;
   11.16 -    int i;
   11.17      for (i=0; i<numPoints; i++) {
   11.18          newx = SDLTest_RandomIntegerInRange(-1024, 1024);
   11.19          newy = SDLTest_RandomIntegerInRange(-1024, 1024);
   11.20 @@ -965,13 +965,15 @@
   11.21          points[i].x = newx;
   11.22          points[i].y = newy;
   11.23          if (i==0) {
   11.24 -            minx=maxx=newx;
   11.25 -            miny=maxy=newy;
   11.26 +            minx = newx;
   11.27 +            maxx = newx;
   11.28 +            miny = newy;
   11.29 +            maxy = newy;
   11.30          } else {
   11.31 -            if (newx<minx) minx=newx;
   11.32 -            if (newx>maxx) maxx=newx;
   11.33 -            if (newy<miny) miny=newy;
   11.34 -            if (newy>maxy) maxy=newy;
   11.35 +            if (newx < minx) minx = newx;
   11.36 +            if (newx > maxx) maxx = newx;
   11.37 +            if (newy < miny) miny = newy;
   11.38 +            if (newy > maxy) maxy = newy;
   11.39          }
   11.40      }
   11.41      
   11.42 @@ -1020,12 +1022,12 @@
   11.43      SDL_Rect result;
   11.44      SDL_bool anyEnclosed;
   11.45      SDL_bool anyEnclosedNoResult;
   11.46 +    SDL_bool expectedEnclosed = SDL_TRUE;
   11.47 +    int newx, newy;
   11.48 +    int minx = 0, maxx = 0, miny = 0, maxy = 0;
   11.49 +    int i;
   11.50  
   11.51      // Create input data, tracking result
   11.52 -    SDL_bool expectedEnclosed = SDL_TRUE;
   11.53 -    int newx, newy;
   11.54 -    int minx, maxx, miny, maxy;
   11.55 -    int i;
   11.56      for (i=0; i<numPoints; i++) {
   11.57          if (i < halfPoints) {
   11.58              newx = SDLTest_RandomIntegerInRange(-1024, 1024);
   11.59 @@ -1039,13 +1041,15 @@
   11.60          points[i].x = newx;
   11.61          points[i].y = newy;
   11.62          if (i==0) {
   11.63 -            minx=maxx=newx;
   11.64 -            miny=maxy=newy;
   11.65 +            minx = newx;
   11.66 +            maxx = newx;
   11.67 +            miny = newy;
   11.68 +            maxy = newy;
   11.69          } else {
   11.70 -            if (newx<minx) minx=newx;
   11.71 -            if (newx>maxx) maxx=newx;
   11.72 -            if (newy<miny) miny=newy;
   11.73 -            if (newy>maxy) maxy=newy;
   11.74 +            if (newx < minx) minx = newx;
   11.75 +            if (newx > maxx) maxx = newx;
   11.76 +            if (newy < miny) miny = newy;
   11.77 +            if (newy > maxy) maxy = newy;
   11.78          }
   11.79      }
   11.80  
   11.81 @@ -1097,7 +1101,7 @@
   11.82      SDL_bool anyEnclosedNoResult;
   11.83      SDL_bool expectedEnclosed = SDL_FALSE;
   11.84      int newx, newy;
   11.85 -    int minx, maxx, miny, maxy;
   11.86 +    int minx = 0, maxx = 0, miny = 0, maxy = 0;
   11.87      int i;
   11.88  
   11.89      // Setup clipping rectangle
   11.90 @@ -1117,13 +1121,15 @@
   11.91          if ((newx>=refClip.x) && (newx<(refClip.x + refClip.w)) &&
   11.92              (newy>=refClip.y) && (newy<(refClip.y + refClip.h))) {
   11.93              if (expectedEnclosed==SDL_FALSE) {
   11.94 -                minx=maxx=newx;
   11.95 -                miny=maxy=newy;
   11.96 +                minx = newx;
   11.97 +                maxx = newx;
   11.98 +                miny = newy;
   11.99 +                maxy = newy;
  11.100              } else {
  11.101 -                if (newx<minx) minx=newx;
  11.102 -                if (newx>maxx) maxx=newx;
  11.103 -                if (newy<miny) miny=newy;
  11.104 -                if (newy>maxy) maxy=newy;
  11.105 +                if (newx < minx) minx = newx;
  11.106 +                if (newx > maxx) maxx = newx;
  11.107 +                if (newy < miny) miny = newy;
  11.108 +                if (newy > maxy) maxy = newy;
  11.109              }
  11.110              expectedEnclosed = SDL_TRUE;
  11.111          }
    12.1 --- a/test/testautomation_render.c	Sat Dec 22 20:43:51 2012 -0800
    12.2 +++ b/test/testautomation_render.c	Mon Dec 24 14:43:57 2012 -0800
    12.3 @@ -690,7 +690,6 @@
    12.4  }
    12.5  
    12.6  
    12.7 -
    12.8  /**
    12.9   * @brief Checks to see if functionality is supported. Helper function.
   12.10   */
   12.11 @@ -722,6 +721,7 @@
   12.12     ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a );
   12.13     if (!_isSupported(ret))
   12.14        fail = 1;
   12.15 +      
   12.16     /* Restore natural. */
   12.17     ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE );
   12.18     if (!_isSupported(ret))
   12.19 @@ -730,6 +730,7 @@
   12.20     /* Something failed, consider not available. */
   12.21     if (fail)
   12.22        return 0;
   12.23 +      
   12.24     /* Not set properly, consider failed. */
   12.25     else if ((r != 100) || (g != 100) || (b != 100) || (a != 100))
   12.26        return 0;
   12.27 @@ -839,7 +840,7 @@
   12.28  
   12.29     /* Get test face. */
   12.30     tface = _loadTestFace();
   12.31 -   if (tface == 0)
   12.32 +   if (tface == NULL)
   12.33        return 0;
   12.34  
   12.35     /* See if supported. */
   12.36 @@ -879,7 +880,7 @@
   12.37  
   12.38     /* Get test face. */
   12.39     tface = _loadTestFace();
   12.40 -   if (tface == 0)
   12.41 +   if (tface == NULL)
   12.42        return 0;
   12.43  
   12.44     /* See if supported. */
   12.45 @@ -901,7 +902,8 @@
   12.46     return 1;
   12.47  }
   12.48  
   12.49 -static _renderCompareCount = 0;
   12.50 +/* Counter for _compare calls use for filename creation when comparisons fail */
   12.51 +static int _renderCompareCount = 0;
   12.52  
   12.53  /**
   12.54   * @brief Compares screen pixels with image pixels. Helper function.
   12.55 @@ -920,7 +922,7 @@
   12.56  {
   12.57     int ret;
   12.58     SDL_Rect rect;
   12.59 -   Uint8 pix[4*80*60];
   12.60 +   Uint8 pix[4*TESTRENDER_SCREEN_W*TESTRENDER_SCREEN_H];
   12.61     SDL_Surface *testsur;
   12.62     char imageFilename[128];
   12.63     char referenceFilename[128];
   12.64 @@ -929,8 +931,8 @@
   12.65     /* Explicitly specify the rect in case the window isn't expected size... */
   12.66     rect.x = 0;
   12.67     rect.y = 0;
   12.68 -   rect.w = 80;
   12.69 -   rect.h = 60;
   12.70 +   rect.w = TESTRENDER_SCREEN_W;
   12.71 +   rect.h = TESTRENDER_SCREEN_H;
   12.72     ret = SDL_RenderReadPixels(renderer, &rect, RENDER_COMPARE_FORMAT, pix, 80*4 );
   12.73     SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderReadPixels, expected: 0, got: %i", ret);
   12.74  
   12.75 @@ -943,17 +945,18 @@
   12.76     ret = SDLTest_CompareSurfaces( testsur, s, allowable_error );
   12.77     SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
   12.78  
   12.79 +   /* Save source image and reference image for analysis */
   12.80     _renderCompareCount++;
   12.81     if (ret != 0) {
   12.82 -      SDL_snprintf(imageFilename, 127, "image%i.bmp", _renderCompareCount);
   12.83 +      SDL_snprintf(imageFilename, 127, "compare%04d_SourceImage.bmp", _renderCompareCount);
   12.84        SDL_SaveBMP(testsur, imageFilename);
   12.85 -      SDL_snprintf(referenceFilename, 127, "reference%i.bmp", _renderCompareCount);
   12.86 +      SDL_snprintf(referenceFilename, 127, "compare%04d_ReferenceImage.bmp", _renderCompareCount);
   12.87        SDL_SaveBMP(s, referenceFilename);
   12.88 -      SDLTest_LogError("Surfaces from failed comparison saved as %s and %s", imageFilename, referenceFilename);
   12.89 +      SDLTest_LogError("Surfaces from failed comparison saved as '%s' and '%s'", imageFilename, referenceFilename);
   12.90     }
   12.91  
   12.92     /* Clean up. */
   12.93 -   SDL_FreeSurface( testsur );
   12.94 +   SDL_FreeSurface(testsur);
   12.95  }
   12.96  
   12.97  /**
    13.1 --- a/test/testautomation_suites.h	Sat Dec 22 20:43:51 2012 -0800
    13.2 +++ b/test/testautomation_suites.h	Mon Dec 24 14:43:57 2012 -0800
    13.3 @@ -9,7 +9,7 @@
    13.4  #include "SDL_test.h"
    13.5  
    13.6  // Test collections
    13.7 -//extern SDLTest_TestSuiteReference audioTestSuite;
    13.8 +extern SDLTest_TestSuiteReference audioTestSuite;
    13.9  extern SDLTest_TestSuiteReference clipboardTestSuite;
   13.10  //extern SDLTest_TestSuiteReference eventsTestSuite;
   13.11  //extern SDLTest_TestSuiteReference keyboardTestSuite;
   13.12 @@ -23,7 +23,7 @@
   13.13  
   13.14  // All test suites
   13.15  SDLTest_TestSuiteReference *testSuites[] =  {
   13.16 -//	&audioTestSuite,
   13.17 +	&audioTestSuite,
   13.18  	&clipboardTestSuite,
   13.19  //	&eventsTestSuite,
   13.20  //	&keyboardTestSuite,