Commit 0b31b507 authored by Sam Lantinga's avatar Sam Lantinga

Merged Edgar's code changes from Google Summer of Code 2009

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403789
parent 3a95fba4
...@@ -196,7 +196,10 @@ SDL_StopEventThread(void) ...@@ -196,7 +196,10 @@ SDL_StopEventThread(void)
SDL_DestroyMutex(SDL_EventLock.lock); SDL_DestroyMutex(SDL_EventLock.lock);
} }
#ifndef IPOD #ifndef IPOD
SDL_DestroyMutex(SDL_EventQ.lock); if (SDL_EventQ.lock) {
SDL_DestroyMutex(SDL_EventQ.lock);
SDL_EventQ.lock = NULL;
}
#endif #endif
} }
......
CFLAGS := -W -Wall -Wextra -g -I. `sdl-config --cflags`
LDFLAGS := `sdl-config --libs`
# If it doesn't pick up defaults
#CFLAGS := -I. -D_GNU_SOURCE=1 -D_REENTRANT -I/usr/local/include/SDL
#LDFLAGS := -lm -ldl -lesd -lpthread
SRC := testsdl.c \
rwops/rwops.c \
platform/platform.c \
surface/surface.c \
render/render.c \
audio/audio.c
COMMON_SRC := SDL_at.c common/common.c
COMMON_INCLUDE := SDL_at.h
TESTS_ALL := testsdl \
rwops/rwops \
platform/platform \
surface/surface \
render/render \
audio/audio
.PHONY: all clean test
all: $(TESTS_ALL)
test: all
@./testsdl
testsdl: $(SRC) $(COMMON_SRC)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(SRC) $(COMMON_SRC)
rwops/rwops: rwops/rwops.c $(COMMON_INCLUDE) $(COMMON_SRC)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ rwops/rwops.c $(COMMON_SRC) -DTEST_STANDALONE
platform/platform: platform/platform.c $(COMMON_INCLUDE) $(COMMON_SRC)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ platform/platform.c $(COMMON_SRC) -DTEST_STANDALONE
surface/surface: surface/surface.c $(COMMON_INCLUDE) $(COMMON_SRC)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ surface/surface.c $(COMMON_SRC) -DTEST_STANDALONE
render/render: render/render.c $(COMMON_INCLUDE) $(COMMON_SRC)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ render/render.c $(COMMON_SRC) -DTEST_STANDALONE
audio/audio: audio/audio.c $(COMMON_INCLUDE) $(COMMON_SRC)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ audio/audio.c $(COMMON_SRC) -DTEST_STANDALONE
clean:
$(RM) $(TESTS_ALL)
SDL Automated Testing Framework User Documentation
by Edgar Simo Serra
Abstract
The SDL Automated Testing Framework, hereby after called SDL_AT, is a meant
to test the SDL code for regressions and other possible failures. It can also
be used to display what your SDL set up supports.
Basics
The main way to use the framework is to compile it and run it, that can be
done with the following command:
$> make test
It should then display something like:
Platform : All tests successful (2)
SDL_RWops : All tests successful (5)
SDL_Surface : All tests successful (6)
Rendering with x11 driver : All tests successful (4)
Indicating that all tests were successful. If however a test fails output it
will report the failure to stderr indicating where and why it happened. This
output can then be sent to the developers so they can attempt to fix the
problem.
Advanced
By passing the "-h" or "--help" parameter to testsdl you can get an overview
of all the possible options you can set to furthur tweak the testing. A sample
of the options would be the following:
Usage: ./testsdl [OPTIONS]
Options are:
-m, --manual enables tests that require user interaction
--noplatform do not run the platform tests
--norwops do not run the rwops tests
--nosurface do not run the surface tests
--norender do not run the render tests
-v, --verbose increases verbosity level by 1 for each -v
-q, --quiet only displays errors
-h, --help display this message and exit
Developers
See SDL_at.h for developer information.
/*
* Common code for automated test suite.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#include "SDL_at.h"
#include <stdio.h> /* printf/fprintf */
#include <stdarg.h> /* va_list */
#include <string.h> /* strdup */
#include <stdlib.h> /* free */
/*
* Internal usage SDL_AT variables.
*/
static char *at_suite_msg = NULL; /**< Testsuite message. */
static char *at_test_msg = NULL; /**< Testcase message. */
static int at_success = 0; /**< Number of successful testcases. */
static int at_failure = 0; /**< Number of failed testcases. */
/*
* Global properties.
*/
static int at_verbose = 0; /**< Verbosity. */
static int at_quiet = 0; /**< Quietness. */
/*
* Prototypes.
*/
static void SDL_ATcleanup (void);
static void SDL_ATendWith( int success );
static void SDL_ATassertFailed( const char *msg );
/**
* @brief Cleans up the automated testsuite state.
*/
static void SDL_ATcleanup (void)
{
if (at_suite_msg != NULL)
free(at_suite_msg);
at_suite_msg = NULL;
if (at_test_msg != NULL)
free(at_test_msg);
at_test_msg = NULL;
at_success = 0;
at_failure = 0;
}
/**
* @brief Begin testsuite.
*/
void SDL_ATinit( const char *suite )
{
/* Do not open twice. */
if (at_suite_msg) {
SDL_ATprintErr( "AT suite '%s' not closed before opening suite '%s'\n",
at_suite_msg, suite );
}
/* Must have a name. */
if (suite == NULL) {
SDL_ATprintErr( "AT testsuite does not have a name.\n");
}
SDL_ATcleanup();
at_suite_msg = strdup(suite);
/* Verbose message. */
SDL_ATprintVerbose( 2, "--+---> Started Test Suite '%s'\n", at_suite_msg );
}
/**
* @brief Finish testsuite.
*/
int SDL_ATfinish (void)
{
int failed;
/* Make sure initialized. */
if (at_suite_msg == NULL) {
SDL_ATprintErr("Ended testcase without initializing.\n");
return 1;
}
/* Finished without closing testcase. */
if (at_test_msg) {
SDL_ATprintErr( "AT suite '%s' finished without closing testcase '%s'\n",
at_suite_msg, at_test_msg );
}
/* Verbose message. */
SDL_ATprintVerbose( 2, "<-+---- Finished Test Suite '%s'\n", at_suite_msg );
/* Display message if verbose on failed. */
failed = at_failure;
if (at_failure > 0) {
SDL_ATprintErr( "%s : Failed %d out of %d testcases!\n",
at_suite_msg, at_failure, at_failure+at_success );
}
else {
SDL_ATprint( "%s : All tests successful (%d)\n",
at_suite_msg, at_success );
}
/* Clean up. */
SDL_ATcleanup();
/* Return failed. */
return failed;
}
/**
* @brief Sets a property.
*/
void SDL_ATseti( int property, int value )
{
switch (property) {
case SDL_AT_VERBOSE:
at_verbose = value;
break;
case SDL_AT_QUIET:
at_quiet = value;
break;
}
}
/**
* @brief Gets a property.
*/
void SDL_ATgeti( int property, int *value )
{
switch (property) {
case SDL_AT_VERBOSE:
*value = at_verbose;
break;
case SDL_AT_QUIET:
*value = at_quiet;
break;
}
}
/**
* @brief Begin testcase.
*/
void SDL_ATbegin( const char *testcase )
{
/* Do not open twice. */
if (at_test_msg) {
SDL_ATprintErr( "AT testcase '%s' not closed before opening testcase '%s'\n",
at_test_msg, testcase );
}
/* Must have a name. */
if (testcase == NULL) {
SDL_ATprintErr( "AT testcase does not have a name.\n");
}
at_test_msg = strdup(testcase);
/* Verbose message. */
SDL_ATprintVerbose( 2, " +---> StartedTest Case '%s'\n", testcase );
}
/**
* @brief Ends the testcase with a succes or failure.
*/
static void SDL_ATendWith( int success )
{
/* Make sure initialized. */
if (at_test_msg == NULL) {
SDL_ATprintErr("Ended testcase without initializing.\n");
return;
}
/* Mark as success or failure. */
if (success)
at_success++;
else
at_failure++;
/* Verbose message. */
SDL_ATprintVerbose( 2, " +---- Finished Test Case '%s'\n", at_test_msg );
/* Clean up. */
if (at_test_msg != NULL)
free(at_test_msg);
at_test_msg = NULL;
}
/**
* @brief Display failed assert message.
*/
static void SDL_ATassertFailed( const char *msg )
{
/* Print. */
SDL_ATprintErr( "Assert Failed!\n" );
SDL_ATprintErr( " %s\n", msg );
SDL_ATprintErr( " Test Case '%s'\n", at_test_msg );
SDL_ATprintErr( " Test Suite '%s'\n", at_suite_msg );
/* End. */
SDL_ATendWith(0);
}
/**
* @brief Testcase test.
*/
int SDL_ATassert( const char *msg, int condition )
{
/* Condition failed. */
if (!condition) {
/* Failed message. */
SDL_ATassertFailed(msg);
}
return !condition;
}
/**
* @brief Testcase test.
*/
int SDL_ATvassert( int condition, const char *msg, ... )
{
va_list args;
char buf[256];
/* Condition failed. */
if (!condition) {
/* Get message. */
va_start( args, msg );
vsnprintf( buf, sizeof(buf), msg, args );
va_end( args );
/* Failed message. */
SDL_ATassertFailed( buf );
}
return !condition;
}
/**
* @brief End testcase.
*/
void SDL_ATend (void)
{
SDL_ATendWith(1);
}
/**
* @brief Displays an error.
*/
int SDL_ATprintErr( const char *msg, ... )
{
va_list ap;
int ret;
/* Make sure there is something to print. */
if (msg == NULL)
return 0;
else {
va_start(ap, msg);
ret = vfprintf( stderr, msg, ap );
va_end(ap);
}
return ret;
}
/**
* @brief Displays a verbose message.
*/
int SDL_ATprintVerbose( int level, const char *msg, ... )
{
va_list ap;
int ret;
/* Only print if not quiet. */
if (at_quiet || (at_verbose < level))
return 0;
/* Make sure there is something to print. */
if (msg == NULL)
return 0;
else {
va_start(ap, msg);
ret = vfprintf( stdout, msg, ap );
va_end(ap);
}
return ret;
}
/*
* Common code for automated test suite.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
/**
* @file SDL_at.h
*
* @brief Handles automatic testing functionality.
*
* The basic approach with SDL_AT is to divide the tests into what are called
* test suites and test cases. Each test suite should have multiple test
* cases, each test case can have multiple asserts.
*
* To actually test for conditions within the testcase you check asserts, if
* the asserts fail the failures will be logged in the testsuite and
* displayed.
*
* Syntax is similar to OpenGL. An example would be:
*
* @code
* int f; // Number failed
* SDL_ATinit( "My testsuite" );
*
* SDL_ATbegin( "My first testcase" );
* if (!SDL_ATassert( (1+1)==2, "Trying '1+1=2'."))
* return; // Implicitly calls SDL_ATend if assert fails
* SDL_ATend(); // Finish testcase
*
* SDL_ATbegin( "My second testcase" );
* if (!SDL_ATassert( (4/2)==2, "Trying '4/2=2'."))
* return; // Implicitly calls SDL_ATend if assert fails
* SDL_ATend(); // Finish testcase
*
* f = SDL_ATfinish();
* @endcode
*
* @author Edgar Simo "bobbens"
*/
#ifndef _SDL_AT_H
# define _SDL_AT_H
enum {
SDL_AT_VERBOSE, /**< Sets the verbose level. */
SDL_AT_QUIET /**< Sets quietness. */
};
/*
* Suite level actions.
*/
/**
* @brief Starts the testsuite.
*
* @param suite Name of the suite to start testing.
*/
void SDL_ATinit( const char *suite );
/**
* @brief Finishes the testsuite printing out global results if verbose.
*
* @return 0 if no errors occurred, otherwise number of failures.
*/
int SDL_ATfinish (void);
/**
* @brief Sets a global property value.
*
* @param property Property to set.
* @param value Value to set property to.
*/
void SDL_ATseti( int property, int value );
/**
* @brief Gets a global property value.
*
* @param property Property to get.
* @param[out] value Value of the property.
*/
void SDL_ATgeti( int property, int *value );
/*
* Testcase level actions.
*/
/**
* @brief Begins a testcase.
*
* @param testcase Name of the testcase to begin.
*/
void SDL_ATbegin( const char *testcase );
/**
* @brief Checks a condition in the testcase.
*
* Will automatically call SDL_ATend if the condition isn't met.
*
* @param condition Condition to make sure is true.
* @param msg Message to display for failure.
* @return Returns 1 if the condition isn't met.
*/
int SDL_ATassert( const char *msg, int condition );
/**
* @brief Checks a condition in the testcase.
*
* Will automatically call SDL_ATend if the condition isn't met.
*
* @param condition Condition to make sure is true.
* @param msg Message to display for failure with printf style formatting.
* @return Returns 1 if the condition isn't met.
*/
int SDL_ATvassert( int condition, const char *msg, ... );
/**
* @brief Ends a testcase.
*/
void SDL_ATend (void);
/*
* Misc functions.
*/
/**
* @brief Prints an error.
*
* @param msg printf formatted string to display.
* @return Number of character printed.
*/
int SDL_ATprintErr( const char *msg, ... );
/**
* @brief Prints some text.
*
* @param msg printf formatted string to display.
* @return Number of character printed.
*/
#define SDL_ATprint(msg, args...) \
SDL_ATprintVerbose( 0, msg, ## args)
/**
* @brief Prints some verbose text.
*
* Verbosity levels are as follows:
*
* - 0 standard stdout, enabled by default
* - 1 additional information
* - 2 detailed information (spammy)
*
* @param level Level of verbosity to print at.
* @param msg printf formatted string to display.
* @return Number of character printed.
*/
int SDL_ATprintVerbose( int level, const char *msg, ... );
#endif /* _SDL_AT_H */
/**
* Automated SDL_RWops test.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#include "SDL.h"
#include "SDL_at.h"
/**
* @brief Prints available devices.
*/
static int audio_printDevices( int iscapture )
{
int i, n;
/* Get number of devices. */
n = SDL_GetNumAudioDevices(iscapture);
SDL_ATprintVerbose( 1, "%d %s Audio Devices\n",
n, iscapture ? "Capture" : "Output" );
/* List devices. */
for (i=0; i<n; i++) {
SDL_ATprintVerbose( 1, " %d) %s\n", i+1, SDL_GetAudioDeviceName( i, iscapture ) );
}
return 0;
}
/**
* @brief Makes sure parameters work properly.
*/
static void audio_testOpen (void)
{
int i, n;
int ret;
/* Begin testcase. */
SDL_ATbegin( "Audio Open" );
/* List drivers. */
n = SDL_GetNumAudioDrivers();
SDL_ATprintVerbose( 1, "%d Audio Drivers\n", n );
for (i=0; i<n; i++) {
SDL_ATprintVerbose( 1, " %s\n", SDL_GetAudioDriver(i) );
}
/* Start SDL. */
ret = SDL_Init( SDL_INIT_AUDIO );
if (SDL_ATvassert( ret==0, "SDL_Init( SDL_INIT_AUDIO ): %s", SDL_GetError()))
return;
/* Print devices. */
SDL_ATprintVerbose( 1, "Using Audio Driver '%s'\n", SDL_GetCurrentAudioDriver() );
audio_printDevices(0);
audio_printDevices(1);
/* Quit SDL. */
SDL_Quit();
/* End testcase. */
SDL_ATend();
}
/**
* @brief Entry point.
*/
#ifdef TEST_STANDALONE
int main( int argc, const char *argv[] )
{
(void) argc;
(void) argv;
#else /* TEST_STANDALONE */
int test_audio (void)
{
#endif /* TEST_STANDALONE */
SDL_ATinit( "SDL_Audio" );
audio_testOpen();
return SDL_ATfinish();
}
/**
* Part of SDL test suite.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#ifndef _TEST_AUDIO
# define _TEST_AUDIO
int test_audio (void);
#endif /* _TEST_AUDIO */
/**
* Automated SDL_Surface test.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#include "SDL.h"
#include "SDL_at.h"
#include "common/common.h"
/**
* @brief Compares a surface and a surface image for equality.
*/
int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img )
{
int ret;
int i,j;
int bpp;
Uint8 *p, *pd;
/* Make sure size is the same. */
if ((sur->w != img->width) || (sur->h != img->height))
return -1;
SDL_LockSurface( sur );
ret = 0;
bpp = sur->format->BytesPerPixel;
/* Compare image - should be same format. */
for (j=0; j<sur->h; j++) {
for (i=0; i<sur->w; i++) {
p = (Uint8 *)sur->pixels + j * sur->pitch + i * bpp;
pd = (Uint8 *)img->pixel_data + (j*img->width + i) * img->bytes_per_pixel;
switch (bpp) {
case 1:
case 2:
case 3:
ret += 1;
printf("%d BPP not supported yet.\n",bpp);
break;
case 4:
ret += !( (p[0] == pd[0]) &&
(p[1] == pd[1]) &&
(p[2] == pd[2]) );
break;
}
}
}
SDL_UnlockSurface( sur );
return ret;
}
/**
* Automated SDL test common framework.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#ifndef COMMON_H
# define COMMON_H
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
# define RMASK 0xff000000 /**< Red bit mask. */
# define GMASK 0x00ff0000 /**< Green bit mask. */
# define BMASK 0x0000ff00 /**< Blue bit mask. */
# define AMASK 0x000000ff /**< Alpha bit mask. */
#else
# define RMASK 0x000000ff /**< Red bit mask. */
# define GMASK 0x0000ff00 /**< Green bit mask. */
# define BMASK 0x00ff0000 /**< Blue bit mask. */
# define AMASK 0xff000000 /**< Alpha bit mask. */
#endif
typedef struct SurfaceImage_s {
int width;
int height;
unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */
const unsigned char pixel_data[];
} SurfaceImage_t;
/**
* @brief Compares a surface and a surface image for equality.
*
* @param sur Surface to compare.
* @param img Image to compare against.
* @return 0 if they are the same, -1 on error and positive if different.
*/
int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img );
#endif /* COMMON_H */
#ifndef IMAGES_H
# define IMAGES_H
#include "common/common.h"
/*
* Pull in images for testcases.
*/
#include "common/img_primitives.c"
#include "common/img_primitivesblend.c"
#include "common/img_face.c"
#include "common/img_blit.c"
#include "common/img_blitblend.c"
#endif /* IMAGES_H */
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/**
* Automated SDL platform test.
*
* Based off of testplatform.c.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#include "SDL.h"
#include "SDL_at.h"
#include "SDL_endian.h"
#include "SDL_cpuinfo.h"
/*
* Prototypes.
*/
static int plat_testSize( size_t sizeoftype, size_t hardcodetype );
static void plat_testTypes (void);
/**
* @brief Test size.
*
* @note Watcom C flags these as Warning 201: "Unreachable code" if you just
* compare them directly, so we push it through a function to keep the
* compiler quiet. --ryan.
*/
static int plat_testSize( size_t sizeoftype, size_t hardcodetype )
{
return sizeoftype != hardcodetype;
}
/**
* @brief Tests type size.
*/
static void plat_testTypes (void)
{
int ret;
SDL_ATbegin( "Type size" );
ret = plat_testSize( sizeof(Uint8), 1 );
if (SDL_ATvassert( ret == 0, "sizeof(Uint8) = %ul instead of 1", sizeof(Uint8) ))
return;
ret = plat_testSize( sizeof(Uint16), 2 );
if (SDL_ATvassert( ret == 0, "sizeof(Uint16) = %ul instead of 2", sizeof(Uint16) ))
return;
ret = plat_testSize( sizeof(Uint32), 4 );
if (SDL_ATvassert( ret == 0, "sizeof(Uint32) = %ul instead of 4", sizeof(Uint32) ))
return;
#ifdef SDL_HAS_64BIT_TYPE
ret = plat_testSize( sizeof(Uint64), 8 );
if (SDL_ATvassert( ret == 0, "sizeof(Uint64) = %ul instead of 8", sizeof(Uint64) ))
return;
#endif /* SDL_HAS_64BIT_TYPE */
SDL_ATend();
}
/**
* @brief Tests platform endianness.
*/
static void plat_testEndian (void)
{
Uint16 value = 0x1234;
int real_byteorder;
Uint16 value16 = 0xCDAB;
Uint16 swapped16 = 0xABCD;
Uint32 value32 = 0xEFBEADDE;
Uint32 swapped32 = 0xDEADBEEF;
#ifdef SDL_HAS_64BIT_TYPE
Uint64 value64, swapped64;
value64 = 0xEFBEADDE;
value64 <<= 32;
value64 |= 0xCDAB3412;
swapped64 = 0x1234ABCD;
swapped64 <<= 32;
swapped64 |= 0xDEADBEEF;
#endif
SDL_ATbegin( "Endianness" );
/* Test endianness. */
if ((*((char *) &value) >> 4) == 0x1) {
real_byteorder = SDL_BIG_ENDIAN;
} else {
real_byteorder = SDL_LIL_ENDIAN;
}
if (SDL_ATvassert( real_byteorder == SDL_BYTEORDER,
"Machine detected as %s endian but appears to be %s endian.",
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big" ))
return;
/* Test 16 swap. */
if (SDL_ATvassert( SDL_Swap16(value16) == swapped16,
"16 bit swapped incorrectly: 0x%X => 0x%X",
value16, SDL_Swap16(value16) ))
return;
/* Test 32 swap. */
if (SDL_ATvassert( SDL_Swap32(value32) == swapped32,
"32 bit swapped incorrectly: 0x%X => 0x%X",
value32, SDL_Swap32(value32) ))
return;
#ifdef SDL_HAS_64BIT_TYPE
/* Test 64 swap. */
if (SDL_ATvassert( SDL_Swap64(value64) == swapped64,
#ifdef _MSC_VER
"64 bit swapped incorrectly: 0x%I64X => 0x%I64X",
#else
"64 bit swapped incorrectly: 0x%llX => 0x%llX",
#endif
value64, SDL_Swap64(value64) ))
return;
#endif
SDL_ATend();
}
/**
* @brief Gets the name of the platform.
*/
const char *platform_getPlatform (void)
{
return
#if __AIX__
"AIX"
#elif __BEOS__
"BeOS"
#elif __BSDI__
"BSDI"
#elif __DREAMCAST__
"Dreamcast"
#elif __FREEBSD__
"FreeBSD"
#elif __HPUX__
"HP-UX"
#elif __IRIX__
"Irix"
#elif __LINUX__
"Linux"
#elif __MINT__
"Atari MiNT"
#elif __MACOS__
"MacOS Classic"
#elif __MACOSX__
"Mac OS X"
#elif __NETBSD__
"NetBSD"
#elif __OPENBSD__
"OpenBSD"
#elif __OS2__
"OS/2"
#elif __OSF__
"OSF/1"
#elif __QNXNTO__
"QNX Neutrino"
#elif __RISCOS__
"RISC OS"
#elif __SOLARIS__
"Solaris"
#elif __WIN32__
#ifdef _WIN32_WCE
"Windows CE"
#else
"Windows"
#endif
#elif __IPHONEOS__
"iPhone OS"
#else
"an unknown operating system! (see SDL_platform.h)"
#endif
;
}
/**
* @brief Platform test entrypoint.
*/
#ifdef TEST_STANDALONE
int main( int argc, const char *argv[] )
{
(void) argc;
(void) argv;
#else /* TEST_STANDALONE */
int test_platform (void)
{
#endif /* TEST_STANDALONE */
SDL_ATinit( "Platform" );
/* Debug information. */
SDL_ATprintVerbose( 1, "%s System detected\n", platform_getPlatform() );
SDL_ATprintVerbose( 1, "System is %s endian\n",
#ifdef SDL_LIL_ENDIAN
"little"
#else
"big"
#endif
);
SDL_ATprintVerbose( 1, "Available extensions:\n" );
SDL_ATprintVerbose( 1, " RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected" );
SDL_ATprintVerbose( 1, " MMX %s\n", SDL_HasMMX()? "detected" : "not detected" );
SDL_ATprintVerbose( 1, " MMX Ext %s\n", SDL_HasMMXExt()? "detected" : "not detected" );
SDL_ATprintVerbose( 1, " 3DNow %s\n", SDL_Has3DNow()? "detected" : "not detected" );
SDL_ATprintVerbose( 1, " 3DNow Ext %s\n",
SDL_Has3DNowExt()? "detected" : "not detected" );
SDL_ATprintVerbose( 1, " SSE %s\n", SDL_HasSSE()? "detected" : "not detected" );
SDL_ATprintVerbose( 1, " SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected" );
SDL_ATprintVerbose( 1, " AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected" );
plat_testTypes();
plat_testEndian();
return SDL_ATfinish();
}
/**
* Part of SDL test suite.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#ifndef _TEST_PLATFORM
# define _TEST_PLATFORM
const char *platform_getPlatform (void);
int test_platform (void);
#endif /* _TEST_PLATFORM */
This diff is collapsed.
/**
* Part of SDL test suite.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#ifndef _TEST_RENDER
# define _TEST_RENDER
int test_render (void);
#endif /* _TEST_RENDER */
Hello World!
\ No newline at end of file
/**
* Automated SDL_RWops test.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#include "SDL.h"
#include "SDL_at.h"
#define RWOPS_READ "rwops/read"
#define RWOPS_WRITE "rwops/write"
static const char hello_world[] = "Hello World!";
/**
* @brief Makes sure parameters work properly.
*/
static void rwops_testParam (void)
{
SDL_RWops *rwops;
/* Begin testcase. */
SDL_ATbegin( "RWops Parameters" );
/* These should all fail. */
rwops = SDL_RWFromFile(NULL, NULL);
if (SDL_ATassert( "SDL_RWFromFile(NULL, NULL) worked", rwops == NULL ))
return;
rwops = SDL_RWFromFile(NULL, "ab+");
if (SDL_ATassert( "SDL_RWFromFile(NULL, \"ab+\") worked", rwops == NULL ))
return;
rwops = SDL_RWFromFile(NULL, "sldfkjsldkfj");
if (SDL_ATassert( "SDL_RWFromFile(NULL, \"sldfkjsldkfj\") worked", rwops == NULL ))
return;
rwops = SDL_RWFromFile("something", "");
if (SDL_ATassert( "SDL_RWFromFile(\"something\", \"\") worked", rwops == NULL ))
return;
rwops = SDL_RWFromFile("something", NULL);
if (SDL_ATassert( "SDL_RWFromFile(\"something\", NULL) worked", rwops == NULL ))
return;
/* End testcase. */
SDL_ATend();
}
/**
* @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;
/* Set to start. */
i = SDL_RWseek( rw, 0, RW_SEEK_SET );
if (SDL_ATvassert( i == 0,
"Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d",
i, 0 ))
return 1;
/* Test write. */
i = SDL_RWwrite( rw, hello_world, sizeof(hello_world)-1, 1 );
if (write) {
if (SDL_ATassert( "Writing with SDL_RWwrite (failed to write)", i == 1 ))
return 1;
}
else {
if (SDL_ATassert( "Writing with SDL_RWwrite (wrote when shouldn't have)", i <= 0 ))
return 1;
}
/* Test seek. */
i = SDL_RWseek( rw, 6, RW_SEEK_SET );
if (SDL_ATvassert( i == 6,
"Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d",
i, 0 ))
return 1;
/* Test seek. */
i = SDL_RWseek( rw, 0, RW_SEEK_SET );
if (SDL_ATvassert( i == 0,
"Seeking with SDL_RWseek (RW_SEEK_SET): got %d, expected %d",
i, 0 ))
return 1;
/* Test read. */
i = SDL_RWread( rw, buf, 1, sizeof(hello_world)-1 );
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;
/* More seek tests. */
i = SDL_RWseek( rw, -4, RW_SEEK_CUR );
if (SDL_ATvassert( i == sizeof(hello_world)-5,
"Seeking with SDL_RWseek (RW_SEEK_CUR): got %d, expected %d",
i, sizeof(hello_world)-5 ))
return 1;
i = SDL_RWseek( rw, -1, RW_SEEK_END );
if (SDL_ATvassert( i == sizeof(hello_world)-2,
"Seeking with SDL_RWseek (RW_SEEK_END): got %d, expected %d",
i, sizeof(hello_world)-2 ))
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(hello_world)-1 );
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)-1 );
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;
/* Begin testcase. */
SDL_ATbegin( "SDL_RWFromFile" );
/* Read test. */
rw = SDL_RWFromFile( RWOPS_READ, "r" );
if (SDL_ATassert( "Opening memory with SDL_RWFromFile '"RWOPS_READ"'", rw != NULL ))
return;
if (rwops_testGeneric( rw, 0 ))
return;
SDL_FreeRW( rw );
/* Write test. */
rw = SDL_RWFromFile( RWOPS_WRITE, "w+" );
if (SDL_ATassert( "Opening memory with SDL_RWFromFile '"RWOPS_WRITE"'", rw != NULL ))
return;
if (rwops_testGeneric( rw, 1 ))
return;
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;
/* Begin testcase. */
SDL_ATbegin( "SDL_RWFromFP" );
/* Run read tests. */
fp = fopen( RWOPS_READ, "r" );
if (SDL_ATassert( "Failed to open file '"RWOPS_READ"'", fp != NULL))
return;
rw = SDL_RWFromFP( fp, 1 );
if (SDL_ATassert( "Opening memory with SDL_RWFromFP", rw != NULL ))
return;
if (rwops_testGeneric( rw, 0 ))
return;
SDL_FreeRW( rw );
/* Run write tests. */
fp = fopen( RWOPS_WRITE, "w+" );
if (SDL_ATassert( "Failed to open file '"RWOPS_WRITE"'", fp != NULL))
return;
rw = SDL_RWFromFP( fp, 1 );
if (SDL_ATassert( "Opening memory with SDL_RWFromFP", rw != NULL ))
return;
if (rwops_testGeneric( rw, 1 ))
return;
SDL_FreeRW( rw );
/* End testcase. */
SDL_ATend();
#endif /* HAVE_STDIO_H */
}
/**
* @brief Entry point.
*/
#ifdef TEST_STANDALONE
int main( int argc, const char *argv[] )
{
(void) argc;
(void) argv;
#else /* TEST_STANDALONE */
int test_rwops (void)
{
#endif /* TEST_STANDALONE */
SDL_ATinit( "SDL_RWops" );
rwops_testParam();
rwops_testMem();
rwops_testConstMem();
rwops_testFile();
rwops_testFP();
return SDL_ATfinish();
}
/**
* Part of SDL test suite.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#ifndef _TEST_RWOPS
# define _TEST_RWOPS
int test_rwops (void);
#endif /* _TEST_RWOPS */
This diff is collapsed.
/**
* Part of SDL test suite.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#ifndef _TEST_SURFACE
# define _TEST_SURFACE
int test_surface (void);
#endif /* _TEST_SURFACE */
/*
* SDL test suite framework code.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#include "SDL.h"
#include "SDL_at.h"
#include "platform/platform.h"
#include "rwops/rwops.h"
#include "surface/surface.h"
#include "render/render.h"
#include "audio/audio.h"
#include <stdio.h> /* printf */
#include <stdlib.h> /* exit */
#include <unistd.h> /* getopt */
#include <getopt.h> /* getopt_long */
#include <string.h> /* strcmp */
/*
* Tests to run.
*/
static int run_manual = 0; /**< Run manual tests. */
/* Manual. */
/* Automatic. */
static int run_platform = 1; /**< Run platform tests. */
static int run_rwops = 1; /**< Run RWops tests. */
static int run_surface = 1; /**< Run surface tests. */
static int run_render = 1; /**< Run render tests. */
static int run_audio = 1; /**< Run audio tests. */
/*
* Prototypes.
*/
static void print_usage( const char *name );
static void parse_options( int argc, char *argv[] );
/**
* @brief Displays program usage.
*/
static void print_usage( const char *name )
{
printf("Usage: %s [OPTIONS]\n", name);
printf("Options are:\n");
printf(" -m, --manual enables tests that require user interaction\n");
printf(" --noplatform do not run the platform tests\n");
printf(" --norwops do not run the rwops tests\n");
printf(" --nosurface do not run the surface tests\n");
printf(" --norender do not run the render tests\n");
printf(" --noaudio do not run the audio tests\n");
printf(" -v, --verbose increases verbosity level by 1 for each -v\n");
printf(" -q, --quiet only displays errors\n");
printf(" -h, --help display this message and exit\n");
}
/**
* @brief Handles the options.
*/
static void parse_options( int argc, char *argv[] )
{
static struct option long_options[] = {
{ "manual", no_argument, 0, 'm' },
{ "noplatform", no_argument, 0, 0 },
{ "norwops", no_argument, 0, 0 },
{ "nosurface", no_argument, 0, 0 },
{ "norender", no_argument, 0, 0 },
{ "noaudio", no_argument, 0, 0 },
{ "verbose", no_argument, 0, 'v' },
{ "quiet", no_argument, 0, 'q' },
{ "help", no_argument, 0, 'h' },
{NULL,0,0,0}
};
int option_index = 0;
int c = 0;
int i;
const char *str;
/* Iterate over options. */
while ((c = getopt_long( argc, argv,
"vqh",
long_options, &option_index)) != -1) {
/* Handle options. */
switch (c) {
case 0:
str = long_options[option_index].name;
if (strcmp(str,"noplatform")==0)
run_platform = 0;
else if (strcmp(str,"norwops")==0)
run_rwops = 0;
else if (strcmp(str,"nosurface")==0)
run_surface = 0;
else if (strcmp(str,"norender")==0)
run_render = 0;
else if (strcmp(str,"noaudio")==0)
run_audio = 0;
break;
/* Manual. */
case 'm':
run_manual = 1;
break;
/* Verbosity. */
case 'v':
SDL_ATgeti( SDL_AT_VERBOSE, &i );
SDL_ATseti( SDL_AT_VERBOSE, i+1 );
break;
/* Quiet. */
case 'q':
SDL_ATseti( SDL_AT_QUIET, 1 );
break;
/* Help. */
case 'h':
print_usage( argv[0] );
exit(EXIT_SUCCESS);
}
}
}
/**
* @brief Main entry point.
*/
int main( int argc, char *argv[] )
{
int failed;
int rev;
SDL_version ver;
/* Get options. */
parse_options( argc, argv );
/* Defaults. */
failed = 0;
/* Print some text if verbose. */
SDL_GetVersion( &ver );
rev = SDL_GetRevision();
SDL_ATprintVerbose( 1, "Running tests with SDL %d.%d.%d revision %d\n",
ver.major, ver.minor, ver.patch, rev );
/* Automatic tests. */
if (run_platform)
failed += test_platform();
if (run_rwops)
failed += test_rwops();
if (run_surface)
failed += test_surface();
if (run_render)
failed += test_render();
if (run_audio)
failed += test_audio();
/* Manual tests. */
if (run_manual) {
}
/* Display more information if failed. */
if (failed > 0) {
SDL_ATprintErr( "Tests run with SDL %d.%d.%d revision %d\n",
ver.major, ver.minor, ver.patch, rev );
SDL_ATprintErr( "System is running %s and is %s endian\n",
platform_getPlatform(),
#ifdef SDL_LIL_ENDIAN
"little"
#else
"big"
#endif
);
}
return failed;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment