SDL  2.0
testautomation_rwops.c File Reference
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
+ Include dependency graph for testautomation_rwops.c:

Go to the source code of this file.

Macros

#define _CRT_SECURE_NO_WARNINGS

Functions

void RWopsSetUp (void *arg)
void RWopsTearDown (void *arg)
void _testGenericRWopsValidations (SDL_RWops *rw, int write)
 Makes sure parameters work properly. Local helper function.
int rwops_testParamNegative (void)
int rwops_testMem (void)
 Tests opening from memory.
int rwops_testConstMem (void)
 Tests opening from memory.
int rwops_testFileRead (void)
 Tests reading from file.
int rwops_testFileWrite (void)
 Tests writing from file.
int rwops_testFPRead (void)
 Tests reading from file handle.
int rwops_testFPWrite (void)
 Tests writing to file handle.
int rwops_testAllocFree (void)
 Tests alloc and free RW context.
int rwops_testCompareRWFromMemWithRWFromFile (void)
 Compare memory and file reads.
int rwops_testFileWriteReadEndian (void)
 Tests writing and reading from file using endian aware functions.

Variables

const char * RWopsReadTestFilename = "rwops_read"
const char * RWopsWriteTestFilename = "rwops_write"
const char * RWopsAlphabetFilename = "rwops_alphabet"
static const char RWopsHelloWorldTestString [] = "Hello World!"
static const char RWopsHelloWorldCompString [] = "Hello World!"
static const char RWopsAlphabetString [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
static const
SDLTest_TestCaseReference 
rwopsTest1
static const
SDLTest_TestCaseReference 
rwopsTest2
static const
SDLTest_TestCaseReference 
rwopsTest3
static const
SDLTest_TestCaseReference 
rwopsTest4
static const
SDLTest_TestCaseReference 
rwopsTest5
static const
SDLTest_TestCaseReference 
rwopsTest6
static const
SDLTest_TestCaseReference 
rwopsTest7
static const
SDLTest_TestCaseReference 
rwopsTest8
static const
SDLTest_TestCaseReference 
rwopsTest9
static const
SDLTest_TestCaseReference 
rwopsTest10
static const
SDLTest_TestCaseReference
rwopsTests []
SDLTest_TestSuiteReference rwopsTestSuite

Macro Definition Documentation

#define _CRT_SECURE_NO_WARNINGS

Automated SDL_RWops test.

Original code written by Edgar Simo "bobbens" Ported by Markus Kauppila (marku.nosp@m.s.ka.nosp@m.uppil.nosp@m.a@gm.nosp@m.ail.c.nosp@m.om) Updated and extended for SDL_test by aschiffler at ferzkopp dot net

Released under Public Domain.

Definition at line 13 of file testautomation_rwops.c.

Function Documentation

void _testGenericRWopsValidations ( SDL_RWops rw,
int  write 
)

Makes sure parameters work properly. Local helper function.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_RWseek http://wiki.libsdl.org/moin.cgi/SDL_RWread

Definition at line 95 of file testautomation_rwops.c.

References i, RW_SEEK_CUR, RW_SEEK_END, RW_SEEK_SET, RWopsHelloWorldTestString, SDL_memcmp, SDL_PRIs64, SDL_RWread, SDL_RWseek, SDL_RWwrite, SDL_zero, SDLTest_AssertCheck(), SDLTest_AssertPass(), and SDLTest_RandomIntegerInRange().

Referenced by rwops_testConstMem(), rwops_testFileRead(), rwops_testFileWrite(), rwops_testFPRead(), rwops_testFPWrite(), and rwops_testMem().

{
size_t s;
int seekPos = SDLTest_RandomIntegerInRange(4, 8);
/* Clear buffer */
/* Set to start. */
i = SDL_RWseek(rw, 0, RW_SEEK_SET );
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %"SDL_PRIs64, i);
/* Test write. */
SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
if (write) {
SDLTest_AssertCheck(s == (size_t)1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", (int) s);
}
else {
SDLTest_AssertCheck(s == (size_t)0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", (int) s);
}
/* Test seek to random position */
i = SDL_RWseek( rw, seekPos, RW_SEEK_SET );
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)seekPos, "Verify seek to %i with SDL_RWseek (RW_SEEK_SET), expected %i, got %"SDL_PRIs64, seekPos, seekPos, i);
/* Test seek back to start */
i = SDL_RWseek(rw, 0, RW_SEEK_SET );
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (RW_SEEK_SET), expected 0, got %"SDL_PRIs64, i);
/* Test read */
s = SDL_RWread( rw, buf, 1, sizeof(RWopsHelloWorldTestString)-1 );
SDLTest_AssertPass("Call to SDL_RWread succeeded");
s == (size_t)(sizeof(RWopsHelloWorldTestString)-1),
"Verify result from SDL_RWread, expected %i, got %i",
(int) (sizeof(RWopsHelloWorldTestString)-1),
(int) s);
"Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf);
/* More seek tests. */
i = SDL_RWseek( rw, -4, RW_SEEK_CUR );
SDLTest_AssertPass("Call to SDL_RWseek(...,-4,RW_SEEK_CUR) succeeded");
i == (Sint64)(sizeof(RWopsHelloWorldTestString)-5),
"Verify seek to -4 with SDL_RWseek (RW_SEEK_CUR), expected %i, got %i",
(int) (sizeof(RWopsHelloWorldTestString)-5),
(int) i);
i = SDL_RWseek( rw, -1, RW_SEEK_END );
SDLTest_AssertPass("Call to SDL_RWseek(...,-1,RW_SEEK_END) succeeded");
i == (Sint64)(sizeof(RWopsHelloWorldTestString)-2),
"Verify seek to -1 with SDL_RWseek (RW_SEEK_END), expected %i, got %i",
(int) (sizeof(RWopsHelloWorldTestString)-2),
(int) i);
/* Invalid whence seek */
i = SDL_RWseek( rw, 0, 999 );
SDLTest_AssertPass("Call to SDL_RWseek(...,0,invalid_whence) succeeded");
i == (Sint64)(-1),
"Verify seek with SDL_RWseek (invalid_whence); expected: -1, got %i",
(int) i);
}
int rwops_testAllocFree ( void  )

