Port clipboard and rwops test suites from GSOC code; minor updates to harness and fuzzer in test lib
authorAndreas Schiffler <aschiffler@ferzkopp.net>
Sun, 16 Dec 2012 21:59:29 -0800
changeset 676004dcce3081e6
parent 6759 b74da0b33530
child 6761 dacf27c78462
Port clipboard and rwops test suites from GSOC code; minor updates to harness and fuzzer in test lib
src/test/SDL_test_fuzzer.c
src/test/SDL_test_harness.c
test/tests/testclipboard.c
test/tests/testrwops.c
test/tests/testsuites.h
     1.1 --- a/src/test/SDL_test_fuzzer.c	Sun Dec 16 14:46:16 2012 -0500
     1.2 +++ b/src/test/SDL_test_fuzzer.c	Sun Dec 16 21:59:29 2012 -0800
     1.3 @@ -630,7 +630,7 @@
     1.4          }
     1.5  
     1.6  	for(counter = 0; counter < size; ++counter) {
     1.7 -		string[counter] = (char)SDLTest_RandomIntegerInRange(1, 127);
     1.8 +		string[counter] = (char)SDLTest_RandomIntegerInRange(32, 126);
     1.9  	}
    1.10  
    1.11  	string[counter] = '\0';
     2.1 --- a/src/test/SDL_test_harness.c	Sun Dec 16 14:46:16 2012 -0500
     2.2 +++ b/src/test/SDL_test_harness.c	Sun Dec 16 21:59:29 2012 -0800
     2.3 @@ -342,6 +342,7 @@
     2.4  	float runEndSeconds;
     2.5  	float suiteEndSeconds;
     2.6  	float testEndSeconds;
     2.7 +	float runtime;
     2.8  	int testResult = 0;
     2.9  	int runResult = 0;
    2.10  	Uint32 totalTestFailedCount = 0;
    2.11 @@ -450,14 +451,16 @@
    2.12  
    2.13  			// Take time - test end
    2.14  			testEndSeconds = GetClock();
    2.15 +			runtime = testEndSeconds - testStartSeconds;
    2.16 +			if (runtime < 0.0f) runtime = 0.0f;
    2.17  
    2.18  			if (testIterations > 1) {
    2.19          			// Log test runtime
    2.20 -	        		SDLTest_Log("Runtime of %i iterations: %.1f sec", testIterations, testEndSeconds - testStartSeconds);
    2.21 -	        		SDLTest_Log("Test runtime: %.5f sec", (testEndSeconds - testStartSeconds) / (float)testIterations);
    2.22 +	        		SDLTest_Log("Runtime of %i iterations: %.1f sec", testIterations, runtime);
    2.23 +	        		SDLTest_Log("Test runtime: %.5f sec", runtime / (float)testIterations);
    2.24                          } else {
    2.25          			// Log test runtime
    2.26 -	        		SDLTest_Log("Test runtime: %.1f sec", testEndSeconds - testStartSeconds);
    2.27 +	        		SDLTest_Log("Test runtime: %.1f sec", runtime);
    2.28                          }
    2.29  
    2.30  			// Log final test result
    2.31 @@ -476,9 +479,11 @@
    2.32  
    2.33  		// Take time - suite end
    2.34  		suiteEndSeconds = GetClock();
    2.35 +		runtime = suiteEndSeconds - suiteStartSeconds;
    2.36 +		if (runtime < 0.0f) runtime = 0.0f;
    2.37  
    2.38  		// Log suite runtime
    2.39 -		SDLTest_Log("Suite runtime: %.1f sec", suiteEndSeconds - suiteStartSeconds);
    2.40 +		SDLTest_Log("Suite runtime: %.1f sec", runtime);
    2.41  
    2.42  		// Log summary and final Suite result
    2.43  		countSum = testPassedCount + testFailedCount + testSkippedCount;
    2.44 @@ -496,9 +501,11 @@
    2.45  
    2.46  	// Take time - run end
    2.47  	runEndSeconds = GetClock();
    2.48 +	runtime = runEndSeconds - runStartSeconds;
    2.49 +	if (runtime < 0.0f) runtime = 0.0f;
    2.50  
    2.51  	// Log total runtime
    2.52 -	SDLTest_Log("Total runtime: %.1f sec", runEndSeconds - runStartSeconds);
    2.53 +	SDLTest_Log("Total runtime: %.1f sec", runtime);
    2.54  
    2.55  	// Log summary and final run result
    2.56  	countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount;
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tests/testclipboard.c	Sun Dec 16 21:59:29 2012 -0800
     3.3 @@ -0,0 +1,182 @@
     3.4 +/**
     3.5 + * New/updated tests: aschiffler at ferzkopp dot net
     3.6 + */
     3.7 +
     3.8 +#include <stdio.h>
     3.9 +#include <string.h>
    3.10 +
    3.11 +#include "SDL.h"
    3.12 +#include "SDL_test.h"
    3.13 +
    3.14 +/* ================= Test Case Implementation ================== */
    3.15 +
    3.16 +/* Test case functions */
    3.17 +
    3.18 +/**
    3.19 + * \brief Check call to SDL_HasClipboardText
    3.20 + *
    3.21 + * \sa
    3.22 + * http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
    3.23 + */
    3.24 +int
    3.25 +clipboard_testHasClipboardText(void *arg)
    3.26 +{
    3.27 +	SDL_bool result;
    3.28 +	result = SDL_HasClipboardText();
    3.29 +	SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
    3.30 +
    3.31 +    return TEST_COMPLETED;
    3.32 +}
    3.33 +
    3.34 +/**
    3.35 + * \brief Check call to SDL_GetClipboardText
    3.36 + *
    3.37 + * \sa
    3.38 + * http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
    3.39 + */
    3.40 +int
    3.41 +clipboard_testGetClipboardText(void *arg)
    3.42 +{
    3.43 +	char *charResult;
    3.44 +	charResult = SDL_GetClipboardText();
    3.45 +	SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
    3.46 +
    3.47 +	if (charResult) SDL_free(charResult);
    3.48 +
    3.49 +    return TEST_COMPLETED;
    3.50 +}
    3.51 +
    3.52 +/**
    3.53 + * \brief Check call to SDL_SetClipboardText
    3.54 + * \sa
    3.55 + * http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
    3.56 + */
    3.57 +int
    3.58 +clipboard_testSetClipboardText(void *arg)
    3.59 +{
    3.60 +	char *textRef = SDLTest_RandomAsciiString();
    3.61 +	char *text = SDL_strdup(textRef);
    3.62 +	int result;
    3.63 +	result = SDL_SetClipboardText((const char *)text);
    3.64 +	SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
    3.65 +	SDLTest_AssertCheck(
    3.66 +		result == 0,
    3.67 +		"Validate SDL_SetClipboardText result, expected 0, got %i",
    3.68 +		result);
    3.69 +	SDLTest_AssertCheck(
    3.70 +		SDL_strcmp(textRef, text) == 0,
    3.71 +		"Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
    3.72 +		textRef, text);
    3.73 +
    3.74 +    /* Cleanup */
    3.75 +    if (textRef) SDL_free(textRef);
    3.76 +    if (text) SDL_free(text);
    3.77 +
    3.78 +   return TEST_COMPLETED;
    3.79 +}
    3.80 +
    3.81 +/**
    3.82 + * \brief End-to-end test of SDL_xyzClipboardText functions
    3.83 + * \sa
    3.84 + * http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
    3.85 + * http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
    3.86 + * http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
    3.87 + */
    3.88 +int
    3.89 +clipboard_testClipboardTextFunctions(void *arg)
    3.90 +{
    3.91 +	char *textRef = SDLTest_RandomAsciiString();
    3.92 +	char *text = SDL_strdup(textRef);
    3.93 +	SDL_bool boolResult;
    3.94 +	int intResult;
    3.95 +	char *charResult;
    3.96 +
    3.97 +	/* Clear clipboard text state */
    3.98 +	boolResult = SDL_HasClipboardText();
    3.99 +	SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
   3.100 +	if (boolResult == SDL_TRUE) {
   3.101 +        intResult = SDL_SetClipboardText((const char *)NULL);
   3.102 +		SDLTest_AssertPass("Call to DL_SetClipboardText(NULL) succeeded");
   3.103 +	    SDLTest_AssertCheck(
   3.104 +			intResult == 0,
   3.105 +			"Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
   3.106 +			intResult);
   3.107 +	    charResult = SDL_GetClipboardText();
   3.108 +		SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
   3.109 +	    boolResult = SDL_HasClipboardText();
   3.110 +		SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
   3.111 +	    SDLTest_AssertCheck(
   3.112 +            boolResult == SDL_FALSE,
   3.113 +	        "Verify SDL_HasClipboardText returned SDL_FALSE, got %s",
   3.114 +			(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
   3.115 +    }
   3.116 +
   3.117 +    /* Empty clipboard  */
   3.118 +	charResult = SDL_GetClipboardText();
   3.119 +	SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
   3.120 +	SDLTest_AssertCheck(
   3.121 +		charResult != NULL,
   3.122 +		"Verify SDL_GetClipboardText did not return NULL");
   3.123 +	SDLTest_AssertCheck(
   3.124 +		strlen(charResult) == 0,
   3.125 +		"Verify SDL_GetClipboardText returned string with length 0, got length %i",
   3.126 +		strlen(charResult));
   3.127 +    intResult = SDL_SetClipboardText((const char *)text);
   3.128 +	SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
   3.129 +	SDLTest_AssertCheck(
   3.130 +		intResult == 0,
   3.131 +		"Verify result from SDL_SetClipboardText(NULL), expected 0, got %i",
   3.132 +		intResult);
   3.133 +	SDLTest_AssertCheck(
   3.134 +		strcmp(textRef, text) == 0,
   3.135 +		"Verify SDL_SetClipboardText did not modify input string, expected '%s', got '%s'",
   3.136 +		textRef, text);
   3.137 +	boolResult = SDL_HasClipboardText();
   3.138 +	SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
   3.139 +	SDLTest_AssertCheck(
   3.140 +        boolResult == SDL_TRUE,
   3.141 +	    "Verify SDL_HasClipboardText returned SDL_TRUE, got %s",
   3.142 +		(boolResult) ? "SDL_TRUE" : "SDL_FALSE");
   3.143 +	charResult = SDL_GetClipboardText();
   3.144 +	SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
   3.145 +	SDLTest_AssertCheck(
   3.146 +		strcmp(textRef, charResult) == 0,
   3.147 +		"Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'",
   3.148 +		textRef, charResult);
   3.149 +
   3.150 +    /* Cleanup */
   3.151 +    if (textRef) SDL_free(textRef);
   3.152 +    if (text) SDL_free(text);
   3.153 +    if (charResult) SDL_free(charResult);
   3.154 +
   3.155 +   return TEST_COMPLETED;
   3.156 +}
   3.157 +
   3.158 +
   3.159 +/* ================= Test References ================== */
   3.160 +
   3.161 +/* Clipboard test cases */
   3.162 +static const SDLTest_TestCaseReference clipboardTest1 =
   3.163 +		{ (SDLTest_TestCaseFp)clipboard_testHasClipboardText, "clipboard_testHasClipboardText", "Check call to SDL_HasClipboardText", TEST_ENABLED };
   3.164 +
   3.165 +static const SDLTest_TestCaseReference clipboardTest2 =
   3.166 +		{ (SDLTest_TestCaseFp)clipboard_testGetClipboardText, "clipboard_testGetClipboardText", "Check call to SDL_GetClipboardText", TEST_ENABLED };
   3.167 +
   3.168 +static const SDLTest_TestCaseReference clipboardTest3 =
   3.169 +		{ (SDLTest_TestCaseFp)clipboard_testSetClipboardText, "clipboard_testSetClipboardText", "Check call to SDL_SetClipboardText", TEST_ENABLED };
   3.170 +
   3.171 +static const SDLTest_TestCaseReference clipboardTest4 =
   3.172 +		{ (SDLTest_TestCaseFp)clipboard_testClipboardTextFunctions, "clipboard_testClipboardTextFunctions", "End-to-end test of SDL_xyzClipboardText functions", TEST_ENABLED };
   3.173 +
   3.174 +/* Sequence of Clipboard test cases */
   3.175 +static const SDLTest_TestCaseReference *clipboardTests[] =  {
   3.176 +	&clipboardTest1, &clipboardTest2, &clipboardTest3, &clipboardTest4, NULL
   3.177 +};
   3.178 +
   3.179 +/* Clipboard test suite (global) */
   3.180 +SDLTest_TestSuiteReference clipboardTestSuite = {
   3.181 +	"Clipboard",
   3.182 +	NULL,
   3.183 +	clipboardTests,
   3.184 +	NULL
   3.185 +};
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tests/testrwops.c	Sun Dec 16 21:59:29 2012 -0800
     4.3 @@ -0,0 +1,427 @@
     4.4 +/**
     4.5 + * Automated SDL_RWops test.
     4.6 + *
     4.7 + * Original code written by Edgar Simo "bobbens"
     4.8 + * Ported by Markus Kauppila (markus.kauppila@gmail.com)
     4.9 + * Updated for SDL_test by aschiffler at ferzkopp dot net
    4.10 + *
    4.11 + * Released under Public Domain.
    4.12 + */
    4.13 +
    4.14 +/* quiet windows compiler warnings */
    4.15 +#define _CRT_SECURE_NO_WARNINGS
    4.16 +
    4.17 +#include <stdio.h>
    4.18 +
    4.19 +#include "SDL.h"
    4.20 +#include "SDL_test.h"
    4.21 +
    4.22 +/* ================= Test Case Implementation ================== */
    4.23 +
    4.24 +const char* RWopsReadTestFilename = "rwops_read";
    4.25 +const char* RWopsWriteTestFilename = "rwops_write";
    4.26 +
    4.27 +static const char RWopsHelloWorldTestString[] = "Hello World!";
    4.28 +static const char RWopsHelloWorldCompString[] = "Hello World!";
    4.29 +
    4.30 +/* Fixture */
    4.31 +
    4.32 +void
    4.33 +RWopsSetUp(void *arg)
    4.34 +{
    4.35 +	int fileLen = SDL_strlen(RWopsHelloWorldTestString);
    4.36 +	FILE *handle;
    4.37 +	int writtenLen;
    4.38 +	int result;
    4.39 +
    4.40 +	/* Clean up from previous runs (if any); ignore errors */
    4.41 +	remove(RWopsReadTestFilename);
    4.42 +	remove(RWopsWriteTestFilename);
    4.43 +
    4.44 +	/* Create a test file */
    4.45 +	handle = fopen(RWopsReadTestFilename, "w");
    4.46 +	SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsReadTestFilename);
    4.47 +    if (handle == NULL) return;
    4.48 +
    4.49 +	/* Write some known test into it */
    4.50 +	writtenLen = (int)fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
    4.51 +	SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
    4.52 +	result = fclose(handle);
    4.53 +	SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
    4.54 +
    4.55 +	SDLTest_AssertPass("Creation of test file completed");
    4.56 +}
    4.57 +
    4.58 +void
    4.59 +RWopsTearDown(void *arg)
    4.60 +{
    4.61 +	int result;
    4.62 +	
    4.63 +	/* Remove the created files to clean up; ignore errors for write filename */
    4.64 +	result = remove(RWopsReadTestFilename);
    4.65 +	SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsReadTestFilename, result);
    4.66 +	remove(RWopsWriteTestFilename);
    4.67 +
    4.68 +	SDLTest_AssertPass("Cleanup of test files completed");
    4.69 +}
    4.70 +
    4.71 +/**
    4.72 + * @brief Makes sure parameters work properly. Local helper function.
    4.73 + *
    4.74 + * \sa
    4.75 + * http://wiki.libsdl.org/moin.cgi/SDL_RWseek
    4.76 + * http://wiki.libsdl.org/moin.cgi/SDL_RWread
    4.77 + */
    4.78 +void 
    4.79 +_testGenericRWopsValidations(SDL_RWops *rw, int write)
    4.80 +{
    4.81 +   char buf[sizeof(RWopsHelloWorldTestString)];
    4.82 +   int i;
    4.83 +   int seekPos = SDLTest_RandomIntegerInRange(4, 8);
    4.84 +
    4.85 +   /* Clear buffer */
    4.86 +   SDL_zero(buf);
    4.87 +
    4.88 +   /* Set to start. */
    4.89 +   i = SDL_RWseek(rw, 0, RW_SEEK_SET );
    4.90 +   SDLTest_AssertPass("Call to SDL_RWseek succeeded");
    4.91 +   SDLTest_AssertCheck(i == 0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);
    4.92 +
    4.93 +   /* Test write. */
    4.94 +   i = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1, 1);
    4.95 +   SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
    4.96 +   if (write) {
    4.97 +		SDLTest_AssertCheck(i == 1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", i);
    4.98 +   }
    4.99 +   else {
   4.100 +		SDLTest_AssertCheck(i <= 0, "Verify result of writing with SDL_RWwrite, expected <=0, got %i", i);
   4.101 +   }
   4.102 +
   4.103 +   /* Test seek to random position */
   4.104 +   i = SDL_RWseek( rw, seekPos, RW_SEEK_SET );
   4.105 +   SDLTest_AssertPass("Call to SDL_RWseek succeeded");
   4.106 +   SDLTest_AssertCheck(i == seekPos, "Verify seek to %i with SDL_RWseek (RW_SEEK_SET), expected %i, got %i", seekPos, seekPos, i);
   4.107 +
   4.108 +   /* Test seek back to start */
   4.109 +   i = SDL_RWseek(rw, 0, RW_SEEK_SET );
   4.110 +   SDLTest_AssertPass("Call to SDL_RWseek succeeded");
   4.111 +   SDLTest_AssertCheck(i == 0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %i", i);
   4.112 +
   4.113 +   /* Test read */
   4.114 +   i = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 );
   4.115 +   SDLTest_AssertPass("Call to SDL_RWread succeeded");
   4.116 +   SDLTest_AssertCheck(
   4.117 +	   i == (sizeof(RWopsHelloWorldTestString)-1), 
   4.118 +	   "Verify result from SDL_RWread, expected %i, got %i",
   4.119 +	   sizeof(RWopsHelloWorldTestString)-1,
   4.120 +	   i);
   4.121 +   SDLTest_AssertCheck(
   4.122 +	   SDL_memcmp(buf, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString)-1 ) == 0, 
   4.123 +	   "Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf);
   4.124 +
   4.125 +   /* More seek tests. */
   4.126 +   i = SDL_RWseek( rw, -4, RW_SEEK_CUR );
   4.127 +   SDLTest_AssertPass("Call to SDL_RWseek(...,-4,RW_SEEK_CUR) succeeded");
   4.128 +   SDLTest_AssertCheck(
   4.129 +	   i == (sizeof(RWopsHelloWorldTestString)-5), 
   4.130 +	   "Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected %i, got %i",
   4.131 +	   sizeof(RWopsHelloWorldTestString)-5,
   4.132 +	   i);
   4.133 +
   4.134 +   i = SDL_RWseek( rw, -1, RW_SEEK_END );
   4.135 +   SDLTest_AssertPass("Call to SDL_RWseek(...,-1,RW_SEEK_END) succeeded");
   4.136 +   SDLTest_AssertCheck(
   4.137 +	   i == (sizeof(RWopsHelloWorldTestString)-2), 
   4.138 +	   "Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %i",
   4.139 +	   sizeof(RWopsHelloWorldTestString)-2,
   4.140 +	   i);
   4.141 +}
   4.142 +
   4.143 +/*!
   4.144 + * Negative test for SDL_RWFromFile parameters
   4.145 + *
   4.146 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
   4.147 + *
   4.148 + */
   4.149 +int
   4.150 +rwops_testParamNegative (void)
   4.151 +{
   4.152 +   SDL_RWops *rwops;
   4.153 +
   4.154 +   /* These should all fail. */
   4.155 +   rwops = SDL_RWFromFile(NULL, NULL);
   4.156 +   SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, NULL) succeeded");
   4.157 +   SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, NULL) returns NULL");
   4.158 +
   4.159 +   rwops = SDL_RWFromFile(NULL, "ab+");
   4.160 +   SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"ab+\") succeeded");
   4.161 +   SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"ab+\") returns NULL");
   4.162 +
   4.163 +   rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
   4.164 +   SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"sldfkjsldkfj\") succeeded");
   4.165 +   SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"sldfkjsldkfj\") returns NULL");
   4.166 +
   4.167 +   rwops = SDL_RWFromFile("something", "");
   4.168 +   SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", \"\") succeeded");
   4.169 +   SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", \"\") returns NULL");
   4.170 +
   4.171 +   rwops = SDL_RWFromFile("something", NULL);
   4.172 +   SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", NULL) succeeded");
   4.173 +   SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", NULL) returns NULL");
   4.174 +
   4.175 +   return TEST_COMPLETED;
   4.176 +}
   4.177 +
   4.178 +/**
   4.179 + * @brief Tests opening from memory.
   4.180 + *
   4.181 + * \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
   4.182 + */
   4.183 +int
   4.184 +rwops_testMem (void)
   4.185 +{
   4.186 +   char mem[sizeof(RWopsHelloWorldTestString)];
   4.187 +   SDL_RWops *rw;
   4.188 +
   4.189 +   /* Clear buffer */
   4.190 +   SDL_zero(mem);
   4.191 +
   4.192 +   /* Open */
   4.193 +   rw = SDL_RWFromMem(mem, sizeof(RWopsHelloWorldTestString)-1);
   4.194 +   SDLTest_AssertPass("Call to SDL_RWFromMem() succeeded");
   4.195 +   SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromMem does not return NULL");
   4.196 +
   4.197 +   /* Bail out if NULL */
   4.198 +   if (rw == NULL) return TEST_ABORTED;
   4.199 +
   4.200 +   /* Run generic tests */
   4.201 +   _testGenericRWopsValidations(rw, 1);
   4.202 +
   4.203 +   /* Close */
   4.204 +   SDL_RWclose(rw);
   4.205 +   SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   4.206 +   SDL_FreeRW(rw);
   4.207 +   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
   4.208 +
   4.209 +   return TEST_COMPLETED;
   4.210 +}
   4.211 +
   4.212 +
   4.213 +/**
   4.214 + * @brief Tests opening from memory.
   4.215 + *
   4.216 + * \sa
   4.217 + * http://wiki.libsdl.org/moin.cgi/SDL_RWFromConstMem
   4.218 + */
   4.219 +int 
   4.220 +rwops_testConstMem (void)
   4.221 +{
   4.222 +   SDL_RWops *rw;
   4.223 +
   4.224 +   /* Open handle */
   4.225 +   rw = SDL_RWFromConstMem( RWopsHelloWorldCompString, sizeof(RWopsHelloWorldCompString)-1 );
   4.226 +   SDLTest_AssertPass("Call to SDL_RWFromConstMem() succeeded");
   4.227 +   SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL");
   4.228 +
   4.229 +   /* Bail out if NULL */
   4.230 +   if (rw == NULL) return TEST_ABORTED;
   4.231 +
   4.232 +   /* Run generic tests */
   4.233 +   _testGenericRWopsValidations( rw, 0 );
   4.234 +
   4.235 +   /* Close handle */
   4.236 +   SDL_RWclose(rw);
   4.237 +   SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   4.238 +   SDL_FreeRW( rw );
   4.239 +   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
   4.240 +
   4.241 +  return TEST_COMPLETED;
   4.242 +}
   4.243 +
   4.244 +
   4.245 +/**
   4.246 + * @brief Tests reading from file.
   4.247 + *
   4.248 + * \sa
   4.249 + * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
   4.250 + * http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
   4.251 + */
   4.252 +int
   4.253 +rwops_testFileRead(void)
   4.254 +{
   4.255 +   SDL_RWops *rw;
   4.256 +
   4.257 +   /* Read test. */
   4.258 +   rw = SDL_RWFromFile(RWopsReadTestFilename, "r");
   4.259 +   SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"r\") succeeded");
   4.260 +   SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in read mode does not return NULL");
   4.261 +
   4.262 +   // Bail out if NULL
   4.263 +   if (rw == NULL) return TEST_ABORTED;
   4.264 +
   4.265 +   /* Run generic tests */
   4.266 +   _testGenericRWopsValidations( rw, 0 );
   4.267 +
   4.268 +   /* Close handle */
   4.269 +   SDL_RWclose(rw);
   4.270 +   SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   4.271 +   SDL_FreeRW( rw );
   4.272 +   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
   4.273 +
   4.274 +   return TEST_COMPLETED;
   4.275 +}
   4.276 +
   4.277 +/**
   4.278 + * @brief Tests writing from memory.
   4.279 + *
   4.280 + * \sa
   4.281 + * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
   4.282 + * http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
   4.283 + */
   4.284 +int
   4.285 +rwops_testFileWrite(void)
   4.286 +{
   4.287 +   SDL_RWops *rw;
   4.288 +
   4.289 +   /* Write test. */
   4.290 +   rw = SDL_RWFromFile(RWopsWriteTestFilename, "w+");
   4.291 +   SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\") succeeded");
   4.292 +   SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
   4.293 +
   4.294 +   // Bail out if NULL
   4.295 +   if (rw == NULL) return TEST_ABORTED;
   4.296 +
   4.297 +   /* Run generic tests */
   4.298 +   _testGenericRWopsValidations( rw, 1 );
   4.299 +
   4.300 +   /* Close handle */
   4.301 +   SDL_RWclose(rw);
   4.302 +   SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   4.303 +   SDL_FreeRW( rw );
   4.304 +   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
   4.305 +
   4.306 +   return TEST_COMPLETED;
   4.307 +}
   4.308 +
   4.309 +
   4.310 +/**
   4.311 + * @brief Tests reading from file handle
   4.312 + *
   4.313 + * \sa
   4.314 + * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
   4.315 + * http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
   4.316 + *
   4.317 + */
   4.318 +int
   4.319 +rwops_testFPRead(void)
   4.320 +{
   4.321 +   FILE *fp;
   4.322 +   SDL_RWops *rw;
   4.323 +
   4.324 +   /* Run read tests. */
   4.325 +   fp = fopen(RWopsReadTestFilename, "r");
   4.326 +   SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in read mode is not NULL", RWopsReadTestFilename);
   4.327 +
   4.328 +   /* Bail out if NULL */
   4.329 +   if (fp == NULL) return TEST_ABORTED;
   4.330 +
   4.331 +   /* Open */
   4.332 +   rw = SDL_RWFromFP( fp, 1 );
   4.333 +   SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
   4.334 +   SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in read mode does not return NULL");
   4.335 +
   4.336 +   /* Bail out if NULL */
   4.337 +   if (rw == NULL) return TEST_ABORTED;
   4.338 +
   4.339 +   /* Run generic tests */
   4.340 +   _testGenericRWopsValidations( rw, 0 );
   4.341 +
   4.342 +   /* Close handle */
   4.343 +   SDL_RWclose(rw);
   4.344 +   SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   4.345 +   SDL_FreeRW( rw );
   4.346 +   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
   4.347 +   fclose(fp);
   4.348 +
   4.349 +   return TEST_COMPLETED;
   4.350 +}
   4.351 +
   4.352 +
   4.353 +/**
   4.354 + * @brief Tests writing to file handle
   4.355 + *
   4.356 + * \sa
   4.357 + * http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
   4.358 + * http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
   4.359 + *
   4.360 + */
   4.361 +int
   4.362 +rwops_testFPWrite(void)
   4.363 +{
   4.364 +   FILE *fp;
   4.365 +   SDL_RWops *rw;
   4.366 +
   4.367 +   /* Run write tests. */
   4.368 +   fp = fopen(RWopsWriteTestFilename, "w+");
   4.369 +   SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in write mode is not NULL", RWopsWriteTestFilename);
   4.370 +
   4.371 +   /* Bail out if NULL */
   4.372 +   if (fp == NULL) return TEST_ABORTED;
   4.373 +
   4.374 +   /* Open */
   4.375 +   rw = SDL_RWFromFP( fp, 1 );
   4.376 +   SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
   4.377 +   SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in write mode does not return NULL");
   4.378 +
   4.379 +   /* Bail out if NULL */
   4.380 +   if (rw == NULL) return TEST_ABORTED;
   4.381 +
   4.382 +   /* Run generic tests */
   4.383 +   _testGenericRWopsValidations( rw, 1 );
   4.384 +
   4.385 +   /* Close handle */
   4.386 +   SDL_RWclose(rw);
   4.387 +   SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
   4.388 +   SDL_FreeRW( rw );
   4.389 +   SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
   4.390 +   fclose(fp);
   4.391 +
   4.392 +   return TEST_COMPLETED;
   4.393 +}
   4.394 +
   4.395 +/* ================= Test References ================== */
   4.396 +
   4.397 +/* RWops test cases */
   4.398 +static const SDLTest_TestCaseReference rwopsTest1 =
   4.399 +		{ (SDLTest_TestCaseFp)rwops_testParamNegative, "rwops_testParamNegative", "Negative test for SDL_RWFromFile parameters", TEST_ENABLED };
   4.400 +
   4.401 +static const SDLTest_TestCaseReference rwopsTest2 =
   4.402 +		{ (SDLTest_TestCaseFp)rwops_testMem, "rwops_testMem", "Tests opening from memory", TEST_ENABLED };
   4.403 +
   4.404 +static const SDLTest_TestCaseReference rwopsTest3 =
   4.405 +		{ (SDLTest_TestCaseFp)rwops_testConstMem, "rwops_testConstMem", "Tests opening from (const) memory", TEST_ENABLED };
   4.406 +
   4.407 +static const SDLTest_TestCaseReference rwopsTest4 =
   4.408 +		{ (SDLTest_TestCaseFp)rwops_testFileRead, "rwops_testFileRead", "Tests reading from a file", TEST_ENABLED };
   4.409 +
   4.410 +static const SDLTest_TestCaseReference rwopsTest5 =
   4.411 +		{ (SDLTest_TestCaseFp)rwops_testFileWrite, "rwops_testFileWrite", "Test writing to a file", TEST_ENABLED };
   4.412 +
   4.413 +static const SDLTest_TestCaseReference rwopsTest6 =
   4.414 +		{ (SDLTest_TestCaseFp)rwops_testFPRead, "rwops_testFPRead", "Test reading from file pointer", TEST_ENABLED };
   4.415 +
   4.416 +static const SDLTest_TestCaseReference rwopsTest7 =
   4.417 +		{ (SDLTest_TestCaseFp)rwops_testFPWrite, "rwops_testFPWrite", "Test writing to file pointer", TEST_ENABLED };
   4.418 +
   4.419 +/* Sequence of RWops test cases */
   4.420 +static const SDLTest_TestCaseReference *rwopsTests[] =  {
   4.421 +	&rwopsTest1, &rwopsTest2, &rwopsTest3, &rwopsTest4, &rwopsTest5, &rwopsTest6, &rwopsTest7, NULL
   4.422 +};
   4.423 +
   4.424 +/* RWops test suite (global) */
   4.425 +SDLTest_TestSuiteReference rwopsTestSuite = {
   4.426 +	"RWops",
   4.427 +	RWopsSetUp,
   4.428 +	rwopsTests,
   4.429 +	RWopsTearDown
   4.430 +};
     5.1 --- a/test/tests/testsuites.h	Sun Dec 16 14:46:16 2012 -0500
     5.2 +++ b/test/tests/testsuites.h	Sun Dec 16 21:59:29 2012 -0800
     5.3 @@ -10,13 +10,13 @@
     5.4  
     5.5  // Test collections
     5.6  //extern SDLTest_TestSuiteReference audioTestSuite;
     5.7 -//extern SDLTest_TestSuiteReference clipboardTestSuite;
     5.8 +extern SDLTest_TestSuiteReference clipboardTestSuite;
     5.9  //extern SDLTest_TestSuiteReference eventsTestSuite;
    5.10  //extern SDLTest_TestSuiteReference keyboardTestSuite;
    5.11  extern SDLTest_TestSuiteReference platformTestSuite;
    5.12  extern SDLTest_TestSuiteReference rectTestSuite;
    5.13  //extern SDLTest_TestSuiteReference renderTestSuite;
    5.14 -//extern SDLTest_TestSuiteReference rwopsTestSuite;
    5.15 +extern SDLTest_TestSuiteReference rwopsTestSuite;
    5.16  //extern SDLTest_TestSuiteReference surfaceTestSuite;
    5.17  //extern SDLTest_TestSuiteReference syswmTestSuite;
    5.18  //extern SDLTest_TestSuiteReference videoTestSuite;
    5.19 @@ -24,13 +24,13 @@
    5.20  // All test suites
    5.21  SDLTest_TestSuiteReference *testSuites[] =  {
    5.22  //	&audioTestSuite,
    5.23 -//	&clipboardTestSuite,
    5.24 +	&clipboardTestSuite,
    5.25  //	&eventsTestSuite,
    5.26  //	&keyboardTestSuite,
    5.27  	&platformTestSuite,
    5.28  	&rectTestSuite,
    5.29  //	&renderTestSuite,
    5.30 -//	&rwopsTestSuite,
    5.31 +	&rwopsTestSuite,
    5.32  //	&surfaceTestSuite,
    5.33  //	&syswmTestSuite,
    5.34  //	&videoTestSuite,