From 1cf7a124e8061deceab52ed69236ba3c3a5c5ad2 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Wed, 4 Sep 2024 20:01:24 +0300
Subject: [PATCH] update headers, tests and testlib from latest SDL2
---
include/SDL2/SDL_audio.h | 5 +-
include/SDL2/SDL_video.h | 82 +++++++++++++------
src/test/SDL_test_memory.c | 157 +++++++++++++++++++++++++++++++++++--
test/testatomic.c | 19 +++++
test/testaudioinfo.c | 17 +++-
test/testbounds.c | 19 ++++-
test/testdisplayinfo.c | 17 +++-
test/testerror.c | 17 +++-
test/testfilesystem.c | 18 ++++-
test/testfilesystem_pre.c | 29 +++++--
test/testkeys.c | 19 ++++-
test/testlocale.c | 67 ++++++++++++----
test/testplatform.c | 35 ++++++++-
test/testpower.c | 19 ++++-
test/testqsort.c | 69 ++++++++++++----
test/testsurround.c | 16 +++-
test/testthread.c | 43 +++++++---
test/testtimer.c | 21 +++--
test/testver.c | 20 ++++-
19 files changed, 576 insertions(+), 113 deletions(-)
diff --git a/include/SDL2/SDL_audio.h b/include/SDL2/SDL_audio.h
index 8f874dcc..36914c43 100644
--- a/include/SDL2/SDL_audio.h
+++ b/include/SDL2/SDL_audio.h
@@ -1172,9 +1172,8 @@ extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 * dst, const Uint8 * src,
* \param format the SDL_AudioFormat structure representing the desired audio
* format.
* \param len the length of the audio buffer in bytes.
- * \param volume ranges from -128 - ∞ (at -128, the volume is at 0%, at 0 -
- * 100% and the higher the number, the bigger the %), and should
- * be set to SDL_MIX_MAXVOLUME for full audio volume.
+ * \param volume ranges from 0 - 128, and should be set to SDL_MIX_MAXVOLUME
+ * for full audio volume.
*
* \since This function is available since SDL 2.0.0.
*/
diff --git a/include/SDL2/SDL_video.h b/include/SDL2/SDL_video.h
index 6afc63e6..e2bc12be 100644
--- a/include/SDL2/SDL_video.h
+++ b/include/SDL2/SDL_video.h
@@ -221,35 +221,65 @@ typedef enum SDL_FlashOperation
typedef void *SDL_GLContext;
/**
- * OpenGL configuration attributes
+ * OpenGL configuration attributes.
+ *
+ * While you can set most OpenGL attributes normally, the attributes listed
+ * above must be known before SDL creates the window that will be used with
+ * the OpenGL context. These attributes are set and read with
+ * SDL_GL_SetAttribute and SDL_GL_GetAttribute.
+ *
+ * In some cases, these attributes are minimum requests; the GL does not
+ * promise to give you exactly what you asked for. It's possible to ask for a
+ * 16-bit depth buffer and get a 24-bit one instead, for example, or to ask
+ * for no stencil buffer and still have one available. Context creation should
+ * fail if the GL can't provide your requested attributes at a minimum, but
+ * you should check to see exactly what you got.
+ *
+ *
+ * [Multisample anti-aliasing](http://en.wikipedia.org/wiki/Multisample_anti-aliasing)
+ * is a type of full screen anti-aliasing. Multipsampling defaults to off but
+ * can be turned on by setting SDL_GL_MULTISAMPLEBUFFERS to 1 and
+ * SDL_GL_MULTISAMPLESAMPLES to a value greater than 0. Typical values are 2
+ * and 4.
+ *
+ * SDL_GL_CONTEXT_PROFILE_MASK determines the type of context created, while
+ * both SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION
+ * determine which version. All three attributes must be set prior to creating
+ * the first window, and in general you can't change the value of
+ * SDL_GL_CONTEXT_PROFILE_MASK without first destroying all windows created
+ * with the previous setting.
+ *
+ * SDL_GL_CONTEXT_RELEASE_BEHAVIOR can be set to
+ * SDL_GL_CONTEXT_RELEASE_BEHAVIOR_NONE or
+ * SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH.
*/
typedef enum SDL_GLattr
{
- SDL_GL_RED_SIZE,
- SDL_GL_GREEN_SIZE,
- SDL_GL_BLUE_SIZE,
- SDL_GL_ALPHA_SIZE,
- SDL_GL_BUFFER_SIZE,
- SDL_GL_DOUBLEBUFFER,
- SDL_GL_DEPTH_SIZE,
- SDL_GL_STENCIL_SIZE,
- SDL_GL_ACCUM_RED_SIZE,
- SDL_GL_ACCUM_GREEN_SIZE,
- SDL_GL_ACCUM_BLUE_SIZE,
- SDL_GL_ACCUM_ALPHA_SIZE,
- SDL_GL_STEREO,
- SDL_GL_MULTISAMPLEBUFFERS,
- SDL_GL_MULTISAMPLESAMPLES,
- SDL_GL_ACCELERATED_VISUAL,
- SDL_GL_RETAINED_BACKING,
- SDL_GL_CONTEXT_MAJOR_VERSION,
- SDL_GL_CONTEXT_MINOR_VERSION,
- SDL_GL_CONTEXT_EGL,
- SDL_GL_CONTEXT_FLAGS,
- SDL_GL_CONTEXT_PROFILE_MASK,
- SDL_GL_SHARE_WITH_CURRENT_CONTEXT,
- SDL_GL_FRAMEBUFFER_SRGB_CAPABLE,
- SDL_GL_CONTEXT_RELEASE_BEHAVIOR,
+ SDL_GL_RED_SIZE, /**< the minimum number of bits for the red channel of the color buffer; defaults to 3. */
+ SDL_GL_GREEN_SIZE, /**< the minimum number of bits for the green channel of the color buffer; defaults to 3. */
+ SDL_GL_BLUE_SIZE, /**< the minimum number of bits for the blue channel of the color buffer; defaults to 2. */
+ SDL_GL_ALPHA_SIZE, /**< the minimum number of bits for the alpha channel of the color buffer; defaults to 0. */
+ SDL_GL_BUFFER_SIZE, /**< the minimum number of bits for frame buffer size; defaults to 0. */
+ SDL_GL_DOUBLEBUFFER, /**< whether the output is single or double buffered; defaults to double buffering on. */
+ SDL_GL_DEPTH_SIZE, /**< the minimum number of bits in the depth buffer; defaults to 16. */
+ SDL_GL_STENCIL_SIZE, /**< the minimum number of bits in the stencil buffer; defaults to 0. */
+ SDL_GL_ACCUM_RED_SIZE, /**< the minimum number of bits for the red channel of the accumulation buffer; defaults to 0. */
+ SDL_GL_ACCUM_GREEN_SIZE, /**< the minimum number of bits for the green channel of the accumulation buffer; defaults to 0. */
+ SDL_GL_ACCUM_BLUE_SIZE, /**< the minimum number of bits for the blue channel of the accumulation buffer; defaults to 0. */
+ SDL_GL_ACCUM_ALPHA_SIZE, /**< the minimum number of bits for the alpha channel of the accumulation buffer; defaults to 0. */
+ SDL_GL_STEREO, /**< whether the output is stereo 3D; defaults to off. */
+ SDL_GL_MULTISAMPLEBUFFERS, /**< the number of buffers used for multisample anti-aliasing; defaults to 0. */
+ SDL_GL_MULTISAMPLESAMPLES, /**< the number of samples used around the current pixel used for multisample anti-aliasing. */
+ SDL_GL_ACCELERATED_VISUAL, /**< set to 1 to require hardware acceleration, set to 0 to force software rendering; defaults to allow either. */
+ SDL_GL_RETAINED_BACKING, /**< not used (deprecated). */
+ SDL_GL_CONTEXT_MAJOR_VERSION, /**< OpenGL context major version. */
+ SDL_GL_CONTEXT_MINOR_VERSION, /**< OpenGL context minor version. */
+ SDL_GL_CONTEXT_EGL, /**< deprecated: set SDL_GL_CONTEXT_PROFILE_MASK to SDL_GL_CONTEXT_PROFILE_ES to enable instead. */
+ SDL_GL_CONTEXT_FLAGS, /**< some combination of 0 or more of elements of the SDL_GLcontextFlag enumeration; defaults to 0. */
+ SDL_GL_CONTEXT_PROFILE_MASK, /**< type of GL context (Core, Compatibility, ES). See SDL_GLprofile; default value depends on platform. */
+ SDL_GL_SHARE_WITH_CURRENT_CONTEXT, /**< OpenGL context sharing; defaults to 0. */
+ SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, /**< requests sRGB capable visual; defaults to 0. (>= SDL 2.0.1) */
+ SDL_GL_CONTEXT_RELEASE_BEHAVIOR, /**< sets context the release behavior; defaults to 1. (>= SDL 2.0.4) */
SDL_GL_CONTEXT_RESET_NOTIFICATION,
SDL_GL_CONTEXT_NO_ERROR,
SDL_GL_FLOATBUFFERS
diff --git a/src/test/SDL_test_memory.c b/src/test/SDL_test_memory.c
index e998094a..491ddfed 100644
--- a/src/test/SDL_test_memory.c
+++ b/src/test/SDL_test_memory.c
@@ -20,6 +20,8 @@
*/
#include "SDL_config.h"
#include "SDL_assert.h"
+#include "SDL_atomic.h"
+#include "SDL_loadso.h"
#include "SDL_stdinc.h"
#include "SDL_log.h"
#include "SDL_test_crc32.h"
@@ -28,6 +30,31 @@
#ifdef HAVE_LIBUNWIND_H
#define UNW_LOCAL_ONLY
#include <libunwind.h>
+#ifndef unw_get_proc_name_by_ip
+#define SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
+static SDL_bool s_unwind_symbol_names = SDL_TRUE;
+#endif
+#endif
+
+#if defined(__WIN32__) && !defined(__WATCOMC__)
+#define WIN32_WITH_DBGHELP
+#endif
+
+#ifdef WIN32_WITH_DBGHELP
+#include <windows.h>
+#include <dbghelp.h>
+
+static struct {
+ HMODULE module;
+ BOOL (WINAPI *pSymInitialize)(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess);
+ BOOL (WINAPI *pSymFromAddr)(HANDLE hProcess, DWORD64 Address, PDWORD64 Displacement, PSYMBOL_INFO Symbol);
+ BOOL (WINAPI *pSymGetLineFromAddr64)(HANDLE hProcess, DWORD64 qwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line);
+} dyn_dbghelp;
+
+/* older SDKs might not have this: */
+__declspec(dllimport) USHORT WINAPI RtlCaptureStackBackTrace(ULONG FramesToSkip, ULONG FramesToCapture, PVOID* BackTrace, PULONG BackTraceHash);
+#define CaptureStackBackTrace RtlCaptureStackBackTrace
+
#endif
/* This is a simple tracking allocator to demonstrate the use of SDL's
@@ -37,13 +64,17 @@
for production code.
*/
+#define MAXIMUM_TRACKED_STACK_DEPTH 16
+
typedef struct SDL_tracked_allocation
{
void *mem;
size_t size;
- Uint64 stack[10];
- char stack_names[10][256];
+ Uint64 stack[MAXIMUM_TRACKED_STACK_DEPTH];
struct SDL_tracked_allocation *next;
+#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
+ char stack_names[MAXIMUM_TRACKED_STACK_DEPTH][256];
+#endif
} SDL_tracked_allocation;
static SDLTest_Crc32Context s_crc32_context;
@@ -53,6 +84,16 @@ static SDL_realloc_func SDL_realloc_orig = NULL;
static SDL_free_func SDL_free_orig = NULL;
static int s_previous_allocations = 0;
static SDL_tracked_allocation *s_tracked_allocations[256];
+static SDL_atomic_t s_lock;
+
+#define LOCK_ALLOCATOR() \
+ do { \
+ if (SDL_AtomicCAS(&s_lock, 0, 1)) { \
+ break; \
+ } \
+ SDL_CPUPauseInstruction(); \
+ } while (SDL_TRUE)
+#define UNLOCK_ALLOCATOR() do { SDL_AtomicSet(&s_lock, 0); } while (0)
static unsigned int get_allocation_bucket(void *mem)
{
@@ -66,12 +107,17 @@ static unsigned int get_allocation_bucket(void *mem)
static SDL_bool SDL_IsAllocationTracked(void *mem)
{
SDL_tracked_allocation *entry;
- int index = get_allocation_bucket(mem);
+ int index;
+
+ LOCK_ALLOCATOR();
+ index = get_allocation_bucket(mem);
for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
if (mem == entry->mem) {
+ UNLOCK_ALLOCATOR();
return SDL_TRUE;
}
}
+ UNLOCK_ALLOCATOR();
return SDL_FALSE;
}
@@ -83,8 +129,10 @@ static void SDL_TrackAllocation(void *mem, size_t size)
if (SDL_IsAllocationTracked(mem)) {
return;
}
+ LOCK_ALLOCATOR();
entry = (SDL_tracked_allocation *)SDL_malloc_orig(sizeof(*entry));
if (!entry) {
+ UNLOCK_ALLOCATOR();
return;
}
entry->mem = mem;
@@ -103,15 +151,20 @@ static void SDL_TrackAllocation(void *mem, size_t size)
stack_index = 0;
while (unw_step(&cursor) > 0) {
- unw_word_t offset, pc;
+ unw_word_t pc;
+#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
+ unw_word_t offset;
char sym[236];
+#endif
unw_get_reg(&cursor, UNW_REG_IP, &pc);
entry->stack[stack_index] = pc;
- if (unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) {
+#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
+ if (s_unwind_symbol_names && unw_get_proc_name(&cursor, sym, sizeof(sym), &offset) == 0) {
SDL_snprintf(entry->stack_names[stack_index], sizeof(entry->stack_names[stack_index]), "%s+0x%llx", sym, (unsigned long long)offset);
}
+#endif
++stack_index;
if (stack_index == SDL_arraysize(entry->stack)) {
@@ -119,10 +172,24 @@ static void SDL_TrackAllocation(void *mem, size_t size)
}
}
}
+#elif defined(WIN32_WITH_DBGHELP)
+ {
+ Uint32 count;
+ PVOID frames[63];
+ Uint32 i;
+
+ count = CaptureStackBackTrace(1, SDL_arraysize(frames), frames, NULL);
+
+ count = SDL_min(count, MAXIMUM_TRACKED_STACK_DEPTH);
+ for (i = 0; i < count; i++) {
+ entry->stack[i] = (Uint64)(uintptr_t)frames[i];
+ }
+ }
#endif /* HAVE_LIBUNWIND_H */
entry->next = s_tracked_allocations[index];
s_tracked_allocations[index] = entry;
+ UNLOCK_ALLOCATOR();
}
static void SDL_UntrackAllocation(void *mem)
@@ -130,6 +197,7 @@ static void SDL_UntrackAllocation(void *mem)
SDL_tracked_allocation *entry, *prev;
int index = get_allocation_bucket(mem);
+ LOCK_ALLOCATOR();
prev = NULL;
for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
if (mem == entry->mem) {
@@ -139,10 +207,12 @@ static void SDL_UntrackAllocation(void *mem)
s_tracked_allocations[index] = entry->next;
}
SDL_free_orig(entry);
+ UNLOCK_ALLOCATOR();
return;
}
prev = entry;
}
+ UNLOCK_ALLOCATOR();
}
static void *SDLCALL SDLTest_TrackedMalloc(size_t size)
@@ -207,6 +277,41 @@ int SDLTest_TrackAllocations(void)
if (s_previous_allocations != 0) {
SDL_Log("SDLTest_TrackAllocations(): There are %d previous allocations, disabling free() validation", s_previous_allocations);
}
+#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
+ do {
+ /* Don't use SDL_GetHint: SDL_malloc is off limits. */
+ const char *env_trackmem = SDL_getenv("SDL_TRACKMEM_SYMBOL_NAMES");
+ if (env_trackmem) {
+ if (SDL_strcasecmp(env_trackmem, "1") == 0 || SDL_strcasecmp(env_trackmem, "yes") == 0 || SDL_strcasecmp(env_trackmem, "true") == 0) {
+ s_unwind_symbol_names = SDL_TRUE;
+ } else if (SDL_strcasecmp(env_trackmem, "0") == 0 || SDL_strcasecmp(env_trackmem, "no") == 0 || SDL_strcasecmp(env_trackmem, "false") == 0) {
+ s_unwind_symbol_names = SDL_FALSE;
+ }
+ }
+ } while (0);
+#elif defined(WIN32_WITH_DBGHELP)
+ do {
+ dyn_dbghelp.module = SDL_LoadObject("dbghelp.dll");
+ if (!dyn_dbghelp.module) {
+ goto dbghelp_failed;
+ }
+ dyn_dbghelp.pSymInitialize = (void *)SDL_LoadFunction(dyn_dbghelp.module, "SymInitialize");
+ dyn_dbghelp.pSymFromAddr = (void *)SDL_LoadFunction(dyn_dbghelp.module, "SymFromAddr");
+ dyn_dbghelp.pSymGetLineFromAddr64 = (void *)SDL_LoadFunction(dyn_dbghelp.module, "SymGetLineFromAddr64");
+ if (!dyn_dbghelp.pSymInitialize || !dyn_dbghelp.pSymFromAddr || !dyn_dbghelp.pSymGetLineFromAddr64) {
+ goto dbghelp_failed;
+ }
+ if (!dyn_dbghelp.pSymInitialize(GetCurrentProcess(), NULL, TRUE)) {
+ goto dbghelp_failed;
+ }
+ break;
+ dbghelp_failed:
+ if (dyn_dbghelp.module) {
+ SDL_UnloadObject(dyn_dbghelp.module);
+ dyn_dbghelp.module = NULL;
+ }
+ } while (0);
+#endif
SDL_GetMemoryFunctions(&SDL_malloc_orig,
&SDL_calloc_orig,
@@ -224,7 +329,7 @@ void SDLTest_LogAllocations(void)
{
char *message = NULL;
size_t message_size = 0;
- char line[128], *tmp;
+ char line[256], *tmp;
SDL_tracked_allocation *entry;
int index, count, stack_index;
Uint64 total_allocated;
@@ -261,10 +366,48 @@ void SDLTest_LogAllocations(void)
ADD_LINE();
/* Start at stack index 1 to skip our tracking functions */
for (stack_index = 1; stack_index < SDL_arraysize(entry->stack); ++stack_index) {
+ char stack_entry_description[256] = "???";
if (!entry->stack[stack_index]) {
break;
}
- (void)SDL_snprintf(line, sizeof(line), "\t0x%" SDL_PRIx64 ": %s\n", entry->stack[stack_index], entry->stack_names[stack_index]);
+#ifdef HAVE_LIBUNWIND_H
+ {
+#ifdef SDLTEST_UNWIND_NO_PROC_NAME_BY_IP
+ if (s_unwind_symbol_names) {
+ (void)SDL_snprintf(stack_entry_description, sizeof(stack_entry_description), "%s", entry->stack_names[stack_index]);
+ }
+#else
+ char name[256] = "???";
+ unw_word_t offset = 0;
+ unw_get_proc_name_by_ip(unw_local_addr_space, entry->stack[stack_index], name, sizeof(name), &offset, NULL);
+ (void)SDL_snprintf(stack_entry_description, sizeof(stack_entry_description), "%s+0x%llx", name, (long long unsigned int)offset);
+#endif
+ }
+#elif defined(WIN32_WITH_DBGHELP)
+ {
+ DWORD64 dwDisplacement = 0;
+ IMAGEHLP_LINE64 dbg_line;
+ char symbol_buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
+ PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)symbol_buffer;
+ DWORD lineColumn = 0;
+ pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
+ pSymbol->MaxNameLen = MAX_SYM_NAME;
+ dbg_line.SizeOfStruct = sizeof(dbg_line);
+ dbg_line.FileName = "";
+ dbg_line.LineNumber = 0;
+
+ if (dyn_dbghelp.module) {
+ if (!dyn_dbghelp.pSymFromAddr(GetCurrentProcess(), entry->stack[stack_index], &dwDisplacement, pSymbol)) {
+ SDL_strlcpy(pSymbol->Name, "???", MAX_SYM_NAME);
+ dwDisplacement = 0;
+ }
+ dyn_dbghelp.pSymGetLineFromAddr64(GetCurrentProcess(), (DWORD64)entry->stack[stack_index], &lineColumn, &dbg_line);
+ }
+ SDL_snprintf(stack_entry_description, sizeof(stack_entry_description), "%s+0x%I64x %s:%u", pSymbol->Name, dwDisplacement, dbg_line.FileName, (Uint32)dbg_line.LineNumber);
+ }
+#endif
+ (void)SDL_snprintf(line, sizeof(line), "\t0x%" SDL_PRIx64 ": %s\n", entry->stack[stack_index], stack_entry_description);
+
ADD_LINE();
}
total_allocated += entry->size;
diff --git a/test/testatomic.c b/test/testatomic.c
index c19415ac..1574295a 100644
--- a/test/testatomic.c
+++ b/test/testatomic.c
@@ -12,6 +12,7 @@
#include <stdio.h>
#include "SDL.h"
+#include "SDL_test.h"
/*
Absolutely basic tests just to see if we get the expected value
@@ -699,9 +700,26 @@ static void RunFIFOTest(SDL_bool lock_free)
int main(int argc, char *argv[])
{
+ SDLTest_CommonState *state;
+
+ state = SDLTest_CommonCreateState(argv, 0);
+ if (!state) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
+ return 1;
+ }
+
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
+ return 1;
+ }
+
+ if (!SDLTest_CommonInit(state)) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
+ return 1;
+ }
+
RunBasicTest();
if (SDL_getenv("SDL_TESTS_QUICK") != NULL) {
@@ -715,6 +733,7 @@ int main(int argc, char *argv[])
RunFIFOTest(SDL_FALSE);
#endif
RunFIFOTest(SDL_TRUE);
+ SDLTest_CommonQuit(state);
return 0;
}
diff --git a/test/testaudioinfo.c b/test/testaudioinfo.c
index ec4b8647..eb9afa70 100644
--- a/test/testaudioinfo.c
+++ b/test/testaudioinfo.c
@@ -11,6 +11,7 @@
*/
#include <stdio.h>
#include "SDL.h"
+#include "SDL_test.h"
static void
print_devices(int iscapture)
@@ -50,12 +51,22 @@ int main(int argc, char **argv)
char *deviceName = NULL;
SDL_AudioSpec spec;
int n;
+ SDLTest_CommonState *state;
+
+ state = SDLTest_CommonCreateState(argv, SDL_INIT_AUDIO);
+ if (!state) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
+ return 1;
+ }
/* 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) {
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
+ return 1;
+ }
+
+ if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
@@ -98,6 +109,6 @@ int main(int argc, char **argv)
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
}
- SDL_Quit();
+ SDLTest_CommonQuit(state);
return 0;
}
diff --git a/test/testbounds.c b/test/testbounds.c
index 9bd73ac9..8879d5fb 100644
--- a/test/testbounds.c
+++ b/test/testbounds.c
@@ -11,12 +11,27 @@
*/
#include "SDL.h"
+#include "SDL_test.h"
int main(int argc, char **argv)
{
int total, i;
+ SDLTest_CommonState *state;
- if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
+ if (!state) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
+ return 1;
+ }
+
+ /* Enable standard application logging */
+ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
+
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
+ return 1;
+ }
+
+ if (!SDLTest_CommonInit(state)) {
SDL_Log("SDL_Init(SDL_INIT_VIDEO) failed: %s", SDL_GetError());
return 1;
}
@@ -32,7 +47,7 @@ int main(int argc, char **argv)
usable.x, usable.y, usable.w, usable.h);
}
- SDL_Quit();
+ SDLTest_CommonQuit(state);
return 0;
}
diff --git a/test/testdisplayinfo.c b/test/testdisplayinfo.c
index 9740ab17..94f5ccee 100644
--- a/test/testdisplayinfo.c
+++ b/test/testdisplayinfo.c
@@ -13,6 +13,7 @@
/* Program to test querying of display info */
#include "SDL.h"
+#include "SDL_test.h"
#include <stdio.h>
#include <stdlib.h>
@@ -33,12 +34,22 @@ int main(int argc, char *argv[])
{
SDL_DisplayMode mode;
int num_displays, dpy;
+ SDLTest_CommonState *state;
+
+ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
+ if (!state) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
+ return 1;
+ }
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
- /* Load the SDL library */
- if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
+ return 1;
+ }
+
+ if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
@@ -88,7 +99,7 @@ int main(int argc, char *argv[])
SDL_Log("\n");
}
- SDL_Quit();
+ SDLTest_CommonQuit(state);
return 0;
}
diff --git a/test/testerror.c b/test/testerror.c
index 25874d1e..3124da2f 100644
--- a/test/testerror.c
+++ b/test/testerror.c
@@ -16,6 +16,7 @@
#include <stdlib.h>
#include "SDL.h"
+#include "SDL_test.h"
static int alive = 0;
@@ -44,12 +45,22 @@ ThreadFunc(void *data)
int main(int argc, char *argv[])
{
SDL_Thread *thread;
+ SDLTest_CommonState *state;
+
+ state = SDLTest_CommonCreateState(argv, 0);
+ if (!state) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
+ return 1;
+ }
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
- /* Load the SDL library */
- if (SDL_Init(0) < 0) {
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
+ return 1;
+ }
+
+ if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
@@ -76,6 +87,6 @@ int main(int argc, char *argv[])
SDL_Log("Main thread error string: %s\n", SDL_GetError());
- SDL_Quit();
+ SDLTest_CommonQuit(state);
return 0;
}
diff --git a/test/testfilesystem.c b/test/testfilesystem.c
index af0bd9f0..33426e2e 100644
--- a/test/testfilesystem.c
+++ b/test/testfilesystem.c
@@ -13,17 +13,29 @@
#include <stdio.h>
#include "SDL.h"
+#include "SDL_test.h"
int main(int argc, char *argv[])
{
char *base_path;
char *pref_path;
+ SDLTest_CommonState *state;
+
+ state = SDLTest_CommonCreateState(argv, 0);
+ if (!state) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
+ return 1;
+ }
/* 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());
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
+ return 1;
+ }
+
+ if (!SDLTest_CommonInit(state)) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
@@ -54,6 +66,6 @@ int main(int argc, char *argv[])
SDL_free(pref_path);
}
- SDL_Quit();
+ SDLTest_CommonQuit(state);
return 0;
}
diff --git a/test/testfilesystem_pre.c b/test/testfilesystem_pre.c
index 11615abd..b9beaaf2 100644
--- a/test/testfilesystem_pre.c
+++ b/test/testfilesystem_pre.c
@@ -17,16 +17,35 @@
*/
#include "SDL.h"
+#include "SDL_test.h"
int main(int argc, char *argv[])
{
+ SDLTest_CommonState *state;
Uint64 start;
- (void)argc;
- (void)argv;
- SDL_Init(0);
+ char *path;
+
+ state = SDLTest_CommonCreateState(argv, 0);
+ if (!state) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
+ return 1;
+ }
+
+ /* Enable standard application logging */
+ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
+
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
+ return 1;
+ }
+
start = SDL_GetTicks();
- SDL_GetPrefPath("libsdl", "test_filesystem");
+ if (!SDLTest_CommonInit(state)) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
+ return 1;
+ }
+ path = SDL_GetPrefPath("libsdl", "test_filesystem");
+ SDL_free(path);
SDL_Log("SDL_GetPrefPath took %" SDL_PRIu64 "ms", SDL_GetTicks() - start);
- SDL_Quit();
+ SDLTest_CommonQuit(state);
return 0;
}
diff --git a/test/testkeys.c b/test/testkeys.c
index c7b120b4..d4770475 100644
--- a/test/testkeys.c
+++ b/test/testkeys.c
@@ -18,14 +18,31 @@
#include <string.h>
#include "SDL.h"
+#include "SDL_test.h"
int main(int argc, char *argv[])
{
+ SDLTest_CommonState *state;
SDL_Scancode scancode;
+ state = SDLTest_CommonCreateState(argv, 0);
+ if (!state) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
+ return 1;
+ }
+
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
+ return 1;
+ }
+
+ if (!SDLTest_CommonInit(state)) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
+ return 1;
+ }
+
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
@@ -34,6 +51,6 @@ int main(int argc, char *argv[])
SDL_Log("Scancode #%d, \"%s\"\n", scancode,
SDL_GetScancodeName(scancode));
}
- SDL_Quit();
+ SDLTest_CommonQuit(state);
return 0;
}
diff --git a/test/testlocale.c b/test/testlocale.c
index 6e371ca1..4d17cec1 100644
--- a/test/testlocale.c
+++ b/test/testlocale.c
@@ -11,6 +11,7 @@
*/
#include <stdio.h>
#include "SDL.h"
+#include "SDL_test.h"
/* !!! FIXME: move this to the test framework */
@@ -35,32 +36,64 @@ static void log_locales(void)
int main(int argc, char **argv)
{
+ SDLTest_CommonState *state;
+ SDL_bool listen = SDL_FALSE;
+ int i = 1;
+
+ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
+ if (!state) {
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
+ return 1;
+ }
+
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
+ /* Parse commandline */
+ for (i = 1; i < argc;) {
+ int consumed;
+
+ consumed = SDLTest_CommonArg(state, i);
+ if (!consumed) {
+ if (SDL_strcmp("--listen", argv[i]) == 0) {
+ listen = SDL_TRUE;
+ consumed = 1;
+ }
+ }
+ if (consumed <= 0) {
+ static const char *options[] = { "[--listen]", NULL };
+ SDLTest_CommonLogUsage(state, argv[0], options);
+ exit(1);
+ }
+
+ i += consumed;
+ }
+
+ if (!SDLTest_CommonInit(state)) {
+ return 1;
+ }
+
/* Print locales and languages */
- if (SDL_Init(SDL_INIT_VIDEO) != -1) {
- log_locales();
-
- if ((argc == 2) && (SDL_strcmp(argv[1], "--listen") == 0)) {
- SDL_bool keep_going = SDL_TRUE;
- while (keep_going) {
- SDL_Event e;
- while (SDL_PollEvent(&e)) {
- if (e.type == SDL_QUIT) {
- keep_going = SDL_FALSE;
- } else if (e.type == SDL_LOCALECHANGED) {
- SDL_Log("Saw SDL_LOCALECHANGED event!");
- log_locales();
- }
+ log_locales();
+
+ if (listen) {
+ SDL_bool keep_going = SDL_TRUE;
+ while (keep_going) {
+ SDL_Event e;
+ while (SDL_PollEvent(&e)) {
+ if (e.type == SDL_QUIT) {
+ keep_going = SDL_FALSE;
+ } else if (e.type == SDL_LOCALECHANGED) {
+ SDL_Log("Saw SDL_LOCALECHANGED event!");
+ log_locales();
}
- SDL_Delay(10);
}
+ SDL_Delay(10);
}
-
- SDL_Quit();
}
+ SDLTest_CommonQuit(state);
+
return 0;
}
diff --git a/test/testplatform.c b/test/testplatform.c
index 353758a7..e017ef65 100644
--- a/test/testplatform.c
+++ b/test/testplatform.c
@@ -13,6 +13,7 @@
#include <stdio.h>
#include "SDL.h"
+#include "SDL_test.h"
/*
* Watcom C flags these as Warning 201: "Unreachable code" if you just
@@ -445,13 +446,42 @@ int main(int argc, char *argv[])
{
SDL_bool verbose = SDL_TRUE;
int status = 0;
+ int i;
+ SDLTest_CommonState *state;
+
+ state = SDLTest_CommonCreateState(argv, 0);
+
(Patch may be truncated, please check the link at the top of this post.)