Skip to content

Commit

Permalink
test: use SDL_test for parsing arguments in all non-interactive tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr committed Aug 31, 2024
1 parent e9c5398 commit dbc1698
Show file tree
Hide file tree
Showing 18 changed files with 415 additions and 101 deletions.
44 changes: 20 additions & 24 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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}
Expand All @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions test/testatomic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -715,6 +733,7 @@ int main(int argc, char *argv[])
RunFIFOTest(SDL_FALSE);
#endif
RunFIFOTest(SDL_TRUE);
SDLTest_CommonQuit(state);
return 0;
}

Expand Down
17 changes: 14 additions & 3 deletions test/testaudioinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"

static void
print_devices(int iscapture)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
19 changes: 17 additions & 2 deletions test/testbounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down
17 changes: 14 additions & 3 deletions test/testdisplayinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/* Program to test querying of display info */

#include "SDL.h"
#include "SDL_test.h"

#include <stdio.h>
#include <stdlib.h>
Expand All @@ -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;
}
Expand Down Expand Up @@ -88,7 +99,7 @@ int main(int argc, char *argv[])
SDL_Log("\n");
}

SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

Expand Down
17 changes: 14 additions & 3 deletions test/testerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <stdlib.h>

#include "SDL.h"
#include "SDL_test.h"

static int alive = 0;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
28 changes: 27 additions & 1 deletion test/testevdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading

0 comments on commit dbc1698

Please sign in to comment.