Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Fri, 14 Dec 2012 23:05:34 -0800
changeset 6756398073b195bb
parent 6755 af77e1a6faf0
child 6757 9935f71c8c81
Refactor/fix test lib harness, assert and log component; add harness driver; port platform suite from GSOC code
include/SDL_test.h
include/SDL_test_assert.h
include/SDL_test_harness.h
src/test/SDL_test_assert.c
src/test/SDL_test_fuzzer.c
src/test/SDL_test_harness.c
src/test/SDL_test_log.c
test/testautomation.c
test/tests/testplatform.c
test/tests/testsuites.h
     1.1 --- a/include/SDL_test.h	Sat Dec 15 00:30:17 2012 +0000
     1.2 +++ b/include/SDL_test.h	Fri Dec 14 23:05:34 2012 -0800
     1.3 @@ -49,9 +49,13 @@
     1.4  /* *INDENT-ON* */
     1.5  #endif
     1.6  
     1.7 -/* Function prototypes */
     1.8 +/* Global definitions */
     1.9  
    1.10 -/* ADD STUFF HERE */
    1.11 +/* 
    1.12 + * Note: Maximum size of SDLTest log message is less than SDLs limit 
    1.13 + * to ensure we can fit additional information such as the timestamp. 
    1.14 + */
    1.15 +#define SDLTEST_MAX_LOGMESSAGE_LENGTH	3584
    1.16  
    1.17  /* Ends C function definitions when using C++ */
    1.18  #ifdef __cplusplus
     2.1 --- a/include/SDL_test_assert.h	Sat Dec 15 00:30:17 2012 +0000
     2.2 +++ b/include/SDL_test_assert.h	Fri Dec 14 23:05:34 2012 -0800
     2.3 @@ -60,17 +60,24 @@
     2.4   * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
     2.5   * \param assertDescription Message to log with the assert describing it.
     2.6   */
     2.7 -void SDLTest_Assert(int assertCondition, char *assertDescription);
     2.8 +void SDLTest_Assert(int assertCondition, char *assertDescription, ...);
     2.9  
    2.10  /**
    2.11 - * \brief Assert for test cases that logs but does not break execution flow on failures.
    2.12 + * \brief Assert for test cases that logs but does not break execution flow on failures. Updates assertion counters.
    2.13   *
    2.14   * \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0).
    2.15   * \param assertDescription Message to log with the assert describing it.
    2.16   *
    2.17 - * \returns Returns the assertCondition so it can be used to externall to break execution flow if desired.
    2.18 + * \returns Returns the assertCondition so it can be used to externally to break execution flow if desired.
    2.19   */
    2.20 -int SDLTest_AssertCheck(int assertCondition, char *assertDescription);
    2.21 +int SDLTest_AssertCheck(int assertCondition, char *assertDescription, ...);
    2.22 +
    2.23 +/**
    2.24 + * \brief Explicitely pass without checking an assertion condition. Updates assertion counter.
    2.25 + *
    2.26 + * \param assertDescription Message to log with the assert describing it.
    2.27 + */
    2.28 +void SDLTest_AssertPass(char *assertDescription, ...);
    2.29  
    2.30  /**
    2.31   * \brief Resets the assert summary counters to zero.
     3.1 --- a/include/SDL_test_harness.h	Sat Dec 15 00:30:17 2012 +0000
     3.2 +++ b/include/SDL_test_harness.h	Fri Dec 14 23:05:34 2012 -0800
     3.3 @@ -98,6 +98,20 @@
     3.4  	SDLTest_TestCaseTearDownFp testTearDown;
     3.5  } SDLTest_TestSuiteReference;
     3.6  
     3.7 +
     3.8 +/**
     3.9 + * \brief Execute a test suite using the given run seed and execution key.
    3.10 + *
    3.11 + * \param testSuites Suites containing the test case.
    3.12 + * \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one.
    3.13 + * \param userExecKey Custom execution key provided by user, or 0 to autogenerate one.
    3.14 + * \param testIterations Number of iterations to run each test case.
    3.15 + *
    3.16 + * \returns Test run result; 0 when all tests passed, 1 if any tests failed.
    3.17 + */
    3.18 +int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, Uint64 userExecKey, int testIterations);
    3.19 +         
    3.20 +
    3.21  /* Ends C function definitions when using C++ */
    3.22  #ifdef __cplusplus
    3.23  /* *INDENT-OFF* */
     4.1 --- a/src/test/SDL_test_assert.c	Sat Dec 15 00:30:17 2012 +0000
     4.2 +++ b/src/test/SDL_test_assert.c	Fri Dec 14 23:05:34 2012 -0800
     4.3 @@ -30,10 +30,10 @@
     4.4  #include "SDL_test.h"
     4.5  
     4.6  /* Assert check message format */
     4.7 -const char *SDLTest_AssertCheckFmt = "Assert '%s': %s";
     4.8 +const char *SDLTest_AssertCheckFormat = "Assert '%s': %s";
     4.9  
    4.10  /* Assert summary message format */
    4.11 -const char *SDLTest_AssertSummaryFmt = "Assert Summary: Total=%d Passed=%d Failed=%d";
    4.12 +const char *SDLTest_AssertSummaryFormat = "Assert Summary: Total=%d Passed=%d Failed=%d";
    4.13  
    4.14  /*! \brief counts the failed asserts */
    4.15  static Uint32 SDLTest_AssertsFailed = 0;
    4.16 @@ -44,32 +44,72 @@
    4.17  /*
    4.18   *  Assert that logs and break execution flow on failures (i.e. for harness errors).
    4.19   */
    4.20 -void SDLTest_Assert(int assertCondition, char *assertDescription)
    4.21 +void SDLTest_Assert(int assertCondition, char *assertDescription, ...)
    4.22  {
    4.23 -	SDL_assert((SDLTest_AssertCheck(assertCondition, assertDescription)));
    4.24 +        va_list list;
    4.25 +	char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
    4.26 +                
    4.27 +	// Print assert description into a buffer
    4.28 +	memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
    4.29 +	va_start(list, assertDescription);
    4.30 +	SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
    4.31 +	va_end(list);
    4.32 +	
    4.33 +	// Log, then assert and break on failure
    4.34 +	SDL_assert((SDLTest_AssertCheck(assertCondition, logMessage)));
    4.35  }
    4.36  
    4.37  /*
    4.38   * Assert that logs but does not break execution flow on failures (i.e. for test cases).
    4.39   */
    4.40 -int SDLTest_AssertCheck(int assertCondition, char *assertDescription)
    4.41 +int SDLTest_AssertCheck(int assertCondition, char *assertDescription, ...)
    4.42  {
    4.43 -	char *fmt = (char *)SDLTest_AssertCheckFmt;
    4.44 +    va_list list;
    4.45 +	char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
    4.46 +	char *logFormat = (char *)SDLTest_AssertCheckFormat;
    4.47 +                
    4.48 +	// Print assert description into a buffer
    4.49 +	memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
    4.50 +	va_start(list, assertDescription);
    4.51 +	SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
    4.52 +	va_end(list);
    4.53 +                                                        
    4.54 +	// Log pass or fail message
    4.55  	if (assertCondition == ASSERT_FAIL)
    4.56  	{
    4.57  		SDLTest_AssertsFailed++;
    4.58 -		SDLTest_LogError(fmt, assertDescription, "Failed");
    4.59 +		SDLTest_LogError(logFormat, logMessage, "Failed");
    4.60  	} 
    4.61  	else 
    4.62  	{
    4.63  		SDLTest_AssertsPassed++;
    4.64 -		SDLTest_Log(fmt, assertDescription, "Passed");
    4.65 +		SDLTest_Log(logFormat, logMessage, "Passed");
    4.66  	}
    4.67  
    4.68  	return assertCondition;
    4.69  }
    4.70  
    4.71  /*
    4.72 + * Explicitly passing Assert that logs (i.e. for test cases).
    4.73 + */
    4.74 +void SDLTest_AssertPass(char *assertDescription, ...)
    4.75 +{
    4.76 +    va_list list;
    4.77 +	char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
    4.78 +	char *logFormat = (char *)SDLTest_AssertCheckFormat;
    4.79 +                
    4.80 +	// Print assert description into a buffer
    4.81 +	memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
    4.82 +	va_start(list, assertDescription);
    4.83 +	SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
    4.84 +	va_end(list);
    4.85 +                            
    4.86 +    // Log pass message                            
    4.87 +	SDLTest_AssertsPassed++;
    4.88 +	SDLTest_Log(logFormat, logMessage, "Pass");
    4.89 +}
    4.90 +
    4.91 +/*
    4.92   * Resets the assert summary counters to zero.
    4.93   */
    4.94  void SDLTest_ResetAssertSummary()
    4.95 @@ -84,15 +124,15 @@
    4.96   */
    4.97  void SDLTest_LogAssertSummary()
    4.98  {
    4.99 -	char *fmt = (char *)SDLTest_AssertSummaryFmt;
   4.100 +	char *logFormat = (char *)SDLTest_AssertSummaryFormat;
   4.101  	Uint32 totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed;
   4.102  	if (SDLTest_AssertsFailed == 0)
   4.103  	{
   4.104 -		SDLTest_Log(fmt, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
   4.105 +		SDLTest_Log(logFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
   4.106  	} 
   4.107  	else 
   4.108  	{
   4.109 -		SDLTest_LogError(fmt, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
   4.110 +		SDLTest_LogError(logFormat, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
   4.111  	}
   4.112  }
   4.113  
     5.1 --- a/src/test/SDL_test_fuzzer.c	Sat Dec 15 00:30:17 2012 +0000
     5.2 +++ b/src/test/SDL_test_fuzzer.c	Fri Dec 14 23:05:34 2012 -0800
     5.3 @@ -58,7 +58,7 @@
     5.4  }
     5.5  
     5.6  int
     5.7 -SDLTest_GetInvocationCount()
     5.8 +SDLTest_GetFuzzerInvocationCount()
     5.9  {
    5.10  	return fuzzerInvocationCounter;
    5.11  }
     6.1 --- a/src/test/SDL_test_harness.c	Sat Dec 15 00:30:17 2012 +0000
     6.2 +++ b/src/test/SDL_test_harness.c	Fri Dec 14 23:05:34 2012 -0800
     6.3 @@ -28,11 +28,14 @@
     6.4  #include <string.h>
     6.5  #include <time.h>
     6.6  
     6.7 -/* Assert check message format */
     6.8 -const char *SDLTest_TestCheckFmt = "Test '%s': %s";
     6.9 +/* Invalid test name/description message format */
    6.10 +const char *SDLTest_InvalidNameFormat = "(Invalid)";
    6.11  
    6.12 -/* Invalid test name/description message format */
    6.13 -const char *SDLTest_InvalidNameFmt = "(Invalid)";
    6.14 +/* Log summary message format */
    6.15 +const char *SDLTest_LogSummaryFormat = "%s Summary: Total=%d Passed=%d Failed=%d Skipped=%d";
    6.16 +
    6.17 +/* Final result message format */
    6.18 +const char *SDLTest_FinalResultFormat = ">>> %s '%s': %s\n";
    6.19  
    6.20  /*! \brief Timeout for single test case execution */
    6.21  static Uint32 SDLTest_TestCaseTimeout = 3600;
    6.22 @@ -228,7 +231,7 @@
    6.23  
    6.24  	if (!testCase->enabled)
    6.25  	{
    6.26 -		SDLTest_Log((char *)SDLTest_TestCheckFmt, testCase->name, "Skipped");
    6.27 +		SDLTest_Log((char *)SDLTest_FinalResultFormat, "Test", testCase->name, "Skipped");
    6.28  		return TEST_RESULT_SKIPPED;
    6.29  	}
    6.30  
    6.31 @@ -245,7 +248,7 @@
    6.32  	if (testSuite->testSetUp) {
    6.33  		testSuite->testSetUp(0x0);
    6.34  		if (SDLTest_AssertSummaryToTestResult() == TEST_RESULT_FAILED) {
    6.35 -			SDLTest_LogError((char *)SDLTest_TestCheckFmt, testSuite->name, "Failed");
    6.36 +			SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Suite Setup", testSuite->name, "Failed");
    6.37  			return TEST_RESULT_SETUP_FAILURE;
    6.38  		}
    6.39  	}
    6.40 @@ -268,16 +271,6 @@
    6.41  	SDLTest_Log("Fuzzer invocations: %d", SDLTest_GetFuzzerInvocationCount());
    6.42  	SDLTest_LogAssertSummary();
    6.43  
    6.44 -	// Analyze assert count to determine final test case result
    6.45 -	switch (testResult) {
    6.46 -		case TEST_RESULT_PASSED:
    6.47 -			SDLTest_LogError((char *)SDLTest_TestCheckFmt, testCase->name, "Failed");
    6.48 -		case TEST_RESULT_FAILED:
    6.49 -			SDLTest_Log((char *)SDLTest_TestCheckFmt, testCase->name, "Passed");
    6.50 -		case TEST_RESULT_NO_ASSERT:
    6.51 -			SDLTest_LogError((char *)SDLTest_TestCheckFmt, testCase->name, "No Asserts");
    6.52 -	}
    6.53 -
    6.54  	return testResult;
    6.55  }
    6.56  
    6.57 @@ -295,7 +288,7 @@
    6.58  		testSuite=&testSuites[suiteCounter];
    6.59  		suiteCounter++;
    6.60  		SDLTest_Log("Test Suite %i - %s\n", suiteCounter, 
    6.61 -			(testSuite->name) ? testSuite->name : SDLTest_InvalidNameFmt);
    6.62 +			(testSuite->name) ? testSuite->name : SDLTest_InvalidNameFormat);
    6.63  
    6.64  		// Loop over all test cases
    6.65  		testCounter = 0;
    6.66 @@ -304,15 +297,21 @@
    6.67  			testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter];
    6.68  			testCounter++;
    6.69  			SDLTest_Log("  Test Case %i - %s: %s", testCounter, 
    6.70 -				(testCase->name) ? testCase->name : SDLTest_InvalidNameFmt, 
    6.71 -				(testCase->description) ? testCase->description : SDLTest_InvalidNameFmt);
    6.72 +				(testCase->name) ? testCase->name : SDLTest_InvalidNameFormat, 
    6.73 +				(testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
    6.74  		}
    6.75  	}
    6.76  }
    6.77  
    6.78 +/* Gets a timer value in seconds */
    6.79 +float GetClock()
    6.80 +{
    6.81 +	float currentClock = (float)clock();
    6.82 +	return currentClock / (float)CLOCKS_PER_SEC;
    6.83 +}
    6.84  
    6.85  /**
    6.86 - * \brief Execute a test using the given execution key.
    6.87 + * \brief Execute a test suite using the given run seend and execution key.
    6.88   *
    6.89   * \param testSuites Suites containing the test case.
    6.90   * \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one.
    6.91 @@ -322,7 +321,7 @@
    6.92   * \returns Test run result; 0 when all tests passed, 1 if any tests failed.
    6.93   */
    6.94  int
    6.95 -SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites, char *userRunSeed, Uint64 userExecKey, int testIterations)
    6.96 +SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, Uint64 userExecKey, int testIterations)
    6.97  {
    6.98  	int suiteCounter;
    6.99  	int testCounter;
   6.100 @@ -330,22 +329,25 @@
   6.101  	SDLTest_TestSuiteReference *testSuite;
   6.102  	SDLTest_TestCaseReference *testCase;
   6.103  	char *runSeed = NULL;
   6.104 +	char *currentSuiteName;
   6.105 +	char *currentTestName;
   6.106  	Uint64 execKey;
   6.107 -	Uint32 runStartTicks;
   6.108 -	time_t runStartTimestamp;
   6.109 -	Uint32 suiteStartTicks;
   6.110 -	time_t suiteStartTimestamp;
   6.111 -	Uint32 testStartTicks;
   6.112 -	time_t testStartTimestamp;
   6.113 -	Uint32 runEndTicks;
   6.114 -	time_t runEndTimestamp;
   6.115 -	Uint32 suiteEndTicks;
   6.116 -	time_t suiteEndTimestamp;
   6.117 -	Uint32 testEndTicks;
   6.118 -	time_t testEndTimestamp;
   6.119 -	int testResult;
   6.120 -	int totalTestFailedCount, totalTestPassedCount, totalTestSkippedCount;
   6.121 -	int testFailedCount, testPassedCount, testSkippedCount;
   6.122 +	float runStartSeconds;
   6.123 +	float suiteStartSeconds;
   6.124 +	float testStartSeconds;
   6.125 +	float runEndSeconds;
   6.126 +	float suiteEndSeconds;
   6.127 +	float testEndSeconds;
   6.128 +	int testResult = 0;
   6.129 +	int runResult = 0;
   6.130 +	Uint32 totalTestFailedCount = 0;
   6.131 +	Uint32 totalTestPassedCount = 0;
   6.132 +	Uint32 totalTestSkippedCount = 0;
   6.133 +	Uint32 testFailedCount = 0;
   6.134 +	Uint32 testPassedCount = 0;
   6.135 +	Uint32 testSkippedCount = 0;
   6.136 +	Uint32 countSum = 0;
   6.137 +	char *logFormat = (char *)SDLTest_LogSummaryFormat;
   6.138  
   6.139  	// Sanitize test iterations
   6.140  	if (testIterations < 1) {
   6.141 @@ -356,36 +358,41 @@
   6.142  	if (userRunSeed == NULL || strlen(userRunSeed) == 0) {
   6.143  		runSeed = SDLTest_GenerateRunSeed(16);
   6.144  		if (runSeed == NULL) {
   6.145 -			SDLTest_LogError("Generating a random run seed failed");
   6.146 +			SDLTest_LogError("Generating a random seed failed");
   6.147  			return 2;
   6.148  		}
   6.149  	}
   6.150  
   6.151  	// Reset per-run counters
   6.152 -	totalTestFailedCount = totalTestPassedCount = totalTestSkippedCount = 0;
   6.153 +	totalTestFailedCount = 0;
   6.154 +	totalTestPassedCount = 0;
   6.155 +	totalTestSkippedCount = 0;
   6.156  
   6.157  	// Take time - run start
   6.158 -	runStartTicks = SDL_GetTicks();
   6.159 -	runStartTimestamp = time(0);
   6.160 +	runStartSeconds = GetClock();
   6.161  
   6.162 -	// TODO log run started
   6.163 +	// Log run with fuzzer parameters
   6.164 +	SDLTest_Log("::::: Test Run '%s' started\n", runSeed);
   6.165  
   6.166  	// Loop over all suites
   6.167  	suiteCounter = 0;
   6.168 -	while(&testSuites[suiteCounter]) {
   6.169 -		testSuite=&testSuites[suiteCounter];
   6.170 +	while(testSuites[suiteCounter]) {
   6.171 +		testSuite=(SDLTest_TestSuiteReference *)testSuites[suiteCounter];
   6.172  		suiteCounter++;
   6.173  
   6.174  		// Reset per-suite counters
   6.175 -		testFailedCount = testPassedCount = testSkippedCount = 0;
   6.176 +		testFailedCount = 0;
   6.177 +		testPassedCount = 0;
   6.178 +		testSkippedCount = 0;
   6.179  
   6.180  		// Take time - suite start
   6.181 -		suiteStartTicks = SDL_GetTicks();
   6.182 -		suiteStartTimestamp = time(0);
   6.183 +		suiteStartSeconds = GetClock();
   6.184  
   6.185 -		// TODO log suite started
   6.186 -		SDLTest_Log("Test Suite %i - %s\n", suiteCounter, 
   6.187 -			(testSuite->name) ? testSuite->name : SDLTest_InvalidNameFmt);
   6.188 +		// Log suite started
   6.189 +		currentSuiteName = (char *)((testSuite->name) ? testSuite->name : SDLTest_InvalidNameFormat);
   6.190 +		SDLTest_Log("===== Test Suite %i: %s started\n", 
   6.191 +			suiteCounter, 
   6.192 +			currentSuiteName);
   6.193  
   6.194  		// Loop over all test cases
   6.195  		testCounter = 0;
   6.196 @@ -395,13 +402,15 @@
   6.197  			testCounter++;
   6.198  			
   6.199  			// Take time - test start
   6.200 -			testStartTicks = SDL_GetTicks();
   6.201 -			testStartTimestamp = time(0);
   6.202 +			testStartSeconds = GetClock();
   6.203  
   6.204 -			// TODO log test started
   6.205 -			SDLTest_Log("Test Case %i - %s: %s", testCounter, 
   6.206 -				(testCase->name) ? testCase->name : SDLTest_InvalidNameFmt, 
   6.207 -				(testCase->description) ? testCase->description : SDLTest_InvalidNameFmt);
   6.208 +			// Log test started
   6.209 +			currentTestName = (char *)((testCase->name) ? testCase->name : SDLTest_InvalidNameFormat);
   6.210 +			SDLTest_Log("----- Test Case %i: %s started", 
   6.211 +				testCounter, 
   6.212 +				currentTestName);
   6.213 +			SDLTest_Log("Test Description: %s", 
   6.214 +				(testCase->description) ? testCase->description : SDLTest_InvalidNameFormat);
   6.215  
   6.216  			// Loop over all iterations
   6.217  			iterationCounter = 0;
   6.218 @@ -431,24 +440,67 @@
   6.219  			}
   6.220  
   6.221  			// Take time - test end
   6.222 -			testEndTicks = SDL_GetTicks();
   6.223 -			testEndTimestamp = time(0);
   6.224 +			testEndSeconds = GetClock();
   6.225  
   6.226 -			// TODO log test ended
   6.227 +			SDLTest_Log("Test Case %s ended", currentTestName);
   6.228 +
   6.229 +			// Log test runtime
   6.230 +			SDLTest_Log("Test runtime: %.1f sec", testEndSeconds - testStartSeconds);
   6.231 +
   6.232 +			// Log final test result
   6.233 +			switch (testResult) {
   6.234 +				case TEST_RESULT_PASSED:
   6.235 +					SDLTest_Log((char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Passed");
   6.236 +					break;
   6.237 +				case TEST_RESULT_FAILED:
   6.238 +					SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Failed");
   6.239 +					break;
   6.240 +				case TEST_RESULT_NO_ASSERT:
   6.241 +					SDLTest_LogError((char *)SDLTest_FinalResultFormat,"Test", currentTestName, "No Asserts");
   6.242 +					break;
   6.243 +			}
   6.244  		}
   6.245  
   6.246  		// Take time - suite end
   6.247 -		suiteEndTicks = SDL_GetTicks();
   6.248 -		suiteEndTimestamp = time(0);
   6.249 +		suiteEndSeconds = GetClock();
   6.250  
   6.251 -		// TODO log suite ended
   6.252 +		// Log suite runtime
   6.253 +		SDLTest_Log("Suite runtime: %.1f sec", suiteEndSeconds - suiteStartSeconds);
   6.254 +
   6.255 +		// Log summary and final Suite result
   6.256 +	    countSum = testPassedCount + testFailedCount + testSkippedCount;
   6.257 +		if (testFailedCount == 0)
   6.258 +		{
   6.259 +			SDLTest_Log(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
   6.260 +			SDLTest_Log((char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Passed");
   6.261 +		} 
   6.262 +		else 
   6.263 +		{
   6.264 +			SDLTest_LogError(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount);
   6.265 +			SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Failed");
   6.266 +		}
   6.267  	}
   6.268  
   6.269  	// Take time - run end
   6.270 -	runEndTicks = SDL_GetTicks();
   6.271 -	runEndTimestamp = time(0);
   6.272 +	runEndSeconds = GetClock();
   6.273  
   6.274 -	// TODO log run ended
   6.275 +	// Log total runtime
   6.276 +	SDLTest_Log("Total runtime: %.1f sec", runEndSeconds - runStartSeconds);
   6.277  
   6.278 -	return (totalTestFailedCount ? 1 : 0);
   6.279 +	// Log summary and final run result
   6.280 +	countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount;
   6.281 +	if (testFailedCount == 0)
   6.282 +	{
   6.283 +		runResult = 0;
   6.284 +		SDLTest_Log(logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
   6.285 +		SDLTest_Log((char *)SDLTest_FinalResultFormat, "Run", runSeed, "Passed");
   6.286 +	} 
   6.287 +	else 
   6.288 +	{
   6.289 +		runResult = 1;
   6.290 +		SDLTest_LogError(logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount);
   6.291 +		SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Run", runSeed, "Failed");
   6.292 +	}
   6.293 +
   6.294 +	return runResult;
   6.295  }
     7.1 --- a/src/test/SDL_test_log.c	Sat Dec 15 00:30:17 2012 +0000
     7.2 +++ b/src/test/SDL_test_log.c	Fri Dec 14 23:05:34 2012 -0800
     7.3 @@ -37,12 +37,6 @@
     7.4  
     7.5  #include "SDL_test.h"
     7.6  
     7.7 -/* 
     7.8 - * Note: Maximum size of SDLTest log message is less than SDLs limit 
     7.9 - * to ensure we can fit additional information such as the timestamp. 
    7.10 - */
    7.11 -#define SDLTEST_MAX_LOGMESSAGE_LENGTH	3584
    7.12 -
    7.13  /*!
    7.14   * Converts unix timestamp to its ascii representation in localtime
    7.15   *
    7.16 @@ -52,18 +46,18 @@
    7.17   *
    7.18   * \param timestamp A Timestamp, i.e. time(0)
    7.19   *
    7.20 - * \return Ascii representation of the timestamp in localtime
    7.21 + * \return Ascii representation of the timestamp in localtime in the format '08/23/01 14:55:02'
    7.22   */
    7.23  char *SDLTest_TimestampToString(const time_t timestamp) 
    7.24  {
    7.25  	time_t copy;
    7.26 -	static char buffer[256];
    7.27 +	static char buffer[64];
    7.28  	struct tm *local;
    7.29  
    7.30  	memset(buffer, 0, sizeof(buffer));\
    7.31  	copy = timestamp;
    7.32  	local = localtime(&copy);
    7.33 -	strftime(buffer, sizeof(buffer), "%a %Y-%m-%d %H:%M:%S %Z", local);
    7.34 +	strftime(buffer, sizeof(buffer), "%x %X", local);
    7.35  
    7.36  	return buffer;
    7.37  }
    7.38 @@ -83,7 +77,7 @@
    7.39  	va_end(list);
    7.40  
    7.41  	// Log with timestamp and newline
    7.42 -	SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_INFO, "%s: %s\n", SDLTest_TimestampToString(time(0)), logMessage);
    7.43 +	SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_INFO, " %s: %s", SDLTest_TimestampToString(time(0)), logMessage);
    7.44  }
    7.45  
    7.46  /*
    7.47 @@ -101,5 +95,5 @@
    7.48  	va_end(list);
    7.49  
    7.50  	// Log with timestamp and newline
    7.51 -	SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR, "%s: %s\n", SDLTest_TimestampToString(time(0)), logMessage);
    7.52 +	SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR, "%s: %s", SDLTest_TimestampToString(time(0)), logMessage);
    7.53  }
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/test/testautomation.c	Fri Dec 14 23:05:34 2012 -0800
     8.3 @@ -0,0 +1,101 @@
     8.4 +/*
     8.5 +  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
     8.6 +
     8.7 +  This software is provided 'as-is', without any express or implied
     8.8 +  warranty.  In no event will the authors be held liable for any damages
     8.9 +  arising from the use of this software.
    8.10 +
    8.11 +  Permission is granted to anyone to use this software for any purpose,
    8.12 +  including commercial applications, and to alter it and redistribute it
    8.13 +  freely.
    8.14 +*/
    8.15 +
    8.16 +#include <stdlib.h>
    8.17 +#include <stdio.h>
    8.18 +#include <time.h>
    8.19 +
    8.20 +#include "SDL.h"
    8.21 +#include "SDL_test.h"
    8.22 +
    8.23 +#include "tests/testsuites.h"
    8.24 +
    8.25 +static SDLTest_CommonState *state;
    8.26 +
    8.27 +
    8.28 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    8.29 +static void
    8.30 +quit(int rc)
    8.31 +{
    8.32 +    SDLTest_CommonQuit(state);
    8.33 +    exit(rc);
    8.34 +}
    8.35 +
    8.36 +int
    8.37 +main(int argc, char *argv[])
    8.38 +{
    8.39 +    int result;
    8.40 +    int i;
    8.41 +
    8.42 +    /* Initialize test framework */
    8.43 +    state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
    8.44 +    if (!state) {
    8.45 +        return 1;
    8.46 +    }
    8.47 +
    8.48 +    // Needed?
    8.49 +    // state->window_flags |= SDL_WINDOW_RESIZABLE;
    8.50 +
    8.51 +    /* Parse commandline */
    8.52 +    for (i = 1; i < argc;) {
    8.53 +        int consumed;
    8.54 +
    8.55 +        consumed = SDLTest_CommonArg(state, i);
    8.56 +        if (consumed == 0) {
    8.57 +            consumed = -1;
    8.58 +/* Parse additional parameters
    8.59 +
    8.60 +            if (SDL_strcasecmp(argv[i], "--BLAH") == 0) {
    8.61 +                if (argv[i + 1]) {
    8.62 +                    if (SDL_strcasecmp(argv[i + 1], "BLUB") == 0) {
    8.63 +                        blah = blub;
    8.64 +                        consumed = 2;
    8.65 +                    }
    8.66 +                }
    8.67 +            } else if (SDL_strcasecmp(argv[i], "--BINGO") == 0) {
    8.68 +                bingo = SDL_TRUE;
    8.69 +                consumed = 1;
    8.70 +            }
    8.71 +*/
    8.72 +        }
    8.73 +        if (consumed < 0) {
    8.74 +            fprintf(stderr,
    8.75 +                    "Usage: %s %s [--BLAH BLUB --BINGO]\n",
    8.76 +                    argv[0], SDLTest_CommonUsage(state));
    8.77 +            quit(1);
    8.78 +        }
    8.79 +        i += consumed;
    8.80 +    }
    8.81 +
    8.82 +    /* Initialize common state */    
    8.83 +    if (!SDLTest_CommonInit(state)) {
    8.84 +        quit(2);
    8.85 +    }
    8.86 +
    8.87 +    /* Create the windows, initialize the renderers */
    8.88 +    for (i = 0; i < state->num_windows; ++i) {
    8.89 +        SDL_Renderer *renderer = state->renderers[i];
    8.90 +        SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
    8.91 +        SDL_RenderClear(renderer);
    8.92 +    }
    8.93 +
    8.94 +    /* Call Harness */
    8.95 +    // TODO: pass custom parameters
    8.96 +    result = SDLTest_RunSuites(testSuites, NULL, 0, 1);
    8.97 +//int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites, char *userRunSeed, Uint64 userExecKey, int testIterations);
    8.98 +    
    8.99 +    /* Shutdown everything */
   8.100 +    quit(result);        
   8.101 +    return(result);
   8.102 +}
   8.103 +
   8.104 +/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/test/tests/testplatform.c	Fri Dec 14 23:05:34 2012 -0800
     9.3 @@ -0,0 +1,561 @@
     9.4 +/**
     9.5 + * Original code: automated SDL platform test written by Edgar Simo "bobbens"
     9.6 + * Extended and updated by aschiffler at ferzkopp dot net
     9.7 + */
     9.8 +
     9.9 +#include <stdio.h>
    9.10 +
    9.11 +#include "SDL.h"
    9.12 +#include "SDL_test.h"
    9.13 +
    9.14 +/* ================= Test Case Implementation ================== */
    9.15 +
    9.16 +/* Helper functions */
    9.17 +
    9.18 +/**
    9.19 + * @brief Compare sizes of types.
    9.20 + *
    9.21 + * @note Watcom C flags these as Warning 201: "Unreachable code" if you just
    9.22 + *  compare them directly, so we push it through a function to keep the
    9.23 + *  compiler quiet.  --ryan.
    9.24 + */
    9.25 +static int _compareSizeOfType( size_t sizeoftype, size_t hardcodetype )
    9.26 +{
    9.27 +    return sizeoftype != hardcodetype;
    9.28 +}
    9.29 +
    9.30 +/* Test case functions */
    9.31 +
    9.32 +/**
    9.33 + * @brief Tests type sizes.
    9.34 + */
    9.35 +int platform_testTypes(void *arg)
    9.36 +{
    9.37 +   int ret;
    9.38 +
    9.39 +   ret = _compareSizeOfType( sizeof(Uint8), 1 );
    9.40 +   SDLTest_AssertCheck( ret == 0, "sizeof(Uint8) = %lu, expected  1", sizeof(Uint8) );
    9.41 +
    9.42 +   ret = _compareSizeOfType( sizeof(Uint16), 2 );
    9.43 +   SDLTest_AssertCheck( ret == 0, "sizeof(Uint16) = %lu, expected 2", sizeof(Uint16) );
    9.44 +
    9.45 +   ret = _compareSizeOfType( sizeof(Uint32), 4 );
    9.46 +   SDLTest_AssertCheck( ret == 0, "sizeof(Uint32) = %lu, expected 4", sizeof(Uint32) );
    9.47 +
    9.48 +   ret = _compareSizeOfType( sizeof(Uint64), 8 );
    9.49 +   SDLTest_AssertCheck( ret == 0, "sizeof(Uint64) = %lu, expected 8", sizeof(Uint64) );
    9.50 +
    9.51 +   return TEST_COMPLETED;
    9.52 +}
    9.53 +
    9.54 +/**
    9.55 + * @brief Tests platform endianness and SDL_SwapXY functions.
    9.56 + */
    9.57 +int platform_testEndianessAndSwap(void *arg)
    9.58 +{
    9.59 +    int real_byteorder;
    9.60 +    Uint16 value = 0x1234;
    9.61 +    Uint16 value16 = 0xCDAB;
    9.62 +    Uint16 swapped16 = 0xABCD;
    9.63 +    Uint32 value32 = 0xEFBEADDE;
    9.64 +    Uint32 swapped32 = 0xDEADBEEF;
    9.65 +
    9.66 +    Uint64 value64, swapped64;
    9.67 +    value64 = 0xEFBEADDE;
    9.68 +    value64 <<= 32;
    9.69 +    value64 |= 0xCDAB3412;
    9.70 +    swapped64 = 0x1234ABCD;
    9.71 +    swapped64 <<= 32;
    9.72 +    swapped64 |= 0xDEADBEEF;
    9.73 +
    9.74 +    if ((*((char *) &value) >> 4) == 0x1) {
    9.75 +        real_byteorder = SDL_BIG_ENDIAN;
    9.76 +    } else {
    9.77 +        real_byteorder = SDL_LIL_ENDIAN;
    9.78 +    }
    9.79 +
    9.80 +    /* Test endianness. */
    9.81 +    SDLTest_AssertCheck( real_byteorder == SDL_BYTEORDER,
    9.82 +             "Machine detected as %s endian, appears to be %s endian.",
    9.83 +             (SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
    9.84 +             (real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big" );
    9.85 +
    9.86 +    /* Test 16 swap. */
    9.87 +    SDLTest_AssertCheck( SDL_Swap16(value16) == swapped16,
    9.88 +             "SDL_Swap16(): 16 bit swapped: 0x%X => 0x%X",
    9.89 +             value16, SDL_Swap16(value16) );
    9.90 +
    9.91 +    /* Test 32 swap. */
    9.92 +    SDLTest_AssertCheck( SDL_Swap32(value32) == swapped32,
    9.93 +             "SDL_Swap32(): 32 bit swapped: 0x%X => 0x%X",
    9.94 +             value32, SDL_Swap32(value32) );
    9.95 +
    9.96 +    /* Test 64 swap. */
    9.97 +    SDLTest_AssertCheck( SDL_Swap64(value64) == swapped64,
    9.98 +#ifdef _MSC_VER
    9.99 +             "SDL_Swap64(): 64 bit swapped: 0x%I64X => 0x%I64X",
   9.100 +#else
   9.101 +             "SDL_Swap64(): 64 bit swapped: 0x%llX => 0x%llX",
   9.102 +#endif
   9.103 +             value64, SDL_Swap64(value64) );
   9.104 +
   9.105 +   return TEST_COMPLETED;
   9.106 +}
   9.107 +
   9.108 +/*!
   9.109 + * \brief Tests SDL_GetXYZ() functions
   9.110 + * \sa
   9.111 + * http://wiki.libsdl.org/moin.cgi/SDL_GetPlatform
   9.112 + * http://wiki.libsdl.org/moin.cgi/SDL_GetCPUCount
   9.113 + * http://wiki.libsdl.org/moin.cgi/SDL_GetCPUCacheLineSize
   9.114 + * http://wiki.libsdl.org/moin.cgi/SDL_GetRevision
   9.115 + * http://wiki.libsdl.org/moin.cgi/SDL_GetRevisionNumber
   9.116 + */
   9.117 +int platform_testGetFunctions (void *arg)
   9.118 +{
   9.119 +   char *platform;
   9.120 +   char *revision;
   9.121 +   int ret;
   9.122 +   int len;
   9.123 +
   9.124 +   platform = (char *)SDL_GetPlatform();
   9.125 +   SDLTest_AssertPass("SDL_GetPlatform()");
   9.126 +   SDLTest_AssertCheck(platform != NULL, "SDL_GetPlatform() != NULL");
   9.127 +   if (platform != NULL) {
   9.128 +     len = strlen(platform);
   9.129 +     SDLTest_AssertCheck(len > 0,
   9.130 +             "SDL_GetPlatform(): expected non-empty platform, was platform: '%s', len: %i",
   9.131 +             platform,
   9.132 +             len);
   9.133 +   }
   9.134 +
   9.135 +   ret = SDL_GetCPUCount();
   9.136 +   SDLTest_AssertPass("SDL_GetCPUCount()");
   9.137 +   SDLTest_AssertCheck(ret > 0,
   9.138 +             "SDL_GetCPUCount(): expected count > 0, was: %i",
   9.139 +             ret);
   9.140 +
   9.141 +   ret = SDL_GetCPUCacheLineSize();
   9.142 +   SDLTest_AssertPass("SDL_GetCPUCacheLineSize()");
   9.143 +   SDLTest_AssertCheck(ret >= 0,
   9.144 +             "SDL_GetCPUCacheLineSize(): expected size >= 0, was: %i",
   9.145 +             ret);
   9.146 +
   9.147 +   revision = (char *)SDL_GetRevision();
   9.148 +   SDLTest_AssertPass("SDL_GetRevision()");
   9.149 +   SDLTest_AssertCheck(revision != NULL, "SDL_GetRevision() != NULL");
   9.150 +
   9.151 +   ret = SDL_GetRevisionNumber();
   9.152 +   SDLTest_AssertPass("SDL_GetRevisionNumber()");
   9.153 +
   9.154 +   return TEST_COMPLETED;
   9.155 +}
   9.156 +
   9.157 +/*!
   9.158 + * \brief Tests SDL_HasXYZ() functions
   9.159 + * \sa
   9.160 + * http://wiki.libsdl.org/moin.cgi/SDL_Has3DNow
   9.161 + * http://wiki.libsdl.org/moin.cgi/SDL_HasAltiVec
   9.162 + * http://wiki.libsdl.org/moin.cgi/SDL_HasMMX
   9.163 + * http://wiki.libsdl.org/moin.cgi/SDL_HasRDTSC
   9.164 + * http://wiki.libsdl.org/moin.cgi/SDL_HasSSE
   9.165 + * http://wiki.libsdl.org/moin.cgi/SDL_HasSSE2
   9.166 + * http://wiki.libsdl.org/moin.cgi/SDL_HasSSE3
   9.167 + * http://wiki.libsdl.org/moin.cgi/SDL_HasSSE41
   9.168 + * http://wiki.libsdl.org/moin.cgi/SDL_HasSSE42
   9.169 + */
   9.170 +int platform_testHasFunctions (void *arg)
   9.171 +{
   9.172 +   int ret;
   9.173 +
   9.174 +   // TODO: independently determine and compare values as well
   9.175 +
   9.176 +   ret = SDL_HasRDTSC();
   9.177 +   SDLTest_AssertPass("SDL_HasRDTSC()");
   9.178 +
   9.179 +   ret = SDL_HasAltiVec();
   9.180 +   SDLTest_AssertPass("SDL_HasAltiVec()");
   9.181 +
   9.182 +   ret = SDL_HasMMX();
   9.183 +   SDLTest_AssertPass("SDL_HasMMX()");
   9.184 +
   9.185 +   ret = SDL_Has3DNow();
   9.186 +   SDLTest_AssertPass("SDL_Has3DNow()");
   9.187 +
   9.188 +   ret = SDL_HasSSE();
   9.189 +   SDLTest_AssertPass("SDL_HasSSE()");
   9.190 +
   9.191 +   ret = SDL_HasSSE2();
   9.192 +   SDLTest_AssertPass("SDL_HasSSE2()");
   9.193 +
   9.194 +   ret = SDL_HasSSE3();
   9.195 +   SDLTest_AssertPass("SDL_HasSSE3()");
   9.196 +
   9.197 +   ret = SDL_HasSSE41();
   9.198 +   SDLTest_AssertPass("SDL_HasSSE41()");
   9.199 +
   9.200 +   ret = SDL_HasSSE42();
   9.201 +   SDLTest_AssertPass("SDL_HasSSE42()");
   9.202 +
   9.203 +   return TEST_COMPLETED;
   9.204 +}
   9.205 +
   9.206 +/*!
   9.207 + * \brief Tests SDL_GetVersion
   9.208 + * \sa
   9.209 + * http://wiki.libsdl.org/moin.cgi/SDL_GetVersion
   9.210 + */
   9.211 +int platform_testGetVersion(void *arg)
   9.212 +{
   9.213 +   SDL_version linked;
   9.214 +   int major = SDL_MAJOR_VERSION;
   9.215 +   int minor = SDL_MINOR_VERSION;
   9.216 +
   9.217 +   SDL_GetVersion(&linked);
   9.218 +   SDLTest_AssertCheck( linked.major >= major,
   9.219 +             "SDL_GetVersion(): returned major %i (>= %i)",
   9.220 +             linked.major,
   9.221 +             major);
   9.222 +   SDLTest_AssertCheck( linked.minor >= minor,
   9.223 +             "SDL_GetVersion(): returned minor %i (>= %i)",
   9.224 +             linked.minor,
   9.225 +             minor);
   9.226 +
   9.227 +   return TEST_COMPLETED;
   9.228 +}
   9.229 +
   9.230 +
   9.231 +/*!
   9.232 + * \brief Tests SDL_VERSION macro
   9.233 + */
   9.234 +int platform_testSDLVersion(void *arg)
   9.235 +{
   9.236 +   SDL_version compiled;
   9.237 +   int major = SDL_MAJOR_VERSION;
   9.238 +   int minor = SDL_MINOR_VERSION;
   9.239 +
   9.240 +   SDL_VERSION(&compiled);
   9.241 +   SDLTest_AssertCheck( compiled.major >= major,
   9.242 +             "SDL_VERSION() returned major %i (>= %i)",
   9.243 +             compiled.major,
   9.244 +             major);
   9.245 +   SDLTest_AssertCheck( compiled.minor >= minor,
   9.246 +             "SDL_VERSION() returned minor %i (>= %i)",
   9.247 +             compiled.minor,
   9.248 +             minor);
   9.249 +
   9.250 +   return TEST_COMPLETED;
   9.251 +}
   9.252 +
   9.253 +
   9.254 +/*!
   9.255 + * \brief Tests default SDL_Init
   9.256 + */
   9.257 +int platform_testDefaultInit(void *arg)
   9.258 +{
   9.259 +   int ret;
   9.260 +   int subsystem;
   9.261 +
   9.262 +   subsystem = SDL_WasInit(SDL_INIT_EVERYTHING);
   9.263 +   SDLTest_AssertCheck( subsystem != 0,
   9.264 +             "SDL_WasInit(0): returned %i, expected != 0",
   9.265 +             subsystem);
   9.266 +
   9.267 +   ret = SDL_Init(SDL_WasInit(SDL_INIT_EVERYTHING));
   9.268 +   SDLTest_AssertCheck( ret == 0,
   9.269 +             "SDL_Init(0): returned %i, expected 0, error: %s",
   9.270 +             ret,
   9.271 +             SDL_GetError());
   9.272 +
   9.273 +   return TEST_COMPLETED;
   9.274 +}
   9.275 +
   9.276 +/*!
   9.277 + * \brief Tests SDL_Get/Set/ClearError
   9.278 + * \sa
   9.279 + * http://wiki.libsdl.org/moin.cgi/SDL_GetError
   9.280 + * http://wiki.libsdl.org/moin.cgi/SDL_SetError
   9.281 + * http://wiki.libsdl.org/moin.cgi/SDL_ClearError
   9.282 + */
   9.283 +int platform_testGetSetClearError(void *arg)
   9.284 +{
   9.285 +   const char *testError = "Testing";
   9.286 +   char *lastError;
   9.287 +   int len;
   9.288 +
   9.289 +   SDL_ClearError();
   9.290 +   SDLTest_AssertPass("SDL_ClearError()");
   9.291 +
   9.292 +   lastError = (char *)SDL_GetError();
   9.293 +   SDLTest_AssertPass("SDL_GetError()");
   9.294 +   SDLTest_AssertCheck(lastError != NULL,
   9.295 +             "SDL_GetError() != NULL");
   9.296 +   if (lastError != NULL)
   9.297 +   {
   9.298 +     len = strlen(lastError);
   9.299 +     SDLTest_AssertCheck(len == 0,
   9.300 +             "SDL_GetError(): no message expected, len: %i", len);
   9.301 +   }
   9.302 +
   9.303 +   SDL_SetError("%s", testError);
   9.304 +   SDLTest_AssertPass("SDL_SetError()");
   9.305 +   lastError = (char *)SDL_GetError();
   9.306 +   SDLTest_AssertCheck(lastError != NULL,
   9.307 +             "SDL_GetError() != NULL");
   9.308 +   if (lastError != NULL)
   9.309 +   {
   9.310 +     len = strlen(lastError);
   9.311 +     SDLTest_AssertCheck(len == strlen(testError),
   9.312 +             "SDL_GetError(): expected message len %i, was len: %i",
   9.313 +             strlen(testError),
   9.314 +             len);
   9.315 +     SDLTest_AssertCheck(strcmp(lastError, testError) == 0,
   9.316 +             "SDL_GetError(): expected message %s, was message: %s",
   9.317 +             testError,
   9.318 +             lastError);
   9.319 +   }
   9.320 +
   9.321 +   // Clean up
   9.322 +   SDL_ClearError();
   9.323 +   SDLTest_AssertPass("SDL_ClearError()");
   9.324 +
   9.325 +   return TEST_COMPLETED;
   9.326 +}
   9.327 +
   9.328 +/*!
   9.329 + * \brief Tests SDL_SetError with empty input
   9.330 + * \sa
   9.331 + * http://wiki.libsdl.org/moin.cgi/SDL_SetError
   9.332 + */
   9.333 +int platform_testSetErrorEmptyInput(void *arg)
   9.334 +{
   9.335 +   const char *testError = "";
   9.336 +   char *lastError;
   9.337 +   int len;
   9.338 +
   9.339 +   SDL_SetError("%s", testError);
   9.340 +   SDLTest_AssertPass("SDL_SetError()");
   9.341 +   lastError = (char *)SDL_GetError();
   9.342 +   SDLTest_AssertCheck(lastError != NULL,
   9.343 +             "SDL_GetError() != NULL");
   9.344 +   if (lastError != NULL)
   9.345 +   {
   9.346 +     len = strlen(lastError);
   9.347 +     SDLTest_AssertCheck(len == strlen(testError),
   9.348 +             "SDL_GetError(): expected message len %i, was len: %i",
   9.349 +             strlen(testError),
   9.350 +             len);
   9.351 +     SDLTest_AssertCheck(strcmp(lastError, testError) == 0,
   9.352 +             "SDL_GetError(): expected message '%s', was message: '%s'",
   9.353 +             testError,
   9.354 +             lastError);
   9.355 +   }
   9.356 +
   9.357 +   // Clean up
   9.358 +   SDL_ClearError();
   9.359 +   SDLTest_AssertPass("SDL_ClearError()");
   9.360 +
   9.361 +   return TEST_COMPLETED;
   9.362 +}
   9.363 +
   9.364 +/*!
   9.365 + * \brief Tests SDL_SetError with invalid input
   9.366 + * \sa
   9.367 + * http://wiki.libsdl.org/moin.cgi/SDL_SetError
   9.368 + */
   9.369 +int platform_testSetErrorInvalidInput(void *arg)
   9.370 +{
   9.371 +   const char *testError = NULL;
   9.372 +   const char *probeError = "Testing";
   9.373 +   char *lastError;
   9.374 +   int len;
   9.375 +
   9.376 +   // Reset
   9.377 +   SDL_ClearError();
   9.378 +   SDLTest_AssertPass("SDL_ClearError()");
   9.379 +
   9.380 +   // Check for no-op
   9.381 +   SDL_SetError(testError);
   9.382 +   SDLTest_AssertPass("SDL_SetError()");
   9.383 +   lastError = (char *)SDL_GetError();
   9.384 +   SDLTest_AssertCheck(lastError != NULL,
   9.385 +             "SDL_GetError() != NULL");
   9.386 +   if (lastError != NULL)
   9.387 +   {
   9.388 +     len = strlen(lastError);
   9.389 +     SDLTest_AssertCheck(len == 0,
   9.390 +             "SDL_GetError(): expected message len 0, was len: %i",
   9.391 +             0,
   9.392 +             len);
   9.393 +     SDLTest_AssertCheck(strcmp(lastError, "") == 0,
   9.394 +             "SDL_GetError(): expected message '', was message: '%s'",
   9.395 +             lastError);
   9.396 +   }
   9.397 +
   9.398 +   // Set
   9.399 +   SDL_SetError(probeError);
   9.400 +   SDLTest_AssertPass("SDL_SetError()");
   9.401 +
   9.402 +   // Check for no-op
   9.403 +   SDL_SetError(testError);
   9.404 +   SDLTest_AssertPass("SDL_SetError()");
   9.405 +   lastError = (char *)SDL_GetError();
   9.406 +   SDLTest_AssertCheck(lastError != NULL,
   9.407 +             "SDL_GetError() != NULL");
   9.408 +   if (lastError != NULL)
   9.409 +   {
   9.410 +     len = strlen(lastError);
   9.411 +     SDLTest_AssertCheck(len == strlen(probeError),
   9.412 +             "SDL_GetError(): expected message len %i, was len: %i",
   9.413 +             strlen(probeError),
   9.414 +             len);
   9.415 +     SDLTest_AssertCheck(strcmp(lastError, probeError) == 0,
   9.416 +             "SDL_GetError(): expected message '%s', was message: '%s'",
   9.417 +             probeError,
   9.418 +             lastError);
   9.419 +   }
   9.420 +
   9.421 +   // Clean up
   9.422 +   SDL_ClearError();
   9.423 +   SDLTest_AssertPass("SDL_ClearError()");
   9.424 +
   9.425 +   return TEST_COMPLETED;
   9.426 +}
   9.427 +
   9.428 +/*!
   9.429 + * \brief Tests SDL_GetPowerInfo
   9.430 + * \sa
   9.431 + * http://wiki.libsdl.org/moin.cgi/SDL_GetPowerInfo
   9.432 + */
   9.433 +int platform_testGetPowerInfo(void *arg)
   9.434 +{
   9.435 +   SDL_PowerState state;
   9.436 +   SDL_PowerState stateAgain;
   9.437 +   int secs;
   9.438 +   int secsAgain;
   9.439 +   int pct;
   9.440 +   int pctAgain;
   9.441 +
   9.442 +   state = SDL_GetPowerInfo(&secs, &pct);
   9.443 +   SDLTest_AssertPass("SDL_GetPowerInfo()");
   9.444 +   SDLTest_AssertCheck(
   9.445 +       state==SDL_POWERSTATE_UNKNOWN ||
   9.446 +       state==SDL_POWERSTATE_ON_BATTERY ||
   9.447 +       state==SDL_POWERSTATE_NO_BATTERY ||
   9.448 +       state==SDL_POWERSTATE_CHARGING ||
   9.449 +       state==SDL_POWERSTATE_CHARGED,
   9.450 +       "SDL_GetPowerInfo(): state %i is one of the expected values",
   9.451 +       (int)state);
   9.452 +
   9.453 +   if (state==SDL_POWERSTATE_ON_BATTERY)
   9.454 +   {
   9.455 +      SDLTest_AssertCheck(
   9.456 +         secs >= 0,
   9.457 +         "SDL_GetPowerInfo(): on battery, secs >= 0, was: %i",
   9.458 +         secs);
   9.459 +      SDLTest_AssertCheck(
   9.460 +         (pct >= 0) && (pct <= 100),
   9.461 +         "SDL_GetPowerInfo(): on battery, pct=[0,100], was: %i",
   9.462 +         pct);
   9.463 +   }
   9.464 +
   9.465 +   if (state==SDL_POWERSTATE_UNKNOWN ||
   9.466 +       state==SDL_POWERSTATE_NO_BATTERY)
   9.467 +   {
   9.468 +      SDLTest_AssertCheck(
   9.469 +         secs == -1,
   9.470 +         "SDL_GetPowerInfo(): no battery, secs == -1, was: %i",
   9.471 +         secs);
   9.472 +      SDLTest_AssertCheck(
   9.473 +         pct == -1,
   9.474 +         "SDL_GetPowerInfo(): no battery, pct == -1, was: %i",
   9.475 +         pct);
   9.476 +   }
   9.477 +
   9.478 +   // Partial return value variations
   9.479 +   stateAgain = SDL_GetPowerInfo(&secsAgain, NULL);
   9.480 +   SDLTest_AssertCheck(
   9.481 +        state==stateAgain,
   9.482 +        "State %i returned when only 'secs' requested",
   9.483 +        stateAgain);
   9.484 +   SDLTest_AssertCheck(
   9.485 +        secs==secsAgain,
   9.486 +        "Value %i matches when only 'secs' requested",
   9.487 +        secsAgain);
   9.488 +   stateAgain = SDL_GetPowerInfo(NULL, &pctAgain);
   9.489 +   SDLTest_AssertCheck(
   9.490 +        state==stateAgain,
   9.491 +        "State %i returned when only 'pct' requested",
   9.492 +        stateAgain);
   9.493 +   SDLTest_AssertCheck(
   9.494 +        pct==pctAgain,
   9.495 +        "Value %i matches when only 'pct' requested",
   9.496 +        pctAgain);
   9.497 +   stateAgain = SDL_GetPowerInfo(NULL, NULL);
   9.498 +   SDLTest_AssertCheck(
   9.499 +        state==stateAgain,
   9.500 +        "State %i returned when no value requested",
   9.501 +        stateAgain);
   9.502 +
   9.503 +   return TEST_COMPLETED;
   9.504 +}
   9.505 +
   9.506 +/* ================= Test References ================== */
   9.507 +
   9.508 +/* Platform test cases */
   9.509 +static const SDLTest_TestCaseReference platformTest1 =
   9.510 +		{ (SDLTest_TestCaseFp)platform_testTypes, "platform_testTypes", "Tests predefined types", TEST_ENABLED};
   9.511 +
   9.512 +static const SDLTest_TestCaseReference platformTest2 =
   9.513 +		{ (SDLTest_TestCaseFp)platform_testEndianessAndSwap, "platform_testEndianessAndSwap", "Tests endianess and swap functions", TEST_ENABLED};
   9.514 +
   9.515 +static const SDLTest_TestCaseReference platformTest3 =
   9.516 +		{ (SDLTest_TestCaseFp)platform_testGetFunctions, "platform_testGetFunctions", "Tests various SDL_GetXYZ functions", TEST_ENABLED};
   9.517 +
   9.518 +static const SDLTest_TestCaseReference platformTest4 =
   9.519 +		{ (SDLTest_TestCaseFp)platform_testHasFunctions, "platform_testHasFunctions", "Tests various SDL_HasXYZ functions", TEST_ENABLED};
   9.520 +
   9.521 +static const SDLTest_TestCaseReference platformTest5 =
   9.522 +		{ (SDLTest_TestCaseFp)platform_testGetVersion, "platform_testGetVersion", "Tests SDL_GetVersion function", TEST_ENABLED};
   9.523 +
   9.524 +static const SDLTest_TestCaseReference platformTest6 =
   9.525 +		{ (SDLTest_TestCaseFp)platform_testSDLVersion, "platform_testSDLVersion", "Tests SDL_VERSION macro", TEST_ENABLED};
   9.526 +
   9.527 +static const SDLTest_TestCaseReference platformTest7 =
   9.528 +		{ (SDLTest_TestCaseFp)platform_testDefaultInit, "platform_testDefaultInit", "Tests default SDL_Init", TEST_ENABLED};
   9.529 +
   9.530 +static const SDLTest_TestCaseReference platformTest8 =
   9.531 +		{ (SDLTest_TestCaseFp)platform_testGetSetClearError, "platform_testGetSetClearError", "Tests SDL_Get/Set/ClearError", TEST_ENABLED};
   9.532 +
   9.533 +static const SDLTest_TestCaseReference platformTest9 =
   9.534 +		{ (SDLTest_TestCaseFp)platform_testSetErrorEmptyInput, "platform_testSetErrorEmptyInput", "Tests SDL_SetError with empty input", TEST_ENABLED};
   9.535 +
   9.536 +static const SDLTest_TestCaseReference platformTest10 =
   9.537 +		{ (SDLTest_TestCaseFp)platform_testSetErrorInvalidInput, "platform_testSetErrorInvalidInput", "Tests SDL_SetError with invalid input", TEST_ENABLED};
   9.538 +
   9.539 +static const SDLTest_TestCaseReference platformTest11 =
   9.540 +		{ (SDLTest_TestCaseFp)platform_testGetPowerInfo, "platform_testGetPowerInfo", "Tests SDL_GetPowerInfo function", TEST_ENABLED };
   9.541 +
   9.542 +/* Sequence of Platform test cases */
   9.543 +static const SDLTest_TestCaseReference *platformTests[] =  {
   9.544 +	&platformTest1,
   9.545 +	&platformTest2,
   9.546 +	&platformTest3,
   9.547 +	&platformTest4,
   9.548 +	&platformTest5,
   9.549 +	&platformTest6,
   9.550 +	&platformTest7,
   9.551 +	&platformTest8,
   9.552 +	&platformTest9,
   9.553 +	&platformTest10,
   9.554 +	&platformTest11,
   9.555 +	NULL
   9.556 +};
   9.557 +
   9.558 +/* Platform test suite (global) */
   9.559 +SDLTest_TestSuiteReference platformTestSuite = {
   9.560 +	"Platform",
   9.561 +	NULL,
   9.562 +	platformTests,
   9.563 +	NULL
   9.564 +};
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/test/tests/testsuites.h	Fri Dec 14 23:05:34 2012 -0800
    10.3 @@ -0,0 +1,40 @@
    10.4 +/**
    10.5 + * Reference to all test suites.
    10.6 + *
    10.7 + */
    10.8 +
    10.9 +#ifndef _testsuites_h
   10.10 +#define _testsuites_h
   10.11 +
   10.12 +#include "SDL_test.h"
   10.13 +
   10.14 +// Test collections
   10.15 +//extern SDLTest_TestSuiteReference audioTestSuite;
   10.16 +//extern SDLTest_TestSuiteReference clipboardTestSuite;
   10.17 +//extern SDLTest_TestSuiteReference eventsTestSuite;
   10.18 +//extern SDLTest_TestSuiteReference keyboardTestSuite;
   10.19 +extern SDLTest_TestSuiteReference platformTestSuite;
   10.20 +//extern SDLTest_TestSuiteReference rectTestSuite;
   10.21 +//extern SDLTest_TestSuiteReference renderTestSuite;
   10.22 +//extern SDLTest_TestSuiteReference rwopsTestSuite;
   10.23 +//extern SDLTest_TestSuiteReference surfaceTestSuite;
   10.24 +//extern SDLTest_TestSuiteReference syswmTestSuite;
   10.25 +//extern SDLTest_TestSuiteReference videoTestSuite;
   10.26 +
   10.27 +// All test suites
   10.28 +SDLTest_TestSuiteReference *testSuites[] =  {
   10.29 +//	&audioTestSuite,
   10.30 +//	&clipboardTestSuite,
   10.31 +//	&eventsTestSuite,
   10.32 +//	&keyboardTestSuite,
   10.33 +	&platformTestSuite,
   10.34 +//	&rectTestSuite,
   10.35 +//	&renderTestSuite,
   10.36 +//	&rwopsTestSuite,
   10.37 +//	&surfaceTestSuite,
   10.38 +//	&syswmTestSuite,
   10.39 +//	&videoTestSuite,
   10.40 +	NULL
   10.41 +};
   10.42 +
   10.43 +#endif