WinRT: merged with SDL 2.0.1 codebase

This commit is contained in:
David Ludwig
2013-10-27 21:26:46 -04:00
343 changed files with 12735 additions and 7248 deletions

View File

@@ -4,7 +4,7 @@ srcdir = @srcdir@
CC = @CC@
EXE = @EXE@
CFLAGS = @CFLAGS@
CFLAGS = @CFLAGS@ -g
LIBS = @LIBS@
TARGETS = \
@@ -14,6 +14,7 @@ TARGETS = \
testautomation$(EXE) \
testdraw2$(EXE) \
testdrawchessboard$(EXE) \
testdropfile$(EXE) \
testerror$(EXE) \
testfile$(EXE) \
testgamecontroller$(EXE) \
@@ -36,6 +37,7 @@ TARGETS = \
testoverlay2$(EXE) \
testplatform$(EXE) \
testpower$(EXE) \
testfilesystem$(EXE) \
testrendertarget$(EXE) \
testresample$(EXE) \
testscale$(EXE) \
@@ -107,6 +109,9 @@ testdraw2$(EXE): $(srcdir)/testdraw2.c
testdrawchessboard$(EXE): $(srcdir)/testdrawchessboard.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testdropfile$(EXE): $(srcdir)/testdropfile.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testerror$(EXE): $(srcdir)/testerror.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
@@ -123,7 +128,7 @@ testgl2$(EXE): $(srcdir)/testgl2.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLLIB@ @MATHLIB@
testgles$(EXE): $(srcdir)/testgles.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLLIB@ @MATHLIB@
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLESLIB@ @MATHLIB@
testhaptic$(EXE): $(srcdir)/testhaptic.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
@@ -180,6 +185,9 @@ testplatform$(EXE): $(srcdir)/testplatform.c
testpower$(EXE): $(srcdir)/testpower.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testfilesystem$(EXE): $(srcdir)/testfilesystem.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testrendertarget$(EXE): $(srcdir)/testrendertarget.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)

View File

@@ -117,13 +117,13 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
static void
PrintText(char *text)
{
unsigned char *spot, expanded[1024];
char *spot, expanded[1024];
expanded[0] = '\0';
for ( spot = text; *spot; ++spot )
{
size_t length = SDL_strlen(expanded);
SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", *spot);
SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot);
}
SDL_Log("Text (%s): \"%s%s\"\n", expanded, *text == '"' ? "\\" : "", text);
}
@@ -134,10 +134,13 @@ main(int argc, char *argv[])
SDL_Window *window;
SDL_Event event;
int done;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
@@ -146,7 +149,7 @@ main(int argc, char *argv[])
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
640, 480, 0);
if (!window) {
fprintf(stderr, "Couldn't create 640x480 window: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
SDL_GetError());
quit(2);
}
@@ -166,7 +169,7 @@ main(int argc, char *argv[])
switch (event.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
PrintKey(&event.key.keysym, event.key.state, event.key.repeat);
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
break;
case SDL_TEXTINPUT:
PrintText(event.text.text);

23
test/configure vendored
View File

@@ -586,6 +586,7 @@ ac_subst_vars='LTLIBOBJS
LIBOBJS
SDL_TTF_LIB
XLIB
GLESLIB
GLLIB
CPP
XMKMF
@@ -3785,16 +3786,21 @@ $as_echo "libraries $x_libraries, headers $x_includes" >&6; }
fi
if test x$have_x = xyes; then
if test x$ac_x_includes = xno || test x$ac_x_includes = x; then
if test x$ac_x_includes = xno || test "x$ac_x_includes" = xNone || test "x$ac_x_includes" = x; then
:
else
CFLAGS="$CFLAGS -I$ac_x_includes"
fi
if test x$ac_x_libraries = xno || test x$ac_x_libraries = x; then
if test x$ac_x_libraries = xno || test "x$ac_x_libraries" = xNone; then
:
else
XPATH="-L$ac_x_libraries"
XLIB="-L$ac_x_libraries -lX11"
if test "x$ac_x_libraries" = x; then
XPATH=""
XLIB="-lX11"
else
XPATH="-L$ac_x_libraries"
XLIB="-L$ac_x_libraries -lX11"
fi
fi
fi
@@ -3855,19 +3861,20 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
$as_echo "$have_opengles" >&6; }
GLLIB=""
GLESLIB=""
if test x$have_opengles = xyes; then
CFLAGS="$CFLAGS -DHAVE_OPENGLES"
GLLIB="$XPATH -lGLESv1_CM"
elif test x$have_opengl = xyes; then
GLESLIB="$XPATH -lGLESv1_CM"
fi
if test x$have_opengl = xyes; then
CFLAGS="$CFLAGS -DHAVE_OPENGL"
GLLIB="$XPATH $SYS_GL_LIBS"
else
GLLIB=""
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for TTF_Init in -lSDL2_ttf" >&5
$as_echo_n "checking for TTF_Init in -lSDL2_ttf... " >&6; }
if ${ac_cv_lib_SDL2_ttf_TTF_Init+:} false; then :

View File

@@ -91,16 +91,21 @@ LIBS="$LIBS -lSDL2_test $SDL_LIBS"
dnl Check for X11 path, needed for OpenGL on some systems
AC_PATH_X
if test x$have_x = xyes; then
if test x$ac_x_includes = xno || test x$ac_x_includes = x; then
if test x$ac_x_includes = xno || test "x$ac_x_includes" = xNone || test "x$ac_x_includes" = x; then
:
else
CFLAGS="$CFLAGS -I$ac_x_includes"
fi
if test x$ac_x_libraries = xno || test x$ac_x_libraries = x; then
if test x$ac_x_libraries = xno || test "x$ac_x_libraries" = xNone; then
:
else
XPATH="-L$ac_x_libraries"
XLIB="-L$ac_x_libraries -lX11"
if test "x$ac_x_libraries" = x; then
XPATH=""
XLIB="-lX11"
else
XPATH="-L$ac_x_libraries"
XLIB="-L$ac_x_libraries -lX11"
fi
fi
fi
@@ -131,17 +136,18 @@ have_opengles=yes
AC_MSG_RESULT($have_opengles)
GLLIB=""
GLESLIB=""
if test x$have_opengles = xyes; then
CFLAGS="$CFLAGS -DHAVE_OPENGLES"
GLLIB="$XPATH -lGLESv1_CM"
elif test x$have_opengl = xyes; then
GLESLIB="$XPATH -lGLESv1_CM"
fi
if test x$have_opengl = xyes; then
CFLAGS="$CFLAGS -DHAVE_OPENGL"
GLLIB="$XPATH $SYS_GL_LIBS"
else
GLLIB=""
fi
AC_SUBST(GLLIB)
AC_SUBST(GLESLIB)
AC_SUBST(XLIB)
dnl Check for SDL_ttf

View File

@@ -1,146 +1,144 @@
/*
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
/* Program to load a wave file and loop playing it using SDL sound */
/* loopwaves.c is much more robust in handling WAVE files --
This is only for simple WAVEs
*/
#include "SDL_config.h"
#include <stdio.h>
#include <stdlib.h>
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
#include "SDL.h"
#include "SDL_audio.h"
struct
{
SDL_AudioSpec spec;
Uint8 *sound; /* Pointer to wave data */
Uint32 soundlen; /* Length of wave data */
int soundpos; /* Current play position */
} wave;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDL_Quit();
exit(rc);
}
void SDLCALL
fillerup(void *unused, Uint8 * stream, int len)
{
Uint8 *waveptr;
int waveleft;
/* Set up the pointers */
waveptr = wave.sound + wave.soundpos;
waveleft = wave.soundlen - wave.soundpos;
/* Go! */
while (waveleft <= len) {
SDL_memcpy(stream, waveptr, waveleft);
stream += waveleft;
len -= waveleft;
waveptr = wave.sound;
waveleft = wave.soundlen;
wave.soundpos = 0;
}
SDL_memcpy(stream, waveptr, len);
wave.soundpos += len;
}
static int done = 0;
void
poked(int sig)
{
done = 1;
}
int
main(int argc, char *argv[])
{
int i;
char filename[4096];
/* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
if (argc >= 1) {
SDL_strlcpy(filename, argv[1], sizeof(filename));
} else {
SDL_strlcpy(filename, "sample.wav", sizeof(filename));
}
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
fprintf(stderr, "Couldn't load %s: %s\n", filename, SDL_GetError());
quit(1);
}
wave.spec.callback = fillerup;
#if HAVE_SIGNAL_H
/* Set the signals */
#ifdef SIGHUP
signal(SIGHUP, poked);
#endif
signal(SIGINT, poked);
#ifdef SIGQUIT
signal(SIGQUIT, poked);
#endif
signal(SIGTERM, poked);
#endif /* HAVE_SIGNAL_H */
/* Show the list of available drivers */
printf("Available audio drivers: ");
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
if (i == 0) {
printf("%s", SDL_GetAudioDriver(i));
} else {
printf(", %s", SDL_GetAudioDriver(i));
}
}
printf("\n");
/* Initialize fillerup() variables */
if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
SDL_FreeWAV(wave.sound);
quit(2);
}
printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
/* Let the audio run */
SDL_PauseAudio(0);
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
SDL_Delay(1000);
/* Clean up on signal */
SDL_CloseAudio();
SDL_FreeWAV(wave.sound);
SDL_Quit();
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */
/*
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
/* Program to load a wave file and loop playing it using SDL sound */
/* loopwaves.c is much more robust in handling WAVE files --
This is only for simple WAVEs
*/
#include "SDL_config.h"
#include <stdio.h>
#include <stdlib.h>
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
#include "SDL.h"
#include "SDL_audio.h"
struct
{
SDL_AudioSpec spec;
Uint8 *sound; /* Pointer to wave data */
Uint32 soundlen; /* Length of wave data */
int soundpos; /* Current play position */
} wave;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDL_Quit();
exit(rc);
}
void SDLCALL
fillerup(void *unused, Uint8 * stream, int len)
{
Uint8 *waveptr;
int waveleft;
/* Set up the pointers */
waveptr = wave.sound + wave.soundpos;
waveleft = wave.soundlen - wave.soundpos;
/* Go! */
while (waveleft <= len) {
SDL_memcpy(stream, waveptr, waveleft);
stream += waveleft;
len -= waveleft;
waveptr = wave.sound;
waveleft = wave.soundlen;
wave.soundpos = 0;
}
SDL_memcpy(stream, waveptr, len);
wave.soundpos += len;
}
static int done = 0;
void
poked(int sig)
{
done = 1;
}
int
main(int argc, char *argv[])
{
int i;
char filename[4096];
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
if (argc >= 1) {
SDL_strlcpy(filename, argv[1], sizeof(filename));
} else {
SDL_strlcpy(filename, "sample.wav", sizeof(filename));
}
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1], SDL_GetError());
quit(1);
}
wave.spec.callback = fillerup;
#if HAVE_SIGNAL_H
/* Set the signals */
#ifdef SIGHUP
signal(SIGHUP, poked);
#endif
signal(SIGINT, poked);
#ifdef SIGQUIT
signal(SIGQUIT, poked);
#endif
signal(SIGTERM, poked);
#endif /* HAVE_SIGNAL_H */
/* Show the list of available drivers */
SDL_Log("Available audio drivers:");
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
SDL_Log("%i: %s", i, SDL_GetAudioDriver(i));
}
/* Initialize fillerup() variables */
if (SDL_OpenAudio(&wave.spec, NULL) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
SDL_FreeWAV(wave.sound);
quit(2);
}
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
/* Let the audio run */
SDL_PauseAudio(0);
while (!done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING))
SDL_Delay(1000);
/* Clean up on signal */
SDL_CloseAudio();
SDL_FreeWAV(wave.sound);
SDL_Quit();
return (0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -45,39 +45,39 @@ void RunBasicTest()
SDL_atomic_t v;
SDL_bool tfret = SDL_FALSE;
printf("\nspin lock---------------------------------------\n\n");
SDL_Log("\nspin lock---------------------------------------\n\n");
SDL_AtomicLock(&lock);
printf("AtomicLock lock=%d\n", lock);
SDL_Log("AtomicLock lock=%d\n", lock);
SDL_AtomicUnlock(&lock);
printf("AtomicUnlock lock=%d\n", lock);
SDL_Log("AtomicUnlock lock=%d\n", lock);
printf("\natomic -----------------------------------------\n\n");
SDL_Log("\natomic -----------------------------------------\n\n");
SDL_AtomicSet(&v, 0);
tfret = SDL_AtomicSet(&v, 10) == 0;
printf("AtomicSet(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = SDL_AtomicAdd(&v, 10) == 10;
printf("AtomicAdd(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = SDL_AtomicSet(&v, 10) == 0 ? SDL_TRUE : SDL_FALSE;
SDL_Log("AtomicSet(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = SDL_AtomicAdd(&v, 10) == 10 ? SDL_TRUE : SDL_FALSE;
SDL_Log("AtomicAdd(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
SDL_AtomicSet(&v, 0);
SDL_AtomicIncRef(&v);
tfret = (SDL_AtomicGet(&v) == 1);
printf("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = (SDL_AtomicGet(&v) == 1) ? SDL_TRUE : SDL_FALSE;
SDL_Log("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
SDL_AtomicIncRef(&v);
tfret = (SDL_AtomicGet(&v) == 2);
printf("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE);
printf("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE);
printf("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = (SDL_AtomicGet(&v) == 2) ? SDL_TRUE : SDL_FALSE;
SDL_Log("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE) ? SDL_TRUE : SDL_FALSE;
SDL_Log("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE) ? SDL_TRUE : SDL_FALSE;
SDL_Log("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
SDL_AtomicSet(&v, 10);
tfret = (SDL_AtomicCAS(&v, 0, 20) == SDL_FALSE);
printf("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = (SDL_AtomicCAS(&v, 0, 20) == SDL_FALSE) ? SDL_TRUE : SDL_FALSE;
SDL_Log("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
value = SDL_AtomicGet(&v);
tfret = (SDL_AtomicCAS(&v, value, 20) == SDL_TRUE);
printf("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = (SDL_AtomicCAS(&v, value, 20) == SDL_TRUE) ? SDL_TRUE : SDL_FALSE;
SDL_Log("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
}
/**************************************************************************/
@@ -120,7 +120,7 @@ static
int adder(void* junk)
{
unsigned long N=NInter;
printf("Thread subtracting %d %lu times\n",CountInc,N);
SDL_Log("Thread subtracting %d %lu times\n",CountInc,N);
while (N--) {
SDL_AtomicAdd(&good, -CountInc);
bad-=CountInc;
@@ -152,7 +152,7 @@ void runAdder(void)
end = SDL_GetTicks();
printf("Finished in %f sec\n", (end - start) / 1000.f);
SDL_Log("Finished in %f sec\n", (end - start) / 1000.f);
}
static
@@ -161,28 +161,28 @@ void RunEpicTest()
int b;
atomicValue v;
printf("\nepic test---------------------------------------\n\n");
SDL_Log("\nepic test---------------------------------------\n\n");
printf("Size asserted to be >= 32-bit\n");
SDL_Log("Size asserted to be >= 32-bit\n");
SDL_assert(sizeof(atomicValue)>=4);
printf("Check static initializer\n");
SDL_Log("Check static initializer\n");
v=SDL_AtomicGet(&good);
SDL_assert(v==42);
SDL_assert(bad==42);
printf("Test negative values\n");
SDL_Log("Test negative values\n");
SDL_AtomicSet(&good, -5);
v=SDL_AtomicGet(&good);
SDL_assert(v==-5);
printf("Verify maximum value\n");
SDL_Log("Verify maximum value\n");
SDL_AtomicSet(&good, CountTo);
v=SDL_AtomicGet(&good);
SDL_assert(v==CountTo);
printf("Test compare and exchange\n");
SDL_Log("Test compare and exchange\n");
b=SDL_AtomicCAS(&good, 500, 43);
SDL_assert(!b); /* no swap since CountTo!=500 */
@@ -194,7 +194,7 @@ void RunEpicTest()
v=SDL_AtomicGet(&good);
SDL_assert(v==44);
printf("Test Add\n");
SDL_Log("Test Add\n");
v=SDL_AtomicAdd(&good, 1);
SDL_assert(v==44);
@@ -206,7 +206,7 @@ void RunEpicTest()
v=SDL_AtomicGet(&good);
SDL_assert(v==55);
printf("Test Add (Negative values)\n");
SDL_Log("Test Add (Negative values)\n");
v=SDL_AtomicAdd(&good, -20);
SDL_assert(v==55);
@@ -223,7 +223,7 @@ void RunEpicTest()
v=SDL_AtomicGet(&good);
SDL_assert(v==15);
printf("Reset before count down test\n");
SDL_Log("Reset before count down test\n");
SDL_AtomicSet(&good, CountTo);
v=SDL_AtomicGet(&good);
SDL_assert(v==CountTo);
@@ -231,11 +231,11 @@ void RunEpicTest()
bad=CountTo;
SDL_assert(bad==CountTo);
printf("Counting down from %d, Expect %d remaining\n",CountTo,Expect);
SDL_Log("Counting down from %d, Expect %d remaining\n",CountTo,Expect);
runAdder();
v=SDL_AtomicGet(&good);
printf("Atomic %d Non-Atomic %d\n",v,bad);
SDL_Log("Atomic %d Non-Atomic %d\n",v,bad);
SDL_assert(v==Expect);
SDL_assert(bad!=Expect);
}
@@ -429,7 +429,7 @@ static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event
} else if (delta < 0) {
/* We ran into an old queue entry, which means it still needs to be dequeued */
} else {
printf("ERROR: mutex failed!\n");
SDL_Log("ERROR: mutex failed!\n");
}
SDL_UnlockMutex(queue->mutex);
@@ -462,7 +462,7 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event)
} else if (delta < 0) {
/* We ran into an old queue entry, which means we've hit empty */
} else {
printf("ERROR: mutex failed!\n");
SDL_Log("ERROR: mutex failed!\n");
}
SDL_UnlockMutex(queue->mutex);
@@ -598,9 +598,11 @@ static void RunFIFOTest(SDL_bool lock_free)
Uint32 start, end;
int i, j;
int grand_total;
char textBuffer[1024];
int len;
printf("\nFIFO test---------------------------------------\n\n");
printf("Mode: %s\n", lock_free ? "LockFree" : "Mutex");
SDL_Log("\nFIFO test---------------------------------------\n\n");
SDL_Log("Mode: %s\n", lock_free ? "LockFree" : "Mutex");
readersDone = SDL_CreateSemaphore(0);
writersDone = SDL_CreateSemaphore(0);
@@ -622,7 +624,7 @@ static void RunFIFOTest(SDL_bool lock_free)
#endif
/* Start the readers first */
printf("Starting %d readers\n", NUM_READERS);
SDL_Log("Starting %d readers\n", NUM_READERS);
SDL_zero(readerData);
SDL_AtomicSet(&readersRunning, NUM_READERS);
for (i = 0; i < NUM_READERS; ++i) {
@@ -634,7 +636,7 @@ static void RunFIFOTest(SDL_bool lock_free)
}
/* Start up the writers */
printf("Starting %d writers\n", NUM_WRITERS);
SDL_Log("Starting %d writers\n", NUM_WRITERS);
SDL_zero(writerData);
SDL_AtomicSet(&writersRunning, NUM_WRITERS);
for (i = 0; i < NUM_WRITERS; ++i) {
@@ -668,16 +670,16 @@ static void RunFIFOTest(SDL_bool lock_free)
SDL_DestroyMutex(queue.mutex);
}
printf("Finished in %f sec\n", (end - start) / 1000.f);
SDL_Log("Finished in %f sec\n", (end - start) / 1000.f);
printf("\n");
SDL_Log("\n");
for (i = 0; i < NUM_WRITERS; ++i) {
printf("Writer %d wrote %d events, had %d waits\n", i, EVENTS_PER_WRITER, writerData[i].waits);
SDL_Log("Writer %d wrote %d events, had %d waits\n", i, EVENTS_PER_WRITER, writerData[i].waits);
}
printf("Writers wrote %d total events\n", NUM_WRITERS*EVENTS_PER_WRITER);
SDL_Log("Writers wrote %d total events\n", NUM_WRITERS*EVENTS_PER_WRITER);
/* Print a breakdown of which readers read messages from which writer */
printf("\n");
SDL_Log("\n");
grand_total = 0;
for (i = 0; i < NUM_READERS; ++i) {
int total = 0;
@@ -685,17 +687,21 @@ static void RunFIFOTest(SDL_bool lock_free)
total += readerData[i].counters[j];
}
grand_total += total;
printf("Reader %d read %d events, had %d waits\n", i, total, readerData[i].waits);
printf(" { ");
SDL_Log("Reader %d read %d events, had %d waits\n", i, total, readerData[i].waits);
SDL_snprintf(textBuffer, sizeof(textBuffer), " { ");
for (j = 0; j < NUM_WRITERS; ++j) {
if (j > 0) {
printf(", ");
len = SDL_strlen(textBuffer);
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, ", ");
}
printf("%d", readerData[i].counters[j]);
len = SDL_strlen(textBuffer);
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, "%d", readerData[i].counters[j]);
}
printf(" }\n");
len = SDL_strlen(textBuffer);
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, " }\n");
SDL_Log(textBuffer);
}
printf("Readers read %d total events\n", grand_total);
SDL_Log("Readers read %d total events\n", grand_total);
}
/* End FIFO test */
@@ -704,6 +710,9 @@ static void RunFIFOTest(SDL_bool lock_free)
int
main(int argc, char *argv[])
{
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
RunBasicTest();
RunEpicTest();
/* This test is really slow, so don't run it by default */

View File

@@ -18,18 +18,18 @@ print_devices(int iscapture)
const char *typestr = ((iscapture) ? "capture" : "output");
int n = SDL_GetNumAudioDevices(iscapture);
printf("%s devices:\n", typestr);
SDL_Log("%s devices:\n", typestr);
if (n == -1)
printf(" Driver can't detect specific %s devices.\n\n", typestr);
SDL_Log(" Driver can't detect specific %s devices.\n\n", typestr);
else if (n == 0)
printf(" No %s devices found.\n\n", typestr);
SDL_Log(" No %s devices found.\n\n", typestr);
else {
int i;
for (i = 0; i < n; i++) {
printf(" %s\n", SDL_GetAudioDeviceName(i, iscapture));
SDL_Log(" %s\n", SDL_GetAudioDeviceName(i, iscapture));
}
printf("\n");
SDL_Log("\n");
}
}
@@ -38,26 +38,29 @@ main(int argc, char **argv)
{
int n;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
/* Print available audio drivers */
n = SDL_GetNumAudioDrivers();
if (n == 0) {
printf("No built-in audio drivers\n\n");
SDL_Log("No built-in audio drivers\n\n");
} else {
int i;
printf("Built-in audio drivers:\n");
SDL_Log("Built-in audio drivers:\n");
for (i = 0; i < n; ++i) {
printf(" %s\n", SDL_GetAudioDriver(i));
SDL_Log(" %s\n", SDL_GetAudioDriver(i));
}
printf("\n");
SDL_Log("\n");
}
printf("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
SDL_Log("Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver());
print_devices(0);
print_devices(1);

View File

@@ -80,8 +80,7 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
fprintf(stderr,
"Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n",
SDL_Log("Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n",
argv[0], SDLTest_CommonUsage(state));
quit(1);
}
@@ -114,12 +113,8 @@ main(int argc, char *argv[])
}
/* Clean up */
if (userRunSeed != NULL) {
SDL_free(userRunSeed);
}
if (filter != NULL) {
SDL_free(filter);
}
SDL_free(userRunSeed);
SDL_free(filter);
/* Shutdown everything */
quit(result);

View File

@@ -77,7 +77,7 @@ int audio_initQuitAudio()
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(SDL_strlen(audioDriver) > 0, "Audio driver name is not empty; got: %s", audioDriver);
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver);
/* Call Init */
result = SDL_AudioInit(audioDriver);
@@ -134,7 +134,7 @@ int audio_initOpenCloseQuitAudio()
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_AssertCheck(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(SDL_strlen(audioDriver) > 0, "Audio driver name is not empty; got: %s", audioDriver);
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver);
/* Change specs */
for (j = 0; j < 2; j++) {
@@ -226,14 +226,14 @@ int audio_enumerateAndNameAudioDevices()
SDLTest_AssertPass("Call to SDL_GetAudioDeviceName(%i, %i)", i, t);
SDLTest_AssertCheck(name != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, t);
if (name != NULL) {
SDLTest_AssertCheck(SDL_strlen(name)>0, "verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, t, name);
SDLTest_AssertCheck(name[0] != '\0', "verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, t, name);
if (t==1) {
/* Also try non-zero type */
tt = t + SDLTest_RandomIntegerInRange(1,10);
nameAgain = SDL_GetAudioDeviceName(i, tt);
SDLTest_AssertCheck(nameAgain != NULL, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not NULL", i, tt);
if (nameAgain != NULL) {
SDLTest_AssertCheck(SDL_strlen(nameAgain)>0, "Verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, tt, nameAgain);
SDLTest_AssertCheck(nameAgain[0] != '\0', "Verify result from SDL_GetAudioDeviceName(%i, %i) is not empty, got: '%s'", i, tt, nameAgain);
SDLTest_AssertCheck(SDL_strcmp(name, nameAgain)==0,
"Verify SDL_GetAudioDeviceName(%i, %i) and SDL_GetAudioDeviceName(%i %i) return the same string",
i, t, i, tt);
@@ -318,7 +318,7 @@ int audio_printAudioDrivers()
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%i)", i);
SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
if (name != NULL) {
SDLTest_AssertCheck(SDL_strlen(name)>0, "Verify returned name is not empty, got: '%s'", name);
SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
}
}
}
@@ -339,7 +339,7 @@ int audio_printCurrentAudioDriver()
SDLTest_AssertPass("Call to SDL_GetCurrentAudioDriver()");
SDLTest_AssertCheck(name != NULL, "Verify returned name is not NULL");
if (name != NULL) {
SDLTest_AssertCheck(SDL_strlen(name)>0, "Verify returned name is not empty, got: '%s'", name);
SDLTest_AssertCheck(name[0] != '\0', "Verify returned name is not empty, got: '%s'", name);
}
return TEST_COMPLETED;
@@ -509,7 +509,7 @@ int audio_buildAudioCVTNegative()
SDLTest_AssertCheck(result == -1, "Verify result value; expected: -1, got: %i", result);
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL && SDL_strlen(error)>0, "Validate that error message was not NULL or empty");
SDLTest_AssertCheck(error != NULL && error[0] != '\0', "Validate that error message was not NULL or empty");
}
SDL_ClearError();
@@ -643,7 +643,7 @@ int audio_lockUnlockOpenAudioDevice()
SDL_Delay(10);
SDLTest_Log("Simulate callback processing - delay");
/* Unlock again*/
/* Unlock again */
SDL_UnlockAudioDevice(id);
SDLTest_AssertPass("SDL_UnlockAudioDevice(%i)", id);
@@ -747,11 +747,9 @@ int audio_convertAudio()
SDLTest_AssertCheck(cvt.len_ratio > 0.0, "Verify conversion length ratio; expected: >0; got: %f", cvt.len_ratio);
/* Free converted buffer */
if (cvt.buf != NULL) {
SDL_free(cvt.buf);
cvt.buf = NULL;
}
}
}
}
}
}

View File

@@ -41,7 +41,7 @@ clipboard_testGetClipboardText(void *arg)
charResult = SDL_GetClipboardText();
SDLTest_AssertPass("Call to SDL_GetClipboardText succeeded");
if (charResult) SDL_free(charResult);
SDL_free(charResult);
return TEST_COMPLETED;
}
@@ -69,8 +69,8 @@ clipboard_testSetClipboardText(void *arg)
textRef, text);
/* Cleanup */
if (textRef) SDL_free(textRef);
if (text) SDL_free(text);
SDL_free(textRef);
SDL_free(text);
return TEST_COMPLETED;
}
@@ -118,7 +118,7 @@ clipboard_testClipboardTextFunctions(void *arg)
charResult != NULL,
"Verify SDL_GetClipboardText did not return NULL");
SDLTest_AssertCheck(
SDL_strlen(charResult) == 0,
charResult[0] == '\0',
"Verify SDL_GetClipboardText returned string with length 0, got length %i",
SDL_strlen(charResult));
intResult = SDL_SetClipboardText((const char *)text);
@@ -145,9 +145,9 @@ clipboard_testClipboardTextFunctions(void *arg)
textRef, charResult);
/* Cleanup */
if (textRef) SDL_free(textRef);
if (text) SDL_free(text);
if (charResult) SDL_free(charResult);
SDL_free(textRef);
SDL_free(text);
SDL_free(charResult);
return TEST_COMPLETED;
}

View File

@@ -58,7 +58,7 @@ events_pushPumpAndPollUserevent(void *arg)
event1.user.data1 = (void *)&_userdataValue1;
event1.user.data2 = (void *)&_userdataValue2;
/* Push a user event onto the queue and force queue update*/
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event1);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
@@ -101,7 +101,7 @@ events_addDelEventWatch(void *arg)
SDL_AddEventWatch(_events_sampleNullEventFilter, NULL);
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
/* Push a user event onto the queue and force queue update*/
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
@@ -112,7 +112,7 @@ events_addDelEventWatch(void *arg)
SDL_DelEventWatch(_events_sampleNullEventFilter, NULL);
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Push a user event onto the queue and force queue update*/
/* Push a user event onto the queue and force queue update */
_eventFilterCalled = 0;
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
@@ -152,7 +152,7 @@ events_addDelEventWatchWithUserdata(void *arg)
SDL_AddEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
SDLTest_AssertPass("Call to SDL_AddEventWatch()");
/* Push a user event onto the queue and force queue update*/
/* Push a user event onto the queue and force queue update */
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");
SDL_PumpEvents();
@@ -163,7 +163,7 @@ events_addDelEventWatchWithUserdata(void *arg)
SDL_DelEventWatch(_events_sampleNullEventFilter, (void *)&_userdataValue);
SDLTest_AssertPass("Call to SDL_DelEventWatch()");
/* Push a user event onto the queue and force queue update*/
/* Push a user event onto the queue and force queue update */
_eventFilterCalled = 0;
SDL_PushEvent(&event);
SDLTest_AssertPass("Call to SDL_PushEvent()");