Tests alloc and free RW context.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_AllocRW
http://wiki.libsdl.org/moin.cgi/SDL_FreeRW

Definition at line 491 of file testautomation_rwops.c.

References NULL, SDL_AllocRW, SDL_FreeRW, SDL_RWOPS_UNKNOWN, SDLTest_AssertCheck(), SDLTest_AssertPass(), TEST_ABORTED, TEST_COMPLETED, and SDL_RWops::type.

{
/* Allocate context */
SDLTest_AssertPass("Call to SDL_AllocRW() succeeded");
SDLTest_AssertCheck(rw != NULL, "Validate result from SDL_AllocRW() is not NULL");
if (rw==NULL) return TEST_ABORTED;
/* Check type */
"Verify RWops type is SDL_RWOPS_UNKNOWN; expected: %d, got: %d", SDL_RWOPS_UNKNOWN, rw->type);
/* Free context again */
SDLTest_AssertPass("Call to SDL_FreeRW() succeeded");
}
int rwops_testCompareRWFromMemWithRWFromFile ( void  )

Compare memory and file reads.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile

Definition at line 518 of file testautomation_rwops.c.

References RWopsAlphabetFilename, RWopsAlphabetString, SDL_RWclose, SDL_RWFromFile, SDL_RWFromMem, SDL_RWread, SDL_RWseek, SDL_strncmp, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

