From dbc1698000976e6fcde030224c70e55b6ff9e22c Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Sat, 31 Aug 2024 19:06:24 +0200 Subject: [PATCH] test: use SDL_test for parsing arguments in all non-interactive tests --- test/CMakeLists.txt | 44 ++++++++++++------------- test/testatomic.c | 19 +++++++++++ test/testaudioinfo.c | 17 ++++++++-- test/testbounds.c | 19 +++++++++-- test/testdisplayinfo.c | 17 ++++++++-- test/testerror.c | 17 ++++++++-- test/testevdev.c | 28 +++++++++++++++- 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 | 68 +++++++++++++++++++++++++++++++-------- test/testsurround.c | 16 +++++++-- test/testthread.c | 43 ++++++++++++++++++------- test/testtimer.c | 21 ++++++++---- test/testver.c | 20 +++++++++++- 18 files changed, 415 insertions(+), 101 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a19f88a757701e..a24461a2b17cb0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -36,7 +36,7 @@ macro(sdltest_add_definitions) endmacro() macro(add_sdl_test_executable TARGET) - cmake_parse_arguments(AST "NONINTERACTIVE;NEEDS_RESOURCES;NOTRACKMEM" "" "" ${ARGN}) + cmake_parse_arguments(AST "NONINTERACTIVE;NEEDS_RESOURCES" "" "" ${ARGN}) list(APPEND SDLTEST_TARGETS ${TARGET}) if(ANDROID) add_library(${TARGET} SHARED ${AST_UNPARSED_ARGUMENTS}) @@ -45,7 +45,6 @@ macro(add_sdl_test_executable TARGET) endif() list(APPEND SDL_TEST_EXECUTABLES ${TARGET}) - set_property(TARGET ${TARGET} PROPERTY SDL_NOTRACKMEM ${AST_NOTRACKMEM}) if(AST_NONINTERACTIVE) list(APPEND SDL_TESTS_NONINTERACTIVE ${TARGET}) endif() @@ -112,26 +111,26 @@ add_sdl_test_executable(checkkeys checkkeys.c) add_sdl_test_executable(checkkeysthreads checkkeysthreads.c) add_sdl_test_executable(loopwave NEEDS_RESOURCES loopwave.c testutils.c) add_sdl_test_executable(loopwavequeue NEEDS_RESOURCES loopwavequeue.c testutils.c) -add_sdl_test_executable(testsurround NOTRACKMEM testsurround.c) +add_sdl_test_executable(testsurround testsurround.c) add_sdl_test_executable(testresample NEEDS_RESOURCES testresample.c) -add_sdl_test_executable(testaudioinfo NOTRACKMEM testaudioinfo.c) +add_sdl_test_executable(testaudioinfo testaudioinfo.c) file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c) add_sdl_test_executable(testautomation NONINTERACTIVE NEEDS_RESOURCES ${TESTAUTOMATION_SOURCE_FILES}) add_sdl_test_executable(testmultiaudio NEEDS_RESOURCES testmultiaudio.c testutils.c) add_sdl_test_executable(testaudiohotplug NEEDS_RESOURCES testaudiohotplug.c testutils.c) add_sdl_test_executable(testaudiocapture testaudiocapture.c) -add_sdl_test_executable(testatomic NOTRACKMEM NONINTERACTIVE testatomic.c) +add_sdl_test_executable(testatomic NONINTERACTIVE testatomic.c) add_sdl_test_executable(testintersections testintersections.c) add_sdl_test_executable(testrelative testrelative.c) add_sdl_test_executable(testhittesting testhittesting.c) add_sdl_test_executable(testdraw2 testdraw2.c) add_sdl_test_executable(testdrawchessboard testdrawchessboard.c) add_sdl_test_executable(testdropfile testdropfile.c) -add_sdl_test_executable(testerror NOTRACKMEM NONINTERACTIVE testerror.c) +add_sdl_test_executable(testerror NONINTERACTIVE testerror.c) if(LINUX) - add_sdl_test_executable(testevdev NOTRACKMEM NONINTERACTIVE testevdev.c) + add_sdl_test_executable(testevdev NONINTERACTIVE testevdev.c) endif() add_sdl_test_executable(testfile testfile.c) @@ -148,13 +147,13 @@ endif() add_sdl_test_executable(testhaptic testhaptic.c) add_sdl_test_executable(testhotplug testhotplug.c) add_sdl_test_executable(testrumble testrumble.c) -add_sdl_test_executable(testthread NOTRACKMEM NONINTERACTIVE testthread.c) +add_sdl_test_executable(testthread NONINTERACTIVE testthread.c) add_sdl_test_executable(testiconv NEEDS_RESOURCES testiconv.c testutils.c) add_sdl_test_executable(testime NEEDS_RESOURCES testime.c testutils.c) add_sdl_test_executable(testjoystick testjoystick.c) -add_sdl_test_executable(testkeys NOTRACKMEM testkeys.c) +add_sdl_test_executable(testkeys testkeys.c) add_sdl_test_executable(testloadso testloadso.c) -add_sdl_test_executable(testlocale NOTRACKMEM NONINTERACTIVE testlocale.c) +add_sdl_test_executable(testlocale NONINTERACTIVE testlocale.c) add_sdl_test_executable(testlock testlock.c) add_sdl_test_executable(testmouse testmouse.c) @@ -182,11 +181,11 @@ elseif(OS2) endif() add_sdl_test_executable(testoverlay2 NEEDS_RESOURCES testoverlay2.c testyuv_cvt.c testutils.c) -add_sdl_test_executable(testplatform NOTRACKMEM NONINTERACTIVE testplatform.c) -add_sdl_test_executable(testpower NOTRACKMEM NONINTERACTIVE testpower.c) -add_sdl_test_executable(testfilesystem NOTRACKMEM NONINTERACTIVE testfilesystem.c) +add_sdl_test_executable(testplatform NONINTERACTIVE testplatform.c) +add_sdl_test_executable(testpower NONINTERACTIVE testpower.c) +add_sdl_test_executable(testfilesystem NONINTERACTIVE testfilesystem.c) if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4) - add_sdl_test_executable(testfilesystem_pre NOTRACKMEM NONINTERACTIVE testfilesystem_pre.c) + add_sdl_test_executable(testfilesystem_pre NONINTERACTIVE testfilesystem_pre.c) endif() add_sdl_test_executable(testrendertarget NEEDS_RESOURCES testrendertarget.c testutils.c) add_sdl_test_executable(testscale NEEDS_RESOURCES testscale.c testutils.c) @@ -197,18 +196,18 @@ add_sdl_test_executable(testshape NEEDS_RESOURCES testshape.c) add_sdl_test_executable(testsprite2 NEEDS_RESOURCES testsprite2.c testutils.c) add_sdl_test_executable(testspriteminimal NEEDS_RESOURCES testspriteminimal.c testutils.c) add_sdl_test_executable(teststreaming NEEDS_RESOURCES teststreaming.c testutils.c) -add_sdl_test_executable(testtimer NOTRACKMEM NONINTERACTIVE testtimer.c) +add_sdl_test_executable(testtimer NONINTERACTIVE testtimer.c) add_sdl_test_executable(testurl testurl.c) -add_sdl_test_executable(testver NOTRACKMEM NONINTERACTIVE testver.c) +add_sdl_test_executable(testver NONINTERACTIVE testver.c) add_sdl_test_executable(testviewport NEEDS_RESOURCES testviewport.c testutils.c) add_sdl_test_executable(testwm2 testwm2.c) add_sdl_test_executable(testyuv NEEDS_RESOURCES testyuv.c testyuv_cvt.c) add_sdl_test_executable(torturethread torturethread.c) add_sdl_test_executable(testrendercopyex NEEDS_RESOURCES testrendercopyex.c testutils.c) add_sdl_test_executable(testmessage testmessage.c) -add_sdl_test_executable(testdisplayinfo NOTRACKMEM testdisplayinfo.c) -add_sdl_test_executable(testqsort NOTRACKMEM NONINTERACTIVE testqsort.c) -add_sdl_test_executable(testbounds NOTRACKMEM testbounds.c) +add_sdl_test_executable(testdisplayinfo testdisplayinfo.c) +add_sdl_test_executable(testqsort NONINTERACTIVE testqsort.c) +add_sdl_test_executable(testbounds testbounds.c) add_sdl_test_executable(testcustomcursor testcustomcursor.c) add_sdl_test_executable(controllermap NEEDS_RESOURCES controllermap.c testutils.c) add_sdl_test_executable(testvulkan testvulkan.c) @@ -505,10 +504,7 @@ set(TESTS_ENVIRONMENT foreach(TESTCASE ${SDL_TESTS_NONINTERACTIVE}) set(command ${TESTCASE}) if(SDLTEST_TRACKMEM) - get_property(notrackmem TARGET ${TESTCASE} PROPERTY SDL_NOTRACKMEM) - if(NOT notrackmem) - list(APPEND command --trackmem) - endif() + list(APPEND command --trackmem) endif() add_test( NAME ${TESTCASE} @@ -520,7 +516,7 @@ foreach(TESTCASE ${SDL_TESTS_NONINTERACTIVE}) ENVIRONMENT "${TESTS_ENVIRONMENT}" TIMEOUT 10 ) - if(NOT notrackmem) + if(SDLTEST_TRACKMEM) set_property(TEST ${TESTCASE} PROPERTY FAIL_REGULAR_EXPRESSION "Total: [0-9]+\\.[0-9]+ Kb in [1-9][0-9]* allocations") endif() if(SDL_INSTALL_TESTS) diff --git a/test/testatomic.c b/test/testatomic.c index c19415ac16a4d1..1574295aa5adea 100644 --- a/test/testatomic.c +++ b/test/testatomic.c @@ -12,6 +12,7 @@ #include #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 ec4b86470d707b..eb9afa70fb1392 100644 --- a/test/testaudioinfo.c +++ b/test/testaudioinfo.c @@ -11,6 +11,7 @@ */ #include #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 9bd73ac962d18d..8879d5fbdd84ae 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 9740ab17428783..94f5ccee6bb2e5 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 #include @@ -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 25874d1ea78f75..3124da2f20c5ea 100644 --- a/test/testerror.c +++ b/test/testerror.c @@ -16,6 +16,7 @@ #include #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/testevdev.c b/test/testevdev.c index 67124ae0f461e3..eed3802f8ee3d8 100644 --- a/test/testevdev.c +++ b/test/testevdev.c @@ -1037,7 +1037,33 @@ run_test(void) #endif +#include "SDL_test.h" + int main(int argc, char *argv[]) { - return run_test() ? 0 : 1; + SDLTest_CommonState *state; + int success; + + 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; + } + + success = run_test(); + + SDLTest_CommonQuit(state); + return success ? 0 : 1; } diff --git a/test/testfilesystem.c b/test/testfilesystem.c index af0bd9f05a3818..33426e2e1e0813 100644 --- a/test/testfilesystem.c +++ b/test/testfilesystem.c @@ -13,17 +13,29 @@ #include #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 11615abd281f53..b9beaaf203ea39 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 c7b120b4f52979..d477047552d240 100644 --- a/test/testkeys.c +++ b/test/testkeys.c @@ -18,14 +18,31 @@ #include #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 6e371ca10175ae..4d17cec13d7a8d 100644 --- a/test/testlocale.c +++ b/test/testlocale.c @@ -11,6 +11,7 @@ */ #include #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 353758a7dac2c7..e017ef65da02f1 100644 --- a/test/testplatform.c +++ b/test/testplatform.c @@ -13,6 +13,7 @@ #include #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); + 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 (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) { - verbose = SDL_FALSE; + /* Parse commandline */ + for (i = 1; i < argc;) { + int consumed; + + consumed = SDLTest_CommonArg(state, i); + if (!consumed) { + if (SDL_strcmp("-q", argv[i]) == 0) { + verbose = SDL_FALSE; + consumed = 1; + } + } + if (consumed <= 0) { + static const char *options[] = { "[-q]", NULL }; + SDLTest_CommonLogUsage(state, argv[0], options); + exit(1); + } + + i += consumed; } + + if (!SDLTest_CommonInit(state)) { + return 1; + } + if (verbose) { SDL_Log("This system is running %s\n", SDL_GetPlatform()); } @@ -462,5 +492,6 @@ int main(int argc, char *argv[]) status += TestCPUInfo(verbose); status += TestAssertions(verbose); + SDLTest_CommonQuit(state); return status; } diff --git a/test/testpower.c b/test/testpower.c index 1c13b4dbaf5893..426a61235c1bf7 100644 --- a/test/testpower.c +++ b/test/testpower.c @@ -13,6 +13,7 @@ #include #include "SDL.h" +#include "SDL_test.h" static void report_power(void) @@ -60,17 +61,29 @@ report_power(void) 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 (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; } report_power(); - SDL_Quit(); + SDLTest_CommonQuit(state); return 0; } diff --git a/test/testqsort.c b/test/testqsort.c index 9c1f7646d95c0c..d29d040539fcbd 100644 --- a/test/testqsort.c +++ b/test/testqsort.c @@ -43,33 +43,71 @@ test_sort(const char *desc, int *nums, const int arraylen) int main(int argc, char *argv[]) { + SDLTest_CommonState *state; static int nums[1024 * 100]; static const int itervals[] = { SDL_arraysize(nums), 12 }; int iteration; + int i; + SDL_bool custom_seed = SDL_FALSE; + Uint64 seed; SDLTest_RandomContext rndctx; - if (argc > 1) { - int success; - Uint64 seed = 0; - if (argv[1][0] == '0' && argv[1][1] == 'x') { - success = SDL_sscanf(argv[1] + 2, "%" SDL_PRIx64, &seed); - } else { - success = SDL_sscanf(argv[1], "%" SDL_PRIu64, &seed); - } - if (!success) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid seed. Use a decimal or hexadecimal number.\n"); - return 1; + 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); + + /* Parse commandline */ + for (i = 1; i < argc;) { + int consumed; + + consumed = SDLTest_CommonArg(state, i); + if (!consumed) { + if (!custom_seed) { + int success; + + if (argv[i][0] == '0' && argv[i][1] == 'x') { + success = SDL_sscanf(argv[i] + 2, "%" SDL_PRIx64, &seed); + } else { + success = SDL_sscanf(argv[i], "%" SDL_PRIu64, &seed); + } + if (!success) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid seed. Use a decimal or hexadecimal number.\n"); + return 1; + } + if (seed <= ((Uint64)0xffffffff)) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Seed must be equal or greater than 0x100000000.\n"); + return 1; + } + custom_seed = SDL_TRUE; + consumed = 1; + } } - if (seed <= ((Uint64)0xffffffff)) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Seed must be equal or greater than 0x100000000.\n"); - return 1; + + if (consumed <= 0) { + static const char *options[] = { "[SEED]", NULL }; + SDLTest_CommonLogUsage(state, argv[0], options); + exit(1); } + + i += consumed; + } + + if (custom_seed) { SDLTest_RandomInit(&rndctx, (unsigned int)(seed >> 32), (unsigned int)(seed & 0xffffffff)); } else { SDLTest_RandomInitTime(&rndctx); } SDL_Log("Using random seed 0x%08x%08x\n", rndctx.x, rndctx.c); + if (!SDLTest_CommonInit(state)) { + return 1; + } + for (iteration = 0; iteration < SDL_arraysize(itervals); iteration++) { const int arraylen = itervals[iteration]; int i; @@ -96,6 +134,8 @@ int main(int argc, char *argv[]) test_sort("random sorted", nums, arraylen); } + SDLTest_CommonQuit(state); + return 0; } diff --git a/test/testsurround.c b/test/testsurround.c index b7dc7d7818cce5..792b3951c32472 100644 --- a/test/testsurround.c +++ b/test/testsurround.c @@ -14,6 +14,7 @@ #include "SDL_config.h" #include "SDL.h" +#include "SDL_test.h" static int total_channels; static int active_channel; @@ -141,11 +142,22 @@ fill_buffer(void *unused, Uint8 *stream, int len) int main(int argc, char *argv[]) { int i; + 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); - 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; } @@ -204,7 +216,7 @@ int main(int argc, char *argv[]) SDL_CloseAudioDevice(dev); } - SDL_Quit(); + SDLTest_CommonQuit(state); return 0; } diff --git a/test/testthread.c b/test/testthread.c index 5ceac05ffac38e..892535055ec308 100644 --- a/test/testthread.c +++ b/test/testthread.c @@ -17,15 +17,18 @@ #include #include "SDL.h" +#include "SDL_test.h" static SDL_TLSID tls; static int alive = 0; static int testprio = 0; +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); SDL_Quit(); exit(rc); } @@ -82,14 +85,39 @@ killed(int sig) int main(int argc, char *argv[]) { - int arg = 1; + int i = 1; SDL_Thread *thread; + 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) { + /* Parse commandline */ + for (i = 1; i < argc;) { + int consumed; + + consumed = SDLTest_CommonArg(state, i); + if (!consumed) { + if (SDL_strcmp("--prio", argv[i]) == 0) { + testprio = 1; + consumed = 1; + } + } + if (consumed <= 0) { + static const char *options[] = { "[--prio]", NULL }; + SDLTest_CommonLogUsage(state, argv[0], options); + exit(1); + } + + i += consumed; + } + + if (!SDLTest_CommonInit(state)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } @@ -100,13 +128,6 @@ int main(int argc, char *argv[]) return 0; } - while (argv[arg] && *argv[arg] == '-') { - if (SDL_strcmp(argv[arg], "--prio") == 0) { - testprio = 1; - } - ++arg; - } - tls = SDL_TLSCreate(); SDL_assert(tls); SDL_TLSSet(tls, "main thread", NULL); @@ -134,6 +155,6 @@ int main(int argc, char *argv[]) } (void)raise(SIGTERM); - SDL_Quit(); /* Never reached */ + SDLTest_CommonQuit(state); /* Never reached */ return 0; /* Never reached */ } diff --git a/test/testtimer.c b/test/testtimer.c index aeecb4df94acf9..49af416a466625 100644 --- a/test/testtimer.c +++ b/test/testtimer.c @@ -78,16 +78,24 @@ int main(int argc, char *argv[]) Uint64 start, now; SDL_bool run_interactive_tests = SDL_FALSE; int return_code = 0; + SDLTest_CommonState *state; + + state = SDLTest_CommonCreateState(argv, SDL_INIT_TIMER); + 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 = 0; + int consumed; + consumed = SDLTest_CommonArg(state, i); if (!consumed) { - if (SDL_strcmp(argv[i], "--interactive") == 0) { + if (SDL_strcmp("--interactive", argv[i]) == 0) { run_interactive_tests = SDL_TRUE; consumed = 1; } else if (desired < 0) { @@ -100,14 +108,15 @@ int main(int argc, char *argv[]) } } if (consumed <= 0) { - SDL_Log("Usage: %s [--interactive] [interval]", argv[0]); - return 1; + static const char *options[] = { "[--interactive]", "[interval]", NULL }; + SDLTest_CommonLogUsage(state, argv[0], options); + exit(1); } i += consumed; } - if (SDL_Init(SDL_INIT_TIMER) < 0) { + if (!SDLTest_CommonInit(state)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } @@ -203,7 +212,7 @@ int main(int argc, char *argv[]) if (run_interactive_tests) { return_code |= test_sdl_delay_within_bounds(); } - SDL_Quit(); + SDLTest_CommonQuit(state); return return_code; } diff --git a/test/testver.c b/test/testver.c index 409b1f12f3967d..20dcf843091078 100644 --- a/test/testver.c +++ b/test/testver.c @@ -19,15 +19,32 @@ #include "SDL.h" #include "SDL_revision.h" +#include "SDL_test.h" int main(int argc, char *argv[]) { SDL_version compiled; SDL_version linked; + 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; + } + #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_Log("Compiled with SDL 2.0 or newer\n"); #else @@ -41,6 +58,7 @@ int main(int argc, char *argv[]) SDL_Log("Linked version: %d.%d.%d (%s)\n", linked.major, linked.minor, linked.patch, SDL_GetRevision()); - SDL_Quit(); + + SDLTest_CommonQuit(state); return 0; }