View File

@@ -1,7 +1,7 @@
/**
* Automated SDL subsystems management test.
*
* Written by J<>rgen Tjern<72> "jorgenpt"
* Written by J<>rgen Tjern<72> "jorgenpt"
*
* Released under Public Domain.
*/
@@ -10,7 +10,7 @@
#include "SDL_test.h"
/*!
/* !
* \brief Tests SDL_Init() and SDL_Quit() of Joystick and Haptic subsystems
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_Init
@@ -38,7 +38,7 @@ static int main_testInitQuitJoystickHaptic (void *arg)
#endif
}
/*!
/* !
* \brief Tests SDL_InitSubSystem() and SDL_QuitSubSystem()
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_Init
@@ -79,16 +79,16 @@ static int main_testImpliedJoystickInit (void *arg)
#else
int initialized_system;
// First initialize the controller
/* First initialize the controller */
SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
// Then make sure this implicitly initialized the joystick subsystem
/* Then make sure this implicitly initialized the joystick subsystem */
initialized_system = SDL_WasInit(joy_and_controller);
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
// Then quit the controller, and make sure that implicitly also quits the
// joystick subsystem
/* Then quit the controller, and make sure that implicitly also quits the */
/* joystick subsystem */
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
initialized_system = SDL_WasInit(joy_and_controller);
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == 0, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );
@@ -104,17 +104,17 @@ static int main_testImpliedJoystickQuit (void *arg)
#else
int initialized_system;
// First initialize the controller and the joystick (explicitly)
/* First initialize the controller and the joystick (explicitly) */
SDLTest_AssertCheck( (SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller" );
SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0, "SDL_InitSubSystem(SDL_INIT_JOYSTICK)" );
SDLTest_AssertCheck( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == 0, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER)" );
// Then make sure they're both initialized properly
/* Then make sure they're both initialized properly */
initialized_system = SDL_WasInit(joy_and_controller);
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == joy_and_controller, "SDL_WasInit() should be true for joystick & controller (%x)", initialized_system );
// Then quit the controller, and make sure that it does NOT quit the
// explicitly initialized joystick subsystem.
/* Then quit the controller, and make sure that it does NOT quit the */
/* explicitly initialized joystick subsystem. */
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
initialized_system = SDL_WasInit(joy_and_controller);
SDLTest_AssertCheck( (initialized_system & joy_and_controller) == SDL_INIT_JOYSTICK, "SDL_WasInit() should be false for joystick & controller (%x)", initialized_system );

View File

@@ -242,7 +242,7 @@ pixels_getPixelFormatName(void *arg)
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(SDL_strlen(result) > 0, "Verify result is non-empty");
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
SDLTest_AssertCheck(SDL_strcmp(result, unknownFormat) == 0,
"Verify result text; expected: %s, got %s", unknownFormat, result);
}
@@ -257,7 +257,7 @@ pixels_getPixelFormatName(void *arg)
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(SDL_strlen(result) > 0, "Verify result is non-empty");
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
SDLTest_AssertCheck(SDL_strcmp(result, _RGBPixelFormatsVerbose[i]) == 0,
"Verify result text; expected: %s, got %s", _RGBPixelFormatsVerbose[i], result);
}
@@ -273,7 +273,7 @@ pixels_getPixelFormatName(void *arg)
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(SDL_strlen(result) > 0, "Verify result is non-empty");
SDLTest_AssertCheck(result[0] != '\0', "Verify result is non-empty");
SDLTest_AssertCheck(SDL_strcmp(result, _nonRGBPixelFormatsVerbose[i]) == 0,
"Verify result text; expected: %s, got %s", _nonRGBPixelFormatsVerbose[i], result);
}
@@ -290,14 +290,14 @@ pixels_getPixelFormatName(void *arg)
SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%u)", format);
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
if (result != NULL) {
SDLTest_AssertCheck(SDL_strlen(result) > 0,
SDLTest_AssertCheck(result[0] != '\0',
"Verify result is non-empty; got: %s", result);
SDLTest_AssertCheck(SDL_strcmp(result, _invalidPixelFormatsVerbose[i]) == 0,
"Validate name is UNKNOWN, expected: '%s', got: '%s'", _invalidPixelFormatsVerbose[i], result);
}
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL && SDL_strlen(error) == 0, "Validate that error message is empty");
SDLTest_AssertCheck(error == NULL || error[0] == '\0', "Validate that error message is empty");
}
return TEST_COMPLETED;
@@ -411,7 +411,7 @@ pixels_calcGammaRamp(void *arg)
int changed;
Uint16 magic = 0xbeef;
/* Allocate temp ramp array and fill with some value*/
/* Allocate temp ramp array and fill with some value */
ramp = (Uint16 *)SDL_malloc(256 * sizeof(Uint16));
SDLTest_AssertCheck(ramp != NULL, "Validate temp ramp array could be allocated");
if (ramp == NULL) return TEST_ABORTED;

View File