{
int slen = 26;
char buffer_file[27];
char buffer_mem[27];
size_t rv_file;
size_t rv_mem;
Uint64 sv_file;
Uint64 sv_mem;
SDL_RWops* rwops_file;
SDL_RWops* rwops_mem;
int size;
int result;
for (size=5; size<10; size++)
{
/* Terminate buffer */
buffer_file[slen] = 0;
buffer_mem[slen] = 0;
/* Read/seek from memory */
rwops_mem = SDL_RWFromMem((void *)RWopsAlphabetString, slen);
SDLTest_AssertPass("Call to SDL_RWFromMem()");
rv_mem = SDL_RWread(rwops_mem, buffer_mem, size, 6);
SDLTest_AssertPass("Call to SDL_RWread(mem, size=%d)", size);
sv_mem = SDL_RWseek(rwops_mem, 0, SEEK_END);
SDLTest_AssertPass("Call to SDL_RWseek(mem,SEEK_END)");
result = SDL_RWclose(rwops_mem);
SDLTest_AssertPass("Call to SDL_RWclose(mem)");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
/* Read/see from file */
SDLTest_AssertPass("Call to SDL_RWFromFile()");
rv_file = SDL_RWread(rwops_file, buffer_file, size, 6);
SDLTest_AssertPass("Call to SDL_RWread(file, size=%d)", size);
sv_file = SDL_RWseek(rwops_file, 0, SEEK_END);
SDLTest_AssertPass("Call to SDL_RWseek(file,SEEK_END)");
result = SDL_RWclose(rwops_file);
SDLTest_AssertPass("Call to SDL_RWclose(file)");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
/* Compare */
SDLTest_AssertCheck(rv_mem == rv_file, "Verify returned read blocks matches for mem and file reads; got: rv_mem=%d rv_file=%d", (int) rv_mem, (int) rv_file);
SDLTest_AssertCheck(sv_mem == sv_file, "Verify SEEK_END position matches for mem and file seeks; got: sv_mem=%d sv_file=%d", (int) sv_mem, (int) sv_file);
SDLTest_AssertCheck(buffer_mem[slen] == 0, "Verify mem buffer termination; expected: 0, got: %d", buffer_mem[slen]);
SDLTest_AssertCheck(buffer_file[slen] == 0, "Verify file buffer termination; expected: 0, got: %d", buffer_file[slen]);
SDL_strncmp(buffer_mem, RWopsAlphabetString, slen) == 0,
"Verify mem buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_mem);
SDL_strncmp(buffer_file, RWopsAlphabetString, slen) == 0,
"Verify file buffer contain alphabet string; expected: %s, got: %s", RWopsAlphabetString, buffer_file);
}
}
int rwops_testConstMem ( void  )

Tests opening from memory.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_RWFromConstMem http://wiki.libsdl.org/moin.cgi/SDL_RWClose

Definition at line 262 of file testautomation_rwops.c.

References _testGenericRWopsValidations(), NULL, RWopsHelloWorldCompString, SDL_RWclose, SDL_RWFromConstMem, SDL_RWOPS_MEMORY_RO, SDLTest_AssertCheck(), SDLTest_AssertPass(), TEST_ABORTED, TEST_COMPLETED, and SDL_RWops::type.

{
SDL_RWops *rw;
int result;
/* Open handle */
SDLTest_AssertPass("Call to SDL_RWFromConstMem() succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromConstMem does not return NULL");
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
/* Check type */
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY_RO, "Verify RWops type is SDL_RWOPS_MEMORY_RO; expected: %d, got: %d", SDL_RWOPS_MEMORY_RO, rw->type);
/* Run generic tests */
/* Close handle */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
}
int rwops_testFileRead ( void  )

Tests reading from file.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile http://wiki.libsdl.org/moin.cgi/SDL_RWClose

Definition at line 298 of file testautomation_rwops.c.

References _testGenericRWopsValidations(), NULL, RWopsReadTestFilename, SDL_RWclose, SDL_RWFromFile, SDL_RWOPS_JNIFILE, SDL_RWOPS_STDFILE, SDL_RWOPS_WINFILE, SDLTest_AssertCheck(), SDLTest_AssertPass(), TEST_ABORTED, TEST_COMPLETED, and SDL_RWops::type.

{
SDL_RWops *rw;
int result;
/* Read test. */
SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"r\") succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in read mode does not return NULL");
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
/* Check type */
#if defined(__ANDROID__)
"Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type);
#elif defined(__WIN32__)
"Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type);
#else
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
#endif
/* Run generic tests */
/* Close handle */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
}
int rwops_testFileWrite ( void  )

Tests writing from file.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile http://wiki.libsdl.org/moin.cgi/SDL_RWClose

Definition at line 345 of file testautomation_rwops.c.

References _testGenericRWopsValidations(), NULL, RWopsWriteTestFilename, SDL_RWclose, SDL_RWFromFile, SDL_RWOPS_JNIFILE, SDL_RWOPS_STDFILE, SDL_RWOPS_WINFILE, SDLTest_AssertCheck(), SDLTest_AssertPass(), TEST_ABORTED, TEST_COMPLETED, and SDL_RWops::type.

