Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Better output.
Newline handling.
rwops test handles ConstMem, FP and File.
  • Loading branch information
bobbens committed Jun 20, 2009
1 parent ea12d6a commit b540c0333c400495459c44afcb6da1d5e5cac42e
Showing with 211 additions and 80 deletions.
  1. +5 −5 test/automated/Makefile
  2. +5 −5 test/automated/SDL_at.c
  3. +0 −70 test/automated/rwops.c
  4. +1 −0 test/automated/rwops/read
  5. +200 −0 test/automated/rwops/rwops.c
@@ -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 @@ 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)
@@ -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",
@@ -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;
}
@@ -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;
}

@@ -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;

This file was deleted.

@@ -0,0 +1 @@
Hello World!
@@ -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.