update sdl to 2.32.6

This commit is contained in:
AzaezelX 2025-05-24 13:39:03 -05:00
parent e557f5962b
commit ddc1f8c1e2
1339 changed files with 53966 additions and 19207 deletions

View file

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0...3.5)
project(SDL2_test)
cmake_minimum_required(VERSION 3.0...3.10)
project(SDL2_test C)
include(CheckCCompilerFlag)
include(CMakeParseArguments)
@ -7,18 +7,83 @@ include(CMakePushCheckState)
set(SDL_TEST_EXECUTABLES)
set(SDL_TESTS_NONINTERACTIVE)
set(SDL_TESTS_NEEDS_ESOURCES)
set(SDL_TESTS_NEEDS_RESOURCES)
option(SDLTEST_TRACKMEM "Run tests with --trackmem" OFF)
if(WIN32 AND NOT WINDOWS_STORE)
option(SDLTEST_PROCDUMP "Run tests using sdlprocdump for minidump generation" OFF)
add_executable(sdlprocdump win32/sdlprocdump.c)
if(SDLTEST_PROCDUMP)
set(CMAKE_TEST_LAUNCHER "$<TARGET_FILE:sdlprocdump>;--")
else()
set_property(TARGET sdlprocdump PROPERTY EXCLUDE_FROM_ALL "1")
endif()
endif()
set(SDLTEST_TARGETS )
macro(sdltest_link_librararies)
foreach(TARGET ${SDLTEST_TARGETS})
target_link_libraries(${TARGET} PRIVATE ${ARGN})
endforeach()
endmacro()
macro(sdltest_add_definitions)
foreach(TARGET ${SDLTEST_TARGETS})
target_compile_definitions(${TARGET} PRIVATE ${ARGN})
endforeach()
endmacro()
macro(add_sdl_test_executable TARGET)
cmake_parse_arguments(AST "NONINTERACTIVE;NEEDS_RESOURCES" "" "" ${ARGN})
add_executable(${TARGET} ${AST_UNPARSED_ARGUMENTS})
cmake_parse_arguments(AST "NONINTERACTIVE;NEEDS_RESOURCES;NOTRACKMEM" "" "" ${ARGN})
list(APPEND SDLTEST_TARGETS ${TARGET})
if(ANDROID)
add_library(${TARGET} SHARED ${AST_UNPARSED_ARGUMENTS})
else()
add_executable(${TARGET} ${AST_UNPARSED_ARGUMENTS})
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()
if(AST_NEEDS_RESOURCES)
list(APPEND SDL_TESTS_NEEDS_ESOURCES ${TARGET})
list(APPEND SDL_TESTS_NEEDS_RESOURCES ${TARGET})
endif()
if(HAVE_GCC_WDOCUMENTATION)
target_compile_options(${TARGET} PRIVATE "-Wdocumentation")
if(HAVE_GCC_WERROR_DOCUMENTATION)
target_compile_options(${TARGET} PRIVATE "-Werror=documentation")
endif()
endif()
if(HAVE_GCC_WDOCUMENTATION_UNKNOWN_COMMAND)
if(SDL_WERROR)
if(HAVE_GCC_WERROR_DOCUMENTATION_UNKNOWN_COMMAND)
target_compile_options(${TARGET} PRIVATE "-Werror=documentation-unknown-command")
endif()
endif()
target_compile_options(${TARGET} PRIVATE "-Wdocumentation-unknown-command")
endif()
if(HAVE_GCC_COMMENT_BLOCK_COMMANDS)
target_compile_options(${TARGET} PRIVATE "-fcomment-block-commands=threadsafety")
target_compile_options(${TARGET} PRIVATE "-fcomment-block-commands=deprecated")
else()
if(HAVE_CLANG_COMMENT_BLOCK_COMMANDS)
target_compile_options(${TARGET} PRIVATE "/clang:-fcomment-block-commands=threadsafety")
target_compile_options(${TARGET} PRIVATE "/clang:-fcomment-block-commands=deprecated")
endif()
endif()
if(USE_GCC OR USE_CLANG)
check_c_compiler_flag(-fno-fast-math HAVE_GCC_FNO_FAST_MATH)
if(HAVE_GCC_FNO_FAST_MATH)
target_compile_options(${TARGET} PRIVATE -fno-fast-math)
endif()
endif()
endmacro()
@ -32,57 +97,6 @@ if(SDL_INSTALL_TESTS)
include(GNUInstallDirs)
endif()
if(N3DS)
link_libraries(SDL2::SDL2main)
endif()
if(PSP)
link_libraries(
SDL2::SDL2main
SDL2::SDL2test
SDL2::SDL2-static
GL
pspvram
pspvfpu
pspdisplay
pspgu
pspge
pspaudio
pspctrl
psphprm
psppower
)
elseif(PS2)
link_libraries(
SDL2main
SDL2_test
SDL2-static
patches
gskit
dmakit
ps2_drivers
)
else()
link_libraries(SDL2::SDL2test SDL2::SDL2-static)
endif()
if(WINDOWS)
# mingw32 must come before SDL2main to link successfully
if(MINGW OR CYGWIN)
link_libraries(mingw32)
endif()
# CET support was added in VS 16.7
if(MSVC_VERSION GREATER 1926 AND CMAKE_GENERATOR_PLATFORM MATCHES "Win32|x64")
link_libraries(-CETCOMPAT)
endif()
# FIXME: Parent directory CMakeLists.txt only sets these for mingw/cygwin,
# but we need them for VS as well.
link_libraries(SDL2main)
add_definitions(-Dmain=SDL_main)
endif()
# CMake incorrectly detects opengl32.lib being present on MSVC ARM64
if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
# Prefer GLVND, if present
@ -91,7 +105,7 @@ if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
endif()
if (OPENGL_FOUND)
add_definitions(-DHAVE_OPENGL)
add_definitions(-DHAVE_OPENGL)
endif()
add_sdl_test_executable(checkkeys checkkeys.c)
@ -103,7 +117,7 @@ add_sdl_test_executable(testresample NEEDS_RESOURCES testresample.c)
add_sdl_test_executable(testaudioinfo testaudioinfo.c)
file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
add_sdl_test_executable(testautomation NEEDS_RESOURCES ${TESTAUTOMATION_SOURCE_FILES})
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)
@ -117,7 +131,7 @@ add_sdl_test_executable(testdropfile testdropfile.c)
add_sdl_test_executable(testerror NONINTERACTIVE testerror.c)
if(LINUX)
add_sdl_test_executable(testevdev NONINTERACTIVE testevdev.c)
add_sdl_test_executable(testevdev NOTRACKMEM NONINTERACTIVE testevdev.c)
endif()
add_sdl_test_executable(testfile testfile.c)
@ -128,6 +142,9 @@ add_sdl_test_executable(testgl2 testgl2.c)
add_sdl_test_executable(testgles testgles.c)
add_sdl_test_executable(testgles2 testgles2.c)
add_sdl_test_executable(testgles2_sdf NEEDS_RESOURCES testgles2_sdf.c testutils.c)
if(APPLE)
set_property(TARGET testgles testgles2 testgles2_sdf APPEND PROPERTY COMPILE_DEFINITIONS "GLES_SILENCE_DEPRECATION")
endif()
add_sdl_test_executable(testhaptic testhaptic.c)
add_sdl_test_executable(testhotplug testhotplug.c)
add_sdl_test_executable(testrumble testrumble.c)
@ -159,7 +176,7 @@ elseif(WINDOWS)
add_sdl_test_executable(testnative NEEDS_RESOURCES testnative.c testnativew32.c testutils.c)
elseif(HAVE_X11)
add_sdl_test_executable(testnative NEEDS_RESOURCES testnative.c testnativex11.c testutils.c)
target_link_libraries(testnative X11)
target_link_libraries(testnative PRIVATE X11)
elseif(OS2)
add_sdl_test_executable(testnative NEEDS_RESOURCES testnative.c testnativeos2.c testutils.c)
endif()
@ -197,6 +214,59 @@ add_sdl_test_executable(controllermap NEEDS_RESOURCES controllermap.c testutils.
add_sdl_test_executable(testvulkan testvulkan.c)
add_sdl_test_executable(testoffscreen testoffscreen.c)
if(N3DS)
sdltest_link_librararies(SDL2::SDL2main)
endif()
if(PSP)
sdltest_link_librararies(
SDL2::SDL2main
SDL2::SDL2test
SDL2::SDL2-static
GL
pspvram
pspvfpu
pspdisplay
pspgu
pspge
pspaudio
pspctrl
psphprm
psppower
)
elseif(PS2)
sdltest_link_librararies(
SDL2main
SDL2_test
SDL2-static
patches
gskit
dmakit
ps2_drivers
)
elseif(IOS OR TVOS)
sdltest_link_librararies(SDL2::SDL2main SDL2::SDL2test SDL2::SDL2-static)
else()
sdltest_link_librararies(SDL2::SDL2test SDL2::SDL2-static)
endif()
if(WINDOWS)
# mingw32 must come before SDL2main to link successfully
if(MINGW OR CYGWIN)
sdltest_link_librararies(mingw32)
endif()
# CET support was added in VS 16.7
if(MSVC_VERSION GREATER 1926 AND CMAKE_GENERATOR_PLATFORM MATCHES "Win32|x64")
sdltest_link_librararies(-CETCOMPAT)
endif()
# FIXME: Parent directory CMakeLists.txt only sets these for mingw/cygwin,
# but we need them for VS as well.
sdltest_link_librararies(SDL2main)
sdltest_add_definitions(-Dmain=SDL_main)
endif()
cmake_push_check_state(RESET)
check_c_compiler_flag(-Wformat-overflow HAVE_WFORMAT_OVERFLOW)
@ -217,35 +287,35 @@ endif()
cmake_pop_check_state()
if(SDL_DUMMYAUDIO)
list(APPEND SDL_TESTS_NONINTERACTIVE
testaudioinfo
testsurround
)
list(APPEND SDL_TESTS_NONINTERACTIVE
testaudioinfo
testsurround
)
endif()
if(SDL_DUMMYVIDEO)
list(APPEND SDL_TESTS_NONINTERACTIVE
testkeys
testbounds
testdisplayinfo
)
list(APPEND SDL_TESTS_NONINTERACTIVE
testkeys
testbounds
testdisplayinfo
)
endif()
if(OPENGL_FOUND)
if(TARGET OpenGL::GL)
target_link_libraries(testshader OpenGL::GL)
target_link_libraries(testgl2 OpenGL::GL)
target_link_libraries(testshader PRIVATE OpenGL::GL)
target_link_libraries(testgl2 PRIVATE OpenGL::GL)
else()
if(EMSCRIPTEN AND OPENGL_gl_LIBRARY STREQUAL "nul")
set(OPENGL_gl_LIBRARY GL)
endif()
# emscripten's FindOpenGL.cmake does not create OpenGL::GL
target_link_libraries(testshader ${OPENGL_gl_LIBRARY})
target_link_libraries(testgl2 ${OPENGL_gl_LIBRARY})
target_link_libraries(testshader PRIVATE ${OPENGL_gl_LIBRARY})
target_link_libraries(testgl2 PRIVATE ${OPENGL_gl_LIBRARY})
endif()
endif()
if(EMSCRIPTEN)
target_link_libraries(testshader -sLEGACY_GL_EMULATION)
target_link_libraries(testshader PRIVATE -sLEGACY_GL_EMULATION)
endif()
file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
@ -254,7 +324,7 @@ file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
if(PSP)
# Build EBOOT files if building for PSP
set(BUILD_EBOOT
${SDL_TESTS_NEEDS_ESOURCES}
${SDL_TESTS_NEEDS_RESOURCES}
testatomic
testaudiocapture
testaudioinfo
@ -294,47 +364,17 @@ if(PSP)
ICON_PATH NULL
BACKGROUND_PATH NULL
PREVIEW_PATH NULL
)
add_custom_command(
TARGET ${APP} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory
$<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}
)
add_custom_command(
TARGET ${APP} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rename
$<TARGET_FILE_DIR:${ARG_TARGET}>/EBOOT.PBP
$<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/EBOOT.PBP
)
if(${BUILD_PRX})
add_custom_command(
TARGET ${APP} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}
$<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}
)
add_custom_command(
TARGET ${APP} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E rename
$<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}.prx
$<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}.prx
)
endif()
add_custom_command(
TARGET ${APP} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E remove
$<TARGET_FILE_DIR:${ARG_TARGET}>/PARAM.SFO
OUTPUT_DIR $<TARGET_FILE_DIR:${APP}>/sdl-${APP}
)
endforeach()
endif()
if(N3DS)
set(ROMFS_DIR "${CMAKE_CURRENT_BINARY_DIR}/romfs")
file(COPY ${RESOURCE_FILES} DESTINATION "${ROMFS_DIR}")
foreach(APP IN LISTS SDL_TEST_EXECUTABLES)
get_target_property(TARGET_BINARY_DIR ${APP} BINARY_DIR)
set(ROMFS_DIR "${TARGET_BINARY_DIR}/sdl-${APP}")
set(SMDH_FILE "${TARGET_BINARY_DIR}/${APP}.smdh")
file(MAKE_DIRECTORY ${ROMFS_DIR})
ctr_generate_smdh("${SMDH_FILE}"
NAME "SDL-${APP}"
DESCRIPTION "SDL2 Test suite"
@ -363,14 +403,41 @@ if(RISCOS)
endforeach()
endif()
if(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(test_bin_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
if(NOT IS_ABSOLUTE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
set(test_bin_dir "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
endif()
else()
set(test_bin_dir "${CMAKE_CURRENT_BINARY_DIR}")
endif()
if(NOT CMAKE_VERSION VERSION_LESS 3.20)
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
set(test_bin_dir "${test_bin_dir}$<$<BOOL:${is_multi_config}>:/$<CONFIG>>")
endif()
set(RESOURCE_FILES_BINDIR)
foreach(resource_file IN LISTS RESOURCE_FILES)
get_filename_component(res_file_name ${resource_file} NAME)
set(resource_file_bindir "${test_bin_dir}/${res_file_name}")
add_custom_command(OUTPUT "${resource_file_bindir}"
COMMAND "${CMAKE_COMMAND}" -E copy "${resource_file}" "${resource_file_bindir}"
DEPENDS "${resource_file}"
)
list(APPEND RESOURCE_FILES_BINDIR "${resource_file_bindir}")
endforeach()
add_custom_target(copy-sdl-test-resources
DEPENDS "${RESOURCE_FILES_BINDIR}"
)
foreach(APP IN LISTS SDL_TESTS_NEEDS_RESOURCES)
foreach(RESOURCE_FILE ${RESOURCE_FILES})
if(PSP OR PS2)
if(PSP OR PS2 OR N3DS)
foreach(RESOURCE_FILE ${RESOURCE_FILES})
add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>/sdl-${APP})
else()
add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
endif()
endforeach(RESOURCE_FILE)
endforeach()
else()
add_dependencies(${APP} copy-sdl-test-resources)
endif()
if(APPLE)
# Make sure resource files get installed into macOS/iOS .app bundles.
target_sources(${APP} PRIVATE "${RESOURCE_FILES}")
@ -406,9 +473,16 @@ 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()
endif()
add_test(
NAME ${TESTCASE}
COMMAND ${TESTCASE}
COMMAND ${command}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set_tests_properties(${TESTCASE}
@ -416,6 +490,9 @@ foreach(TESTCASE ${SDL_TESTS_NONINTERACTIVE})
ENVIRONMENT "${TESTS_ENVIRONMENT}"
TIMEOUT 10
)
if(NOT notrackmem)
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)
set(exe ${TESTCASE})
set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL2")
@ -427,6 +504,7 @@ foreach(TESTCASE ${SDL_TESTS_NONINTERACTIVE})
endif()
endforeach()
set_tests_properties(testautomation PROPERTIES TIMEOUT 120)
set_tests_properties(testthread PROPERTIES TIMEOUT 40)
set_tests_properties(testtimer PROPERTIES TIMEOUT 60)
if(TARGET testfilesystem_pre)
@ -446,6 +524,11 @@ if(SDL_INSTALL_TESTS)
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
)
endif()
if(MSVC)
foreach(test ${SDL_TEST_EXECUTABLES})
SDL_install_pdb(${test} "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2")
endforeach()
endif()
install(
FILES ${RESOURCE_FILES}
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2

View file

@ -95,7 +95,7 @@ installedtestsmetadir = $(datadir)/installed-tests/SDL2
generatetestmeta:
rm -f *.test
set -e; for exe in $(noninteractive) $(needs_audio) $(needs_display); do \
set -e; for exe in $(TESTS); do \
sed \
-e 's#@installedtestsdir@#$(installedtestsdir)#g' \
-e "s#@exe@#$$exe#g" \
@ -141,6 +141,7 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
$(srcdir)/testautomation_hints.c \
$(srcdir)/testautomation_joystick.c \
$(srcdir)/testautomation_keyboard.c \
$(srcdir)/testautomation_log.c \
$(srcdir)/testautomation_main.c \
$(srcdir)/testautomation_math.c \
$(srcdir)/testautomation_mouse.c \
@ -151,6 +152,7 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
$(srcdir)/testautomation_rwops.c \
$(srcdir)/testautomation_sdltest.c \
$(srcdir)/testautomation_stdlib.c \
$(srcdir)/testautomation_subsystems.c \
$(srcdir)/testautomation_surface.c \
$(srcdir)/testautomation_syswm.c \
$(srcdir)/testautomation_timer.c \
@ -385,8 +387,12 @@ distclean: clean
rm -f config.status config.cache config.log
rm -rf $(srcdir)/autom4te*
noninteractive = \
TESTS = \
testatomic$(EXE) \
testaudioinfo$(EXE) \
testautomation$(EXE) \
testbounds$(EXE) \
testdisplayinfo$(EXE) \
testerror$(EXE) \
testevdev$(EXE) \
testfilesystem$(EXE) \
@ -395,23 +401,12 @@ noninteractive = \
testplatform$(EXE) \
testpower$(EXE) \
testqsort$(EXE) \
testsurround$(EXE) \
testthread$(EXE) \
testtimer$(EXE) \
testver$(EXE) \
$(NULL)
needs_audio = \
testaudioinfo$(EXE) \
testsurround$(EXE) \
$(NULL)
needs_display = \
testbounds$(EXE) \
testdisplayinfo$(EXE) \
$(NULL)
TESTS = $(noninteractive) $(needs_audio) $(needs_display)
check:
@set -e; \
status=0; \

View file

@ -5,8 +5,6 @@
# stolen from Manish Singh
# Shamelessly stolen from Owen Taylor
# serial 2
dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
dnl
@ -45,7 +43,7 @@ AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run
if test "x$sdl_pc" = xyes ; then
no_sdl=""
SDL2_CONFIG="pkg-config sdl2"
SDL2_CONFIG="$PKG_CONFIG sdl2"
else
as_save_PATH="$PATH"
if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -107,7 +107,7 @@ print_modifiers(char **text, size_t *maxlen)
}
static void
PrintModifierState()
PrintModifierState(void)
{
char message[512];
char *spot;
@ -166,7 +166,7 @@ PrintText(const char *eventtype, const char *text)
SDL_Log("%s Text (%s): \"%s%s\"\n", eventtype, expanded, *text == '"' ? "\\" : "", text);
}
void loop()
void loop(void)
{
SDL_Event event;
/* Check for events */
@ -269,14 +269,14 @@ int main(int argc, char *argv[])
window = SDL_CreateWindow("CheckKeys Test",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
640, 480, 0);
if (window == NULL) {
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
SDL_GetError());
quit(2);
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n",
SDL_GetError());
quit(2);
@ -284,7 +284,7 @@ int main(int argc, char *argv[])
textwin = SDLTest_TextWindowCreate(0, 0, 640, 480);
#if __IPHONEOS__
#ifdef __IPHONEOS__
/* Creating the context creates the view, which we need to show keyboard */
SDL_GL_CreateContext(window);
#endif

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -103,7 +103,7 @@ print_modifiers(char **text, size_t *maxlen)
}
static void
PrintModifierState()
PrintModifierState(void)
{
char message[512];
char *spot;
@ -162,7 +162,7 @@ PrintText(const char *eventtype, const char *text)
SDL_Log("%s Text (%s): \"%s%s\"\n", eventtype, expanded, *text == '"' ? "\\" : "", text);
}
void loop()
void loop(void)
{
SDL_Event event;
/* Check for events */
@ -254,7 +254,7 @@ int main(int argc, char *argv[])
window = SDL_CreateWindow("CheckKeys Test",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
640, 480, 0);
if (window == NULL) {
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
SDL_GetError());
quit(2);
@ -266,7 +266,7 @@ int main(int argc, char *argv[])
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_RenderPresent(renderer);
#if __IPHONEOS__
#ifdef __IPHONEOS__
/* Creating the context creates the view, which we need to show keyboard */
SDL_GL_CreateContext(window);
#endif

View file

@ -3966,7 +3966,7 @@ fi
if test "x$sdl_pc" = xyes ; then
no_sdl=""
SDL2_CONFIG="pkg-config sdl2"
SDL2_CONFIG="$PKG_CONFIG sdl2"
else
as_save_PATH="$PATH"
if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -288,7 +288,8 @@ ConfigureBinding(const SDL_GameControllerExtendedBind *pBinding)
SDL_Log("Configuring button binding for button %d\n", pBinding->value.button);
break;
case SDL_CONTROLLER_BINDTYPE_AXIS:
SDL_Log("Configuring axis binding for axis %d %d/%d committed = %s\n", pBinding->value.axis.axis, pBinding->value.axis.axis_min, pBinding->value.axis.axis_max, pBinding->committed ? "true" : "false");
SDL_Log("Configuring axis binding for axis %d %d/%d committed = %s\n", pBinding->value.axis.axis, pBinding->value.axis.axis_min, pBinding->value.axis.axis_max,
pBinding->committed ? "true" : "false");
break;
case SDL_CONTROLLER_BINDTYPE_HAT:
SDL_Log("Configuring hat binding for hat %d %d\n", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
@ -729,13 +730,13 @@ int main(int argc, char *argv[])
window = SDL_CreateWindow("Game Controller Map", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
SCREEN_HEIGHT, 0);
if (window == NULL) {
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
return 2;
}
screen = SDL_CreateRenderer(window, -1, 0);
if (screen == NULL) {
if (!screen) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
return 2;
}
@ -766,7 +767,7 @@ int main(int argc, char *argv[])
name = SDL_JoystickNameForIndex(i);
SDL_Log("Joystick %d: %s\n", i, name ? name : "Unknown Joystick");
joystick = SDL_JoystickOpen(i);
if (joystick == NULL) {
if (!joystick) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_JoystickOpen(%d) failed: %s\n", i,
SDL_GetError());
} else {
@ -792,7 +793,7 @@ int main(int argc, char *argv[])
}
}
joystick = SDL_JoystickOpen(joystick_index);
if (joystick == NULL) {
if (!joystick) {
SDL_Log("Couldn't open joystick %d: %s\n", joystick_index, SDL_GetError());
} else {
WatchJoystick(joystick);

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -46,7 +46,7 @@ quit(int rc)
}
static void
close_audio()
close_audio(void)
{
if (device != 0) {
SDL_CloseAudioDevice(device);
@ -55,7 +55,7 @@ close_audio()
}
static void
open_audio()
open_audio(void)
{
/* Initialize fillerup() variables */
device = SDL_OpenAudioDevice(NULL, SDL_FALSE, &wave.spec, NULL, 0);
@ -70,7 +70,7 @@ open_audio()
}
#ifndef __EMSCRIPTEN__
static void reopen_audio()
static void reopen_audio(void)
{
close_audio();
open_audio();
@ -103,7 +103,7 @@ fillerup(void *unused, Uint8 *stream, int len)
static int done = 0;
#ifdef __EMSCRIPTEN__
void loop()
void loop(void)
{
if (done || (SDL_GetAudioDeviceStatus(device) != SDL_AUDIO_PLAYING)) {
emscripten_cancel_main_loop();
@ -127,7 +127,7 @@ int main(int argc, char *argv[])
filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
if (filename == NULL) {
if (!filename) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
quit(1);
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -21,7 +21,7 @@
#include "SDL.h"
#if HAVE_SIGNAL_H
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
@ -48,7 +48,7 @@ void poked(int sig)
done = 1;
}
void loop()
void loop(void)
{
#ifdef __EMSCRIPTEN__
if (done || (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING)) {
@ -84,7 +84,7 @@ int main(int argc, char *argv[])
filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
if (filename == NULL) {
if (!filename) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
quit(1);
}
@ -97,7 +97,7 @@ int main(int argc, char *argv[])
wave.spec.callback = NULL; /* we'll push audio. */
#if HAVE_SIGNAL_H
#ifdef HAVE_SIGNAL_H
/* Set the signals */
#ifdef SIGHUP
(void)signal(SIGHUP, poked);

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -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
@ -31,7 +32,7 @@ tf(SDL_bool _tf)
return f;
}
static void RunBasicTest()
static void RunBasicTest(void)
{
int value;
SDL_SpinLock lock = 0;
@ -130,7 +131,8 @@ static int SDLCALL adder(void *junk)
static void runAdder(void)
{
Uint32 start, end;
int T = NThreads;
int i;
SDL_Thread *threads[NThreads];
start = SDL_GetTicks();
@ -138,14 +140,18 @@ static void runAdder(void)
SDL_AtomicSet(&threadsRunning, NThreads);
while (T--) {
SDL_CreateThread(adder, "Adder", NULL);
for (i = 0; i < NThreads; i++) {
threads[i] = SDL_CreateThread(adder, "Adder", NULL);
}
while (SDL_AtomicGet(&threadsRunning) > 0) {
SDL_SemWait(threadDone);
}
for (i = 0; i < NThreads; i++) {
SDL_WaitThread(threads[i], NULL);
}
SDL_DestroySemaphore(threadDone);
end = SDL_GetTicks();
@ -153,7 +159,7 @@ static void runAdder(void)
SDL_Log("Finished in %f sec\n", (end - start) / 1000.f);
}
static void RunEpicTest()
static void RunEpicTest(void)
{
int b;
atomicValue v;
@ -234,7 +240,8 @@ static void RunEpicTest()
v = SDL_AtomicGet(&good);
SDL_Log("Atomic %d Non-Atomic %d\n", v, bad);
SDL_assert(v == Expect);
SDL_assert(bad != Expect);
/* We can't guarantee that bad != Expect, this would happen on a single core system, for example. */
/*SDL_assert(bad != Expect);*/
}
/* End atomic operation test */
@ -698,9 +705,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) {
@ -714,6 +738,8 @@ int main(int argc, char *argv[])
RunFIFOTest(SDL_FALSE);
#endif
RunFIFOTest(SDL_TRUE);
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -24,7 +24,7 @@ static SDL_AudioDeviceID devid_in = 0;
static SDL_AudioDeviceID devid_out = 0;
static void
loop()
loop(void)
{
SDL_bool please_quit = SDL_FALSE;
SDL_Event e;

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -17,7 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#if HAVE_SIGNAL_H
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
@ -81,7 +81,7 @@ devtypestr(int iscapture)
}
static void
iteration()
iteration(void)
{
SDL_Event e;
SDL_AudioDeviceID dev;
@ -96,7 +96,7 @@ iteration()
int index = e.adevice.which;
int iscapture = e.adevice.iscapture;
const char *name = SDL_GetAudioDeviceName(index, iscapture);
if (name != NULL) {
if (name) {
SDL_Log("New %s audio device at index %u: %s\n", devtypestr(iscapture), (unsigned int)index, name);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Got new %s device at index %u, but failed to get the name: %s\n",
@ -124,7 +124,7 @@ iteration()
}
#ifdef __EMSCRIPTEN__
void loop()
void loop(void)
{
if (done)
emscripten_cancel_main_loop();
@ -152,7 +152,7 @@ int main(int argc, char *argv[])
filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
if (filename == NULL) {
if (!filename) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
quit(1);
}
@ -163,7 +163,7 @@ int main(int argc, char *argv[])
quit(1);
}
#if HAVE_SIGNAL_H
#ifdef HAVE_SIGNAL_H
/* Set the signals */
#ifdef SIGHUP
(void)signal(SIGHUP, poked);

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -11,6 +11,7 @@
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
static void
print_devices(int iscapture)
@ -29,7 +30,7 @@ print_devices(int iscapture)
int i;
for (i = 0; i < n; i++) {
const char *name = SDL_GetAudioDeviceName(i, iscapture);
if (name != NULL) {
if (name) {
SDL_Log(" %d: %s\n", i, name);
} else {
SDL_Log(" %d Error: %s\n", i, SDL_GetError());
@ -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;
}
@ -81,7 +92,7 @@ int main(int argc, char **argv)
if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 0) < 0) {
SDL_Log("Error when calling SDL_GetDefaultAudioInfo: %s\n", SDL_GetError());
} else {
SDL_Log("Default Output Name: %s\n", deviceName != NULL ? deviceName : "unknown");
SDL_Log("Default Output Name: %s\n", deviceName ? deviceName : "unknown");
SDL_free(deviceName);
SDL_Log("Sample Rate: %d\n", spec.freq);
SDL_Log("Channels: %d\n", spec.channels);
@ -91,13 +102,13 @@ int main(int argc, char **argv)
if (SDL_GetDefaultAudioInfo(&deviceName, &spec, 1) < 0) {
SDL_Log("Error when calling SDL_GetDefaultAudioInfo: %s\n", SDL_GetError());
} else {
SDL_Log("Default Capture Name: %s\n", deviceName != NULL ? deviceName : "unknown");
SDL_Log("Default Capture Name: %s\n", deviceName ? deviceName : "unknown");
SDL_free(deviceName);
SDL_Log("Sample Rate: %d\n", spec.freq);
SDL_Log("Channels: %d\n", spec.channels);
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
}
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -41,7 +41,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}

View file

@ -52,6 +52,42 @@ void SDLCALL _audio_testCallback(void *userdata, Uint8 *stream, int len)
_audio_testCallbackLength += len;
}
#if defined(__linux__)
/* Linux builds can include many audio drivers, but some are very
* obscure and typically unsupported on modern systems. They will
* be skipped in tests that run against all included drivers, as
* they are basically guaranteed to fail.
*/
static SDL_bool DriverIsProblematic(const char *driver)
{
static const char *driverList[] = {
/* Omnipresent in Linux builds, but deprecated since 2002,
* very rarely used on Linux nowadays, and is almost certainly
* guaranteed to fail.
*/
"dsp",
/* OpenBSD sound API. Can be used on Linux, but very rare. */
"sndio",
/* Always fails on initialization and/or opening a device.
* Does anyone or anything actually use this?
*/
"nas"
};
int i;
for (i = 0; i < SDL_arraysize(driverList); ++i) {
if (SDL_strcmp(driver, driverList[i]) == 0) {
return SDL_TRUE;
}
}
return SDL_FALSE;
}
#endif
/* Test case functions */
/**
@ -60,7 +96,7 @@ void SDLCALL _audio_testCallback(void *userdata, Uint8 *stream, int len)
* \sa https://wiki.libsdl.org/SDL_QuitSubSystem
* \sa https://wiki.libsdl.org/SDL_InitSubSystem
*/
int audio_quitInitAudioSubSystem()
int audio_quitInitAudioSubSystem(void)
{
/* Stop SDL audio subsystem */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
@ -78,25 +114,48 @@ int audio_quitInitAudioSubSystem()
* \sa https://wiki.libsdl.org/SDL_InitAudio
* \sa https://wiki.libsdl.org/SDL_QuitAudio
*/
int audio_initQuitAudio()
int audio_initQuitAudio(void)
{
int result;
int i, iMax;
const char *audioDriver;
const char *hint = SDL_GetHint(SDL_HINT_AUDIODRIVER);
/* Stop SDL audio subsystem */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
/* Loop over all available audio drivers */
iMax = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
/* Was a specific driver requested? */
audioDriver = SDL_GetHint(SDL_HINT_AUDIODRIVER);
if (audioDriver == NULL) {
/* Loop over all available audio drivers */
iMax = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
} else {
/* A specific driver was requested for testing */
iMax = 1;
}
for (i = 0; i < iMax; i++) {
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
if (audioDriver == NULL) {
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
#if defined(__linux__)
if (DriverIsProblematic(audioDriver)) {
SDLTest_Log("Audio driver '%s' flagged as problematic: skipping init/quit test (set SDL_AUDIODRIVER=%s to force)", audioDriver, audioDriver);
audioDriver = NULL;
continue;
}
#endif
}
if (hint && SDL_strcmp(audioDriver, hint) != 0) {
continue;
}
/* Call Init */
result = SDL_AudioInit(audioDriver);
@ -106,6 +165,8 @@ int audio_initQuitAudio()
/* Call Quit */
SDL_AudioQuit();
SDLTest_AssertPass("Call to SDL_AudioQuit()");
audioDriver = NULL;
}
/* NULL driver specification */
@ -134,26 +195,49 @@ int audio_initQuitAudio()
* \sa https://wiki.libsdl.org/SDL_CloseAudio
* \sa https://wiki.libsdl.org/SDL_QuitAudio
*/
int audio_initOpenCloseQuitAudio()
int audio_initOpenCloseQuitAudio(void)
{
int result, expectedResult;
int i, iMax, j, k;
const char *audioDriver;
SDL_AudioSpec desired;
const char *hint = SDL_GetHint(SDL_HINT_AUDIODRIVER);
/* Stop SDL audio subsystem */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
/* Loop over all available audio drivers */
iMax = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
/* Was a specific driver requested? */
audioDriver = SDL_GetHint(SDL_HINT_AUDIODRIVER);
if (audioDriver == NULL) {
/* Loop over all available audio drivers */
iMax = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
} else {
/* A specific driver was requested for testing */
iMax = 1;
}
for (i = 0; i < iMax; i++) {
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
if (audioDriver == NULL) {
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
#if defined(__linux__)
if (DriverIsProblematic(audioDriver)) {
SDLTest_Log("Audio driver '%s' flagged as problematic: skipping device open/close test (set SDL_AUDIODRIVER=%s to force)", audioDriver, audioDriver);
audioDriver = NULL;
continue;
}
#endif
}
if (hint && SDL_strcmp(audioDriver, hint) != 0) {
continue;
}
/* Change specs */
for (j = 0; j < 2; j++) {
@ -163,6 +247,17 @@ int audio_initOpenCloseQuitAudio()
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
/* Check for output devices */
result = SDL_GetNumAudioDevices(SDL_FALSE);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(SDL_FALSE)");
SDLTest_AssertCheck(result >= 0, "Validate result value; expected: >=0 got: %d", result);
if (result <= 0) {
SDLTest_Log("No output devices for '%s': skipping device open/close test", audioDriver);
SDL_AudioQuit();
SDLTest_AssertPass("Call to SDL_AudioQuit()");
break;
}
/* Set spec */
SDL_memset(&desired, 0, sizeof(desired));
switch (j) {
@ -207,7 +302,10 @@ int audio_initOpenCloseQuitAudio()
}
} /* spec loop */
} /* driver loop */
audioDriver = NULL;
} /* driver loop */
/* Restart audio again */
_audioSetUp(NULL);
@ -220,7 +318,7 @@ int audio_initOpenCloseQuitAudio()
*
* \sa https://wiki.libsdl.org/SDL_PauseAudio
*/
int audio_pauseUnpauseAudio()
int audio_pauseUnpauseAudio(void)
{
int result;
int i, iMax, j, k, l;
@ -229,20 +327,43 @@ int audio_pauseUnpauseAudio()
int originalCounter;
const char *audioDriver;
SDL_AudioSpec desired;
const char *hint = SDL_GetHint(SDL_HINT_AUDIODRIVER);
/* Stop SDL audio subsystem */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
/* Loop over all available audio drivers */
iMax = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
/* Was a specific driver requested? */
audioDriver = SDL_GetHint(SDL_HINT_AUDIODRIVER);
if (audioDriver == NULL) {
/* Loop over all available audio drivers */
iMax = SDL_GetNumAudioDrivers();
SDLTest_AssertPass("Call to SDL_GetNumAudioDrivers()");
SDLTest_AssertCheck(iMax > 0, "Validate number of audio drivers; expected: >0 got: %d", iMax);
} else {
/* A specific driver was requested for testing */
iMax = 1;
}
for (i = 0; i < iMax; i++) {
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
if (audioDriver == NULL) {
audioDriver = SDL_GetAudioDriver(i);
SDLTest_AssertPass("Call to SDL_GetAudioDriver(%d)", i);
SDLTest_Assert(audioDriver != NULL, "Audio driver name is not NULL");
SDLTest_AssertCheck(audioDriver[0] != '\0', "Audio driver name is not empty; got: %s", audioDriver); /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
#if defined(__linux__)
if (DriverIsProblematic(audioDriver)) {
SDLTest_Log("Audio driver '%s' flagged as problematic: skipping pause/unpause test (set SDL_AUDIODRIVER=%s to force)", audioDriver, audioDriver);
audioDriver = NULL;
continue;
}
#endif
}
if (hint && SDL_strcmp(audioDriver, hint) != 0) {
continue;
}
/* Change specs */
for (j = 0; j < 2; j++) {
@ -252,6 +373,16 @@ int audio_pauseUnpauseAudio()
SDLTest_AssertPass("Call to SDL_AudioInit('%s')", audioDriver);
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result);
result = SDL_GetNumAudioDevices(SDL_FALSE);
SDLTest_AssertPass("Call to SDL_GetNumAudioDevices(SDL_FALSE)");
SDLTest_AssertCheck(result >= 0, "Validate result value; expected: >=0 got: %d", result);
if (result <= 0) {
SDLTest_Log("No output devices for '%s': skipping pause/unpause test", audioDriver);
SDL_AudioQuit();
SDLTest_AssertPass("Call to SDL_AudioQuit()");
break;
}
/* Set spec */
SDL_memset(&desired, 0, sizeof(desired));
switch (j) {
@ -326,7 +457,10 @@ int audio_pauseUnpauseAudio()
SDLTest_AssertPass("Call to SDL_AudioQuit()");
} /* spec loop */
} /* driver loop */
audioDriver = NULL;
} /* driver loop */
/* Restart audio again */
_audioSetUp(NULL);
@ -340,7 +474,7 @@ int audio_pauseUnpauseAudio()
* \sa https://wiki.libsdl.org/SDL_GetNumAudioDevices
* \sa https://wiki.libsdl.org/SDL_GetAudioDeviceName
*/
int audio_enumerateAndNameAudioDevices()
int audio_enumerateAndNameAudioDevices(void)
{
int t, tt;
int i, n, nn;
@ -398,7 +532,7 @@ int audio_enumerateAndNameAudioDevices()
* \sa https://wiki.libsdl.org/SDL_GetNumAudioDevices
* \sa https://wiki.libsdl.org/SDL_GetAudioDeviceName
*/
int audio_enumerateAndNameAudioDevicesNegativeTests()
int audio_enumerateAndNameAudioDevicesNegativeTests(void)
{
int t;
int i, j, no, nc;
@ -444,7 +578,7 @@ int audio_enumerateAndNameAudioDevicesNegativeTests()
* \sa https://wiki.libsdl.org/SDL_GetNumAudioDrivers
* \sa https://wiki.libsdl.org/SDL_GetAudioDriver
*/
int audio_printAudioDrivers()
int audio_printAudioDrivers(void)
{
int i, n;
const char *name;
@ -474,7 +608,7 @@ int audio_printAudioDrivers()
*
* \sa https://wiki.libsdl.org/SDL_GetCurrentAudioDriver
*/
int audio_printCurrentAudioDriver()
int audio_printCurrentAudioDriver(void)
{
/* Check current audio driver */
const char *name = SDL_GetCurrentAudioDriver();
@ -505,7 +639,7 @@ int _audioFrequencies[] = { 11025, 22050, 44100, 48000 };
*
* \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
*/
int audio_buildAudioCVT()
int audio_buildAudioCVT(void)
{
int result;
SDL_AudioCVT cvt;
@ -569,7 +703,7 @@ int audio_buildAudioCVT()
*
* \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
*/
int audio_buildAudioCVTNegative()
int audio_buildAudioCVTNegative(void)
{
const char *expectedError = "Parameter 'cvt' is invalid";
const char *error;
@ -664,7 +798,7 @@ int audio_buildAudioCVTNegative()
*
* \sa https://wiki.libsdl.org/SDL_GetAudioStatus
*/
int audio_getAudioStatus()
int audio_getAudioStatus(void)
{
SDL_AudioStatus result;
@ -683,7 +817,7 @@ int audio_getAudioStatus()
*
* \sa https://wiki.libsdl.org/SDL_GetAudioStatus
*/
int audio_openCloseAndGetAudioStatus()
int audio_openCloseAndGetAudioStatus(void)
{
SDL_AudioStatus result;
int i;
@ -744,7 +878,7 @@ int audio_openCloseAndGetAudioStatus()
* \sa https://wiki.libsdl.org/SDL_LockAudioDevice
* \sa https://wiki.libsdl.org/SDL_UnlockAudioDevice
*/
int audio_lockUnlockOpenAudioDevice()
int audio_lockUnlockOpenAudioDevice(void)
{
int i;
int count;
@ -808,7 +942,7 @@ int audio_lockUnlockOpenAudioDevice()
* \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
* \sa https://wiki.libsdl.org/SDL_ConvertAudio
*/
int audio_convertAudio()
int audio_convertAudio(void)
{
int result;
SDL_AudioCVT cvt;
@ -909,7 +1043,7 @@ int audio_convertAudio()
*
* \sa https://wiki.libsdl.org/SDL_AudioDeviceConnected
*/
int audio_openCloseAudioDeviceConnected()
int audio_openCloseAudioDeviceConnected(void)
{
int result = -1;
int i;
@ -984,7 +1118,7 @@ static double sine_wave_sample(const Sint64 idx, const Sint64 rate, const Sint64
* \sa https://wiki.libsdl.org/SDL_BuildAudioCVT
* \sa https://wiki.libsdl.org/SDL_ConvertAudio
*/
int audio_resampleLoss()
int audio_resampleLoss(void)
{
/* Note: always test long input time (>= 5s from experience) in some test
* cases because an improper implementation may suffer from low resampling
@ -1025,8 +1159,8 @@ int audio_resampleLoss()
SDLTest_AssertPass("Test resampling of %i s %i Hz %f phase sine wave from sampling rate of %i Hz to %i Hz",
spec->time, spec->freq, spec->phase, spec->rate_in, spec->rate_out);
ret = SDL_BuildAudioCVT(&cvt, AUDIO_F32, 1, spec->rate_in, AUDIO_F32, 1, spec->rate_out);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(&cvt, AUDIO_F32, 1, %i, AUDIO_F32, 1, %i)", spec->rate_in, spec->rate_out);
ret = SDL_BuildAudioCVT(&cvt, AUDIO_F32SYS, 1, spec->rate_in, AUDIO_F32SYS, 1, spec->rate_out);
SDLTest_AssertPass("Call to SDL_BuildAudioCVT(&cvt, AUDIO_F32SYS, 1, %i, AUDIO_F32SYS, 1, %i)", spec->rate_in, spec->rate_out);
SDLTest_AssertCheck(ret == 1, "Expected SDL_BuildAudioCVT to succeed and conversion to be needed.");
if (ret != 1) {
return TEST_ABORTED;

View file

@ -84,7 +84,7 @@ int clipboard_testSetClipboardText(void *arg)
char *textRef = SDLTest_RandomAsciiString();
char *text = SDL_strdup(textRef);
int result;
result = SDL_SetClipboardText((const char *)text);
result = SDL_SetClipboardText(text);
SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
SDLTest_AssertCheck(
result == 0,
@ -112,7 +112,7 @@ int clipboard_testSetPrimarySelectionText(void *arg)
char *textRef = SDLTest_RandomAsciiString();
char *text = SDL_strdup(textRef);
int result;
result = SDL_SetPrimarySelectionText((const char *)text);
result = SDL_SetPrimarySelectionText(text);
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText succeeded");
SDLTest_AssertCheck(
result == 0,
@ -149,7 +149,7 @@ int clipboard_testClipboardTextFunctions(void *arg)
boolResult = SDL_HasClipboardText();
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
if (boolResult == SDL_TRUE) {
intResult = SDL_SetClipboardText((const char *)NULL);
intResult = SDL_SetClipboardText(NULL);
SDLTest_AssertPass("Call to SDL_SetClipboardText(NULL) succeeded");
SDLTest_AssertCheck(
intResult == 0,
@ -176,7 +176,7 @@ int clipboard_testClipboardTextFunctions(void *arg)
charResult[0] == '\0', /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
"Verify SDL_GetClipboardText returned string with length 0, got length %i",
(int)SDL_strlen(charResult));
intResult = SDL_SetClipboardText((const char *)text);
intResult = SDL_SetClipboardText(text);
SDLTest_AssertPass("Call to SDL_SetClipboardText succeeded");
SDLTest_AssertCheck(
intResult == 0,
@ -227,7 +227,7 @@ int clipboard_testPrimarySelectionTextFunctions(void *arg)
boolResult = SDL_HasPrimarySelectionText();
SDLTest_AssertPass("Call to SDL_HasPrimarySelectionText succeeded");
if (boolResult == SDL_TRUE) {
intResult = SDL_SetPrimarySelectionText((const char *)NULL);
intResult = SDL_SetPrimarySelectionText(NULL);
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText(NULL) succeeded");
SDLTest_AssertCheck(
intResult == 0,
@ -254,7 +254,7 @@ int clipboard_testPrimarySelectionTextFunctions(void *arg)
charResult[0] == '\0', /* NOLINT(clang-analyzer-core.NullDereference): Checked for NULL above */
"Verify SDL_GetPrimarySelectionText returned string with length 0, got length %i",
(int)SDL_strlen(charResult));
intResult = SDL_SetPrimarySelectionText((const char *)text);
intResult = SDL_SetPrimarySelectionText(text);
SDLTest_AssertPass("Call to SDL_SetPrimarySelectionText succeeded");
SDLTest_AssertCheck(
intResult == 0,

View file

@ -68,6 +68,10 @@ int events_pushPumpAndPollUserevent(void *arg)
SDLTest_AssertPass("Call to SDL_PollEvent()");
SDLTest_AssertCheck(result == 1, "Check result from SDL_PollEvent, expected: 1, got: %d", result);
/* Need to finish getting all events and sentinel, otherwise other tests that rely on event are in bad state */
while (SDL_PollEvent(&event2)) {
}
return TEST_COMPLETED;
}

View file

@ -125,7 +125,7 @@ TestGuidToString(void *arg)
SDL_GUIDToString(guid, guid_str, size);
/* Check bytes before guid_str_buf */
expected_prefix = fill_char | (fill_char << 8) | (fill_char << 16) | (fill_char << 24);
expected_prefix = fill_char | (fill_char << 8) | (fill_char << 16) | (((Uint32)fill_char) << 24);
SDL_memcpy(&actual_prefix, guid_str_buf, 4);
SDLTest_AssertCheck(expected_prefix == actual_prefix, "String buffer memory before output untouched, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32 ", at size=%d", expected_prefix, actual_prefix, size);

View file

@ -102,7 +102,7 @@ int keyboard_getKeyFromName(void *arg)
/*
* Local helper to check for the invalid scancode error message
*/
void _checkInvalidScancodeError()
void _checkInvalidScancodeError(void)
{
const char *expectedError = "Parameter 'scancode' is invalid";
const char *error;
@ -127,9 +127,9 @@ int keyboard_getKeyFromScancode(void *arg)
SDL_Keycode result;
/* Case where input is valid */
result = SDL_GetKeyFromScancode(SDL_SCANCODE_A);
result = SDL_GetKeyFromScancode(SDL_SCANCODE_SPACE);
SDLTest_AssertPass("Call to SDL_GetKeyFromScancode(valid)");
SDLTest_AssertCheck(result == SDLK_a, "Verify result from call, expected: %i, got: %" SDL_PRIs32, SDLK_a, result);
SDLTest_AssertCheck(result == SDLK_SPACE, "Verify result from call, expected: %i, got: %" SDL_PRIs32, SDLK_SPACE, result);
/* Case where input is zero */
result = SDL_GetKeyFromScancode(0);
@ -463,32 +463,34 @@ int keyboard_setTextInputRect(void *arg)
*/
int keyboard_setTextInputRectNegative(void *arg)
{
int platform_sets_error_message = SDL_strcmp(SDL_GetCurrentVideoDriver(), "windows") == 0 ||
SDL_strcmp(SDL_GetCurrentVideoDriver(), "android") == 0 ||
SDL_strcmp(SDL_GetCurrentVideoDriver(), "cococa") == 0;
/* Some platforms set also an error message; prepare for checking it */
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA
const char *expectedError = "Parameter 'rect' is invalid";
const char *error;
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
#endif
/* NULL refRect */
SDL_SetTextInputRect(NULL);
SDLTest_AssertPass("Call to SDL_SetTextInputRect(NULL)");
/* Some platforms set also an error message; so check it */
#if SDL_VIDEO_DRIVER_WINDOWS || SDL_VIDEO_DRIVER_ANDROID || SDL_VIDEO_DRIVER_COCOA
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
if (platform_sets_error_message) {
error = SDL_GetError();
SDLTest_AssertPass("Call to SDL_GetError()");
SDLTest_AssertCheck(error != NULL, "Validate that error message was not NULL");
if (error != NULL) {
SDLTest_AssertCheck(SDL_strcmp(error, expectedError) == 0,
"Validate error message, expected: '%s', got: '%s'", expectedError, error);
}
}
SDL_ClearError();
SDLTest_AssertPass("Call to SDL_ClearError()");
#endif
return TEST_COMPLETED;
}
@ -572,7 +574,7 @@ int keyboard_getScancodeFromName(void *arg)
/*
* Local helper to check for the invalid scancode error message
*/
void _checkInvalidNameError()
void _checkInvalidNameError(void)
{
const char *expectedError = "Parameter 'name' is invalid";
const char *error;

View file

@ -0,0 +1,209 @@
/**
* Log test suite
*/
#include "SDL.h"
#include "SDL_test.h"
static SDL_LogOutputFunction original_function;
static void *original_userdata;
static void SDLCALL TestLogOutput(void *userdata, int category, SDL_LogPriority priority, const char *message)
{
int *message_count = (int *)userdata;
++(*message_count);
}
static void EnableTestLog(int *message_count)
{
*message_count = 0;
SDL_LogGetOutputFunction(&original_function, &original_userdata);
SDL_LogSetOutputFunction(TestLogOutput, message_count);
}
static void DisableTestLog(void)
{
SDL_LogSetOutputFunction(original_function, original_userdata);
}
/* Fixture */
/* Test case functions */
/**
* Check SDL_HINT_LOGGING functionality
*/
static int log_testHint(void *arg)
{
int count;
SDL_SetHint(SDL_HINT_LOGGING, NULL);
SDLTest_AssertPass("SDL_SetHint(SDL_HINT_LOGGING, NULL)");
{
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, \"test\")");
SDLTest_AssertCheck(count == 1, "Check result value, expected: 1, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, \"test\")");
SDLTest_AssertCheck(count == 0, "Check result value, expected: 0, got: %d", count);
}
SDL_SetHint(SDL_HINT_LOGGING, "debug");
SDLTest_AssertPass("SDL_SetHint(SDL_HINT_LOGGING, \"debug\")");
{
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, \"test\")");
SDLTest_AssertCheck(count == 1, "Check result value, expected: 1, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_VERBOSE, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_VERBOSE, \"test\")");
SDLTest_AssertCheck(count == 0, "Check result value, expected: 0, got: %d", count);
}
SDL_SetHint(SDL_HINT_LOGGING, "system=debug");
SDLTest_AssertPass("SDL_SetHint(SDL_HINT_LOGGING, \"system=debug\")");
{
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, \"test\")");
SDLTest_AssertCheck(count == 0, "Check result value, expected: 0, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_DEBUG, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_DEBUG, \"test\")");
SDLTest_AssertCheck(count == 1, "Check result value, expected: 1, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_VERBOSE, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_VERBOSE, \"test\")");
SDLTest_AssertCheck(count == 0, "Check result value, expected: 0, got: %d", count);
}
SDL_SetHint(SDL_HINT_LOGGING, "app=warn,system=debug,assert=quiet,*=info");
SDLTest_AssertPass("SDL_SetHint(SDL_HINT_LOGGING, \"app=warn,system=debug,assert=quiet,*=info\")");
{
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, \"test\")");
SDLTest_AssertCheck(count == 1, "Check result value, expected: 1, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, \"test\")");
SDLTest_AssertCheck(count == 0, "Check result value, expected: 0, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_DEBUG, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_DEBUG, \"test\")");
SDLTest_AssertCheck(count == 1, "Check result value, expected: 1, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_VERBOSE, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_VERBOSE, \"test\")");
SDLTest_AssertCheck(count == 0, "Check result value, expected: 0, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_ASSERT, SDL_LOG_PRIORITY_CRITICAL, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_ASSERT, SDL_LOG_PRIORITY_CRITICAL, \"test\")");
SDLTest_AssertCheck(count == 0, "Check result value, expected: 0, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_CUSTOM, SDL_LOG_PRIORITY_INFO, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_CUSTOM, SDL_LOG_PRIORITY_INFO, \"test\")");
SDLTest_AssertCheck(count == 1, "Check result value, expected: 1, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_CUSTOM, SDL_LOG_PRIORITY_DEBUG, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_CUSTOM, SDL_LOG_PRIORITY_DEBUG, \"test\")");
SDLTest_AssertCheck(count == 0, "Check result value, expected: 0, got: %d", count);
}
SDL_SetHint(SDL_HINT_LOGGING, "0=4,3=2,2=0,*=3");
SDLTest_AssertPass("SDL_SetHint(SDL_HINT_LOGGING, \"0=4,3=2,2=0,*=3\")");
{
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, \"test\")");
SDLTest_AssertCheck(count == 1, "Check result value, expected: 1, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, \"test\")");
SDLTest_AssertCheck(count == 0, "Check result value, expected: 0, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_DEBUG, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_DEBUG, \"test\")");
SDLTest_AssertCheck(count == 1, "Check result value, expected: 1, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_VERBOSE, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_VERBOSE, \"test\")");
SDLTest_AssertCheck(count == 0, "Check result value, expected: 0, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_ASSERT, SDL_LOG_PRIORITY_CRITICAL, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_ASSERT, SDL_LOG_PRIORITY_CRITICAL, \"test\")");
SDLTest_AssertCheck(count == 0, "Check result value, expected: 0, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_CUSTOM, SDL_LOG_PRIORITY_INFO, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_CUSTOM, SDL_LOG_PRIORITY_INFO, \"test\")");
SDLTest_AssertCheck(count == 1, "Check result value, expected: 1, got: %d", count);
EnableTestLog(&count);
SDL_LogMessage(SDL_LOG_CATEGORY_CUSTOM, SDL_LOG_PRIORITY_DEBUG, "test");
DisableTestLog();
SDLTest_AssertPass("SDL_LogMessage(SDL_LOG_CATEGORY_CUSTOM, SDL_LOG_PRIORITY_DEBUG, \"test\")");
SDLTest_AssertCheck(count == 0, "Check result value, expected: 0, got: %d", count);
}
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Log test cases */
static const SDLTest_TestCaseReference logTestHint = {
(SDLTest_TestCaseFp)log_testHint, "log_testHint", "Check SDL_HINT_LOGGING functionality", TEST_ENABLED
};
/* Sequence of Log test cases */
static const SDLTest_TestCaseReference *logTests[] = {
&logTestHint, NULL
};
/* Timer test suite (global) */
SDLTest_TestSuiteReference logTestSuite = {
"Log",
NULL,
logTests,
NULL
};

View file

@ -9,34 +9,6 @@
#include "SDL.h"
#include "SDL_test.h"
/* !
* \brief Tests SDL_Init() and SDL_Quit() of Joystick and Haptic subsystems
* \sa
* http://wiki.libsdl.org/SDL_Init
* http://wiki.libsdl.org/SDL_Quit
*/
static int main_testInitQuitJoystickHaptic(void *arg)
{
#if defined SDL_JOYSTICK_DISABLED || defined SDL_HAPTIC_DISABLED
return TEST_SKIPPED;
#else
int enabled_subsystems;
int initialized_subsystems = SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC;
SDLTest_AssertCheck(SDL_Init(initialized_subsystems) == 0, "SDL_Init multiple systems.");
enabled_subsystems = SDL_WasInit(initialized_subsystems);
SDLTest_AssertCheck(enabled_subsystems == initialized_subsystems, "SDL_WasInit(SDL_INIT_EVERYTHING) contains all systems (%i)", enabled_subsystems);
SDL_Quit();
enabled_subsystems = SDL_WasInit(initialized_subsystems);
SDLTest_AssertCheck(enabled_subsystems == 0, "SDL_Quit should shut down everything (%i)", enabled_subsystems);
return TEST_COMPLETED;
#endif
}
/* !
* \brief Tests SDL_InitSubSystem() and SDL_QuitSubSystem()
* \sa
@ -154,22 +126,18 @@ main_testSetError(void *arg)
#endif
static const SDLTest_TestCaseReference mainTest1 = {
(SDLTest_TestCaseFp)main_testInitQuitJoystickHaptic, "main_testInitQuitJoystickHaptic", "Tests SDL_Init/Quit of Joystick and Haptic subsystem", TEST_ENABLED
};
static const SDLTest_TestCaseReference mainTest2 = {
(SDLTest_TestCaseFp)main_testInitQuitSubSystem, "main_testInitQuitSubSystem", "Tests SDL_InitSubSystem/QuitSubSystem", TEST_ENABLED
};
static const SDLTest_TestCaseReference mainTest3 = {
static const SDLTest_TestCaseReference mainTest2 = {
(SDLTest_TestCaseFp)main_testImpliedJoystickInit, "main_testImpliedJoystickInit", "Tests that init for gamecontroller properly implies joystick", TEST_ENABLED
};
static const SDLTest_TestCaseReference mainTest4 = {
static const SDLTest_TestCaseReference mainTest3 = {
(SDLTest_TestCaseFp)main_testImpliedJoystickQuit, "main_testImpliedJoystickQuit", "Tests that quit for gamecontroller doesn't quit joystick if you inited it explicitly", TEST_ENABLED
};
static const SDLTest_TestCaseReference mainTest5 = {
static const SDLTest_TestCaseReference mainTest4 = {
(SDLTest_TestCaseFp)main_testSetError, "main_testSetError", "Tests that SDL_SetError() handles arbitrarily large strings", TEST_ENABLED
};
@ -179,7 +147,6 @@ static const SDLTest_TestCaseReference *mainTests[] = {
&mainTest2,
&mainTest3,
&mainTest4,
&mainTest5,
NULL
};
@ -190,5 +157,3 @@ SDLTest_TestSuiteReference mainTestSuite = {
mainTests,
NULL
};
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -49,6 +49,12 @@ typedef struct
double expected;
} dd_to_d;
#define DD_TO_D_CASE(IDX, X, Y, E) do { \
cases[IDX].x_input = (X); \
cases[IDX].y_input = (Y); \
cases[IDX].expected = (E); \
} while (0)
/*
NB: You cannot create an array of these structures containing INFINITY or NAN.
On platforms such as OS/2, they are defined as 'extern const double' making them
@ -64,10 +70,10 @@ typedef double(SDLCALL *dd_to_d_func)(double, double);
* \brief Runs all the cases on a given function with a signature double -> double.
* The result is expected to be exact.
*
* \param func_name, a printable name for the tested function.
* \param func, the function to call.
* \param cases, an array of all the cases.
* \param cases_size, the size of the cases array.
* \param func_name a printable name for the tested function.
* \param func the function to call.
* \param cases an array of all the cases.
* \param cases_size the size of the cases array.
*/
static int
helper_dtod(const char *func_name, d_to_d_func func,
@ -76,7 +82,7 @@ helper_dtod(const char *func_name, d_to_d_func func,
Uint32 i;
for (i = 0; i < cases_size; i++) {
const double result = func(cases[i].input);
SDLTest_AssertCheck(result == cases[i].expected,
SDLTest_AssertCheck(SDL_fabs(result - cases[i].expected) < FLT_EPSILON,
"%s(%f), expected %f, got %f",
func_name,
cases[i].input,
@ -90,10 +96,10 @@ helper_dtod(const char *func_name, d_to_d_func func,
* \brief Runs all the cases on a given function with a signature double -> double.
* Checks if the result between expected +/- EPSILON.
*
* \param func_name, a printable name for the tested function.
* \param func, the function to call.
* \param cases, an array of all the cases.
* \param cases_size, the size of the cases array.
* \param func_name a printable name for the tested function.
* \param func the function to call.
* \param cases an array of all the cases.
* \param cases_size the size of the cases array.
*/
static int
helper_dtod_inexact(const char *func_name, d_to_d_func func,
@ -102,13 +108,19 @@ helper_dtod_inexact(const char *func_name, d_to_d_func func,
Uint32 i;
for (i = 0; i < cases_size; i++) {
const double result = func(cases[i].input);
SDLTest_AssertCheck(result >= cases[i].expected - EPSILON &&
result <= cases[i].expected + EPSILON,
"%s(%f), expected [%f,%f], got %f",
double diff = result - cases[i].expected;
double max_err = (cases[i].expected + 1.) * EPSILON;
if (diff < 0) {
diff = -diff;
}
if (max_err < 0) {
max_err = -max_err;
}
SDLTest_AssertCheck(diff <= max_err,
"%s(%f), expected %f +/- %g, got %f",
func_name,
cases[i].input,
cases[i].expected - EPSILON,
cases[i].expected + EPSILON,
cases[i].expected, max_err,
result);
}
@ -119,10 +131,10 @@ helper_dtod_inexact(const char *func_name, d_to_d_func func,
* \brief Runs all the cases on a given function with a signature
* (double, double) -> double. The result is expected to be exact.
*
* \param func_name, a printable name for the tested function.
* \param func, the function to call.
* \param cases, an array of all the cases.
* \param cases_size, the size of the cases array.
* \param func_name a printable name for the tested function.
* \param func the function to call.
* \param cases an array of all the cases.
* \param cases_size the size of the cases array.
*/
static int
helper_ddtod(const char *func_name, dd_to_d_func func,
@ -131,6 +143,8 @@ helper_ddtod(const char *func_name, dd_to_d_func func,
Uint32 i;
for (i = 0; i < cases_size; i++) {
const double result = func(cases[i].x_input, cases[i].y_input);
/* By using the result as input, the compiler is less likely to use higher precision floating point number */
(void)SDL_sin(result);
SDLTest_AssertCheck(result == cases[i].expected,
"%s(%f,%f), expected %f, got %f",
func_name,
@ -145,10 +159,10 @@ helper_ddtod(const char *func_name, dd_to_d_func func,
* \brief Runs all the cases on a given function with a signature
* (double, double) -> double. Checks if the result between expected +/- EPSILON.
*
* \param func_name, a printable name for the tested function.
* \param func, the function to call.
* \param cases, an array of all the cases.
* \param cases_size, the size of the cases array.
* \param func_name a printable name for the tested function.
* \param func the function to call.
* \param cases an array of all the cases.
* \param cases_size the size of the cases array.
*/
static int
helper_ddtod_inexact(const char *func_name, dd_to_d_func func,
@ -157,13 +171,20 @@ helper_ddtod_inexact(const char *func_name, dd_to_d_func func,
Uint32 i;
for (i = 0; i < cases_size; i++) {
const double result = func(cases[i].x_input, cases[i].y_input);
SDLTest_AssertCheck(result >= cases[i].expected - EPSILON &&
result <= cases[i].expected + EPSILON,
"%s(%f,%f), expected [%f,%f], got %f",
double diff = result - cases[i].expected;
double max_err = (cases[i].expected + 1.) * EPSILON;
if (diff < 0) {
diff = -diff;
}
if (max_err < 0) {
max_err = -max_err;
}
SDLTest_AssertCheck(diff <= max_err,
"%s(%f,%f), expected %f +/- %g, got %f",
func_name,
cases[i].x_input, cases[i].y_input,
cases[i].expected - EPSILON,
cases[i].expected + EPSILON,
cases[i].expected, max_err,
result);
}
@ -176,8 +197,8 @@ helper_ddtod_inexact(const char *func_name, dd_to_d_func func,
* This function is only meant to test functions that returns the input value if it is
* integral: f(x) -> x for x in N.
*
* \param func_name, a printable name for the tested function.
* \param func, the function to call.
* \param func_name a printable name for the tested function.
* \param func the function to call.
*/
static int
helper_range(const char *func_name, d_to_d_func func)
@ -1091,7 +1112,7 @@ exp_regularCases(void *args)
{ 112.89, 10653788283588960962604279261058893737879589093376.0 },
{ 539.483, 1970107755334319939701129934673541628417235942656909222826926175622435588279443011110464355295725187195188154768877850257012251677751742837992843520967922303961718983154427294786640886286983037548604937796221048661733679844353544028160.0 },
};
return helper_dtod("Exp", SDL_exp, regular_cases, SDL_arraysize(regular_cases));
return helper_dtod_inexact("Exp", SDL_exp, regular_cases, SDL_arraysize(regular_cases));
}
/* SDL_log tests functions */
@ -1138,7 +1159,7 @@ log_baseCases(void *args)
1.0, 0.0, result);
result = SDL_log(EULER);
SDLTest_AssertCheck(1.0 == result,
SDLTest_AssertCheck(SDL_fabs(result - 1.) < FLT_EPSILON,
"Log(%f), expected %f, got %f",
EULER, 1.0, result);
@ -1646,14 +1667,16 @@ static int
pow_regularCases(void *args)
{
const dd_to_d regular_cases[] = {
#if 0 /* These tests fail when using the Mingw C runtime, we'll disable them for now */
{ -391.25, -2.0, 0.00000653267870448815438463212659780943170062528224661946296691894531250 },
{ -72.3, 12.0, 20401381050275984310272.0 },
#endif
{ -5.0, 3.0, -125.0 },
{ 3.0, 2.5, 15.58845726811989607085706666111946105957031250 },
{ 39.23, -1.5, 0.0040697950366865498147972424192175822099670767784118652343750 },
{ 478.972, 12.125, 315326359630449587856007411793920.0 }
};
return helper_ddtod("Pow", SDL_pow, regular_cases, SDL_arraysize(regular_cases));
return helper_ddtod_inexact("Pow", SDL_pow, regular_cases, SDL_arraysize(regular_cases));
}
/**
@ -1981,24 +2004,24 @@ static int
cos_precisionTest(void *args)
{
const d_to_d precision_cases[] = {
{ M_PI * 1.0 / 10.0, 0.9510565162 },
{ M_PI * 2.0 / 10.0, 0.8090169943 },
{ M_PI * 3.0 / 10.0, 0.5877852522 },
{ M_PI * 4.0 / 10.0, 0.3090169943 },
{ M_PI * 1.0 / 10.0, 0.9510565162951535 },
{ M_PI * 2.0 / 10.0, 0.8090169943749475 },
{ M_PI * 3.0 / 10.0, 0.5877852522924731 },
{ M_PI * 4.0 / 10.0, 0.30901699437494745 },
{ M_PI * 5.0 / 10.0, 0.0 },
{ M_PI * 6.0 / 10.0, -0.3090169943 },
{ M_PI * 7.0 / 10.0, -0.5877852522 },
{ M_PI * 8.0 / 10.0, -0.8090169943 },
{ M_PI * 9.0 / 10.0, -0.9510565162 },
{ M_PI * -1.0 / 10.0, 0.9510565162 },
{ M_PI * -2.0 / 10.0, 0.8090169943 },
{ M_PI * -3.0 / 10.0, 0.5877852522 },
{ M_PI * -4.0 / 10.0, 0.3090169943 },
{ M_PI * 6.0 / 10.0, -0.30901699437494734 },
{ M_PI * 7.0 / 10.0, -0.587785252292473 },
{ M_PI * 8.0 / 10.0, -0.8090169943749473 },
{ M_PI * 9.0 / 10.0, -0.9510565162951535 },
{ M_PI * -1.0 / 10.0, 0.9510565162951535 },
{ M_PI * -2.0 / 10.0, 0.8090169943749475 },
{ M_PI * -3.0 / 10.0, 0.5877852522924731 },
{ M_PI * -4.0 / 10.0, 0.30901699437494745 },
{ M_PI * -5.0 / 10.0, 0.0 },
{ M_PI * -6.0 / 10.0, -0.3090169943 },
{ M_PI * -7.0 / 10.0, -0.5877852522 },
{ M_PI * -8.0 / 10.0, -0.8090169943 },
{ M_PI * -9.0 / 10.0, -0.9510565162 }
{ M_PI * -6.0 / 10.0, -0.30901699437494734 },
{ M_PI * -7.0 / 10.0, -0.587785252292473 },
{ M_PI * -8.0 / 10.0, -0.8090169943749473 },
{ M_PI * -9.0 / 10.0, -0.9510565162951535 }
};
return helper_dtod_inexact("Cos", SDL_cos, precision_cases, SDL_arraysize(precision_cases));
}
@ -2099,23 +2122,23 @@ static int
sin_precisionTest(void *args)
{
const d_to_d precision_cases[] = {
{ M_PI * 1.0 / 10.0, 0.3090169943 },
{ M_PI * 2.0 / 10.0, 0.5877852522 },
{ M_PI * 3.0 / 10.0, 0.8090169943 },
{ M_PI * 4.0 / 10.0, 0.9510565162 },
{ M_PI * 6.0 / 10.0, 0.9510565162 },
{ M_PI * 7.0 / 10.0, 0.8090169943 },
{ M_PI * 8.0 / 10.0, 0.5877852522 },
{ M_PI * 9.0 / 10.0, 0.3090169943 },
{ M_PI * 1.0 / 10.0, 0.3090169943749474 },
{ M_PI * 2.0 / 10.0, 0.5877852522924731 },
{ M_PI * 3.0 / 10.0, 0.8090169943749475 },
{ M_PI * 4.0 / 10.0, 0.9510565162951535 },
{ M_PI * 6.0 / 10.0, 0.9510565162951536 },
{ M_PI * 7.0 / 10.0, 0.8090169943749475 },
{ M_PI * 8.0 / 10.0, 0.5877852522924732 },
{ M_PI * 9.0 / 10.0, 0.3090169943749475 },
{ M_PI, 0.0 },
{ M_PI * -1.0 / 10.0, -0.3090169943 },
{ M_PI * -2.0 / 10.0, -0.5877852522 },
{ M_PI * -3.0 / 10.0, -0.8090169943 },
{ M_PI * -4.0 / 10.0, -0.9510565162 },
{ M_PI * -6.0 / 10.0, -0.9510565162 },
{ M_PI * -7.0 / 10.0, -0.8090169943 },
{ M_PI * -8.0 / 10.0, -0.5877852522 },
{ M_PI * -9.0 / 10.0, -0.3090169943 },
{ M_PI * -1.0 / 10.0, -0.3090169943749474 },
{ M_PI * -2.0 / 10.0, -0.5877852522924731 },
{ M_PI * -3.0 / 10.0, -0.8090169943749475 },
{ M_PI * -4.0 / 10.0, -0.9510565162951535 },
{ M_PI * -6.0 / 10.0, -0.9510565162951536 },
{ M_PI * -7.0 / 10.0, -0.8090169943749475 },
{ M_PI * -8.0 / 10.0, -0.5877852522924732 },
{ M_PI * -9.0 / 10.0, -0.3090169943749475 },
{ -M_PI, 0.0 },
};
return helper_dtod_inexact("Sin", SDL_sin, precision_cases, SDL_arraysize(precision_cases));
@ -2215,26 +2238,26 @@ static int
tan_precisionTest(void *args)
{
const d_to_d precision_cases[] = {
{ M_PI * 1.0 / 11.0, 0.2936264929 },
{ M_PI * 2.0 / 11.0, 0.6426609771 },
{ M_PI * 3.0 / 11.0, 1.1540615205 },
{ M_PI * 4.0 / 11.0, 2.1896945629 },
{ M_PI * 5.0 / 11.0, 6.9551527717 },
{ M_PI * 6.0 / 11.0, -6.9551527717 },
{ M_PI * 7.0 / 11.0, -2.1896945629 },
{ M_PI * 8.0 / 11.0, -1.1540615205 },
{ M_PI * 9.0 / 11.0, -0.6426609771 },
{ M_PI * 10.0 / 11.0, -0.2936264929 },
{ M_PI * -1.0 / 11.0, -0.2936264929 },
{ M_PI * -2.0 / 11.0, -0.6426609771 },
{ M_PI * -3.0 / 11.0, -1.1540615205 },
{ M_PI * -4.0 / 11.0, -2.1896945629 },
{ M_PI * -5.0 / 11.0, -6.9551527717 },
{ M_PI * -6.0 / 11.0, 6.9551527717 },
{ M_PI * -7.0 / 11.0, 2.1896945629 },
{ M_PI * -8.0 / 11.0, 1.1540615205 },
{ M_PI * -9.0 / 11.0, 0.6426609771 },
{ M_PI * -10.0 / 11.0, 0.2936264929 }
{ M_PI * 1.0 / 11.0, 0.29362649293836673 },
{ M_PI * 2.0 / 11.0, 0.642660977168331 },
{ M_PI * 3.0 / 11.0, 1.1540615205330094 },
{ M_PI * 4.0 / 11.0, 2.189694562989681 },
{ M_PI * 5.0 / 11.0, 6.9551527717734745 },
{ M_PI * 6.0 / 11.0, -6.955152771773481 },
{ M_PI * 7.0 / 11.0, -2.189694562989682 },
{ M_PI * 8.0 / 11.0, -1.1540615205330096 },
{ M_PI * 9.0 / 11.0, -0.6426609771683314 },
{ M_PI * 10.0 / 11.0, -0.2936264929383667 },
{ M_PI * -1.0 / 11.0, -0.29362649293836673 },
{ M_PI * -2.0 / 11.0, -0.642660977168331 },
{ M_PI * -3.0 / 11.0, -1.1540615205330094 },
{ M_PI * -4.0 / 11.0, -2.189694562989681 },
{ M_PI * -5.0 / 11.0, -6.9551527717734745 },
{ M_PI * -6.0 / 11.0, 6.955152771773481 },
{ M_PI * -7.0 / 11.0, 2.189694562989682 },
{ M_PI * -8.0 / 11.0, 1.1540615205330096 },
{ M_PI * -9.0 / 11.0, 0.6426609771683314 },
{ M_PI * -10.0 / 11.0, 0.2936264929383667 }
};
return helper_dtod_inexact("Tan", SDL_tan, precision_cases, SDL_arraysize(precision_cases));
}
@ -2256,7 +2279,7 @@ acos_limitCases(void *args)
1.0, 0.0, result);
result = SDL_acos(-1.0);
SDLTest_AssertCheck(M_PI == result,
SDLTest_AssertCheck(SDL_fabs(M_PI - result) <= EPSILON,
"Acos(%f), expected %f, got %f",
-1.0, M_PI, result);
@ -2343,12 +2366,12 @@ asin_limitCases(void *args)
double result;
result = SDL_asin(1.0);
SDLTest_AssertCheck(M_PI / 2.0 == result,
SDLTest_AssertCheck(SDL_fabs(M_PI / 2.0 - result) <= EPSILON,
"Asin(%f), expected %f, got %f",
1.0, M_PI / 2.0, result);
result = SDL_asin(-1.0);
SDLTest_AssertCheck(-M_PI / 2.0 == result,
SDLTest_AssertCheck(SDL_fabs(-M_PI / 2.0 - result) <= EPSILON,
"Asin(%f), expected %f, got %f",
-1.0, -M_PI / 2.0, result);
@ -2399,26 +2422,26 @@ static int
asin_precisionTest(void *args)
{
const d_to_d precision_cases[] = {
{ 0.9, 1.1197695149 },
{ 0.8, 0.9272952180 },
{ 0.7, 0.7753974966 },
{ 0.6, 0.6435011087 },
{ 0.5, 0.5235987755 },
{ 0.4, 0.4115168460 },
{ 0.3, 0.3046926540 },
{ 0.2, 0.2013579207 },
{ 0.1, 0.1001674211 },
{ 0.9, 1.1197695149986342 },
{ 0.8, 0.9272952180016123 },
{ 0.7, 0.775397496610753 },
{ 0.6, 0.6435011087932844 },
{ 0.5, 0.5235987755982989 },
{ 0.4, 0.41151684606748806 },
{ 0.3, 0.3046926540153976 },
{ 0.2, 0.20135792079033074 },
{ 0.1, 0.10016742116155977 },
{ 0.0, 0.0 },
{ -0.0, -0.0 },
{ -0.1, -0.1001674211 },
{ -0.2, -0.2013579207 },
{ -0.3, -0.3046926540 },
{ -0.4, -0.4115168460 },
{ -0.5, -0.5235987755 },
{ -0.6, -0.6435011087 },
{ -0.7, -0.7753974966 },
{ -0.8, -0.9272952180 },
{ -0.9, -1.1197695149 }
{ -0.1, -0.10016742116155977 },
{ -0.2, -0.20135792079033074 },
{ -0.3, -0.3046926540153976 },
{ -0.4, -0.41151684606748806 },
{ -0.5, -0.5235987755982989 },
{ -0.6, -0.6435011087932844 },
{ -0.7, -0.775397496610753 },
{ -0.8, -0.9272952180016123 },
{ -0.9, -1.1197695149986342 }
};
return helper_dtod_inexact("Asin", SDL_asin, precision_cases, SDL_arraysize(precision_cases));
}
@ -2493,24 +2516,24 @@ static int
atan_precisionTest(void *args)
{
const d_to_d precision_cases[] = {
{ 6.313751514675041, 1.4137166941 },
{ 3.0776835371752527, 1.2566370614 },
{ 1.9626105055051504, 1.0995574287 },
{ 1.3763819204711734, 0.9424777960 },
{ 1.0, 0.7853981633 },
{ 0.7265425280053609, 0.6283185307 },
{ 0.5095254494944288, 0.4712388980 },
{ 0.3249196962329063, 0.3141592653 },
{ 0.15838444032453627, 0.1570796326 },
{ -0.15838444032453627, -0.1570796326 },
{ -0.3249196962329063, -0.3141592653 },
{ -0.5095254494944288, -0.4712388980 },
{ -0.7265425280053609, -0.6283185307 },
{ -1.0, -0.7853981633 },
{ -1.3763819204711734, -0.9424777960 },
{ -1.9626105055051504, -1.0995574287 },
{ -3.0776835371752527, -1.2566370614 },
{ -6.313751514675041, -1.4137166941 },
{ 6.313751514675041, 1.413716694115407 },
{ 3.0776835371752527, 1.2566370614359172 },
{ 1.9626105055051504, 1.0995574287564276 },
{ 1.3763819204711734, 0.9424777960769379 },
{ 1.0, 0.7853981633974483 },
{ 0.7265425280053609, 0.6283185307179586 },
{ 0.5095254494944288, 0.47123889803846897 },
{ 0.3249196962329063, 0.3141592653589793 },
{ 0.15838444032453627, 0.15707963267948966 },
{ -0.15838444032453627, -0.15707963267948966 },
{ -0.3249196962329063, -0.3141592653589793 },
{ -0.5095254494944288, -0.47123889803846897 },
{ -0.7265425280053609, -0.6283185307179586 },
{ -1.0, -0.7853981633974483 },
{ -1.3763819204711734, -0.9424777960769379 },
{ -1.9626105055051504, -1.0995574287564276 },
{ -3.0776835371752527, -1.2566370614359172 },
{ -6.313751514675041, -1.413716694115407 },
};
return helper_dtod_inexact("Atan", SDL_atan, precision_cases, SDL_arraysize(precision_cases));
}
@ -2535,7 +2558,7 @@ atan2_bothZeroCases(void *args)
{ 0.0, -0.0, M_PI },
{ -0.0, -0.0, -M_PI },
};
return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
}
/**
@ -2554,7 +2577,7 @@ atan2_yZeroCases(void *args)
{ -0.0, 1.0, -0.0 },
{ -0.0, -1.0, -M_PI }
};
return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
}
/**
@ -2570,7 +2593,7 @@ atan2_xZeroCases(void *args)
{ 1.0, -0.0, M_PI / 2.0 },
{ -1.0, -0.0, -M_PI / 2.0 }
};
return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
}
/* Infinity cases */
@ -2586,29 +2609,12 @@ atan2_xZeroCases(void *args)
static int
atan2_bothInfCases(void *args)
{
double result;
result = SDL_atan2(INFINITY, INFINITY);
SDLTest_AssertCheck(M_PI / 4.0 == result,
"Atan2(%f,%f), expected %f, got %f",
INFINITY, INFINITY, M_PI / 4.0, result);
result = SDL_atan2(INFINITY, -INFINITY);
SDLTest_AssertCheck(3.0 * M_PI / 4.0 == result,
"Atan2(%f,%f), expected %f, got %f",
INFINITY, -INFINITY, 3.0 * M_PI / 4.0, result);
result = SDL_atan2(-INFINITY, INFINITY);
SDLTest_AssertCheck(-M_PI / 4.0 == result,
"Atan2(%f,%f), expected %f, got %f",
-INFINITY, INFINITY, -M_PI / 4.0, result);
result = SDL_atan2(-INFINITY, -INFINITY);
SDLTest_AssertCheck(-3.0 * M_PI / 4.0 == result,
"Atan2(%f,%f), expected %f, got %f",
-INFINITY, -INFINITY, -3.0 * M_PI / 4.0, result);
return TEST_COMPLETED;
dd_to_d cases[4];
DD_TO_D_CASE(0, INFINITY, INFINITY, 1.0 * M_PI / 4.0);
DD_TO_D_CASE(1, INFINITY, -INFINITY, 3.0 * M_PI / 4.0);
DD_TO_D_CASE(2, -INFINITY, INFINITY, -1.0 * M_PI / 4.0);
DD_TO_D_CASE(3, -INFINITY, -INFINITY, -3.0 * M_PI / 4.0);
return helper_ddtod("SDL_atan2(bothInfCases)", SDL_atan2, cases, SDL_arraysize(cases));
}
/**
@ -2618,29 +2624,12 @@ atan2_bothInfCases(void *args)
static int
atan2_yInfCases(void *args)
{
double result;
result = SDL_atan2(INFINITY, 1.0);
SDLTest_AssertCheck(M_PI / 2.0 == result,
"Atan2(%f,%f), expected %f, got %f",
INFINITY, 1.0, M_PI / 2.0, result);
result = SDL_atan2(INFINITY, -1.0);
SDLTest_AssertCheck(M_PI / 2.0 == result,
"Atan2(%f,%f), expected %f, got %f",
INFINITY, -1.0, M_PI / 2.0, result);
result = SDL_atan2(-INFINITY, 1.0);
SDLTest_AssertCheck(-M_PI / 2.0 == result,
"Atan2(%f,%f), expected %f, got %f",
-INFINITY, 1.0, -M_PI / 2.0, result);
result = SDL_atan2(-INFINITY, -1.0);
SDLTest_AssertCheck(-M_PI / 2.0 == result,
"Atan2(%f,%f), expected %f, got %f",
-INFINITY, -1.0, -M_PI / 2.0, result);
return TEST_COMPLETED;
dd_to_d cases[4];
DD_TO_D_CASE(0, INFINITY, 1.0, 1.0 * M_PI / 2.0);
DD_TO_D_CASE(1, INFINITY, -1.0, 1.0 * M_PI / 2.0);
DD_TO_D_CASE(2, -INFINITY, 1.0, -1.0 * M_PI / 2.0);
DD_TO_D_CASE(3, -INFINITY, -1.0, -1.0 * M_PI / 2.0);
return helper_ddtod("SDL_atan2(atan2_yInfCases)", SDL_atan2, cases, SDL_arraysize(cases));
}
/**
@ -2652,29 +2641,12 @@ atan2_yInfCases(void *args)
static int
atan2_xInfCases(void *args)
{
double result;
result = SDL_atan2(1.0, INFINITY);
SDLTest_AssertCheck(0.0 == result,
"Atan2(%f,%f), expected %f, got %f",
1.0, INFINITY, 0.0, result);
result = SDL_atan2(-1.0, INFINITY);
SDLTest_AssertCheck(-0.0 == result,
"Atan2(%f,%f), expected %f, got %f",
-1.0, INFINITY, -0.0, result);
result = SDL_atan2(1.0, -INFINITY);
SDLTest_AssertCheck(M_PI == result,
"Atan2(%f,%f), expected %f, got %f",
1.0, -INFINITY, M_PI, result);
result = SDL_atan2(-1.0, -INFINITY);
SDLTest_AssertCheck(-M_PI == result,
"Atan2(%f,%f), expected %f, got %f",
-1.0, -INFINITY, -M_PI, result);
return TEST_COMPLETED;
dd_to_d cases[4];
DD_TO_D_CASE(0, 1.0, INFINITY, 0.0);
DD_TO_D_CASE(1, -1.0, INFINITY, -0.0);
DD_TO_D_CASE(2, 1.0, -INFINITY, M_PI);
DD_TO_D_CASE(3, -1.0, -INFINITY, -M_PI);
return helper_ddtod("atan2_xInfCases(atan2_yInfCases)", SDL_atan2, cases, SDL_arraysize(cases));
}
/* Miscelanious cases */

View file

@ -423,7 +423,7 @@ SDL_Window *_createMouseSuiteTestWindow()
*/
void _destroyMouseSuiteTestWindow(SDL_Window *window)
{
if (window != NULL) {
if (window) {
SDL_DestroyWindow(window);
window = NULL;
SDLTest_AssertPass("SDL_DestroyWindow()");
@ -458,7 +458,7 @@ int mouse_warpMouseInWindow(void *arg)
yPositions[5] = h + 1;
/* Create test window */
window = _createMouseSuiteTestWindow();
if (window == NULL) {
if (!window) {
return TEST_ABORTED;
}
@ -503,6 +503,7 @@ int mouse_getMouseFocus(void *arg)
int x, y;
SDL_Window *window;
SDL_Window *focusWindow;
const SDL_bool video_driver_is_wayland = !SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland");
/* Get focus - focus non-deterministic */
focusWindow = SDL_GetMouseFocus();
@ -510,32 +511,37 @@ int mouse_getMouseFocus(void *arg)
/* Create test window */
window = _createMouseSuiteTestWindow();
if (window == NULL) {
if (!window) {
return TEST_ABORTED;
}
/* Mouse to random position inside window */
x = SDLTest_RandomIntegerInRange(1, w - 1);
y = SDLTest_RandomIntegerInRange(1, h - 1);
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
/* Wayland explicitly disallows warping the mouse pointer, so this test must be skipped. */
if (!video_driver_is_wayland) {
/* Mouse to random position inside window */
x = SDLTest_RandomIntegerInRange(1, w - 1);
y = SDLTest_RandomIntegerInRange(1, h - 1);
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
/* Pump events to update focus state */
SDL_Delay(100);
SDL_PumpEvents();
SDLTest_AssertPass("SDL_PumpEvents()");
/* Pump events to update focus state */
SDL_Delay(100);
SDL_PumpEvents();
SDLTest_AssertPass("SDL_PumpEvents()");
/* Get focus with explicit window setup - focus deterministic */
focusWindow = SDL_GetMouseFocus();
SDLTest_AssertPass("SDL_GetMouseFocus()");
SDLTest_AssertCheck(focusWindow != NULL, "Check returned window value is not NULL");
SDLTest_AssertCheck(focusWindow == window, "Check returned window value is test window");
/* Get focus with explicit window setup - focus deterministic */
focusWindow = SDL_GetMouseFocus();
SDLTest_AssertPass("SDL_GetMouseFocus()");
SDLTest_AssertCheck(focusWindow != NULL, "Check returned window value is not NULL");
SDLTest_AssertCheck(focusWindow == window, "Check returned window value is test window");
/* Mouse to random position outside window */
x = SDLTest_RandomIntegerInRange(-9, -1);
y = SDLTest_RandomIntegerInRange(-9, -1);
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
/* Mouse to random position outside window */
x = SDLTest_RandomIntegerInRange(-9, -1);
y = SDLTest_RandomIntegerInRange(-9, -1);
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
} else {
SDLTest_Log("Skipping mouse warp focus tests: Wayland does not support warping the mouse pointer");
}
/* Clean up test window */
_destroyMouseSuiteTestWindow(window);

View file

@ -14,6 +14,8 @@ const int _numRGBPixelFormats = 31;
Uint32 _RGBPixelFormats[] = {
SDL_PIXELFORMAT_INDEX1LSB,
SDL_PIXELFORMAT_INDEX1MSB,
SDL_PIXELFORMAT_INDEX2LSB,
SDL_PIXELFORMAT_INDEX2MSB,
SDL_PIXELFORMAT_INDEX4LSB,
SDL_PIXELFORMAT_INDEX4MSB,
SDL_PIXELFORMAT_INDEX8,
@ -47,6 +49,8 @@ Uint32 _RGBPixelFormats[] = {
const char *_RGBPixelFormatsVerbose[] = {
"SDL_PIXELFORMAT_INDEX1LSB",
"SDL_PIXELFORMAT_INDEX1MSB",
"SDL_PIXELFORMAT_INDEX2LSB",
"SDL_PIXELFORMAT_INDEX2MSB",
"SDL_PIXELFORMAT_INDEX4LSB",
"SDL_PIXELFORMAT_INDEX4MSB",
"SDL_PIXELFORMAT_INDEX8",

View file

@ -386,7 +386,7 @@ int platform_testSetErrorEmptyInput(void *arg)
int platform_testSetErrorInvalidInput(void *arg)
{
int result;
const char *invalidError = NULL;
const char *invalidError = "";
const char *probeError = "Testing";
char *lastError;
size_t len;

View file

@ -43,6 +43,7 @@ static int _isSupported(int code);
void InitCreateRenderer(void *arg)
{
int posX = 100, posY = 100, width = 320, height = 240;
int renderer_flags = SDL_RENDERER_ACCELERATED;
renderer = NULL;
window = SDL_CreateWindow("render_testCreateRenderer", posX, posY, width, height, 0);
SDLTest_AssertPass("SDL_CreateWindow()");
@ -51,7 +52,11 @@ void InitCreateRenderer(void *arg)
return;
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "dummy") == 0) {
renderer_flags = 0;
}
renderer = SDL_CreateRenderer(window, -1, renderer_flags);
SDLTest_AssertPass("SDL_CreateRenderer()");
SDLTest_AssertCheck(renderer != NULL, "Check SDL_CreateRenderer result");
if (renderer == NULL) {
@ -65,13 +70,13 @@ void InitCreateRenderer(void *arg)
*/
void CleanupDestroyRenderer(void *arg)
{
if (renderer != NULL) {
if (renderer) {
SDL_DestroyRenderer(renderer);
renderer = NULL;
SDLTest_AssertPass("SDL_DestroyRenderer()");
}
if (window != NULL) {
if (window) {
SDL_DestroyWindow(window);
window = NULL;
SDLTest_AssertPass("SDL_DestroyWindow");
@ -938,12 +943,12 @@ _loadTestFace(void)
SDL_Texture *tface;
face = SDLTest_ImageFace();
if (face == NULL) {
if (!face) {
return NULL;
}
tface = SDL_CreateTextureFromSurface(renderer, face);
if (tface == NULL) {
if (!tface) {
SDLTest_LogError("SDL_CreateTextureFromSurface() failed with error: %s", SDL_GetError());
}
@ -970,7 +975,7 @@ _hasTexColor(void)
/* Get test face. */
tface = _loadTestFace();
if (tface == NULL) {
if (!tface) {
return 0;
}
@ -1014,7 +1019,7 @@ _hasTexAlpha(void)
/* Get test face. */
tface = _loadTestFace();
if (tface == NULL) {
if (!tface) {
return 0;
}
@ -1043,7 +1048,7 @@ _hasTexAlpha(void)
/**
* @brief Compares screen pixels with image pixels. Helper function.
*
* @param s Image to compare against.
* @param referenceSurface Image to compare against.
*
* \sa
* http://wiki.libsdl.org/SDL_RenderReadPixels

View file

@ -1074,13 +1074,13 @@ int sdltest_randomIntegerInRange(void *arg)
/* Range with min at integer limit */
min = long_min;
max = long_max + (Sint32)SDLTest_RandomSint16();
max = long_min + (Sint32)SDLTest_RandomUint16();
result = SDLTest_RandomIntegerInRange(min, max);
SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(SINT32_MIN,...)");
SDLTest_AssertCheck(min <= result && result <= max, "Validated returned value; expected: [%" SDL_PRIs32 ",%" SDL_PRIs32 "], got: %" SDL_PRIs32, min, max, result);
/* Range with max at integer limit */
min = long_min - (Sint32)SDLTest_RandomSint16();
min = long_max - (Sint32)SDLTest_RandomUint16();
max = long_max;
result = SDLTest_RandomIntegerInRange(min, max);
SDLTest_AssertPass("Call to SDLTest_RandomIntegerInRange(...,SINT32_MAX)");

View file

@ -53,7 +53,7 @@ int stdlib_snprintf(void *arg)
int result;
int predicted;
char text[1024];
const char *expected;
const char *expected, *expected2, *expected3, *expected4, *expected5;
size_t size;
result = SDL_snprintf(text, sizeof(text), "%s", "foo");
@ -62,6 +62,18 @@ int stdlib_snprintf(void *arg)
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
result = SDL_snprintf(text, sizeof(text), "%10sA", "foo");
expected = " fooA";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%10sA\", \"foo\")");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
result = SDL_snprintf(text, sizeof(text), "%-10sA", "foo");
expected = "foo A";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%-10sA\", \"foo\")");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int)SDL_strlen(text), result);
result = SDL_snprintf(text, sizeof(text), "%S", L"foo");
expected = "foo";
SDLTest_AssertPass("Call to SDL_snprintf(\"%%S\", \"foo\")");
@ -175,6 +187,61 @@ int stdlib_snprintf(void *arg)
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == 7, "Check result value, expected: 7, got: %d", result);
result = SDL_snprintf(text, sizeof(text), "%p", (void *)0x1234abcd);
expected = "0x1234abcd";
expected2 = "1234ABCD";
expected3 = "000000001234ABCD";
expected4 = "1234abcd";
expected5 = "000000001234abcd";
SDLTest_AssertPass("Call to SDL_snprintf(text, sizeof(text), \"%%p\", 0x1234abcd)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0 ||
SDL_strcmp(text, expected2) == 0 ||
SDL_strcmp(text, expected3) == 0 ||
SDL_strcmp(text, expected4) == 0 ||
SDL_strcmp(text, expected5) == 0,
"Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(expected) ||
result == SDL_strlen(expected2) ||
result == SDL_strlen(expected3) ||
result == SDL_strlen(expected4) ||
result == SDL_strlen(expected5),
"Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
result = SDL_snprintf(text, sizeof(text), "A %p B", (void *)0x1234abcd);
expected = "A 0x1234abcd B";
expected2 = "A 1234ABCD B";
expected3 = "A 000000001234ABCD B";
expected4 = "A 1234abcd B";
expected5 = "A 000000001234abcd B";
SDLTest_AssertPass("Call to SDL_snprintf(text, sizeof(text), \"A %%p B\", 0x1234abcd)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0 ||
SDL_strcmp(text, expected2) == 0 ||
SDL_strcmp(text, expected3) == 0 ||
SDL_strcmp(text, expected4) == 0 ||
SDL_strcmp(text, expected5) == 0,
"Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(expected) ||
result == SDL_strlen(expected2) ||
result == SDL_strlen(expected3) ||
result == SDL_strlen(expected4) ||
result == SDL_strlen(expected5),
"Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
if (sizeof(void *) >= 8) {
result = SDL_snprintf(text, sizeof(text), "%p", (void *)0x1ba07bddf60L);
expected = "0x1ba07bddf60";
expected2 = "000001BA07BDDF60";
expected3 = "000001ba07bddf60";
SDLTest_AssertPass("Call to SDL_snprintf(text, sizeof(text), \"%%p\", 0x1ba07bddf60)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0 ||
SDL_strcmp(text, expected2) == 0 ||
SDL_strcmp(text, expected3) == 0,
"Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(expected) ||
result == SDL_strlen(expected2) ||
result == SDL_strlen(expected3),
"Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
}
return TEST_COMPLETED;
}
@ -207,10 +274,10 @@ int stdlib_getsetenv(void *arg)
text = SDL_getenv(name);
SDLTest_AssertPass("Call to SDL_getenv('%s')", name);
if (text != NULL) {
if (text) {
SDLTest_Log("Expected: NULL, Got: '%s' (%i)", text, (int)SDL_strlen(text));
}
} while (text != NULL);
} while (text);
/* Create random values to set */
value1 = SDLTest_RandomAsciiStringOfSize(10);
@ -325,6 +392,10 @@ int stdlib_getsetenv(void *arg)
#endif
#endif
#define FMT_PRILLd "%lld"
#define FMT_PRILLdn "%lld%lln"
#define FMT_PRILLu "%llu"
/**
* @brief Call to SDL_sscanf
*/
@ -333,13 +404,15 @@ int stdlib_sscanf(void *arg)
{
int output;
int result;
int length;
int expected_output;
int expected_result;
short short_output, expected_short_output;
long long_output, expected_long_output;
long long long_long_output, expected_long_long_output;
short short_output, expected_short_output, short_length;
long long_output, expected_long_output, long_length;
long long long_long_output, expected_long_long_output, long_long_length;
size_t size_output, expected_size_output;
char text[128];
char text[128], text2[128];
unsigned int r = 0, g = 0, b = 0;
expected_output = output = 123;
expected_result = -1;
@ -356,43 +429,62 @@ int stdlib_sscanf(void *arg)
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
output = 123;
length = 0;
expected_output = 2;
expected_result = 1;
result = SDL_sscanf("2", "%i", &output);
SDLTest_AssertPass("Call to SDL_sscanf(\"2\", \"%%i\", &output)");
result = SDL_sscanf("2", "%i%n", &output, &length);
SDLTest_AssertPass("Call to SDL_sscanf(\"2\", \"%%i%%n\", &output, &length)");
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
SDLTest_AssertCheck(length == 1, "Check length, expected: 1, got: %i", length);
output = 123;
length = 0;
expected_output = 0xa;
expected_result = 1;
result = SDL_sscanf("aa", "%1x", &output);
SDLTest_AssertPass("Call to SDL_sscanf(\"aa\", \"%%1x\", &output)");
result = SDL_sscanf("aa", "%1x%n", &output, &length);
SDLTest_AssertPass("Call to SDL_sscanf(\"aa\", \"%%1x%%n\", &output, &length)");
SDLTest_AssertCheck(expected_output == output, "Check output, expected: %i, got: %i", expected_output, output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
SDLTest_AssertCheck(length == 1, "Check length, expected: 1, got: %i", length);
#define SIZED_TEST_CASE(type, var, format_specifier) \
var##_output = 123; \
expected_##var##_output = (type)(((unsigned type)(~0)) >> 1); \
expected_result = 1; \
result = SDL_snprintf(text, sizeof(text), format_specifier, expected_##var##_output); \
result = SDL_sscanf(text, format_specifier, &var##_output); \
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%s\", &output)", text, #format_specifier); \
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " format_specifier ", got: " format_specifier, expected_##var##_output, var##_output); \
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); \
\
var##_output = 123; \
expected_##var##_output = ~(type)(((unsigned type)(~0)) >> 1); \
expected_result = 1; \
result = SDL_snprintf(text, sizeof(text), format_specifier, expected_##var##_output); \
result = SDL_sscanf(text, format_specifier, &var##_output); \
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", \"%s\", &output)", text, #format_specifier); \
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " format_specifier ", got: " format_specifier, expected_##var##_output, var##_output); \
expected_result = 3;
result = SDL_sscanf("#026", "#%1x%1x%1x", &r, &g, &b);
SDLTest_AssertPass("Call to SDL_sscanf(\"#026\", \"#%%1x%%1x%%1x\", &r, &g, &b)");
expected_output = 0;
SDLTest_AssertCheck(r == expected_output, "Check output for r, expected: %i, got: %i", expected_output, r);
expected_output = 2;
SDLTest_AssertCheck(g == expected_output, "Check output for g, expected: %i, got: %i", expected_output, g);
expected_output = 6;
SDLTest_AssertCheck(b == expected_output, "Check output for b, expected: %i, got: %i", expected_output, b);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
SIZED_TEST_CASE(short, short, "%hd")
SIZED_TEST_CASE(long, long, "%ld")
SIZED_TEST_CASE(long long, long_long, "%lld")
#define SIZED_TEST_CASE(type, var, printf_specifier, scanf_specifier) \
var##_output = 123; \
var##_length = 0; \
expected_##var##_output = (type)(((unsigned type)(~0)) >> 1); \
expected_result = 1; \
result = SDL_snprintf(text, sizeof(text), printf_specifier, expected_##var##_output); \
result = SDL_sscanf(text, scanf_specifier, &var##_output, &var##_length); \
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", %s, &output, &length)", text, #scanf_specifier); \
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " printf_specifier ", got: " printf_specifier, expected_##var##_output, var##_output); \
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); \
SDLTest_AssertCheck(var##_length == (type)SDL_strlen(text), "Check length, expected: %i, got: %i", (int)SDL_strlen(text), (int)var##_length); \
\
var##_output = 123; \
var##_length = 0; \
expected_##var##_output = ~(type)(((unsigned type)(~0)) >> 1); \
expected_result = 1; \
result = SDL_snprintf(text, sizeof(text), printf_specifier, expected_##var##_output); \
result = SDL_sscanf(text, scanf_specifier, &var##_output, &var##_length); \
SDLTest_AssertPass("Call to SDL_sscanf(\"%s\", %s, &output, &length)", text, #scanf_specifier); \
SDLTest_AssertCheck(expected_##var##_output == var##_output, "Check output, expected: " printf_specifier ", got: " printf_specifier, expected_##var##_output, var##_output); \
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result); \
SDLTest_AssertCheck(var##_length == (type)SDL_strlen(text), "Check length, expected: %i, got: %i", (int)SDL_strlen(text), (int)var##_length); \
SIZED_TEST_CASE(short, short, "%hd", "%hd%hn")
SIZED_TEST_CASE(long, long, "%ld", "%ld%ln")
SIZED_TEST_CASE(long long, long_long, FMT_PRILLd, FMT_PRILLdn)
size_output = 123;
expected_size_output = ~((size_t)0);
@ -403,6 +495,82 @@ int stdlib_sscanf(void *arg)
SDLTest_AssertCheck(expected_size_output == size_output, "Check output, expected: %zu, got: %zu", expected_size_output, size_output);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 1;
text[0] = '\0';
result = SDL_sscanf("abc def", "%s", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc def\", \"%%s\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 1;
text[0] = '\0';
result = SDL_sscanf("abc,def", "%s", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%s\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc,def") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 1;
text[0] = '\0';
result = SDL_sscanf("abc,def", "%[cba]", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%[cba]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 1;
text[0] = '\0';
result = SDL_sscanf("abc,def", "%[a-z]", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%[z-a]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 1;
text[0] = '\0';
result = SDL_sscanf("abc,def", "%[^,]", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%[^,]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 0;
text[0] = '\0';
result = SDL_sscanf("abc,def", "%[A-Z]", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%[A-Z]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "") == 0, "Check output, expected: \"\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 2;
text[0] = '\0';
text2[0] = '\0';
result = SDL_sscanf("abc,def", "%[abc],%[def]", text, text2);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%[abc],%%[def]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(SDL_strcmp(text2, "def") == 0, "Check output, expected: \"def\", got: \"%s\"", text2);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 2;
text[0] = '\0';
text2[0] = '\0';
result = SDL_sscanf("abc,def", "%[abc]%*[,]%[def]", text, text2);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc,def\", \"%%[abc]%%*[,]%%[def]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(SDL_strcmp(text2, "def") == 0, "Check output, expected: \"def\", got: \"%s\"", text2);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 2;
text[0] = '\0';
text2[0] = '\0';
result = SDL_sscanf("abc def", "%[abc] %[def]", text, text2);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc def\", \"%%[abc] %%[def]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc") == 0, "Check output, expected: \"abc\", got: \"%s\"", text);
SDLTest_AssertCheck(SDL_strcmp(text2, "def") == 0, "Check output, expected: \"def\", got: \"%s\"", text2);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
expected_result = 1;
text[0] = '\0';
result = SDL_sscanf("abc123XYZ", "%[a-zA-Z0-9]", text);
SDLTest_AssertPass("Call to SDL_sscanf(\"abc123XYZ\", \"%%[a-zA-Z0-9]\", text)");
SDLTest_AssertCheck(SDL_strcmp(text, "abc123XYZ") == 0, "Check output, expected: \"abc123XYZ\", got: \"%s\"", text);
SDLTest_AssertCheck(expected_result == result, "Check return value, expected: %i, got: %i", expected_result, result);
return TEST_COMPLETED;
}
@ -570,6 +738,112 @@ stdlib_overflow(void *arg)
return TEST_COMPLETED;
}
static int
stdlib_strtox(void *arg)
{
const unsigned long long ullong_max = ~0ULL;
#define STRTOX_TEST_CASE(func_name, type, format_spec, str, base, expected_result, expected_endp_offset) do { \
const char *s = str; \
type r, expected_r = expected_result; \
char *ep, *expected_ep = (char *)s + expected_endp_offset; \
r = func_name(s, &ep, base); \
SDLTest_AssertPass("Call to " #func_name "(" #str ", &endp, " #base ")"); \
SDLTest_AssertCheck(r == expected_r, "Check result value, expected: " format_spec ", got: " format_spec, expected_r, r); \
SDLTest_AssertCheck(ep == expected_ep, "Check endp value, expected: %p, got: %p", expected_ep, ep); \
} while (0)
// infer decimal
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "\t 123abcxyz", 0, 123, 6); // skip leading space
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "+123abcxyz", 0, 123, 4);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "+123abcxyz", 0, 123, 4);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "-123abcxyz", 0, -123, 4);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "9999999999999999999999999999999999999999abcxyz", 0, ullong_max, 40);
// infer hexadecimal
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "0x123abcxyz", 0, 0x123abc, 8);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "0X123ABCXYZ", 0, 0x123abc, 8); // uppercase X
// infer octal
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "0123abcxyz", 0, 0123, 4);
// arbitrary bases
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "00110011", 2, 51, 8);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "-uvwxyz", 32, -991, 3);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "ZzZzZzZzZzZzZzZzZzZzZzZzZ", 36, ullong_max, 25);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "0", 0, 0, 1);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "0", 10, 0, 1);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "-0", 0, 0, 2);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, "-0", 10, 0, 2);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLu, " - 1", 0, 0, 0); // invalid input
// We know that SDL_strtol, SDL_strtoul and SDL_strtoll share the same code path as SDL_strtoull under the hood,
// so the most interesting test cases are those close to the bounds of the integer type.
// For simplicity, we only run long/long long tests when they are 32-bit/64-bit, respectively.
// Suppressing warnings would be difficult otherwise.
// Since the CI runs the tests against a variety of targets, this should be fine in practice.
if (sizeof(long) == 4) {
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "0", 0, 0, 1);
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "0", 10, 0, 1);
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "-0", 0, 0, 2);
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "-0", 10, 0, 2);
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "2147483647", 10, 2147483647, 10);
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "2147483648", 10, 2147483647, 10);
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "-2147483648", 10, -2147483647L - 1, 11);
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "-2147483649", 10, -2147483647L - 1, 11);
STRTOX_TEST_CASE(SDL_strtol, long, "%ld", "-9999999999999999999999999999999999999999", 10, -2147483647L - 1, 41);
STRTOX_TEST_CASE(SDL_strtoul, unsigned long, "%lu", "4294967295", 10, 4294967295UL, 10);
STRTOX_TEST_CASE(SDL_strtoul, unsigned long, "%lu", "4294967296", 10, 4294967295UL, 10);
STRTOX_TEST_CASE(SDL_strtoul, unsigned long, "%lu", "-4294967295", 10, 1, 11);
}
if (sizeof(long long) == 8) {
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "0", 0, 0LL, 1);
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "0", 10, 0LL, 1);
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "-0", 0, 0LL, 2);
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "-0", 10, 0LL, 2);
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "9223372036854775807", 10, 9223372036854775807LL, 19);
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "9223372036854775808", 10, 9223372036854775807LL, 19);
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "-9223372036854775808", 10, -9223372036854775807LL - 1, 20);
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "-9223372036854775809", 10, -9223372036854775807LL - 1, 20);
STRTOX_TEST_CASE(SDL_strtoll, long long, FMT_PRILLd, "-9999999999999999999999999999999999999999", 10, -9223372036854775807LL - 1, 41);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLd, "18446744073709551615", 10, 18446744073709551615ULL, 20);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLd, "18446744073709551616", 10, 18446744073709551615ULL, 20);
STRTOX_TEST_CASE(SDL_strtoull, unsigned long long, FMT_PRILLd, "-18446744073709551615", 10, 1, 21);
}
#undef STRTOX_TEST_CASE
return TEST_COMPLETED;
}
static int
stdlib_strtod(void *arg)
{
#define STRTOD_TEST_CASE(str, expected_result, expected_endp_offset) do { \
const char *s = str; \
double r, expected_r = expected_result; \
char *ep, *expected_ep = (char *)s + expected_endp_offset; \
r = SDL_strtod(s, &ep); \
SDLTest_AssertPass("Call to SDL_strtod(" #str ", &endp)"); \
SDLTest_AssertCheck(r == expected_r, "Check result value, expected: %f, got: %f", expected_r, r); \
SDLTest_AssertCheck(ep == expected_ep, "Check endp value, expected: %p, got: %p", expected_ep, ep); \
} while (0)
STRTOD_TEST_CASE("\t 123.75abcxyz", 123.75, 9); // skip leading space
STRTOD_TEST_CASE("+999.555", 999.555, 8);
STRTOD_TEST_CASE("-999.555", -999.555, 8);
#undef STRTOD_TEST_CASE
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Standard C routine test cases */
@ -593,6 +867,14 @@ static const SDLTest_TestCaseReference stdlibTestOverflow = {
stdlib_overflow, "stdlib_overflow", "Overflow detection", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest_strtox = {
stdlib_strtox, "stdlib_strtox", "Calls to SDL_strtol, SDL_strtoul, SDL_strtoll and SDL_strtoull", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest_strtod = {
stdlib_strtod, "stdlib_strtod", "Calls to SDL_strtod", TEST_ENABLED
};
/* Sequence of Standard C routine test cases */
static const SDLTest_TestCaseReference *stdlibTests[] = {
&stdlibTest1,
@ -600,6 +882,8 @@ static const SDLTest_TestCaseReference *stdlibTests[] = {
&stdlibTest3,
&stdlibTest4,
&stdlibTestOverflow,
&stdlibTest_strtox,
&stdlibTest_strtod,
NULL
};

View file

@ -0,0 +1,241 @@
/**
* Subsystem test suite
*/
#include "SDL.h"
#include "SDL_test.h"
/* ================= Test Case Implementation ================== */
/* Fixture */
static void subsystemsSetUp(void *arg)
{
/* Reset each one of the SDL subsystems */
/* CHECKME: can we use SDL_Quit here, or this will break the flow of tests? */
SDL_Quit();
/* Alternate variant without SDL_Quit:
while (SDL_WasInit(SDL_INIT_EVERYTHING) != 0) {
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
}
*/
SDLTest_AssertPass("Reset all subsystems before subsystems test");
SDLTest_AssertCheck(SDL_WasInit(SDL_INIT_EVERYTHING) == 0, "Check result from SDL_WasInit(SDL_INIT_EVERYTHING)");
}
static void subsystemsTearDown(void *arg)
{
/* Reset each one of the SDL subsystems */
SDL_Quit();
SDLTest_AssertPass("Cleanup of subsystems test completed");
}
/* Test case functions */
/**
* \brief Inits and Quits particular subsystem, checking its Init status.
*
* \sa SDL_InitSubSystem
* \sa SDL_QuitSubSystem
*
*/
static int subsystems_referenceCount(void)
{
const int system = SDL_INIT_VIDEO;
int result;
/* Ensure that we start with a non-initialized subsystem. */
SDLTest_AssertCheck(SDL_WasInit(system) == 0, "Check result from SDL_WasInit(0x%x)", system);
/* Init subsystem once, and quit once */
SDL_InitSubSystem(system);
SDLTest_AssertPass("Call to SDL_InitSubSystem(0x%x)", system);
result = SDL_WasInit(system);
SDLTest_AssertCheck(result == system, "Check result from SDL_WasInit(0x%x), expected: 0x%x, got: 0x%x", system, system, result);
SDL_QuitSubSystem(system);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(0x%x)", system);
result = SDL_WasInit(system);
SDLTest_AssertCheck(result == 0, "Check result from SDL_WasInit(0x%x), expected: 0, got: 0x%x", system, result);
/* Init subsystem number of times, then decrement reference count until it's disposed of. */
SDL_InitSubSystem(system);
SDL_InitSubSystem(system);
SDL_InitSubSystem(system);
SDLTest_AssertPass("Call to SDL_InitSubSystem(0x%x) x3 times", system);
result = SDL_WasInit(system);
SDLTest_AssertCheck(result == system, "Check result from SDL_WasInit(0x%x), expected: 0x%x, got: 0x%x", system, system, result);
SDL_QuitSubSystem(system);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(0x%x) x1", system);
result = SDL_WasInit(system);
SDLTest_AssertCheck(result == system, "Check result from SDL_WasInit(0x%x), expected: 0x%x, got: 0x%x", system, system, result);
SDL_QuitSubSystem(system);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(0x%x) x2", system);
result = SDL_WasInit(system);
SDLTest_AssertCheck(result == system, "Check result from SDL_WasInit(0x%x), expected: 0x%x, got: 0x%x", system, system, result);
SDL_QuitSubSystem(system);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(0x%x) x3", system);
result = SDL_WasInit(system);
SDLTest_AssertCheck(result == 0, "Check result from SDL_WasInit(0x%x), expected: 0, got: 0x%x", system, result);
return TEST_COMPLETED;
}
/**
* \brief Inits and Quits subsystems that have another as dependency;
* check that the dependency is not removed before the last of its dependents.
*
* \sa SDL_InitSubSystem
* \sa SDL_QuitSubSystem
*
*/
static int subsystems_dependRefCountInitAllQuitByOne(void)
{
int result;
/* Ensure that we start with reset subsystems. */
SDLTest_AssertCheck(SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS) == 0,
"Check result from SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS)");
/* Following should init SDL_INIT_EVENTS and give it +3 ref counts. */
SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK)");
result = SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
SDLTest_AssertCheck(result == (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK), "Check result from SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK), expected: 0x%x, got: 0x%x", (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK), result);
result = SDL_WasInit(SDL_INIT_EVENTS);
SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
/* Quit systems one by one. */
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_VIDEO)");
result = SDL_WasInit(SDL_INIT_EVENTS);
SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
result = SDL_WasInit(SDL_INIT_EVENTS);
SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_JOYSTICK)");
result = SDL_WasInit(SDL_INIT_EVENTS);
SDLTest_AssertCheck(result == 0, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0, got: 0x%x", result);
return TEST_COMPLETED;
}
/**
* \brief Inits and Quits subsystems that have another as dependency;
* check that the dependency is not removed before the last of its dependents.
*
* \sa SDL_InitSubSystem
* \sa SDL_QuitSubSystem
*
*/
static int subsystems_dependRefCountInitByOneQuitAll(void)
{
int result;
/* Ensure that we start with reset subsystems. */
SDLTest_AssertCheck(SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS) == 0,
"Check result from SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS)");
/* Following should init SDL_INIT_EVENTS and give it +3 ref counts. */
SDL_InitSubSystem(SDL_INIT_VIDEO);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_VIDEO)");
result = SDL_WasInit(SDL_INIT_EVENTS);
SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
SDL_InitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)");
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_JOYSTICK)");
/* Quit systems all at once. */
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK)");
result = SDL_WasInit(SDL_INIT_EVENTS);
SDLTest_AssertCheck(result == 0, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0, got: 0x%x", result);
return TEST_COMPLETED;
}
/**
* \brief Inits and Quits subsystems that have another as dependency,
* but also inits that dependency explicitly, giving it extra ref count.
* Check that the dependency is not removed before the last reference is gone.
*
* \sa SDL_InitSubSystem
* \sa SDL_QuitSubSystem
*
*/
static int subsystems_dependRefCountWithExtraInit(void)
{
int result;
/* Ensure that we start with reset subsystems. */
SDLTest_AssertCheck(SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS) == 0,
"Check result from SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS)");
/* Init EVENTS explicitly, +1 ref count. */
SDL_InitSubSystem(SDL_INIT_EVENTS);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_EVENTS)");
result = SDL_WasInit(SDL_INIT_EVENTS);
SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
/* Following should init SDL_INIT_EVENTS and give it +3 ref counts. */
SDL_InitSubSystem(SDL_INIT_VIDEO);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_VIDEO)");
SDL_InitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)");
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_JOYSTICK)");
/* Quit EVENTS explicitly, -1 ref count. */
SDL_QuitSubSystem(SDL_INIT_EVENTS);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_EVENTS)");
result = SDL_WasInit(SDL_INIT_EVENTS);
SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
/* Quit systems one by one. */
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_VIDEO)");
result = SDL_WasInit(SDL_INIT_EVENTS);
SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
result = SDL_WasInit(SDL_INIT_EVENTS);
SDLTest_AssertCheck(result == SDL_INIT_EVENTS, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0x4000, got: 0x%x", result);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_JOYSTICK)");
result = SDL_WasInit(SDL_INIT_EVENTS);
SDLTest_AssertCheck(result == 0, "Check result from SDL_WasInit(SDL_INIT_EVENTS), expected: 0, got: 0x%x", result);
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Subsystems test cases */
static const SDLTest_TestCaseReference subsystemsTest1 = {
(SDLTest_TestCaseFp)subsystems_referenceCount, "subsystems_referenceCount", "Makes sure that subsystem stays until number of quits matches inits.", TEST_ENABLED
};
static const SDLTest_TestCaseReference subsystemsTest2 = {
(SDLTest_TestCaseFp)subsystems_dependRefCountInitAllQuitByOne, "subsystems_dependRefCountInitAllQuitByOne", "Check reference count of subsystem dependencies.", TEST_ENABLED
};
static const SDLTest_TestCaseReference subsystemsTest3 = {
(SDLTest_TestCaseFp)subsystems_dependRefCountInitByOneQuitAll, "subsystems_dependRefCountInitByOneQuitAll", "Check reference count of subsystem dependencies.", TEST_ENABLED
};
static const SDLTest_TestCaseReference subsystemsTest4 = {
(SDLTest_TestCaseFp)subsystems_dependRefCountWithExtraInit, "subsystems_dependRefCountWithExtraInit", "Check reference count of subsystem dependencies.", TEST_ENABLED
};
/* Sequence of Events test cases */
static const SDLTest_TestCaseReference *subsystemsTests[] = {
&subsystemsTest1, &subsystemsTest2, &subsystemsTest3, &subsystemsTest4, NULL
};
/* Events test suite (global) */
SDLTest_TestSuiteReference subsystemsTestSuite = {
"Subsystems",
subsystemsSetUp,
subsystemsTests,
subsystemsTearDown
};

View file

@ -16,6 +16,7 @@ extern SDLTest_TestSuiteReference guidTestSuite;
extern SDLTest_TestSuiteReference hintsTestSuite;
extern SDLTest_TestSuiteReference joystickTestSuite;
extern SDLTest_TestSuiteReference keyboardTestSuite;
extern SDLTest_TestSuiteReference logTestSuite;
extern SDLTest_TestSuiteReference mainTestSuite;
extern SDLTest_TestSuiteReference mathTestSuite;
extern SDLTest_TestSuiteReference mouseTestSuite;
@ -26,6 +27,7 @@ extern SDLTest_TestSuiteReference renderTestSuite;
extern SDLTest_TestSuiteReference rwopsTestSuite;
extern SDLTest_TestSuiteReference sdltestTestSuite;
extern SDLTest_TestSuiteReference stdlibTestSuite;
extern SDLTest_TestSuiteReference subsystemsTestSuite;
extern SDLTest_TestSuiteReference surfaceTestSuite;
extern SDLTest_TestSuiteReference syswmTestSuite;
extern SDLTest_TestSuiteReference timerTestSuite;
@ -40,6 +42,7 @@ SDLTest_TestSuiteReference *testSuites[] = {
&hintsTestSuite,
&joystickTestSuite,
&keyboardTestSuite,
&logTestSuite,
&mainTestSuite,
&mathTestSuite,
&mouseTestSuite,
@ -54,6 +57,7 @@ SDLTest_TestSuiteReference *testSuites[] = {
&syswmTestSuite,
&timerTestSuite,
&videoTestSuite,
&subsystemsTestSuite, /* run last, not interfere with other test enviroment */
NULL
};

View file

@ -81,7 +81,7 @@ void _surfaceTearDown(void *arg)
/**
* Helper that clears the test surface
*/
void _clearTestSurface()
void _clearTestSurface(void)
{
int ret;
Uint32 color;
@ -346,7 +346,9 @@ int surface_testCompleteSurfaceConversion(void *arg)
SDL_PIXELFORMAT_RGBA8888,
SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_BGRA8888,
#if 0 /* We aren't testing HDR10 colorspace conversion */
SDL_PIXELFORMAT_ARGB2101010,
#endif
};
SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
SDL_PixelFormat *fmt1, *fmt2;
@ -668,6 +670,34 @@ int surface_testOverflow(void *arg)
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
/* SDL_PIXELFORMAT_INDEX2* needs 1 byte per 4 pixels. */
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 12, 1, 2, 3, SDL_PIXELFORMAT_INDEX2LSB);
SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceFrom(buf, 12, 1, 2, 3, 0, 0, 0, 0);
SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 13, 1, 2, 3, SDL_PIXELFORMAT_INDEX2LSB);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp (%d)", surface ? surface->pitch : 0);
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceFrom(buf, 13, 1, 2, 3, 0, 0, 0, 0);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 13, 1, 2, 4, SDL_PIXELFORMAT_INDEX2LSB);
SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceFrom(buf, 13, 1, 2, 4, 0, 0, 0, 0);
SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
/* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 16, 1, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
@ -737,19 +767,26 @@ int surface_testOverflow(void *arg)
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
if (sizeof(size_t) == 4 && sizeof(int) >= 4) {
SDL_ClearError();
expectedError = "Out of memory";
surface = SDL_CreateRGBSurfaceWithFormat(0, SDL_MAX_SINT32, 1, 8, SDL_PIXELFORMAT_INDEX8);
/* 0x5555'5555 * 3bpp = 0xffff'ffff which fits in size_t, but adding
* alignment padding makes it overflow */
surface = SDL_CreateRGBSurfaceWithFormat(0, 0x55555555, 1, 24, SDL_PIXELFORMAT_RGB24);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width + alignment");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormat(0, SDL_MAX_SINT32 / 2, 1, 32, SDL_PIXELFORMAT_ARGB8888);
SDL_ClearError();
/* 0x4000'0000 * 4bpp = 0x1'0000'0000 which (just) overflows */
surface = SDL_CreateRGBSurfaceWithFormat(0, 0x40000000, 1, 32, SDL_PIXELFORMAT_ARGB8888);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * bytes per pixel");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
SDL_ClearError();
surface = SDL_CreateRGBSurfaceWithFormat(0, (1 << 29) - 1, (1 << 29) - 1, 8, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
SDL_ClearError();
surface = SDL_CreateRGBSurfaceWithFormat(0, (1 << 15) + 1, (1 << 15) + 1, 32, SDL_PIXELFORMAT_ARGB8888);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height * bytes per pixel");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,

View file

@ -94,7 +94,10 @@ int timer_delayAndGetTicks(void *arg)
SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %" SDL_PRIu32, result2);
difference = result2 - result;
SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%" SDL_PRIu32 ", got: %" SDL_PRIu32, testDelay - marginOfError, difference);
#if 0
/* Disabled because this might fail on non-interactive systems. Moved to testtimer. */
SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%" SDL_PRIu32 ", got: %" SDL_PRIu32, testDelay + marginOfError, difference);
#endif
return TEST_COMPLETED;
}

View file

@ -28,6 +28,7 @@ SDL_Window *_createVideoSuiteTestWindow(const char *title)
SDL_Window *window;
int x, y, w, h;
SDL_WindowFlags flags;
SDL_bool needs_renderer = SDL_FALSE;
/* Standard window */
x = SDLTest_RandomIntegerInRange(1, 100);
@ -40,6 +41,35 @@ SDL_Window *_createVideoSuiteTestWindow(const char *title)
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,%d)", x, y, w, h, flags);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
/* Wayland and XWayland windows require that a frame be presented before they are fully mapped and visible onscreen.
* This is required for the mouse/keyboard grab tests to pass.
*/
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) {
needs_renderer = SDL_TRUE;
} else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
/* Try to detect if the x11 driver is running under XWayland */
const char *session_type = SDL_getenv("XDG_SESSION_TYPE");
if (session_type && SDL_strcasecmp(session_type, "wayland") == 0) {
needs_renderer = SDL_TRUE;
}
}
if (needs_renderer) {
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer) {
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
/* Some desktops don't display the window immediately after presentation,
* so delay to give the window time to actually appear on the desktop.
*/
SDL_Delay(100);
} else {
SDLTest_Log("Unable to create a renderer, some tests may fail on Wayland/XWayland");
}
}
return window;
}
@ -48,7 +78,7 @@ SDL_Window *_createVideoSuiteTestWindow(const char *title)
*/
void _destroyVideoSuiteTestWindow(SDL_Window *window)
{
if (window != NULL) {
if (window) {
SDL_DestroyWindow(window);
window = NULL;
SDLTest_AssertPass("Call to SDL_DestroyWindow()");
@ -278,6 +308,8 @@ int video_createWindowVariousFlags(void *arg)
break;
case 2:
flags = SDL_WINDOW_OPENGL;
/* Skip - not every video driver supports OpenGL; comment out next line to run test */
continue;
break;
case 3:
flags = SDL_WINDOW_SHOWN;
@ -576,7 +608,7 @@ int video_getWindowDisplayMode(void *arg)
/* Call against new test window */
window = _createVideoSuiteTestWindow(title);
if (window != NULL) {
if (window) {
result = SDL_GetWindowDisplayMode(window, &mode);
SDLTest_AssertPass("Call to SDL_GetWindowDisplayMode()");
SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0, got: %d", result);
@ -592,7 +624,7 @@ int video_getWindowDisplayMode(void *arg)
}
/* Helper function that checks for an 'Invalid window' error */
void _checkInvalidWindowError()
void _checkInvalidWindowError(void)
{
const char *invalidWindowError = "Invalid window";
char *lastError;
@ -670,7 +702,7 @@ video_getWindowGammaRamp(void *arg)
/* Call against new test window */
window = _createVideoSuiteTestWindow(title);
if (window == NULL) return TEST_ABORTED;
if (!window) return TEST_ABORTED;
/* Retrieve no channel */
result = SDL_GetWindowGammaRamp(window, NULL, NULL, NULL);
@ -820,13 +852,33 @@ int video_getSetWindowGrab(void *arg)
const char *title = "video_getSetWindowGrab Test Window";
SDL_Window *window;
SDL_bool originalMouseState, originalKeyboardState;
SDL_bool hasFocusGained = SDL_FALSE;
/* Call against new test window */
window = _createVideoSuiteTestWindow(title);
if (window == NULL) {
if (!window) {
return TEST_ABORTED;
}
/* Need to raise the window to have and SDL_EVENT_WINDOW_FOCUS_GAINED,
* so that the window gets the flags SDL_WINDOW_INPUT_FOCUS,
* so that it can be "grabbed" */
SDL_RaiseWindow(window);
{
SDL_Event evt;
SDL_zero(evt);
while (SDL_PollEvent(&evt)) {
if (evt.type == SDL_WINDOWEVENT) {
if (evt.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
hasFocusGained = SDL_TRUE;
}
}
}
}
SDLTest_AssertCheck(hasFocusGained == SDL_TRUE, "Expected window with focus");
/* Get state */
originalMouseState = SDL_GetWindowMouseGrab(window);
SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
@ -967,7 +1019,7 @@ int video_getWindowId(void *arg)
/* Call against new test window */
window = _createVideoSuiteTestWindow(title);
if (window == NULL) {
if (!window) {
return TEST_ABORTED;
}
@ -1022,7 +1074,7 @@ int video_getWindowPixelFormat(void *arg)
/* Call against new test window */
window = _createVideoSuiteTestWindow(title);
if (window == NULL) {
if (!window) {
return TEST_ABORTED;
}
@ -1085,28 +1137,58 @@ int video_getSetWindowPosition(void *arg)
{
const char *title = "video_getSetWindowPosition Test Window";
SDL_Window *window;
int maxxVariation, maxyVariation;
int xVariation, yVariation;
int referenceX, referenceY;
int currentX, currentY;
int desiredX, desiredY;
SDL_Rect display_bounds;
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) {
SDLTest_Log("Skipping test: wayland does not support window positioning");
return TEST_SKIPPED;
}
/* Call against new test window */
window = _createVideoSuiteTestWindow(title);
if (window == NULL) {
if (!window) {
return TEST_ABORTED;
}
for (xVariation = 0; xVariation < 4; xVariation++) {
for (yVariation = 0; yVariation < 4; yVariation++) {
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
/* The X11 server allows arbitrary window placement, but compositing
* window managers such as GNOME and KDE force windows to be within
* desktop bounds.
*/
maxxVariation = 2;
maxyVariation = 2;
SDL_GetDisplayUsableBounds(SDL_GetWindowDisplayIndex(window), &display_bounds);
} else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "cocoa") == 0) {
/* Platform doesn't allow windows with negative Y desktop bounds */
maxxVariation = 4;
maxyVariation = 3;
SDL_GetDisplayUsableBounds(SDL_GetWindowDisplayIndex(window), &display_bounds);
} else {
/* Platform allows windows to be placed out of bounds */
maxxVariation = 4;
maxyVariation = 4;
SDL_GetDisplayBounds(SDL_GetWindowDisplayIndex(window), &display_bounds);
}
for (xVariation = 0; xVariation < maxxVariation; xVariation++) {
for (yVariation = 0; yVariation < maxyVariation; yVariation++) {
switch (xVariation) {
default:
case 0:
/* Zero X Position */
desiredX = 0;
desiredX = display_bounds.x > 0 ? display_bounds.x : 0;
break;
case 1:
/* Random X position inside screen */
desiredX = SDLTest_RandomIntegerInRange(1, 100);
desiredX = SDLTest_RandomIntegerInRange(display_bounds.x + 1, display_bounds.x + 100);
break;
case 2:
/* Random X position outside screen (positive) */
@ -1121,15 +1203,15 @@ int video_getSetWindowPosition(void *arg)
switch (yVariation) {
default:
case 0:
/* Zero X Position */
desiredY = 0;
/* Zero Y Position */
desiredY = display_bounds.y > 0 ? display_bounds.y : 0;
break;
case 1:
/* Random X position inside screen */
desiredY = SDLTest_RandomIntegerInRange(1, 100);
/* Random Y position inside screen */
desiredY = SDLTest_RandomIntegerInRange(display_bounds.y + 1, display_bounds.y + 100);
break;
case 2:
/* Random X position outside screen (positive) */
/* Random Y position outside screen (positive) */
desiredY = SDLTest_RandomIntegerInRange(10000, 11000);
break;
case 3:
@ -1218,7 +1300,7 @@ int video_getSetWindowPosition(void *arg)
}
/* Helper function that checks for an 'Invalid parameter' error */
void _checkInvalidParameterError()
void _checkInvalidParameterError(void)
{
const char *invalidParameterError = "Parameter";
char *lastError;
@ -1255,7 +1337,7 @@ int video_getSetWindowSize(void *arg)
int desiredW, desiredH;
/* Get display bounds for size range */
result = SDL_GetDisplayBounds(0, &display);
result = SDL_GetDisplayUsableBounds(0, &display);
SDLTest_AssertPass("SDL_GetDisplayBounds()");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
if (result != 0) {
@ -1264,19 +1346,20 @@ int video_getSetWindowSize(void *arg)
/* Call against new test window */
window = _createVideoSuiteTestWindow(title);
if (window == NULL) {
if (!window) {
return TEST_ABORTED;
}
#ifdef __WIN32__
/* Platform clips window size to screen size */
maxwVariation = 4;
maxhVariation = 4;
#else
/* Platform allows window size >= screen size */
maxwVariation = 5;
maxhVariation = 5;
#endif
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "windows") == 0 ||
SDL_strcmp(SDL_GetCurrentVideoDriver(), "x11") == 0) {
/* Platform clips window size to screen size */
maxwVariation = 4;
maxhVariation = 4;
} else {
/* Platform allows window size >= screen size */
maxwVariation = 5;
maxhVariation = 5;
}
for (wVariation = 0; wVariation < maxwVariation; wVariation++) {
for (hVariation = 0; hVariation < maxhVariation; hVariation++) {
@ -1355,7 +1438,6 @@ int video_getSetWindowSize(void *arg)
}
}
/* Get just width */
currentW = desiredW + 1;
SDL_GetWindowSize(window, &currentW, NULL);
@ -1447,7 +1529,7 @@ int video_getSetWindowMinimumSize(void *arg)
/* Call against new test window */
window = _createVideoSuiteTestWindow(title);
if (window == NULL) {
if (!window) {
return TEST_ABORTED;
}
@ -1589,7 +1671,7 @@ int video_getSetWindowMaximumSize(void *arg)
/* Call against new test window */
window = _createVideoSuiteTestWindow(title);
if (window == NULL) {
if (!window) {
return TEST_ABORTED;
}
@ -1727,30 +1809,30 @@ int video_getSetWindowData(void *arg)
/* Call against new test window */
window = _createVideoSuiteTestWindow(title);
if (window == NULL) {
if (!window) {
return TEST_ABORTED;
}
/* Create testdata */
datasize = SDLTest_RandomIntegerInRange(1, 32);
referenceUserdata = SDLTest_RandomAsciiStringOfSize(datasize);
if (referenceUserdata == NULL) {
if (!referenceUserdata) {
returnValue = TEST_ABORTED;
goto cleanup;
}
userdata = SDL_strdup(referenceUserdata);
if (userdata == NULL) {
if (!userdata) {
returnValue = TEST_ABORTED;
goto cleanup;
}
datasize = SDLTest_RandomIntegerInRange(1, 32);
referenceUserdata2 = SDLTest_RandomAsciiStringOfSize(datasize);
if (referenceUserdata2 == NULL) {
if (!referenceUserdata2) {
returnValue = TEST_ABORTED;
goto cleanup;
}
userdata2 = SDL_strdup(referenceUserdata2);
if (userdata2 == NULL) {
if (!userdata2) {
returnValue = TEST_ABORTED;
goto cleanup;
}
@ -1935,6 +2017,11 @@ int video_setWindowCenteredOnDisplay(void *arg)
SDL_Rect display0, display1;
displayNum = SDL_GetNumVideoDisplays();
SDLTest_AssertPass("SDL_GetNumVideoDisplays()");
SDLTest_AssertCheck(displayNum >= 1, "Validate result (current: %d, expected >= 1)", displayNum);
if (displayNum <= 0) {
return TEST_ABORTED;
}
/* Get display bounds */
result = SDL_GetDisplayBounds(0 % displayNum, &display0);
@ -1959,6 +2046,7 @@ int video_setWindowCenteredOnDisplay(void *arg)
int currentDisplay;
int expectedDisplay;
SDL_Rect expectedDisplayRect;
SDL_bool video_driver_is_wayland = SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0;
/* xVariation is the display we start on */
expectedDisplay = xVariation % displayNum;
@ -1970,20 +2058,46 @@ int video_setWindowCenteredOnDisplay(void *arg)
expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_BORDERLESS);
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
/* Wayland windows require that a frame be presented before they are fully mapped and visible onscreen. */
if (video_driver_is_wayland) {
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer) {
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
/* Some desktops don't display the window immediately after presentation,
* so delay to give the window time to actually appear on the desktop.
*/
SDL_Delay(100);
} else {
SDLTest_Log("Unable to create a renderer, tests may fail under Wayland");
}
}
/* Check the window is centered on the requested display */
currentDisplay = SDL_GetWindowDisplayIndex(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
} else {
SDLTest_Log("Skipping display index validation: Wayland driver does not support window positioning");
}
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
} else {
SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning");
}
/* Enter fullscreen desktop */
result = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
@ -1994,11 +2108,19 @@ int video_setWindowCenteredOnDisplay(void *arg)
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
} else {
SDLTest_Log("Skipping display index validation: Wayland driver does not support window positioning");
}
SDLTest_AssertCheck(currentW == expectedDisplayRect.w, "Validate width (current: %d, expected: %d)", currentW, expectedDisplayRect.w);
SDLTest_AssertCheck(currentH == expectedDisplayRect.h, "Validate height (current: %d, expected: %d)", currentH, expectedDisplayRect.h);
SDLTest_AssertCheck(currentX == expectedDisplayRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedDisplayRect.x);
SDLTest_AssertCheck(currentY == expectedDisplayRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedDisplayRect.y);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentX == expectedDisplayRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedDisplayRect.x);
SDLTest_AssertCheck(currentY == expectedDisplayRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedDisplayRect.y);
} else {
SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning");
}
/* Leave fullscreen desktop */
result = SDL_SetWindowFullscreen(window, 0);
@ -2009,11 +2131,19 @@ int video_setWindowCenteredOnDisplay(void *arg)
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
} else {
SDLTest_Log("Skipping display index validation: Wayland driver does not support window positioning");
}
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
} else {
SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning");
}
/* Center on display yVariation, and check window properties */
@ -2029,11 +2159,19 @@ int video_setWindowCenteredOnDisplay(void *arg)
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
} else {
SDLTest_Log("Skipping display index validation: Wayland driver does not support window positioning");
}
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
if (!video_driver_is_wayland) {
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
} else {
SDLTest_Log("Skipping window position validation: Wayland driver does not support window positioning");
}
/* Clean up */
_destroyVideoSuiteTestWindow(window);
@ -2043,6 +2181,76 @@ int video_setWindowCenteredOnDisplay(void *arg)
return TEST_COMPLETED;
}
/**
* Tests window surface functionality
*/
static int video_getWindowSurface(void *arg)
{
const char *title = "video_getWindowSurface Test Window";
SDL_Window *window;
SDL_Surface *surface;
SDL_Renderer *renderer;
Uint32 renderer_flags = SDL_RENDERER_ACCELERATED;
int result;
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "dummy") == 0) {
renderer_flags = SDL_RENDERER_SOFTWARE;
}
/* Make sure we're testing interaction with an accelerated renderer */
SDL_SetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION, "1");
window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 320, 0);
SDLTest_AssertPass("Call to SDL_CreateWindow('%s', SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 320, 0)", title);
SDLTest_AssertCheck(window != NULL, "Validate that returned window is not NULL");
surface = SDL_GetWindowSurface(window);
SDLTest_AssertPass("Call to SDL_GetWindowSurface(window)");
SDLTest_AssertCheck(surface != NULL, "Validate that returned surface is not NULL");
SDLTest_AssertCheck(SDL_HasWindowSurface(window), "Validate that window has a surface");
result = SDL_UpdateWindowSurface(window);
SDLTest_AssertPass("Call to SDL_UpdateWindowSurface(window)");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
/* We shouldn't be able to create a renderer on a window with a surface */
renderer = SDL_CreateRenderer(window, -1, renderer_flags);
SDLTest_AssertPass("Call to SDL_CreateRenderer(window)");
SDLTest_AssertCheck(renderer == NULL, "Validate that returned renderer is NULL");
result = SDL_DestroyWindowSurface(window);
SDLTest_AssertPass("Call to SDL_DestroyWindowSurface(window)");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
SDLTest_AssertCheck(!SDL_HasWindowSurface(window), "Validate that window does not have a surface");
/* We should be able to create a renderer on the window now */
renderer = SDL_CreateRenderer(window, -1, renderer_flags);
SDLTest_AssertPass("Call to SDL_CreateRenderer(window)");
SDLTest_AssertCheck(renderer != NULL, "Validate that returned renderer is not NULL");
/* We should not be able to create a window surface now, unless it was created by the renderer */
if (!SDL_HasWindowSurface(window)) {
surface = SDL_GetWindowSurface(window);
SDLTest_AssertPass("Call to SDL_GetWindowSurface(window)");
SDLTest_AssertCheck(surface == NULL, "Validate that returned surface is NULL");
}
SDL_DestroyRenderer(renderer);
SDLTest_AssertPass("Call to SDL_DestroyRenderer(renderer)");
SDLTest_AssertCheck(!SDL_HasWindowSurface(window), "Validate that window does not have a surface");
/* We should be able to create a window surface again */
surface = SDL_GetWindowSurface(window);
SDLTest_AssertPass("Call to SDL_GetWindowSurface(window)");
SDLTest_AssertCheck(surface != NULL, "Validate that returned surface is not NULL");
SDLTest_AssertCheck(SDL_HasWindowSurface(window), "Validate that window has a surface");
/* Clean up */
SDL_DestroyWindow(window);
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Video test cases */
@ -2127,13 +2335,17 @@ static const SDLTest_TestCaseReference videoTest23 =
static const SDLTest_TestCaseReference videoTest24 =
{ (SDLTest_TestCaseFp) video_setWindowCenteredOnDisplay, "video_setWindowCenteredOnDisplay", "Checks using SDL_WINDOWPOS_CENTERED_DISPLAY centers the window on a display", TEST_ENABLED };
static const SDLTest_TestCaseReference videoTest25 = {
(SDLTest_TestCaseFp)video_getWindowSurface, "video_getWindowSurface", "Checks window surface functionality", TEST_ENABLED
};
/* Sequence of Video test cases */
static const SDLTest_TestCaseReference *videoTests[] = {
&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
&videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12,
&videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17,
&videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22,
&videoTest23, &videoTest24, NULL
&videoTest23, &videoTest24, &videoTest25, NULL
};
/* Video test suite (global) */

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -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;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -148,7 +148,7 @@ quit(int rc)
exit(rc);
}
void loop()
void loop(void)
{
int i;
SDL_Event event;
@ -242,7 +242,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
for (i = 1; i < argc;) {

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -13,6 +13,7 @@
/* Program to test querying of display info */
#include "SDL.h"
#include "SDL_test.h"
#include <stdio.h>
#include <stdlib.h>
@ -20,7 +21,7 @@
static void
print_mode(const char *prefix, const SDL_DisplayMode *mode)
{
if (mode == NULL) {
if (!mode) {
return;
}
@ -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;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -174,7 +174,7 @@ void DrawRects(SDL_Renderer *renderer)
}
}
void loop()
void loop(void)
{
Uint32 now;
int i;
@ -227,7 +227,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
for (i = 1; i < argc;) {

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -12,7 +12,10 @@
This file is created by : Nitin Jain (nitin.j4@samsung.com)
*/
/* Sample program: Draw a Chess Board by using SDL_CreateSoftwareRenderer API */
/* Sample program: Draw a Chess Board by using the SDL render API */
/* This allows testing SDL_CreateSoftwareRenderer with the window surface API. Undefine it to use the accelerated renderer instead. */
#define USE_SOFTWARE_RENDERER
#include <stdlib.h>
#include <stdio.h>
@ -25,10 +28,13 @@
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Surface *surface;
int done;
void DrawChessBoard()
#ifdef USE_SOFTWARE_RENDERER
SDL_Surface *surface;
#endif
void DrawChessBoard(void)
{
int row = 0, column = 0, x = 0;
SDL_Rect rect, darea;
@ -52,11 +58,12 @@ void DrawChessBoard()
}
}
void loop()
void loop(void)
{
SDL_Event e;
while (SDL_PollEvent(&e)) {
#ifdef USE_SOFTWARE_RENDERER
/* Re-create when window has been resized */
if ((e.type == SDL_WINDOWEVENT) && (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) {
@ -68,6 +75,7 @@ void loop()
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
}
#endif
if (e.type == SDL_QUIT) {
done = 1;
@ -86,11 +94,19 @@ void loop()
}
}
/* Clear the rendering surface with the specified color */
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
DrawChessBoard();
SDL_RenderPresent(renderer);
#ifdef USE_SOFTWARE_RENDERER
/* Got everything on rendering surface,
now Update the drawing image on window screen */
SDL_UpdateWindowSurface(window);
#endif
}
int main(int argc, char *argv[])
@ -106,21 +122,21 @@ int main(int argc, char *argv[])
/* Create window and renderer for given surface */
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE);
if (window == NULL) {
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n", SDL_GetError());
return 1;
}
#ifdef USE_SOFTWARE_RENDERER
surface = SDL_GetWindowSurface(window);
renderer = SDL_CreateSoftwareRenderer(surface);
if (renderer == NULL) {
#else
renderer = SDL_CreateRenderer(window, -1, 0);
#endif
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n", SDL_GetError());
return 1;
}
/* Clear the rendering surface with the specified color */
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
/* Draw the Image on rendering surface */
done = 0;
#ifdef __EMSCRIPTEN__

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -35,7 +35,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -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;
}
@ -65,7 +76,7 @@ int main(int argc, char *argv[])
alive = 1;
thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
if (thread == NULL) {
if (!thread) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(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;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 2020-2022 Collabora Ltd.
This software is provided 'as-is', without any express or implied
@ -18,7 +18,7 @@
static int run_test(void);
#if HAVE_LIBUDEV_H || defined(SDL_JOYSTICK_LINUX)
#if defined(HAVE_LIBUDEV_H) || defined(SDL_JOYSTICK_LINUX)
#include <stdint.h>

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -107,25 +107,25 @@ int main(int argc, char *argv[])
RWOP_ERR_QUIT(rwops);
}
rwops = SDL_RWFromFile(FBASENAME2, "wb");
if (rwops == NULL) {
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
unlink(FBASENAME2);
rwops = SDL_RWFromFile(FBASENAME2, "wb+");
if (rwops == NULL) {
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
unlink(FBASENAME2);
rwops = SDL_RWFromFile(FBASENAME2, "ab");
if (rwops == NULL) {
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
unlink(FBASENAME2);
rwops = SDL_RWFromFile(FBASENAME2, "ab+");
if (rwops == NULL) {
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
rwops->close(rwops);
@ -136,7 +136,7 @@ int main(int argc, char *argv[])
test : w mode, r mode, w+ mode
*/
rwops = SDL_RWFromFile(FBASENAME1, "wb"); /* write only */
if (rwops == NULL) {
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
@ -158,7 +158,7 @@ int main(int argc, char *argv[])
rwops->close(rwops);
rwops = SDL_RWFromFile(FBASENAME1, "rb"); /* read mode, file must exists */
if (rwops == NULL) {
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
if (0 != rwops->seek(rwops, 0L, RW_SEEK_SET)) {
@ -196,7 +196,7 @@ int main(int argc, char *argv[])
/* test 3: same with w+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "wb+"); /* write + read + truncation */
if (rwops == NULL) {
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
@ -247,7 +247,7 @@ int main(int argc, char *argv[])
/* test 4: same in r+ mode */
rwops = SDL_RWFromFile(FBASENAME1, "rb+"); /* write + read + file must exists, no truncation */
if (rwops == NULL) {
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {
@ -298,7 +298,7 @@ int main(int argc, char *argv[])
/* test5 : append mode */
rwops = SDL_RWFromFile(FBASENAME1, "ab+"); /* write + read + append */
if (rwops == NULL) {
if (!rwops) {
RWOP_ERR_QUIT(rwops);
}
if (1 != rwops->write(rwops, "1234567890", 10, 1)) {

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -13,22 +13,34 @@
#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;
}
base_path = SDL_GetBasePath();
if (base_path == NULL) {
if (!base_path) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find base path: %s\n",
SDL_GetError());
} else {
@ -37,7 +49,7 @@ int main(int argc, char *argv[])
}
pref_path = SDL_GetPrefPath("libsdl", "test_filesystem");
if (pref_path == NULL) {
if (!pref_path) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path: %s\n",
SDL_GetError());
} else {
@ -46,7 +58,7 @@ int main(int argc, char *argv[])
}
pref_path = SDL_GetPrefPath(NULL, "test_filesystem");
if (pref_path == NULL) {
if (!pref_path) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path without organization: %s\n",
SDL_GetError());
} else {
@ -54,6 +66,6 @@ int main(int argc, char *argv[])
SDL_free(pref_path);
}
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -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;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -107,9 +107,9 @@ static int virtual_axis_start_x;
static int virtual_axis_start_y;
static SDL_GameControllerButton virtual_button_active = SDL_CONTROLLER_BUTTON_INVALID;
static void UpdateWindowTitle()
static void UpdateWindowTitle(void)
{
if (window == NULL) {
if (!window) {
return;
}
@ -201,13 +201,13 @@ static void AddController(int device_index, SDL_bool verbose)
}
controller = SDL_GameControllerOpen(device_index);
if (controller == NULL) {
if (!controller) {
SDL_Log("Couldn't open controller: %s\n", SDL_GetError());
return;
}
controllers = (SDL_GameController **)SDL_realloc(gamecontrollers, (num_controllers + 1) * sizeof(*controllers));
if (controllers == NULL) {
if (!controllers) {
SDL_GameControllerClose(controller);
return;
}
@ -221,6 +221,7 @@ static void AddController(int device_index, SDL_bool verbose)
const char *name = SDL_GameControllerName(gamecontroller);
const char *path = SDL_GameControllerPath(gamecontroller);
SDL_Log("Opened game controller %s%s%s\n", name, path ? ", " : "", path ? path : "");
SDL_Log("Mapping: %s\n", SDL_GameControllerMapping(gamecontroller));
}
firmware_version = SDL_GameControllerGetFirmwareVersion(gamecontroller);
@ -328,7 +329,7 @@ typedef struct
Uint8 ucLedBlue; /* 46 */
} DS5EffectsState_t;
static void CyclePS5TriggerEffect()
static void CyclePS5TriggerEffect(void)
{
DS5EffectsState_t state;
@ -350,7 +351,7 @@ static void CyclePS5TriggerEffect()
SDL_GameControllerSendEffect(gamecontroller, &state, sizeof(state));
}
static SDL_bool ShowingFront()
static SDL_bool ShowingFront(void)
{
SDL_bool showing_front = SDL_TRUE;
int i;
@ -393,7 +394,7 @@ static int SDLCALL VirtualControllerSetLED(void *userdata, Uint8 red, Uint8 gree
return 0;
}
static void OpenVirtualController()
static void OpenVirtualController(void)
{
SDL_VirtualJoystickDesc desc;
int virtual_index;
@ -413,13 +414,13 @@ static void OpenVirtualController()
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
} else {
virtual_joystick = SDL_JoystickOpen(virtual_index);
if (virtual_joystick == NULL) {
if (!virtual_joystick) {
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
}
}
}
static void CloseVirtualController()
static void CloseVirtualController(void)
{
int i;
@ -624,7 +625,8 @@ void loop(void *arg)
if (event.type == SDL_CONTROLLERBUTTONDOWN) {
SetController(event.cbutton.which);
}
SDL_Log("Controller %" SDL_PRIs32 " button %s %s\n", event.cbutton.which, SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
SDL_Log("Controller %" SDL_PRIs32 " button %s %s\n", event.cbutton.which, SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button),
event.cbutton.state ? "pressed" : "released");
/* Cycle PS5 trigger effects when the microphone button is pressed */
if (event.type == SDL_CONTROLLERBUTTONDOWN &&
@ -896,13 +898,13 @@ int main(int argc, char *argv[])
window = SDL_CreateWindow("Game Controller Test", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
SCREEN_HEIGHT, 0);
if (window == NULL) {
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
return 2;
}
screen = SDL_CreateRenderer(window, -1, 0);
if (screen == NULL) {
if (!screen) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
SDL_DestroyWindow(window);
return 2;
@ -920,7 +922,7 @@ int main(int argc, char *argv[])
button_texture = LoadTexture(screen, "button.bmp", SDL_TRUE, NULL, NULL);
axis_texture = LoadTexture(screen, "axis.bmp", SDL_TRUE, NULL, NULL);
if (background_front == NULL || background_back == NULL || button_texture == NULL || axis_texture == NULL) {
if (!background_front || !background_back || !button_texture || !axis_texture) {
SDL_DestroyRenderer(screen);
SDL_DestroyWindow(window);
return 2;

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -62,7 +62,7 @@ int LoadSprite(const char *file)
return 0;
}
void loop()
void loop(void)
{
int i;
SDL_Event event;
@ -172,7 +172,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
for (i = 1; i < argc;) {
@ -216,7 +216,7 @@ int main(int argc, char *argv[])
/* Create the windows, initialize the renderers, and load the textures */
sprites =
(SDL_Texture **)SDL_malloc(state->num_windows * sizeof(*sprites));
if (sprites == NULL) {
if (!sprites) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -131,7 +131,7 @@ DrawScreen(SDL_Window *window)
SDL_Surface *screen = SDL_GetWindowSurface(window);
int i;
if (screen == NULL) {
if (!screen) {
return;
}
@ -251,7 +251,7 @@ loop(void)
break;
case SDL_DOLLARRECORD:
SDL_Log("Recorded gesture: %" SDL_PRIs64 "", event.dgesture.gestureId);
SDL_Log("Recorded gesture: %" SDL_PRIs64, event.dgesture.gestureId);
break;
}
}
@ -272,7 +272,7 @@ loop(void)
int main(int argc, char *argv[])
{
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -40,11 +40,11 @@ static GL_Context ctx;
static int LoadContext(GL_Context *data)
{
#if SDL_VIDEO_DRIVER_UIKIT
#ifdef SDL_VIDEO_DRIVER_UIKIT
#define __SDL_NOGETPROCADDR__
#elif SDL_VIDEO_DRIVER_ANDROID
#elif defined(SDL_VIDEO_DRIVER_ANDROID)
#define __SDL_NOGETPROCADDR__
#elif SDL_VIDEO_DRIVER_PANDORA
#elif defined(SDL_VIDEO_DRIVER_PANDORA)
#define __SDL_NOGETPROCADDR__
#endif
@ -78,7 +78,7 @@ quit(int rc)
}
static void
Render()
Render(void)
{
static float color[8][3] = {
{ 1.0, 1.0, 0.0 },
@ -205,6 +205,11 @@ Render()
ctx.glRotatef(5.0, 1.0, 1.0, 1.0);
}
static void LogSwapInterval(void)
{
SDL_Log("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
}
int main(int argc, char *argv[])
{
int fsaa, accel;
@ -226,7 +231,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
for (i = 1; i < argc;) {
@ -300,7 +305,9 @@ int main(int argc, char *argv[])
SDL_GetCurrentDisplayMode(0, &mode);
SDL_Log("Screen BPP : %" SDL_PRIu32 "\n", SDL_BITSPERPIXEL(mode.format));
SDL_Log("Swap Interval : %d\n", SDL_GL_GetSwapInterval());
LogSwapInterval();
SDL_GetWindowSize(state->windows[0], &dw, &dh);
SDL_Log("Window Size : %d,%d\n", dw, dh);
SDL_GL_GetDrawableSize(state->windows[0], &dw, &dh);
@ -408,6 +415,7 @@ int main(int argc, char *argv[])
SDL_GL_MakeCurrent(state->windows[i], context);
if (update_swap_interval) {
SDL_GL_SetSwapInterval(swap_interval);
LogSwapInterval();
}
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
ctx.glViewport(0, 0, w, h);

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -34,7 +34,7 @@ quit(int rc)
{
int i;
if (context != NULL) {
if (context) {
for (i = 0; i < state->num_windows; i++) {
if (context[i]) {
SDL_GL_DeleteContext(context[i]);
@ -49,7 +49,7 @@ quit(int rc)
}
static void
Render()
Render(void)
{
static GLubyte color[8][4] = { { 255, 0, 0, 0 },
{ 255, 0, 0, 255 },
@ -114,7 +114,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
for (i = 1; i < argc;) {
@ -169,7 +169,7 @@ int main(int argc, char *argv[])
}
context = (SDL_GLContext *)SDL_calloc(state->num_windows, sizeof(*context));
if (context == NULL) {
if (!context) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -65,11 +65,11 @@ static GLES2_Context ctx;
static int LoadContext(GLES2_Context *data)
{
#if SDL_VIDEO_DRIVER_UIKIT
#ifdef SDL_VIDEO_DRIVER_UIKIT
#define __SDL_NOGETPROCADDR__
#elif SDL_VIDEO_DRIVER_ANDROID
#elif defined(SDL_VIDEO_DRIVER_ANDROID)
#define __SDL_NOGETPROCADDR__
#elif SDL_VIDEO_DRIVER_PANDORA
#elif defined(SDL_VIDEO_DRIVER_PANDORA)
#define __SDL_NOGETPROCADDR__
#endif
@ -96,7 +96,7 @@ quit(int rc)
{
int i;
if (context != NULL) {
if (context) {
for (i = 0; i < state->num_windows; i++) {
if (context[i]) {
SDL_GL_DeleteContext(context[i]);
@ -569,7 +569,7 @@ render_thread_fn(void *render_ctx)
}
static void
loop_threaded()
loop_threaded(void)
{
SDL_Event event;
int i;
@ -598,7 +598,7 @@ loop_threaded()
#endif
static void
loop()
loop(void)
{
SDL_Event event;
int i;
@ -636,7 +636,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
for (i = 1; i < argc;) {
@ -696,7 +696,7 @@ int main(int argc, char *argv[])
}
context = (SDL_GLContext *)SDL_calloc(state->num_windows, sizeof(*context));
if (context == NULL) {
if (!context) {
SDL_Log("Out of memory!\n");
quit(2);
}
@ -893,9 +893,9 @@ int main(int argc, char *argv[])
SDL_Log("%2.2f frames per second\n",
((double)frames * 1000) / (now - then));
}
#if !defined(__ANDROID__) && !defined(__NACL__)
#if !defined(__ANDROID__) && !defined(__NACL__)
quit(0);
#endif
#endif
return 0;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -63,11 +63,11 @@ static GLES2_Context ctx;
static int LoadContext(GLES2_Context *data)
{
#if SDL_VIDEO_DRIVER_UIKIT
#ifdef SDL_VIDEO_DRIVER_UIKIT
#define __SDL_NOGETPROCADDR__
#elif SDL_VIDEO_DRIVER_ANDROID
#elif defined(SDL_VIDEO_DRIVER_ANDROID)
#define __SDL_NOGETPROCADDR__
#elif SDL_VIDEO_DRIVER_PANDORA
#elif defined(SDL_VIDEO_DRIVER_PANDORA)
#define __SDL_NOGETPROCADDR__
#endif
@ -94,7 +94,7 @@ quit(int rc)
{
int i;
if (context != NULL) {
if (context) {
for (i = 0; i < state->num_windows; i++) {
if (context[i]) {
SDL_GL_DeleteContext(context[i]);
@ -325,7 +325,7 @@ int done;
Uint32 frames;
shader_data *datas;
void loop()
void loop(void)
{
SDL_Event event;
int i;
@ -445,7 +445,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
for (i = 1; i < argc;) {
@ -502,7 +502,7 @@ int main(int argc, char *argv[])
}
context = (SDL_GLContext *)SDL_calloc(state->num_windows, sizeof(*context));
if (context == NULL) {
if (!context) {
SDL_Log("Out of memory!\n");
quit(2);
}
@ -543,17 +543,17 @@ int main(int argc, char *argv[])
#if 1
path = GetNearbyFilename(f);
if (path == NULL) {
if (!path) {
path = SDL_strdup(f);
}
if (path == NULL) {
if (!path) {
SDL_Log("out of memory\n");
exit(-1);
}
tmp = SDL_LoadBMP(path);
if (tmp == NULL) {
if (!tmp) {
SDL_Log("missing image file: %s", path);
exit(-1);
} else {

View file

@ -16,6 +16,8 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
*/
#include "SDL.h"
#include <stdlib.h>
#ifndef SDL_HAPTIC_DISABLED
static SDL_Haptic *haptic;
@ -69,7 +71,7 @@ int main(int argc, char **argv)
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) {
if (!name) {
i = (index != -1) ? index : 0;
}
/* Try to find matching device */
@ -88,7 +90,7 @@ int main(int argc, char **argv)
}
haptic = SDL_HapticOpen(i);
if (haptic == NULL) {
if (!haptic) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
SDL_GetError());
return 1;
@ -279,7 +281,7 @@ int main(int argc, char **argv)
}
/* Quit */
if (haptic != NULL) {
if (haptic) {
SDL_HapticClose(haptic);
}
SDL_Quit();

View file

@ -106,7 +106,7 @@ int main(int argc, char **argv)
if (e.key.keysym.sym == SDLK_ESCAPE) {
done = 1;
} else if (e.key.keysym.sym == SDLK_x) {
if (areas == NULL) {
if (!areas) {
areas = drag_areas;
numareas = SDL_arraysize(drag_areas);
} else {

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -68,7 +68,7 @@ int main(int argc, char *argv[])
keepGoing = SDL_FALSE;
break;
case SDL_JOYDEVICEADDED:
if (joystick != NULL) {
if (joystick) {
SDL_Log("Only one joystick supported by this test\n");
} else {
joystick = SDL_JoystickOpen(event.jdevice.which);

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -61,7 +61,7 @@ int main(int argc, char *argv[])
fname = GetResourceFilename(argc > 1 ? argv[1] : NULL, "utf8.txt");
file = fopen(fname, "rb");
if (file == NULL) {
if (!file) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", fname);
return 1;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -29,7 +29,7 @@
#ifdef HAVE_SDL_TTF
#ifdef __MACOSX__
#define DEFAULT_FONT "/System/Library/Fonts/华文细黑.ttf"
#elif __WIN32__
#elif defined(__WIN32__)
/* Some japanese font present on at least Windows 8.1. */
#define DEFAULT_FONT "C:\\Windows\\Fonts\\yugothic.ttf"
#else
@ -97,7 +97,7 @@ static Uint8 validate_hex(const char *cp, size_t len, Uint32 *np)
}
n = (n << 4) | c;
}
if (np != NULL) {
if (np) {
*np = n;
}
return 1;
@ -116,7 +116,7 @@ static int unifont_init(const char *fontname)
/* Allocate memory for the glyph data so the file can be closed after initialization. */
unifontGlyph = (struct UnifontGlyph *)SDL_malloc(unifontGlyphSize);
if (unifontGlyph == NULL) {
if (!unifontGlyph) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d KiB for glyph data.\n", (int)(unifontGlyphSize + 1023) / 1024);
return -1;
}
@ -124,20 +124,20 @@ static int unifont_init(const char *fontname)
/* Allocate memory for texture pointers for all renderers. */
unifontTexture = (SDL_Texture **)SDL_malloc(unifontTextureSize);
if (unifontTexture == NULL) {
if (!unifontTexture) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d KiB for texture pointer data.\n", (int)(unifontTextureSize + 1023) / 1024);
return -1;
}
SDL_memset(unifontTexture, 0, unifontTextureSize);
filename = GetResourceFilename(NULL, fontname);
if (filename == NULL) {
if (!filename) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory\n");
return -1;
}
hexFile = SDL_RWFromFile(filename, "rb");
SDL_free(filename);
if (hexFile == NULL) {
if (!hexFile) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to open font file: %s\n", fontname);
return -1;
}
@ -269,7 +269,7 @@ static int unifont_load_texture(Uint32 textureID)
}
textureRGBA = (Uint8 *)SDL_malloc(UNIFONT_TEXTURE_SIZE);
if (textureRGBA == NULL) {
if (!textureRGBA) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to allocate %d MiB for a texture.\n", UNIFONT_TEXTURE_SIZE / 1024 / 1024);
return -1;
}
@ -324,7 +324,7 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dst
}
}
texture = unifontTexture[UNIFONT_NUM_TEXTURES * rendererID + textureID];
if (texture != NULL) {
if (texture) {
const Uint32 cInTex = codepoint % UNIFONT_GLYPHS_IN_TEXTURE;
srcrect.x = cInTex % UNIFONT_GLYPHS_IN_ROW * 16;
srcrect.y = cInTex / UNIFONT_GLYPHS_IN_ROW * 16;
@ -333,17 +333,17 @@ static Sint32 unifont_draw_glyph(Uint32 codepoint, int rendererID, SDL_Rect *dst
return unifontGlyph[codepoint].width;
}
static void unifont_cleanup()
static void unifont_cleanup(void)
{
int i, j;
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
if (state->windows[i] == NULL || renderer == NULL) {
if (state->windows[i] == NULL || !renderer) {
continue;
}
for (j = 0; j < UNIFONT_NUM_TEXTURES; j++) {
SDL_Texture *tex = unifontTexture[UNIFONT_NUM_TEXTURES * i + j];
if (tex != NULL) {
if (tex) {
SDL_DestroyTexture(tex);
}
}
@ -425,12 +425,12 @@ Uint32 utf8_decode(char *p, size_t len)
return codepoint;
}
void usage()
void usage(void)
{
SDL_Log("usage: testime [--font fontfile]\n");
}
void InitInput()
void InitInput(void)
{
/* Prepare a rect for text input */
textRect.x = textRect.y = 100;
@ -444,7 +444,7 @@ void InitInput()
SDL_StartTextInput();
}
void CleanupVideo()
void CleanupVideo(void)
{
SDL_StopTextInput();
#ifdef HAVE_SDL_TTF
@ -530,7 +530,7 @@ void _Redraw(int rendererID)
if (cursor) {
char *p = utf8_advance(markedText, cursor);
char c = 0;
if (p == NULL) {
if (!p) {
p = &markedText[SDL_strlen(markedText)];
}
@ -597,7 +597,7 @@ void _Redraw(int rendererID)
SDL_SetTextInputRect(&markedRect);
}
void Redraw()
void Redraw(void)
{
int i;
for (i = 0; i < state->num_windows; ++i) {
@ -626,7 +626,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
for (i = 1; i < argc; i++) {
@ -660,7 +660,7 @@ int main(int argc, char *argv[])
TTF_Init();
font = TTF_OpenFont(fontname, DEFAULT_PTSIZE);
if (font == NULL) {
if (!font) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to find font: %s\n", TTF_GetError());
return -1;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -208,7 +208,7 @@ DrawRectRectIntersections(SDL_Renderer *renderer)
}
}
void loop()
void loop(void)
{
int i;
SDL_Event event;
@ -289,7 +289,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
for (i = 1; i < argc;) {

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -117,7 +117,7 @@ void loop(void *arg)
case SDL_JOYDEVICEADDED:
SDL_Log("Joystick device %d added.\n", (int)event.jdevice.which);
if (joystick == NULL) {
if (!joystick) {
joystick = SDL_JoystickOpen(event.jdevice.which);
if (joystick) {
PrintJoystick(joystick);
@ -296,13 +296,13 @@ int main(int argc, char *argv[])
window = SDL_CreateWindow("Joystick Test", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
SCREEN_HEIGHT, 0);
if (window == NULL) {
if (!window) {
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) {
if (!screen) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
SDL_DestroyWindow(window);
return SDL_FALSE;

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -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;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -53,13 +53,13 @@ int main(int argc, char *argv[])
}
lib = SDL_LoadObject(libname);
if (lib == NULL) {
if (!lib) {
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) {
if (!fn) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadFunction('%s') failed: %s\n",
symname, SDL_GetError());
retval = 4;

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -11,13 +11,14 @@
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
/* !!! FIXME: move this to the test framework */
static void log_locales(void)
{
SDL_Locale *locales = SDL_GetPreferredLocales();
if (locales == NULL) {
if (!locales) {
SDL_Log("Couldn't determine locales: %s", SDL_GetError());
} else {
SDL_Locale *l;
@ -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);
/* Print locales and languages */
if (SDL_Init(SDL_INIT_VIDEO) != -1) {
log_locales();
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
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();
}
}
SDL_Delay(10);
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);
return 1;
}
SDL_Quit();
i += consumed;
}
if (!SDLTest_CommonInit(state)) {
return 1;
}
/* Print locales and languages */
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);
}
}
SDLTest_CommonQuit(state);
return 0;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -106,7 +106,7 @@ int main(int argc, char *argv[])
SDL_AtomicSet(&doterminate, 0);
mutex = SDL_CreateMutex();
if (mutex == NULL) {
if (!mutex) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create mutex: %s\n", SDL_GetError());
exit(1);
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -18,7 +18,13 @@
#include <stdlib.h> /* exit() */
#ifdef __IPHONEOS__
#ifdef __3DS__
/* For mouse-based tests, we want to have the window on the touch screen */
#define SCREEN_X 40
#define SCREEN_Y 240
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#elif defined(__IPHONEOS__)
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 480
#else
@ -26,6 +32,13 @@
#define SCREEN_HEIGHT 480
#endif
#ifndef SCREEN_X
#define SCREEN_X SDL_WINDOWPOS_CENTERED
#endif
#ifndef SCREEN_Y
#define SCREEN_Y SDL_WINDOWPOS_CENTERED
#endif
static SDL_Window *window;
typedef struct _Object
@ -83,7 +96,7 @@ void DrawObject(SDL_Renderer *renderer, Object *object)
void DrawObjects(SDL_Renderer *renderer)
{
Object *next = objects;
while (next != NULL) {
while (next) {
DrawObject(renderer, next);
next = next->next;
}
@ -93,7 +106,7 @@ void AppendObject(Object *object)
{
if (objects) {
Object *next = objects;
while (next->next != NULL) {
while (next->next) {
next = next->next;
}
next->next = object;
@ -130,7 +143,7 @@ void loop(void *arg)
break;
case SDL_MOUSEMOTION:
if (active == NULL) {
if (!active) {
break;
}
@ -139,7 +152,7 @@ void loop(void *arg)
break;
case SDL_MOUSEBUTTONDOWN:
if (active == NULL) {
if (!active) {
active = SDL_calloc(1, sizeof(*active));
active->x1 = active->x2 = event.button.x;
active->y1 = active->y2 = event.button.y;
@ -173,7 +186,7 @@ void loop(void *arg)
break;
case SDL_MOUSEBUTTONUP:
if (active == NULL) {
if (!active) {
break;
}
@ -263,16 +276,14 @@ int main(int argc, char *argv[])
}
/* Create a window to display joystick axis position */
window = SDL_CreateWindow("Mouse Test", SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
SCREEN_HEIGHT, 0);
if (window == NULL) {
window = SDL_CreateWindow("Mouse Test", SCREEN_X, SCREEN_Y, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
return SDL_FALSE;
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
SDL_DestroyWindow(window);
return SDL_FALSE;

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -53,7 +53,7 @@ play_through_once(void *arg, Uint8 *stream, int len)
}
}
void loop()
void loop(void)
{
if (SDL_AtomicGet(&cbd[0].done)) {
#ifdef __EMSCRIPTEN__

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -47,7 +47,7 @@ static void
quit(int rc)
{
SDL_VideoQuit();
if (native_window != NULL && factory != NULL) {
if (native_window && factory) {
factory->DestroyNativeWindow(native_window);
}
exit(rc);
@ -119,19 +119,19 @@ int main(int argc, char *argv[])
break;
}
}
if (factory == NULL) {
if (!factory) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find native window code for %s driver\n",
driver);
quit(2);
}
SDL_Log("Creating native window for %s driver\n", driver);
native_window = factory->CreateNativeWindow(WINDOW_W, WINDOW_H);
if (native_window == NULL) {
if (!native_window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create native window\n");
quit(3);
}
window = SDL_CreateWindowFrom(native_window);
if (window == NULL) {
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window: %s\n", SDL_GetError());
quit(4);
}
@ -139,7 +139,7 @@ int main(int argc, char *argv[])
/* Create the renderer */
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
quit(5);
}
@ -149,7 +149,7 @@ int main(int argc, char *argv[])
SDL_RenderClear(renderer);
sprite = LoadTexture(renderer, "icon.bmp", SDL_TRUE, NULL, NULL);
if (sprite == NULL) {
if (!sprite) {
quit(6);
}
@ -158,7 +158,7 @@ int main(int argc, char *argv[])
SDL_QueryTexture(sprite, NULL, NULL, &sprite_w, &sprite_h);
positions = (SDL_Rect *)SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
velocities = (SDL_Rect *)SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
if (positions == NULL || velocities == NULL) {
if (!positions || !velocities) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -66,7 +66,7 @@ CreateWindowNative(int w, int h)
CreateWindow("SDL Test", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, w, h, NULL, NULL, GetModuleHandle(NULL),
NULL);
if (hwnd == NULL) {
if (!hwnd) {
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -32,7 +32,7 @@ static int width = 640;
static int height = 480;
static unsigned int max_frames = 200;
void draw()
void draw(void)
{
SDL_Rect Rect;
@ -50,7 +50,7 @@ void draw()
SDL_RenderPresent(renderer);
}
void save_surface_to_bmp()
void save_surface_to_bmp(void)
{
SDL_Surface *surface;
Uint32 r_mask, g_mask, b_mask, a_mask;
@ -71,7 +71,7 @@ void save_surface_to_bmp()
SDL_FreeSurface(surface);
}
void loop()
void loop(void)
{
SDL_Event event;
@ -115,14 +115,14 @@ int main(int argc, char *argv[])
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
width, height, 0);
if (window == NULL) {
if (!window) {
SDL_Log("Couldn't create window: %s\n", SDL_GetError());
return SDL_FALSE;
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
if (!renderer) {
SDL_Log("Couldn't create renderer: %s\n",
SDL_GetError());
return SDL_FALSE;

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -178,7 +178,7 @@ PrintUsage(char *argv0)
SDL_Log("\n");
}
void loop()
void loop(void)
{
SDL_Event event;
@ -311,21 +311,21 @@ int main(int argc, char **argv)
}
RawMooseData = (Uint8 *)SDL_malloc(MOOSEFRAME_SIZE * MOOSEFRAMES_COUNT);
if (RawMooseData == NULL) {
if (!RawMooseData) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't allocate memory for movie !\n");
quit(1);
}
/* load the trojan moose images */
filename = GetResourceFilename(NULL, "moose.dat");
if (filename == NULL) {
if (!filename) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory\n");
SDL_free(RawMooseData);
return -1;
}
handle = SDL_RWFromFile(filename, "rb");
SDL_free(filename);
if (handle == NULL) {
if (!handle) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
SDL_free(RawMooseData);
quit(2);
@ -343,21 +343,21 @@ int main(int argc, char **argv)
SDL_WINDOWPOS_UNDEFINED,
window_w, window_h,
SDL_WINDOW_RESIZABLE);
if (window == NULL) {
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create window: %s\n", SDL_GetError());
SDL_free(RawMooseData);
quit(4);
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create renderer: %s\n", SDL_GetError());
SDL_free(RawMooseData);
quit(4);
}
MooseTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, MOOSEPIC_W, MOOSEPIC_H);
if (MooseTexture == NULL) {
if (!MooseTexture) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
SDL_free(RawMooseData);
quit(5);

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -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
@ -284,7 +285,7 @@ static LL_Test LL_Tests[] = {
{ "_allmul", &TST_allmul, 0x0000000080000000ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFF00000000ll },
{ "_allmul", &TST_allmul, 0xFFFFFFFFFFFFFFFEll, 0x0000000080000008ll, 0, 0xFFFFFFFEFFFFFFF0ll },
{ "_allmul", &TST_allmul, 0x0000000080000008ll, 0xFFFFFFFFFFFFFFFEll, 0, 0xFFFFFFFEFFFFFFF0ll },
{ "_allmul", &TST_allmul, 0x00000000FFFFFFFFll, 0x00000000FFFFFFFFll, 0, 0xFFFFFFFE00000001ll },
/* UNDEFINED { "_allmul", &TST_allmul, 0x00000000FFFFFFFFll, 0x00000000FFFFFFFFll, 0, 0xFFFFFFFE00000001ll }, */
{ "_alldiv", &TST_alldiv, 0x0000000000000000ll, 0x0000000000000001ll, 0, 0x0000000000000000ll },
{ "_alldiv", &TST_alldiv, 0x0000000000000000ll, 0xFFFFFFFFFFFFFFFFll, 0, 0x0000000000000000ll },
@ -366,7 +367,7 @@ int Test64Bit(SDL_bool verbose)
LL_Test *t;
int failed = 0;
for (t = LL_Tests; t->routine != NULL; t++) {
for (t = LL_Tests; t->routine; t++) {
unsigned long long result = 0;
unsigned int *al = (unsigned int *)&t->a;
unsigned int *bl = (unsigned int *)&t->b;
@ -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);
return 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;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -13,6 +13,7 @@
#include <stdio.h>
#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;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -43,36 +43,73 @@ 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);
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 (!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");
if (consumed <= 0) {
static const char *options[] = { "[SEED]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
return 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;
for (i = 0; i < arraylen; i++) {
nums[i] = i;
@ -96,6 +133,8 @@ int main(int argc, char *argv[])
test_sort("random sorted", nums, arraylen);
}
SDLTest_CommonQuit(state);
return 0;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -35,7 +35,7 @@ DrawRects(SDL_Renderer *renderer)
}
static void
loop()
loop(void)
{
/* Check for events */
while (SDL_PollEvent(&event)) {
@ -91,7 +91,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
for (i = 1; i < argc; ++i) {

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -87,7 +87,7 @@ void Draw(DrawState *s)
/* SDL_Delay(10); */
}
void loop()
void loop(void)
{
int i;
SDL_Event event;
@ -121,7 +121,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -138,7 +138,7 @@ 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 == NULL) {
if (!target) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create render target texture: %s\n", SDL_GetError());
return SDL_FALSE;
}
@ -173,7 +173,7 @@ Draw(DrawState *s)
return SDL_TRUE;
}
void loop()
void loop(void)
{
int i;
SDL_Event event;
@ -214,7 +214,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
for (i = 1; i < argc;) {

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -57,7 +57,7 @@ int main(int argc, char **argv)
cvt.len = len;
cvt.buf = (Uint8 *)SDL_malloc((size_t)len * cvt.len_mult);
if (cvt.buf == NULL) {
if (!cvt.buf) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory.\n");
SDL_FreeWAV(data);
SDL_Quit();
@ -75,7 +75,7 @@ int main(int argc, char **argv)
/* write out a WAV header... */
io = SDL_RWFromFile(argv[2], "wb");
if (io == NULL) {
if (!io) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "fopen('%s') failed: %s\n", argv[2], SDL_GetError());
SDL_free(cvt.buf);
SDL_FreeWAV(data);

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -71,7 +71,7 @@ int main(int argc, char **argv)
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) {
if (!name) {
i = (index != -1) ? index : 0;
}
/* Try to find matching device */
@ -90,7 +90,7 @@ int main(int argc, char **argv)
}
haptic = SDL_HapticOpen(i);
if (haptic == NULL) {
if (!haptic) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n",
SDL_GetError());
return 1;
@ -129,7 +129,7 @@ int main(int argc, char **argv)
SDL_Delay(2000);
/* Quit */
if (haptic != NULL) {
if (haptic) {
SDL_HapticClose(haptic);
}
SDL_Quit();

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -78,7 +78,7 @@ void Draw(DrawState *s)
SDL_RenderPresent(s->renderer);
}
void loop()
void loop(void)
{
int i;
SDL_Event event;
@ -111,7 +111,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -36,7 +36,7 @@ static const char *GetSensorTypeString(SDL_SensorType type)
static void HandleSensorEvent(SDL_SensorEvent *event)
{
SDL_Sensor *sensor = SDL_SensorFromInstanceID(event->which);
if (sensor == NULL) {
if (!sensor) {
SDL_Log("Couldn't get sensor for sensor event\n");
return;
}
@ -78,7 +78,7 @@ int main(int argc, char **argv)
if (SDL_SensorGetDeviceType(i) != SDL_SENSOR_UNKNOWN) {
SDL_Sensor *sensor = SDL_SensorOpen(i);
if (sensor == NULL) {
if (!sensor) {
SDL_Log("Couldn't open sensor %" SDL_PRIs32 ": %s\n", SDL_SensorGetDeviceInstanceID(i), SDL_GetError());
} else {
++num_opened;

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -11,6 +11,7 @@
*/
/* This is a simple example of using GLSL shaders with SDL */
#include <stdlib.h>
#include "SDL.h"
#ifdef HAVE_OPENGL
@ -109,36 +110,36 @@ static ShaderData shaders[NUM_SHADERS] = {
"}" },
};
static PFNGLATTACHOBJECTARBPROC glAttachObjectARB;
static PFNGLCOMPILESHADERARBPROC glCompileShaderARB;
static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;
static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;
static PFNGLDELETEOBJECTARBPROC glDeleteObjectARB;
static PFNGLGETINFOLOGARBPROC glGetInfoLogARB;
static PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB;
static PFNGLLINKPROGRAMARBPROC glLinkProgramARB;
static PFNGLSHADERSOURCEARBPROC glShaderSourceARB;
static PFNGLUNIFORM1IARBPROC glUniform1iARB;
static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
static PFNGLATTACHOBJECTARBPROC pglAttachObjectARB;
static PFNGLCOMPILESHADERARBPROC pglCompileShaderARB;
static PFNGLCREATEPROGRAMOBJECTARBPROC pglCreateProgramObjectARB;
static PFNGLCREATESHADEROBJECTARBPROC pglCreateShaderObjectARB;
static PFNGLDELETEOBJECTARBPROC pglDeleteObjectARB;
static PFNGLGETINFOLOGARBPROC pglGetInfoLogARB;
static PFNGLGETOBJECTPARAMETERIVARBPROC pglGetObjectParameterivARB;
static PFNGLGETUNIFORMLOCATIONARBPROC pglGetUniformLocationARB;
static PFNGLLINKPROGRAMARBPROC pglLinkProgramARB;
static PFNGLSHADERSOURCEARBPROC pglShaderSourceARB;
static PFNGLUNIFORM1IARBPROC pglUniform1iARB;
static PFNGLUSEPROGRAMOBJECTARBPROC pglUseProgramObjectARB;
static SDL_bool CompileShader(GLhandleARB shader, const char *source)
{
GLint status = 0;
glShaderSourceARB(shader, 1, &source, NULL);
glCompileShaderARB(shader);
glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
pglShaderSourceARB(shader, 1, &source, NULL);
pglCompileShaderARB(shader);
pglGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
if (status == 0) {
GLint length = 0;
char *info;
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
pglGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = (char *)SDL_malloc((size_t)length + 1);
if (info == NULL) {
if (!info) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
} else {
glGetInfoLogARB(shader, length, NULL, info);
pglGetInfoLogARB(shader, length, NULL, info);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info);
SDL_free(info);
}
@ -152,21 +153,21 @@ static SDL_bool LinkProgram(ShaderData *data)
{
GLint status = 0;
glAttachObjectARB(data->program, data->vert_shader);
glAttachObjectARB(data->program, data->frag_shader);
glLinkProgramARB(data->program);
pglAttachObjectARB(data->program, data->vert_shader);
pglAttachObjectARB(data->program, data->frag_shader);
pglLinkProgramARB(data->program);
glGetObjectParameterivARB(data->program, GL_OBJECT_LINK_STATUS_ARB, &status);
pglGetObjectParameterivARB(data->program, GL_OBJECT_LINK_STATUS_ARB, &status);
if (status == 0) {
GLint length = 0;
char *info;
glGetObjectParameterivARB(data->program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
pglGetObjectParameterivARB(data->program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = (char *)SDL_malloc((size_t)length + 1);
if (info == NULL) {
if (!info) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
} else {
glGetInfoLogARB(data->program, length, NULL, info);
pglGetInfoLogARB(data->program, length, NULL, info);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to link program:\n%s", info);
SDL_free(info);
}
@ -185,16 +186,16 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
glGetError();
/* Create one program object to rule them all */
data->program = glCreateProgramObjectARB();
data->program = pglCreateProgramObjectARB();
/* Create the vertex shader */
data->vert_shader = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
data->vert_shader = pglCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
if (!CompileShader(data->vert_shader, data->vert_source)) {
return SDL_FALSE;
}
/* Create the fragment shader */
data->frag_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
data->frag_shader = pglCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
if (!CompileShader(data->frag_shader, data->frag_source)) {
return SDL_FALSE;
}
@ -205,16 +206,16 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
}
/* Set up some uniform variables */
glUseProgramObjectARB(data->program);
pglUseProgramObjectARB(data->program);
for (i = 0; i < num_tmus_bound; ++i) {
char tex_name[5];
(void)SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i);
location = glGetUniformLocationARB(data->program, tex_name);
location = pglGetUniformLocationARB(data->program, tex_name);
if (location >= 0) {
glUniform1iARB(location, i);
pglUniform1iARB(location, i);
}
}
glUseProgramObjectARB(0);
pglUseProgramObjectARB(0);
return (glGetError() == GL_NO_ERROR) ? SDL_TRUE : SDL_FALSE;
}
@ -222,13 +223,13 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
static void DestroyShaderProgram(ShaderData *data)
{
if (shaders_supported) {
glDeleteObjectARB(data->vert_shader);
glDeleteObjectARB(data->frag_shader);
glDeleteObjectARB(data->program);
pglDeleteObjectARB(data->vert_shader);
pglDeleteObjectARB(data->frag_shader);
pglDeleteObjectARB(data->program);
}
}
static SDL_bool InitShaders()
static SDL_bool InitShaders(void)
{
int i;
@ -238,30 +239,30 @@ static SDL_bool InitShaders()
SDL_GL_ExtensionSupported("GL_ARB_shading_language_100") &&
SDL_GL_ExtensionSupported("GL_ARB_vertex_shader") &&
SDL_GL_ExtensionSupported("GL_ARB_fragment_shader")) {
glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)SDL_GL_GetProcAddress("glAttachObjectARB");
glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)SDL_GL_GetProcAddress("glCompileShaderARB");
glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glCreateProgramObjectARB");
glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)SDL_GL_GetProcAddress("glCreateShaderObjectARB");
glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)SDL_GL_GetProcAddress("glDeleteObjectARB");
glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)SDL_GL_GetProcAddress("glGetInfoLogARB");
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)SDL_GL_GetProcAddress("glGetObjectParameterivARB");
glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)SDL_GL_GetProcAddress("glGetUniformLocationARB");
glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)SDL_GL_GetProcAddress("glLinkProgramARB");
glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)SDL_GL_GetProcAddress("glShaderSourceARB");
glUniform1iARB = (PFNGLUNIFORM1IARBPROC)SDL_GL_GetProcAddress("glUniform1iARB");
glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glUseProgramObjectARB");
if (glAttachObjectARB &&
glCompileShaderARB &&
glCreateProgramObjectARB &&
glCreateShaderObjectARB &&
glDeleteObjectARB &&
glGetInfoLogARB &&
glGetObjectParameterivARB &&
glGetUniformLocationARB &&
glLinkProgramARB &&
glShaderSourceARB &&
glUniform1iARB &&
glUseProgramObjectARB) {
pglAttachObjectARB = (PFNGLATTACHOBJECTARBPROC)SDL_GL_GetProcAddress("glAttachObjectARB");
pglCompileShaderARB = (PFNGLCOMPILESHADERARBPROC)SDL_GL_GetProcAddress("glCompileShaderARB");
pglCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glCreateProgramObjectARB");
pglCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC)SDL_GL_GetProcAddress("glCreateShaderObjectARB");
pglDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC)SDL_GL_GetProcAddress("glDeleteObjectARB");
pglGetInfoLogARB = (PFNGLGETINFOLOGARBPROC)SDL_GL_GetProcAddress("glGetInfoLogARB");
pglGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC)SDL_GL_GetProcAddress("glGetObjectParameterivARB");
pglGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC)SDL_GL_GetProcAddress("glGetUniformLocationARB");
pglLinkProgramARB = (PFNGLLINKPROGRAMARBPROC)SDL_GL_GetProcAddress("glLinkProgramARB");
pglShaderSourceARB = (PFNGLSHADERSOURCEARBPROC)SDL_GL_GetProcAddress("glShaderSourceARB");
pglUniform1iARB = (PFNGLUNIFORM1IARBPROC)SDL_GL_GetProcAddress("glUniform1iARB");
pglUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)SDL_GL_GetProcAddress("glUseProgramObjectARB");
if (pglAttachObjectARB &&
pglCompileShaderARB &&
pglCreateProgramObjectARB &&
pglCreateShaderObjectARB &&
pglDeleteObjectARB &&
pglGetInfoLogARB &&
pglGetObjectParameterivARB &&
pglGetUniformLocationARB &&
pglLinkProgramARB &&
pglShaderSourceARB &&
pglUniform1iARB &&
pglUseProgramObjectARB) {
shaders_supported = SDL_TRUE;
}
}
@ -282,7 +283,7 @@ static SDL_bool InitShaders()
return SDL_TRUE;
}
static void QuitShaders()
static void QuitShaders(void)
{
int i;
@ -329,7 +330,7 @@ SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord)
0x00FF0000, 0x0000FF00, 0x000000FF
#endif
);
if (image == NULL) {
if (!image) {
return 0;
}
@ -420,7 +421,7 @@ void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat *texcoord)
glBindTexture(GL_TEXTURE_2D, texture);
glColor3f(1.0f, 1.0f, 1.0f);
if (shaders_supported) {
glUseProgramObjectARB(shaders[current_shader].program);
pglUseProgramObjectARB(shaders[current_shader].program);
}
glBegin(GL_QUADS); /* start drawing a polygon (4 sided) */
@ -435,7 +436,7 @@ void DrawGLScene(SDL_Window *window, GLuint texture, GLfloat *texcoord)
glEnd(); /* done with the polygon */
if (shaders_supported) {
glUseProgramObjectARB(0);
pglUseProgramObjectARB(0);
}
glDisable(GL_TEXTURE_2D);
@ -462,7 +463,7 @@ int main(int argc, char **argv)
/* Create a 640x480 OpenGL screen */
window = SDL_CreateWindow("Shader Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL);
if (window == NULL) {
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create OpenGL window: %s\n", SDL_GetError());
SDL_Quit();
exit(2);
@ -475,7 +476,7 @@ int main(int argc, char **argv)
}
surface = SDL_LoadBMP("icon.bmp");
if (surface == NULL) {
if (!surface) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to load icon.bmp: %s\n", SDL_GetError());
SDL_Quit();
exit(3);

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -71,7 +71,7 @@ int main(int argc, char **argv)
num_pictures = argc - 1;
pictures = (LoadedPicture *)SDL_malloc(sizeof(LoadedPicture) * num_pictures);
if (pictures == NULL) {
if (!pictures) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not allocate memory.");
exit(1);
}
@ -106,7 +106,7 @@ int main(int argc, char **argv)
SHAPED_WINDOW_DIMENSION, SHAPED_WINDOW_DIMENSION,
0);
SDL_SetWindowPosition(window, SHAPED_WINDOW_X, SHAPED_WINDOW_Y);
if (window == NULL) {
if (!window) {
for (i = 0; i < num_pictures; i++) {
SDL_FreeSurface(pictures[i].surface);
}
@ -116,7 +116,7 @@ int main(int argc, char **argv)
exit(-4);
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
if (!renderer) {
SDL_DestroyWindow(window);
for (i = 0; i < num_pictures; i++) {
SDL_FreeSurface(pictures[i].surface);

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -392,22 +392,30 @@ void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
SDL_RenderPresent(renderer);
}
void loop()
static void MoveAllSprites(void)
{
Uint32 now;
int i;
SDL_Event event;
/* Check for events */
while (SDL_PollEvent(&event)) {
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]);
}
}
void loop(void)
{
Uint32 now;
SDL_Event event;
/* Check for events */
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
}
MoveAllSprites();
#ifdef __EMSCRIPTEN__
if (done) {
emscripten_cancel_main_loop();
@ -426,6 +434,14 @@ void loop()
}
}
static int SDLCALL ExposeEventWatcher(void *userdata, SDL_Event *event)
{
if (event->type == SDL_WINDOWEVENT && event->window.event == SDL_WINDOWEVENT_EXPOSED) {
MoveAllSprites();
}
return 0;
}
int main(int argc, char *argv[])
{
int i;
@ -437,7 +453,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
@ -525,7 +541,7 @@ int main(int argc, char *argv[])
/* Create the windows, initialize the renderers, and load the textures */
sprites =
(SDL_Texture **)SDL_malloc(state->num_windows * sizeof(*sprites));
if (sprites == NULL) {
if (!sprites) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);
}
@ -541,7 +557,7 @@ int main(int argc, char *argv[])
/* Allocate memory for the sprite info */
positions = (SDL_Rect *)SDL_malloc(num_sprites * sizeof(SDL_Rect));
velocities = (SDL_Rect *)SDL_malloc(num_sprites * sizeof(SDL_Rect));
if (positions == NULL || velocities == NULL) {
if (!positions || !velocities) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
quit(2);
}
@ -568,6 +584,9 @@ int main(int argc, char *argv[])
}
}
/* Add an event watcher to redraw from within modal window resize/move loops */
SDL_AddEventWatch(ExposeEventWatcher, NULL);
/* Main render loop */
frames = 0;
next_fps_check = SDL_GetTicks() + fps_check_delay;

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -43,7 +43,7 @@ quit(int rc)
exit(rc);
}
void MoveSprites()
void MoveSprites(void)
{
int i;
int window_w = WINDOW_WIDTH;
@ -77,7 +77,7 @@ void MoveSprites()
SDL_RenderPresent(renderer);
}
void loop()
void loop(void)
{
SDL_Event event;
@ -109,7 +109,7 @@ int main(int argc, char *argv[])
sprite = LoadTexture(renderer, "icon.bmp", SDL_TRUE, &sprite_w, &sprite_h);
if (sprite == NULL) {
if (!sprite) {
quit(2);
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -94,7 +94,7 @@ void UpdateTexture(SDL_Texture *texture)
SDL_UnlockTexture(texture);
}
void loop()
void loop(void)
{
SDL_Event event;
@ -141,13 +141,13 @@ int main(int argc, char **argv)
/* load the moose images */
filename = GetResourceFilename(NULL, "moose.dat");
if (filename == NULL) {
if (!filename) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory\n");
return -1;
}
handle = SDL_RWFromFile(filename, "rb");
SDL_free(filename);
if (handle == NULL) {
if (!handle) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
quit(2);
}
@ -160,19 +160,19 @@ int main(int argc, char **argv)
SDL_WINDOWPOS_UNDEFINED,
MOOSEPIC_W * 4, MOOSEPIC_H * 4,
SDL_WINDOW_RESIZABLE);
if (window == NULL) {
if (!window) {
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 == NULL) {
if (!renderer) {
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 == NULL) {
if (!MooseTexture) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set create texture: %s\n", SDL_GetError());
quit(5);
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -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;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -17,15 +17,19 @@
#include <signal.h>
#include "SDL.h"
#include "SDL_test.h"
static SDL_TLSID tls;
static int alive = 0;
static SDL_Thread *thread = NULL;
static SDL_atomic_t alive;
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);
}
@ -55,7 +59,7 @@ 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) {
while (SDL_AtomicGet(&alive)) {
SDL_Log("Thread '%s' is alive!\n", (char *)data);
if (testprio) {
@ -76,20 +80,45 @@ killed(int sig)
{
SDL_Log("Killed with SIGTERM, waiting 5 seconds to exit\n");
SDL_Delay(5 * 1000);
alive = 0;
SDL_AtomicSet(&alive, 0);
SDL_WaitThread(thread, NULL);
quit(0);
}
int main(int argc, char *argv[])
{
int arg = 1;
SDL_Thread *thread;
int i;
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,40 +129,33 @@ 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);
SDL_Log("Main thread data initially: %s\n", (const char *)SDL_TLSGet(tls));
alive = 1;
SDL_AtomicSet(&alive, 1);
thread = SDL_CreateThread(ThreadFunc, "One", "#1");
if (thread == NULL) {
if (!thread) {
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_AtomicSet(&alive, 0);
SDL_WaitThread(thread, NULL);
SDL_Log("Main thread data finally: %s\n", (const char *)SDL_TLSGet(tls));
alive = 1;
SDL_AtomicSet(&alive, 1);
(void)signal(SIGTERM, killed);
thread = SDL_CreateThread(ThreadFunc, "Two", "#2");
if (thread == NULL) {
if (!thread) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(1);
}
(void)raise(SIGTERM);
SDL_Quit(); /* Never reached */
SDLTest_CommonQuit(state); /* Never reached */
return 0; /* Never reached */
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -18,9 +18,38 @@
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
#define DEFAULT_RESOLUTION 1
static int test_sdl_delay_within_bounds(void) {
const int testDelay = 100;
const int marginOfError = 25;
Uint64 result;
Uint64 result2;
Sint64 difference;
SDLTest_ResetAssertSummary();
/* Get ticks count - should be non-zero by now */
result = SDL_GetTicks();
SDLTest_AssertPass("Call to SDL_GetTicks()");
SDLTest_AssertCheck(result > 0, "Check result value, expected: >0, got: %" SDL_PRIu64, result);
/* Delay a bit longer and measure ticks and verify difference */
SDL_Delay(testDelay);
SDLTest_AssertPass("Call to SDL_Delay(%d)", testDelay);
result2 = SDL_GetTicks();
SDLTest_AssertPass("Call to SDL_GetTicks()");
SDLTest_AssertCheck(result2 > 0, "Check result value, expected: >0, got: %" SDL_PRIu64, result2);
difference = result2 - result;
SDLTest_AssertCheck(difference > (testDelay - marginOfError), "Check difference, expected: >%d, got: %" SDL_PRIu64, testDelay - marginOfError, difference);
/* Disabled because this might fail on non-interactive systems. */
SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%d, got: %" SDL_PRIu64, testDelay + marginOfError, difference);
return SDLTest_AssertSummaryToTestResult() == TEST_RESULT_PASSED ? 0 : 1;
}
static int ticks = 0;
static Uint32 SDLCALL
@ -33,22 +62,61 @@ ticktock(Uint32 interval, void *param)
static Uint32 SDLCALL
callback(Uint32 interval, void *param)
{
SDL_Log("Timer %" SDL_PRIu32 " : param = %d\n", interval, (int)(uintptr_t)param);
int value = (int)(uintptr_t)param;
SDL_assert( value == 1 || value == 2 || value == 3 );
SDL_Log("Timer %" SDL_PRIu32 " : param = %d\n", interval, value);
return interval;
}
int main(int argc, char *argv[])
{
int i, desired;
int i;
int desired = -1;
SDL_TimerID t1, t2, t3;
Uint64 start64, now64;
Uint32 start32, now32;
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);
if (SDL_Init(SDL_INIT_TIMER) < 0) {
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (!consumed) {
if (SDL_strcmp("--interactive", argv[i]) == 0) {
run_interactive_tests = SDL_TRUE;
consumed = 1;
} else if (desired < 0) {
char *endptr;
desired = SDL_strtoul(argv[i], &endptr, 0);
if (desired != 0 && endptr != argv[i] && *endptr == '\0') {
consumed = 1;
}
}
}
if (consumed <= 0) {
static const char *options[] = { "[--interactive]", "[interval]", 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;
}
@ -74,14 +142,11 @@ int main(int argc, char *argv[])
}
}
/* Start the timer */
desired = 0;
if (argv[1]) {
desired = SDL_atoi(argv[1]);
}
if (desired == 0) {
if (desired < 0) {
desired = DEFAULT_RESOLUTION;
}
/* Start the timer */
t1 = SDL_AddTimer(desired, ticktock, NULL);
/* Wait 10 seconds */
@ -102,14 +167,17 @@ int main(int argc, char *argv[])
t1 = SDL_AddTimer(100, callback, (void *)1);
if (!t1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 1: %s\n", SDL_GetError());
return_code = 1;
}
t2 = SDL_AddTimer(50, callback, (void *)2);
if (!t2) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 2: %s\n", SDL_GetError());
return_code = 1;
}
t3 = SDL_AddTimer(233, callback, (void *)3);
if (!t3) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create timer 3: %s\n", SDL_GetError());
return_code = 1;
}
/* Wait 10 seconds */
@ -141,8 +209,11 @@ int main(int argc, char *argv[])
now32 = SDL_GetTicks();
SDL_Log("Delay 1 second = %d ms in ticks, %d ms in ticks64, %f ms according to performance counter\n", (int)(now32 - start32), (int)(now64 - start64), (double)((now - start) * 1000) / SDL_GetPerformanceFrequency());
SDL_Quit();
return 0;
if (run_interactive_tests) {
return_code |= test_sdl_delay_within_bounds();
}
SDLTest_CommonQuit(state);
return return_code;
}
/* vi: set ts=4 sw=4 expandtab: */

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright 2022 Collabora Ltd.
This software is provided 'as-is', without any express or implied
@ -28,13 +28,13 @@ GetNearbyFilename(const char *file)
base = SDL_GetBasePath();
if (base != NULL) {
if (base) {
SDL_RWops *rw;
size_t len = SDL_strlen(base) + SDL_strlen(file) + 1;
path = SDL_malloc(len);
if (path == NULL) {
if (!path) {
SDL_free(base);
SDL_OutOfMemory();
return NULL;
@ -54,7 +54,7 @@ GetNearbyFilename(const char *file)
}
path = SDL_strdup(file);
if (path == NULL) {
if (!path) {
SDL_OutOfMemory();
}
return path;
@ -72,10 +72,10 @@ GetNearbyFilename(const char *file)
char *
GetResourceFilename(const char *user_specified, const char *def)
{
if (user_specified != NULL) {
if (user_specified) {
char *ret = SDL_strdup(user_specified);
if (ret == NULL) {
if (!ret) {
SDL_OutOfMemory();
}
@ -105,12 +105,12 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent,
path = GetNearbyFilename(file);
if (path != NULL) {
if (path) {
file = path;
}
temp = SDL_LoadBMP(file);
if (temp == NULL) {
if (!temp) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
} else {
/* Set transparent pixel as the pixel at (0,0) */
@ -137,16 +137,16 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent,
}
}
if (width_out != NULL) {
if (width_out) {
*width_out = temp->w;
}
if (height_out != NULL) {
if (height_out) {
*height_out = temp->h;
}
texture = SDL_CreateTextureFromSurface(renderer, temp);
if (texture == NULL) {
if (!texture) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
}
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
Copyright 2022 Collabora Ltd.
This software is provided 'as-is', without any express or implied

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -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;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -95,7 +95,7 @@ void DrawOnViewport(SDL_Renderer *renderer)
SDL_RenderSetClipRect(renderer, NULL);
}
void loop()
void loop(void)
{
SDL_Event event;
int i;
@ -152,7 +152,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
@ -180,7 +180,7 @@ int main(int argc, char *argv[])
sprite = LoadTexture(state->renderers[0], "icon.bmp", SDL_TRUE, &sprite_w, &sprite_h);
if (sprite == NULL) {
if (!sprite) {
quit(2);
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -236,7 +236,7 @@ static void createInstance(void)
quit(2);
}
extensions = (const char **)SDL_malloc(sizeof(const char *) * extensionCount);
if (extensions == NULL) {
if (!extensions) {
SDL_OutOfMemory();
quit(2);
}
@ -312,7 +312,7 @@ static void findPhysicalDevice(void)
quit(2);
}
physicalDevices = (VkPhysicalDevice *)SDL_malloc(sizeof(VkPhysicalDevice) * physicalDeviceCount);
if (physicalDevices == NULL) {
if (!physicalDevices) {
SDL_OutOfMemory();
quit(2);
}
@ -346,7 +346,7 @@ static void findPhysicalDevice(void)
SDL_free(queueFamiliesProperties);
queueFamiliesPropertiesAllocatedSize = queueFamiliesCount;
queueFamiliesProperties = (VkQueueFamilyProperties *)SDL_malloc(sizeof(VkQueueFamilyProperties) * queueFamiliesPropertiesAllocatedSize);
if (queueFamiliesProperties == NULL) {
if (!queueFamiliesProperties) {
SDL_free(physicalDevices);
SDL_free(deviceExtensions);
SDL_OutOfMemory();
@ -408,7 +408,7 @@ static void findPhysicalDevice(void)
SDL_free(deviceExtensions);
deviceExtensionsAllocatedSize = deviceExtensionCount;
deviceExtensions = SDL_malloc(sizeof(VkExtensionProperties) * deviceExtensionsAllocatedSize);
if (deviceExtensions == NULL) {
if (!deviceExtensions) {
SDL_free(physicalDevices);
SDL_free(queueFamiliesProperties);
SDL_OutOfMemory();
@ -929,7 +929,7 @@ static void initVulkan(void)
SDL_Vulkan_LoadLibrary(NULL);
vulkanContexts = (VulkanContext *)SDL_calloc(state->num_windows, sizeof(VulkanContext));
if (vulkanContexts == NULL) {
if (!vulkanContexts) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
quit(2);
}
@ -1092,7 +1092,7 @@ int main(int argc, char **argv)
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -143,7 +143,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_Rect viewport)
}
}
void loop()
void loop(void)
{
int i;
SDL_Event event;
@ -208,7 +208,7 @@ void loop()
}
if (event.type == SDL_MOUSEBUTTONUP) {
SDL_Window *window = SDL_GetMouseFocus();
if (highlighted_mode != -1 && window != NULL) {
if (highlighted_mode != -1 && window) {
const int display_index = SDL_GetWindowDisplayIndex(window);
SDL_DisplayMode mode;
if (0 != SDL_GetDisplayMode(display_index, highlighted_mode, &mode)) {
@ -223,7 +223,7 @@ void loop()
for (i = 0; i < state->num_windows; ++i) {
SDL_Window *window = state->windows[i];
SDL_Renderer *renderer = state->renderers[i];
if (window != NULL && renderer != NULL) {
if (window && renderer) {
int y = 0;
SDL_Rect viewport, menurect;
@ -262,7 +262,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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
@ -75,7 +75,7 @@ static SDL_bool verify_yuv_data(Uint32 format, const Uint8 *yuv, int yuv_pitch,
SDL_bool result = SDL_FALSE;
rgb = (Uint8 *)SDL_malloc(size);
if (rgb == NULL) {
if (!rgb) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory");
return SDL_FALSE;
}
@ -126,7 +126,7 @@ static int run_automated_tests(int pattern_size, int extra_pitch)
int yuv1_pitch, yuv2_pitch;
int result = -1;
if (pattern == NULL || yuv1 == NULL || yuv2 == NULL) {
if (!pattern || !yuv1 || !yuv2) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't allocate test surfaces");
goto done;
}
@ -327,7 +327,7 @@ int main(int argc, char **argv)
filename = "testyuv.bmp";
}
original = SDL_ConvertSurfaceFormat(SDL_LoadBMP(filename), SDL_PIXELFORMAT_RGB24, 0);
if (original == NULL) {
if (!original) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
return 3;
}
@ -339,7 +339,7 @@ int main(int argc, char **argv)
pitch = CalculateYUVPitch(yuv_format, original->w);
converted = SDL_CreateRGBSurfaceWithFormat(0, original->w, original->h, 0, rgb_format);
if (converted == NULL) {
if (!converted) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create converted surface: %s\n", SDL_GetError());
return 3;
}
@ -356,13 +356,13 @@ int main(int argc, char **argv)
SDL_WINDOWPOS_UNDEFINED,
original->w, original->h,
0);
if (window == NULL) {
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
return 4;
}
renderer = SDL_CreateRenderer(window, -1, 0);
if (renderer == NULL) {
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
return 4;
}

View file

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2025 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

Some files were not shown because too many files have changed in this diff Show more