{
SDL_RWops *rw;
int result;
/* Write test. */
SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\") succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
/* Check type */
#if defined(__ANDROID__)
"Verify RWops type is SDL_RWOPS_STDFILE or SDL_RWOPS_JNIFILE; expected: %d|%d, got: %d", SDL_RWOPS_STDFILE, SDL_RWOPS_JNIFILE, rw->type);
#elif defined(__WIN32__)
"Verify RWops type is SDL_RWOPS_WINFILE; expected: %d, got: %d", SDL_RWOPS_WINFILE, rw->type);
#else
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
#endif
/* Run generic tests */
/* Close handle */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
}
int rwops_testFileWriteReadEndian ( void  )

Tests writing and reading from file using endian aware functions.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile http://wiki.libsdl.org/moin.cgi/SDL_RWClose http://wiki.libsdl.org/moin.cgi/SDL_ReadBE16 http://wiki.libsdl.org/moin.cgi/SDL_WriteBE16

Definition at line 587 of file testautomation_rwops.c.

References NULL, RW_SEEK_SET, RWopsWriteTestFilename, SDL_PRIu64, SDL_ReadBE16, SDL_ReadBE32, SDL_ReadBE64, SDL_ReadLE16, SDL_ReadLE32, SDL_ReadLE64, SDL_RWclose, SDL_RWFromFile, SDL_RWseek, SDL_WriteBE16, SDL_WriteBE32, SDL_WriteBE64, SDL_WriteLE16, SDL_WriteLE32, SDL_WriteLE64, SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_Log(), SDLTest_RandomUint16(), SDLTest_RandomUint32(), SDLTest_RandomUint64(), TEST_ABORTED, and TEST_COMPLETED.