@@ -102,7 +102,7 @@ int platform_testEndianessAndSwap(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_GetXYZ() functions
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_GetPlatform
@@ -151,7 +151,7 @@ int platform_testGetFunctions (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_HasXYZ() functions
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_Has3DNow
@@ -168,7 +168,7 @@ int platform_testHasFunctions (void *arg)
{
int ret;
// TODO: independently determine and compare values as well
/* TODO: independently determine and compare values as well */
ret = SDL_HasRDTSC();
SDLTest_AssertPass("SDL_HasRDTSC()");
@@ -200,7 +200,7 @@ int platform_testHasFunctions (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_GetVersion
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_GetVersion
@@ -225,7 +225,7 @@ int platform_testGetVersion(void *arg)
}
/*!
/* !
* \brief Tests SDL_VERSION macro
*/
int platform_testSDLVersion(void *arg)
@@ -248,7 +248,7 @@ int platform_testSDLVersion(void *arg)
}
/*!
/* !
* \brief Tests default SDL_Init
*/
int platform_testDefaultInit(void *arg)
@@ -270,7 +270,7 @@ int platform_testDefaultInit(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_Get/Set/ClearError
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_GetError
@@ -315,14 +315,14 @@ int platform_testGetSetClearError(void *arg)
lastError);
}
// Clean up
/* Clean up */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_SetError with empty input
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
@@ -351,14 +351,14 @@ int platform_testSetErrorEmptyInput(void *arg)
lastError);
}
// Clean up
/* Clean up */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_SetError with invalid input
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
@@ -370,11 +370,11 @@ int platform_testSetErrorInvalidInput(void *arg)
char *lastError;
int len;
// Reset
/* Reset */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
// Check for no-op
/* Check for no-op */
SDL_SetError(testError);
SDLTest_AssertPass("SDL_SetError()");
lastError = (char *)SDL_GetError();
@@ -392,11 +392,11 @@ int platform_testSetErrorInvalidInput(void *arg)
lastError);
}
// Set
/* Set */
SDL_SetError(probeError);
SDLTest_AssertPass("SDL_SetError()");
// Check for no-op
/* Check for no-op */
SDL_SetError(testError);
SDLTest_AssertPass("SDL_SetError()");
lastError = (char *)SDL_GetError();
@@ -415,14 +415,14 @@ int platform_testSetErrorInvalidInput(void *arg)
lastError);
}
// Clean up
/* Clean up */
SDL_ClearError();
SDLTest_AssertPass("SDL_ClearError()");
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_GetPowerInfo
* \sa
* http://wiki.libsdl.org/moin.cgi/SDL_GetPowerInfo
@@ -472,7 +472,7 @@ int platform_testGetPowerInfo(void *arg)
pct);
}
// Partial return value variations
/* Partial return value variations */
stateAgain = SDL_GetPowerInfo(&secsAgain, NULL);
SDLTest_AssertCheck(
state==stateAgain,

View File

@@ -12,7 +12,7 @@
/* Helper functions */
/*!
/* !
* \brief Private helper to check SDL_IntersectRectAndLine results
*/
void _validateIntersectRectAndLineResults(
@@ -39,7 +39,7 @@ void _validateIntersectRectAndLineResults(
/* Test case functions */
/*!
/* !
* \brief Tests SDL_IntersectRectAndLine() clipping cases
*
* \sa
@@ -110,7 +110,7 @@ rect_testIntersectRectAndLine (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_IntersectRectAndLine() non-clipping case line inside
*
* \sa
@@ -177,7 +177,7 @@ rect_testIntersectRectAndLineInside (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_IntersectRectAndLine() non-clipping cases outside
*
* \sa
@@ -232,7 +232,7 @@ rect_testIntersectRectAndLineOutside (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_IntersectRectAndLine() with empty rectangle
*
* \sa
@@ -267,7 +267,7 @@ rect_testIntersectRectAndLineEmpty (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Negative tests against SDL_IntersectRectAndLine() with invalid parameters
*
* \sa
@@ -302,7 +302,7 @@ rect_testIntersectRectAndLineParam (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Private helper to check SDL_HasIntersection results
*/
void _validateHasIntersectionResults(
@@ -325,7 +325,7 @@ void _validateHasIntersectionResults(
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
}
/*!
/* !
* \brief Private helper to check SDL_IntersectRect results
*/
void _validateIntersectRectResults(
@@ -344,7 +344,7 @@ void _validateIntersectRectResults(
}
}
/*!
/* !
* \brief Private helper to check SDL_UnionRect results
*/
void _validateUnionRectResults(
@@ -367,7 +367,7 @@ void _validateUnionRectResults(
expectedResult->x, expectedResult->y, expectedResult->w, expectedResult->h);
}
/*!
/* !
* \brief Private helper to check SDL_RectEmpty results
*/
void _validateRectEmptyResults(
@@ -385,7 +385,7 @@ void _validateRectEmptyResults(
refRect->x, refRect->y, refRect->w, refRect->h);
}
/*!
/* !
* \brief Private helper to check SDL_RectEquals results
*/
void _validateRectEqualsResults(
@@ -408,7 +408,7 @@ void _validateRectEqualsResults(
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
}
/*!
/* !
* \brief Tests SDL_IntersectRect() with B fully inside A
*
* \sa
@@ -423,7 +423,7 @@ int rect_testIntersectRectInside (void *arg)
SDL_Rect result;
SDL_bool intersection;
// rectB fully contained in rectA
/* rectB fully contained in rectA */
refRectB.x = 0;
refRectB.y = 0;
refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
@@ -436,7 +436,7 @@ int rect_testIntersectRectInside (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_IntersectRect() with B fully outside A
*
* \sa
@@ -451,7 +451,7 @@ int rect_testIntersectRectOutside (void *arg)
SDL_Rect result;
SDL_bool intersection;
// rectB fully outside of rectA
/* rectB fully outside of rectA */
refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
refRectB.w = refRectA.w;
@@ -464,7 +464,7 @@ int rect_testIntersectRectOutside (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_IntersectRect() with B partially intersecting A
*
* \sa
@@ -480,7 +480,7 @@ int rect_testIntersectRectPartial (void *arg)
SDL_Rect expectedResult;
SDL_bool intersection;
// rectB partially contained in rectA
/* rectB partially contained in rectA */
refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
refRectB.w = refRectA.w;
@@ -494,7 +494,7 @@ int rect_testIntersectRectPartial (void *arg)
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
// rectB right edge
/* rectB right edge */
refRectB.x = rectA.w - 1;
refRectB.y = rectA.y;
refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
@@ -508,7 +508,7 @@ int rect_testIntersectRectPartial (void *arg)
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
// rectB left edge
/* rectB left edge */
refRectB.x = 1 - rectA.w;
refRectB.y = rectA.y;
refRectB.w = refRectA.w;
@@ -522,7 +522,7 @@ int rect_testIntersectRectPartial (void *arg)
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
// rectB bottom edge
/* rectB bottom edge */
refRectB.x = rectA.x;
refRectB.y = rectA.h - 1;
refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
@@ -536,7 +536,7 @@ int rect_testIntersectRectPartial (void *arg)
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &expectedResult);
// rectB top edge
/* rectB top edge */
refRectB.x = rectA.x;
refRectB.y = 1 - rectA.h;
refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
@@ -553,7 +553,7 @@ int rect_testIntersectRectPartial (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_IntersectRect() with 1x1 pixel sized rectangles
*
* \sa
@@ -569,7 +569,7 @@ int rect_testIntersectRectPoint (void *arg)
SDL_bool intersection;
int offsetX, offsetY;
// intersecting pixels
/* intersecting pixels */
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectB.x = refRectA.x;
@@ -579,7 +579,7 @@ int rect_testIntersectRectPoint (void *arg)
intersection = SDL_IntersectRect(&rectA, &rectB, &result);
_validateIntersectRectResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB, &result, &refRectA);
// non-intersecting pixels cases
/* non-intersecting pixels cases */
for (offsetX = -1; offsetX <= 1; offsetX++) {
for (offsetY = -1; offsetY <= 1; offsetY++) {
if (offsetX != 0 || offsetY != 0) {
@@ -600,7 +600,7 @@ int rect_testIntersectRectPoint (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_IntersectRect() with empty rectangles
*
* \sa
@@ -616,7 +616,7 @@ int rect_testIntersectRectEmpty (void *arg)
SDL_bool intersection;
SDL_bool empty;
// Rect A empty
/* Rect A empty */
result.w = SDLTest_RandomIntegerInRange(1, 100);
result.h = SDLTest_RandomIntegerInRange(1, 100);
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
@@ -633,7 +633,7 @@ int rect_testIntersectRectEmpty (void *arg)
empty = (SDL_bool)SDL_RectEmpty(&result);
SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
// Rect B empty
/* Rect B empty */
result.w = SDLTest_RandomIntegerInRange(1, 100);
result.h = SDLTest_RandomIntegerInRange(1, 100);
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
@@ -650,7 +650,7 @@ int rect_testIntersectRectEmpty (void *arg)
empty = (SDL_bool)SDL_RectEmpty(&result);
SDLTest_AssertCheck(empty == SDL_TRUE, "Validate result is empty Rect; got: %s", (empty == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE");
// Rect A and B empty
/* Rect A and B empty */
result.w = SDLTest_RandomIntegerInRange(1, 100);
result.h = SDLTest_RandomIntegerInRange(1, 100);
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
@@ -672,7 +672,7 @@ int rect_testIntersectRectEmpty (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Negative tests against SDL_IntersectRect() with invalid parameters
*
* \sa
@@ -685,7 +685,7 @@ int rect_testIntersectRectParam(void *arg)
SDL_Rect result;
SDL_bool intersection;
// invalid parameter combinations
/* invalid parameter combinations */
intersection = SDL_IntersectRect((SDL_Rect *)NULL, &rectB, &result);
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
intersection = SDL_IntersectRect(&rectA, (SDL_Rect *)NULL, &result);
@@ -702,7 +702,7 @@ int rect_testIntersectRectParam(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_HasIntersection() with B fully inside A
*
* \sa
@@ -716,7 +716,7 @@ int rect_testHasIntersectionInside (void *arg)
SDL_Rect rectB;
SDL_bool intersection;
// rectB fully contained in rectA
/* rectB fully contained in rectA */
refRectB.x = 0;
refRectB.y = 0;
refRectB.w = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
@@ -729,7 +729,7 @@ int rect_testHasIntersectionInside (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_HasIntersection() with B fully outside A
*
* \sa
@@ -743,7 +743,7 @@ int rect_testHasIntersectionOutside (void *arg)
SDL_Rect rectB;
SDL_bool intersection;
// rectB fully outside of rectA
/* rectB fully outside of rectA */
refRectB.x = refRectA.x + refRectA.w + SDLTest_RandomIntegerInRange(1, 10);
refRectB.y = refRectA.y + refRectA.h + SDLTest_RandomIntegerInRange(1, 10);
refRectB.w = refRectA.w;
@@ -756,7 +756,7 @@ int rect_testHasIntersectionOutside (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_HasIntersection() with B partially intersecting A
*
* \sa
@@ -770,7 +770,7 @@ int rect_testHasIntersectionPartial (void *arg)
SDL_Rect rectB;
SDL_bool intersection;
// rectB partially contained in rectA
/* rectB partially contained in rectA */
refRectB.x = SDLTest_RandomIntegerInRange(refRectA.x + 1, refRectA.x + refRectA.w - 1);
refRectB.y = SDLTest_RandomIntegerInRange(refRectA.y + 1, refRectA.y + refRectA.h - 1);
refRectB.w = refRectA.w;
@@ -780,7 +780,7 @@ int rect_testHasIntersectionPartial (void *arg)
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
// rectB right edge
/* rectB right edge */
refRectB.x = rectA.w - 1;
refRectB.y = rectA.y;
refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
@@ -790,7 +790,7 @@ int rect_testHasIntersectionPartial (void *arg)
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
// rectB left edge
/* rectB left edge */
refRectB.x = 1 - rectA.w;
refRectB.y = rectA.y;
refRectB.w = refRectA.w;
@@ -800,7 +800,7 @@ int rect_testHasIntersectionPartial (void *arg)
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
// rectB bottom edge
/* rectB bottom edge */
refRectB.x = rectA.x;
refRectB.y = rectA.h - 1;
refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
@@ -810,7 +810,7 @@ int rect_testHasIntersectionPartial (void *arg)
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
// rectB top edge
/* rectB top edge */
refRectB.x = rectA.x;
refRectB.y = 1 - rectA.h;
refRectB.w = SDLTest_RandomIntegerInRange(1, refRectA.w - 1);
@@ -823,7 +823,7 @@ int rect_testHasIntersectionPartial (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_HasIntersection() with 1x1 pixel sized rectangles
*
* \sa
@@ -838,7 +838,7 @@ int rect_testHasIntersectionPoint (void *arg)
SDL_bool intersection;
int offsetX, offsetY;
// intersecting pixels
/* intersecting pixels */
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectB.x = refRectA.x;
@@ -848,7 +848,7 @@ int rect_testHasIntersectionPoint (void *arg)
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_TRUE, &rectA, &rectB, &refRectA, &refRectB);
// non-intersecting pixels cases
/* non-intersecting pixels cases */
for (offsetX = -1; offsetX <= 1; offsetX++) {
for (offsetY = -1; offsetY <= 1; offsetY++) {
if (offsetX != 0 || offsetY != 0) {
@@ -869,7 +869,7 @@ int rect_testHasIntersectionPoint (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_HasIntersection() with empty rectangles
*
* \sa
@@ -883,7 +883,7 @@ int rect_testHasIntersectionEmpty (void *arg)
SDL_Rect rectB;
SDL_bool intersection;
// Rect A empty
/* Rect A empty */
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
@@ -896,7 +896,7 @@ int rect_testHasIntersectionEmpty (void *arg)
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
// Rect B empty
/* Rect B empty */
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
@@ -909,7 +909,7 @@ int rect_testHasIntersectionEmpty (void *arg)
intersection = SDL_HasIntersection(&rectA, &rectB);
_validateHasIntersectionResults(intersection, SDL_FALSE, &rectA, &rectB, &refRectA, &refRectB);
// Rect A and B empty
/* Rect A and B empty */
refRectA.x = SDLTest_RandomIntegerInRange(1, 100);
refRectA.y = SDLTest_RandomIntegerInRange(1, 100);
refRectA.w = SDLTest_RandomIntegerInRange(1, 100);
@@ -927,7 +927,7 @@ int rect_testHasIntersectionEmpty (void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Negative tests against SDL_HasIntersection() with invalid parameters
*
* \sa
@@ -939,7 +939,7 @@ int rect_testHasIntersectionParam(void *arg)
SDL_Rect rectB;
SDL_bool intersection;
// invalid parameter combinations
/* invalid parameter combinations */
intersection = SDL_HasIntersection((SDL_Rect *)NULL, &rectB);
SDLTest_AssertCheck(intersection == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
intersection = SDL_HasIntersection(&rectA, (SDL_Rect *)NULL);
@@ -950,7 +950,7 @@ int rect_testHasIntersectionParam(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Test SDL_EnclosePoints() without clipping
*
* \sa
@@ -969,7 +969,7 @@ int rect_testEnclosePoints(void *arg)
int minx = 0, maxx = 0, miny = 0, maxy = 0;
int i;
// Create input data, tracking result
/* Create input data, tracking result */
for (i=0; i<numPoints; i++) {
newx = SDLTest_RandomIntegerInRange(-1024, 1024);
newy = SDLTest_RandomIntegerInRange(-1024, 1024);
@@ -990,7 +990,7 @@ int rect_testEnclosePoints(void *arg)
}
}
// Call function and validate - special case: no result requested
/* Call function and validate - special case: no result requested */
anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult,
"Check expected return value %s, got %s",
@@ -1002,7 +1002,7 @@ int rect_testEnclosePoints(void *arg)
i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
}
// Call function and validate
/* Call function and validate */
anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
SDLTest_AssertCheck(expectedEnclosed==anyEnclosed,
"Check return value %s, got %s",
@@ -1020,7 +1020,7 @@ int rect_testEnclosePoints(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Test SDL_EnclosePoints() with repeated input points
*
* \sa
@@ -1040,7 +1040,7 @@ int rect_testEnclosePointsRepeatedInput(void *arg)
int minx = 0, maxx = 0, miny = 0, maxy = 0;
int i;
// Create input data, tracking result
/* Create input data, tracking result */
for (i=0; i<numPoints; i++) {
if (i < halfPoints) {
newx = SDLTest_RandomIntegerInRange(-1024, 1024);
@@ -1066,7 +1066,7 @@ int rect_testEnclosePointsRepeatedInput(void *arg)
}
}
// Call function and validate - special case: no result requested
/* Call function and validate - special case: no result requested */
anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, (SDL_Rect *)NULL);
SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult,
"Check return value %s, got %s",
@@ -1078,7 +1078,7 @@ int rect_testEnclosePointsRepeatedInput(void *arg)
i, refPoints[i].x, refPoints[i].y, points[i].x, points[i].y);
}
// Call function and validate
/* Call function and validate */
anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)NULL, &result);
SDLTest_AssertCheck(expectedEnclosed==anyEnclosed,
"Check return value %s, got %s",
@@ -1096,7 +1096,7 @@ int rect_testEnclosePointsRepeatedInput(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Test SDL_EnclosePoints() with clipping
*
* \sa
@@ -1117,13 +1117,13 @@ int rect_testEnclosePointsWithClipping(void *arg)
int minx = 0, maxx = 0, miny = 0, maxy = 0;
int i;
// Setup clipping rectangle
/* Setup clipping rectangle */
refClip.x = SDLTest_RandomIntegerInRange(-1024, 1024);
refClip.y = SDLTest_RandomIntegerInRange(-1024, 1024);
refClip.w = SDLTest_RandomIntegerInRange(1, 1024);
refClip.h = SDLTest_RandomIntegerInRange(1, 1024);
// Create input data, tracking result
/* Create input data, tracking result */
for (i=0; i<numPoints; i++) {
newx = SDLTest_RandomIntegerInRange(-1024, 1024);
newy = SDLTest_RandomIntegerInRange(-1024, 1024);
@@ -1148,7 +1148,7 @@ int rect_testEnclosePointsWithClipping(void *arg)
}
}
// Call function and validate - special case: no result requested
/* Call function and validate - special case: no result requested */
clip = refClip;
anyEnclosedNoResult = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, (SDL_Rect *)NULL);
SDLTest_AssertCheck(expectedEnclosed==anyEnclosedNoResult,
@@ -1163,7 +1163,7 @@ int rect_testEnclosePointsWithClipping(void *arg)
SDLTest_AssertCheck(refClip.x==clip.x && refClip.y==clip.y && refClip.w==clip.w && refClip.h==clip.h,
"Check that source clipping rectangle was not modified");
// Call function and validate
/* Call function and validate */
anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, numPoints, (const SDL_Rect *)&clip, &result);
SDLTest_AssertCheck(expectedEnclosed==anyEnclosed,
"Check return value %s, got %s",
@@ -1195,7 +1195,7 @@ int rect_testEnclosePointsWithClipping(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Negative tests against SDL_EnclosePoints() with invalid parameters
*
* \sa
@@ -1209,7 +1209,7 @@ int rect_testEnclosePointsParam(void *arg)
SDL_Rect result;
SDL_bool anyEnclosed;
// invalid parameter combinations
/* invalid parameter combinations */
anyEnclosed = SDL_EnclosePoints((SDL_Point *)NULL, 1, (const SDL_Rect *)&clip, &result);
SDLTest_AssertCheck(anyEnclosed == SDL_FALSE, "Check that functions returns SDL_FALSE when 1st parameter is NULL");
anyEnclosed = SDL_EnclosePoints((const SDL_Point *)points, 0, (const SDL_Rect *)&clip, &result);
@@ -1223,7 +1223,7 @@ int rect_testEnclosePointsParam(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_UnionRect() where rect B is outside rect A
*
* \sa
@@ -1294,7 +1294,7 @@ int rect_testUnionRectOutside(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_UnionRect() where rect A or rect B are empty
*
* \sa
@@ -1359,7 +1359,7 @@ int rect_testUnionRectEmpty(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_UnionRect() where rect B is inside rect A
*
* \sa
@@ -1423,7 +1423,7 @@ int rect_testUnionRectInside(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Negative tests against SDL_UnionRect() with invalid parameters
*
* \sa
@@ -1434,7 +1434,7 @@ int rect_testUnionRectParam(void *arg)
SDL_Rect rectA, rectB;
SDL_Rect result;
// invalid parameter combinations
/* invalid parameter combinations */
SDL_UnionRect((SDL_Rect *)NULL, &rectB, &result);
SDLTest_AssertPass("Check that function returns when 1st parameter is NULL");
SDL_UnionRect(&rectA, (SDL_Rect *)NULL, &result);
@@ -1451,7 +1451,7 @@ int rect_testUnionRectParam(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_RectEmpty() with various inputs
*
* \sa
@@ -1465,7 +1465,7 @@ int rect_testRectEmpty(void *arg)
SDL_bool result;
int w, h;
// Non-empty case
/* Non-empty case */
refRect.x=SDLTest_RandomIntegerInRange(-1024, 1024);
refRect.y=SDLTest_RandomIntegerInRange(-1024, 1024);
refRect.w=SDLTest_RandomIntegerInRange(256, 1024);
@@ -1475,7 +1475,7 @@ int rect_testRectEmpty(void *arg)
result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)&rect);
_validateRectEmptyResults(result, expectedResult, &rect, &refRect);
// Empty case
/* Empty case */
for (w=-1; w<2; w++) {
for (h=-1; h<2; h++) {
if ((w != 1) || (h != 1)) {
@@ -1494,7 +1494,7 @@ int rect_testRectEmpty(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Negative tests against SDL_RectEmpty() with invalid parameters
*
* \sa
@@ -1504,14 +1504,14 @@ int rect_testRectEmptyParam(void *arg)
{
SDL_bool result;
// invalid parameter combinations
/* invalid parameter combinations */
result = (SDL_bool)SDL_RectEmpty((const SDL_Rect *)NULL);
SDLTest_AssertCheck(result == SDL_TRUE, "Check that function returns TRUE when 1st parameter is NULL");
return TEST_COMPLETED;
}
/*!
/* !
* \brief Tests SDL_RectEquals() with various inputs
*
* \sa
@@ -1526,7 +1526,7 @@ int rect_testRectEquals(void *arg)
SDL_bool expectedResult;
SDL_bool result;
// Equals
/* Equals */
refRectA.x=SDLTest_RandomIntegerInRange(-1024, 1024);
refRectA.y=SDLTest_RandomIntegerInRange(-1024, 1024);
refRectA.w=SDLTest_RandomIntegerInRange(1, 1024);
@@ -1541,7 +1541,7 @@ int rect_testRectEquals(void *arg)
return TEST_COMPLETED;
}
/*!
/* !
* \brief Negative tests against SDL_RectEquals() with invalid parameters
*
* \sa
@@ -1563,7 +1563,7 @@ int rect_testRectEqualsParam(void *arg)
rectB.w=SDLTest_RandomIntegerInRange(1, 1024);
rectB.h=SDLTest_RandomIntegerInRange(1, 1024);
// invalid parameter combinations
/* invalid parameter combinations */
result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)NULL, (const SDL_Rect *)&rectB);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
result = (SDL_bool)SDL_RectEquals((const SDL_Rect *)&rectA, (const SDL_Rect *)NULL);
@@ -1674,7 +1674,7 @@ static const SDLTest_TestCaseReference rectTest29 =
{ (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED };
/*!
/* !
* \brief Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
*
* \sa

View File

@@ -190,10 +190,8 @@ int render_testPrimitives (void *arg)
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
/* Clean up. */
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
@@ -333,10 +331,8 @@ int render_testPrimitivesBlend (void *arg)
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
/* Clean up. */
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
@@ -400,10 +396,8 @@ render_testBlit(void *arg)
/* Clean up. */
SDL_DestroyTexture( tface );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
@@ -470,10 +464,8 @@ render_testBlitColor (void *arg)
/* Clean up. */
SDL_DestroyTexture( tface );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
@@ -543,10 +535,8 @@ render_testBlitAlpha (void *arg)
/* Clean up. */
SDL_DestroyTexture( tface );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
@@ -655,37 +645,29 @@ render_testBlitBlend (void *arg)
_testBlitBlendMode( tface, SDL_BLENDMODE_NONE );
referenceSurface = SDLTest_ImageBlitBlendNone();
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
/* Test Blend. */
_testBlitBlendMode( tface, SDL_BLENDMODE_BLEND );
referenceSurface = SDLTest_ImageBlitBlend();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
/* Test Add. */
_testBlitBlendMode( tface, SDL_BLENDMODE_ADD );
referenceSurface = SDLTest_ImageBlitBlendAdd();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
/* Test Mod. */
_testBlitBlendMode( tface, SDL_BLENDMODE_MOD);
referenceSurface = SDLTest_ImageBlitBlendMod();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
/* Clear surface. */
_clearScreen();
@@ -733,10 +715,8 @@ render_testBlitBlend (void *arg)
/* Check to see if final image matches. */
referenceSurface = SDLTest_ImageBlitBlendAll();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
return TEST_COMPLETED;
}
@@ -995,12 +975,8 @@ _compare(SDL_Surface *referenceSurface, int allowable_error)
SDLTest_AssertCheck(result == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", result);
/* Clean up. */
if (pixels != NULL) {
SDL_free(pixels);
}
if (testSurface != NULL) {
SDL_FreeSurface(testSurface);
}
SDL_free(pixels);
SDL_FreeSurface(testSurface);
}
/**

View File

@@ -165,7 +165,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
i);
}
/*!
/* !
* Negative test for SDL_RWFromFile parameters
*
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
@@ -305,7 +305,7 @@ rwops_testFileRead(void)
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
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
/* Check type */
@@ -352,7 +352,7 @@ rwops_testFileWrite(void)
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
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
/* Check type */
@@ -642,7 +642,7 @@ rwops_testFileWriteReadEndian(void)
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
/* Bail out if NULL */
if (rw == NULL) return TEST_ABORTED;
/* Write test data */

View File

@@ -192,7 +192,7 @@ sdltest_randomBoundaryNumberUint8(void *arg)
"Validate result value for parameters (1,255,SDL_FALSE); expected: 0, got: %lld", uresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomUintXBoundaryValue(0, 0xfe, SDL_FALSE) returns 0xff (no error) */
uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(0, 254, SDL_FALSE);
@@ -202,7 +202,7 @@ sdltest_randomBoundaryNumberUint8(void *arg)
"Validate result value for parameters (0,254,SDL_FALSE); expected: 0xff, got: %lld", uresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomUintXBoundaryValue(0, 0xff, SDL_FALSE) returns 0 (sets error) */
uresult = (Uint64)SDLTest_RandomUint8BoundaryValue(0, 255, SDL_FALSE);
@@ -302,7 +302,7 @@ sdltest_randomBoundaryNumberUint16(void *arg)
"Validate result value for parameters (1,0xffff,SDL_FALSE); expected: 0, got: %lld", uresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomUintXBoundaryValue(0, 0xfffe, SDL_FALSE) returns 0xffff (no error) */
uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(0, 0xfffe, SDL_FALSE);
@@ -312,7 +312,7 @@ sdltest_randomBoundaryNumberUint16(void *arg)
"Validate result value for parameters (0,0xfffe,SDL_FALSE); expected: 0xffff, got: %lld", uresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomUintXBoundaryValue(0, 0xffff, SDL_FALSE) returns 0 (sets error) */
uresult = (Uint64)SDLTest_RandomUint16BoundaryValue(0, 0xffff, SDL_FALSE);
@@ -412,7 +412,7 @@ sdltest_randomBoundaryNumberUint32(void *arg)
"Validate result value for parameters (1,0xffffffff,SDL_FALSE); expected: 0, got: %lld", uresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomUintXBoundaryValue(0, 0xfffffffe, SDL_FALSE) returns 0xffffffff (no error) */
uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(0, 0xfffffffe, SDL_FALSE);
@@ -422,7 +422,7 @@ sdltest_randomBoundaryNumberUint32(void *arg)
"Validate result value for parameters (0,0xfffffffe,SDL_FALSE); expected: 0xffffffff, got: %lld", uresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomUintXBoundaryValue(0, 0xffffffff, SDL_FALSE) returns 0 (sets error) */
uresult = (Uint64)SDLTest_RandomUint32BoundaryValue(0, 0xffffffff, SDL_FALSE);
@@ -522,7 +522,7 @@ sdltest_randomBoundaryNumberUint64(void *arg)
"Validate result value for parameters (1,0xffffffffffffffff,SDL_FALSE); expected: 0, got: %lld", uresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomUintXBoundaryValue(0, 0xfffffffffffffffe, SDL_FALSE) returns 0xffffffffffffffff (no error) */
uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(0, (Uint64)0xfffffffffffffffeULL, SDL_FALSE);
@@ -532,7 +532,7 @@ sdltest_randomBoundaryNumberUint64(void *arg)
"Validate result value for parameters (0,0xfffffffffffffffe,SDL_FALSE); expected: 0xffffffffffffffff, got: %lld", uresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomUintXBoundaryValue(0, 0xffffffffffffffff, SDL_FALSE) returns 0 (sets error) */
uresult = (Uint64)SDLTest_RandomUint64BoundaryValue(0, (Uint64)0xffffffffffffffffULL, SDL_FALSE);
@@ -632,7 +632,7 @@ sdltest_randomBoundaryNumberSint8(void *arg)
"Validate result value for parameters (SCHAR_MIN + 1,SCHAR_MAX,SDL_FALSE); expected: %d, got: %lld", SCHAR_MIN, sresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomSintXBoundaryValue(SCHAR_MIN, SCHAR_MAX - 1, SDL_FALSE) returns SCHAR_MAX (no error) */
sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(SCHAR_MIN, SCHAR_MAX -1, SDL_FALSE);
@@ -642,7 +642,7 @@ sdltest_randomBoundaryNumberSint8(void *arg)
"Validate result value for parameters (SCHAR_MIN,SCHAR_MAX - 1,SDL_FALSE); expected: %d, got: %lld", SCHAR_MAX, sresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomSintXBoundaryValue(SCHAR_MIN, SCHAR_MAX, SDL_FALSE) returns SCHAR_MIN (sets error) */
sresult = (Sint64)SDLTest_RandomSint8BoundaryValue(SCHAR_MIN, SCHAR_MAX, SDL_FALSE);
@@ -742,7 +742,7 @@ sdltest_randomBoundaryNumberSint16(void *arg)
"Validate result value for parameters (SHRT_MIN+1,SHRT_MAX,SDL_FALSE); expected: %d, got: %lld", SHRT_MIN, sresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomSintXBoundaryValue(SHRT_MIN, SHRT_MAX - 1, SDL_FALSE) returns SHRT_MAX (no error) */
sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(SHRT_MIN, SHRT_MAX - 1, SDL_FALSE);
@@ -752,7 +752,7 @@ sdltest_randomBoundaryNumberSint16(void *arg)
"Validate result value for parameters (SHRT_MIN,SHRT_MAX - 1,SDL_FALSE); expected: %d, got: %lld", SHRT_MAX, sresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomSintXBoundaryValue(SHRT_MIN, SHRT_MAX, SDL_FALSE) returns 0 (sets error) */
sresult = (Sint64)SDLTest_RandomSint16BoundaryValue(SHRT_MIN, SHRT_MAX, SDL_FALSE);
@@ -859,7 +859,7 @@ sdltest_randomBoundaryNumberSint32(void *arg)
"Validate result value for parameters (LONG_MIN+1,LONG_MAX,SDL_FALSE); expected: %d, got: %lld", long_min, sresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomSintXBoundaryValue(LONG_MIN, LONG_MAX - 1, SDL_FALSE) returns LONG_MAX (no error) */
sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(long_min, long_max - 1, SDL_FALSE);
@@ -869,7 +869,7 @@ sdltest_randomBoundaryNumberSint32(void *arg)
"Validate result value for parameters (LONG_MIN,LONG_MAX - 1,SDL_FALSE); expected: %d, got: %lld", long_max, sresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomSintXBoundaryValue(LONG_MIN, LONG_MAX, SDL_FALSE) returns 0 (sets error) */
sresult = (Sint64)SDLTest_RandomSint32BoundaryValue(long_min, long_max, SDL_FALSE);
@@ -969,7 +969,7 @@ sdltest_randomBoundaryNumberSint64(void *arg)
"Validate result value for parameters (LLONG_MIN+1,LLONG_MAX,SDL_FALSE); expected: %lld, got: %lld", LLONG_MIN, sresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomSintXBoundaryValue(LLONG_MIN, LLONG_MAX - 1, SDL_FALSE) returns LLONG_MAX (no error) */
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN, LLONG_MAX - 1, SDL_FALSE);
@@ -979,7 +979,7 @@ sdltest_randomBoundaryNumberSint64(void *arg)
"Validate result value for parameters (LLONG_MIN,LLONG_MAX - 1,SDL_FALSE); expected: %lld, got: %lld", LLONG_MAX, sresult);
lastError = (char *)SDL_GetError();
SDLTest_AssertPass("SDL_GetError()");
SDLTest_AssertCheck(lastError == NULL || SDL_strlen(lastError) == 0, "Validate no error message was set");
SDLTest_AssertCheck(lastError == NULL || lastError[0] == '\0', "Validate no error message was set");
/* RandomSintXBoundaryValue(LLONG_MIN, LLONG_MAX, SDL_FALSE) returns 0 (sets error) */
sresult = (Sint64)SDLTest_RandomSint64BoundaryValue(LLONG_MIN, LLONG_MAX, SDL_FALSE);

View File

@@ -8,7 +8,7 @@
#include "SDL_test.h"
// Test collections
/* Test collections */
extern SDLTest_TestSuiteReference audioTestSuite;
extern SDLTest_TestSuiteReference clipboardTestSuite;
extern SDLTest_TestSuiteReference eventsTestSuite;
@@ -27,7 +27,7 @@ extern SDLTest_TestSuiteReference syswmTestSuite;
extern SDLTest_TestSuiteReference timerTestSuite;
extern SDLTest_TestSuiteReference videoTestSuite;
// All test suites
/* All test suites */
SDLTest_TestSuiteReference *testSuites[] = {
&audioTestSuite,
&clipboardTestSuite,

View File

@@ -63,14 +63,10 @@ _surfaceSetUp(void *arg)
void
_surfaceTearDown(void *arg)
{
if (referenceSurface != NULL) {
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
}
if (testSurface != NULL) {
SDL_FreeSurface(testSurface);
testSurface = NULL;
}
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
SDL_FreeSurface(testSurface);
testSurface = NULL;
}
/**
@@ -193,10 +189,8 @@ void _testBlitBlendMode(int mode)
SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_SetSurfaceBlendMode, expected: 0, got: %i", checkFailCount4);
/* Clean up */
if (face != NULL) {
SDL_FreeSurface(face);
face = NULL;
}
SDL_FreeSurface(face);
face = NULL;
}
/* Helper to check that a file exists */
@@ -250,19 +244,15 @@ surface_testSaveLoadBitmap(void *arg)
unlink(sampleFilename);
/* Clean up */
if (face != NULL) {
SDL_FreeSurface(face);
face = NULL;
}
if (rface != NULL) {
SDL_FreeSurface(rface);
rface = NULL;
}
return TEST_COMPLETED;
}
/*!
/* !
* Tests surface conversion.
*/
int
@@ -294,20 +284,16 @@ surface_testSurfaceConversion(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (face != NULL) {
SDL_FreeSurface( face );
face = NULL;
}
if (rface != NULL) {
SDL_FreeSurface( rface );
rface = NULL;
}
SDL_FreeSurface(face);
face = NULL;
SDL_FreeSurface(rface);
rface = NULL;
return TEST_COMPLETED;
}
/*!
/* !
* Tests surface conversion across all pixel formats.
*/
int
@@ -360,8 +346,6 @@ surface_testCompleteSurfaceConversion(void *arg)
for ( i = 0; i < SDL_arraysize(pixel_formats); ++i ) {
for ( j = 0; j < SDL_arraysize(pixel_formats); ++j ) {
/*printf("Converting %s -> %s\n", SDL_GetPixelFormatName(pixel_formats[i]), SDL_GetPixelFormatName(pixel_formats[j]));*/
fmt1 = SDL_AllocFormat(pixel_formats[i]);
SDL_assert(fmt1 != NULL);
cvt1 = SDL_ConvertSurface(face, fmt1, 0);
@@ -429,9 +413,7 @@ surface_testBlit(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@@ -454,9 +436,7 @@ surface_testBlitColorMod(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@@ -479,9 +459,7 @@ surface_testBlitAlphaMod(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@@ -505,9 +483,7 @@ surface_testBlitBlendNone(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@@ -530,9 +506,7 @@ surface_testBlitBlendBlend(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@@ -555,9 +529,7 @@ surface_testBlitBlendAdd(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@@ -580,9 +552,7 @@ surface_testBlitBlendMod(void *arg)
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface( compareSurface );
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;
}
@@ -605,9 +575,7 @@ surface_testBlitBlendLoop(void *arg) {
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
/* Clean up. */
if (compareSurface != NULL) {
SDL_FreeSurface(compareSurface);
}
SDL_FreeSurface(compareSurface);
return TEST_COMPLETED;

View File

@@ -876,7 +876,7 @@ video_getWindowId(void *arg)
/* Clean up */
_destroyVideoSuiteTestWindow(window);
/* Get window from ID for closed window*/
/* Get window from ID for closed window */
result = SDL_GetWindowFromID(id);
SDLTest_AssertPass("Call to SDL_GetWindowID(%d/closed_window)", id);
SDLTest_AssertCheck(result == NULL, "Verify result is NULL");
@@ -1714,10 +1714,10 @@ video_getSetWindowData(void *arg)
_destroyVideoSuiteTestWindow(window);
cleanup:
if (referenceUserdata != NULL) SDL_free(referenceUserdata);
if (referenceUserdata2 != NULL) SDL_free(referenceUserdata2);
if (userdata != NULL) SDL_free(userdata);
if (userdata2 != NULL) SDL_free(userdata2);
SDL_free(referenceUserdata);
SDL_free(referenceUserdata2);
SDL_free(userdata);
SDL_free(userdata2);
return returnValue;
}

View File

@@ -176,6 +176,9 @@ main(int argc, char *argv[])
SDL_Event event;
Uint32 then, now, frames;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize parameters */
num_objects = NUM_OBJECTS;
@@ -218,8 +221,7 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
fprintf(stderr,
"Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
argv[0], SDLTest_CommonUsage(state));
return 1;
}
@@ -251,6 +253,8 @@ main(int argc, char *argv[])
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
if (state->windows[i] == NULL)
continue;
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
@@ -268,7 +272,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
printf("%2.2f frames per second\n", fps);
SDL_Log("%2.2f frames per second\n", fps);
}
return 0;
}

View File

@@ -54,10 +54,13 @@ main(int argc, char *argv[])
SDL_Surface *surface;
SDL_Renderer *renderer;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL */
if(SDL_Init(SDL_INIT_VIDEO) != 0)
{
fprintf(stderr,"SDL_Init fail : %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
return 1;
}
@@ -66,14 +69,14 @@ main(int argc, char *argv[])
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
if(!window)
{
fprintf(stderr,"Window creation fail : %s\n",SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
return 1;
}
surface = SDL_GetWindowSurface(window);
renderer = SDL_CreateSoftwareRenderer(surface);
if(!renderer)
{
fprintf(stderr,"Render creation for surface fail : %s\n",SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
return 1;
}

87
test/testdropfile.c Normal file
View File

@@ -0,0 +1,87 @@
/*
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
#include <stdlib.h>
#include <stdio.h>
#include "SDL_test_common.h"
static SDLTest_CommonState *state;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDLTest_CommonQuit(state);
exit(rc);
}
int
main(int argc, char *argv[])
{
int i, done;
SDL_Event event;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
return 1;
}
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) {
consumed = -1;
}
if (consumed < 0) {
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
quit(1);
}
i += consumed;
}
if (!SDLTest_CommonInit(state)) {
quit(2);
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}
/* Main render loop */
done = 0;
while (!done) {
/* Check for events */
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
if (event.type == SDL_DROPFILE) {
char *dropped_filedir = event.drop.file;
SDL_Log("File dropped on window: %s", dropped_filedir);
SDL_free(dropped_filedir);
}
}
}
quit(0);
/* keep the compiler happy ... */
return(0);
}
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -36,10 +36,10 @@ ThreadFunc(void *data)
SDL_SetError("Thread %s (%lu) had a problem: %s",
(char *) data, SDL_ThreadID(), "nevermind");
while (alive) {
printf("Thread '%s' is alive!\n", (char *) data);
SDL_Log("Thread '%s' is alive!\n", (char *) data);
SDL_Delay(1 * 1000);
}
printf("Child thread error string: %s\n", SDL_GetError());
SDL_Log("Child thread error string: %s\n", SDL_GetError());
return (0);
}
@@ -48,9 +48,12 @@ main(int argc, char *argv[])
{
SDL_Thread *thread;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(0) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
@@ -60,15 +63,15 @@ main(int argc, char *argv[])
alive = 1;
thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
if (thread == NULL) {
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(1);
}
SDL_Delay(5 * 1000);
printf("Waiting for thread #1\n");
SDL_Log("Waiting for thread #1\n");
alive = 0;
SDL_WaitThread(thread, NULL);
printf("Main thread error string: %s\n", SDL_GetError());
SDL_Log("Main thread error string: %s\n", SDL_GetError());
SDL_Quit();
return (0);

View File

@@ -12,7 +12,7 @@
/* sanity tests on SDL_rwops.c (usefull for alternative implementations of stdio rwops) */
// quiet windows compiler warnings
/* quiet windows compiler warnings */
#define _CRT_NONSTDC_NO_WARNINGS
#include <stdlib.h>
@@ -44,7 +44,6 @@
static void
cleanup(void)
{
unlink(FBASENAME1);
unlink(FBASENAME2);
}
@@ -52,8 +51,7 @@ cleanup(void)
static void
rwops_error_quit(unsigned line, SDL_RWops * rwops)
{
printf("testfile.c(%d): failed\n", line);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testfile.c(%d): failed\n", line);
if (rwops) {
rwops->close(rwops); /* This calls SDL_FreeRW(rwops); */
}
@@ -71,6 +69,9 @@ main(int argc, char *argv[])
SDL_RWops *rwops = NULL;
char test_buf[30];
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
cleanup();
/* test 1 : basic argument test: all those calls to SDL_RWFromFile should fail */
@@ -90,7 +91,7 @@ main(int argc, char *argv[])
rwops = SDL_RWFromFile("something", NULL);
if (rwops)
RWOP_ERR_QUIT(rwops);
printf("test1 OK\n");
SDL_Log("test1 OK\n");
/* test 2 : check that inexistent file is not successfully opened/created when required */
/* modes : r, r+ imply that file MUST exist
@@ -123,7 +124,7 @@ main(int argc, char *argv[])
RWOP_ERR_QUIT(rwops);
rwops->close(rwops);
unlink(FBASENAME2);
printf("test2 OK\n");
SDL_Log("test2 OK\n");
/* test 3 : creation, writing , reading, seeking,
test : w mode, r mode, w+ mode
@@ -201,7 +202,7 @@ main(int argc, char *argv[])
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
RWOP_ERR_QUIT(rwops);
rwops->close(rwops);
printf("test3 OK\n");
SDL_Log("test3 OK\n");
/* test 4: same in r+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */
@@ -236,7 +237,7 @@ main(int argc, char *argv[])
if (SDL_memcmp(test_buf, "12345678901234567890", 20))
RWOP_ERR_QUIT(rwops);
rwops->close(rwops);
printf("test4 OK\n");
SDL_Log("test4 OK\n");
/* test5 : append mode */
rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */
@@ -277,7 +278,7 @@ main(int argc, char *argv[])
if (SDL_memcmp(test_buf, "123456789012345678901234567123", 30))
RWOP_ERR_QUIT(rwops);
rwops->close(rwops);
printf("test5 OK\n");
SDL_Log("test5 OK\n");
cleanup();
return 0; /* all ok */
}

33
test/testfilesystem.c Normal file
View File

@@ -0,0 +1,33 @@
/*
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
/* Simple test of power subsystem. */
#include <stdio.h>
#include "SDL.h"
int
main(int argc, char *argv[])
{
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(0) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
return 1;
}
SDL_Log("base path: '%s'\n", SDL_GetBasePath());
SDL_Log("pref path: '%s'\n", SDL_GetPrefPath("libsdl", "testfilesystem"));
SDL_Quit();
return 0;
}

View File

@@ -91,7 +91,7 @@ WatchGameController(SDL_GameController * gamecontroller)
const char *name = SDL_GameControllerName(gamecontroller);
const char *basetitle = "Game Controller Test: ";
const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1;
char *title = SDL_malloc(titlelen);
char *title = (char *)SDL_malloc(titlelen);
SDL_Window *window = NULL;
SDL_Renderer *screen = NULL;
int done = 0;
@@ -107,13 +107,13 @@ WatchGameController(SDL_GameController * gamecontroller)
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
SCREEN_HEIGHT, 0);
if (window == NULL) {
fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
return;
}
screen = SDL_CreateRenderer(window, -1, 0);
if (screen == NULL) {
fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
SDL_DestroyWindow(window);
return;
}
@@ -124,7 +124,7 @@ WatchGameController(SDL_GameController * gamecontroller)
SDL_RaiseWindow(window);
/* Print info about the controller we are watching */
printf("Watching controller %s\n", name ? name : "Unknown Controller");
SDL_Log("Watching controller %s\n", name ? name : "Unknown Controller");
/* Loop, getting controller events! */
while (!done) {
@@ -135,21 +135,21 @@ WatchGameController(SDL_GameController * gamecontroller)
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_CONTROLLERAXISMOTION:
printf("Controller %d axis %d ('%s') value: %d\n",
SDL_Log("Controller %d axis %d ('%s') value: %d\n",
event.caxis.which,
event.caxis.axis,
ControllerAxisName(event.caxis.axis),
ControllerAxisName((SDL_GameControllerAxis)event.caxis.axis),
event.caxis.value);
break;
case SDL_CONTROLLERBUTTONDOWN:
printf("Controller %d button %d ('%s') down\n",
SDL_Log("Controller %d button %d ('%s') down\n",
event.cbutton.which, event.cbutton.button,
ControllerButtonName(event.cbutton.button));
ControllerButtonName((SDL_GameControllerButton)event.cbutton.button));
break;
case SDL_CONTROLLERBUTTONUP:
printf("Controller %d button %d ('%s') up\n",
SDL_Log("Controller %d button %d ('%s') up\n",
event.cbutton.which, event.cbutton.button,
ControllerButtonName(event.cbutton.button));
ControllerButtonName((SDL_GameControllerButton)event.cbutton.button));
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym != SDLK_ESCAPE) {
@@ -167,7 +167,7 @@ WatchGameController(SDL_GameController * gamecontroller)
/* Update visual controller state */
SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE);
for (i = 0; i <SDL_CONTROLLER_BUTTON_MAX; ++i) {
if (SDL_GameControllerGetButton(gamecontroller, i) == SDL_PRESSED) {
if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
DrawRect(screen, i * 34, SCREEN_HEIGHT - 34, 32, 32);
}
}
@@ -176,7 +176,7 @@ WatchGameController(SDL_GameController * gamecontroller)
for (i = 0; i < SDL_CONTROLLER_AXIS_MAX / 2; ++i) {
/* Draw the X/Y axis */
int x, y;
x = (((int) SDL_GameControllerGetAxis(gamecontroller, i * 2 + 0)) + 32768);
x = (((int) SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i * 2 + 0))) + 32768);
x *= SCREEN_WIDTH;
x /= 65535;
if (x < 0) {
@@ -184,7 +184,7 @@ WatchGameController(SDL_GameController * gamecontroller)
} else if (x > (SCREEN_WIDTH - 16)) {
x = SCREEN_WIDTH - 16;
}
y = (((int) SDL_GameControllerGetAxis(gamecontroller, i * 2 + 1)) + 32768);
y = (((int) SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i * 2 + 1))) + 32768);
y *= SCREEN_HEIGHT;
y /= 65535;
if (y < 0) {
@@ -217,16 +217,19 @@ main(int argc, char *argv[])
char guid[64];
SDL_GameController *gamecontroller;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL (Note: video is required to start event loop) */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
/* Print information about the controller */
for (i = 0; i < SDL_NumJoysticks(); ++i) {
const char *name;
const char *description = "Joystick (not recognized as game controller)";
const char *description;
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),
guid, sizeof (guid));
@@ -235,25 +238,27 @@ main(int argc, char *argv[])
{
nController++;
name = SDL_GameControllerNameForIndex(i);
description = "Controller";
} else {
name = SDL_JoystickNameForIndex(i);
description = "Joystick";
}
printf("%s %d: %s (guid %s)\n", description, i, name ? name : "Unknown", guid);
SDL_Log("%s %d: %s (guid %s)\n", description, i, name ? name : "Unknown", guid);
}
printf("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks());
SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks());
if (argv[1]) {
int device = atoi(argv[1]);
if (device >= SDL_NumJoysticks()) {
printf("%i is an invalid joystick index.\n", device);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%i is an invalid joystick index.\n", device);
retcode = 1;
} else {
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(device),
guid, sizeof (guid));
printf("Attempting to open device %i, guid %s\n", device, guid);
SDL_Log("Attempting to open device %i, guid %s\n", device, guid);
gamecontroller = SDL_GameControllerOpen(device);
if (gamecontroller == NULL) {
printf("Couldn't open joystick %d: %s\n", device, SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open joystick %d: %s\n", device, SDL_GetError());
retcode = 1;
} else {
WatchGameController(gamecontroller);
@@ -272,7 +277,7 @@ main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
fprintf(stderr, "SDL compiled without Joystick support.\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick support.\n");
exit(1);
}

View File

@@ -49,7 +49,7 @@
#define BPP 4
#define DEPTH 32
//MUST BE A POWER OF 2!
/* MUST BE A POWER OF 2! */
#define EVENT_BUF_SIZE 256
@@ -102,9 +102,9 @@ void setpix(SDL_Surface *screen, float _x, float _y, unsigned int col)
SDL_memcpy(&colour,pixmem32,screen->format->BytesPerPixel);
SDL_GetRGB(colour,screen->format,&r,&g,&b);
//r = 0;g = 0; b = 0;
/* r = 0;g = 0; b = 0; */
a = (float)((col>>24)&0xFF);
if(a == 0) a = 0xFF; //Hack, to make things easier.
if(a == 0) a = 0xFF; /* Hack, to make things easier. */
a /= 0xFF;
r = (Uint8)(r*(1-a) + ((col>>16)&0xFF)*(a));
g = (Uint8)(g*(1-a) + ((col>> 8)&0xFF)*(a));
@@ -127,7 +127,7 @@ void drawCircle(SDL_Surface* screen,float x,float y,float r,unsigned int c)
float xr;
for(ty = (float)-SDL_fabs(r);ty <= (float)SDL_fabs((int)r);ty++) {
xr = (float)sqrt(r*r - ty*ty);
if(r > 0) { //r > 0 ==> filled circle
if(r > 0) { /* r > 0 ==> filled circle */
for(tx=-xr+.5f;tx<=xr-.5;tx++) {
setpix(screen,x+tx,y+ty,c);
}
@@ -157,7 +157,7 @@ void DrawScreen(SDL_Surface* screen)
setpix(screen,(float)x,(float)y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255);
#endif
//draw Touch History
/* draw Touch History */
for(i = eventWrite; i < eventWrite+EVENT_BUF_SIZE; ++i) {
const SDL_Event *event = &events[i&(EVENT_BUF_SIZE-1)];
float age = (float)(i - eventWrite) / EVENT_BUF_SIZE;
@@ -170,7 +170,7 @@ void DrawScreen(SDL_Surface* screen)
x = event->tfinger.x;
y = event->tfinger.y;
//draw the touch:
/* draw the touch: */
c = colors[event->tfinger.fingerId%7];
col = ((unsigned int)(c*(.1+.85))) | (unsigned int)(0xFF*age)<<24;
@@ -207,7 +207,10 @@ int main(int argc, char* argv[])
SDL_bool quitting = SDL_FALSE;
SDL_RWops *src;
//gesture variables
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* gesture variables */
knob.r = .1f;
knob.ang = 0;
@@ -222,7 +225,7 @@ int main(int argc, char* argv[])
while(!quitting) {
while(SDL_PollEvent(&event))
{
//Record _all_ events
/* Record _all_ events */
events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
eventWrite++;

View File

@@ -180,6 +180,10 @@ main(int argc, char *argv[])
SDL_Event event;
Uint32 then, now, frames;
int status;
int dw, dh;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize parameters */
fsaa = 0;
@@ -206,7 +210,7 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
fprintf(stderr, "Usage: %s %s [--fsaa n] [--accel n]\n", argv[0],
SDL_Log("Usage: %s %s [--fsaa n] [--accel n]\n", argv[0],
SDLTest_CommonUsage(state));
quit(1);
}
@@ -235,7 +239,7 @@ main(int argc, char *argv[])
/* Create OpenGL context */
context = SDL_GL_CreateContext(state->windows[0]);
if (!context) {
fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
quit(2);
}
@@ -249,63 +253,67 @@ main(int argc, char *argv[])
}
SDL_GetCurrentDisplayMode(0, &mode);
printf("Screen BPP : %d\n", SDL_BITSPERPIXEL(mode.format));
printf("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
printf("\n");
printf("Vendor : %s\n", glGetString(GL_VENDOR));
printf("Renderer : %s\n", glGetString(GL_RENDERER));
printf("Version : %s\n", glGetString(GL_VERSION));
printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
printf("\n");
SDL_Log("Screen BPP : %d\n", SDL_BITSPERPIXEL(mode.format));
SDL_Log("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
SDL_GetWindowSize(state->windows[0], &dw, &dh);
SDL_Log("Window Size : %d,%d\n", dw, dh);
SDL_GL_GetDrawableSize(state->windows[0], &dw, &dh);
SDL_Log("Draw Size : %d,%d\n", dw, dh);
SDL_Log("\n");
SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR));
SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER));
SDL_Log("Version : %s\n", glGetString(GL_VERSION));
SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS));
SDL_Log("\n");
status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
if (!status) {
printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
} else {
printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
if (!status) {
printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
} else {
printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
if (!status) {
printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
} else {
printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
if (!status) {
printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
} else {
printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
}
if (fsaa) {
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
if (!status) {
printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
} else {
printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
if (!status) {
printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value);
} else {
printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_GetError());
}
}
if (accel >= 0) {
status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
if (!status) {
printf("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel,
value);
} else {
printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_GetError());
}
}
@@ -319,7 +327,7 @@ main(int argc, char *argv[])
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glShadeModel(GL_SMOOTH);
/* Main render loop */
frames = 0;
then = SDL_GetTicks();
@@ -332,8 +340,10 @@ main(int argc, char *argv[])
}
for (i = 0; i < state->num_windows; ++i) {
int w, h;
if (state->windows[i] == NULL)
continue;
SDL_GL_MakeCurrent(state->windows[i], context);
SDL_GetWindowSize(state->windows[i], &w, &h);
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
glViewport(0, 0, w, h);
Render();
SDL_GL_SwapWindow(state->windows[i]);
@@ -343,7 +353,7 @@ main(int argc, char *argv[])
/* Print out some timing information */
now = SDL_GetTicks();
if (now > then) {
printf("%2.2f frames per second\n",
SDL_Log("%2.2f frames per second\n",
((double) frames * 1000) / (now - then));
}
quit(0);
@@ -355,7 +365,7 @@ main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
printf("No OpenGL support on this system\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
return 1;
}

View File

@@ -110,6 +110,9 @@ main(int argc, char *argv[])
Uint32 then, now, frames;
int status;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize parameters */
fsaa = 0;
accel = 0;
@@ -143,7 +146,7 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
fprintf(stderr, "Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
SDL_Log("Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
SDLTest_CommonUsage(state));
quit(1);
}
@@ -156,6 +159,9 @@ main(int argc, char *argv[])
state->gl_green_size = 5;
state->gl_blue_size = 5;
state->gl_depth_size = depth;
state->gl_major_version = 1;
state->gl_minor_version = 1;
state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
if (fsaa) {
state->gl_multisamplebuffers=1;
state->gl_multisamplesamples=fsaa;
@@ -169,7 +175,7 @@ main(int argc, char *argv[])
context = SDL_calloc(state->num_windows, sizeof(context));
if (context == NULL) {
fprintf(stderr, "Out of memory!\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);
}
@@ -177,7 +183,7 @@ main(int argc, char *argv[])
for (i = 0; i < state->num_windows; i++) {
context[i] = SDL_GL_CreateContext(state->windows[i]);
if (!context[i]) {
fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
quit(2);
}
}
@@ -189,65 +195,65 @@ main(int argc, char *argv[])
}
SDL_GetCurrentDisplayMode(0, &mode);
printf("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
printf("\n");
printf("Vendor : %s\n", glGetString(GL_VENDOR));
printf("Renderer : %s\n", glGetString(GL_RENDERER));
printf("Version : %s\n", glGetString(GL_VERSION));
printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
printf("\n");
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
SDL_Log("\n");
SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR));
SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER));
SDL_Log("Version : %s\n", glGetString(GL_VERSION));
SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS));
SDL_Log("\n");
status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
if (!status) {
printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
} else {
fprintf(stderr, "Failed to get SDL_GL_RED_SIZE: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
if (!status) {
printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
} else {
fprintf(stderr, "Failed to get SDL_GL_GREEN_SIZE: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
if (!status) {
printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
} else {
fprintf(stderr, "Failed to get SDL_GL_BLUE_SIZE: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
if (!status) {
printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
} else {
fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
SDL_GetError());
}
if (fsaa) {
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
if (!status) {
printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
} else {
fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_GetError());
}
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
if (!status) {
printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value);
} else {
fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_GetError());
}
}
if (accel) {
status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
if (!status) {
printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
} else {
fprintf(stderr, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_GetError());
}
}
@@ -258,7 +264,7 @@ main(int argc, char *argv[])
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) {
printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
/* Continue for next window */
continue;
@@ -292,7 +298,7 @@ main(int argc, char *argv[])
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) {
printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
break;
}
/* Change view port to the new window dimensions */
@@ -309,9 +315,11 @@ main(int argc, char *argv[])
SDLTest_CommonEvent(state, &event, &done);
}
for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i] == NULL)
continue;
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) {
printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
/* Continue for next window */
continue;
@@ -324,7 +332,7 @@ main(int argc, char *argv[])
/* Print out some timing information */
now = SDL_GetTicks();
if (now > then) {
printf("%2.2f frames per second\n",
SDL_Log("%2.2f frames per second\n",
((double) frames * 1000) / (now - then));
}
quit(0);
@@ -336,7 +344,7 @@ main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
printf("No OpenGL ES support on this system\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL ES support on this system\n");
return 1;
}

View File

@@ -26,7 +26,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* includes
*/
#include <stdlib.h>
#include <stdio.h> /* printf */
#include <string.h> /* strstr */
#include <ctype.h> /* isdigit */
@@ -62,12 +61,15 @@ main(int argc, char **argv)
int nefx;
unsigned int supported;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
name = NULL;
index = -1;
if (argc > 1) {
name = argv[1];
if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
printf("USAGE: %s [device]\n"
SDL_Log("USAGE: %s [device]\n"
"If device is a two-digit number it'll use it as an index, otherwise\n"
"it'll use it as if it were part of the device's name.\n",
argv[0]);
@@ -84,7 +86,7 @@ main(int argc, char **argv)
/* Initialize the force feedbackness */
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
SDL_INIT_HAPTIC);
printf("%d Haptic devices detected.\n", SDL_NumHaptics());
SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics());
if (SDL_NumHaptics() > 0) {
/* We'll just use index or the first force feedback device found */
if (name == NULL) {
@@ -98,7 +100,7 @@ main(int argc, char **argv)
}
if (i >= SDL_NumHaptics()) {
printf("Unable to find device matching '%s', aborting.\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
name);
return 1;
}
@@ -106,14 +108,14 @@ main(int argc, char **argv)
haptic = SDL_HapticOpen(i);
if (haptic == NULL) {
printf("Unable to create the haptic device: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
SDL_GetError());
return 1;
}
printf("Device: %s\n", SDL_HapticName(i));
SDL_Log("Device: %s\n", SDL_HapticName(i));
HapticPrintSupported(haptic);
} else {
printf("No Haptic devices found!\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
return 1;
}
@@ -125,10 +127,10 @@ main(int argc, char **argv)
nefx = 0;
supported = SDL_HapticQuery(haptic);
printf("\nUploading effects\n");
SDL_Log("\nUploading effects\n");
/* First we'll try a SINE effect. */
if (supported & SDL_HAPTIC_SINE) {
printf(" effect %d: Sine Wave\n", nefx);
SDL_Log(" effect %d: Sine Wave\n", nefx);
efx[nefx].type = SDL_HAPTIC_SINE;
efx[nefx].periodic.period = 1000;
efx[nefx].periodic.magnitude = 0x4000;
@@ -137,14 +139,14 @@ main(int argc, char **argv)
efx[nefx].periodic.fade_length = 1000;
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) {
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
abort_execution();
}
nefx++;
}
/* Now we'll try a SAWTOOTHUP */
if (supported & SDL_HAPTIC_SAWTOOTHUP) {
printf(" effect %d: Sawtooth Up\n", nefx);
SDL_Log(" effect %d: Sawtooth Up\n", nefx);
efx[nefx].type = SDL_HAPTIC_SAWTOOTHUP;
efx[nefx].periodic.period = 500;
efx[nefx].periodic.magnitude = 0x5000;
@@ -153,14 +155,14 @@ main(int argc, char **argv)
efx[nefx].periodic.fade_length = 1000;
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) {
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
abort_execution();
}
nefx++;
}
/* Now the classical constant effect. */
if (supported & SDL_HAPTIC_CONSTANT) {
printf(" effect %d: Constant Force\n", nefx);
SDL_Log(" effect %d: Constant Force\n", nefx);
efx[nefx].type = SDL_HAPTIC_CONSTANT;
efx[nefx].constant.direction.type = SDL_HAPTIC_POLAR;
efx[nefx].constant.direction.dir[0] = 20000; /* Force comes from the south-west. */
@@ -170,14 +172,14 @@ main(int argc, char **argv)
efx[nefx].constant.fade_length = 1000;
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) {
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
abort_execution();
}
nefx++;
}
/* The cute spring effect. */
if (supported & SDL_HAPTIC_SPRING) {
printf(" effect %d: Condition Spring\n", nefx);
SDL_Log(" effect %d: Condition Spring\n", nefx);
efx[nefx].type = SDL_HAPTIC_SPRING;
efx[nefx].condition.length = 5000;
for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
@@ -189,14 +191,14 @@ main(int argc, char **argv)
}
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) {
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
abort_execution();
}
nefx++;
}
/* The pretty awesome inertia effect. */
if (supported & SDL_HAPTIC_INERTIA) {
printf(" effect %d: Condition Inertia\n", nefx);
SDL_Log(" effect %d: Condition Inertia\n", nefx);
efx[nefx].type = SDL_HAPTIC_SPRING;
efx[nefx].condition.length = 5000;
for (i = 0; i < SDL_HapticNumAxes(haptic); i++) {
@@ -207,7 +209,7 @@ main(int argc, char **argv)
}
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) {
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
abort_execution();
}
nefx++;
@@ -215,24 +217,24 @@ main(int argc, char **argv)
/* Finally we'll try a left/right effect. */
if (supported & SDL_HAPTIC_LEFTRIGHT) {
printf(" effect %d: Left/Right\n", nefx);
SDL_Log(" effect %d: Left/Right\n", nefx);
efx[nefx].type = SDL_HAPTIC_LEFTRIGHT;
efx[nefx].leftright.length = 5000;
efx[nefx].leftright.large_magnitude = 0x3000;
efx[nefx].leftright.small_magnitude = 0xFFFF;
id[nefx] = SDL_HapticNewEffect(haptic, &efx[nefx]);
if (id[nefx] < 0) {
printf("UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "UPLOADING EFFECT ERROR: %s\n", SDL_GetError());
abort_execution();
}
nefx++;
}
printf
SDL_Log
("\nNow playing effects for 5 seconds each with 1 second delay between\n");
for (i = 0; i < nefx; i++) {
printf(" Playing effect %d\n", i);
SDL_Log(" Playing effect %d\n", i);
SDL_HapticRunEffect(haptic, id[i], 1);
SDL_Delay(6000); /* Effects only have length 5000 */
}
@@ -252,7 +254,7 @@ main(int argc, char **argv)
static void
abort_execution(void)
{
printf("\nAborting program execution.\n");
SDL_Log("\nAborting program execution.\n");
SDL_HapticClose(haptic);
SDL_Quit();
@@ -270,42 +272,42 @@ HapticPrintSupported(SDL_Haptic * haptic)
unsigned int supported;
supported = SDL_HapticQuery(haptic);
printf(" Supported effects [%d effects, %d playing]:\n",
SDL_Log(" Supported effects [%d effects, %d playing]:\n",
SDL_HapticNumEffects(haptic), SDL_HapticNumEffectsPlaying(haptic));
if (supported & SDL_HAPTIC_CONSTANT)
printf(" constant\n");
SDL_Log(" constant\n");
if (supported & SDL_HAPTIC_SINE)
printf(" sine\n");
SDL_Log(" sine\n");
/* !!! FIXME: put this back when we have more bits in 2.1 */
/*if (supported & SDL_HAPTIC_SQUARE)
printf(" square\n");*/
/* if (supported & SDL_HAPTIC_SQUARE)
SDL_Log(" square\n"); */
if (supported & SDL_HAPTIC_TRIANGLE)
printf(" triangle\n");
SDL_Log(" triangle\n");
if (supported & SDL_HAPTIC_SAWTOOTHUP)
printf(" sawtoothup\n");
SDL_Log(" sawtoothup\n");
if (supported & SDL_HAPTIC_SAWTOOTHDOWN)
printf(" sawtoothdown\n");
SDL_Log(" sawtoothdown\n");
if (supported & SDL_HAPTIC_RAMP)
printf(" ramp\n");
SDL_Log(" ramp\n");
if (supported & SDL_HAPTIC_FRICTION)
printf(" friction\n");
SDL_Log(" friction\n");
if (supported & SDL_HAPTIC_SPRING)
printf(" spring\n");
SDL_Log(" spring\n");
if (supported & SDL_HAPTIC_DAMPER)
printf(" damper\n");
SDL_Log(" damper\n");
if (supported & SDL_HAPTIC_INERTIA)
printf(" intertia\n");
SDL_Log(" inertia\n");
if (supported & SDL_HAPTIC_CUSTOM)
printf(" custom\n");
SDL_Log(" custom\n");
if (supported & SDL_HAPTIC_LEFTRIGHT)
printf(" left/right\n");
printf(" Supported capabilities:\n");
SDL_Log(" left/right\n");
SDL_Log(" Supported capabilities:\n");
if (supported & SDL_HAPTIC_GAIN)
printf(" gain\n");
SDL_Log(" gain\n");
if (supported & SDL_HAPTIC_AUTOCENTER)
printf(" autocenter\n");
SDL_Log(" autocenter\n");
if (supported & SDL_HAPTIC_STATUS)
printf(" status\n");
SDL_Log(" status\n");
}
#else
@@ -313,7 +315,7 @@ HapticPrintSupported(SDL_Haptic * haptic)
int
main(int argc, char *argv[])
{
fprintf(stderr, "SDL compiled without Haptic support.\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Haptic support.\n");
exit(1);
}

View File

@@ -49,12 +49,15 @@ main(int argc, char *argv[])
FILE *file;
int errors = 0;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (!argv[1]) {
argv[1] = "utf8.txt";
}
file = fopen(argv[1], "rb");
if (!file) {
fprintf(stderr, "Unable to open %s\n", argv[1]);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", argv[1]);
return (1);
}
@@ -69,15 +72,11 @@ main(int argc, char *argv[])
test[0] = SDL_iconv_string(formats[i], "UCS-4", ucs4, len);
test[1] = SDL_iconv_string("UCS-4", formats[i], test[0], len);
if (!test[1] || SDL_memcmp(test[1], ucs4, len) != 0) {
fprintf(stderr, "FAIL: %s\n", formats[i]);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "FAIL: %s\n", formats[i]);
++errors;
}
if (test[0]) {
SDL_free(test[0]);
}
if (test[1]) {
SDL_free(test[1]);
}
SDL_free(test[0]);
SDL_free(test[1]);
}
test[0] = SDL_iconv_string("UTF-8", "UCS-4", ucs4, len);
SDL_free(ucs4);

View File

@@ -80,7 +80,7 @@ char *utf8_advance(char *p, size_t distance)
void usage()
{
printf("usage: testime [--font fontfile]\n");
SDL_Log("usage: testime [--font fontfile]\n");
exit(0);
}
@@ -135,7 +135,7 @@ void _Redraw(SDL_Renderer * renderer) {
markedRect.w = textRect.w - w;
if (markedRect.w < 0)
{
// Stop text input because we cannot hold any more characters
/* Stop text input because we cannot hold any more characters */
SDL_StopTextInput();
return;
}
@@ -196,6 +196,8 @@ void Redraw() {
int i;
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
if (state->windows[i] == NULL)
continue;
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
@@ -210,6 +212,9 @@ int main(int argc, char *argv[]) {
SDL_Event event;
const char *fontname = DEFAULT_FONT;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
@@ -251,12 +256,12 @@ int main(int argc, char *argv[]) {
font = TTF_OpenFont(fontname, DEFAULT_PTSIZE);
if (! font)
{
fprintf(stderr, "Failed to find font: %s\n", TTF_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to find font: %s\n", TTF_GetError());
exit(-1);
}
#endif
printf("Using font: %s\n", fontname);
SDL_Log("Using font: %s\n", fontname);
atexit(SDL_Quit);
InitInput();
@@ -321,33 +326,32 @@ int main(int argc, char *argv[]) {
break;
}
fprintf(stderr,
"Keyboard: scancode 0x%08X = %s, keycode 0x%08X = %s\n",
SDL_Log("Keyboard: scancode 0x%08X = %s, keycode 0x%08X = %s\n",
event.key.keysym.scancode,
SDL_GetScancodeName(event.key.keysym.scancode),
event.key.keysym.sym, SDL_GetKeyName(event.key.keysym.sym));
break;
case SDL_TEXTINPUT:
if (SDL_strlen(event.text.text) == 0 || event.text.text[0] == '\n' ||
if (event.text.text[0] == '\0' || event.text.text[0] == '\n' ||
markedRect.w < 0)
break;
fprintf(stderr, "Keyboard: text input \"%s\"\n", event.text.text);
SDL_Log("Keyboard: text input \"%s\"\n", event.text.text);
if (SDL_strlen(text) + SDL_strlen(event.text.text) < sizeof(text))
SDL_strlcat(text, event.text.text, sizeof(text));
fprintf(stderr, "text inputed: %s\n", text);
SDL_Log("text inputed: %s\n", text);
// After text inputed, we can clear up markedText because it
// is committed
/* After text inputed, we can clear up markedText because it */
/* is committed */
markedText[0] = 0;
Redraw();
break;
case SDL_TEXTEDITING:
fprintf(stderr, "text editing \"%s\", selected range (%d, %d)\n",
SDL_Log("text editing \"%s\", selected range (%d, %d)\n",
event.edit.text, event.edit.start, event.edit.length);
strcpy(markedText, event.edit.text);

View File

@@ -84,7 +84,7 @@ add_line(int x1, int y1, int x2, int y2)
if ((x1 == x2) && (y1 == y2))
return 0;
printf("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2);
SDL_Log("adding line (%d, %d), (%d, %d)\n", x1, y1, x2, y2);
lines[num_lines].x = x1;
lines[num_lines].y = y1;
lines[num_lines].w = x2;
@@ -133,7 +133,7 @@ add_rect(int x1, int y1, int x2, int y2)
if (y1 > y2)
SWAP(int, y1, y2);
printf("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2,
SDL_Log("adding rect (%d, %d), (%d, %d) [%dx%d]\n", x1, y1, x2, y2,
x2 - x1, y2 - y1);
rects[num_rects].x = x1;
@@ -199,6 +199,9 @@ main(int argc, char *argv[])
SDL_Event event;
Uint32 then, now, frames;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize parameters */
num_objects = NUM_OBJECTS;
@@ -241,8 +244,7 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
fprintf(stderr,
"Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
argv[0], SDLTest_CommonUsage(state));
return 1;
}
@@ -308,6 +310,8 @@ main(int argc, char *argv[])
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
if (state->windows[i] == NULL)
continue;
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
@@ -327,7 +331,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
printf("%2.2f frames per second\n", fps);
SDL_Log("%2.2f frames per second\n", fps);
}
return 0;
}

View File

@@ -52,13 +52,13 @@ WatchJoystick(SDL_Joystick * joystick)
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
SCREEN_HEIGHT, 0);
if (window == NULL) {
fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
return SDL_FALSE;
}
screen = SDL_CreateRenderer(window, -1, 0);
if (screen == NULL) {
fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
SDL_DestroyWindow(window);
return SDL_FALSE;
}
@@ -70,9 +70,9 @@ WatchJoystick(SDL_Joystick * joystick)
/* Print info about the joystick we are watching */
name = SDL_JoystickName(joystick);
printf("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
name ? name : "Unknown Joystick");
printf("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
SDL_Log("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
SDL_JoystickNumAxes(joystick), SDL_JoystickNumHats(joystick),
SDL_JoystickNumBalls(joystick), SDL_JoystickNumButtons(joystick));
@@ -85,36 +85,36 @@ WatchJoystick(SDL_Joystick * joystick)
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_JOYAXISMOTION:
printf("Joystick %d axis %d value: %d\n",
SDL_Log("Joystick %d axis %d value: %d\n",
event.jaxis.which,
event.jaxis.axis, event.jaxis.value);
break;
case SDL_JOYHATMOTION:
printf("Joystick %d hat %d value:",
SDL_Log("Joystick %d hat %d value:",
event.jhat.which, event.jhat.hat);
if (event.jhat.value == SDL_HAT_CENTERED)
printf(" centered");
SDL_Log(" centered");
if (event.jhat.value & SDL_HAT_UP)
printf(" up");
SDL_Log(" up");
if (event.jhat.value & SDL_HAT_RIGHT)
printf(" right");
SDL_Log(" right");
if (event.jhat.value & SDL_HAT_DOWN)
printf(" down");
SDL_Log(" down");
if (event.jhat.value & SDL_HAT_LEFT)
printf(" left");
printf("\n");
SDL_Log(" left");
SDL_Log("\n");
break;
case SDL_JOYBALLMOTION:
printf("Joystick %d ball %d delta: (%d,%d)\n",
SDL_Log("Joystick %d ball %d delta: (%d,%d)\n",
event.jball.which,
event.jball.ball, event.jball.xrel, event.jball.yrel);
break;
case SDL_JOYBUTTONDOWN:
printf("Joystick %d button %d down\n",
SDL_Log("Joystick %d button %d down\n",
event.jbutton.which, event.jbutton.button);
break;
case SDL_JOYBUTTONUP:
printf("Joystick %d button %d up\n",
SDL_Log("Joystick %d button %d up\n",
event.jbutton.which, event.jbutton.button);
break;
case SDL_KEYDOWN:
@@ -211,31 +211,34 @@ main(int argc, char *argv[])
int i;
SDL_Joystick *joystick;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL (Note: video is required to start event loop) */
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}
/* Print information about the joysticks */
printf("There are %d joysticks attached\n", SDL_NumJoysticks());
SDL_Log("There are %d joysticks attached\n", SDL_NumJoysticks());
for (i = 0; i < SDL_NumJoysticks(); ++i) {
name = SDL_JoystickNameForIndex(i);
printf("Joystick %d: %s\n", i, name ? name : "Unknown Joystick");
SDL_Log("Joystick %d: %s\n", i, name ? name : "Unknown Joystick");
joystick = SDL_JoystickOpen(i);
if (joystick == NULL) {
fprintf(stderr, "SDL_JoystickOpen(%d) failed: %s\n", i,
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i,
SDL_GetError());
} else {
char guid[64];
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick),
guid, sizeof (guid));
printf(" axes: %d\n", SDL_JoystickNumAxes(joystick));
printf(" balls: %d\n", SDL_JoystickNumBalls(joystick));
printf(" hats: %d\n", SDL_JoystickNumHats(joystick));
printf(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
printf("instance id: %d\n", SDL_JoystickInstanceID(joystick));
printf(" guid: %s\n", guid);
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick));
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick));
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick));
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
SDL_Log(" guid: %s\n", guid);
SDL_JoystickClose(joystick);
}
}
@@ -256,7 +259,7 @@ main(int argc, char *argv[])
while ( keepGoing ) {
if (joystick == NULL) {
if ( !reportederror ) {
printf("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError());
SDL_Log("Couldn't open joystick %d: %s\n", atoi(argv[1]), SDL_GetError());
keepGoing = SDL_FALSE;
reportederror = SDL_TRUE;
}
@@ -268,7 +271,7 @@ main(int argc, char *argv[])
joystick = NULL;
if (keepGoing) {
printf("Waiting for attach\n");
SDL_Log("Waiting for attach\n");
}
while (keepGoing) {
SDL_WaitEvent(&event);
@@ -296,7 +299,7 @@ main(int argc, char *argv[])
int
main(int argc, char *argv[])
{
fprintf(stderr, "SDL compiled without Joystick support.\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick support.\n");
exit(1);
}

View File

@@ -24,12 +24,15 @@ main(int argc, char *argv[])
{
SDL_Scancode scancode;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}
for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
printf("Scancode #%d, \"%s\"\n", scancode,
SDL_Log("Scancode #%d, \"%s\"\n", scancode,
SDL_GetScancodeName(scancode));
}
SDL_Quit();

View File

@@ -33,14 +33,14 @@ main(int argc, char *argv[])
if (argc != 3) {
const char *app = argv[0];
fprintf(stderr, "USAGE: %s <library> <functionname>\n", app);
fprintf(stderr, " %s --hello <lib with puts()>\n", app);
SDL_Log("USAGE: %s <library> <functionname>\n", app);
SDL_Log(" %s --hello <lib with puts()>\n", app);
return 1;
}
/* Initialize SDL */
if (SDL_Init(0) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 2;
}
@@ -55,23 +55,23 @@ main(int argc, char *argv[])
lib = SDL_LoadObject(libname);
if (lib == NULL) {
fprintf(stderr, "SDL_LoadObject('%s') failed: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadObject('%s') failed: %s\n",
libname, SDL_GetError());
retval = 3;
} else {
fn = (fntype) SDL_LoadFunction(lib, symname);
if (fn == NULL) {
fprintf(stderr, "SDL_LoadFunction('%s') failed: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadFunction('%s') failed: %s\n",
symname, SDL_GetError());
retval = 4;
} else {
printf("Found %s in %s at %p\n", symname, libname, fn);
SDL_Log("Found %s in %s at %p\n", symname, libname, fn);
if (hello) {
printf("Calling function...\n");
SDL_Log("Calling function...\n");
fflush(stdout);
fn(" HELLO, WORLD!\n");
printf("...apparently, we survived. :)\n");
printf("Unloading library...\n");
SDL_Log("...apparently, we survived. :)\n");
SDL_Log("Unloading library...\n");
fflush(stdout);
}
}

View File

@@ -40,7 +40,7 @@ SDL_Quit_Wrapper(void)
void
printid(void)
{
printf("Process %lu: exiting\n", SDL_ThreadID());
SDL_Log("Process %lu: exiting\n", SDL_ThreadID());
}
void
@@ -55,7 +55,7 @@ closemutex(int sig)
{
SDL_threadID id = SDL_ThreadID();
int i;
printf("Process %lu: Cleaning up...\n", id == mainthread ? 0 : id);
SDL_Log("Process %lu: Cleaning up...\n", id == mainthread ? 0 : id);
doterminate = 1;
for (i = 0; i < 6; ++i)
SDL_WaitThread(threads[i], NULL);
@@ -69,23 +69,23 @@ Run(void *data)
if (SDL_ThreadID() == mainthread)
signal(SIGTERM, closemutex);
while (!doterminate) {
printf("Process %lu ready to work\n", SDL_ThreadID());
SDL_Log("Process %lu ready to work\n", SDL_ThreadID());
if (SDL_LockMutex(mutex) < 0) {
fprintf(stderr, "Couldn't lock mutex: %s", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock mutex: %s", SDL_GetError());
exit(1);
}
printf("Process %lu, working!\n", SDL_ThreadID());
SDL_Log("Process %lu, working!\n", SDL_ThreadID());
SDL_Delay(1 * 1000);
printf("Process %lu, done!\n", SDL_ThreadID());
SDL_Log("Process %lu, done!\n", SDL_ThreadID());
if (SDL_UnlockMutex(mutex) < 0) {
fprintf(stderr, "Couldn't unlock mutex: %s", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't unlock mutex: %s", SDL_GetError());
exit(1);
}
/* If this sleep isn't done, then threads may starve */
SDL_Delay(10);
}
if (SDL_ThreadID() == mainthread && doterminate) {
printf("Process %lu: raising SIGTERM\n", SDL_ThreadID());
SDL_Log("Process %lu: raising SIGTERM\n", SDL_ThreadID());
raise(SIGTERM);
}
return (0);
@@ -97,26 +97,29 @@ main(int argc, char *argv[])
int i;
int maxproc = 6;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(0) < 0) {
fprintf(stderr, "%s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit_Wrapper);
if ((mutex = SDL_CreateMutex()) == NULL) {
fprintf(stderr, "Couldn't create mutex: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create mutex: %s\n", SDL_GetError());
exit(1);
}
mainthread = SDL_ThreadID();
printf("Main thread: %lu\n", mainthread);
SDL_Log("Main thread: %lu\n", mainthread);
atexit(printid);
for (i = 0; i < maxproc; ++i) {
char name[64];
SDL_snprintf(name, sizeof (name), "Worker%d", i);
if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL)
fprintf(stderr, "Couldn't create thread!\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread!\n");
}
signal(SIGINT, terminate);
Run(NULL);

View File

@@ -10,7 +10,7 @@
freely.
*/
/* Simple test of the SDL MessageBox API*/
/* Simple test of the SDL MessageBox API */
#include <stdio.h>
#include <stdlib.h>
@@ -46,12 +46,12 @@ button_messagebox(void *eventNumber)
SDL_MessageBoxData data = {
SDL_MESSAGEBOX_INFORMATION,
NULL, // no parent window
NULL, /* no parent window */
"Custom MessageBox",
"This is a custom messagebox",
2,
buttons,
NULL // Default color scheme
NULL /* Default color scheme */
};
int button = -1;
@@ -62,7 +62,7 @@ button_messagebox(void *eventNumber)
success = SDL_ShowMessageBox(&data, &button);
if (success == -1) {
printf("Error Presenting MessageBox: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
if (eventNumber) {
SDL_UserEvent event;
event.type = (intptr_t)eventNumber;
@@ -72,7 +72,7 @@ button_messagebox(void *eventNumber)
quit(2);
}
}
printf("Pressed button: %d, %s\n", button, button == 1 ? "Cancel" : "OK");
SDL_Log("Pressed button: %d, %s\n", button, button == 1 ? "Cancel" : "OK");
if (eventNumber) {
SDL_UserEvent event;
@@ -88,12 +88,15 @@ main(int argc, char *argv[])
{
int success;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Simple MessageBox",
"This is a simple error MessageBox",
NULL);
if (success == -1) {
printf("Error Presenting MessageBox: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);
}
@@ -102,7 +105,7 @@ main(int argc, char *argv[])
"This is a simple MessageBox with a newline:\r\nHello world!",
NULL);
if (success == -1) {
printf("Error Presenting MessageBox: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);
}
@@ -112,7 +115,7 @@ main(int argc, char *argv[])
"Unicode text: '牛肉西蘭花' ...",
NULL);
if (success == -1) {
printf("Error Presenting MessageBox: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);
}
@@ -122,7 +125,7 @@ main(int argc, char *argv[])
"Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'",
NULL);
if (success == -1) {
printf("Error Presenting MessageBox: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);
}
@@ -135,7 +138,7 @@ main(int argc, char *argv[])
subsystem on the main thread.
*/
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError());
return (1);
}
{
@@ -153,7 +156,7 @@ main(int argc, char *argv[])
SDL_WaitThread(thread, &status);
printf("Message box thread return %i\n", status);
SDL_Log("Message box thread return %i\n", status);
}
/* Test showing a message box with a parent window */
@@ -166,7 +169,7 @@ main(int argc, char *argv[])
"This is a simple error MessageBox with a parent window",
window);
if (success == -1) {
printf("Error Presenting MessageBox: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
quit(1);
}

View File

@@ -10,7 +10,6 @@
freely.
*/
#include "SDL.h"
#include <stdio.h>
static SDL_AudioSpec spec;
static Uint8 *sound = NULL; /* Pointer to wave data */
@@ -51,7 +50,7 @@ test_multi_audio(int devcount)
int i;
if (devcount > 64) {
fprintf(stderr, "Too many devices (%d), clamping to 64...\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Too many devices (%d), clamping to 64...\n",
devcount);
devcount = 64;
}
@@ -60,33 +59,33 @@ test_multi_audio(int devcount)
for (i = 0; i < devcount; i++) {
const char *devname = SDL_GetAudioDeviceName(i, 0);
printf("playing on device #%d: ('%s')...", i, devname);
SDL_Log("playing on device #%d: ('%s')...", i, devname);
fflush(stdout);
SDL_memset(&cbd[0], '\0', sizeof(callback_data));
spec.userdata = &cbd[0];
cbd[0].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
if (cbd[0].dev == 0) {
printf("\nOpen device failed: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device failed: %s\n", SDL_GetError());
} else {
SDL_PauseAudioDevice(cbd[0].dev, 0);
while (!cbd[0].done)
SDL_Delay(100);
SDL_PauseAudioDevice(cbd[0].dev, 1);
printf("done.\n");
SDL_Log("done.\n");
SDL_CloseAudioDevice(cbd[0].dev);
}
}
SDL_memset(cbd, '\0', sizeof(cbd));
printf("playing on all devices...\n");
SDL_Log("playing on all devices...\n");
for (i = 0; i < devcount; i++) {
const char *devname = SDL_GetAudioDeviceName(i, 0);
spec.userdata = &cbd[i];
cbd[i].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
if (cbd[i].dev == 0) {
printf("Open device %d failed: %s\n", i, SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Open device %d failed: %s\n", i, SDL_GetError());
}
}
@@ -113,7 +112,7 @@ test_multi_audio(int devcount)
}
}
printf("All done!\n");
SDL_Log("All done!\n");
}
@@ -122,17 +121,20 @@ main(int argc, char **argv)
{
int devcount = 0;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
devcount = SDL_GetNumAudioDevices(0);
if (devcount < 1) {
fprintf(stderr, "Don't see any specific audio devices!\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!\n");
} else {
if (argv[1] == NULL) {
argv[1] = "sample.wav";
@@ -140,7 +142,7 @@ main(int argc, char **argv)
/* Load the wave file into memory */
if (SDL_LoadWAV(argv[1], &spec, &sound, &soundlen) == NULL) {
fprintf(stderr, "Couldn't load %s: %s\n", argv[1],
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1],
SDL_GetError());
} else {
test_multi_audio(devcount);

View File

@@ -58,7 +58,7 @@ LoadSprite(SDL_Renderer *renderer, char *file)
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return 0;
}
@@ -70,7 +70,7 @@ LoadSprite(SDL_Renderer *renderer, char *file)
/* Create textures from the image */
sprite = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprite) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return 0;
}
@@ -131,8 +131,11 @@ main(int argc, char *argv[])
int sprite_w, sprite_h;
SDL_Event event;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_VideoInit(NULL) < 0) {
fprintf(stderr, "Couldn't initialize SDL video: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video: %s\n",
SDL_GetError());
exit(1);
}
@@ -146,19 +149,19 @@ main(int argc, char *argv[])
}
}
if (!factory) {
fprintf(stderr, "Couldn't find native window code for %s driver\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find native window code for %s driver\n",
driver);
quit(2);
}
printf("Creating native window for %s driver\n", driver);
SDL_Log("Creating native window for %s driver\n", driver);
native_window = factory->CreateNativeWindow(WINDOW_W, WINDOW_H);
if (!native_window) {
fprintf(stderr, "Couldn't create native window\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create native window\n");
quit(3);
}
window = SDL_CreateWindowFrom(native_window);
if (!window) {
fprintf(stderr, "Couldn't create SDL window: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window: %s\n", SDL_GetError());
quit(4);
}
SDL_SetWindowTitle(window, "SDL Native Window Test");
@@ -166,7 +169,7 @@ main(int argc, char *argv[])
/* Create the renderer */
renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) {
fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
quit(5);
}
@@ -185,7 +188,7 @@ main(int argc, char *argv[])
positions = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
velocities = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
if (!positions || !velocities) {
fprintf(stderr, "Out of memory!\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);
}
srand(time(NULL));

View File

@@ -209,19 +209,18 @@ ConvertRGBtoYV12(Uint8 *rgb, Uint8 *out, int w, int h,
static void
PrintUsage(char *argv0)
{
fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0);
fprintf(stderr, "\n");
fprintf(stderr, "Where 'arg' is any of the following options:\n");
fprintf(stderr, "\n");
fprintf(stderr, " -fps <frames per second>\n");
fprintf(stderr, " -nodelay\n");
fprintf(stderr, " -format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
fprintf(stderr, " -scale <scale factor> (initial scale of the overlay)\n");
fprintf(stderr, " -help (shows this help)\n");
fprintf(stderr, "\n");
fprintf(stderr,
"Press ESC to exit, or SPACE to freeze the movie while application running.\n");
fprintf(stderr, "\n");
SDL_Log("Usage: %s [arg] [arg] [arg] ...\n", argv0);
SDL_Log("\n");
SDL_Log("Where 'arg' is any of the following options:\n");
SDL_Log("\n");
SDL_Log(" -fps <frames per second>\n");
SDL_Log(" -nodelay\n");
SDL_Log(" -format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n");
SDL_Log(" -scale <scale factor> (initial scale of the overlay)\n");
SDL_Log(" -help (shows this help)\n");
SDL_Log("\n");
SDL_Log("Press ESC to exit, or SPACE to freeze the movie while application running.\n");
SDL_Log("\n");
}
int
@@ -246,8 +245,11 @@ main(int argc, char **argv)
int scale = 5;
SDL_bool done = SDL_FALSE;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 3;
}
@@ -256,19 +258,19 @@ main(int argc, char **argv)
if (argv[2]) {
fps = atoi(argv[2]);
if (fps == 0) {
fprintf(stderr,
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
quit(10);
}
if ((fps < 0) || (fps > 1000)) {
fprintf(stderr,
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -fps option must be in range from 1 to 1000, default is 12.\n");
quit(10);
}
argv += 2;
argc -= 2;
} else {
fprintf(stderr,
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
quit(10);
}
@@ -280,19 +282,19 @@ main(int argc, char **argv)
if (argv[2]) {
scale = atoi(argv[2]);
if (scale == 0) {
fprintf(stderr,
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -scale option requires an argument [from 1 to 50], default is 5.\n");
quit(10);
}
if ((scale < 0) || (scale > 50)) {
fprintf(stderr,
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -scale option must be in range from 1 to 50, default is 5.\n");
quit(10);
}
argv += 2;
argc -= 2;
} else {
fprintf(stderr,
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"The -fps option requires an argument [from 1 to 1000], default is 12.\n");
quit(10);
}
@@ -301,7 +303,7 @@ main(int argc, char **argv)
PrintUsage(argv[0]);
quit(0);
} else {
fprintf(stderr, "Unrecognized option: %s.\n", argv[1]);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unrecognized option: %s.\n", argv[1]);
quit(10);
}
break;
@@ -309,7 +311,7 @@ main(int argc, char **argv)
RawMooseData = (Uint8 *) malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
if (RawMooseData == NULL) {
fprintf(stderr, "Can't allocate memory for movie !\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't allocate memory for movie !\n");
free(RawMooseData);
quit(1);
}
@@ -317,7 +319,7 @@ main(int argc, char **argv)
/* load the trojan moose images */
handle = SDL_RWFromFile("moose.dat", "rb");
if (handle == NULL) {
fprintf(stderr, "Can't find the file moose.dat !\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
free(RawMooseData);
quit(2);
}
@@ -335,26 +337,26 @@ main(int argc, char **argv)
window_w, window_h,
SDL_WINDOW_RESIZABLE);
if (!window) {
fprintf(stderr, "Couldn't set create window: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
free(RawMooseData);
quit(4);
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) {
fprintf(stderr, "Couldn't set create renderer: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
free(RawMooseData);
quit(4);
}
MooseTexture = SDL_CreateTexture(renderer, pixel_format, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
if (!MooseTexture) {
fprintf(stderr, "Couldn't set create texture: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
free(RawMooseData);
quit(5);
}
/* Uncomment this to check vertex color with a YUV texture */
/*SDL_SetTextureColorMod(MooseTexture, 0xff, 0x80, 0x80);*/
/* SDL_SetTextureColorMod(MooseTexture, 0xff, 0x80, 0x80); */
for (i = 0; i < MOOSEFRAMES_COUNT; i++) {
Uint8 MooseFrameRGB[MOOSEFRAME_SIZE*3];

View File

@@ -35,30 +35,30 @@ TestTypes(SDL_bool verbose)
if (badsize(sizeof(Uint8), 1)) {
if (verbose)
printf("sizeof(Uint8) != 1, instead = %u\n",
SDL_Log("sizeof(Uint8) != 1, instead = %u\n",
(unsigned int)sizeof(Uint8));
++error;
}
if (badsize(sizeof(Uint16), 2)) {
if (verbose)
printf("sizeof(Uint16) != 2, instead = %u\n",
SDL_Log("sizeof(Uint16) != 2, instead = %u\n",
(unsigned int)sizeof(Uint16));
++error;
}
if (badsize(sizeof(Uint32), 4)) {
if (verbose)
printf("sizeof(Uint32) != 4, instead = %u\n",
SDL_Log("sizeof(Uint32) != 4, instead = %u\n",
(unsigned int)sizeof(Uint32));
++error;
}
if (badsize(sizeof(Uint64), 8)) {
if (verbose)
printf("sizeof(Uint64) != 8, instead = %u\n",
SDL_Log("sizeof(Uint64) != 8, instead = %u\n",
(unsigned int)sizeof(Uint64));
++error;
}
if (verbose && !error)
printf("All data types are the expected size.\n");
SDL_Log("All data types are the expected size.\n");
return (error ? 1 : 0);
}
@@ -83,7 +83,7 @@ TestEndian(SDL_bool verbose)
swapped64 |= 0xDEADBEEF;
if (verbose) {
printf("Detected a %s endian machine.\n",
SDL_Log("Detected a %s endian machine.\n",
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big");
}
if ((*((char *) &value) >> 4) == 0x1) {
@@ -93,44 +93,44 @@ TestEndian(SDL_bool verbose)
}
if (real_byteorder != SDL_BYTEORDER) {
if (verbose) {
printf("Actually a %s endian machine!\n",
SDL_Log("Actually a %s endian machine!\n",
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big");
}
++error;
}
if (verbose) {
printf("Value 16 = 0x%X, swapped = 0x%X\n", value16,
SDL_Log("Value 16 = 0x%X, swapped = 0x%X\n", value16,
SDL_Swap16(value16));
}
if (SDL_Swap16(value16) != swapped16) {
if (verbose) {
printf("16 bit value swapped incorrectly!\n");
SDL_Log("16 bit value swapped incorrectly!\n");
}
++error;
}
if (verbose) {
printf("Value 32 = 0x%X, swapped = 0x%X\n", value32,
SDL_Log("Value 32 = 0x%X, swapped = 0x%X\n", value32,
SDL_Swap32(value32));
}
if (SDL_Swap32(value32) != swapped32) {
if (verbose) {
printf("32 bit value swapped incorrectly!\n");
SDL_Log("32 bit value swapped incorrectly!\n");
}
++error;
}
if (verbose) {
#ifdef _MSC_VER
printf("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64,
SDL_Log("Value 64 = 0x%I64X, swapped = 0x%I64X\n", value64,
SDL_Swap64(value64));
#else
printf("Value 64 = 0x%llX, swapped = 0x%llX\n",
SDL_Log("Value 64 = 0x%llX, swapped = 0x%llX\n",
(unsigned long long) value64,
(unsigned long long) SDL_Swap64(value64));
#endif
}
if (SDL_Swap64(value64) != swapped64) {
if (verbose) {
printf("64 bit value swapped incorrectly!\n");
SDL_Log("64 bit value swapped incorrectly!\n");
}
++error;
}
@@ -142,17 +142,18 @@ int
TestCPUInfo(SDL_bool verbose)
{
if (verbose) {
printf("CPU count: %d\n", SDL_GetCPUCount());
printf("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
printf("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
printf("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected");
printf("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
printf("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected");
printf("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
printf("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
printf("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected");
printf("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected");
printf("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected");
SDL_Log("CPU count: %d\n", SDL_GetCPUCount());
SDL_Log("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
SDL_Log("RDTSC %s\n", SDL_HasRDTSC()? "detected" : "not detected");
SDL_Log("AltiVec %s\n", SDL_HasAltiVec()? "detected" : "not detected");
SDL_Log("MMX %s\n", SDL_HasMMX()? "detected" : "not detected");
SDL_Log("3DNow! %s\n", SDL_Has3DNow()? "detected" : "not detected");
SDL_Log("SSE %s\n", SDL_HasSSE()? "detected" : "not detected");
SDL_Log("SSE2 %s\n", SDL_HasSSE2()? "detected" : "not detected");
SDL_Log("SSE3 %s\n", SDL_HasSSE3()? "detected" : "not detected");
SDL_Log("SSE4.1 %s\n", SDL_HasSSE41()? "detected" : "not detected");
SDL_Log("SSE4.2 %s\n", SDL_HasSSE42()? "detected" : "not detected");
SDL_Log("System RAM %d MB\n", SDL_GetSystemRAM());
}
return (0);
}
@@ -176,7 +177,7 @@ TestAssertions(SDL_bool verbose)
{
const SDL_assert_data *item = SDL_GetAssertionReport();
while (item) {
printf("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n",
SDL_Log("'%s', %s (%s:%d), triggered %u times, always ignore: %s.\n",
item->condition, item->function, item->filename,
item->linenum, item->trigger_count,
item->always_ignore ? "yes" : "no");
@@ -192,11 +193,14 @@ main(int argc, char *argv[])
SDL_bool verbose = SDL_TRUE;
int status = 0;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) {
verbose = SDL_FALSE;
}
if (verbose) {
printf("This system is running %s\n", SDL_GetPlatform());
SDL_Log("This system is running %s\n", SDL_GetPlatform());
}
status += TestTypes(verbose);

View File

@@ -21,7 +21,7 @@ report_power(void)
const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
char *statestr = NULL;
printf("SDL-reported power info...\n");
SDL_Log("SDL-reported power info...\n");
switch (state) {
case SDL_POWERSTATE_UNKNOWN:
statestr = "Unknown";
@@ -43,18 +43,18 @@ report_power(void)
break;
}
printf("State: %s\n", statestr);
SDL_Log("State: %s\n", statestr);
if (percent == -1) {
printf("Percent left: unknown\n");
SDL_Log("Percent left: unknown\n");
} else {
printf("Percent left: %d%%\n", percent);
SDL_Log("Percent left: %d%%\n", percent);
}
if (seconds == -1) {
printf("Time left: unknown\n");
SDL_Log("Time left: unknown\n");
} else {
printf("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
SDL_Log("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
(int) (seconds % 60));
}
}
@@ -63,8 +63,11 @@ report_power(void)
int
main(int argc, char *argv[])
{
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(0) == -1) {
fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
return 1;
}

View File

@@ -35,6 +35,8 @@ main(int argc, char *argv[])
int i, done;
SDL_Event event;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
@@ -74,16 +76,16 @@ main(int argc, char *argv[])
switch(event.type) {
case SDL_MOUSEMOTION:
{
/*printf("mouse motion ABS x %d y %d REL x %d y %d\n",event.motion.x,event.motion.y,event.motion.xrel,event.motion.yrel);*/
rect.x += event.motion.xrel;
rect.y += event.motion.yrel;
}
break;
}
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
if (state->windows[i] == NULL)
continue;
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);

View File

@@ -46,7 +46,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return NULL;
}
@@ -77,7 +77,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
/* Create textures from the image */
texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!texture) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return NULL;
}
@@ -127,7 +127,7 @@ Draw(DrawState *s)
/* Update the screen! */
SDL_RenderPresent(s->renderer);
//SDL_Delay(10);
/* SDL_Delay(10); */
}
int
@@ -139,6 +139,9 @@ main(int argc, char *argv[])
int frames;
Uint32 then, now;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
@@ -149,7 +152,7 @@ main(int argc, char *argv[])
consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) {
fprintf(stderr, "Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
return 1;
}
i += consumed;
@@ -185,6 +188,8 @@ main(int argc, char *argv[])
SDLTest_CommonEvent(state, &event, &done);
}
for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i] == NULL)
continue;
Draw(&drawstates[i]);
}
}
@@ -193,7 +198,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
printf("%2.2f frames per second\n", fps);
SDL_Log("%2.2f frames per second\n", fps);
}
SDL_stack_free(drawstates);

View File

@@ -46,7 +46,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return NULL;
}
@@ -77,7 +77,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
/* Create textures from the image */
texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!texture) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return NULL;
}
@@ -87,7 +87,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
return texture;
}
void
SDL_bool
DrawComposite(DrawState *s)
{
SDL_Rect viewport, R;
@@ -114,7 +114,7 @@ DrawComposite(DrawState *s)
SDL_RenderCopy(s->renderer, A, NULL, NULL);
SDL_RenderReadPixels(s->renderer, NULL, SDL_PIXELFORMAT_ARGB8888, &P, sizeof(P));
printf("Blended pixel: 0x%8.8X\n", P);
SDL_Log("Blended pixel: 0x%8.8X\n", P);
SDL_DestroyTexture(A);
SDL_DestroyTexture(B);
@@ -167,9 +167,10 @@ DrawComposite(DrawState *s)
/* Update the screen! */
SDL_RenderPresent(s->renderer);
return SDL_TRUE;
}
void
SDL_bool
Draw(DrawState *s)
{
SDL_Rect viewport;
@@ -178,6 +179,10 @@ Draw(DrawState *s)
SDL_RenderGetViewport(s->renderer, &viewport);
target = SDL_CreateTexture(s->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, viewport.w, viewport.h);
if (!target) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create render target texture: %s\n", SDL_GetError());
return SDL_FALSE;
}
SDL_SetRenderTarget(s->renderer, target);
/* Draw the background */
@@ -206,6 +211,7 @@ Draw(DrawState *s)
/* Update the screen! */
SDL_RenderPresent(s->renderer);
return SDL_TRUE;
}
int
@@ -218,6 +224,9 @@ main(int argc, char *argv[])
Uint32 then, now;
SDL_bool test_composite = SDL_FALSE;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
@@ -235,8 +244,7 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
fprintf(stderr,
"Usage: %s %s [--composite]\n",
SDL_Log("Usage: %s %s [--composite]\n",
argv[0], SDLTest_CommonUsage(state));
quit(1);
}
@@ -277,10 +285,12 @@ main(int argc, char *argv[])
SDLTest_CommonEvent(state, &event, &done);
}
for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i] == NULL)
continue;
if (test_composite) {
DrawComposite(&drawstates[i]);
if (!DrawComposite(&drawstates[i])) done = 1;
} else {
Draw(&drawstates[i]);
if (!Draw(&drawstates[i])) done = 1;
}
}
}
@@ -289,7 +299,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
printf("%2.2f frames per second\n", fps);
SDL_Log("%2.2f frames per second\n", fps);
}
SDL_stack_free(drawstates);

View File

@@ -9,7 +9,7 @@
including commercial applications, and to alter it and redistribute it
freely.
*/
#include <stdio.h>
#include "SDL.h"
int
@@ -25,27 +25,30 @@ main(int argc, char **argv)
int avgbytes = 0;
SDL_RWops *io = NULL;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (argc != 4) {
fprintf(stderr, "USAGE: %s in.wav out.wav newfreq\n", argv[0]);
SDL_Log("USAGE: %s in.wav out.wav newfreq\n", argv[0]);
return 1;
}
cvtfreq = SDL_atoi(argv[3]);
if (SDL_Init(SDL_INIT_AUDIO) == -1) {
fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
return 2;
}
if (SDL_LoadWAV(argv[1], &spec, &data, &len) == NULL) {
fprintf(stderr, "failed to load %s: %s\n", argv[1], SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to load %s: %s\n", argv[1], SDL_GetError());
SDL_Quit();
return 3;
}
if (SDL_BuildAudioCVT(&cvt, spec.format, spec.channels, spec.freq,
spec.format, spec.channels, cvtfreq) == -1) {
fprintf(stderr, "failed to build CVT: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to build CVT: %s\n", SDL_GetError());
SDL_FreeWAV(data);
SDL_Quit();
return 4;
@@ -54,7 +57,7 @@ main(int argc, char **argv)
cvt.len = len;
cvt.buf = (Uint8 *) SDL_malloc(len * cvt.len_mult);
if (cvt.buf == NULL) {
fprintf(stderr, "Out of memory.\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory.\n");
SDL_FreeWAV(data);
SDL_Quit();
return 5;
@@ -62,7 +65,7 @@ main(int argc, char **argv)
SDL_memcpy(cvt.buf, data, len);
if (SDL_ConvertAudio(&cvt) == -1) {
fprintf(stderr, "Conversion failed: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Conversion failed: %s\n", SDL_GetError());
SDL_free(cvt.buf);
SDL_FreeWAV(data);
SDL_Quit();
@@ -72,7 +75,7 @@ main(int argc, char **argv)
/* write out a WAV header... */
io = SDL_RWFromFile(argv[2], "wb");
if (io == NULL) {
fprintf(stderr, "fopen('%s') failed: %s\n", argv[2], SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "fopen('%s') failed: %s\n", argv[2], SDL_GetError());
SDL_free(cvt.buf);
SDL_FreeWAV(data);
SDL_Quit();
@@ -99,17 +102,17 @@ main(int argc, char **argv)
SDL_RWwrite(io, cvt.buf, cvt.len_cvt, 1);
if (SDL_RWclose(io) == -1) {
fprintf(stderr, "fclose('%s') failed: %s\n", argv[2], SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "fclose('%s') failed: %s\n", argv[2], SDL_GetError());
SDL_free(cvt.buf);
SDL_FreeWAV(data);
SDL_Quit();
return 8;
} // if
} /* if */
SDL_free(cvt.buf);
SDL_FreeWAV(data);
SDL_Quit();
return 0;
} // main
} /* main */
// end of resample_test.c ...
/* end of resample_test.c ... */

View File

@@ -26,7 +26,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* includes
*/
#include <stdlib.h>
#include <stdio.h> /* printf */
#include <string.h> /* strstr */
#include <ctype.h> /* isdigit */
@@ -51,12 +50,15 @@ main(int argc, char **argv)
char *name;
int index;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
name = NULL;
index = -1;
if (argc > 1) {
name = argv[1];
if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
printf("USAGE: %s [device]\n"
SDL_Log("USAGE: %s [device]\n"
"If device is a two-digit number it'll use it as an index, otherwise\n"
"it'll use it as if it were part of the device's name.\n",
argv[0]);
@@ -73,7 +75,7 @@ main(int argc, char **argv)
/* Initialize the force feedbackness */
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK |
SDL_INIT_HAPTIC);
printf("%d Haptic devices detected.\n", SDL_NumHaptics());
SDL_Log("%d Haptic devices detected.\n", SDL_NumHaptics());
if (SDL_NumHaptics() > 0) {
/* We'll just use index or the first force feedback device found */
if (name == NULL) {
@@ -87,7 +89,7 @@ main(int argc, char **argv)
}
if (i >= SDL_NumHaptics()) {
printf("Unable to find device matching '%s', aborting.\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n",
name);
return 1;
}
@@ -95,13 +97,13 @@ main(int argc, char **argv)
haptic = SDL_HapticOpen(i);
if (haptic == NULL) {
printf("Unable to create the haptic device: %s\n",
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
SDL_GetError());
return 1;
}
printf("Device: %s\n", SDL_HapticName(i));
SDL_Log("Device: %s\n", SDL_HapticName(i));
} else {
printf("No Haptic devices found!\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
return 1;
}
@@ -109,25 +111,25 @@ main(int argc, char **argv)
SDL_ClearError();
if (SDL_HapticRumbleSupported(haptic) == SDL_FALSE) {
printf("\nRumble not supported!\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Rumble not supported!\n");
return 1;
}
if (SDL_HapticRumbleInit(haptic) != 0) {
printf("\nFailed to initialize rumble: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize rumble: %s\n", SDL_GetError());
return 1;
}
printf("Playing 2 second rumble at 0.5 magnitude.\n");
SDL_Log("Playing 2 second rumble at 0.5 magnitude.\n");
if (SDL_HapticRumblePlay(haptic, 0.5, 5000) != 0) {
printf("\nFailed to play rumble: %s\n", SDL_GetError() );
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
return 1;
}
SDL_Delay(2000);
printf("Stopping rumble.\n");
SDL_Log("Stopping rumble.\n");
SDL_HapticRumbleStop(haptic);
SDL_Delay(2000);
printf("Playing 2 second rumble at 0.3 magnitude.\n");
SDL_Log("Playing 2 second rumble at 0.3 magnitude.\n");
if (SDL_HapticRumblePlay(haptic, 0.3f, 5000) != 0) {
printf("\nFailed to play rumble: %s\n", SDL_GetError() );
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError() );
return 1;
}
SDL_Delay(2000);
@@ -145,7 +147,7 @@ main(int argc, char **argv)
int
main(int argc, char *argv[])
{
fprintf(stderr, "SDL compiled without Haptic support.\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Haptic support.\n");
exit(1);
}

View File

@@ -48,7 +48,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return NULL;
}
@@ -79,7 +79,7 @@ LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
/* Create textures from the image */
texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!texture) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return NULL;
}
@@ -129,6 +129,9 @@ main(int argc, char *argv[])
int frames;
Uint32 then, now;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
@@ -139,7 +142,7 @@ main(int argc, char *argv[])
consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) {
fprintf(stderr, "Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
return 1;
}
i += consumed;
@@ -175,6 +178,8 @@ main(int argc, char *argv[])
SDLTest_CommonEvent(state, &event, &done);
}
for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i] == NULL)
continue;
Draw(&drawstates[i]);
}
}
@@ -183,7 +188,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
printf("%2.2f frames per second\n", fps);
SDL_Log("%2.2f frames per second\n", fps);
}
SDL_stack_free(drawstates);

View File

@@ -30,17 +30,15 @@ ThreadFunc(void *data)
int threadnum = (int) (uintptr_t) data;
while (alive) {
SDL_SemWait(sem);
fprintf(stderr,
"Thread number %d has got the semaphore (value = %d)!\n",
SDL_Log("Thread number %d has got the semaphore (value = %d)!\n",
threadnum, SDL_SemValue(sem));
SDL_Delay(200);
SDL_SemPost(sem);
fprintf(stderr,
"Thread number %d has released the semaphore (value = %d)!\n",
SDL_Log("Thread number %d has released the semaphore (value = %d)!\n",
threadnum, SDL_SemValue(sem));
SDL_Delay(1); /* For the scheduler */
}
printf("Thread number %d exiting.\n", threadnum);
SDL_Log("Thread number %d exiting.\n", threadnum);
return 0;
}
@@ -59,7 +57,7 @@ TestWaitTimeout(void)
int retval;
sem = SDL_CreateSemaphore(0);
printf("Waiting 2 seconds on semaphore\n");
SDL_Log("Waiting 2 seconds on semaphore\n");
start_ticks = SDL_GetTicks();
retval = SDL_SemWaitTimeout(sem, 2000);
@@ -69,13 +67,13 @@ TestWaitTimeout(void)
/* Accept a little offset in the effective wait */
if (duration > 1900 && duration < 2050)
printf("Wait done.\n");
SDL_Log("Wait done.\n");
else
fprintf(stderr, "Wait took %d milliseconds\n", duration);
SDL_Log("Wait took %d milliseconds\n", duration);
/* Check to make sure the return value indicates timed out */
if (retval != SDL_MUTEX_TIMEDOUT)
fprintf(stderr, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT);
}
int
@@ -85,14 +83,17 @@ main(int argc, char **argv)
uintptr_t i;
int init_sem;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (argc < 2) {
fprintf(stderr, "Usage: %s init_value\n", argv[0]);
SDL_Log("Usage: %s init_value\n", argv[0]);
return (1);
}
/* Load the SDL library */
if (SDL_Init(0) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
signal(SIGTERM, killed);
@@ -101,7 +102,7 @@ main(int argc, char **argv)
init_sem = atoi(argv[1]);
sem = SDL_CreateSemaphore(init_sem);
printf("Running %d threads, semaphore value = %d\n", NUM_THREADS,
SDL_Log("Running %d threads, semaphore value = %d\n", NUM_THREADS,
init_sem);
/* Create all the threads */
for (i = 0; i < NUM_THREADS; ++i) {
@@ -114,12 +115,12 @@ main(int argc, char **argv)
SDL_Delay(10 * 1000);
/* Wait for all threads to finish */
printf("Waiting for threads to finish\n");
SDL_Log("Waiting for threads to finish\n");
alive = 0;
for (i = 0; i < NUM_THREADS; ++i) {
SDL_WaitThread(threads[i], NULL);
}
printf("Finished waiting for threads\n");
SDL_Log("Finished waiting for threads\n");
SDL_DestroySemaphore(sem);

View File

@@ -11,7 +11,6 @@
*/
/* This is a simple example of using GLSL shaders with SDL */
#include <stdio.h> /* for printf() */
#include "SDL.h"
#ifdef HAVE_OPENGL
@@ -139,7 +138,7 @@ static SDL_bool CompileShader(GLhandleARB shader, const char *source)
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = SDL_stack_alloc(char, length+1);
glGetInfoLogARB(shader, length, NULL, info);
fprintf(stderr, "Failed to compile shader:\n%s\n%s", source, info);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info);
SDL_stack_free(info);
return SDL_FALSE;
@@ -245,7 +244,7 @@ static SDL_bool InitShaders()
/* Compile all the shaders */
for (i = 0; i < NUM_SHADERS; ++i) {
if (!CompileShaderProgram(&shaders[i])) {
fprintf(stderr, "Unable to compile shader!\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to compile shader!\n");
return SDL_FALSE;
}
}
@@ -333,19 +332,19 @@ SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord)
}
/* A general OpenGL initialization function. Sets all of the initial parameters. */
void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.
void InitGL(int Width, int Height) /* We call this right after our OpenGL window is created. */
{
GLdouble aspect;
glViewport(0, 0, Width, Height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); /* This Will Clear The Background Color To Black */
glClearDepth(1.0); /* Enables Clearing Of The Depth Buffer */
glDepthFunc(GL_LESS); /* The Type Of Depth Test To Do */
glEnable(GL_DEPTH_TEST); /* Enables Depth Testing */
glShadeModel(GL_SMOOTH); /* Enables Smooth Color Shading */
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Reset The Projection Matrix
glLoadIdentity(); /* Reset The Projection Matrix */
aspect = (GLdouble)Width / Height;
glOrtho(-3.0, 3.0, -3.0 / aspect, 3.0 / aspect, 0.0, 1.0);
@@ -364,29 +363,29 @@ void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat * texcoord)
MAXY
};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Clear The Screen And The Depth Buffer */
glLoadIdentity(); /* Reset The View */
glTranslatef(-1.5f,0.0f,0.0f); // Move Left 1.5 Units
glTranslatef(-1.5f,0.0f,0.0f); /* Move Left 1.5 Units */
// draw a triangle (in smooth coloring mode)
glBegin(GL_POLYGON); // start drawing a polygon
glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd(); // we're done with the polygon (smooth color interpolation)
/* draw a triangle (in smooth coloring mode) */
glBegin(GL_POLYGON); /* start drawing a polygon */
glColor3f(1.0f,0.0f,0.0f); /* Set The Color To Red */
glVertex3f( 0.0f, 1.0f, 0.0f); /* Top */
glColor3f(0.0f,1.0f,0.0f); /* Set The Color To Green */
glVertex3f( 1.0f,-1.0f, 0.0f); /* Bottom Right */
glColor3f(0.0f,0.0f,1.0f); /* Set The Color To Blue */
glVertex3f(-1.0f,-1.0f, 0.0f); /* Bottom Left */
glEnd(); /* we're done with the polygon (smooth color interpolation) */
glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units
glTranslatef(3.0f,0.0f,0.0f); /* Move Right 3 Units */
// Enable blending
/* Enable blending */
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// draw a textured square (quadrilateral)
/* draw a textured square (quadrilateral) */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glColor3f(1.0f,1.0f,1.0f);
@@ -394,23 +393,23 @@ void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat * texcoord)
glUseProgramObjectARB(shaders[current_shader].program);
}
glBegin(GL_QUADS); // start drawing a polygon (4 sided)
glBegin(GL_QUADS); /* start drawing a polygon (4 sided) */
glTexCoord2f(texcoord[MINX], texcoord[MINY]);
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f(-1.0f, 1.0f, 0.0f); /* Top Left */
glTexCoord2f(texcoord[MAXX], texcoord[MINY]);
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f, 1.0f, 0.0f); /* Top Right */
glTexCoord2f(texcoord[MAXX], texcoord[MAXY]);
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f( 1.0f,-1.0f, 0.0f); /* Bottom Right */
glTexCoord2f(texcoord[MINX], texcoord[MAXY]);
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd(); // done with the polygon
glVertex3f(-1.0f,-1.0f, 0.0f); /* Bottom Left */
glEnd(); /* done with the polygon */
if (shaders_supported) {
glUseProgramObjectARB(0);
}
glDisable(GL_TEXTURE_2D);
// swap buffers to display, since we're double buffered.
/* swap buffers to display, since we're double buffered. */
SDL_GL_SwapWindow(window);
}
@@ -422,29 +421,32 @@ int main(int argc, char **argv)
GLuint texture;
GLfloat texcoords[4];
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize SDL for video output */
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Unable to initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL: %s\n", SDL_GetError());
exit(1);
}
/* Create a 640x480 OpenGL screen */
window = SDL_CreateWindow( "Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL );
if ( !window ) {
fprintf(stderr, "Unable to create OpenGL window: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL window: %s\n", SDL_GetError());
SDL_Quit();
exit(2);
}
if ( !SDL_GL_CreateContext(window)) {
fprintf(stderr, "Unable to create OpenGL context: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL context: %s\n", SDL_GetError());
SDL_Quit();
exit(2);
}
surface = SDL_LoadBMP("icon.bmp");
if ( ! surface ) {
fprintf(stderr, "Unable to load icon.bmp: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to load icon.bmp: %s\n", SDL_GetError());
SDL_Quit();
exit(3);
}
@@ -454,9 +456,9 @@ int main(int argc, char **argv)
/* Loop, drawing and checking events */
InitGL(640, 480);
if (InitShaders()) {
printf("Shaders supported, press SPACE to cycle them.\n");
SDL_Log("Shaders supported, press SPACE to cycle them.\n");
} else {
printf("Shaders not supported!\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Shaders not supported!\n");
}
done = 0;
while ( ! done ) {
@@ -489,7 +491,7 @@ int main(int argc, char **argv)
int
main(int argc, char *argv[])
{
printf("No OpenGL support on this system\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No OpenGL support on this system\n");
return 1;
}

View File

@@ -29,11 +29,11 @@ typedef struct LoadedPicture {
void render(SDL_Renderer *renderer,SDL_Texture *texture,SDL_Rect texture_dimensions)
{
//Clear render-target to blue.
/* Clear render-target to blue. */
SDL_SetRenderDrawColor(renderer,0x00,0x00,0xff,0xff);
SDL_RenderClear(renderer);
//Render the texture.
/* Render the texture. */
SDL_RenderCopy(renderer,texture,&texture_dimensions,&texture_dimensions);
SDL_RenderPresent(renderer);
@@ -68,13 +68,16 @@ int main(int argc,char** argv)
int access = 0;
SDL_Rect texture_dimensions;;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if(argc < 2) {
printf("SDL_Shape requires at least one bitmap file as argument.\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Shape requires at least one bitmap file as argument.");
exit(-1);
}
if(SDL_VideoInit(NULL) == -1) {
printf("Could not initialize SDL video.\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not initialize SDL video.");
exit(-2);
}
@@ -87,11 +90,10 @@ int main(int argc,char** argv)
if(pictures[i].surface == NULL) {
j = 0;
for(j=0;j<num_pictures;j++)
if(pictures[j].surface != NULL)
SDL_FreeSurface(pictures[j].surface);
SDL_FreeSurface(pictures[j].surface);
SDL_free(pictures);
SDL_VideoQuit();
printf("Could not load surface from named bitmap file.\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not load surface from named bitmap file.");
exit(-3);
}
@@ -112,7 +114,7 @@ int main(int argc,char** argv)
SDL_FreeSurface(pictures[i].surface);
SDL_free(pictures);
SDL_VideoQuit();
printf("Could not create shaped window for SDL_Shape.\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create shaped window for SDL_Shape.");
exit(-4);
}
renderer = SDL_CreateRenderer(window,-1,0);
@@ -122,7 +124,7 @@ int main(int argc,char** argv)
SDL_FreeSurface(pictures[i].surface);
SDL_free(pictures);
SDL_VideoQuit();
printf("Could not create rendering context for SDL_Shape window.\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create rendering context for SDL_Shape window.");
exit(-5);
}
@@ -141,7 +143,7 @@ int main(int argc,char** argv)
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_VideoQuit();
printf("Could not create texture for SDL_shape.\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create texture for SDL_shape.");
exit(-6);
}
}
@@ -185,17 +187,17 @@ int main(int argc,char** argv)
next_time += TICK_INTERVAL;
}
//Free the textures.
/* Free the textures. */
for(i=0;i<num_pictures;i++)
SDL_DestroyTexture(pictures[i].texture);
SDL_DestroyRenderer(renderer);
//Destroy the window.
/* Destroy the window. */
SDL_DestroyWindow(window);
//Free the original surfaces backing the textures.
/* Free the original surfaces backing the textures. */
for(i=0;i<num_pictures;i++)
SDL_FreeSurface(pictures[i].surface);
SDL_free(pictures);
//Call SDL_VideoQuit() before quitting.
/* Call SDL_VideoQuit() before quitting. */
SDL_VideoQuit();
return 0;

View File

@@ -42,15 +42,9 @@ static int iterations = -1;
static void
quit(int rc)
{
if (sprites) {
SDL_free(sprites);
}
if (positions) {
SDL_free(positions);
}
if (velocities) {
SDL_free(velocities);
}
SDL_free(sprites);
SDL_free(positions);
SDL_free(velocities);
SDLTest_CommonQuit(state);
exit(rc);
}
@@ -64,7 +58,7 @@ LoadSprite(const char *file)
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return (-1);
}
sprite_w = temp->w;
@@ -95,7 +89,7 @@ LoadSprite(const char *file)
SDL_Renderer *renderer = state->renderers[i];
sprites[i] = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprites[i]) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return (-1);
}
@@ -299,8 +293,7 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
fprintf(stderr,
"Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n",
SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n",
argv[0], SDLTest_CommonUsage(state));
quit(1);
}
@@ -314,7 +307,7 @@ main(int argc, char *argv[])
sprites =
(SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
if (!sprites) {
fprintf(stderr, "Out of memory!\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);
}
for (i = 0; i < state->num_windows; ++i) {
@@ -330,7 +323,7 @@ main(int argc, char *argv[])
positions = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
velocities = (SDL_Rect *) SDL_malloc(num_sprites * sizeof(SDL_Rect));
if (!positions || !velocities) {
fprintf(stderr, "Out of memory!\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);
}
@@ -367,6 +360,8 @@ main(int argc, char *argv[])
SDLTest_CommonEvent(state, &event, &done);
}
for (i = 0; i < state->num_windows; ++i) {
if (state->windows[i] == NULL)
continue;
MoveSprites(state->renderers[i], sprites[i]);
}
}
@@ -375,7 +370,7 @@ main(int argc, char *argv[])
now = SDL_GetTicks();
if (now > then) {
double fps = ((double) frames * 1000) / (now - then);
printf("%2.2f frames per second\n", fps);
SDL_Log("%2.2f frames per second\n", fps);
}
quit(0);
return 0;

View File

@@ -42,7 +42,7 @@ LoadSprite(char *file, SDL_Renderer *renderer)
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", file, SDL_GetError());
return (-1);
}
sprite_w = temp->w;
@@ -73,7 +73,7 @@ LoadSprite(char *file, SDL_Renderer *renderer)
/* Create textures from the image */
sprite = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprite) {
fprintf(stderr, "Couldn't create texture: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return (-1);
}
@@ -126,6 +126,9 @@ main(int argc, char *argv[])
int i, done;
SDL_Event event;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer) < 0) {
quit(2);
}

View File

@@ -68,7 +68,7 @@ void UpdateTexture(SDL_Texture *texture, int frame)
int pitch;
if (SDL_LockTexture(texture, NULL, &pixels, &pitch) < 0) {
fprintf(stderr, "Couldn't lock texture: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock texture: %s\n", SDL_GetError());
quit(5);
}
src = MooseFrames[frame];
@@ -93,15 +93,18 @@ main(int argc, char **argv)
SDL_bool done = SDL_FALSE;
int frame;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
/* load the moose images */
handle = SDL_RWFromFile("moose.dat", "rb");
if (handle == NULL) {
fprintf(stderr, "Can't find the file moose.dat !\n");
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
quit(2);
}
SDL_RWread(handle, MooseFrames, MOOSEFRAME_SIZE, MOOSEFRAMES_COUNT);
@@ -115,19 +118,19 @@ main(int argc, char **argv)
MOOSEPIC_W*4, MOOSEPIC_H*4,
SDL_WINDOW_RESIZABLE);
if (!window) {
fprintf(stderr, "Couldn't set create window: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
quit(3);
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (!renderer) {
fprintf(stderr, "Couldn't set create renderer: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
quit(4);
}
MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
if (!MooseTexture) {
fprintf(stderr, "Couldn't set create texture: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
quit(5);
}

View File

@@ -1,96 +1,99 @@
/*
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
/* Simple test of the SDL threading code */
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include "SDL.h"
#include "SDL_thread.h"
static SDL_TLSID tls;
static int alive = 0;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDL_Quit();
exit(rc);
}
int SDLCALL
ThreadFunc(void *data)
{
SDL_TLSSet(tls, "baby thread", NULL);
SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n",
(char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
while (alive) {
SDL_Log("Thread '%s' is alive!\n", (char *) data);
SDL_Delay(1 * 1000);
}
SDL_Log("Thread '%s' exiting!\n", (char *) data);
return (0);
}
static void
killed(int sig)
{
SDL_Log("Killed with SIGTERM, waiting 5 seconds to exit\n");
SDL_Delay(5 * 1000);
alive = 0;
quit(0);
}
int
main(int argc, char *argv[])
{
SDL_Thread *thread;
/* Load the SDL library */
if (SDL_Init(0) < 0) {
SDL_Log("Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
tls = SDL_TLSCreate();
SDL_assert(tls);
SDL_TLSSet(tls, "main thread", NULL);
SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
alive = 1;
thread = SDL_CreateThread(ThreadFunc, "One", "#1");
if (thread == NULL) {
SDL_Log("Couldn't create thread: %s\n", SDL_GetError());
quit(1);
}
SDL_Delay(5 * 1000);
SDL_Log("Waiting for thread #1\n");
alive = 0;
SDL_WaitThread(thread, NULL);
SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
alive = 1;
signal(SIGTERM, killed);
thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
if (thread == NULL) {
SDL_Log("Couldn't create thread: %s\n", SDL_GetError());
quit(1);
}
raise(SIGTERM);
SDL_Quit(); /* Never reached */
return (0); /* Never reached */
}
/*
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
/* Simple test of the SDL threading code */
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include "SDL.h"
#include "SDL_thread.h"
static SDL_TLSID tls;
static int alive = 0;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDL_Quit();
exit(rc);
}
int SDLCALL
ThreadFunc(void *data)
{
SDL_TLSSet(tls, "baby thread", NULL);
SDL_Log("Started thread %s: My thread id is %lu, thread data = %s\n",
(char *) data, SDL_ThreadID(), (const char *)SDL_TLSGet(tls));
while (alive) {
SDL_Log("Thread '%s' is alive!\n", (char *) data);
SDL_Delay(1 * 1000);
}
SDL_Log("Thread '%s' exiting!\n", (char *) data);
return (0);
}
static void
killed(int sig)
{
SDL_Log("Killed with SIGTERM, waiting 5 seconds to exit\n");
SDL_Delay(5 * 1000);
alive = 0;
quit(0);
}
int
main(int argc, char *argv[])
{
SDL_Thread *thread;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(0) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
tls = SDL_TLSCreate();
SDL_assert(tls);
SDL_TLSSet(tls, "main thread", NULL);
SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
alive = 1;
thread = SDL_CreateThread(ThreadFunc, "One", "#1");
if (thread == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(1);
}
SDL_Delay(5 * 1000);
SDL_Log("Waiting for thread #1\n");
alive = 0;
SDL_WaitThread(thread, NULL);
SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
alive = 1;
signal(SIGTERM, killed);
thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
if (thread == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(1);
}
raise(SIGTERM);
SDL_Quit(); /* Never reached */
return (0); /* Never reached */
}

View File

@@ -33,7 +33,7 @@ ticktock(Uint32 interval, void *param)
static Uint32 SDLCALL
callback(Uint32 interval, void *param)
{
printf("Timer %d : param = %d\n", interval, (int) (uintptr_t) param);
SDL_Log("Timer %d : param = %d\n", interval, (int) (uintptr_t) param);
return interval;
}
@@ -45,8 +45,11 @@ main(int argc, char *argv[])
Uint32 start32, now32;
Uint64 start, now;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(SDL_INIT_TIMER) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
@@ -61,7 +64,7 @@ main(int argc, char *argv[])
t1 = SDL_AddTimer(desired, ticktock, NULL);
/* Wait 10 seconds */
printf("Waiting 10 seconds\n");
SDL_Log("Waiting 10 seconds\n");
SDL_Delay(10 * 1000);
/* Stop the timer */
@@ -69,28 +72,27 @@ main(int argc, char *argv[])
/* Print the results */
if (ticks) {
fprintf(stderr,
"Timer resolution: desired = %d ms, actual = %f ms\n",
SDL_Log("Timer resolution: desired = %d ms, actual = %f ms\n",
desired, (double) (10 * 1000) / ticks);
}
/* Test multiple timers */
printf("Testing multiple timers...\n");
SDL_Log("Testing multiple timers...\n");
t1 = SDL_AddTimer(100, callback, (void *) 1);
if (!t1)
fprintf(stderr, "Could not create timer 1: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 1: %s\n", SDL_GetError());
t2 = SDL_AddTimer(50, callback, (void *) 2);
if (!t2)
fprintf(stderr, "Could not create timer 2: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 2: %s\n", SDL_GetError());
t3 = SDL_AddTimer(233, callback, (void *) 3);
if (!t3)
fprintf(stderr, "Could not create timer 3: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,"Could not create timer 3: %s\n", SDL_GetError());
/* Wait 10 seconds */
printf("Waiting 10 seconds\n");
SDL_Log("Waiting 10 seconds\n");
SDL_Delay(10 * 1000);
printf("Removing timer 1 and waiting 5 more seconds\n");
SDL_Log("Removing timer 1 and waiting 5 more seconds\n");
SDL_RemoveTimer(t1);
SDL_Delay(5 * 1000);
@@ -103,15 +105,15 @@ main(int argc, char *argv[])
ticktock(0, NULL);
}
now = SDL_GetPerformanceCounter();
printf("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
SDL_Log("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
printf("Performance counter frequency: %llu\n", (unsigned long long) SDL_GetPerformanceFrequency());
SDL_Log("Performance counter frequency: %llu\n", (unsigned long long) SDL_GetPerformanceFrequency());
start32 = SDL_GetTicks();
start = SDL_GetPerformanceCounter();
SDL_Delay(1000);
now = SDL_GetPerformanceCounter();
now32 = SDL_GetTicks();
printf("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (now32-start32), (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
SDL_Log("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (now32-start32), (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
SDL_Quit();
return (0);

View File

@@ -26,17 +26,20 @@ main(int argc, char *argv[])
SDL_version compiled;
SDL_version linked;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
#if SDL_VERSION_ATLEAST(2, 0, 0)
printf("Compiled with SDL 2.0 or newer\n");
SDL_Log("Compiled with SDL 2.0 or newer\n");
#else
printf("Compiled with SDL older than 2.0\n");
SDL_Log("Compiled with SDL older than 2.0\n");
#endif
SDL_VERSION(&compiled);
printf("Compiled version: %d.%d.%d.%d (%s)\n",
SDL_Log("Compiled version: %d.%d.%d.%d (%s)\n",
compiled.major, compiled.minor, compiled.patch,
SDL_REVISION_NUMBER, SDL_REVISION);
SDL_GetVersion(&linked);
printf("Linked version: %d.%d.%d.%d (%s)\n",
SDL_Log("Linked version: %d.%d.%d.%d (%s)\n",
linked.major, linked.minor, linked.patch,
SDL_GetRevisionNumber(), SDL_GetRevision());
SDL_Quit();

View File

@@ -48,6 +48,9 @@ main(int argc, char *argv[])
int system_cursor = -1;
SDL_Cursor *cursor = NULL;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
/* Initialize test framework */
@@ -64,7 +67,7 @@ main(int argc, char *argv[])
consumed = -1;
}
if (consumed < 0) {
fprintf(stderr, "Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
quit(1);
}
i += consumed;
@@ -84,7 +87,7 @@ main(int argc, char *argv[])
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) {
printf("Window %d resized to %dx%d\n",
SDL_Log("Window %d resized to %dx%d\n",
event.window.windowID,
event.window.data1,
event.window.data2);
@@ -93,7 +96,7 @@ main(int argc, char *argv[])
if (event.window.event == SDL_WINDOWEVENT_MOVED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) {
printf("Window %d moved to %d,%d (display %s)\n",
SDL_Log("Window %d moved to %d,%d (display %s)\n",
event.window.windowID,
event.window.data1,
event.window.data2,
@@ -129,7 +132,7 @@ main(int argc, char *argv[])
SDL_FreeCursor(cursor);
quit(0);
// keep the compiler happy ...
/* keep the compiler happy ... */
return(0);
}

View File

@@ -36,7 +36,7 @@ int SDLCALL
SubThreadFunc(void *data)
{
while (!*(int volatile *) data) {
; /*SDL_Delay(10); *//* do nothing */
; /* SDL_Delay(10); *//* do nothing */
}
return 0;
}
@@ -49,7 +49,7 @@ ThreadFunc(void *data)
int i;
int tid = (int) (uintptr_t) data;
fprintf(stderr, "Creating Thread %d\n", tid);
SDL_Log("Creating Thread %d\n", tid);
for (i = 0; i < NUMTHREADS; i++) {
char name[64];
@@ -58,18 +58,18 @@ ThreadFunc(void *data)
sub_threads[i] = SDL_CreateThread(SubThreadFunc, name, &flags[i]);
}
printf("Thread '%d' waiting for signal\n", tid);
SDL_Log("Thread '%d' waiting for signal\n", tid);
while (time_for_threads_to_die[tid] != 1) {
; /* do nothing */
}
printf("Thread '%d' sending signals to subthreads\n", tid);
SDL_Log("Thread '%d' sending signals to subthreads\n", tid);
for (i = 0; i < NUMTHREADS; i++) {
flags[i] = 1;
SDL_WaitThread(sub_threads[i], NULL);
}
printf("Thread '%d' exiting!\n", tid);
SDL_Log("Thread '%d' exiting!\n", tid);
return 0;
}
@@ -80,9 +80,12 @@ main(int argc, char *argv[])
SDL_Thread *threads[NUMTHREADS];
int i;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(0) < 0) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
@@ -94,7 +97,7 @@ main(int argc, char *argv[])
threads[i] = SDL_CreateThread(ThreadFunc, name, (void*) (uintptr_t) i);
if (threads[i] == NULL) {
fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(1);
}
}