# HG changeset patch # User Edgar Simo # Date 1245516418 0 # Node ID a34bab848c7e1cb3ae7fc4fe0e7d2f4628bc762e # Parent 916469fbdc295314e167717d946e029cae6edae5 Better output. Newline handling. rwops test handles ConstMem, FP and File. diff -r 916469fbdc29 -r a34bab848c7e test/automated/Makefile --- a/test/automated/Makefile Fri Jun 19 18:57:23 2009 +0000 +++ b/test/automated/Makefile Sat Jun 20 16:46:58 2009 +0000 @@ -1,12 +1,12 @@ -CFLAGS := `sdl-config --cflags` +CFLAGS := -I. `sdl-config --cflags` LDFLAGS := `sdl-config --libs` COMMON_SRC := SDL_at.c COMMON_INCLUDE := SDL_at.h -TESTS_ALL := rwops +TESTS_ALL := rwops/rwops .PHONY: all clean test @@ -15,10 +15,10 @@ all: $(TESTS_ALL) test: - @./rwops + @./rwops/rwops -rwops: rwops.c $(COMMON_INCLUDE) - $(CC) $(CFLAGS) $(LDFLAGS) -o rwops rwops.c $(COMMON_SRC) +rwops/rwops: rwops/rwops.c $(COMMON_INCLUDE) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ rwops/rwops.c $(COMMON_SRC) clean: $(RM) $(TESTS_ALL) diff -r 916469fbdc29 -r a34bab848c7e test/automated/SDL_at.c --- a/test/automated/SDL_at.c Fri Jun 19 18:57:23 2009 +0000 +++ b/test/automated/SDL_at.c Sat Jun 20 16:46:58 2009 +0000 @@ -71,7 +71,7 @@ if (verbose) { if (at_failure > 0) { SDL_ATprint( "%s : Failed %d out of %d testcases!\n", - at_suite_msg, at_failure, at_success ); + at_suite_msg, at_failure, at_failure+at_success ); } else { SDL_ATprint( "%s : All tests successful (%d)\n", @@ -94,12 +94,12 @@ { /* Do not open twice. */ if (at_test_msg) { - SDL_ATprint( "AT testcase '%s' not closed before opening testcase '%s'", + SDL_ATprint( "AT testcase '%s' not closed before opening testcase '%s'\n", at_test_msg, testcase ); } /* Must have a name. */ if (testcase == NULL) { - SDL_ATprint( "AT testcase does not have a name."); + SDL_ATprint( "AT testcase does not have a name.\n"); } at_test_msg = testcase; } @@ -112,7 +112,7 @@ { /* Make sure initialized. */ if (at_test_msg == NULL) { - SDL_ATprint("Ended testcase without initializing."); + SDL_ATprint("Ended testcase without initializing.\n"); return; } @@ -134,7 +134,7 @@ { /* Condition failed. */ if (!condition) { - SDL_ATprint( "%s [%s] : %s", at_suite_msg, at_test_msg, msg ); + SDL_ATprint( "%s [%s] : %s\n", at_suite_msg, at_test_msg, msg ); SDL_ATendWith(0); } return !condition; diff -r 916469fbdc29 -r a34bab848c7e test/automated/rwops.c --- a/test/automated/rwops.c Fri Jun 19 18:57:23 2009 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/** - * Automated SDL_RWops test. - * - * Written by Edgar Simo "bobbens" - * - * Released under Public Domain. - */ - - -#include "SDL.h" -#include "SDL_at.h" - - -static const char hello_world[] = "Hello World!"; - - -/** - * @brief Tests opening from memory. - */ -static void rwops_testMem (void) -{ - SDL_RWops *rw; - char mem[sizeof(hello_world)], buf[sizeof(hello_world)]; - int i; - - /* Begin testcase. */ - SDL_ATbegin( "SDL_RWFromMem" ); - - /* Open. */ - rw = SDL_RWFromMem( mem, sizeof(mem) ); - if (SDL_ATassert( "Opening memory with SDL_RWFromMem", rw != NULL )) - return; - - /* Test write. */ - i = SDL_RWwrite( rw, hello_world, sizeof(hello_world), 1 ); - if (SDL_ATassert( "Writing with SDL_RWwrite", i == 1 )) - return; - - /* Test seek. */ - i = SDL_RWseek( rw, 0, RW_SEEK_SET ); - if (SDL_ATassert( "Seeking with SDL_RWseek", i == 0 )) - return; - - /* Test read. */ - i = SDL_RWread( rw, buf, sizeof(hello_world), 1 ); - if (SDL_ATassert( "Reading with SDL_RWread", i == 1 )) - return; - if (SDL_ATassert( "Memory read does not match memory written", - memcmp( buf, hello_world, sizeof(hello_world) ) == 0 )) - return; - - /* Close. */ - SDL_FreeRW( rw ); - - /* End testcase. */ - SDL_ATend(); -} - - -/** - * @brief Entry point. - */ -int main( int argc, const char *argv[] ) -{ - SDL_ATinit( "SDL_RWops" ); - - rwops_testMem(); - - return SDL_ATfinish(1); -} diff -r 916469fbdc29 -r a34bab848c7e test/automated/rwops/read --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/automated/rwops/read Sat Jun 20 16:46:58 2009 +0000 @@ -0,0 +1,1 @@ +Hello World! diff -r 916469fbdc29 -r a34bab848c7e test/automated/rwops/rwops.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/automated/rwops/rwops.c Sat Jun 20 16:46:58 2009 +0000 @@ -0,0 +1,200 @@ +/** + * Automated SDL_RWops test. + * + * Written by Edgar Simo "bobbens" + * + * Released under Public Domain. + */ + + +#include "SDL.h" +#include "SDL_at.h" + + +static const char hello_world[] = "Hello World!"; + + +/** + * @brief Does a generic rwops test. + * + * RWops should have "Hello World!" in it already if write is disabled. + * + * @param write Test writing also. + * @return 1 if an assert is failed. + */ +static int rwops_testGeneric( SDL_RWops *rw, int write ) +{ + char buf[sizeof(hello_world)]; + int i; + + if (write) { + /* Test write. */ + i = SDL_RWwrite( rw, hello_world, sizeof(hello_world)-1, 1 ); + if (SDL_ATassert( "Writing with SDL_RWwrite", i == 1 )) + return 1; + } + + /* Test seek. */ + i = SDL_RWseek( rw, 6, RW_SEEK_SET ); + if (SDL_ATassert( "Seeking with SDL_RWseek", i == 6 )) + return 1; + + /* Test seek. */ + i = SDL_RWseek( rw, 0, RW_SEEK_SET ); + if (SDL_ATassert( "Seeking with SDL_RWseek", i == 0 )) + return 1; + + /* Test read. */ + i = SDL_RWread( rw, buf, 1, sizeof(hello_world)-1 ); + if (i != sizeof(hello_world)-1) + printf("%s\n", SDL_GetError()); + if (SDL_ATassert( "Reading with SDL_RWread", i == sizeof(hello_world)-1 )) + return 1; + if (SDL_ATassert( "Memory read does not match memory written", + memcmp( buf, hello_world, sizeof(hello_world)-1 ) == 0 )) + return 1; + + return 0; +} + + +/** + * @brief Tests opening from memory. + */ +static void rwops_testMem (void) +{ + char mem[sizeof(hello_world)]; + SDL_RWops *rw; + + /* Begin testcase. */ + SDL_ATbegin( "SDL_RWFromMem" ); + + /* Open. */ + rw = SDL_RWFromMem( mem, sizeof(mem) ); + if (SDL_ATassert( "Opening memory with SDL_RWFromMem", rw != NULL )) + return; + + /* Run generic tests. */ + if (rwops_testGeneric( rw, 1 )) + return; + + /* Close. */ + SDL_FreeRW( rw ); + + /* End testcase. */ + SDL_ATend(); +} + + +static const char const_mem[] = "Hello World!"; +/** + * @brief Tests opening from memory. + */ +static void rwops_testConstMem (void) +{ + SDL_RWops *rw; + + /* Begin testcase. */ + SDL_ATbegin( "SDL_RWFromConstMem" ); + + /* Open. */ + rw = SDL_RWFromConstMem( const_mem, sizeof(const_mem) ); + if (SDL_ATassert( "Opening memory with SDL_RWFromConstMem", rw != NULL )) + return; + + /* Run generic tests. */ + if (rwops_testGeneric( rw, 0 )) + return; + + /* Close. */ + SDL_FreeRW( rw ); + + /* End testcase. */ + SDL_ATend(); +} + + +/** + * @brief Tests opening from memory. + */ +static void rwops_testFile (void) +{ + SDL_RWops *rw; + int i; + + /* Begin testcase. */ + SDL_ATbegin( "SDL_RWFromFile" ); + + /* Open. */ + rw = SDL_RWFromFile( "rwops/read", "r" ); + if (SDL_ATassert( "Opening memory with SDL_RWFromFile", rw != NULL )) + return; + + /* Test writing. */ + i = SDL_RWwrite( rw, hello_world, sizeof(hello_world), 1 ); + if (SDL_ATassert( "Writing with SDL_RWwrite", i == 0 )) + return; + + /* Run generic tests. */ + if (rwops_testGeneric( rw, 0 )) + return; + + /* Close. */ + SDL_FreeRW( rw ); + + /* End testcase. */ + SDL_ATend(); +} + + +/** + * @brief Tests opening from memory. + */ +static void rwops_testFP (void) +{ +#ifdef HAVE_STDIO_H + FILE *fp; + SDL_RWops *rw; + int i; + + /* Begin testcase. */ + SDL_ATbegin( "SDL_RWFromFP" ); + + /* Open. */ + fp = fopen( "rwops/write", "w+" ); + if (fp == NULL) { + SDL_ATprint("Failed to open file rwops/write"); + SDL_ATend(); + return; + } + rw = SDL_RWFromFP( fp, 1 ); + if (SDL_ATassert( "Opening memory with SDL_RWFromFP", rw != NULL )) + return; + + /* Run generic tests. */ + if (rwops_testGeneric( rw, 1 )) + return; + + /* Close. */ + SDL_FreeRW( rw ); + + /* End testcase. */ + SDL_ATend(); +#endif /* HAVE_STDIO_H */ +} + + +/** + * @brief Entry point. + */ +int main( int argc, const char *argv[] ) +{ + SDL_ATinit( "SDL_RWops" ); + + rwops_testMem(); + rwops_testConstMem(); + rwops_testFile(); + rwops_testFP(); + + return SDL_ATfinish(1); +}