{
SDL_RWops *rw;
int mode;
size_t objectsWritten;
Uint16 BE16value;
Uint32 BE32value;
Uint64 BE64value;
Uint16 LE16value;
Uint32 LE32value;
Uint64 LE64value;
Uint16 BE16test;
Uint32 BE32test;
Uint64 BE64test;
Uint16 LE16test;
Uint32 LE32test;
Uint64 LE64test;
int cresult;
for (mode = 0; mode < 3; mode++) {
/* Create test data */
switch (mode) {
case 0:
SDLTest_Log("All 0 values");
BE16value = 0;
BE32value = 0;
BE64value = 0;
LE16value = 0;
LE32value = 0;
LE64value = 0;
break;
case 1:
SDLTest_Log("All 1 values");
BE16value = 1;
BE32value = 1;
BE64value = 1;
LE16value = 1;
LE32value = 1;
LE64value = 1;
break;
case 2:
SDLTest_Log("Random values");
BE16value = SDLTest_RandomUint16();
BE32value = SDLTest_RandomUint32();
BE64value = SDLTest_RandomUint64();
LE16value = SDLTest_RandomUint16();
LE32value = SDLTest_RandomUint32();
LE64value = SDLTest_RandomUint64();
break;
}
/* Write test. */
SDLTest_AssertPass("Call to SDL_RWFromFile(..,\"w+\")");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFile in write mode does not return NULL");
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
/* Write test data */
objectsWritten = SDL_WriteBE16(rw, BE16value);
SDLTest_AssertPass("Call to SDL_WriteBE16()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
objectsWritten = SDL_WriteBE32(rw, BE32value);
SDLTest_AssertPass("Call to SDL_WriteBE32()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
objectsWritten = SDL_WriteBE64(rw, BE64value);
SDLTest_AssertPass("Call to SDL_WriteBE64()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
objectsWritten = SDL_WriteLE16(rw, LE16value);
SDLTest_AssertPass("Call to SDL_WriteLE16()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
objectsWritten = SDL_WriteLE32(rw, LE32value);
SDLTest_AssertPass("Call to SDL_WriteLE32()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
objectsWritten = SDL_WriteLE64(rw, LE64value);
SDLTest_AssertPass("Call to SDL_WriteLE64()");
SDLTest_AssertCheck(objectsWritten == 1, "Validate number of objects written, expected: 1, got: %i", (int) objectsWritten);
/* Test seek to start */
result = SDL_RWseek( rw, 0, RW_SEEK_SET );
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(result == 0, "Verify result from position 0 with SDL_RWseek, expected 0, got %i", (int) result);
/* Read test data */
BE16test = SDL_ReadBE16(rw);
SDLTest_AssertPass("Call to SDL_ReadBE16()");
SDLTest_AssertCheck(BE16test == BE16value, "Validate return value from SDL_ReadBE16, expected: %hu, got: %hu", BE16value, BE16test);
BE32test = SDL_ReadBE32(rw);
SDLTest_AssertPass("Call to SDL_ReadBE32()");
SDLTest_AssertCheck(BE32test == BE32value, "Validate return value from SDL_ReadBE32, expected: %u, got: %u", BE32value, BE32test);
BE64test = SDL_ReadBE64(rw);
SDLTest_AssertPass("Call to SDL_ReadBE64()");
SDLTest_AssertCheck(BE64test == BE64value, "Validate return value from SDL_ReadBE64, expected: %"SDL_PRIu64", got: %"SDL_PRIu64, BE64value, BE64test);
LE16test = SDL_ReadLE16(rw);
SDLTest_AssertPass("Call to SDL_ReadLE16()");
SDLTest_AssertCheck(LE16test == LE16value, "Validate return value from SDL_ReadLE16, expected: %hu, got: %hu", LE16value, LE16test);
LE32test = SDL_ReadLE32(rw);
SDLTest_AssertPass("Call to SDL_ReadLE32()");
SDLTest_AssertCheck(LE32test == LE32value, "Validate return value from SDL_ReadLE32, expected: %u, got: %u", LE32value, LE32test);
LE64test = SDL_ReadLE64(rw);
SDLTest_AssertPass("Call to SDL_ReadLE64()");
SDLTest_AssertCheck(LE64test == LE64value, "Validate return value from SDL_ReadLE64, expected: %"SDL_PRIu64", got: %"SDL_PRIu64, LE64value, LE64test);
/* Close handle */
cresult = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(cresult == 0, "Verify result value is 0; got: %d", cresult);
}
}
int rwops_testFPRead ( void  )

Tests reading from file handle.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP http://wiki.libsdl.org/moin.cgi/SDL_RWClose

Definition at line 394 of file testautomation_rwops.c.

References _testGenericRWopsValidations(), NULL, RWopsReadTestFilename, SDL_RWclose, SDL_RWFromFP, SDL_RWOPS_STDFILE, SDL_TRUE, SDLTest_AssertCheck(), SDLTest_AssertPass(), TEST_ABORTED, TEST_COMPLETED, and SDL_RWops::type.

{
FILE *fp;
SDL_RWops *rw;
int result;
/* Run read tests. */
fp = fopen(RWopsReadTestFilename, "r");
SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in read mode is not NULL", RWopsReadTestFilename);
/* Bail out if NULL */
if (fp == NULL) return TEST_ABORTED;
/* Open */
rw = SDL_RWFromFP( fp, SDL_TRUE );
SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in read mode does not return NULL");
/* Bail out if NULL */
if (rw == NULL) {
fclose(fp);
return TEST_ABORTED;
}
/* Check type */
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
/* Run generic tests */
/* Close handle - does fclose() */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
}
int rwops_testFPWrite ( void  )

Tests writing to file handle.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP http://wiki.libsdl.org/moin.cgi/SDL_RWClose

Definition at line 444 of file testautomation_rwops.c.

References _testGenericRWopsValidations(), NULL, RWopsWriteTestFilename, SDL_RWclose, SDL_RWFromFP, SDL_RWOPS_STDFILE, SDL_TRUE, SDLTest_AssertCheck(), SDLTest_AssertPass(), TEST_ABORTED, TEST_COMPLETED, and SDL_RWops::type.

{
FILE *fp;
SDL_RWops *rw;
int result;
/* Run write tests. */
fp = fopen(RWopsWriteTestFilename, "w+");
SDLTest_AssertCheck(fp != NULL, "Verify handle from opening file '%s' in write mode is not NULL", RWopsWriteTestFilename);
/* Bail out if NULL */
if (fp == NULL) return TEST_ABORTED;
/* Open */
rw = SDL_RWFromFP( fp, SDL_TRUE );
SDLTest_AssertPass("Call to SDL_RWFromFP() succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening file with SDL_RWFromFP in write mode does not return NULL");
/* Bail out if NULL */
if (rw == NULL) {
fclose(fp);
return TEST_ABORTED;
}
/* Check type */
"Verify RWops type is SDL_RWOPS_STDFILE; expected: %d, got: %d", SDL_RWOPS_STDFILE, rw->type);
/* Run generic tests */
/* Close handle - does fclose() */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
}
int rwops_testMem ( void  )

Tests opening from memory.

See Also
http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
http://wiki.libsdl.org/moin.cgi/SDL_RWClose

Definition at line 222 of file testautomation_rwops.c.

References _testGenericRWopsValidations(), NULL, RWopsHelloWorldTestString, SDL_RWclose, SDL_RWFromMem, SDL_RWOPS_MEMORY, SDL_zero, SDLTest_AssertCheck(), SDLTest_AssertPass(), TEST_ABORTED, and TEST_COMPLETED.

{
char mem[sizeof(RWopsHelloWorldTestString)];
SDL_RWops *rw;
int result;
/* Clear buffer */
SDL_zero(mem);
/* Open */
SDLTest_AssertPass("Call to SDL_RWFromMem() succeeded");
SDLTest_AssertCheck(rw != NULL, "Verify opening memory with SDL_RWFromMem does not return NULL");
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
/* Check type */
SDLTest_AssertCheck(rw->type == SDL_RWOPS_MEMORY, "Verify RWops type is SDL_RWOPS_MEMORY; expected: %d, got: %d", SDL_RWOPS_MEMORY, rw->type);
/* Run generic tests */
/* Close */
result = SDL_RWclose(rw);
SDLTest_AssertPass("Call to SDL_RWclose() succeeded");
SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result);
}
int rwops_testParamNegative ( void  )

Definition at line 175 of file testautomation_rwops.c.

References NULL, RWopsAlphabetString, SDL_RWFromConstMem, SDL_RWFromFile, SDL_RWFromMem, SDLTest_AssertCheck(), SDLTest_AssertPass(), and TEST_COMPLETED.

{
SDL_RWops *rwops;
/* These should all fail. */
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, NULL) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, NULL) returns NULL");
rwops = SDL_RWFromFile(NULL, "ab+");
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"ab+\") succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"ab+\") returns NULL");
rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
SDLTest_AssertPass("Call to SDL_RWFromFile(NULL, \"sldfkjsldkfj\") succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(NULL, \"sldfkjsldkfj\") returns NULL");
rwops = SDL_RWFromFile("something", "");
SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", \"\") succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", \"\") returns NULL");
rwops = SDL_RWFromFile("something", NULL);
SDLTest_AssertPass("Call to SDL_RWFromFile(\"something\", NULL) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromFile(\"something\", NULL) returns NULL");
rwops = SDL_RWFromMem((void *)NULL, 10);
SDLTest_AssertPass("Call to SDL_RWFromMem(NULL, 10) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(NULL, 10) returns NULL");
rwops = SDL_RWFromMem((void *)RWopsAlphabetString, 0);
SDLTest_AssertPass("Call to SDL_RWFromMem(data, 0) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromMem(data, 0) returns NULL");
rwops = SDL_RWFromConstMem((const void *)RWopsAlphabetString, 0);
SDLTest_AssertPass("Call to SDL_RWFromConstMem(data, 0) succeeded");
SDLTest_AssertCheck(rwops == NULL, "Verify SDL_RWFromConstMem(data, 0) returns NULL");
}
void RWopsSetUp ( void arg)

Definition at line 33 of file testautomation_rwops.c.

References NULL, RWopsAlphabetFilename, RWopsAlphabetString, RWopsHelloWorldTestString, RWopsReadTestFilename, RWopsWriteTestFilename, SDL_strlen, SDLTest_AssertCheck(), and SDLTest_AssertPass().

{
size_t fileLen;
FILE *handle;
size_t writtenLen;
int result;
/* Clean up from previous runs (if any); ignore errors */
/* Create a test file */
handle = fopen(RWopsReadTestFilename, "w");
SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsReadTestFilename);
if (handle == NULL) return;
/* Write some known text into it */
writtenLen = fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", (int) fileLen, (int) writtenLen);
result = fclose(handle);
SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
/* Create a second test file */
handle = fopen(RWopsAlphabetFilename, "w");
SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsAlphabetFilename);
if (handle == NULL) return;
/* Write alphabet text into it */
writtenLen = fwrite(RWopsAlphabetString, 1, fileLen, handle);
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", (int) fileLen, (int) writtenLen);
result = fclose(handle);
SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
SDLTest_AssertPass("Creation of test file completed");
}
void RWopsTearDown ( void arg)

Definition at line 73 of file testautomation_rwops.c.

References RWopsAlphabetFilename, RWopsReadTestFilename, RWopsWriteTestFilename, SDLTest_AssertCheck(), and SDLTest_AssertPass().

