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

Commit

Permalink
Browse files Browse the repository at this point in the history
Cleaned up the rwops test suite.
  • Loading branch information
mkauppila committed Aug 11, 2011
1 parent 24ce23c commit 65c6f7f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 50 deletions.
2 changes: 1 addition & 1 deletion test/test-automation/tests/testdummy/testdummy.c
Expand Up @@ -100,7 +100,7 @@ dummycase1(void *arg)

//Log(0, "uint8 (same value): %d", RandomUint8BoundaryValue(200, 200, SDL_TRUE));

for(; 01 ; )
for(; 0 ; )
printf("%d\n", RandomSint16());

for( ; 0 ; ) {
Expand Down
2 changes: 1 addition & 1 deletion test/test-automation/tests/testrwops/Makefile.am
@@ -1,4 +1,4 @@
lib_LTLIBRARIES = libtestrwops.la
libtestrwops_la_SOURCES = testrwops.c TestSupportRWops_Generic.c
libtestrwops_la_SOURCES = testrwops.c
libtestrwops_la_CLAGS = -fPIC -g
libtestrwops_la_LDFLAGS = `sdl-config --libs` -I ../../src/libSDLtest/.libs/libSDLtest.la
31 changes: 0 additions & 31 deletions test/test-automation/tests/testrwops/TestSupportRWops_Generic.c

This file was deleted.

54 changes: 37 additions & 17 deletions test/test-automation/tests/testrwops/testrwops.c
Expand Up @@ -13,12 +13,9 @@

#include "../../include/SDL_test.h"

#include "TestSupportRWops.h"

const char* RWOPS_READ = "tests/testrwops/read";
const char* RWOPS_WRITE = "tests/testrwops/write";


static const char hello_world[] = "Hello World!";
static const char const_mem[] = "Hello World!";

Expand Down Expand Up @@ -51,6 +48,11 @@ TestCaseReference **QueryTestSuite() {

/**
* @brief Makes sure parameters work properly. Helper function
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RWseek
* http://wiki.libsdl.org/moin.cgi/SDL_RWread
*
*/
int _testGeneric( SDL_RWops *rw, int write )
{
Expand All @@ -59,41 +61,45 @@ int _testGeneric( SDL_RWops *rw, int write )

/* Set to start. */
i = SDL_RWseek( rw, 0, RW_SEEK_SET );
AssertEquals(i, 0, "Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d");
AssertEquals(i, 0, "Seeking with SDL_RWseek (RW_SEEK_SET)");

/* Test write. */
i = SDL_RWwrite( rw, hello_world, sizeof(hello_world)-1, 1 );
i = SDL_RWwrite( rw, hello_world, sizeof(hello_world)-1, 1);

if (write) {
AssertEquals(i, 1, "Writing with SDL_RWwrite (failed to write)");
}
else {
AssertTrue(i <= 0, "Writing with SDL_RWwrite (wrote when shouldn't have)");
AssertTrue(i <= 0, "Writing with SDL_RWwrite (wrote when shouldn't have): %d <= 0", i);
}

/* Test seek. */
i = SDL_RWseek( rw, 6, RW_SEEK_SET );

AssertEquals(i, 6, "Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d", i, 0);
AssertEquals(i, 6, "Seeking with SDL_RWseek (RW_SEEK_SET)");

/* Test seek. */
i = SDL_RWseek( rw, 0, RW_SEEK_SET );
AssertEquals(i, 0, "Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d", i, 0);
AssertEquals(i, 0, "Seeking with SDL_RWseek (RW_SEEK_SET)");

/* Test read. */
i = SDL_RWread( rw, buf, 1, sizeof(hello_world)-1 );
AssertTrue(i == sizeof(hello_world)-1, "Reading with SDL_RWread");
AssertTrue(SDL_memcmp( buf, hello_world, sizeof(hello_world)-1 ) == 0, "Memory read does not match memory written");
AssertEquals(i, sizeof(hello_world)-1, "Reading with SDL_RWread");
AssertEquals(SDL_memcmp( buf, hello_world, sizeof(hello_world)-1 ), 0, "Memory read does not match memory written");

/* More seek tests. */
i = SDL_RWseek( rw, -4, RW_SEEK_CUR );
AssertTrue(i == sizeof(hello_world)-5, "Seeking with SDL_RWseek (RW_SEEK_CUR): got %d, expected %d");
AssertEquals(i, sizeof(hello_world)-5, "Seeking with SDL_RWseek (RW_SEEK_CUR))");

i = SDL_RWseek( rw, -1, RW_SEEK_END );
AssertTrue(i == sizeof(hello_world)-2, "Seeking with SDL_RWseek (RW_SEEK_END): got %d, expected %d", i, sizeof(hello_world)-2);
AssertEquals(i, sizeof(hello_world)-2, "Seeking with SDL_RWseek (RW_SEEK_END)");
}


/*!
* Tests rwops parameters
*
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
*/
void rwops_testParam (void)
{
SDL_RWops *rwops;
Expand Down Expand Up @@ -124,8 +130,11 @@ void rwops_testParam (void)
* @param write Test writing also.
* @return 1 if an assert is failed.
*/

/**
* @brief Tests opening from memory.
*
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
*/
void rwops_testMem (void)
{
Expand All @@ -146,6 +155,9 @@ void rwops_testMem (void)

/**
* @brief Tests opening from memory.
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromConstMem
*/
void rwops_testConstMem (void)
{
Expand All @@ -165,21 +177,25 @@ void rwops_testConstMem (void)

/**
* @brief Tests opening from memory.
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
* http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
*/
void rwops_testFile (void)
{
SDL_RWops *rw;

/* Read test. */
rw = TestSupportRWops_OpenRWopsFromReadDir( RWOPS_READ, "r" );
rw = SDL_RWFromFile(RWOPS_READ, "r");
AssertTrue(rw != NULL, "Opening memory with SDL_RWFromFile RWOPS_READ");

_testGeneric( rw, 0 );

SDL_FreeRW( rw );

/* Write test. */
rw = TestSupportRWops_OpenRWopsFromWriteDir( RWOPS_WRITE, "w+" );
rw = SDL_RWFromFile(RWOPS_WRITE, "w+");
AssertTrue(rw != NULL, "Opening memory with SDL_RWFromFile RWOPS_WRITE");

_testGeneric( rw, 1 );
Expand All @@ -190,14 +206,18 @@ void rwops_testFile (void)

/**
* @brief Tests opening from stdio
*
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
* http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
*/
void rwops_testFP (void)
{
FILE *fp;
SDL_RWops *rw;

/* Run read tests. */
fp = TestSupportRWops_OpenFPFromReadDir( RWOPS_READ, "r" );
fp = fopen(RWOPS_READ, "r");
AssertTrue(fp != NULL, "Failed to open file %s,", RWOPS_READ);

rw = SDL_RWFromFP( fp, 1 );
Expand All @@ -208,7 +228,7 @@ void rwops_testFP (void)
SDL_FreeRW( rw );

/* Run write tests. */
fp = TestSupportRWops_OpenFPFromWriteDir( RWOPS_WRITE, "w+" );
fp = fopen(RWOPS_WRITE, "w+");
AssertTrue(fp != NULL, "Failed to open file %s", RWOPS_WRITE);

rw = SDL_RWFromFP( fp, 1 );
Expand Down

0 comments on commit 65c6f7f

Please sign in to comment.