Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Better output.
Browse files Browse the repository at this point in the history
Newline handling.
rwops test handles ConstMem, FP and File.
  • Loading branch information
bobbens committed Jun 20, 2009
1 parent ea12d6a commit b540c03
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 80 deletions.
10 changes: 5 additions & 5 deletions test/automated/Makefile
@@ -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
Expand All @@ -15,10 +15,10 @@ TESTS_ALL := rwops
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)
10 changes: 5 additions & 5 deletions test/automated/SDL_at.c
Expand Up @@ -71,7 +71,7 @@ int SDL_ATfinish( int verbose )
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",
Expand All @@ -94,12 +94,12 @@ void SDL_ATbegin( const char *testcase )
{
/* 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;
}
Expand All @@ -112,7 +112,7 @@ static void SDL_ATendWith( int success )
{
/* Make sure initialized. */
if (at_test_msg == NULL) {
SDL_ATprint("Ended testcase without initializing.");
SDL_ATprint("Ended testcase without initializing.\n");
return;
}

Expand All @@ -134,7 +134,7 @@ int SDL_ATassert( const char *msg, int condition )
{
/* 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;
Expand Down
70 changes: 0 additions & 70 deletions test/automated/rwops.c

This file was deleted.

1 change: 1 addition & 0 deletions test/automated/rwops/read
@@ -0,0 +1 @@
Hello World!
200 changes: 200 additions & 0 deletions test/automated/rwops/rwops.c
@@ -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);
}

0 comments on commit b540c03

Please sign in to comment.