{
int result;
/* Remove the created files to clean up; ignore errors for write filename */
result = remove(RWopsReadTestFilename);
SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsReadTestFilename, result);
result = remove(RWopsAlphabetFilename);
SDLTest_AssertCheck(result == 0, "Verify result from remove(%s), expected 0, got %i", RWopsAlphabetFilename, result);
SDLTest_AssertPass("Cleanup of test files completed");
}

Variable Documentation

const char* RWopsAlphabetFilename = "rwops_alphabet"
const char RWopsAlphabetString[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
static
const char RWopsHelloWorldCompString[] = "Hello World!"
static

Definition at line 27 of file testautomation_rwops.c.

Referenced by rwops_testConstMem().

const char RWopsHelloWorldTestString[] = "Hello World!"
static

Definition at line 26 of file testautomation_rwops.c.

Referenced by _testGenericRWopsValidations(), rwops_testMem(), and RWopsSetUp().

const char* RWopsReadTestFilename = "rwops_read"
const SDLTest_TestCaseReference rwopsTest1
static
Initial value:
{ (SDLTest_TestCaseFp)rwops_testParamNegative, "rwops_testParamNegative", "Negative test for SDL_RWFromFile parameters", TEST_ENABLED }

Definition at line 706 of file testautomation_rwops.c.

const SDLTest_TestCaseReference rwopsTest10
static
Initial value:
{ (SDLTest_TestCaseFp)rwops_testCompareRWFromMemWithRWFromFile, "rwops_testCompareRWFromMemWithRWFromFile", "Compare RWFromMem and RWFromFile RWops for read and seek", TEST_ENABLED }

Definition at line 733 of file testautomation_rwops.c.

const SDLTest_TestCaseReference rwopsTest2
static
Initial value:
{ (SDLTest_TestCaseFp)rwops_testMem, "rwops_testMem", "Tests opening from memory", TEST_ENABLED }

Definition at line 709 of file testautomation_rwops.c.

const SDLTest_TestCaseReference rwopsTest3
static
Initial value:
{ (SDLTest_TestCaseFp)rwops_testConstMem, "rwops_testConstMem", "Tests opening from (const) memory", TEST_ENABLED }

Definition at line 712 of file testautomation_rwops.c.

const SDLTest_TestCaseReference rwopsTest4
static
Initial value:
{ (SDLTest_TestCaseFp)rwops_testFileRead, "rwops_testFileRead", "Tests reading from a file", TEST_ENABLED }

Definition at line 715 of file testautomation_rwops.c.

const SDLTest_TestCaseReference rwopsTest5
static
Initial value:
{ (SDLTest_TestCaseFp)rwops_testFileWrite, "rwops_testFileWrite", "Test writing to a file", TEST_ENABLED }

Definition at line 718 of file testautomation_rwops.c.

const SDLTest_TestCaseReference rwopsTest6
static
Initial value:
{ (SDLTest_TestCaseFp)rwops_testFPRead, "rwops_testFPRead", "Test reading from file pointer", TEST_ENABLED }

Definition at line 721 of file testautomation_rwops.c.

const SDLTest_TestCaseReference rwopsTest7
static
Initial value:
{ (SDLTest_TestCaseFp)rwops_testFPWrite, "rwops_testFPWrite", "Test writing to file pointer", TEST_ENABLED }

Definition at line 724 of file testautomation_rwops.c.

const SDLTest_TestCaseReference rwopsTest8
static
Initial value:
{ (SDLTest_TestCaseFp)rwops_testAllocFree, "rwops_testAllocFree", "Test alloc and free of RW context", TEST_ENABLED }

Definition at line 727 of file testautomation_rwops.c.

const SDLTest_TestCaseReference rwopsTest9
static
Initial value:
{ (SDLTest_TestCaseFp)rwops_testFileWriteReadEndian, "rwops_testFileWriteReadEndian", "Test writing and reading via the Endian aware functions", TEST_ENABLED }

Definition at line 730 of file testautomation_rwops.c.

const SDLTest_TestCaseReference* rwopsTests[]
static
Initial value:

Definition at line 743 of file testautomation_rwops.c.

const char* RWopsWriteTestFilename = "rwops_write"