Merge commit '852f2a6343518919e5ca8d3c1bbcab9f493e3cd8'

This commit is contained in:
2024-01-17 17:02:59 +01:00
1244 changed files with 50102 additions and 28146 deletions

View File

@ -1,6 +1,9 @@
#
# CMake script for building the SDL tests
#
include(CheckStructHasMember)
if(SDL_TESTS_LINK_SHARED)
set(sdl_name_component SDL3-shared)
else()
@ -29,11 +32,35 @@ add_library(sdltests_utils OBJECT
target_link_libraries(sdltests_utils PRIVATE SDL3::Headers)
file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
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_FILE_NAMES)
foreach(RESOURCE_FILE IN LISTS RESOURCE_FILES)
get_filename_component(res_file_name ${RESOURCE_FILE} NAME)
set(RESOURCE_FILES_BINDIR)
foreach(resource_file IN LISTS RESOURCE_FILES)
get_filename_component(res_file_name ${resource_file} NAME)
list(APPEND RESOURCE_FILE_NAMES "${res_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}"
)
define_property(TARGET PROPERTY SDL_NONINTERACTIVE BRIEF_DOCS "If true, target is a non-interactive test executable." FULL_DOCS "If true, target is a noninteractive test executable.")
define_property(TARGET PROPERTY SDL_NONINTERACTIVE_ARGUMENTS BRIEF_DOCS "Argument(s) to run executable in non-interactive mode." FULL_DOCS "Argument(s) to run executable in non-interactive mode.")
@ -44,11 +71,16 @@ if(WINDOWS_STORE)
target_link_libraries(sdl_test_main_uwp PRIVATE SDL3::Headers)
target_compile_options(sdl_test_main_uwp PRIVATE "/ZW")
add_library(sdl_test_main_callbacks_uwp OBJECT main.cpp)
target_link_libraries(sdl_test_main_callbacks_uwp PRIVATE SDL3::Headers)
target_compile_options(sdl_test_main_callbacks_uwp PRIVATE "/ZW")
target_compile_definitions(sdl_test_main_callbacks_uwp PRIVATE "SDL_MAIN_USE_CALLBACKS")
set_source_files_properties(${RESOURCE_FILES} PROPERTIES VS_DEPLOYENT_LOCATION "Assets")
endif()
macro(add_sdl_test_executable TARGET)
cmake_parse_arguments(AST "BUILD_DEPENDENT;NONINTERACTIVE;NEEDS_RESOURCES;TESTUTILS;NO_C90" "" "NONINTERACTIVE_TIMEOUT;NONINTERACTIVE_ARGS;SOURCES" ${ARGN})
cmake_parse_arguments(AST "BUILD_DEPENDENT;NONINTERACTIVE;NEEDS_RESOURCES;TESTUTILS;NO_C90;MAIN_CALLBACKS" "" "NONINTERACTIVE_TIMEOUT;NONINTERACTIVE_ARGS;SOURCES" ${ARGN})
if(AST_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown argument(s): ${AST_UNPARSED_ARGUMENTS}")
endif()
@ -70,8 +102,14 @@ macro(add_sdl_test_executable TARGET)
TARGET "${TARGET}"
)
set_property(SOURCE "${uwp_bindir}/${TARGET}.appxmanifest" PROPERTY VS_DEPLOYMENT_CONTENT 1)
if(AST_MAIN_CALLBACKS)
list(APPEND EXTRA_SOURCES "$<TARGET_OBJECTS:sdl_test_main_callbacks_uwp>")
else()
list(APPEND EXTRA_SOURCES "$<TARGET_OBJECTS:sdl_test_main_uwp>")
endif()
list(APPEND EXTRA_SOURCES
"$<TARGET_OBJECTS:sdl_test_main_uwp>"
"${uwp_bindir}/${TARGET}.appxmanifest"
"uwp/logo-50x50.png"
"uwp/square-44x44.png"
@ -120,8 +158,7 @@ macro(add_sdl_test_executable TARGET)
)
add_dependencies(${TARGET} zzz-resources-copy-${TARGET})
else()
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILES} $<TARGET_FILE_DIR:${TARGET}>)
add_dependencies(${TARGET} copy-sdl-test-resources)
endif()
if(APPLE)
# Make sure resource files get installed into macOS/iOS .app bundles.
@ -182,19 +219,45 @@ if(HAVE_LIBUDEV_H)
add_definitions(-DHAVE_LIBUDEV_H)
endif()
set(FFmpeg_FIND_COMPONENTS AVCODEC AVFORMAT AVUTIL SWSCALE)
include("${SDL3_SOURCE_DIR}/cmake/FindFFmpeg.cmake")
if(FFmpeg_FOUND)
cmake_push_check_state()
list(APPEND CMAKE_REQUIRED_INCLUDES "${FFmpeg_AVUTIL_INCLUDE_DIRS}")
check_struct_has_member("AVFrame" "ch_layout" "libavutil/frame.h" LIBAVUTIL_AVFRAME_HAS_CH_LAYOUT)
cmake_pop_check_state()
endif()
if(FFmpeg_FOUND AND LIBAVUTIL_AVFRAME_HAS_CH_LAYOUT)
add_sdl_test_executable(testffmpeg NO_C90 SOURCES testffmpeg.c ${icon_bmp_header})
if(APPLE)
target_sources(testffmpeg PRIVATE testffmpeg_videotoolbox.m)
target_link_options(testffmpeg PRIVATE "-Wl,-framework,CoreFoundation" "-Wl,-framework,CoreVideo" "-Wl,-framework,Metal")
endif()
if(HAVE_OPENGLES_V2)
message(DEBUG "Enabling EGL support in testffmpeg")
target_compile_definitions(testffmpeg PRIVATE HAVE_EGL)
if(TARGET OpenGL::EGL)
target_link_libraries(testffmpeg PRIVATE OpenGL::EGL)
endif()
endif()
target_link_libraries(testffmpeg PRIVATE ${FFMPEG_LIBRARIES})
else()
message(STATUS "Can't find ffmpeg 5.1.3 or newer, skipping testffmpeg")
endif()
add_sdl_test_executable(checkkeys SOURCES checkkeys.c)
add_sdl_test_executable(checkkeysthreads SOURCES checkkeysthreads.c)
add_sdl_test_executable(loopwave NEEDS_RESOURCES TESTUTILS SOURCES loopwave.c)
add_sdl_test_executable(loopwave NEEDS_RESOURCES TESTUTILS MAIN_CALLBACKS SOURCES loopwave.c)
add_sdl_test_executable(testsurround SOURCES testsurround.c)
add_sdl_test_executable(testresample NEEDS_RESOURCES SOURCES testresample.c)
add_sdl_test_executable(testaudioinfo SOURCES testaudioinfo.c)
add_sdl_test_executable(testaudiostreamdynamicresample NEEDS_RESOURCES TESTUTILS SOURCES testaudiostreamdynamicresample.c)
file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
add_sdl_test_executable(testautomation NEEDS_RESOURCES NO_C90 SOURCES ${TESTAUTOMATION_SOURCE_FILES})
add_sdl_test_executable(testautomation NONINTERACTIVE NONINTERACTIVE_TIMEOUT 120 NEEDS_RESOURCES NO_C90 SOURCES ${TESTAUTOMATION_SOURCE_FILES})
add_sdl_test_executable(testmultiaudio NEEDS_RESOURCES TESTUTILS SOURCES testmultiaudio.c)
add_sdl_test_executable(testaudiohotplug NEEDS_RESOURCES TESTUTILS SOURCES testaudiohotplug.c)
add_sdl_test_executable(testaudiocapture SOURCES testaudiocapture.c)
add_sdl_test_executable(testaudiocapture MAIN_CALLBACKS SOURCES testaudiocapture.c)
add_sdl_test_executable(testatomic NONINTERACTIVE SOURCES testatomic.c)
add_sdl_test_executable(testintersections SOURCES testintersections.c)
add_sdl_test_executable(testrelative SOURCES testrelative.c)
@ -225,9 +288,20 @@ if(APPLE)
endif()
elseif(WINDOWS)
add_sdl_test_executable(testnative BUILD_DEPENDENT NEEDS_RESOURCES TESTUTILS SOURCES testnative.c testnativew32.c)
elseif(HAVE_X11)
add_sdl_test_executable(testnative BUILD_DEPENDENT NEEDS_RESOURCES TESTUTILS SOURCES testnative.c testnativex11.c)
target_link_libraries(testnative PRIVATE X11)
elseif(HAVE_X11 OR HAVE_WAYLAND)
add_sdl_test_executable(testnative BUILD_DEPENDENT NO_C90 NEEDS_RESOURCES TESTUTILS SOURCES testnative.c)
if(HAVE_X11)
target_sources(testnative PRIVATE testnativex11.c)
target_link_libraries(testnative PRIVATE X11)
endif()
if(HAVE_WAYLAND)
set_property(SOURCE ${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c PROPERTY GENERATED 1)
target_sources(testnative PRIVATE testnativewayland.c ${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c)
# Needed to silence the documentation warning in the generated header file
target_compile_options(testnative PRIVATE -Wno-documentation-unknown-command)
target_link_libraries(testnative PRIVATE wayland-client)
endif ()
endif()
find_package(Python3)
@ -275,7 +349,7 @@ files2headers(gamepad_image_headers
)
files2headers(icon_bmp_header icon.bmp)
add_sdl_test_executable(testaudio NEEDS_RESOURCES TESTUTILS SOURCES testaudio.c)
add_sdl_test_executable(testaudio MAIN_CALLBACKS NEEDS_RESOURCES TESTUTILS SOURCES testaudio.c)
add_sdl_test_executable(testfile NONINTERACTIVE SOURCES testfile.c)
add_sdl_test_executable(testcontroller TESTUTILS SOURCES testcontroller.c gamepadutils.c ${gamepad_image_headers})
add_sdl_test_executable(testgeometry TESTUTILS SOURCES testgeometry.c)
@ -288,6 +362,7 @@ add_sdl_test_executable(testgles2 SOURCES testgles2.c)
add_sdl_test_executable(testgles2_sdf NEEDS_RESOURCES TESTUTILS SOURCES testgles2_sdf.c)
add_sdl_test_executable(testhaptic SOURCES testhaptic.c)
add_sdl_test_executable(testhotplug SOURCES testhotplug.c)
add_sdl_test_executable(testpen SOURCES testpen.c)
add_sdl_test_executable(testrumble SOURCES testrumble.c)
add_sdl_test_executable(testthread NONINTERACTIVE NONINTERACTIVE_TIMEOUT 40 SOURCES testthread.c)
add_sdl_test_executable(testiconv NEEDS_RESOURCES TESTUTILS SOURCES testiconv.c)
@ -304,7 +379,7 @@ add_sdl_test_executable(testplatform NONINTERACTIVE SOURCES testplatform.c)
add_sdl_test_executable(testpower NONINTERACTIVE SOURCES testpower.c)
add_sdl_test_executable(testfilesystem NONINTERACTIVE SOURCES testfilesystem.c)
if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
add_sdl_test_executable(testfilesystem_pre SOURCES testfilesystem_pre.c NONINTERACTIVE NONINTERACTIVE_TIMEOUT 60)
add_sdl_test_executable(pretest SOURCES pretest.c NONINTERACTIVE NONINTERACTIVE_TIMEOUT 60)
endif()
add_sdl_test_executable(testrendertarget NEEDS_RESOURCES TESTUTILS SOURCES testrendertarget.c)
add_sdl_test_executable(testscale NEEDS_RESOURCES TESTUTILS SOURCES testscale.c)
@ -312,12 +387,14 @@ add_sdl_test_executable(testsem NONINTERACTIVE NONINTERACTIVE_ARGS 10 NONINTERAC
add_sdl_test_executable(testsensor SOURCES testsensor.c)
add_sdl_test_executable(testshader NEEDS_RESOURCES TESTUTILS SOURCES testshader.c)
add_sdl_test_executable(testshape NEEDS_RESOURCES SOURCES testshape.c)
add_sdl_test_executable(testsprite NEEDS_RESOURCES TESTUTILS SOURCES testsprite.c)
add_sdl_test_executable(testsprite MAIN_CALLBACKS NEEDS_RESOURCES TESTUTILS SOURCES testsprite.c)
add_sdl_test_executable(testspriteminimal SOURCES testspriteminimal.c ${icon_bmp_header})
add_sdl_test_executable(teststreaming NEEDS_RESOURCES TESTUTILS SOURCES teststreaming.c)
add_sdl_test_executable(testtimer NONINTERACTIVE NONINTERACTIVE_TIMEOUT 60 SOURCES testtimer.c)
add_sdl_test_executable(testtimer NONINTERACTIVE NONINTERACTIVE_ARGS --no-interactive NONINTERACTIVE_TIMEOUT 60 SOURCES testtimer.c)
add_sdl_test_executable(testurl SOURCES testurl.c)
add_sdl_test_executable(testver NONINTERACTIVE SOURCES testver.c)
add_sdl_test_executable(testvideocapture SOURCES testvideocapture.c)
add_sdl_test_executable(testvideocaptureminimal SOURCES testvideocaptureminimal.c)
add_sdl_test_executable(testviewport NEEDS_RESOURCES TESTUTILS SOURCES testviewport.c)
add_sdl_test_executable(testwm SOURCES testwm.c)
add_sdl_test_executable(testyuv NONINTERACTIVE NONINTERACTIVE_ARGS "--automated" NEEDS_RESOURCES TESTUTILS SOURCES testyuv.c testyuv_cvt.c)
@ -332,6 +409,15 @@ add_sdl_test_executable(testvulkan NO_C90 SOURCES testvulkan.c)
add_sdl_test_executable(testoffscreen SOURCES testoffscreen.c)
add_sdl_test_executable(testpopup SOURCES testpopup.c)
if (HAVE_WAYLAND)
# Set the GENERATED property on the protocol file, since it is first created at build time
set_property(SOURCE ${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c PROPERTY GENERATED 1)
add_sdl_test_executable(testwaylandcustom NO_C90 NEEDS_RESOURCES SOURCES testwaylandcustom.c ${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c)
# Needed to silence the documentation warning in the generated header file
target_compile_options(testwaylandcustom PRIVATE -Wno-documentation-unknown-command)
target_link_libraries(testwaylandcustom PRIVATE wayland-client)
endif()
check_c_compiler_flag(-Wformat-overflow HAVE_WFORMAT_OVERFLOW)
if(HAVE_WFORMAT_OVERFLOW)
target_compile_definitions(testautomation PRIVATE HAVE_WFORMAT_OVERFLOW)
@ -511,13 +597,12 @@ foreach(TEST ${SDL_TEST_EXECUTABLES})
DESTINATION ${CMAKE_INSTALL_DATADIR}/installed-tests/SDL3
)
endif()
if(TARGET pretest AND NOT "${TEST}" MATCHES "pretest")
set_property(TEST ${TEST} APPEND PROPERTY DEPENDS pretest)
endif()
endif()
endforeach()
if(TARGET testfilesystem_pre)
set_property(TEST testfilesystem APPEND PROPERTY DEPENDS testfilesystem_pre)
endif()
if(SDL_INSTALL_TESTS)
if(RISCOS)
install(
@ -530,13 +615,18 @@ if(SDL_INSTALL_TESTS)
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3
)
endif()
if(MSVC)
foreach(test IN LISTS SDL_TEST_EXECUTABLES)
SDL_install_pdb(${test} "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3")
endforeach()
endif()
install(
FILES ${RESOURCE_FILES}
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL3
)
endif()
if(ANDROID AND TARGET SDL3-jar)
if(ANDROID AND TARGET SDL3::Jar)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../cmake/android")
find_package(SdlAndroid MODULE)
if(SdlAndroid_FOUND)
@ -593,14 +683,14 @@ if(ANDROID AND TARGET SDL3-jar)
COMMAND ${CMAKE_COMMAND} -E make_directory "${classes_path}"
COMMAND ${Java_JAVAC_EXECUTABLE}
-source 1.8 -target 1.8
-bootclasspath "$<TARGET_PROPERTY:SDL3-jar,OUTPUT>"
-bootclasspath "$<TARGET_PROPERTY:SDL3::Jar,JAR_FILE>"
"${JAVA_PACKAGE_DIR}/SDLEntryTestActivity.java"
"${JAVA_PACKAGE_DIR}/SDLTestActivity.java"
$<TARGET_PROPERTY:${TEST}-apk-linked,JAVA_R>
-cp "$<TARGET_PROPERTY:SDL3-jar,OUTPUT>:${path_android_jar}"
-cp "$<TARGET_PROPERTY:SDL3::Jar,JAR_FILE>:${SDL_ANDROID_PLATFORM_ANDROID_JAR}"
-d "${classes_path}"
COMMAND ${Java_JAR_EXECUTABLE} cf "${OUT_JAR}" -C "${classes_path}" .
DEPENDS $<TARGET_PROPERTY:${TEST}-apk-linked,OUTPUTS> "$<TARGET_PROPERTY:SDL3-jar,OUTPUT>" "${JAVA_PACKAGE_DIR}/SDLTestActivity.java" "${JAVA_PACKAGE_DIR}/SDLEntryTestActivity.java"
DEPENDS $<TARGET_PROPERTY:${TEST}-apk-linked,OUTPUTS> "$<TARGET_PROPERTY:SDL3::Jar,JAR_FILE>" "${JAVA_PACKAGE_DIR}/SDLTestActivity.java" "${JAVA_PACKAGE_DIR}/SDLEntryTestActivity.java"
)
add_custom_target(${TEST}-jar DEPENDS "${OUT_JAR}")
set_property(TARGET ${TEST}-jar PROPERTY OUTPUT "${OUT_JAR}")
@ -616,10 +706,10 @@ if(ANDROID AND TARGET SDL3-jar)
OUTPUT "${classes_dex}"
COMMAND SdlAndroid::d8
$<TARGET_PROPERTY:${TEST}-jar,OUTPUT>
$<TARGET_PROPERTY:SDL3-jar,OUTPUT>
--lib "${path_android_jar}"
$<TARGET_PROPERTY:SDL3::Jar,JAR_FILE>
--lib "${SDL_ANDROID_PLATFORM_ANDROID_JAR}"
--output "${dexworkdir}"
DEPENDS $<TARGET_PROPERTY:${TEST}-jar,OUTPUT> $<TARGET_PROPERTY:SDL3-jar,OUTPUT>
DEPENDS $<TARGET_PROPERTY:${TEST}-jar,OUTPUT> $<TARGET_PROPERTY:SDL3::Jar,JAR_FILE>
)
add_custom_target(${TEST}-dex DEPENDS "${classes_dex}")
set_property(TARGET ${TEST}-dex PROPERTY OUTPUT "${classes_dex}")

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -165,7 +165,7 @@ static void loop(void)
switch (event.type) {
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED), (event.key.repeat > 0));
if (event.type == SDL_EVENT_KEY_DOWN) {
switch (event.key.keysym.sym) {
case SDLK_BACKSPACE:
@ -182,10 +182,6 @@ static void loop(void)
case SDL_EVENT_TEXT_EDITING:
PrintText("EDIT", event.edit.text);
break;
case SDL_EVENT_TEXT_EDITING_EXT:
PrintText("EDIT_EXT", event.editExt.text);
SDL_free(event.editExt.text);
break;
case SDL_EVENT_TEXT_INPUT:
PrintText("INPUT", event.text.text);
SDLTest_TextWindowAddText(textwin, "%s", event.text.text);
@ -245,7 +241,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
state->window_title = "CheckKeys Test";
@ -261,9 +257,6 @@ int main(int argc, char *argv[])
/* Disable mouse emulation */
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
/* Enable extended text editing events */
SDL_SetHint(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT, "1");
/* Initialize SDL */
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -179,7 +179,7 @@ static void loop(void)
switch (event.type) {
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED), (event.key.repeat > 0));
break;
case SDL_EVENT_TEXT_EDITING:
PrintText("EDIT", event.text.text);
@ -247,7 +247,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
if (state == NULL) {
if (!state) {
return 1;
}
@ -267,7 +267,7 @@ int main(int argc, char *argv[])
/* Set 640x480 video mode */
window = SDL_CreateWindow("CheckKeys Test", 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);

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -38,10 +38,10 @@ static const struct
int x;
int y;
} button_positions[] = {
{ 413, 190 }, /* SDL_GAMEPAD_BUTTON_A */
{ 456, 156 }, /* SDL_GAMEPAD_BUTTON_B */
{ 372, 159 }, /* SDL_GAMEPAD_BUTTON_X */
{ 415, 127 }, /* SDL_GAMEPAD_BUTTON_Y */
{ 413, 190 }, /* SDL_GAMEPAD_BUTTON_SOUTH */
{ 456, 156 }, /* SDL_GAMEPAD_BUTTON_EAST */
{ 372, 159 }, /* SDL_GAMEPAD_BUTTON_WEST */
{ 415, 127 }, /* SDL_GAMEPAD_BUTTON_NORTH */
{ 199, 157 }, /* SDL_GAMEPAD_BUTTON_BACK */
{ 257, 153 }, /* SDL_GAMEPAD_BUTTON_GUIDE */
{ 314, 157 }, /* SDL_GAMEPAD_BUTTON_START */
@ -120,7 +120,7 @@ struct GamepadImage
int y;
SDL_bool showing_front;
SDL_bool showing_touchpad;
GamepadImageFaceStyle face_style;
SDL_GamepadType type;
ControllerDisplayMode display_mode;
SDL_bool elements[SDL_GAMEPAD_ELEMENT_MAX];
@ -146,29 +146,6 @@ static SDL_Texture *CreateTexture(SDL_Renderer *renderer, unsigned char *data, u
return texture;
}
static SDL_GamepadButton GetRemappedButton(GamepadImageFaceStyle face_style, SDL_GamepadButton button)
{
if (face_style == GAMEPAD_IMAGE_FACE_BAYX) {
switch (button) {
case SDL_GAMEPAD_BUTTON_A:
button = SDL_GAMEPAD_BUTTON_B;
break;
case SDL_GAMEPAD_BUTTON_B:
button = SDL_GAMEPAD_BUTTON_A;
break;
case SDL_GAMEPAD_BUTTON_X:
button = SDL_GAMEPAD_BUTTON_Y;
break;
case SDL_GAMEPAD_BUTTON_Y:
button = SDL_GAMEPAD_BUTTON_X;
break;
default:
break;
}
}
return button;
}
GamepadImage *CreateGamepadImage(SDL_Renderer *renderer)
{
GamepadImage *ctx = SDL_calloc(1, sizeof(*ctx));
@ -241,22 +218,22 @@ void SetGamepadImageShowingFront(GamepadImage *ctx, SDL_bool showing_front)
ctx->showing_front = showing_front;
}
void SetGamepadImageFaceStyle(GamepadImage *ctx, GamepadImageFaceStyle face_style)
void SetGamepadImageFaceButtonType(GamepadImage *ctx, SDL_GamepadType type)
{
if (!ctx) {
return;
}
ctx->face_style = face_style;
ctx->type = type;
}
GamepadImageFaceStyle GetGamepadImageFaceStyle(GamepadImage *ctx)
SDL_GamepadType GetGamepadImageType(GamepadImage *ctx)
{
if (!ctx) {
return GAMEPAD_IMAGE_FACE_BLANK;
return SDL_GAMEPAD_TYPE_UNKNOWN;
}
return ctx->face_style;
return ctx->type;
}
void SetGamepadImageDisplayMode(GamepadImage *ctx, ControllerDisplayMode display_mode)
@ -407,7 +384,7 @@ int GetGamepadImageElementAt(GamepadImage *ctx, float x, float y)
rect.w = (float)ctx->button_width;
rect.h = (float)ctx->button_height;
if (SDL_PointInRectFloat(&point, &rect)) {
return GetRemappedButton(ctx->face_style, (SDL_GamepadButton)i);
return (SDL_GamepadButton)i;
}
}
}
@ -440,29 +417,15 @@ void UpdateGamepadImageFromGamepad(GamepadImage *ctx, SDL_Gamepad *gamepad)
return;
}
ctx->type = SDL_GetGamepadType(gamepad);
char *mapping = SDL_GetGamepadMapping(gamepad);
SDL_GamepadType gamepad_type = SDL_GetGamepadType(gamepad);
switch (gamepad_type) {
case SDL_GAMEPAD_TYPE_PS3:
case SDL_GAMEPAD_TYPE_PS4:
case SDL_GAMEPAD_TYPE_PS5:
ctx->face_style = GAMEPAD_IMAGE_FACE_SONY;
break;
case SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO:
case SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT:
case SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT:
case SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR:
ctx->face_style = GAMEPAD_IMAGE_FACE_BAYX;
break;
default:
if (mapping && SDL_strstr(mapping, "SDL_GAMECONTROLLER_USE_BUTTON_LABELS")) {
ctx->face_style = GAMEPAD_IMAGE_FACE_BAYX;
} else {
ctx->face_style = GAMEPAD_IMAGE_FACE_ABXY;
if (mapping) {
if (SDL_strstr(mapping, "SDL_GAMECONTROLLER_USE_BUTTON_LABELS")) {
/* Just for display purposes */
ctx->type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO;
}
break;
SDL_free(mapping);
}
SDL_free(mapping);
for (i = 0; i < SDL_GAMEPAD_BUTTON_TOUCHPAD; ++i) {
const SDL_GamepadButton button = (SDL_GamepadButton)i;
@ -557,7 +520,7 @@ void RenderGamepadImage(GamepadImage *ctx)
for (i = 0; i < SDL_arraysize(button_positions); ++i) {
if (ctx->elements[i]) {
SDL_GamepadButton button_position = GetRemappedButton(ctx->face_style, (SDL_GamepadButton)i);
SDL_GamepadButton button_position = (SDL_GamepadButton)i;
SDL_bool on_front = SDL_TRUE;
if (i >= SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1 && i <= SDL_GAMEPAD_BUTTON_LEFT_PADDLE2) {
@ -579,14 +542,14 @@ void RenderGamepadImage(GamepadImage *ctx)
dst.w = (float)ctx->face_width;
dst.h = (float)ctx->face_height;
switch (ctx->face_style) {
case GAMEPAD_IMAGE_FACE_ABXY:
switch (SDL_GetGamepadButtonLabelForType(ctx->type, SDL_GAMEPAD_BUTTON_SOUTH)) {
case SDL_GAMEPAD_BUTTON_LABEL_A:
SDL_RenderTexture(ctx->renderer, ctx->face_abxy_texture, NULL, &dst);
break;
case GAMEPAD_IMAGE_FACE_BAYX:
case SDL_GAMEPAD_BUTTON_LABEL_B:
SDL_RenderTexture(ctx->renderer, ctx->face_bayx_texture, NULL, &dst);
break;
case GAMEPAD_IMAGE_FACE_SONY:
case SDL_GAMEPAD_BUTTON_LABEL_CROSS:
SDL_RenderTexture(ctx->renderer, ctx->face_sony_texture, NULL, &dst);
break;
default:
@ -665,10 +628,10 @@ void DestroyGamepadImage(GamepadImage *ctx)
static const char *gamepad_button_names[] = {
"A",
"B",
"X",
"Y",
"South",
"East",
"West",
"North",
"Back",
"Guide",
"Start",
@ -801,9 +764,49 @@ static SDL_bool GetBindingString(const char *label, char *mapping, char *text, s
static SDL_bool GetButtonBindingString(SDL_GamepadButton button, char *mapping, char *text, size_t size)
{
char label[32];
SDL_bool baxy_mapping = SDL_FALSE;
if (!mapping) {
return SDL_FALSE;
}
SDL_snprintf(label, sizeof(label), ",%s:", SDL_GetGamepadStringForButton(button));
return GetBindingString(label, mapping, text, size);
if (GetBindingString(label, mapping, text, size)) {
return SDL_TRUE;
}
/* Try the legacy button names */
if (SDL_strstr(mapping, ",hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1") != NULL) {
baxy_mapping = SDL_TRUE;
}
switch (button) {
case SDL_GAMEPAD_BUTTON_SOUTH:
if (baxy_mapping) {
return GetBindingString(",b:", mapping, text, size);
} else {
return GetBindingString(",a:", mapping, text, size);
}
case SDL_GAMEPAD_BUTTON_EAST:
if (baxy_mapping) {
return GetBindingString(",a:", mapping, text, size);
} else {
return GetBindingString(",b:", mapping, text, size);
}
case SDL_GAMEPAD_BUTTON_WEST:
if (baxy_mapping) {
return GetBindingString(",y:", mapping, text, size);
} else {
return GetBindingString(",x:", mapping, text, size);
}
case SDL_GAMEPAD_BUTTON_NORTH:
if (baxy_mapping) {
return GetBindingString(",x:", mapping, text, size);
} else {
return GetBindingString(",y:", mapping, text, size);
}
default:
return SDL_FALSE;
}
}
static SDL_bool GetAxisBindingString(SDL_GamepadAxis axis, int direction, char *mapping, char *text, size_t size)
@ -1707,7 +1710,7 @@ void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick)
highlight.h = (float)ctx->button_height;
RenderJoystickButtonHighlight(ctx, i, &highlight);
SDL_snprintf(text, sizeof(text), "%2.d:", i);
SDL_snprintf(text, sizeof(text), "%2d:", i);
SDLTest_DrawString(ctx->renderer, x, y, text);
if (SDL_GetJoystickButton(joystick, (Uint8)i)) {
@ -2224,9 +2227,11 @@ static int FindMappingKey(const MappingParts *parts, const char *key)
{
int i;
for (i = 0; i < parts->num_elements; ++i) {
if (SDL_strcmp(key, parts->keys[i]) == 0) {
return i;
if (key) {
for (i = 0; i < parts->num_elements; ++i) {
if (SDL_strcmp(key, parts->keys[i]) == 0) {
return i;
}
}
}
return -1;
@ -2243,6 +2248,55 @@ static void RemoveMappingValueAt(MappingParts *parts, int index)
}
}
static void ConvertBAXYMapping(MappingParts *parts)
{
int i;
SDL_bool baxy_mapping = SDL_FALSE;
for (i = 0; i < parts->num_elements; ++i) {
const char *key = parts->keys[i];
const char *value = parts->values[i];
if (SDL_strcmp(key, "hint") == 0 &&
SDL_strcmp(value, "SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1") == 0) {
baxy_mapping = SDL_TRUE;
}
}
if (!baxy_mapping) {
return;
}
/* Swap buttons, invert hint */
for (i = 0; i < parts->num_elements; ++i) {
char *key = parts->keys[i];
char *value = parts->values[i];
if (SDL_strcmp(key, "a") == 0) {
parts->keys[i] = SDL_strdup("b");
SDL_free(key);
} else if (SDL_strcmp(key, "b") == 0) {
parts->keys[i] = SDL_strdup("a");
SDL_free(key);
} else if (SDL_strcmp(key, "x") == 0) {
parts->keys[i] = SDL_strdup("y");
SDL_free(key);
} else if (SDL_strcmp(key, "y") == 0) {
parts->keys[i] = SDL_strdup("x");
SDL_free(key);
} else if (SDL_strcmp(key, "hint") == 0 &&
SDL_strcmp(value, "SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1") == 0) {
parts->values[i] = SDL_strdup("!SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1");
SDL_free(value);
}
}
}
static void UpdateLegacyElements(MappingParts *parts)
{
ConvertBAXYMapping(parts);
}
static SDL_bool CombineMappingAxes(MappingParts *parts)
{
int i, matching, axis;
@ -2337,6 +2391,7 @@ static char *JoinMapping(MappingParts *parts)
const char *name;
MappingSortEntry *sort_order;
UpdateLegacyElements(parts);
CombineMappingAxes(parts);
guid = parts->guid;
@ -2420,6 +2475,43 @@ static char *RecreateMapping(MappingParts *parts, char *mapping)
return mapping;
}
static const char *GetLegacyKey(const char *key, SDL_bool baxy)
{
if (SDL_strcmp(key, SDL_GetGamepadStringForButton(SDL_GAMEPAD_BUTTON_SOUTH)) == 0) {
if (baxy) {
return "b";
} else {
return "a";
}
}
if (SDL_strcmp(key, SDL_GetGamepadStringForButton(SDL_GAMEPAD_BUTTON_EAST)) == 0) {
if (baxy) {
return "a";
} else {
return "b";
}
}
if (SDL_strcmp(key, SDL_GetGamepadStringForButton(SDL_GAMEPAD_BUTTON_WEST)) == 0) {
if (baxy) {
return "y";
} else {
return "x";
}
}
if (SDL_strcmp(key, SDL_GetGamepadStringForButton(SDL_GAMEPAD_BUTTON_NORTH)) == 0) {
if (baxy) {
return "y";
} else {
return "x";
}
}
return key;
}
static SDL_bool MappingHasKey(const char *mapping, const char *key)
{
int i;
@ -2428,6 +2520,14 @@ static SDL_bool MappingHasKey(const char *mapping, const char *key)
SplitMapping(mapping, &parts);
i = FindMappingKey(&parts, key);
if (i < 0) {
SDL_bool baxy_mapping = SDL_FALSE;
if (mapping && SDL_strstr(mapping, ",hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1") != NULL) {
baxy_mapping = SDL_TRUE;
}
i = FindMappingKey(&parts, GetLegacyKey(key, baxy_mapping));
}
if (i >= 0) {
result = SDL_TRUE;
}
@ -2444,6 +2544,14 @@ static char *GetMappingValue(const char *mapping, const char *key)
SplitMapping(mapping, &parts);
i = FindMappingKey(&parts, key);
if (i < 0) {
SDL_bool baxy_mapping = SDL_FALSE;
if (mapping && SDL_strstr(mapping, ",hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1") != NULL) {
baxy_mapping = SDL_TRUE;
}
i = FindMappingKey(&parts, GetLegacyKey(key, baxy_mapping));
}
if (i >= 0) {
value = parts.values[i];
parts.values[i] = NULL; /* So we don't free it */
@ -2658,7 +2766,7 @@ SDL_GamepadType GetMappingType(const char *mapping)
char *SetMappingType(char *mapping, SDL_GamepadType type)
{
const char *type_string = SDL_GetGamepadStringForType(type);
if (type_string == NULL || type == SDL_GAMEPAD_TYPE_UNKNOWN) {
if (!type_string || type == SDL_GAMEPAD_TYPE_UNKNOWN) {
return RemoveMappingValue(mapping, "type");
} else {
return SetMappingValue(mapping, "type", type_string);

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -20,14 +20,6 @@ typedef enum
CONTROLLER_MODE_BINDING,
} ControllerDisplayMode;
typedef enum
{
GAMEPAD_IMAGE_FACE_BLANK,
GAMEPAD_IMAGE_FACE_ABXY,
GAMEPAD_IMAGE_FACE_BAYX,
GAMEPAD_IMAGE_FACE_SONY,
} GamepadImageFaceStyle;
enum
{
SDL_GAMEPAD_ELEMENT_INVALID = -1,
@ -63,8 +55,8 @@ extern GamepadImage *CreateGamepadImage(SDL_Renderer *renderer);
extern void SetGamepadImagePosition(GamepadImage *ctx, int x, int y);
extern void GetGamepadImageArea(GamepadImage *ctx, SDL_Rect *area);
extern void SetGamepadImageShowingFront(GamepadImage *ctx, SDL_bool showing_front);
extern void SetGamepadImageFaceStyle(GamepadImage *ctx, GamepadImageFaceStyle face_style);
extern GamepadImageFaceStyle GetGamepadImageFaceStyle(GamepadImage *ctx);
extern void SetGamepadImageType(GamepadImage *ctx, SDL_GamepadType type);
extern SDL_GamepadType GetGamepadImageType(GamepadImage *ctx);
extern void SetGamepadImageDisplayMode(GamepadImage *ctx, ControllerDisplayMode display_mode);
extern int GetGamepadImageButtonWidth(GamepadImage *ctx);
extern int GetGamepadImageButtonHeight(GamepadImage *ctx);

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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,10 +17,7 @@
*/
#include <stdlib.h>
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
#define SDL_MAIN_USE_CALLBACKS 1
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h>
@ -34,72 +31,28 @@ static struct
} wave;
static SDL_AudioStream *stream;
static SDLTest_CommonState *state;
static void fillerup(void)
static int fillerup(void)
{
const int minimum = (wave.soundlen / SDL_AUDIO_FRAMESIZE(wave.spec)) / 2;
if (SDL_GetAudioStreamQueued(stream) < minimum) {
SDL_PutAudioStreamData(stream, wave.sound, wave.soundlen);
}
return 0;
}
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDL_Quit();
/* Let 'main()' return normally */
if (rc != 0) {
exit(rc);
}
}
static void
close_audio(void)
{
if (stream) {
SDL_DestroyAudioStream(stream);
stream = NULL;
}
}
static void
open_audio(void)
{
stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &wave.spec, NULL, NULL);
if (!stream) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create audio stream: %s\n", SDL_GetError());
SDL_free(wave.sound);
quit(2);
}
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream));
}
static int done = 0;
#ifdef __EMSCRIPTEN__
static void loop(void)
{
if (done) {
emscripten_cancel_main_loop();
} else {
fillerup();
}
}
#endif
int main(int argc, char *argv[])
int SDL_AppInit(int argc, char *argv[])
{
int i;
char *filename = NULL;
SDLTest_CommonState *state;
/* this doesn't have to run very much, so give up tons of CPU time between iterations. */
SDL_SetHint(SDL_HINT_MAIN_CALLBACK_RATE, "5");
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
if (state == NULL) {
if (!state) {
return 1;
}
@ -129,22 +82,25 @@ int main(int argc, char *argv[])
/* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_EVENTS) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
return -1;
}
filename = GetResourceFilename(filename, "sample.wav");
if (filename == NULL) {
if (!filename) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
quit(1);
return -1;
}
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
quit(1);
SDL_free(filename);
return -1;
}
SDL_free(filename);
/* Show the list of available drivers */
SDL_Log("Available audio drivers:");
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
@ -153,30 +109,30 @@ int main(int argc, char *argv[])
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
open_audio();
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!done) {
SDL_Event event;
while (SDL_PollEvent(&event) > 0) {
if (event.type == SDL_EVENT_QUIT) {
done = 1;
}
}
fillerup();
SDL_Delay(100);
stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &wave.spec, NULL, NULL);
if (!stream) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create audio stream: %s\n", SDL_GetError());
return -1;
}
#endif
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream));
/* Clean up on signal */
close_audio();
SDL_free(wave.sound);
SDL_free(filename);
SDL_Quit();
SDLTest_CommonDestroyState(state);
return 0;
}
int SDL_AppEvent(const SDL_Event *event)
{
return (event->type == SDL_EVENT_QUIT) ? 1 : 0;
}
int SDL_AppIterate(void)
{
return fillerup();
}
void SDL_AppQuit(void)
{
SDL_DestroyAudioStream(stream);
SDL_free(wave.sound);
SDLTest_CommonDestroyState(state);
}

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -22,12 +22,15 @@
int main(int argc, char *argv[])
{
Uint64 start;
Uint64 prequit;
(void)argc;
(void)argv;
SDL_Init(0);
start = SDL_GetTicks();
SDL_GetPrefPath("libsdl", "test_filesystem");
SDL_Log("SDL_GetPrefPath took %" SDL_PRIu64 "ms", SDL_GetTicks() - start);
prequit = SDL_GetTicks();
SDL_Log("SDL_GetPrefPath took %" SDL_PRIu64 "ms", prequit - start);
SDL_Quit();
SDL_Log("SDL_Quit took %" SDL_PRIu64 "ms", SDL_GetTicks() - prequit);
return 0;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 KiB

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -50,28 +50,28 @@ static void RunBasicTest(void)
SDL_Log("\natomic -----------------------------------------\n\n");
SDL_AtomicSet(&v, 0);
tfret = SDL_AtomicSet(&v, 10) == 0 ? SDL_TRUE : SDL_FALSE;
tfret = SDL_AtomicSet(&v, 10) == 0;
SDL_Log("AtomicSet(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = SDL_AtomicAdd(&v, 10) == 10 ? SDL_TRUE : SDL_FALSE;
tfret = SDL_AtomicAdd(&v, 10) == 10;
SDL_Log("AtomicAdd(10) tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
SDL_AtomicSet(&v, 0);
SDL_AtomicIncRef(&v);
tfret = (SDL_AtomicGet(&v) == 1) ? SDL_TRUE : SDL_FALSE;
tfret = (SDL_AtomicGet(&v) == 1);
SDL_Log("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
SDL_AtomicIncRef(&v);
tfret = (SDL_AtomicGet(&v) == 2) ? SDL_TRUE : SDL_FALSE;
tfret = (SDL_AtomicGet(&v) == 2);
SDL_Log("AtomicIncRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE) ? SDL_TRUE : SDL_FALSE;
tfret = (SDL_AtomicDecRef(&v) == SDL_FALSE);
SDL_Log("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE) ? SDL_TRUE : SDL_FALSE;
tfret = (SDL_AtomicDecRef(&v) == SDL_TRUE);
SDL_Log("AtomicDecRef() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
SDL_AtomicSet(&v, 10);
tfret = (SDL_AtomicCAS(&v, 0, 20) == SDL_FALSE) ? SDL_TRUE : SDL_FALSE;
tfret = (SDL_AtomicCAS(&v, 0, 20) == SDL_FALSE);
SDL_Log("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
value = SDL_AtomicGet(&v);
tfret = (SDL_AtomicCAS(&v, value, 20) == SDL_TRUE) ? SDL_TRUE : SDL_FALSE;
tfret = (SDL_AtomicCAS(&v, value, 20) == SDL_TRUE);
SDL_Log("AtomicCAS() tfret=%s val=%d\n", tf(tfret), SDL_AtomicGet(&v));
}
@ -701,7 +701,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
if (state == NULL) {
if (!state) {
return 1;
}

View File

@ -1,9 +1,4 @@
#include <stdlib.h>
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
#define SDL_MAIN_USE_CALLBACKS 1
#include <SDL3/SDL_test.h>
#include <SDL3/SDL_test_common.h>
#include <SDL3/SDL_main.h>
@ -75,7 +70,7 @@ struct Thing
} poof;
struct {
SDL_AudioStream *stream;
int total_ticks;
int total_bytes;
Uint64 next_level_update;
Uint8 levels[5];
} stream;
@ -103,7 +98,6 @@ struct Thing
static Uint64 app_ready_ticks = 0;
static int done = 0;
static SDLTest_CommonState *state = NULL;
static Thing *things = NULL;
@ -113,6 +107,9 @@ static Thing *mouseover_thing = NULL;
static Thing *droppable_highlighted_thing = NULL;
static Thing *dragging_thing = NULL;
static int dragging_button = -1;
static int dragging_button_real = -1;
static SDL_bool ctrl_held = SDL_FALSE;
static SDL_bool alt_held = SDL_FALSE;
static Texture *physdev_texture = NULL;
static Texture *logdev_texture = NULL;
@ -121,51 +118,6 @@ static Texture *trashcan_texture = NULL;
static Texture *soundboard_texture = NULL;
static Texture *soundboard_levels_texture = NULL;
static void DestroyTexture(Texture *tex);
static void DestroyThing(Thing *thing);
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void Quit(int rc)
{
while (things != NULL) {
DestroyThing(things); /* make sure all the audio devices are closed, etc. */
}
DestroyTexture(physdev_texture);
DestroyTexture(logdev_texture);
DestroyTexture(audio_texture);
DestroyTexture(trashcan_texture);
DestroyTexture(soundboard_texture);
DestroyTexture(soundboard_levels_texture);
SDLTest_CommonQuit(state);
/* Let 'main()' return normally */
if (rc != 0) {
exit(rc);
}
}
static char *xstrdup(const char *str)
{
char *ptr = SDL_strdup(str);
if (!ptr) {
SDL_Log("Out of memory!");
Quit(1);
}
return ptr;
}
static void *xalloc(const size_t len)
{
void *ptr = SDL_calloc(1, len);
if (!ptr) {
SDL_Log("Out of memory!");
Quit(1);
}
return ptr;
}
static void SetTitleBar(const char *fmt, ...)
{
@ -194,7 +146,7 @@ static Thing *FindThingAtPoint(const float x, const float y)
const SDL_FPoint pt = { x, y };
Thing *retval = NULL;
Thing *i;
for (i = things; i != NULL; i = i->next) {
for (i = things; i; i = i->next) {
if ((i != dragging_thing) && SDL_PointInRectFloat(&pt, &i->rect)) {
retval = i; /* keep going, though, because things drawn on top are later in the list. */
}
@ -229,7 +181,12 @@ static Thing *CreateThing(ThingType what, float x, float y, float z, float w, fl
Thing *i;
Thing *thing;
thing = (Thing *) xalloc(sizeof (Thing));
thing = (Thing *) SDL_calloc(1, sizeof (Thing));
if (!thing) {
SDL_Log("Out of memory!");
return NULL;
}
if ((w < 0) || (h < 0)) {
SDL_assert(texture != NULL);
if (w < 0) {
@ -253,15 +210,15 @@ static Thing *CreateThing(ThingType what, float x, float y, float z, float w, fl
thing->scale = 1.0f;
thing->createticks = SDL_GetTicks();
thing->texture = texture;
thing->titlebar = titlebar ? xstrdup(titlebar) : NULL;
thing->titlebar = titlebar ? SDL_strdup(titlebar) : NULL; /* if allocation fails, oh well. */
/* insert in list by Z order (furthest from the "camera" first, so they get drawn over; negative Z is not drawn at all). */
if (things == NULL) {
if (!things) {
things = thing;
return thing;
}
for (i = things; i != NULL; i = i->next) {
for (i = things; i; i = i->next) {
if (z > i->z) { /* insert here. */
thing->next = i;
thing->prev = i->prev;
@ -313,7 +270,9 @@ static void DestroyThing(Thing *thing)
case THING_LOGDEV:
case THING_LOGDEV_CAPTURE:
SDL_CloseAudioDevice(thing->data.logdev.devid);
SDL_DestroyTexture(thing->data.logdev.visualizer);
if (state->renderers[0] != NULL) {
SDL_DestroyTexture(thing->data.logdev.visualizer);
}
SDL_DestroyMutex(thing->data.logdev.postmix_lock);
SDL_free(thing->data.logdev.postmix_buffer);
break;
@ -354,9 +313,10 @@ static void DrawOneThing(SDL_Renderer *renderer, Thing *thing)
if (thing->scale != 1.0f) {
const float centerx = thing->rect.x + (thing->rect.w / 2);
const float centery = thing->rect.y + (thing->rect.h / 2);
SDL_assert(thing->texture != NULL);
dst.w = thing->texture->w * thing->scale;
dst.h = thing->texture->h * thing->scale;
const int w = thing->texture ? (int) thing->texture->w : 128;
const int h = thing->texture ? (int) thing->texture->h : 128;
dst.w = w * thing->scale;
dst.h = h * thing->scale;
dst.x = centerx - (dst.w / 2);
dst.y = centery - (dst.h / 2);
}
@ -413,11 +373,13 @@ static void DrawThings(SDL_Renderer *renderer)
static void Draw(void)
{
SDL_Renderer *renderer = state->renderers[0];
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, 64, 0, 64, 255);
SDL_RenderClear(renderer);
DrawThings(renderer);
SDL_RenderPresent(renderer);
if (renderer) { /* might be NULL if we're shutting down. */
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(renderer, 64, 0, 64, 255);
SDL_RenderClear(renderer);
DrawThings(renderer);
SDL_RenderPresent(renderer);
}
}
static void RepositionRowOfThings(const ThingType what, const float y)
@ -427,7 +389,7 @@ static void RepositionRowOfThings(const ThingType what, const float y)
float texh = 0.0f;
Thing *i;
for (i = things; i != NULL; i = i->next) {
for (i = things; i; i = i->next) {
if (i->what == what) {
texw = i->rect.w;
texh = i->rect.h;
@ -440,7 +402,7 @@ static void RepositionRowOfThings(const ThingType what, const float y)
SDL_GetWindowSize(state->windows[0], &w, &h);
const float spacing = w / ((float) total_things);
float x = (spacing - texw) / 2.0f;
for (i = things; i != NULL; i = i->next) {
for (i = things; i; i = i->next) {
if (i->what == what) {
i->rect.x = x;
i->rect.y = (y >= 0.0f) ? y : ((h + y) - texh);
@ -507,12 +469,14 @@ static Thing *CreatePoofThing(Thing *poofing_thing)
const float centery = poofing_thing->rect.y + (poofing_thing->rect.h / 2);
const float z = poofing_thing->z;
Thing *thing = CreateThing(THING_POOF, poofing_thing->rect.x, poofing_thing->rect.y, z, poofing_thing->rect.w, poofing_thing->rect.h, poofing_thing->texture, NULL);
thing->data.poof.startw = poofing_thing->rect.w;
thing->data.poof.starth = poofing_thing->rect.h;
thing->data.poof.centerx = centerx;
thing->data.poof.centery = centery;
thing->ontick = PoofThing_ontick;
thing->ondrag = PoofThing_ondrag;
if (thing) {
thing->data.poof.startw = poofing_thing->rect.w;
thing->data.poof.starth = poofing_thing->rect.h;
thing->data.poof.centerx = centerx;
thing->data.poof.centery = centery;
thing->ontick = PoofThing_ontick;
thing->ondrag = PoofThing_ondrag;
}
return thing;
}
@ -530,7 +494,7 @@ static void DestroyThingInPoof(Thing *thing)
static void TrashThing(Thing *thing)
{
Thing *i, *next;
for (i = things; i != NULL; i = next) {
for (i = things; i; i = next) {
next = i->next;
if (i->line_connected_to == thing) {
TrashThing(i);
@ -549,13 +513,11 @@ static void StreamThing_ontick(Thing *thing, Uint64 now)
/* are we playing? See if we're done, or update state. */
if (thing->line_connected_to->what == THING_LOGDEV) {
const int available = SDL_GetAudioStreamAvailable(thing->data.stream.stream);
SDL_AudioSpec spec;
if (!available || (SDL_GetAudioStreamFormat(thing->data.stream.stream, NULL, &spec) < 0)) {
if (!available) {
DestroyThingInPoof(thing);
return;
} else {
const int ticksleft = (int) ((((Uint64) (available / SDL_AUDIO_FRAMESIZE(spec))) * 1000) / spec.freq);
const float pct = thing->data.stream.total_ticks ? (((float) (ticksleft)) / ((float) thing->data.stream.total_ticks)) : 0.0f;
thing->progress = 1.0f - pct;
thing->progress = 1.0f - (thing->data.stream.total_bytes ? (((float) (available)) / ((float) thing->data.stream.total_bytes)) : 0.0f);
}
}
@ -575,6 +537,9 @@ static void StreamThing_ondrag(Thing *thing, int button, float x, float y)
if (button == SDL_BUTTON_RIGHT) { /* this is kinda hacky, but use this to disconnect from a playing source. */
if (thing->line_connected_to) {
SDL_UnbindAudioStream(thing->data.stream.stream); /* unbind from current device */
if (thing->line_connected_to->what == THING_LOGDEV_CAPTURE) {
SDL_FlushAudioStream(thing->data.stream.stream);
}
thing->line_connected_to = NULL;
}
}
@ -589,16 +554,14 @@ static void StreamThing_ondrop(Thing *thing, int button, float x, float y)
/* connect to a logical device! */
SDL_Log("Binding audio stream ('%s') to logical device %u", thing->titlebar, (unsigned int) droppable_highlighted_thing->data.logdev.devid);
if (thing->line_connected_to) {
const SDL_AudioSpec *spec = &droppable_highlighted_thing->data.logdev.spec;
SDL_UnbindAudioStream(thing->data.stream.stream); /* unbind from current device */
if (thing->line_connected_to->what == THING_LOGDEV_CAPTURE) {
SDL_FlushAudioStream(thing->data.stream.stream);
thing->data.stream.total_ticks = (int) ((((Uint64) (SDL_GetAudioStreamAvailable(thing->data.stream.stream) / SDL_AUDIO_FRAMESIZE(*spec))) * 1000) / spec->freq);
}
}
SDL_BindAudioStream(droppable_highlighted_thing->data.logdev.devid, thing->data.stream.stream); /* bind to new device! */
thing->data.stream.total_bytes = SDL_GetAudioStreamAvailable(thing->data.stream.stream);
thing->progress = 0.0f; /* ontick will adjust this if we're on an output device.*/
thing->data.stream.next_level_update = SDL_GetTicks() + 100;
thing->line_connected_to = droppable_highlighted_thing;
@ -631,18 +594,20 @@ static Thing *CreateStreamThing(const SDL_AudioSpec *spec, const Uint8 *buf, con
{
static const ThingType can_be_dropped_onto[] = { THING_TRASHCAN, THING_LOGDEV, THING_LOGDEV_CAPTURE, THING_NULL };
Thing *thing = CreateThing(THING_STREAM, x, y, 0, -1, -1, soundboard_texture, fname);
SDL_Log("Adding audio stream for %s", fname ? fname : "(null)");
thing->data.stream.stream = SDL_CreateAudioStream(spec, spec);
if (buf && buflen) {
SDL_PutAudioStreamData(thing->data.stream.stream, buf, (int) buflen);
SDL_FlushAudioStream(thing->data.stream.stream);
thing->data.stream.total_ticks = (int) ((((Uint64) (SDL_GetAudioStreamAvailable(thing->data.stream.stream) / SDL_AUDIO_FRAMESIZE(*spec))) * 1000) / spec->freq);
if (thing) {
SDL_Log("Adding audio stream for %s", fname ? fname : "(null)");
thing->data.stream.stream = SDL_CreateAudioStream(spec, spec);
if (buf && buflen) {
SDL_PutAudioStreamData(thing->data.stream.stream, buf, (int) buflen);
SDL_FlushAudioStream(thing->data.stream.stream);
thing->data.stream.total_bytes = SDL_GetAudioStreamAvailable(thing->data.stream.stream);
}
thing->ontick = StreamThing_ontick;
thing->ondrag = StreamThing_ondrag;
thing->ondrop = StreamThing_ondrop;
thing->ondraw = StreamThing_ondraw;
thing->can_be_dropped_onto = can_be_dropped_onto;
}
thing->ontick = StreamThing_ontick;
thing->ondrag = StreamThing_ondrag;
thing->ondrop = StreamThing_ondrop;
thing->ondraw = StreamThing_ondraw;
thing->can_be_dropped_onto = can_be_dropped_onto;
return thing;
}
@ -696,13 +661,15 @@ static Thing *LoadWavThing(const char *fname, float x, float y)
SDL_asprintf(&titlebar, "WAV file (\"%s\", %s, %s, %uHz)", nodirs, AudioFmtToString(spec.format), AudioChansToStr(spec.channels), (unsigned int) spec.freq);
thing = CreateThing(THING_WAV, x - (audio_texture->w / 2), y - (audio_texture->h / 2), 5, -1, -1, audio_texture, titlebar);
SDL_free(titlebar);
SDL_memcpy(&thing->data.wav.spec, &spec, sizeof (SDL_AudioSpec));
thing->data.wav.buf = buf;
thing->data.wav.buflen = buflen;
thing->can_be_dropped_onto = can_be_dropped_onto;
thing->ondrag = WavThing_ondrag;
thing->ondrop = WavThing_ondrop;
if (thing) {
SDL_free(titlebar);
SDL_memcpy(&thing->data.wav.spec, &spec, sizeof (SDL_AudioSpec));
thing->data.wav.buf = buf;
thing->data.wav.buflen = buflen;
thing->can_be_dropped_onto = can_be_dropped_onto;
thing->ondrag = WavThing_ondrag;
thing->ondrop = WavThing_ondrop;
}
}
SDL_free(path);
@ -727,24 +694,30 @@ static void LoadStockWavThings(void)
static void DestroyTexture(Texture *tex)
{
if (tex) {
SDL_DestroyTexture(tex->texture);
if (state->renderers[0] != NULL) { /* if the renderer went away, this pointer is already bogus. */
SDL_DestroyTexture(tex->texture);
}
SDL_free(tex);
}
}
static Texture *CreateTexture(const char *fname)
{
Texture *tex = (Texture *) xalloc(sizeof (Texture));
int texw, texh;
tex->texture = LoadTexture(state->renderers[0], fname, SDL_TRUE, &texw, &texh);
if (!tex->texture) {
SDL_Log("Failed to load '%s': %s", fname, SDL_GetError());
SDL_free(tex);
Quit(1);
Texture *tex = (Texture *) SDL_calloc(1, sizeof (Texture));
if (!tex) {
SDL_Log("Out of memory!");
} else {
int texw, texh;
tex->texture = LoadTexture(state->renderers[0], fname, SDL_TRUE, &texw, &texh);
if (!tex->texture) {
SDL_Log("Failed to load '%s': %s", fname, SDL_GetError());
SDL_free(tex);
return NULL;
}
SDL_SetTextureBlendMode(tex->texture, SDL_BLENDMODE_BLEND);
tex->w = (float) texw;
tex->h = (float) texh;
}
SDL_SetTextureBlendMode(tex->texture, SDL_BLENDMODE_BLEND);
tex->w = (float) texw;
tex->h = (float) texh;
return tex;
}
@ -754,9 +727,11 @@ static void DeviceThing_ondrag(Thing *thing, int button, float x, float y)
{
if ((button == SDL_BUTTON_MIDDLE) && (thing->what == THING_LOGDEV_CAPTURE)) { /* drag out a new stream. This is a UX mess. :/ */
dragging_thing = CreateStreamThing(&thing->data.logdev.spec, NULL, 0, NULL, x, y);
dragging_thing->data.stream.next_level_update = SDL_GetTicks() + 100;
SDL_BindAudioStream(thing->data.logdev.devid, dragging_thing->data.stream.stream); /* bind to new device! */
dragging_thing->line_connected_to = thing;
if (dragging_thing) {
dragging_thing->data.stream.next_level_update = SDL_GetTicks() + 100;
SDL_BindAudioStream(thing->data.logdev.devid, dragging_thing->data.stream.stream); /* bind to new device! */
dragging_thing->line_connected_to = thing;
}
} else if (button == SDL_BUTTON_RIGHT) { /* drag out a new logical device. */
const SDL_AudioDeviceID which = ((thing->what == THING_LOGDEV) || (thing->what == THING_LOGDEV_CAPTURE)) ? thing->data.logdev.devid : thing->data.physdev.devid;
const SDL_AudioDeviceID devid = SDL_OpenAudioDevice(which, NULL);
@ -858,7 +833,7 @@ static void UpdateVisualizer(SDL_Renderer *renderer, SDL_Texture *visualizer, co
static void LogicalDeviceThing_ontick(Thing *thing, Uint64 now)
{
const SDL_bool ismousedover = (thing == mouseover_thing) ? SDL_TRUE : SDL_FALSE;
const SDL_bool ismousedover = (thing == mouseover_thing);
if (!thing->data.logdev.visualizer || !thing->data.logdev.postmix_lock) { /* need these to work, skip if they failed. */
return;
@ -920,22 +895,24 @@ static Thing *CreateLogicalDeviceThing(Thing *parent, const SDL_AudioDeviceID wh
SDL_Log("Adding logical audio device %u", (unsigned int) which);
thing = CreateThing(iscapture ? THING_LOGDEV_CAPTURE : THING_LOGDEV, x, y, 5, -1, -1, logdev_texture, NULL);
thing->data.logdev.devid = which;
thing->data.logdev.iscapture = iscapture;
thing->data.logdev.physdev = physthing;
thing->data.logdev.visualizer = SDL_CreateTexture(state->renderers[0], SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, VISUALIZER_WIDTH, VISUALIZER_HEIGHT);
thing->data.logdev.postmix_lock = SDL_CreateMutex();
if (thing->data.logdev.visualizer) {
SDL_SetTextureBlendMode(thing->data.logdev.visualizer, SDL_BLENDMODE_BLEND);
}
thing->line_connected_to = physthing;
thing->ontick = LogicalDeviceThing_ontick;
thing->ondrag = DeviceThing_ondrag;
thing->ondrop = LogicalDeviceThing_ondrop;
thing->ondraw = LogicalDeviceThing_ondraw;
thing->can_be_dropped_onto = can_be_dropped_onto;
if (thing) {
thing->data.logdev.devid = which;
thing->data.logdev.iscapture = iscapture;
thing->data.logdev.physdev = physthing;
thing->data.logdev.visualizer = SDL_CreateTexture(state->renderers[0], SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, VISUALIZER_WIDTH, VISUALIZER_HEIGHT);
thing->data.logdev.postmix_lock = SDL_CreateMutex();
if (thing->data.logdev.visualizer) {
SDL_SetTextureBlendMode(thing->data.logdev.visualizer, SDL_BLENDMODE_BLEND);
}
thing->line_connected_to = physthing;
thing->ontick = LogicalDeviceThing_ontick;
thing->ondrag = DeviceThing_ondrag;
thing->ondrop = LogicalDeviceThing_ondrop;
thing->ondraw = LogicalDeviceThing_ondraw;
thing->can_be_dropped_onto = can_be_dropped_onto;
SetLogicalDeviceTitlebar(thing);
SetLogicalDeviceTitlebar(thing);
}
return thing;
}
@ -993,21 +970,23 @@ static Thing *CreatePhysicalDeviceThing(const SDL_AudioDeviceID which, const SDL
SDL_Log("Adding physical audio device %u", (unsigned int) which);
thing = CreateThing(iscapture ? THING_PHYSDEV_CAPTURE : THING_PHYSDEV, next_physdev_x, 170, 5, -1, -1, physdev_texture, NULL);
thing->data.physdev.devid = which;
thing->data.physdev.iscapture = iscapture;
thing->data.physdev.name = SDL_GetAudioDeviceName(which);
thing->ondrag = DeviceThing_ondrag;
thing->ondrop = PhysicalDeviceThing_ondrop;
thing->ontick = PhysicalDeviceThing_ontick;
thing->can_be_dropped_onto = can_be_dropped_onto;
if (thing) {
thing->data.physdev.devid = which;
thing->data.physdev.iscapture = iscapture;
thing->data.physdev.name = SDL_GetAudioDeviceName(which);
thing->ondrag = DeviceThing_ondrag;
thing->ondrop = PhysicalDeviceThing_ondrop;
thing->ontick = PhysicalDeviceThing_ontick;
thing->can_be_dropped_onto = can_be_dropped_onto;
SetPhysicalDeviceTitlebar(thing);
if (SDL_GetTicks() <= (app_ready_ticks + 2000)) { /* assume this is the initial batch if it happens in the first two seconds. */
RepositionRowOfThings(THING_PHYSDEV, 10.0f); /* don't rearrange them after the initial add. */
RepositionRowOfThings(THING_PHYSDEV_CAPTURE, 170.0f); /* don't rearrange them after the initial add. */
next_physdev_x = 0.0f;
} else {
next_physdev_x += physdev_texture->w * 1.5f;
SetPhysicalDeviceTitlebar(thing);
if (SDL_GetTicks() <= (app_ready_ticks + 2000)) { /* assume this is the initial batch if it happens in the first two seconds. */
RepositionRowOfThings(THING_PHYSDEV, 10.0f); /* don't rearrange them after the initial add. */
RepositionRowOfThings(THING_PHYSDEV_CAPTURE, 170.0f); /* don't rearrange them after the initial add. */
next_physdev_x = 0.0f;
} else {
next_physdev_x += physdev_texture->w * 1.5f;
}
}
return thing;
@ -1030,7 +1009,7 @@ static void TickThings(void)
Thing *i;
Thing *next;
const Uint64 now = SDL_GetTicks();
for (i = things; i != NULL; i = next) {
for (i = things; i; i = next) {
next = i->next; /* in case this deletes itself. */
if (i->ontick) {
i->ontick(i, now);
@ -1045,7 +1024,7 @@ static void WindowResized(const int newwinw, const int newwinh)
const float newh = (float) newwinh;
const float oldw = (float) state->window_w;
const float oldh = (float) state->window_h;
for (i = things; i != NULL; i = i->next) {
for (i = things; i; i = i->next) {
const float halfw = i->rect.w / 2.0f;
const float halfh = i->rect.h / 2.0f;
const float x = (i->rect.x + halfw) / oldw;
@ -1057,140 +1036,13 @@ static void WindowResized(const int newwinw, const int newwinh)
state->window_h = newwinh;
}
static void Loop(void)
{
SDL_Event event;
SDL_bool saw_event = SDL_FALSE;
if (app_ready_ticks == 0) {
app_ready_ticks = SDL_GetTicks();
}
while (SDL_PollEvent(&event)) {
Thing *thing = NULL;
saw_event = SDL_TRUE;
switch (event.type) {
case SDL_EVENT_MOUSE_MOTION:
thing = UpdateMouseOver(event.motion.x, event.motion.y);
if ((dragging_button == -1) && event.motion.state) {
if (event.motion.state & SDL_BUTTON_LMASK) {
dragging_button = SDL_BUTTON_LEFT;
} else if (event.motion.state & SDL_BUTTON_RMASK) {
dragging_button = SDL_BUTTON_RIGHT;
} else if (event.motion.state & SDL_BUTTON_MMASK) {
dragging_button = SDL_BUTTON_MIDDLE;
}
if (dragging_button != -1) {
dragging_thing = thing;
if (thing && thing->ondrag) {
thing->ondrag(thing, dragging_button, event.motion.x, event.motion.y);
}
}
}
droppable_highlighted_thing = NULL;
if (dragging_thing) {
dragging_thing->rect.x = event.motion.x - (dragging_thing->rect.w / 2);
dragging_thing->rect.y = event.motion.y - (dragging_thing->rect.h / 2);
if (dragging_thing->can_be_dropped_onto) {
thing = FindThingAtPoint(event.motion.x, event.motion.y);
if (thing) {
int i;
for (i = 0; dragging_thing->can_be_dropped_onto[i]; i++) {
if (dragging_thing->can_be_dropped_onto[i] == thing->what) {
droppable_highlighted_thing = thing;
break;
}
}
}
}
}
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
thing = UpdateMouseOver(event.button.x, event.button.y);
break;
case SDL_EVENT_MOUSE_BUTTON_UP:
if (dragging_button == event.button.button) {
Thing *dropped_thing = dragging_thing;
dragging_thing = NULL;
dragging_button = -1;
if (dropped_thing && dropped_thing->ondrop) {
dropped_thing->ondrop(dropped_thing, event.button.button, event.button.x, event.button.y);
}
droppable_highlighted_thing = NULL;
}
thing = UpdateMouseOver(event.button.x, event.button.y);
break;
case SDL_EVENT_MOUSE_WHEEL:
UpdateMouseOver(event.wheel.mouseX, event.wheel.mouseY);
break;
case SDL_EVENT_DROP_FILE:
SDL_Log("Drop file! '%s'", event.drop.file);
LoadWavThing(event.drop.file, event.drop.x, event.drop.y);
/* SDLTest_CommonEvent will free the string, below. */
break;
case SDL_EVENT_WINDOW_RESIZED:
WindowResized(event.window.data1, event.window.data2);
break;
case SDL_EVENT_AUDIO_DEVICE_ADDED:
CreatePhysicalDeviceThing(event.adevice.which, event.adevice.iscapture);
break;
case SDL_EVENT_AUDIO_DEVICE_REMOVED: {
const SDL_AudioDeviceID which = event.adevice.which;
Thing *i, *next;
SDL_Log("Removing audio device %u", (unsigned int) which);
for (i = things; i != NULL; i = next) {
next = i->next;
if (((i->what == THING_PHYSDEV) || (i->what == THING_PHYSDEV_CAPTURE)) && (i->data.physdev.devid == which)) {
TrashThing(i);
next = things; /* in case we mangled the list. */
} else if (((i->what == THING_LOGDEV) || (i->what == THING_LOGDEV_CAPTURE)) && (i->data.logdev.devid == which)) {
TrashThing(i);
next = things; /* in case we mangled the list. */
}
}
break;
}
default: break;
}
SDLTest_CommonEvent(state, &event, &done);
}
TickThings();
Draw();
if (!saw_event) {
SDL_Delay(10);
}
#ifdef __EMSCRIPTEN__
if (done) {
emscripten_cancel_main_loop();
}
#endif
}
int main(int argc, char *argv[])
int SDL_AppInit(int argc, char *argv[])
{
int i;
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO);
if (state == NULL) {
Quit(1);
if (!state) {
return -1;
}
state->window_flags |= SDL_WINDOW_RESIZABLE;
@ -1208,13 +1060,13 @@ int main(int argc, char *argv[])
NULL
};
SDLTest_CommonLogUsage(state, argv[0], options);
Quit(1);
return -1;
}
i += consumed;
}
if (!SDLTest_CommonInit(state)) {
Quit(2);
return -1;
}
if (state->audio_id) {
@ -1224,27 +1076,174 @@ int main(int argc, char *argv[])
SetDefaultTitleBar();
physdev_texture = CreateTexture("physaudiodev.bmp");
logdev_texture = CreateTexture("logaudiodev.bmp");
audio_texture = CreateTexture("audiofile.bmp");
trashcan_texture = CreateTexture("trashcan.bmp");
soundboard_texture = CreateTexture("soundboard.bmp");
soundboard_levels_texture = CreateTexture("soundboard_levels.bmp");
if ((physdev_texture = CreateTexture("physaudiodev.bmp")) == NULL) { return -1; }
if ((logdev_texture = CreateTexture("logaudiodev.bmp")) == NULL) { return -1; }
if ((audio_texture = CreateTexture("audiofile.bmp")) == NULL) { return -1; }
if ((trashcan_texture = CreateTexture("trashcan.bmp")) == NULL) { return -1; }
if ((soundboard_texture = CreateTexture("soundboard.bmp")) == NULL) { return -1; }
if ((soundboard_levels_texture = CreateTexture("soundboard_levels.bmp")) == NULL) { return -1; }
LoadStockWavThings();
CreateTrashcanThing();
CreateDefaultPhysicalDevice(SDL_FALSE);
CreateDefaultPhysicalDevice(SDL_TRUE);
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(Loop, 0, 1);
#else
while (!done) {
Loop();
}
#endif
Quit(0);
return 0;
}
static SDL_bool saw_event = SDL_FALSE;
int SDL_AppEvent(const SDL_Event *event)
{
Thing *thing = NULL;
saw_event = SDL_TRUE;
switch (event->type) {
case SDL_EVENT_MOUSE_MOTION:
thing = UpdateMouseOver(event->motion.x, event->motion.y);
if ((dragging_button == -1) && event->motion.state) {
if (event->motion.state & SDL_BUTTON_LMASK) {
/* for people that don't have all three buttons... */
if (ctrl_held) {
dragging_button = SDL_BUTTON_RIGHT;
} else if (alt_held) {
dragging_button = SDL_BUTTON_MIDDLE;
} else {
dragging_button = SDL_BUTTON_LEFT;
}
dragging_button_real = SDL_BUTTON_LEFT;
} else if (event->motion.state & SDL_BUTTON_RMASK) {
dragging_button = SDL_BUTTON_RIGHT;
dragging_button_real = SDL_BUTTON_RIGHT;
} else if (event->motion.state & SDL_BUTTON_MMASK) {
dragging_button = SDL_BUTTON_MIDDLE;
dragging_button_real = SDL_BUTTON_MIDDLE;
}
if (dragging_button != -1) {
dragging_thing = thing;
if (thing && thing->ondrag) {
thing->ondrag(thing, dragging_button, event->motion.x, event->motion.y);
}
}
}
droppable_highlighted_thing = NULL;
if (dragging_thing) {
dragging_thing->rect.x = event->motion.x - (dragging_thing->rect.w / 2);
dragging_thing->rect.y = event->motion.y - (dragging_thing->rect.h / 2);
if (dragging_thing->can_be_dropped_onto) {
thing = FindThingAtPoint(event->motion.x, event->motion.y);
if (thing) {
int i;
for (i = 0; dragging_thing->can_be_dropped_onto[i]; i++) {
if (dragging_thing->can_be_dropped_onto[i] == thing->what) {
droppable_highlighted_thing = thing;
break;
}
}
}
}
}
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
thing = UpdateMouseOver(event->button.x, event->button.y);
break;
case SDL_EVENT_MOUSE_BUTTON_UP:
if (dragging_button_real == event->button.button) {
Thing *dropped_thing = dragging_thing;
dragging_thing = NULL;
dragging_button = -1;
dragging_button_real = -1;
if (dropped_thing && dropped_thing->ondrop) {
dropped_thing->ondrop(dropped_thing, event->button.button, event->button.x, event->button.y);
}
droppable_highlighted_thing = NULL;
}
thing = UpdateMouseOver(event->button.x, event->button.y);
break;
case SDL_EVENT_MOUSE_WHEEL:
UpdateMouseOver(event->wheel.mouseX, event->wheel.mouseY);
break;
case SDL_EVENT_KEY_DOWN:
case SDL_EVENT_KEY_UP:
ctrl_held = ((event->key.keysym.mod & SDL_KMOD_CTRL) != 0);
alt_held = ((event->key.keysym.mod & SDL_KMOD_ALT) != 0);
break;
case SDL_EVENT_DROP_FILE:
SDL_Log("Drop file! '%s'", event->drop.data);
LoadWavThing(event->drop.data, event->drop.x, event->drop.y);
/* SDL frees event->drop.data for you when you use SDL_AppEvent(). */
break;
case SDL_EVENT_WINDOW_RESIZED:
WindowResized(event->window.data1, event->window.data2);
break;
case SDL_EVENT_AUDIO_DEVICE_ADDED:
CreatePhysicalDeviceThing(event->adevice.which, event->adevice.iscapture);
break;
case SDL_EVENT_AUDIO_DEVICE_REMOVED: {
const SDL_AudioDeviceID which = event->adevice.which;
Thing *i, *next;
SDL_Log("Removing audio device %u", (unsigned int) which);
for (i = things; i; i = next) {
next = i->next;
if (((i->what == THING_PHYSDEV) || (i->what == THING_PHYSDEV_CAPTURE)) && (i->data.physdev.devid == which)) {
TrashThing(i);
next = things; /* in case we mangled the list. */
} else if (((i->what == THING_LOGDEV) || (i->what == THING_LOGDEV_CAPTURE)) && (i->data.logdev.devid == which)) {
TrashThing(i);
next = things; /* in case we mangled the list. */
}
}
break;
}
default: break;
}
return SDLTest_CommonEventMainCallbacks(state, event);
}
int SDL_AppIterate(void)
{
if (app_ready_ticks == 0) {
app_ready_ticks = SDL_GetTicks();
}
TickThings();
Draw();
if (saw_event) {
saw_event = SDL_FALSE; /* reset this so we know when SDL_AppEvent() runs again */
} else {
SDL_Delay(10);
}
return 0; /* keep going. */
}
void SDL_AppQuit(void)
{
while (things) {
DestroyThing(things); /* make sure all the audio devices are closed, etc. */
}
DestroyTexture(physdev_texture);
DestroyTexture(logdev_texture);
DestroyTexture(audio_texture);
DestroyTexture(trashcan_texture);
DestroyTexture(soundboard_texture);
DestroyTexture(soundboard_levels_texture);
SDLTest_CommonQuit(state);
}

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -10,94 +10,20 @@
freely.
*/
#include <stdlib.h>
#define SDL_MAIN_USE_CALLBACKS 1
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include <SDL3/SDL_test.h>
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
static SDL_Window *window = NULL;
static SDL_Renderer *renderer = NULL;
static SDL_AudioStream *stream_in = NULL;
static SDL_AudioStream *stream_out = NULL;
static int done = 0;
static SDLTest_CommonState *state = NULL;
static void loop(void)
{
const SDL_AudioDeviceID devid_in = SDL_GetAudioStreamDevice(stream_in);
const SDL_AudioDeviceID devid_out = SDL_GetAudioStreamDevice(stream_out);
SDL_bool please_quit = SDL_FALSE;
SDL_Event e;
while (SDL_PollEvent(&e)) {
if (e.type == SDL_EVENT_QUIT) {
please_quit = SDL_TRUE;
} else if (e.type == SDL_EVENT_KEY_DOWN) {
if (e.key.keysym.sym == SDLK_ESCAPE) {
please_quit = SDL_TRUE;
}
} else if (e.type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
if (e.button.button == 1) {
SDL_PauseAudioDevice(devid_out);
SDL_ResumeAudioDevice(devid_in);
}
} else if (e.type == SDL_EVENT_MOUSE_BUTTON_UP) {
if (e.button.button == 1) {
SDL_PauseAudioDevice(devid_in);
SDL_FlushAudioStream(stream_in); /* so no samples are held back for resampling purposes. */
SDL_ResumeAudioDevice(devid_out);
}
}
}
if (!SDL_AudioDevicePaused(devid_in)) {
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
} else {
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
}
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
/* Feed any new data we captured to the output stream. It'll play when we unpause the device. */
while (!please_quit && (SDL_GetAudioStreamAvailable(stream_in) > 0)) {
Uint8 buf[1024];
const int br = SDL_GetAudioStreamData(stream_in, buf, sizeof(buf));
if (br < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to read from input audio stream: %s\n", SDL_GetError());
please_quit = 1;
} else if (SDL_PutAudioStreamData(stream_out, buf, br) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to write to output audio stream: %s\n", SDL_GetError());
please_quit = 1;
}
}
if (please_quit) {
/* stop playing back, quit. */
SDL_Log("Shutting down.\n");
SDL_CloseAudioDevice(devid_in);
SDL_CloseAudioDevice(devid_out);
SDL_DestroyAudioStream(stream_in);
SDL_DestroyAudioStream(stream_out);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
#ifdef __EMSCRIPTEN__
emscripten_cancel_main_loop();
#endif
/* Let 'main()' return normally */
done = 1;
return;
}
}
int main(int argc, char **argv)
int SDL_AppInit(int argc, char **argv)
{
SDL_AudioDeviceID *devices;
SDLTest_CommonState *state;
SDL_AudioSpec outspec;
SDL_AudioSpec inspec;
SDL_AudioDeviceID device;
@ -105,9 +31,12 @@ int main(int argc, char **argv)
const char *devname = NULL;
int i;
/* this doesn't have to run very much, so give up tons of CPU time between iterations. */
SDL_SetHint(SDL_HINT_MAIN_CALLBACK_RATE, "15");
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
if (state == NULL) {
if (!state) {
return 1;
}
@ -128,7 +57,7 @@ int main(int argc, char **argv)
if (consumed <= 0) {
static const char *options[] = { "[device_name]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
exit(1);
return -1;
}
i += consumed;
@ -175,20 +104,17 @@ int main(int argc, char **argv)
device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, NULL);
if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for playback: %s!\n", SDL_GetError());
SDL_Quit();
exit(1);
return -1;
}
SDL_PauseAudioDevice(device);
SDL_GetAudioDeviceFormat(device, &outspec, NULL);
stream_out = SDL_CreateAudioStream(&outspec, &outspec);
if (!stream_out) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for playback: %s!\n", SDL_GetError());
SDL_Quit();
exit(1);
return -1;
} else if (SDL_BindAudioStream(device, stream_out) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for playback: %s!\n", SDL_GetError());
SDL_Quit();
exit(1);
return -1;
}
SDL_Log("Opening capture device %s%s%s...\n",
@ -199,38 +125,89 @@ int main(int argc, char **argv)
device = SDL_OpenAudioDevice(want_device, NULL);
if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for capture: %s!\n", SDL_GetError());
SDL_Quit();
exit(1);
return -1;
}
SDL_PauseAudioDevice(device);
SDL_GetAudioDeviceFormat(device, &inspec, NULL);
stream_in = SDL_CreateAudioStream(&inspec, &inspec);
if (!stream_in) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for capture: %s!\n", SDL_GetError());
SDL_Quit();
exit(1);
return -1;
} else if (SDL_BindAudioStream(device, stream_in) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for capture: %s!\n", SDL_GetError());
SDL_Quit();
exit(1);
return -1;
}
SDL_SetAudioStreamFormat(stream_in, NULL, &outspec); /* make sure we output at the playback format. */
SDL_Log("Ready! Hold down mouse or finger to record!\n");
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!done) {
loop();
if (!done) {
SDL_Delay(16);
}
}
#endif
SDLTest_CommonDestroyState(state);
return 0;
}
int SDL_AppEvent(const SDL_Event *event)
{
if (event->type == SDL_EVENT_QUIT) {
return 1; /* terminate as success. */
} else if (event->type == SDL_EVENT_KEY_DOWN) {
if (event->key.keysym.sym == SDLK_ESCAPE) {
return 1; /* terminate as success. */
}
} else if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) {
if (event->button.button == 1) {
SDL_PauseAudioDevice(SDL_GetAudioStreamDevice(stream_out));
SDL_FlushAudioStream(stream_out); /* so no samples are held back for resampling purposes. */
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream_in));
}
} else if (event->type == SDL_EVENT_MOUSE_BUTTON_UP) {
if (event->button.button == 1) {
SDL_PauseAudioDevice(SDL_GetAudioStreamDevice(stream_in));
SDL_FlushAudioStream(stream_in); /* so no samples are held back for resampling purposes. */
SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream_out));
}
}
return 0; /* keep going. */
}
int SDL_AppIterate(void)
{
if (!SDL_AudioDevicePaused(SDL_GetAudioStreamDevice(stream_in))) {
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);
} else {
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
}
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
/* Feed any new data we captured to the output stream. It'll play when we unpause the device. */
while (SDL_GetAudioStreamAvailable(stream_in) > 0) {
Uint8 buf[1024];
const int br = SDL_GetAudioStreamData(stream_in, buf, sizeof(buf));
if (br < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to read from input audio stream: %s\n", SDL_GetError());
return -1; /* quit the app, report failure. */
} else if (SDL_PutAudioStreamData(stream_out, buf, br) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to write to output audio stream: %s\n", SDL_GetError());
return -1; /* quit the app, report failure. */
}
}
return 0; /* keep app going. */
}
void SDL_AppQuit(void)
{
SDL_Log("Shutting down.\n");
const SDL_AudioDeviceID devid_in = SDL_GetAudioStreamDevice(stream_in);
const SDL_AudioDeviceID devid_out = SDL_GetAudioStreamDevice(stream_out);
SDL_CloseAudioDevice(devid_in); /* !!! FIXME: use SDL_OpenAudioDeviceStream instead so we can dump this. */
SDL_CloseAudioDevice(devid_out);
SDL_DestroyAudioStream(stream_in);
SDL_DestroyAudioStream(stream_out);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDLTest_CommonDestroyState(state);
SDL_Quit();
}

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -72,7 +72,7 @@ static void iteration(void)
const SDL_AudioDeviceID which = (SDL_AudioDeviceID) e.adevice.which;
const SDL_bool iscapture = e.adevice.iscapture ? SDL_TRUE : SDL_FALSE;
char *name = SDL_GetAudioDeviceName(which);
if (name != NULL) {
if (name) {
SDL_Log("New %s audio device at id %u: %s", devtypestr(iscapture), (unsigned int)which, name);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Got new %s device, id %u, but failed to get the name: %s",
@ -119,7 +119,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
if (state == NULL) {
if (!state) {
return 1;
}
@ -154,7 +154,7 @@ int main(int argc, char *argv[])
/* Some targets (Mac CoreAudio) need an event queue for audio hotplug, so make and immediately hide a window. */
window = SDL_CreateWindow("testaudiohotplug", 640, 480, 0);
if (window == NULL) {
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateWindow failed: %s\n", SDL_GetError());
quit(1);
}
@ -162,7 +162,7 @@ int main(int argc, char *argv[])
filename = GetResourceFilename(filename, "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-2024 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
@ -22,7 +22,7 @@ print_devices(SDL_bool iscapture)
int frames;
SDL_AudioDeviceID *devices = iscapture ? SDL_GetAudioCaptureDevices(&n) : SDL_GetAudioOutputDevices(&n);
if (devices == NULL) {
if (!devices) {
SDL_Log(" Driver failed to report %s devices: %s\n\n", typestr, SDL_GetError());
} else if (n == 0) {
SDL_Log(" No %s devices found.\n\n", typestr);
@ -31,7 +31,7 @@ print_devices(SDL_bool iscapture)
SDL_Log("Found %d %s device%s:\n", n, typestr, n != 1 ? "s" : "");
for (i = 0; i < n; i++) {
char *name = SDL_GetAudioDeviceName(devices[i]);
if (name != NULL) {
if (name) {
SDL_Log(" %d: %s\n", i, name);
SDL_free(name);
} else {
@ -60,7 +60,7 @@ int main(int argc, char **argv)
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
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-2024 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
@ -158,7 +158,7 @@ static void skip_audio(float amount)
num_frames = (int)(new_spec.freq * ((speed * amount) / 100.0f));
buf = SDL_malloc(num_frames);
if (buf != NULL) {
if (buf) {
retval = SDL_GetAudioStreamData(stream, buf, num_frames);
SDL_free(buf);
}
@ -233,9 +233,9 @@ static void loop(void)
SDL_PauseAudioDevice(state->audio_id);
}
} else if (sym == SDLK_w) {
auto_loop = auto_loop ? SDL_FALSE : SDL_TRUE;
auto_loop = !auto_loop;
} else if (sym == SDLK_e) {
auto_flush = auto_flush ? SDL_FALSE : SDL_TRUE;
auto_flush = !auto_flush;
} else if (sym == SDLK_a) {
SDL_ClearAudioStream(stream);
SDL_Log("Cleared audio stream");
@ -374,7 +374,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_AUDIO | 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-2024 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
@ -33,17 +33,19 @@ static SDLTest_TestSuiteReference *testSuites[] = {
&mainTestSuite,
&mathTestSuite,
&mouseTestSuite,
&penTestSuite,
&pixelsTestSuite,
&platformTestSuite,
&propertiesTestSuite,
&rectTestSuite,
&renderTestSuite,
&rwopsTestSuite,
&sdltestTestSuite,
&stdlibTestSuite,
&surfaceTestSuite,
&syswmTestSuite,
&timerTestSuite,
&videoTestSuite,
&subsystemsTestSuite, /* run last, not interfere with other test enviroment */
NULL
};
@ -71,7 +73,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO | SDL_INIT_AUDIO);
if (state == NULL) {
if (!state) {
return 1;
}
@ -131,7 +133,7 @@ int main(int argc, char *argv[])
SDL_Log("Test suite: %s", testSuite->name);
for (testCounter = 0; testSuite->testCases[testCounter]; ++testCounter) {
const SDLTest_TestCaseReference *testCase = testSuite->testCases[testCounter];
SDL_Log(" test: %s", testCase->name);
SDL_Log(" test: %s%s", testCase->name, testCase->enabled ? "" : " (disabled)");
}
}
return 0;

View File

@ -59,7 +59,7 @@ static SDL_AudioDeviceID g_audio_id = -1;
/* Test case functions */
/**
* \brief Stop and restart audio subsystem
* Stop and restart audio subsystem
*
* \sa SDL_QuitSubSystem
* \sa SDL_InitSubSystem
@ -77,7 +77,7 @@ static int audio_quitInitAudioSubSystem(void *arg)
}
/**
* \brief Start and stop audio directly
* Start and stop audio directly
*
* \sa SDL_InitAudio
* \sa SDL_QuitAudio
@ -87,6 +87,7 @@ static int audio_initQuitAudio(void *arg)
int result;
int i, iMax;
const char *audioDriver;
const char *hint = SDL_GetHint(SDL_HINT_AUDIO_DRIVER);
/* Stop SDL audio subsystem */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
@ -102,6 +103,10 @@ static int audio_initQuitAudio(void *arg)
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 (hint && SDL_strcmp(audioDriver, hint) != 0) {
continue;
}
/* Call Init */
SDL_SetHint("SDL_AUDIO_DRIVER", audioDriver);
result = SDL_InitSubSystem(SDL_INIT_AUDIO);
@ -133,7 +138,7 @@ static int audio_initQuitAudio(void *arg)
}
/**
* \brief Start, open, close and stop audio
* Start, open, close and stop audio
*
* \sa SDL_InitAudio
* \sa SDL_OpenAudioDevice
@ -146,6 +151,7 @@ static int audio_initOpenCloseQuitAudio(void *arg)
int i, iMax, j, k;
const char *audioDriver;
SDL_AudioSpec desired;
const char *hint = SDL_GetHint(SDL_HINT_AUDIO_DRIVER);
/* Stop SDL audio subsystem */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
@ -161,6 +167,10 @@ static int audio_initOpenCloseQuitAudio(void *arg)
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 (hint && SDL_strcmp(audioDriver, hint) != 0) {
continue;
}
/* Change specs */
for (j = 0; j < 2; j++) {
@ -219,7 +229,7 @@ static int audio_initOpenCloseQuitAudio(void *arg)
}
/**
* \brief Pause and unpause audio
* Pause and unpause audio
*
* \sa SDL_PauseAudioDevice
* \sa SDL_PlayAudioDevice
@ -231,6 +241,7 @@ static int audio_pauseUnpauseAudio(void *arg)
int result;
const char *audioDriver;
SDL_AudioSpec desired;
const char *hint = SDL_GetHint(SDL_HINT_AUDIO_DRIVER);
/* Stop SDL audio subsystem */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
@ -246,6 +257,10 @@ static int audio_pauseUnpauseAudio(void *arg)
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 (hint && SDL_strcmp(audioDriver, hint) != 0) {
continue;
}
/* Change specs */
for (j = 0; j < 2; j++) {
@ -340,7 +355,7 @@ static int audio_pauseUnpauseAudio(void *arg)
}
/**
* \brief Enumerate and name available audio devices (output and capture).
* Enumerate and name available audio devices (output and capture).
*
* \sa SDL_GetNumAudioDevices
* \sa SDL_GetAudioDeviceName
@ -381,7 +396,7 @@ static int audio_enumerateAndNameAudioDevices(void *arg)
}
/**
* \brief Negative tests around enumeration and naming of audio devices.
* Negative tests around enumeration and naming of audio devices.
*
* \sa SDL_GetNumAudioDevices
* \sa SDL_GetAudioDeviceName
@ -392,7 +407,7 @@ static int audio_enumerateAndNameAudioDevicesNegativeTests(void *arg)
}
/**
* \brief Checks available audio driver names.
* Checks available audio driver names.
*
* \sa SDL_GetNumAudioDrivers
* \sa SDL_GetAudioDriver
@ -423,7 +438,7 @@ static int audio_printAudioDrivers(void *arg)
}
/**
* \brief Checks current audio driver name with initialized audio.
* Checks current audio driver name with initialized audio.
*
* \sa SDL_GetCurrentAudioDriver
*/
@ -470,7 +485,7 @@ SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_F32LE_FORMAT, SDL_AUDIO_F32LE == (SDL_AUDIO_BI
SDL_COMPILE_TIME_ASSERT(SDL_AUDIO_F32BE_FORMAT, SDL_AUDIO_F32BE == (SDL_AUDIO_F32LE | SDL_AUDIO_MASK_BIG_ENDIAN));
/**
* \brief Builds various audio conversion structures
* Builds various audio conversion structures
*
* \sa SDL_CreateAudioStream
*/
@ -481,6 +496,10 @@ static int audio_buildAudioStream(void *arg)
SDL_AudioSpec spec2;
int i, ii, j, jj, k, kk;
/* Call Quit */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDLTest_AssertPass("Call to SDL_QuitSubSystem(SDL_INIT_AUDIO)");
/* No conversion needed */
spec1.format = SDL_AUDIO_S16LE;
spec1.channels = 2;
@ -528,11 +547,14 @@ static int audio_buildAudioStream(void *arg)
}
}
/* Restart audio again */
audioSetUp(NULL);
return TEST_COMPLETED;
}
/**
* \brief Checks calls with invalid input to SDL_CreateAudioStream
* Checks calls with invalid input to SDL_CreateAudioStream
*
* \sa SDL_CreateAudioStream
*/
@ -612,7 +634,7 @@ static int audio_buildAudioStreamNegative(void *arg)
}
/**
* \brief Checks current audio status.
* Checks current audio status.
*
* \sa SDL_GetAudioDeviceStatus
*/
@ -622,7 +644,7 @@ static int audio_getAudioStatus(void *arg)
}
/**
* \brief Opens, checks current audio status, and closes a device.
* Opens, checks current audio status, and closes a device.
*
* \sa SDL_GetAudioStatus
*/
@ -632,7 +654,7 @@ static int audio_openCloseAndGetAudioStatus(void *arg)
}
/**
* \brief Locks and unlocks open audio device.
* Locks and unlocks open audio device.
*
* \sa SDL_LockAudioDevice
* \sa SDL_UnlockAudioDevice
@ -643,7 +665,7 @@ static int audio_lockUnlockOpenAudioDevice(void *arg)
}
/**
* \brief Convert audio using various conversion structures
* Convert audio using various conversion structures
*
* \sa SDL_CreateAudioStream
*/
@ -777,7 +799,7 @@ static int audio_convertAudio(void *arg)
}
/**
* \brief Opens, checks current connected status, and closes a device.
* Opens, checks current connected status, and closes a device.
*
* \sa SDL_AudioDeviceConnected
*/
@ -799,7 +821,7 @@ static double sine_wave_sample(const Sint64 idx, const Sint64 rate, const Sint64
}
/**
* \brief Check signal-to-noise ratio and maximum error of audio resampling.
* Check signal-to-noise ratio and maximum error of audio resampling.
*
* \sa https://wiki.libsdl.org/SDL_CreateAudioStream
* \sa https://wiki.libsdl.org/SDL_DestroyAudioStream
@ -956,7 +978,7 @@ static int audio_resampleLoss(void *arg)
}
/**
* \brief Check accuracy converting between audio formats.
* Check accuracy converting between audio formats.
*
* \sa SDL_ConvertAudioSamples
*/
@ -1091,7 +1113,7 @@ static int audio_convertAccuracy(void *arg)
}
/**
* \brief Check accuracy when switching between formats
* Check accuracy when switching between formats
*
* \sa SDL_SetAudioStreamFormat
*/

View File

@ -74,7 +74,7 @@ static void ClipboardCleanupCallback(void *userdata)
/* Test case functions */
/**
* \brief End-to-end test of SDL_xyzClipboardData functions
* End-to-end test of SDL_xyzClipboardData functions
* \sa SDL_HasClipboardData
* \sa SDL_GetClipboardData
* \sa SDL_SetClipboardData
@ -373,7 +373,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
}
/**
* \brief End-to-end test of SDL_xyzClipboardText functions
* End-to-end test of SDL_xyzClipboardText functions
* \sa SDL_HasClipboardText
* \sa SDL_GetClipboardText
* \sa SDL_SetClipboardText
@ -457,7 +457,7 @@ static int clipboard_testClipboardTextFunctions(void *arg)
}
/**
* \brief End-to-end test of SDL_xyzPrimarySelectionText functions
* End-to-end test of SDL_xyzPrimarySelectionText functions
* \sa SDL_HasPrimarySelectionText
* \sa SDL_GetPrimarySelectionText
* \sa SDL_SetPrimarySelectionText

View File

@ -38,7 +38,7 @@ static int SDLCALL events_sampleNullEventFilter(void *userdata, SDL_Event *event
}
/**
* \brief Test pumping and peeking events.
* Test pumping and peeking events.
*
* \sa SDL_PumpEvents
* \sa SDL_PollEvent
@ -75,7 +75,7 @@ static int events_pushPumpAndPollUserevent(void *arg)
}
/**
* \brief Adds and deletes an event watch function with NULL userdata
* Adds and deletes an event watch function with NULL userdata
*
* \sa SDL_AddEventWatch
* \sa SDL_DelEventWatch
@ -125,7 +125,7 @@ static int events_addDelEventWatch(void *arg)
}
/**
* \brief Adds and deletes an event watch function with userdata
* Adds and deletes an event watch function with userdata
*
* \sa SDL_AddEventWatch
* \sa SDL_DelEventWatch

View File

@ -70,7 +70,7 @@ upper_lower_to_bytestring(Uint8 *out, Uint64 upper, Uint64 lower)
/* Test case functions */
/**
* \brief Check String-to-GUID conversion
* Check String-to-GUID conversion
*
* \sa SDL_GUIDFromString
*/
@ -95,7 +95,7 @@ TestGuidFromString(void *arg)
}
/**
* \brief Check GUID-to-String conversion
* Check GUID-to-String conversion
*
* \sa SDL_GUIDToString
*/
@ -126,7 +126,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

@ -24,7 +24,6 @@ static const char *HintsEnum[] = {
SDL_HINT_VIDEO_ALLOW_SCREENSAVER,
SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES,
SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
SDL_HINT_VIDEO_WIN_D3DCOMPILER,
SDL_HINT_VIDEO_X11_XRANDR,
SDL_HINT_XINPUT_ENABLED,
@ -47,7 +46,6 @@ static const char *HintsVerbose[] = {
"SDL_VIDEO_ALLOW_SCREENSAVER",
"SDL_VIDEO_MAC_FULLSCREEN_SPACES",
"SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
"SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
"SDL_VIDEO_WIN_D3DCOMPILER",
"SDL_VIDEO_X11_XRANDR",
"SDL_XINPUT_ENABLED"
@ -60,7 +58,7 @@ static const int numHintsEnum = SDL_arraysize(HintsEnum);
/* Test case functions */
/**
* \brief Call to SDL_GetHint
* Call to SDL_GetHint
*/
static int hints_getHint(void *arg)
{
@ -89,7 +87,7 @@ static void SDLCALL hints_testHintChanged(void *userdata, const char *name, cons
}
/**
* \brief Call to SDL_SetHint
* Call to SDL_SetHint
*/
static int hints_setHint(void *arg)
{

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -528,7 +528,7 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlit = {
};
/**
* \brief Returns the Blit test image as SDL_Surface.
* Returns the Blit test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlit(void)
{
@ -1000,7 +1000,7 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitColor = {
};
/**
* \brief Returns the BlitColor test image as SDL_Surface.
* Returns the BlitColor test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitColor(void)
{
@ -1635,7 +1635,7 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitAlpha = {
};
/**
* \brief Returns the BlitAlpha test image as SDL_Surface.
* Returns the BlitAlpha test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitAlpha(void)
{
@ -2203,7 +2203,7 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAdd = {
};
/**
* \brief Returns the BlitBlendAdd test image as SDL_Surface.
* Returns the BlitBlendAdd test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitBlendAdd(void)
{
@ -2792,7 +2792,7 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlend = {
};
/**
* \brief Returns the BlitBlend test image as SDL_Surface.
* Returns the BlitBlend test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitBlend(void)
{
@ -3211,7 +3211,7 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendMod = {
};
/**
* \brief Returns the BlitBlendMod test image as SDL_Surface.
* Returns the BlitBlendMod test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitBlendMod(void)
{
@ -4013,7 +4013,7 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendNone = {
};
/**
* \brief Returns the BlitBlendNone test image as SDL_Surface.
* Returns the BlitBlendNone test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitBlendNone(void)
{
@ -4547,7 +4547,7 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAll = {
};
/**
* \brief Returns the BlitBlendAll test image as SDL_Surface.
* Returns the BlitBlendAll test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageBlitBlendAll(void)
{
@ -4758,7 +4758,7 @@ static const SDLTest_SurfaceImage_t SDLTest_imageFace = {
};
/**
* \brief Returns the Face test image as SDL_Surface.
* Returns the Face test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImageFace(void)
{
@ -5251,7 +5251,7 @@ static const SDLTest_SurfaceImage_t SDLTest_imagePrimitives = {
};
/**
* \brief Returns the Primitives test image as SDL_Surface.
* Returns the Primitives test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImagePrimitives(void)
{
@ -5916,7 +5916,7 @@ static const SDLTest_SurfaceImage_t SDLTest_imagePrimitivesBlend = {
};
/**
* \brief Returns the PrimitivesBlend test image as SDL_Surface.
* Returns the PrimitivesBlend test image as SDL_Surface.
*/
SDL_Surface *SDLTest_ImagePrimitivesBlend(void)
{

View File

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

@ -86,7 +86,7 @@ static void free_arrays(void *dest, void *a, void *b) {
}
/**
* \brief Verify element-wise addition of 2 int arrays.
* Verify element-wise addition of 2 int arrays.
*/
static void verify_ints_addition(const Sint32 *dest, const Sint32 *a, const Sint32 *b, size_t size, const char *desc) {
size_t i;
@ -106,7 +106,7 @@ static void verify_ints_addition(const Sint32 *dest, const Sint32 *a, const Sint
}
/**
* \brief Verify element-wise multiplication of 2 int arrays.
* Verify element-wise multiplication of 2 int arrays.
*/
static void verify_ints_multiplication(const Sint32 *dest, const Sint32 *a, const Sint32 *b, size_t size, const char *desc) {
size_t i;
@ -126,7 +126,7 @@ static void verify_ints_multiplication(const Sint32 *dest, const Sint32 *a, cons
}
/**
* \brief Verify element-wise addition of 2 float arrays.
* Verify element-wise addition of 2 float arrays.
*/
static void verify_floats_addition(const float *dest, const float *a, const float *b, size_t size, const char *desc) {
size_t i;
@ -147,7 +147,7 @@ static void verify_floats_addition(const float *dest, const float *a, const floa
}
/**
* \brief Verify element-wise addition of 2 double arrays.
* Verify element-wise addition of 2 double arrays.
*/
static void verify_doubles_addition(const double *dest, const double *a, const double *b, size_t size, const char *desc) {
size_t i;

View File

@ -12,7 +12,7 @@
/* Test case functions */
/**
* \brief Check virtual joystick creation
* Check virtual joystick creation
*
* \sa SDL_AttachVirtualJoystickEx
*/
@ -20,6 +20,7 @@ static int TestVirtualJoystick(void *arg)
{
SDL_VirtualJoystickDesc desc;
SDL_Joystick *joystick = NULL;
SDL_Gamepad *gamepad = NULL;
SDL_JoystickID device_id;
SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMEPAD) == 0, "SDL_InitSubSystem(SDL_INIT_GAMEPAD)");
@ -52,13 +53,65 @@ static int TestVirtualJoystick(void *arg)
SDLTest_AssertCheck(SDL_GetNumJoystickHats(joystick) == desc.nhats, "SDL_GetNumJoystickHats()");
SDLTest_AssertCheck(SDL_GetNumJoystickButtons(joystick) == desc.nbuttons, "SDL_GetNumJoystickButtons()");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_A, SDL_PRESSED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_A, SDL_PRESSED)");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_GAMEPAD_BUTTON_A) == SDL_PRESSED, "SDL_GetJoystickButton(SDL_GAMEPAD_BUTTON_A) == SDL_PRESSED");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_A, SDL_RELEASED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_A, SDL_RELEASED)");
SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED, "SDL_GetJoystickButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_GAMEPAD_BUTTON_A) == SDL_RELEASED, "SDL_GetJoystickButton(SDL_GAMEPAD_BUTTON_A) == SDL_RELEASED");
SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED, "SDL_GetJoystickButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED");
gamepad = SDL_OpenGamepad(SDL_GetJoystickInstanceID(joystick));
SDLTest_AssertCheck(gamepad != NULL, "SDL_OpenGamepad() succeeded");
if (gamepad) {
SDLTest_AssertCheck(SDL_strcmp(SDL_GetGamepadName(gamepad), desc.name) == 0, "SDL_GetGamepadName()");
SDLTest_AssertCheck(SDL_GetGamepadVendor(gamepad) == desc.vendor_id, "SDL_GetGamepadVendor()");
SDLTest_AssertCheck(SDL_GetGamepadProduct(gamepad) == desc.product_id, "SDL_GetGamepadProduct()");
/* Set an explicit mapping with a different name */
SDL_SetGamepadMapping(SDL_GetJoystickInstanceID(joystick), "ff0013db5669727475616c2043007601,Virtual Gamepad,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetGamepadName(gamepad), "Virtual Gamepad") == 0, "SDL_GetGamepadName() == Virtual Gamepad");
SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_A, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_A");
/* Set the south button and verify that the gamepad responds */
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED");
/* Set an explicit mapping with legacy Nintendo style buttons */
SDL_SetGamepadMapping(SDL_GetJoystickInstanceID(joystick), "ff0013db5669727475616c2043007601,Virtual Nintendo Gamepad,a:b1,b:b0,x:b3,y:b2,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetGamepadName(gamepad), "Virtual Nintendo Gamepad") == 0, "SDL_GetGamepadName() == Virtual Nintendo Gamepad");
SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_B, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_B");
/* Set the south button and verify that the gamepad responds */
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED");
/* Set an explicit mapping with PS4 style buttons */
SDL_SetGamepadMapping(SDL_GetJoystickInstanceID(joystick), "ff0013db5669727475616c2043007601,Virtual PS4 Gamepad,type:ps4,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetGamepadName(gamepad), "Virtual PS4 Gamepad") == 0, "SDL_GetGamepadName() == Virtual PS4 Gamepad");
SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_CROSS, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_CROSS");
/* Set the south button and verify that the gamepad responds */
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED");
SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)");
SDL_UpdateJoysticks();
SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED");
SDL_CloseGamepad(gamepad);
}
SDL_CloseJoystick(joystick);
}

View File

@ -11,7 +11,7 @@
/* Test case functions */
/**
* \brief Check call to SDL_GetKeyboardState with and without numkeys reference.
* Check call to SDL_GetKeyboardState with and without numkeys reference.
*
* \sa SDL_GetKeyboardState
*/
@ -36,7 +36,7 @@ static int keyboard_getKeyboardState(void *arg)
}
/**
* \brief Check call to SDL_GetKeyboardFocus
* Check call to SDL_GetKeyboardFocus
*
* \sa SDL_GetKeyboardFocus
*/
@ -50,7 +50,7 @@ static int keyboard_getKeyboardFocus(void *arg)
}
/**
* \brief Check call to SDL_GetKeyFromName for known, unknown and invalid name.
* Check call to SDL_GetKeyFromName for known, unknown and invalid name.
*
* \sa SDL_GetKeyFromName
*/
@ -115,7 +115,7 @@ static void checkInvalidScancodeError(void)
}
/**
* \brief Check call to SDL_GetKeyFromScancode
* Check call to SDL_GetKeyFromScancode
*
* \sa SDL_GetKeyFromScancode
*/
@ -153,7 +153,7 @@ static int keyboard_getKeyFromScancode(void *arg)
}
/**
* \brief Check call to SDL_GetKeyName
* Check call to SDL_GetKeyName
*
* \sa SDL_GetKeyName
*/
@ -208,7 +208,7 @@ static int keyboard_getKeyName(void *arg)
}
/**
* \brief SDL_GetScancodeName negative cases
* SDL_GetScancodeName negative cases
*
* \sa SDL_GetScancodeName
*/
@ -234,7 +234,7 @@ static int keyboard_getScancodeNameNegative(void *arg)
}
/**
* \brief SDL_GetKeyName negative cases
* SDL_GetKeyName negative cases
*
* \sa SDL_GetKeyName
*/
@ -270,7 +270,7 @@ static int keyboard_getKeyNameNegative(void *arg)
}
/**
* \brief Check call to SDL_GetModState and SDL_SetModState
* Check call to SDL_GetModState and SDL_SetModState
*
* \sa SDL_GetModState
* \sa SDL_SetModState
@ -329,7 +329,7 @@ static int keyboard_getSetModState(void *arg)
}
/**
* \brief Check call to SDL_StartTextInput and SDL_StopTextInput
* Check call to SDL_StartTextInput and SDL_StopTextInput
*
* \sa SDL_StartTextInput
* \sa SDL_StopTextInput
@ -375,7 +375,7 @@ static void testSetTextInputRect(SDL_Rect refRect)
}
/**
* \brief Check call to SDL_SetTextInputRect
* Check call to SDL_SetTextInputRect
*
* \sa SDL_SetTextInputRect
*/
@ -454,7 +454,7 @@ static int keyboard_setTextInputRect(void *arg)
}
/**
* \brief Check call to SDL_SetTextInputRect with invalid data
* Check call to SDL_SetTextInputRect with invalid data
*
* \sa SDL_SetTextInputRect
*/
@ -491,7 +491,7 @@ static int keyboard_setTextInputRectNegative(void *arg)
}
/**
* \brief Check call to SDL_GetScancodeFromKey
* Check call to SDL_GetScancodeFromKey
*
* \sa SDL_GetScancodeFromKey
* \sa SDL_Keycode
@ -514,7 +514,7 @@ static int keyboard_getScancodeFromKey(void *arg)
}
/**
* \brief Check call to SDL_GetScancodeFromName
* Check call to SDL_GetScancodeFromName
*
* \sa SDL_GetScancodeFromName
* \sa SDL_Keycode
@ -585,7 +585,7 @@ static void checkInvalidNameError(void)
}
/**
* \brief Check call to SDL_GetScancodeFromName with invalid data
* Check call to SDL_GetScancodeFromName with invalid data
*
* \sa SDL_GetScancodeFromName
* \sa SDL_Keycode

View File

@ -11,7 +11,7 @@
#include "testautomation_suites.h"
/**
* \brief Tests SDL_InitSubSystem() and SDL_QuitSubSystem()
* Tests SDL_InitSubSystem() and SDL_QuitSubSystem()
* \sa SDL_Init
* \sa SDL_Quit
*/

View File

@ -62,7 +62,7 @@ typedef double(SDLCALL *d_to_d_func)(double);
typedef double(SDLCALL *dd_to_d_func)(double, double);
/**
* \brief Runs all the cases on a given function with a signature double -> double.
* 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.
@ -77,7 +77,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((result - cases[i].expected) < FLT_EPSILON,
"%s(%f), expected %f, got %f",
func_name,
cases[i].input,
@ -88,7 +88,7 @@ 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.
* 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.
@ -117,7 +117,7 @@ helper_dtod_inexact(const char *func_name, d_to_d_func func,
}
/**
* \brief Runs all the cases on a given function with a signature
* 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.
@ -143,7 +143,7 @@ helper_ddtod(const char *func_name, dd_to_d_func func,
}
/**
* \brief Runs all the cases on a given function with a signature
* 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.
@ -172,7 +172,7 @@ helper_ddtod_inexact(const char *func_name, dd_to_d_func func,
}
/**
* \brief Runs a range of values on a given function with a signature double -> double
* Runs a range of values on a given function with a signature double -> double
*
* This function is only meant to test functions that returns the input value if it is
* integral: f(x) -> x for x in N.
@ -1139,7 +1139,7 @@ log_baseCases(void *args)
1.0, 0.0, result);
result = SDL_log(EULER);
SDLTest_AssertCheck(1.0 == result,
SDLTest_AssertCheck((result - 1.) < FLT_EPSILON,
"Log(%f), expected %f, got %f",
EULER, 1.0, result);
@ -2275,7 +2275,7 @@ acos_limitCases(void *args)
1.0, 0.0, result);
result = SDL_acos(-1.0);
SDLTest_AssertCheck(SDL_PI_D == result,
SDLTest_AssertCheck(SDL_fabs(SDL_PI_D - result) <= EPSILON,
"Acos(%f), expected %f, got %f",
-1.0, SDL_PI_D, result);
@ -2362,12 +2362,12 @@ asin_limitCases(void *args)
double result;
result = SDL_asin(1.0);
SDLTest_AssertCheck(SDL_PI_D / 2.0 == result,
SDLTest_AssertCheck(SDL_fabs(SDL_PI_D / 2.0 - result) <= EPSILON,
"Asin(%f), expected %f, got %f",
1.0, SDL_PI_D / 2.0, result);
result = SDL_asin(-1.0);
SDLTest_AssertCheck(-SDL_PI_D / 2.0 == result,
SDLTest_AssertCheck(SDL_fabs(-SDL_PI_D / 2.0 - result) <= EPSILON,
"Asin(%f), expected %f, got %f",
-1.0, -SDL_PI_D / 2.0, result);
@ -2554,7 +2554,7 @@ atan2_bothZeroCases(void *args)
{ 0.0, -0.0, SDL_PI_D },
{ -0.0, -0.0, -SDL_PI_D },
};
return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
}
/**
@ -2573,7 +2573,7 @@ atan2_yZeroCases(void *args)
{ -0.0, 1.0, -0.0 },
{ -0.0, -1.0, -SDL_PI_D }
};
return helper_ddtod("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
return helper_ddtod_inexact("SDL_atan2", SDL_atan2, cases, SDL_arraysize(cases));
}
/**
@ -2589,7 +2589,7 @@ atan2_xZeroCases(void *args)
{ 1.0, -0.0, SDL_PI_D / 2.0 },
{ -1.0, -0.0, -SDL_PI_D / 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 */
@ -2608,22 +2608,22 @@ atan2_bothInfCases(void *args)
double result;
result = SDL_atan2(INFINITY, INFINITY);
SDLTest_AssertCheck(SDL_PI_D / 4.0 == result,
SDLTest_AssertCheck(SDL_fabs(SDL_PI_D / 4.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f",
INFINITY, INFINITY, SDL_PI_D / 4.0, result);
result = SDL_atan2(INFINITY, -INFINITY);
SDLTest_AssertCheck(3.0 * SDL_PI_D / 4.0 == result,
SDLTest_AssertCheck(SDL_fabs(3.0 * SDL_PI_D / 4.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f",
INFINITY, -INFINITY, 3.0 * SDL_PI_D / 4.0, result);
result = SDL_atan2(-INFINITY, INFINITY);
SDLTest_AssertCheck(-SDL_PI_D / 4.0 == result,
SDLTest_AssertCheck(SDL_fabs(-SDL_PI_D / 4.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f",
-INFINITY, INFINITY, -SDL_PI_D / 4.0, result);
result = SDL_atan2(-INFINITY, -INFINITY);
SDLTest_AssertCheck(-3.0 * SDL_PI_D / 4.0 == result,
SDLTest_AssertCheck(SDL_fabs(-3.0 * SDL_PI_D / 4.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f",
-INFINITY, -INFINITY, -3.0 * SDL_PI_D / 4.0, result);
@ -2640,22 +2640,22 @@ atan2_yInfCases(void *args)
double result;
result = SDL_atan2(INFINITY, 1.0);
SDLTest_AssertCheck(SDL_PI_D / 2.0 == result,
SDLTest_AssertCheck(SDL_fabs(SDL_PI_D / 2.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f",
INFINITY, 1.0, SDL_PI_D / 2.0, result);
result = SDL_atan2(INFINITY, -1.0);
SDLTest_AssertCheck(SDL_PI_D / 2.0 == result,
SDLTest_AssertCheck(SDL_fabs(SDL_PI_D / 2.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f",
INFINITY, -1.0, SDL_PI_D / 2.0, result);
result = SDL_atan2(-INFINITY, 1.0);
SDLTest_AssertCheck(-SDL_PI_D / 2.0 == result,
SDLTest_AssertCheck(SDL_fabs(-SDL_PI_D / 2.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f",
-INFINITY, 1.0, -SDL_PI_D / 2.0, result);
result = SDL_atan2(-INFINITY, -1.0);
SDLTest_AssertCheck(-SDL_PI_D / 2.0 == result,
SDLTest_AssertCheck(SDL_fabs(-SDL_PI_D / 2.0 - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f",
-INFINITY, -1.0, -SDL_PI_D / 2.0, result);
@ -2684,12 +2684,12 @@ atan2_xInfCases(void *args)
-1.0, INFINITY, -0.0, result);
result = SDL_atan2(1.0, -INFINITY);
SDLTest_AssertCheck(SDL_PI_D == result,
SDLTest_AssertCheck(SDL_fabs(SDL_PI_D - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f",
1.0, -INFINITY, SDL_PI_D, result);
result = SDL_atan2(-1.0, -INFINITY);
SDLTest_AssertCheck(-SDL_PI_D == result,
SDLTest_AssertCheck(SDL_fabs(-SDL_PI_D - result) <= EPSILON,
"Atan2(%f,%f), expected %f, got %f",
-1.0, -INFINITY, -SDL_PI_D, result);

View File

@ -25,7 +25,7 @@ static int mouseStateCheck(Uint32 state)
}
/**
* \brief Check call to SDL_GetMouseState
* Check call to SDL_GetMouseState
*
*/
static int mouse_getMouseState(void *arg)
@ -70,7 +70,7 @@ static int mouse_getMouseState(void *arg)
}
/**
* \brief Check call to SDL_GetRelativeMouseState
* Check call to SDL_GetRelativeMouseState
*
*/
static int mouse_getRelativeMouseState(void *arg)
@ -188,7 +188,7 @@ static SDL_Cursor *initArrowCursor(const char *image[])
}
/**
* \brief Check call to SDL_CreateCursor and SDL_DestroyCursor
* Check call to SDL_CreateCursor and SDL_DestroyCursor
*
* \sa SDL_CreateCursor
* \sa SDL_DestroyCursor
@ -213,7 +213,7 @@ static int mouse_createFreeCursor(void *arg)
}
/**
* \brief Check call to SDL_CreateColorCursor and SDL_DestroyCursor
* Check call to SDL_CreateColorCursor and SDL_DestroyCursor
*
* \sa SDL_CreateColorCursor
* \sa SDL_DestroyCursor
@ -269,7 +269,7 @@ static void changeCursorVisibility(SDL_bool state)
}
/**
* \brief Check call to SDL_ShowCursor
* Check call to SDL_ShowCursor
*
* \sa SDL_ShowCursor
*/
@ -294,7 +294,7 @@ static int mouse_showCursor(void *arg)
}
/**
* \brief Check call to SDL_SetCursor
* Check call to SDL_SetCursor
*
* \sa SDL_SetCursor
*/
@ -326,7 +326,7 @@ static int mouse_setCursor(void *arg)
}
/**
* \brief Check call to SDL_GetCursor
* Check call to SDL_GetCursor
*
* \sa SDL_GetCursor
*/
@ -343,7 +343,7 @@ static int mouse_getCursor(void *arg)
}
/**
* \brief Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode
* Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode
*
* \sa SDL_GetRelativeMouseMode
* \sa SDL_SetRelativeMouseMode
@ -418,7 +418,7 @@ static SDL_Window *createMouseSuiteTestWindow(void)
*/
static void destroyMouseSuiteTestWindow(SDL_Window *window)
{
if (window != NULL) {
if (window) {
SDL_DestroyWindow(window);
window = NULL;
SDLTest_AssertPass("SDL_DestroyWindow()");
@ -426,7 +426,7 @@ static void destroyMouseSuiteTestWindow(SDL_Window *window)
}
/**
* \brief Check call to SDL_WarpMouseInWindow
* Check call to SDL_WarpMouseInWindow
*
* \sa SDL_WarpMouseInWindow
*/
@ -454,7 +454,7 @@ static int mouse_warpMouseInWindow(void *arg)
yPositions[5] = (float)h + 1;
/* Create test window */
window = createMouseSuiteTestWindow();
if (window == NULL) {
if (!window) {
return TEST_ABORTED;
}
@ -489,7 +489,7 @@ static int mouse_warpMouseInWindow(void *arg)
}
/**
* \brief Check call to SDL_GetMouseFocus
* Check call to SDL_GetMouseFocus
*
* \sa SDL_GetMouseFocus
*/
@ -499,6 +499,7 @@ static int mouse_getMouseFocus(void *arg)
float 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();
@ -506,32 +507,37 @@ static 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 = (float)SDLTest_RandomIntegerInRange(1, w - 1);
y = (float)SDLTest_RandomIntegerInRange(1, h - 1);
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%.f,%.f)", 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 = (float)SDLTest_RandomIntegerInRange(1, w - 1);
y = (float)SDLTest_RandomIntegerInRange(1, h - 1);
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%.f,%.f)", 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 = (float)SDLTest_RandomIntegerInRange(-9, -1);
y = (float)SDLTest_RandomIntegerInRange(-9, -1);
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%.f,%.f)", x, y);
/* Mouse to random position outside window */
x = (float)SDLTest_RandomIntegerInRange(-9, -1);
y = (float)SDLTest_RandomIntegerInRange(-9, -1);
SDL_WarpMouseInWindow(window, x, y);
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%.f,%.f)", x, y);
} else {
SDLTest_Log("Skipping mouse warp focus tests: Wayland does not support warping the mouse pointer");
}
/* Clean up test window */
destroyMouseSuiteTestWindow(window);
@ -549,7 +555,7 @@ static int mouse_getMouseFocus(void *arg)
}
/**
* \brief Check call to SDL_GetDefaultCursor
* Check call to SDL_GetDefaultCursor
*
* \sa SDL_GetDefaultCursor
*/
@ -566,7 +572,7 @@ static int mouse_getDefaultCursor(void *arg)
}
/**
* \brief Check call to SDL_GetGlobalMouseState
* Check call to SDL_GetGlobalMouseState
*
* \sa SDL_GetGlobalMouseState
*/

1909
external/sdl/SDL/test/testautomation_pen.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,8 @@
static const Uint32 g_AllFormats[] = {
SDL_PIXELFORMAT_INDEX1LSB,
SDL_PIXELFORMAT_INDEX1MSB,
SDL_PIXELFORMAT_INDEX2LSB,
SDL_PIXELFORMAT_INDEX2MSB,
SDL_PIXELFORMAT_INDEX4LSB,
SDL_PIXELFORMAT_INDEX4MSB,
SDL_PIXELFORMAT_INDEX8,
@ -39,7 +41,10 @@ static const Uint32 g_AllFormats[] = {
SDL_PIXELFORMAT_RGBA8888,
SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_XRGB2101010,
SDL_PIXELFORMAT_XBGR2101010,
SDL_PIXELFORMAT_ARGB2101010,
SDL_PIXELFORMAT_ABGR2101010,
SDL_PIXELFORMAT_YV12,
SDL_PIXELFORMAT_IYUV,
SDL_PIXELFORMAT_YUY2,
@ -53,6 +58,8 @@ static const int g_numAllFormats = SDL_arraysize(g_AllFormats);
static const char *g_AllFormatsVerbose[] = {
"SDL_PIXELFORMAT_INDEX1LSB",
"SDL_PIXELFORMAT_INDEX1MSB",
"SDL_PIXELFORMAT_INDEX2LSB",
"SDL_PIXELFORMAT_INDEX2MSB",
"SDL_PIXELFORMAT_INDEX4LSB",
"SDL_PIXELFORMAT_INDEX4MSB",
"SDL_PIXELFORMAT_INDEX8",
@ -81,7 +88,10 @@ static const char *g_AllFormatsVerbose[] = {
"SDL_PIXELFORMAT_RGBA8888",
"SDL_PIXELFORMAT_ABGR8888",
"SDL_PIXELFORMAT_BGRA8888",
"SDL_PIXELFORMAT_XRGB2101010",
"SDL_PIXELFORMAT_XBGR2101010",
"SDL_PIXELFORMAT_ARGB2101010",
"SDL_PIXELFORMAT_ABGR2101010",
"SDL_PIXELFORMAT_YV12",
"SDL_PIXELFORMAT_IYUV",
"SDL_PIXELFORMAT_YUY2",
@ -105,7 +115,7 @@ static const char *g_invalidPixelFormatsVerbose[] = {
/* Test case functions */
/**
* \brief Call to SDL_CreatePixelFormat and SDL_DestroyPixelFormat
* Call to SDL_CreatePixelFormat and SDL_DestroyPixelFormat
*
* \sa SDL_CreatePixelFormat
* \sa SDL_DestroyPixelFormat
@ -198,7 +208,7 @@ static int pixels_allocFreeFormat(void *arg)
}
/**
* \brief Call to SDL_GetPixelFormatName
* Call to SDL_GetPixelFormatName
*
* \sa SDL_GetPixelFormatName
*/
@ -265,7 +275,7 @@ static int pixels_getPixelFormatName(void *arg)
}
/**
* \brief Call to SDL_CreatePalette and SDL_DestroyPalette
* Call to SDL_CreatePalette and SDL_DestroyPalette
*
* \sa SDL_CreatePalette
* \sa SDL_DestroyPalette

View File

@ -11,7 +11,7 @@
/* Helper functions */
/**
* \brief Compare sizes of types.
* Compare sizes of types.
*
* @note Watcom C flags these as Warning 201: "Unreachable code" if you just
* compare them directly, so we push it through a function to keep the
@ -25,7 +25,7 @@ static int compareSizeOfType(size_t sizeoftype, size_t hardcodetype)
/* Test case functions */
/**
* \brief Tests type sizes.
* Tests type sizes.
*/
static int platform_testTypes(void *arg)
{
@ -47,7 +47,7 @@ static int platform_testTypes(void *arg)
}
/**
* \brief Tests platform endianness and SDL_SwapXY functions.
* Tests platform endianness and SDL_SwapXY functions.
*/
static int platform_testEndianessAndSwap(void *arg)
{
@ -118,7 +118,7 @@ static int platform_testEndianessAndSwap(void *arg)
}
/**
* \brief Tests SDL_GetXYZ() functions
* Tests SDL_GetXYZ() functions
* \sa SDL_GetPlatform
* \sa SDL_GetCPUCount
* \sa SDL_GetRevision
@ -162,7 +162,7 @@ static int platform_testGetFunctions(void *arg)
}
/**
* \brief Tests SDL_HasXYZ() functions
* Tests SDL_HasXYZ() functions
* \sa SDL_HasAltiVec
* \sa SDL_HasMMX
* \sa SDL_HasSSE
@ -204,7 +204,7 @@ static int platform_testHasFunctions(void *arg)
}
/**
* \brief Tests SDL_GetVersion
* Tests SDL_GetVersion
* \sa SDL_GetVersion
*/
static int platform_testGetVersion(void *arg)
@ -227,7 +227,7 @@ static int platform_testGetVersion(void *arg)
}
/**
* \brief Tests SDL_VERSION macro
* Tests SDL_VERSION macro
*/
static int platform_testSDLVersion(void *arg)
{
@ -249,7 +249,7 @@ static int platform_testSDLVersion(void *arg)
}
/**
* \brief Tests default SDL_Init
* Tests default SDL_Init
*/
static int platform_testDefaultInit(void *arg)
{
@ -271,7 +271,7 @@ static int platform_testDefaultInit(void *arg)
}
/**
* \brief Tests SDL_Get/Set/ClearError
* Tests SDL_Get/Set/ClearError
* \sa SDL_GetError
* \sa SDL_SetError
* \sa SDL_ClearError
@ -322,7 +322,7 @@ static int platform_testGetSetClearError(void *arg)
}
/**
* \brief Tests SDL_SetError with empty input
* Tests SDL_SetError with empty input
* \sa SDL_SetError
*/
static int platform_testSetErrorEmptyInput(void *arg)
@ -363,13 +363,13 @@ static int platform_testSetErrorEmptyInput(void *arg)
#endif
/**
* \brief Tests SDL_SetError with invalid input
* Tests SDL_SetError with invalid input
* \sa SDL_SetError
*/
static int platform_testSetErrorInvalidInput(void *arg)
{
int result;
const char *invalidError = NULL;
const char *invalidError = "";
const char *probeError = "Testing";
const char *lastError;
size_t len;
@ -446,7 +446,7 @@ static int platform_testSetErrorInvalidInput(void *arg)
#endif
/**
* \brief Tests SDL_GetPowerInfo
* Tests SDL_GetPowerInfo
* \sa SDL_GetPowerInfo
*/
static int platform_testGetPowerInfo(void *arg)

View File

@ -0,0 +1,350 @@
/**
* Properties test suite
*/
#include <SDL3/SDL.h>
#include <SDL3/SDL_test.h>
#include "testautomation_suites.h"
/* Test case functions */
/**
* Test basic functionality
*/
static void SDLCALL count_properties(void *userdata, SDL_PropertiesID props, const char *name)
{
int *count = (int *)userdata;
++(*count);
}
static void SDLCALL count_foo_properties(void *userdata, SDL_PropertiesID props, const char *name)
{
int *count = (int *)userdata;
if (SDL_strcmp(name, "foo") == 0) {
++(*count);
}
}
static int properties_testBasic(void *arg)
{
SDL_PropertiesID props;
char key[2], expected_value[2];
SDL_PropertyType type;
void *value;
const char *value_string;
Sint64 value_number;
float value_float;
SDL_bool value_bool;
int i, result, count;
props = SDL_CreateProperties();
SDLTest_AssertPass("Call to SDL_CreateProperties()");
SDLTest_AssertCheck(props != 0,
"Verify props were created, got: %" SDL_PRIu32 "", props);
for (i = 0; i < 10; ++i) {
SDL_snprintf(key, SDL_arraysize(key), "%c", 'a' + i);
SDL_snprintf(expected_value, SDL_arraysize(expected_value), "%c", 'a' + i);
result = SDL_SetProperty(props, key, expected_value);
SDLTest_AssertPass("Call to SDL_SetProperty()");
SDLTest_AssertCheck(result == 0,
"Verify property value was set, got: %d", result);
value = SDL_GetProperty(props, key, NULL);
SDLTest_AssertPass("Call to SDL_GetProperty()");
SDLTest_AssertCheck(value && SDL_strcmp((const char *)value, expected_value) == 0,
"Verify property value was set, got %s, expected %s", value ? (const char *)value : "NULL", expected_value);
}
count = 0;
SDL_EnumerateProperties(props, count_properties, &count);
SDLTest_AssertCheck(count == 10,
"Verify property count, expected 10, got: %d", count);
for (i = 0; i < 10; ++i) {
SDL_snprintf(key, SDL_arraysize(key), "%c", 'a' + i);
result = SDL_SetProperty(props, key, NULL);
SDLTest_AssertPass("Call to SDL_SetProperty(NULL)");
SDLTest_AssertCheck(result == 0,
"Verify property value was set, got: %d", result);
value = SDL_GetProperty(props, key, NULL);
SDLTest_AssertPass("Call to SDL_GetProperty()");
SDLTest_AssertCheck(value == NULL,
"Verify property value was set, got %s, expected NULL", (const char *)value);
}
count = 0;
SDL_EnumerateProperties(props, count_properties, &count);
SDLTest_AssertCheck(count == 0,
"Verify property count, expected 0, got: %d", count);
/* Check default values */
value = SDL_GetProperty(props, "foo", (void *)0xabcd);
SDLTest_AssertCheck(value == (void *)0xabcd,
"Verify property, expected 0xabcd, got: %p", value);
value_string = SDL_GetStringProperty(props, "foo", "abcd");
SDLTest_AssertCheck(value_string && SDL_strcmp(value_string, "abcd") == 0,
"Verify string property, expected abcd, got: %s", value_string);
value_number = SDL_GetNumberProperty(props, "foo", 1234);
SDLTest_AssertCheck(value_number == 1234,
"Verify number property, expected 1234, got: %" SDL_PRIu64 "", value_number);
value_float = SDL_GetFloatProperty(props, "foo", 1234.0f);
SDLTest_AssertCheck(value_float == 1234.0f,
"Verify float property, expected 1234, got: %f", value_float);
value_bool = SDL_GetBooleanProperty(props, "foo", SDL_TRUE);
SDLTest_AssertCheck(value_bool == SDL_TRUE,
"Verify boolean property, expected SDL_TRUE, got: %s", value_bool ? "SDL_TRUE" : "SDL_FALSE");
/* Check data value */
SDLTest_AssertPass("Call to SDL_SetProperty(\"foo\", 0x01)");
SDL_SetProperty(props, "foo", (void *)0x01);
type = SDL_GetPropertyType(props, "foo");
SDLTest_AssertCheck(type == SDL_PROPERTY_TYPE_POINTER,
"Verify property type, expected %d, got: %d", SDL_PROPERTY_TYPE_POINTER, type);
value = SDL_GetProperty(props, "foo", NULL);
SDLTest_AssertCheck(value == (void *)0x01,
"Verify property, expected 0x01, got: %p", value);
value_string = SDL_GetStringProperty(props, "foo", NULL);
SDLTest_AssertCheck(value_string == NULL,
"Verify string property, expected NULL, got: %s", value_string);
value_number = SDL_GetNumberProperty(props, "foo", 0);
SDLTest_AssertCheck(value_number == 0,
"Verify number property, expected 0, got: %" SDL_PRIu64 "", value_number);
value_float = SDL_GetFloatProperty(props, "foo", 0.0f);
SDLTest_AssertCheck(value_float == 0.0f,
"Verify float property, expected 0, got: %f", value_float);
value_bool = SDL_GetBooleanProperty(props, "foo", SDL_FALSE);
SDLTest_AssertCheck(value_bool == SDL_FALSE,
"Verify boolean property, expected SDL_FALSE, got: %s", value_bool ? "SDL_TRUE" : "SDL_FALSE");
/* Check string value */
SDLTest_AssertPass("Call to SDL_SetStringProperty(\"foo\", \"bar\")");
SDL_SetStringProperty(props, "foo", "bar");
type = SDL_GetPropertyType(props, "foo");
SDLTest_AssertCheck(type == SDL_PROPERTY_TYPE_STRING,
"Verify property type, expected %d, got: %d", SDL_PROPERTY_TYPE_STRING, type);
value = SDL_GetProperty(props, "foo", NULL);
SDLTest_AssertCheck(value == NULL,
"Verify property, expected NULL, got: %p", value);
value_string = SDL_GetStringProperty(props, "foo", NULL);
SDLTest_AssertCheck(value_string != NULL && SDL_strcmp(value_string, "bar") == 0,
"Verify string property, expected bar, got: %s", value_string);
value_number = SDL_GetNumberProperty(props, "foo", 0);
SDLTest_AssertCheck(value_number == 0,
"Verify number property, expected 0, got: %" SDL_PRIu64 "", value_number);
value_float = SDL_GetFloatProperty(props, "foo", 0.0f);
SDLTest_AssertCheck(value_float == 0.0f,
"Verify float property, expected 0, got: %f", value_float);
value_bool = SDL_GetBooleanProperty(props, "foo", SDL_FALSE);
SDLTest_AssertCheck(value_bool == SDL_TRUE,
"Verify boolean property, expected SDL_TRUE, got: %s", value_bool ? "SDL_TRUE" : "SDL_FALSE");
/* Check number value */
SDLTest_AssertPass("Call to SDL_SetNumberProperty(\"foo\", 1)");
SDL_SetNumberProperty(props, "foo", 1);
type = SDL_GetPropertyType(props, "foo");
SDLTest_AssertCheck(type == SDL_PROPERTY_TYPE_NUMBER,
"Verify property type, expected %d, got: %d", SDL_PROPERTY_TYPE_NUMBER, type);
value = SDL_GetProperty(props, "foo", NULL);
SDLTest_AssertCheck(value == NULL,
"Verify property, expected NULL, got: %p", value);
value_string = SDL_GetStringProperty(props, "foo", NULL);
SDLTest_AssertCheck(value_string && SDL_strcmp(value_string, "1") == 0,
"Verify string property, expected 1, got: %s", value_string);
value_number = SDL_GetNumberProperty(props, "foo", 0);
SDLTest_AssertCheck(value_number == 1,
"Verify number property, expected 1, got: %" SDL_PRIu64 "", value_number);
value_float = SDL_GetFloatProperty(props, "foo", 0.0f);
SDLTest_AssertCheck(value_float == 1.0f,
"Verify float property, expected 1, got: %f", value_float);
value_bool = SDL_GetBooleanProperty(props, "foo", SDL_FALSE);
SDLTest_AssertCheck(value_bool == SDL_TRUE,
"Verify boolean property, expected SDL_TRUE, got: %s", value_bool ? "SDL_TRUE" : "SDL_FALSE");
/* Check float value */
SDLTest_AssertPass("Call to SDL_SetFloatProperty(\"foo\", 1)");
SDL_SetFloatProperty(props, "foo", 1.75f);
type = SDL_GetPropertyType(props, "foo");
SDLTest_AssertCheck(type == SDL_PROPERTY_TYPE_FLOAT,
"Verify property type, expected %d, got: %d", SDL_PROPERTY_TYPE_FLOAT, type);
value = SDL_GetProperty(props, "foo", NULL);
SDLTest_AssertCheck(value == NULL,
"Verify property, expected NULL, got: %p", value);
value_string = SDL_GetStringProperty(props, "foo", NULL);
SDLTest_AssertCheck(value_string && SDL_strcmp(value_string, "1.750000") == 0,
"Verify string property, expected 1.750000, got: %s", value_string);
value_number = SDL_GetNumberProperty(props, "foo", 0);
SDLTest_AssertCheck(value_number == 2,
"Verify number property, expected 2, got: %" SDL_PRIu64 "", value_number);
value_float = SDL_GetFloatProperty(props, "foo", 0.0f);
SDLTest_AssertCheck(value_float == 1.75f,
"Verify float property, expected 1.75, got: %f", value_float);
value_bool = SDL_GetBooleanProperty(props, "foo", SDL_FALSE);
SDLTest_AssertCheck(value_bool == SDL_TRUE,
"Verify boolean property, expected SDL_TRUE, got: %s", value_bool ? "SDL_TRUE" : "SDL_FALSE");
/* Check boolean value */
SDLTest_AssertPass("Call to SDL_SetBooleanProperty(\"foo\", SDL_TRUE)");
SDL_SetBooleanProperty(props, "foo", 3); /* Note we're testing non-true/false value here */
type = SDL_GetPropertyType(props, "foo");
SDLTest_AssertCheck(type == SDL_PROPERTY_TYPE_BOOLEAN,
"Verify property type, expected %d, got: %d", SDL_PROPERTY_TYPE_BOOLEAN, type);
value = SDL_GetProperty(props, "foo", NULL);
SDLTest_AssertCheck(value == NULL,
"Verify property, expected NULL, got: %p", value);
value_string = SDL_GetStringProperty(props, "foo", NULL);
SDLTest_AssertCheck(value_string && SDL_strcmp(value_string, "true") == 0,
"Verify string property, expected true, got: %s", value_string);
value_number = SDL_GetNumberProperty(props, "foo", 0);
SDLTest_AssertCheck(value_number == 1,
"Verify number property, expected 1, got: %" SDL_PRIu64 "", value_number);
value_float = SDL_GetFloatProperty(props, "foo", 0.0f);
SDLTest_AssertCheck(value_float == 1.0f,
"Verify float property, expected 1, got: %f", value_float);
value_bool = SDL_GetBooleanProperty(props, "foo", SDL_FALSE);
SDLTest_AssertCheck(value_bool == SDL_TRUE,
"Verify boolean property, expected SDL_TRUE, got: %s", value_bool ? "SDL_TRUE" : "SDL_FALSE");
/* Make sure we have exactly one property named foo */
count = 0;
SDL_EnumerateProperties(props, count_foo_properties, &count);
SDLTest_AssertCheck(count == 1,
"Verify foo property count, expected 1, got: %d", count);
SDL_DestroyProperties(props);
return TEST_COMPLETED;
}
/**
* Test cleanup functionality
*/
static void SDLCALL cleanup(void *userdata, void *value)
{
int *count = (int *)userdata;
++(*count);
}
static int properties_testCleanup(void *arg)
{
SDL_PropertiesID props;
char key[2], expected_value[2];
int i, count;
props = SDL_CreateProperties();
SDLTest_AssertPass("Call to SDL_SetProperty(cleanup)");
count = 0;
SDL_SetPropertyWithCleanup(props, "a", "0", cleanup, &count);
SDL_SetPropertyWithCleanup(props, "a", NULL, cleanup, &count);
SDLTest_AssertCheck(count == 1,
"Verify cleanup for deleting property, got %d, expected 1", count);
SDLTest_AssertPass("Call to SDL_DestroyProperties()");
count = 0;
for (i = 0; i < 10; ++i) {
SDL_snprintf(key, SDL_arraysize(key), "%c", 'a' + i);
SDL_snprintf(expected_value, SDL_arraysize(expected_value), "%c", 'a' + i);
SDL_SetPropertyWithCleanup(props, key, expected_value, cleanup, &count);
}
SDL_DestroyProperties(props);
SDLTest_AssertCheck(count == 10,
"Verify cleanup for destroying properties, got %d, expected 10", count);
return TEST_COMPLETED;
}
/**
* Test locking functionality
*/
struct properties_thread_data
{
SDL_bool done;
SDL_PropertiesID props;
};
static int properties_thread(void *arg)
{
struct properties_thread_data *data = (struct properties_thread_data *)arg;
while (!data->done) {
SDL_LockProperties(data->props);
SDL_SetProperty(data->props, "a", "thread_loop");
SDL_UnlockProperties(data->props);
}
SDL_LockProperties(data->props);
SDL_SetProperty(data->props, "a", "thread_done");
SDL_UnlockProperties(data->props);
return 0;
}
static int properties_testLocking(void *arg)
{
struct properties_thread_data data;
SDL_Thread *thread;
void *value;
SDLTest_AssertPass("Testing property locking");
data.done = SDL_FALSE;
data.props = SDL_CreateProperties();
SDLTest_AssertPass("Setting property to 'init'");
SDL_SetProperty(data.props, "a", "init");
thread = SDL_CreateThread(properties_thread, "properties_thread", &data);
if (thread) {
SDLTest_AssertPass("Waiting for property to change to 'thread_loop'");
for ( ; ; )
{
SDL_Delay(10);
SDL_LockProperties(data.props);
value = SDL_GetProperty(data.props, "a", NULL);
SDL_UnlockProperties(data.props);
if (!value || SDL_strcmp((const char *)value, "thread_loop") == 0) {
break;
}
}
SDLTest_AssertCheck(value && SDL_strcmp((const char *)value, "thread_loop") == 0,
"After thread loop, property is %s, expected 'thread_loop'", value ? (const char *)value : "NULL");
SDLTest_AssertPass("Setting property to 'main'");
SDL_LockProperties(data.props);
SDL_SetProperty(data.props, "a", "main");
SDL_Delay(100);
value = SDL_GetProperty(data.props, "a", NULL);
SDLTest_AssertCheck(value && SDL_strcmp((const char *)value, "main") == 0,
"After 100ms sleep, property is %s, expected 'main'", value ? (const char *)value : "NULL");
SDL_UnlockProperties(data.props);
data.done = SDL_TRUE;
SDL_WaitThread(thread, NULL);
value = SDL_GetProperty(data.props, "a", NULL);
SDLTest_AssertCheck(value && SDL_strcmp((const char *)value, "thread_done") == 0,
"After thread complete, property is %s, expected 'thread_done'", value ? (const char *)value : "NULL");
}
SDL_DestroyProperties(data.props);
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Properties test cases */
static const SDLTest_TestCaseReference propertiesTest1 = {
(SDLTest_TestCaseFp)properties_testBasic, "properties_testBasic", "Test basic property functionality", TEST_ENABLED
};
static const SDLTest_TestCaseReference propertiesTest2 = {
(SDLTest_TestCaseFp)properties_testCleanup, "properties_testCleanup", "Test property cleanup functionality", TEST_ENABLED
};
static const SDLTest_TestCaseReference propertiesTest3 = {
(SDLTest_TestCaseFp)properties_testLocking, "properties_testLocking", "Test property locking functionality", TEST_ENABLED
};
/* Sequence of Properties test cases */
static const SDLTest_TestCaseReference *propertiesTests[] = {
&propertiesTest1, &propertiesTest2, &propertiesTest3, NULL
};
/* Properties test suite (global) */
SDLTest_TestSuiteReference propertiesTestSuite = {
"Properties",
NULL,
propertiesTests,
NULL
};

View File

@ -11,7 +11,7 @@
/* Helper functions */
/**
* \brief Private helper to check SDL_GetRectAndLineIntersection results
* Private helper to check SDL_GetRectAndLineIntersection results
*/
static void validateIntersectRectAndLineResults(
SDL_bool intersection, SDL_bool expectedIntersection,
@ -38,7 +38,7 @@ static void validateIntersectRectAndLineResults(
/* Test case functions */
/**
* \brief Tests SDL_GetRectAndLineIntersection() clipping cases
* Tests SDL_GetRectAndLineIntersection() clipping cases
*
* \sa SDL_GetRectAndLineIntersection
*/
@ -107,7 +107,7 @@ static int rect_testIntersectRectAndLine(void *arg)
}
/**
* \brief Tests SDL_GetRectAndLineIntersection() non-clipping case line inside
* Tests SDL_GetRectAndLineIntersection() non-clipping case line inside
*
* \sa SDL_GetRectAndLineIntersection
*/
@ -172,7 +172,7 @@ static int rect_testIntersectRectAndLineInside(void *arg)
}
/**
* \brief Tests SDL_GetRectAndLineIntersection() non-clipping cases outside
* Tests SDL_GetRectAndLineIntersection() non-clipping cases outside
*
* \sa SDL_GetRectAndLineIntersection
*/
@ -225,7 +225,7 @@ static int rect_testIntersectRectAndLineOutside(void *arg)
}
/**
* \brief Tests SDL_GetRectAndLineIntersection() with empty rectangle
* Tests SDL_GetRectAndLineIntersection() with empty rectangle
*
* \sa SDL_GetRectAndLineIntersection
*/
@ -258,7 +258,7 @@ static int rect_testIntersectRectAndLineEmpty(void *arg)
}
/**
* \brief Negative tests against SDL_GetRectAndLineIntersection() with invalid parameters
* Negative tests against SDL_GetRectAndLineIntersection() with invalid parameters
*
* \sa SDL_GetRectAndLineIntersection
*/
@ -291,7 +291,7 @@ static int rect_testIntersectRectAndLineParam(void *arg)
}
/**
* \brief Private helper to check SDL_HasRectIntersection results
* Private helper to check SDL_HasRectIntersection results
*/
static void validateHasIntersectionResults(
SDL_bool intersection, SDL_bool expectedIntersection,
@ -314,7 +314,7 @@ static void validateHasIntersectionResults(
}
/**
* \brief Private helper to check SDL_GetRectIntersection results
* Private helper to check SDL_GetRectIntersection results
*/
static void validateIntersectRectResults(
SDL_bool intersection, SDL_bool expectedIntersection,
@ -333,7 +333,7 @@ static void validateIntersectRectResults(
}
/**
* \brief Private helper to check SDL_GetRectUnion results
* Private helper to check SDL_GetRectUnion results
*/
static void validateUnionRectResults(
SDL_Rect *rectA, SDL_Rect *rectB, SDL_Rect *refRectA, SDL_Rect *refRectB,
@ -356,7 +356,7 @@ static void validateUnionRectResults(
}
/**
* \brief Private helper to check SDL_RectEmpty results
* Private helper to check SDL_RectEmpty results
*/
static void validateRectEmptyResults(
SDL_bool empty, SDL_bool expectedEmpty,
@ -374,7 +374,7 @@ static void validateRectEmptyResults(
}
/**
* \brief Private helper to check SDL_RectsEqual results
* Private helper to check SDL_RectsEqual results
*/
static void validateRectEqualsResults(
SDL_bool equals, SDL_bool expectedEquals,
@ -397,7 +397,7 @@ static void validateRectEqualsResults(
}
/**
* \brief Private helper to check SDL_RectsEqualFloat results
* Private helper to check SDL_RectsEqualFloat results
*/
static void validateFRectEqualsResults(
SDL_bool equals, SDL_bool expectedEquals,
@ -423,7 +423,7 @@ static void validateFRectEqualsResults(
}
/**
* \brief Tests SDL_GetRectIntersection() with B fully inside A
* Tests SDL_GetRectIntersection() with B fully inside A
*
* \sa SDL_GetRectIntersection
*/
@ -450,7 +450,7 @@ static int rect_testIntersectRectInside(void *arg)
}
/**
* \brief Tests SDL_GetRectIntersection() with B fully outside A
* Tests SDL_GetRectIntersection() with B fully outside A
*
* \sa SDL_GetRectIntersection
*/
@ -477,7 +477,7 @@ static int rect_testIntersectRectOutside(void *arg)
}
/**
* \brief Tests SDL_GetRectIntersection() with B partially intersecting A
* Tests SDL_GetRectIntersection() with B partially intersecting A
*
* \sa SDL_GetRectIntersection
*/
@ -565,7 +565,7 @@ static int rect_testIntersectRectPartial(void *arg)
}
/**
* \brief Tests SDL_GetRectIntersection() with 1x1 pixel sized rectangles
* Tests SDL_GetRectIntersection() with 1x1 pixel sized rectangles
*
* \sa SDL_GetRectIntersection
*/
@ -611,7 +611,7 @@ static int rect_testIntersectRectPoint(void *arg)
}
/**
* \brief Tests SDL_GetRectIntersection() with empty rectangles
* Tests SDL_GetRectIntersection() with empty rectangles
*
* \sa SDL_GetRectIntersection
*/
@ -682,7 +682,7 @@ static int rect_testIntersectRectEmpty(void *arg)
}
/**
* \brief Negative tests against SDL_GetRectIntersection() with invalid parameters
* Negative tests against SDL_GetRectIntersection() with invalid parameters
*
* \sa SDL_GetRectIntersection
*/
@ -711,7 +711,7 @@ static int rect_testIntersectRectParam(void *arg)
}
/**
* \brief Tests SDL_HasRectIntersection() with B fully inside A
* Tests SDL_HasRectIntersection() with B fully inside A
*
* \sa SDL_HasRectIntersection
*/
@ -737,7 +737,7 @@ static int rect_testHasIntersectionInside(void *arg)
}
/**
* \brief Tests SDL_HasRectIntersection() with B fully outside A
* Tests SDL_HasRectIntersection() with B fully outside A
*
* \sa SDL_HasRectIntersection
*/
@ -763,7 +763,7 @@ static int rect_testHasIntersectionOutside(void *arg)
}
/**
* \brief Tests SDL_HasRectIntersection() with B partially intersecting A
* Tests SDL_HasRectIntersection() with B partially intersecting A
*
* \sa SDL_HasRectIntersection
*/
@ -829,7 +829,7 @@ static int rect_testHasIntersectionPartial(void *arg)
}
/**
* \brief Tests SDL_HasRectIntersection() with 1x1 pixel sized rectangles
* Tests SDL_HasRectIntersection() with 1x1 pixel sized rectangles
*
* \sa SDL_HasRectIntersection
*/
@ -874,7 +874,7 @@ static int rect_testHasIntersectionPoint(void *arg)
}
/**
* \brief Tests SDL_HasRectIntersection() with empty rectangles
* Tests SDL_HasRectIntersection() with empty rectangles
*
* \sa SDL_HasRectIntersection
*/
@ -931,7 +931,7 @@ static int rect_testHasIntersectionEmpty(void *arg)
}
/**
* \brief Negative tests against SDL_HasRectIntersection() with invalid parameters
* Negative tests against SDL_HasRectIntersection() with invalid parameters
*
* \sa SDL_HasRectIntersection
*/
@ -953,7 +953,7 @@ static int rect_testHasIntersectionParam(void *arg)
}
/**
* \brief Test SDL_GetRectEnclosingPoints() without clipping
* Test SDL_GetRectEnclosingPoints() without clipping
*
* \sa SDL_GetRectEnclosingPoints
*/
@ -1030,7 +1030,7 @@ static int rect_testEnclosePoints(void *arg)
}
/**
* \brief Test SDL_GetRectEnclosingPoints() with repeated input points
* Test SDL_GetRectEnclosingPoints() with repeated input points
*
* \sa SDL_GetRectEnclosingPoints
*/
@ -1113,7 +1113,7 @@ static int rect_testEnclosePointsRepeatedInput(void *arg)
}
/**
* \brief Test SDL_GetRectEnclosingPoints() with clipping
* Test SDL_GetRectEnclosingPoints() with clipping
*
* \sa SDL_GetRectEnclosingPoints
*/
@ -1219,7 +1219,7 @@ static int rect_testEnclosePointsWithClipping(void *arg)
}
/**
* \brief Negative tests against SDL_GetRectEnclosingPoints() with invalid parameters
* Negative tests against SDL_GetRectEnclosingPoints() with invalid parameters
*
* \sa SDL_GetRectEnclosingPoints
*/
@ -1246,7 +1246,7 @@ static int rect_testEnclosePointsParam(void *arg)
}
/**
* \brief Tests SDL_GetRectUnion() where rect B is outside rect A
* Tests SDL_GetRectUnion() where rect B is outside rect A
*
* \sa SDL_GetRectUnion
*/
@ -1324,7 +1324,7 @@ static int rect_testUnionRectOutside(void *arg)
}
/**
* \brief Tests SDL_GetRectUnion() where rect A or rect B are empty
* Tests SDL_GetRectUnion() where rect A or rect B are empty
*
* \sa SDL_GetRectUnion
*/
@ -1388,7 +1388,7 @@ static int rect_testUnionRectEmpty(void *arg)
}
/**
* \brief Tests SDL_GetRectUnion() where rect B is inside rect A
* Tests SDL_GetRectUnion() where rect B is inside rect A
*
* \sa SDL_GetRectUnion
*/
@ -1459,7 +1459,7 @@ static int rect_testUnionRectInside(void *arg)
}
/**
* \brief Negative tests against SDL_GetRectUnion() with invalid parameters
* Negative tests against SDL_GetRectUnion() with invalid parameters
*
* \sa SDL_GetRectUnion
*/
@ -1486,7 +1486,7 @@ static int rect_testUnionRectParam(void *arg)
}
/**
* \brief Tests SDL_RectEmpty() with various inputs
* Tests SDL_RectEmpty() with various inputs
*
* \sa SDL_RectEmpty
*/
@ -1528,7 +1528,7 @@ static int rect_testRectEmpty(void *arg)
}
/**
* \brief Negative tests against SDL_RectEmpty() with invalid parameters
* Negative tests against SDL_RectEmpty() with invalid parameters
*
* \sa SDL_RectEmpty
*/
@ -1544,7 +1544,7 @@ static int rect_testRectEmptyParam(void *arg)
}
/**
* \brief Tests SDL_RectsEqual() with various inputs
* Tests SDL_RectsEqual() with various inputs
*
* \sa SDL_RectsEqual
*/
@ -1573,7 +1573,7 @@ static int rect_testRectEquals(void *arg)
}
/**
* \brief Negative tests against SDL_RectsEqual() with invalid parameters
* Negative tests against SDL_RectsEqual() with invalid parameters
*
* \sa SDL_RectsEqual
*/
@ -1605,7 +1605,7 @@ static int rect_testRectEqualsParam(void *arg)
}
/**
* \brief Tests SDL_RectsEqualFloat() with various inputs
* Tests SDL_RectsEqualFloat() with various inputs
*
* \sa SDL_RectsEqualFloat
*/
@ -1634,7 +1634,7 @@ static int rect_testFRectEquals(void *arg)
}
/**
* \brief Negative tests against SDL_RectsEqualFloat() with invalid parameters
* Negative tests against SDL_RectsEqualFloat() with invalid parameters
*
* \sa SDL_RectsEqualFloat
*/
@ -1804,7 +1804,7 @@ static const SDLTest_TestCaseReference rectTest31 = {
};
/**
* \brief Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
* Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
*/
static const SDLTest_TestCaseReference *rectTests[] = {
&rectTest1, &rectTest2, &rectTest3, &rectTest4, &rectTest5, &rectTest6, &rectTest7, &rectTest8, &rectTest9, &rectTest10, &rectTest11, &rectTest12, &rectTest13, &rectTest14,

View File

@ -49,6 +49,7 @@ static int isSupported(int code);
static void InitCreateRenderer(void *arg)
{
int width = 320, height = 240;
int renderer_flags = SDL_RENDERER_ACCELERATED;
renderer = NULL;
window = SDL_CreateWindow("render_testCreateRenderer", width, height, 0);
SDLTest_AssertPass("SDL_CreateWindow()");
@ -57,9 +58,13 @@ static void InitCreateRenderer(void *arg)
return;
}
renderer = SDL_CreateRenderer(window, NULL, SDL_RENDERER_ACCELERATED);
if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "dummy") == 0) {
renderer_flags = 0;
}
renderer = SDL_CreateRenderer(window, NULL, renderer_flags);
SDLTest_AssertPass("SDL_CreateRenderer()");
SDLTest_AssertCheck(renderer != NULL, "Check SDL_CreateRenderer result");
SDLTest_AssertCheck(renderer != NULL, "Check SDL_CreateRenderer result: %s", renderer != NULL ? "success" : SDL_GetError());
if (renderer == NULL) {
SDL_DestroyWindow(window);
return;
@ -71,13 +76,13 @@ static void InitCreateRenderer(void *arg)
*/
static 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");
@ -85,7 +90,7 @@ static void CleanupDestroyRenderer(void *arg)
}
/**
* \brief Tests call to SDL_GetNumRenderDrivers
* Tests call to SDL_GetNumRenderDrivers
*
* \sa SDL_GetNumRenderDrivers
*/
@ -98,7 +103,7 @@ static int render_testGetNumRenderDrivers(void *arg)
}
/**
* \brief Tests the SDL primitives for rendering.
* Tests the SDL primitives for rendering.
*
* \sa SDL_SetRenderDrawColor
* \sa SDL_RenderFillRect
@ -185,7 +190,7 @@ static int render_testPrimitives(void *arg)
}
/**
* \brief Tests the SDL primitives with alpha for rendering.
* Tests the SDL primitives with alpha for rendering.
*
* \sa SDL_SetRenderDrawColor
* \sa SDL_SetRenderDrawBlendMode
@ -328,7 +333,7 @@ static int render_testPrimitivesBlend(void *arg)
}
/**
* \brief Tests some blitting routines.
* Tests some blitting routines.
*
* \sa SDL_RenderTexture
* \sa SDL_DestroyTexture
@ -395,7 +400,7 @@ static int render_testBlit(void *arg)
}
/**
* \brief Blits doing color tests.
* Blits doing color tests.
*
* \sa SDL_SetTextureColorMod
* \sa SDL_RenderTexture
@ -469,7 +474,7 @@ static int render_testBlitColor(void *arg)
}
/**
* \brief Tests blitting with alpha.
* Tests blitting with alpha.
*
* \sa SDL_SetTextureAlphaMod
* \sa SDL_RenderTexture
@ -546,7 +551,7 @@ static int render_testBlitAlpha(void *arg)
}
/**
* \brief Tests a blend mode.
* Tests a blend mode.
*
* \sa SDL_SetTextureBlendMode
* \sa SDL_RenderTexture
@ -597,7 +602,7 @@ testBlitBlendMode(SDL_Texture *tface, int mode)
}
/**
* \brief Tests some more blitting routines.
* Tests some more blitting routines.
*
* \sa SDL_SetTextureColorMod
* \sa SDL_SetTextureAlphaMod
@ -754,7 +759,7 @@ static int render_testBlitBlend(void *arg)
}
/**
* \brief Test viewport
* Test viewport
*/
static int render_testViewport(void *arg)
{
@ -811,7 +816,7 @@ static int render_testViewport(void *arg)
}
/**
* \brief Test logical size
* Test logical size
*/
static int render_testLogicalSize(void *arg)
{
@ -921,7 +926,7 @@ static int render_testLogicalSize(void *arg)
/* Helper functions */
/**
* \brief Checks to see if functionality is supported. Helper function.
* Checks to see if functionality is supported. Helper function.
*/
static int
isSupported(int code)
@ -930,7 +935,7 @@ isSupported(int code)
}
/**
* \brief Test to see if we can vary the draw color. Helper function.
* Test to see if we can vary the draw color. Helper function.
*
* \sa SDL_SetRenderDrawColor
* \sa SDL_GetRenderDrawColor
@ -971,7 +976,7 @@ hasDrawColor(void)
}
/**
* \brief Test to see if we can vary the blend mode. Helper function.
* Test to see if we can vary the blend mode. Helper function.
*
* \sa SDL_SetRenderDrawBlendMode
* \sa SDL_GetRenderDrawBlendMode
@ -1038,7 +1043,7 @@ hasBlendModes(void)
}
/**
* \brief Loads the test image 'Face' as texture. Helper function.
* Loads the test image 'Face' as texture. Helper function.
*
* \sa SDL_CreateTextureFromSurface
*/
@ -1049,12 +1054,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());
}
@ -1064,7 +1069,7 @@ loadTestFace(void)
}
/**
* \brief Test to see if can set texture color mode. Helper function.
* Test to see if can set texture color mode. Helper function.
*
* \sa SDL_SetTextureColorMod
* \sa SDL_GetTextureColorMod
@ -1080,7 +1085,7 @@ hasTexColor(void)
/* Get test face. */
tface = loadTestFace();
if (tface == NULL) {
if (!tface) {
return 0;
}
@ -1107,7 +1112,7 @@ hasTexColor(void)
}
/**
* \brief Test to see if we can vary the alpha of the texture. Helper function.
* Test to see if we can vary the alpha of the texture. Helper function.
*
* \sa SDL_SetTextureAlphaMod
* \sa SDL_GetTextureAlphaMod
@ -1123,7 +1128,7 @@ hasTexAlpha(void)
/* Get test face. */
tface = loadTestFace();
if (tface == NULL) {
if (!tface) {
return 0;
}
@ -1150,7 +1155,7 @@ hasTexAlpha(void)
}
/**
* \brief Compares screen pixels with image pixels. Helper function.
* Compares screen pixels with image pixels. Helper function.
*
* \param referenceSurface Image to compare against.
* \param allowable_error allowed difference from the reference image
@ -1195,7 +1200,7 @@ compare(SDL_Surface *referenceSurface, int allowable_error)
}
/**
* \brief Clears the screen. Helper function.
* Clears the screen. Helper function.
*
* \sa SDL_SetRenderDrawColor
* \sa SDL_RenderClear

View File

@ -90,7 +90,7 @@ static void RWopsTearDown(void *arg)
}
/**
* \brief Makes sure parameters work properly. Local helper function.
* Makes sure parameters work properly. Local helper function.
*
* \sa SDL_RWseek
* \sa SDL_RWread
@ -110,11 +110,11 @@ static void testGenericRWopsValidations(SDL_RWops *rw, SDL_bool write)
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (SDL_RW_SEEK_SET), expected 0, got %" SDL_PRIs64, i);
/* Test write. */
/* Test write */
s = SDL_RWwrite(rw, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString) - 1);
SDLTest_AssertPass("Call to SDL_RWwrite succeeded");
if (write) {
SDLTest_AssertCheck(s == sizeof(RWopsHelloWorldTestString) - 1, "Verify result of writing one byte with SDL_RWwrite, expected 1, got %i", (int)s);
SDLTest_AssertCheck(s == sizeof(RWopsHelloWorldTestString) - 1, "Verify result of writing with SDL_RWwrite, expected %i, got %i", (int)sizeof(RWopsHelloWorldTestString) - 1, (int)s);
} else {
SDLTest_AssertCheck(s == 0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", (int)s);
}
@ -129,6 +129,37 @@ static void testGenericRWopsValidations(SDL_RWops *rw, SDL_bool write)
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (SDL_RW_SEEK_SET), expected 0, got %" SDL_PRIs64, i);
/* Test read */
s = SDL_RWread(rw, buf, sizeof(RWopsHelloWorldTestString) - 1);
SDLTest_AssertPass("Call to SDL_RWread succeeded");
SDLTest_AssertCheck(
s == (sizeof(RWopsHelloWorldTestString) - 1),
"Verify result from SDL_RWread, expected %i, got %i",
(int)(sizeof(RWopsHelloWorldTestString) - 1),
(int)s);
SDLTest_AssertCheck(
SDL_memcmp(buf, RWopsHelloWorldTestString, sizeof(RWopsHelloWorldTestString) - 1) == 0,
"Verify read bytes match expected string, expected '%s', got '%s'", RWopsHelloWorldTestString, buf);
/* Test seek back to start */
i = SDL_RWseek(rw, 0, SDL_RW_SEEK_SET);
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (SDL_RW_SEEK_SET), expected 0, got %" SDL_PRIs64, i);
/* Test printf */
s = SDL_RWprintf(rw, "%s", RWopsHelloWorldTestString);
SDLTest_AssertPass("Call to SDL_RWprintf succeeded");
if (write) {
SDLTest_AssertCheck(s == sizeof(RWopsHelloWorldTestString) - 1, "Verify result of writing with SDL_RWprintf, expected %i, got %i", (int)sizeof(RWopsHelloWorldTestString) - 1, (int)s);
} else {
SDLTest_AssertCheck(s == 0, "Verify result of writing with SDL_RWwrite, expected: 0, got %i", (int)s);
}
/* Test seek back to start */
i = SDL_RWseek(rw, 0, SDL_RW_SEEK_SET);
SDLTest_AssertPass("Call to SDL_RWseek succeeded");
SDLTest_AssertCheck(i == (Sint64)0, "Verify seek to 0 with SDL_RWseek (SDL_RW_SEEK_SET), expected 0, got %" SDL_PRIs64, i);
/* Test read */
s = SDL_RWread(rw, buf, sizeof(RWopsHelloWorldTestString) - 1);
SDLTest_AssertPass("Call to SDL_RWread succeeded");
@ -214,7 +245,7 @@ static int rwops_testParamNegative(void *arg)
}
/**
* \brief Tests opening from memory.
* Tests opening from memory.
*
* \sa SDL_RWFromMem
* \sa SDL_RWClose
@ -253,7 +284,7 @@ static int rwops_testMem(void *arg)
}
/**
* \brief Tests opening from memory.
* Tests opening from memory.
*
* \sa SDL_RWFromConstMem
* \sa SDL_RWClose
@ -288,7 +319,7 @@ static int rwops_testConstMem(void *arg)
}
/**
* \brief Tests reading from file.
* Tests reading from file.
*
* \sa SDL_RWFromFile
* \sa SDL_RWClose
@ -335,7 +366,7 @@ static int rwops_testFileRead(void *arg)
}
/**
* \brief Tests writing from file.
* Tests writing from file.
*
* \sa SDL_RWFromFile
* \sa SDL_RWClose
@ -382,7 +413,7 @@ static int rwops_testFileWrite(void *arg)
}
/**
* \brief Tests alloc and free RW context.
* Tests alloc and free RW context.
*
* \sa SDL_CreateRW
* \sa SDL_DestroyRW
@ -410,7 +441,7 @@ static int rwops_testAllocFree(void *arg)
}
/**
* \brief Compare memory and file reads
* Compare memory and file reads
*
* \sa SDL_RWFromMem
* \sa SDL_RWFromFile
@ -473,7 +504,7 @@ static int rwops_testCompareRWFromMemWithRWFromFile(void *arg)
}
/**
* \brief Tests writing and reading from file using endian aware functions.
* Tests writing and reading from file using endian aware functions.
*
* \sa SDL_RWFromFile
* \sa SDL_RWClose

View File

@ -12,7 +12,7 @@
/* Test case functions */
/**
* \brief Calls to SDLTest_GenerateRunSeed()
* Calls to SDLTest_GenerateRunSeed()
*/
static int sdltest_generateRunSeed(void *arg)
{
@ -42,7 +42,7 @@ static int sdltest_generateRunSeed(void *arg)
}
/**
* \brief Calls to SDLTest_GetFuzzerInvocationCount()
* Calls to SDLTest_GetFuzzerInvocationCount()
*/
static int sdltest_getFuzzerInvocationCount(void *arg)
{
@ -64,7 +64,7 @@ static int sdltest_getFuzzerInvocationCount(void *arg)
}
/**
* \brief Calls to random number generators
* Calls to random number generators
*/
static int sdltest_randomNumber(void *arg)
{
@ -131,7 +131,7 @@ static int sdltest_randomNumber(void *arg)
}
/**
* \brief Calls to random boundary number generators for Uint8
* Calls to random boundary number generators for Uint8
*/
static int sdltest_randomBoundaryNumberUint8(void *arg)
{
@ -240,7 +240,7 @@ static int sdltest_randomBoundaryNumberUint8(void *arg)
}
/**
* \brief Calls to random boundary number generators for Uint16
* Calls to random boundary number generators for Uint16
*/
static int sdltest_randomBoundaryNumberUint16(void *arg)
{
@ -349,7 +349,7 @@ static int sdltest_randomBoundaryNumberUint16(void *arg)
}
/**
* \brief Calls to random boundary number generators for Uint32
* Calls to random boundary number generators for Uint32
*/
static int sdltest_randomBoundaryNumberUint32(void *arg)
{
@ -458,7 +458,7 @@ static int sdltest_randomBoundaryNumberUint32(void *arg)
}
/**
* \brief Calls to random boundary number generators for Uint64
* Calls to random boundary number generators for Uint64
*/
static int sdltest_randomBoundaryNumberUint64(void *arg)
{
@ -567,7 +567,7 @@ static int sdltest_randomBoundaryNumberUint64(void *arg)
}
/**
* \brief Calls to random boundary number generators for Sint8
* Calls to random boundary number generators for Sint8
*/
static int sdltest_randomBoundaryNumberSint8(void *arg)
{
@ -676,7 +676,7 @@ static int sdltest_randomBoundaryNumberSint8(void *arg)
}
/**
* \brief Calls to random boundary number generators for Sint16
* Calls to random boundary number generators for Sint16
*/
static int sdltest_randomBoundaryNumberSint16(void *arg)
{
@ -785,7 +785,7 @@ static int sdltest_randomBoundaryNumberSint16(void *arg)
}
/**
* \brief Calls to random boundary number generators for Sint32
* Calls to random boundary number generators for Sint32
*/
static int sdltest_randomBoundaryNumberSint32(void *arg)
{
@ -901,7 +901,7 @@ static int sdltest_randomBoundaryNumberSint32(void *arg)
}
/**
* \brief Calls to random boundary number generators for Sint64
* Calls to random boundary number generators for Sint64
*/
static int sdltest_randomBoundaryNumberSint64(void *arg)
{
@ -1010,7 +1010,7 @@ static int sdltest_randomBoundaryNumberSint64(void *arg)
}
/**
* \brief Calls to SDLTest_RandomIntegerInRange
* Calls to SDLTest_RandomIntegerInRange
*/
static int sdltest_randomIntegerInRange(void *arg)
{
@ -1084,7 +1084,7 @@ static int sdltest_randomIntegerInRange(void *arg)
}
/**
* \brief Calls to SDLTest_RandomAsciiString
* Calls to SDLTest_RandomAsciiString
*/
static int sdltest_randomAsciiString(void *arg)
{
@ -1116,7 +1116,7 @@ static int sdltest_randomAsciiString(void *arg)
}
/**
* \brief Calls to SDLTest_RandomAsciiStringWithMaximumLength
* Calls to SDLTest_RandomAsciiStringWithMaximumLength
*/
static int sdltest_randomAsciiStringWithMaximumLength(void *arg)
{
@ -1168,7 +1168,7 @@ static int sdltest_randomAsciiStringWithMaximumLength(void *arg)
}
/**
* \brief Calls to SDLTest_RandomAsciiStringOfSize
* Calls to SDLTest_RandomAsciiStringOfSize
*/
static int sdltest_randomAsciiStringOfSize(void *arg)
{

View File

@ -8,7 +8,7 @@
/* Test case functions */
/**
* \brief Call to SDL_strnlen
* Call to SDL_strnlen
*/
#undef SDL_strnlen
static int stdlib_strnlen(void *arg)
@ -36,7 +36,7 @@ static int stdlib_strnlen(void *arg)
}
/**
* \brief Call to SDL_strlcpy
* Call to SDL_strlcpy
*/
#undef SDL_strlcpy
static int stdlib_strlcpy(void *arg)
@ -60,6 +60,68 @@ static int stdlib_strlcpy(void *arg)
return TEST_COMPLETED;
}
/**
* Call to SDL_strstr
*/
static int stdlib_strstr(void *arg)
{
char *result;
const char *text = "abcdef";
const char *expected;
result = SDL_strstr(text, "");
expected = text;
SDLTest_AssertPass("Call to SDL_strstr(text, \"\")");
SDLTest_AssertCheck(result == expected, "Check result, expected: %s, got: %s", expected, result);
result = SDL_strstr(text, "abc");
expected = text;
SDLTest_AssertPass("Call to SDL_strstr(text, \"abc\")");
SDLTest_AssertCheck(result == expected, "Check result, expected: %s, got: %s", expected, result);
result = SDL_strstr(text, "bcd");
expected = text+1;
SDLTest_AssertPass("Call to SDL_strstr(text, \"bcd\")");
SDLTest_AssertCheck(result == expected, "Check result, expected: %s, got: %s", expected, result);
result = SDL_strstr(text, "xyz");
expected = NULL;
SDLTest_AssertPass("Call to SDL_strstr(text, \"xyz\")");
SDLTest_AssertCheck(result == expected, "Check result, expected: (null), got: %s", result);
result = SDL_strnstr(text, "", SDL_strlen(text));
expected = text;
SDLTest_AssertPass("Call to SDL_strnstr(text, \"\", SDL_strlen(text))");
SDLTest_AssertCheck(result == expected, "Check result, expected: %s, got: %s", expected, result);
result = SDL_strnstr(text, "abc", SDL_strlen(text));
expected = text;
SDLTest_AssertPass("Call to SDL_strnstr(text, \"abc\", SDL_strlen(text))");
SDLTest_AssertCheck(result == expected, "Check result, expected: %s, got: %s", expected, result);
result = SDL_strnstr(text, "bcd", SDL_strlen(text));
expected = text+1;
SDLTest_AssertPass("Call to SDL_strnstr(text, \"bcd\", SDL_strlen(text))");
SDLTest_AssertCheck(result == expected, "Check result, expected: %s, got: %s", expected, result);
result = SDL_strnstr(text, "bcd", 3);
expected = NULL;
SDLTest_AssertPass("Call to SDL_strnstr(text, \"bcd\", 3)");
SDLTest_AssertCheck(result == expected, "Check result, expected: (null), got: %s", result);
result = SDL_strnstr(text, "xyz", 3);
expected = NULL;
SDLTest_AssertPass("Call to SDL_strnstr(text, \"xyz\", 3)");
SDLTest_AssertCheck(result == expected, "Check result, expected: (null), got: %s", result);
result = SDL_strnstr(text, "xyz", SDL_strlen(text)*100000);
expected = NULL;
SDLTest_AssertPass("Call to SDL_strnstr(text, \"xyz\", SDL_strlen(text)*100000)");
SDLTest_AssertCheck(result == expected, "Check result, expected: (null), got: %s", result);
return TEST_COMPLETED;
}
#if defined(HAVE_WFORMAT) || defined(HAVE_WFORMAT_EXTRA_ARGS)
#pragma GCC diagnostic push
#ifdef HAVE_WFORMAT
@ -71,7 +133,7 @@ static int stdlib_strlcpy(void *arg)
#endif
/**
* \brief Call to SDL_snprintf
* Call to SDL_snprintf
*/
#undef SDL_snprintf
static int stdlib_snprintf(void *arg)
@ -258,11 +320,18 @@ static 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(expected), "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";
SDLTest_AssertPass("Call to SDL_snprintf(text, sizeof(text), \"%%p\", 0x1ba07bddf60)");
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
SDLTest_AssertCheck(result == SDL_strlen(expected), "Check result value, expected: %d, got: %d", (int)SDL_strlen(expected), result);
}
return TEST_COMPLETED;
}
/**
* \brief Call to SDL_swprintf
* Call to SDL_swprintf
*/
#undef SDL_swprintf
static int stdlib_swprintf(void *arg)
@ -429,7 +498,7 @@ static int stdlib_swprintf(void *arg)
#endif
/**
* \brief Call to SDL_getenv and SDL_setenv
* Call to SDL_getenv and SDL_setenv
*/
static int stdlib_getsetenv(void *arg)
{
@ -453,10 +522,10 @@ static 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);
@ -572,7 +641,7 @@ static int stdlib_getsetenv(void *arg)
#endif
/**
* \brief Call to SDL_sscanf
* Call to SDL_sscanf
*/
#undef SDL_sscanf
static int stdlib_sscanf(void *arg)
@ -585,7 +654,7 @@ static int stdlib_sscanf(void *arg)
long long_output, expected_long_output;
long long long_long_output, expected_long_long_output;
size_t size_output, expected_size_output;
char text[128];
char text[128], text2[128];
expected_output = output = 123;
expected_result = -1;
@ -649,6 +718,82 @@ static 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;
}
@ -665,7 +810,7 @@ static int stdlib_sscanf(void *arg)
#endif
/**
* \brief Call to SDL_aligned_alloc
* Call to SDL_aligned_alloc
*/
static int stdlib_aligned_alloc(void *arg)
{
@ -854,22 +999,26 @@ static const SDLTest_TestCaseReference stdlibTest2 = {
};
static const SDLTest_TestCaseReference stdlibTest3 = {
stdlib_snprintf, "stdlib_snprintf", "Call to SDL_snprintf", TEST_ENABLED
stdlib_strstr, "stdlib_strstr", "Call to SDL_strstr", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest4 = {
stdlib_swprintf, "stdlib_swprintf", "Call to SDL_swprintf", TEST_ENABLED
stdlib_snprintf, "stdlib_snprintf", "Call to SDL_snprintf", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest5 = {
stdlib_getsetenv, "stdlib_getsetenv", "Call to SDL_getenv and SDL_setenv", TEST_ENABLED
stdlib_swprintf, "stdlib_swprintf", "Call to SDL_swprintf", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest6 = {
stdlib_sscanf, "stdlib_sscanf", "Call to SDL_sscanf", TEST_ENABLED
stdlib_getsetenv, "stdlib_getsetenv", "Call to SDL_getenv and SDL_setenv", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest7 = {
stdlib_sscanf, "stdlib_sscanf", "Call to SDL_sscanf", TEST_ENABLED
};
static const SDLTest_TestCaseReference stdlibTest8 = {
stdlib_aligned_alloc, "stdlib_aligned_alloc", "Call to SDL_aligned_alloc", TEST_ENABLED
};
@ -886,6 +1035,7 @@ static const SDLTest_TestCaseReference *stdlibTests[] = {
&stdlibTest5,
&stdlibTest6,
&stdlibTest7,
&stdlibTest8,
&stdlibTestOverflow,
NULL
};

View File

@ -0,0 +1,239 @@
/**
* Events test suite
*/
#include "testautomation_suites.h"
#include <SDL3/SDL.h>
#include <SDL3/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 */
/**
* Inits and Quits particular subsystem, checking its Init status.
*
* \sa SDL_InitSubSystem
* \sa SDL_QuitSubSystem
*
*/
static int subsystems_referenceCount()
{
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;
}
/**
* 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()
{
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_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;
}
/**
* 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()
{
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;
}
/**
* 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()
{
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

@ -20,15 +20,17 @@ extern SDLTest_TestSuiteReference keyboardTestSuite;
extern SDLTest_TestSuiteReference mainTestSuite;
extern SDLTest_TestSuiteReference mathTestSuite;
extern SDLTest_TestSuiteReference mouseTestSuite;
extern SDLTest_TestSuiteReference penTestSuite;
extern SDLTest_TestSuiteReference pixelsTestSuite;
extern SDLTest_TestSuiteReference platformTestSuite;
extern SDLTest_TestSuiteReference propertiesTestSuite;
extern SDLTest_TestSuiteReference rectTestSuite;
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;
extern SDLTest_TestSuiteReference videoTestSuite;

View File

@ -209,7 +209,7 @@ static void AssertFileExist(const char *filename)
/* Test case functions */
/**
* \brief Tests sprite saving and loading
* Tests sprite saving and loading
*/
static int surface_testSaveLoadBitmap(void *arg)
{
@ -327,7 +327,10 @@ static int surface_testCompleteSurfaceConversion(void *arg)
SDL_PIXELFORMAT_RGBA8888,
SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_XRGB2101010,
SDL_PIXELFORMAT_XBGR2101010,
SDL_PIXELFORMAT_ARGB2101010,
SDL_PIXELFORMAT_ABGR2101010,
};
SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
SDL_PixelFormat *fmt1, *fmt2;
@ -386,7 +389,7 @@ static int surface_testCompleteSurfaceConversion(void *arg)
}
/**
* \brief Tests sprite loading. A failure case.
* Tests sprite loading. A failure case.
*/
static int surface_testLoadFailure(void *arg)
{
@ -397,7 +400,7 @@ static int surface_testLoadFailure(void *arg)
}
/**
* \brief Tests some blitting routines.
* Tests some blitting routines.
*/
static int surface_testBlit(void *arg)
{
@ -419,7 +422,7 @@ static int surface_testBlit(void *arg)
}
/**
* \brief Tests some blitting routines with color mod
* Tests some blitting routines with color mod
*/
static int surface_testBlitColorMod(void *arg)
{
@ -441,7 +444,7 @@ static int surface_testBlitColorMod(void *arg)
}
/**
* \brief Tests some blitting routines with alpha mod
* Tests some blitting routines with alpha mod
*/
static int surface_testBlitAlphaMod(void *arg)
{
@ -463,7 +466,7 @@ static int surface_testBlitAlphaMod(void *arg)
}
/**
* \brief Tests some more blitting routines.
* Tests some more blitting routines.
*/
static int surface_testBlitBlendNone(void *arg)
{
@ -485,7 +488,7 @@ static int surface_testBlitBlendNone(void *arg)
}
/**
* \brief Tests some more blitting routines.
* Tests some more blitting routines.
*/
static int surface_testBlitBlendBlend(void *arg)
{
@ -507,7 +510,7 @@ static int surface_testBlitBlendBlend(void *arg)
}
/**
* \brief Tests some more blitting routines.
* Tests some more blitting routines.
*/
static int surface_testBlitBlendAdd(void *arg)
{
@ -529,7 +532,7 @@ static int surface_testBlitBlendAdd(void *arg)
}
/**
* \brief Tests some more blitting routines.
* Tests some more blitting routines.
*/
static int surface_testBlitBlendMod(void *arg)
{
@ -551,7 +554,7 @@ static int surface_testBlitBlendMod(void *arg)
}
/**
* \brief Tests some more blitting routines with loop
* Tests some more blitting routines with loop
*/
static int surface_testBlitBlendLoop(void *arg)
{
@ -629,12 +632,12 @@ static int surface_testOverflow(void *arg)
/* Less than 1 byte per pixel: the pitch can legitimately be less than
* the width, but it must be enough to hold the appropriate number of
* bits per pixel. SDL_PIXELFORMAT_INDEX4LSB* needs 1 byte per 2 pixels. */
* bits per pixel. SDL_PIXELFORMAT_INDEX4* needs 1 byte per 2 pixels. */
surface = SDL_CreateSurfaceFrom(buf, 6, 1, 3, SDL_PIXELFORMAT_INDEX4LSB);
SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
surface = SDL_CreateSurfaceFrom(buf, 6, 1, 3, SDL_PIXELFORMAT_INDEX4LSB);
surface = SDL_CreateSurfaceFrom(buf, 6, 1, 3, SDL_PIXELFORMAT_INDEX4MSB);
SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
@ -643,7 +646,7 @@ static int surface_testOverflow(void *arg)
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_CreateSurfaceFrom(buf, 7, 1, 3, SDL_PIXELFORMAT_INDEX4LSB);
surface = SDL_CreateSurfaceFrom(buf, 7, 1, 3, SDL_PIXELFORMAT_INDEX4MSB);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
@ -652,17 +655,45 @@ static int surface_testOverflow(void *arg)
SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
surface = SDL_CreateSurfaceFrom(buf, 7, 1, 4, SDL_PIXELFORMAT_INDEX4LSB);
surface = SDL_CreateSurfaceFrom(buf, 7, 1, 4, SDL_PIXELFORMAT_INDEX4MSB);
SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
/* SDL_PIXELFORMAT_INDEX2* needs 1 byte per 4 pixels. */
surface = SDL_CreateSurfaceFrom(buf, 12, 1, 3, SDL_PIXELFORMAT_INDEX2LSB);
SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
surface = SDL_CreateSurfaceFrom(buf, 12, 1, 3, SDL_PIXELFORMAT_INDEX2MSB);
SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
surface = SDL_CreateSurfaceFrom(buf, 13, 1, 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_CreateSurfaceFrom(buf, 13, 1, 3, SDL_PIXELFORMAT_INDEX2MSB);
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_CreateSurfaceFrom(buf, 13, 1, 4, SDL_PIXELFORMAT_INDEX2LSB);
SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
surface = SDL_CreateSurfaceFrom(buf, 13, 1, 4, SDL_PIXELFORMAT_INDEX2MSB);
SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
/* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */
surface = SDL_CreateSurfaceFrom(buf, 16, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
surface = SDL_CreateSurfaceFrom(buf, 16, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
surface = SDL_CreateSurfaceFrom(buf, 16, 1, 2, SDL_PIXELFORMAT_INDEX1MSB);
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
@ -671,7 +702,7 @@ static int surface_testOverflow(void *arg)
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_CreateSurfaceFrom(buf, 17, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
surface = SDL_CreateSurfaceFrom(buf, 17, 1, 2, SDL_PIXELFORMAT_INDEX1MSB);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
@ -680,7 +711,7 @@ static int surface_testOverflow(void *arg)
SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);
surface = SDL_CreateSurfaceFrom(buf, 17, 1, 3, SDL_PIXELFORMAT_INDEX1LSB);
surface = SDL_CreateSurfaceFrom(buf, 17, 1, 3, SDL_PIXELFORMAT_INDEX1MSB);
SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_DestroySurface(surface);

View File

@ -1,60 +0,0 @@
/**
* SysWM test suite
*/
/* Avoid inclusion of e.g. X11 headers when these are not installed */
#include <build_config/SDL_build_config.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_syswm.h>
#include <SDL3/SDL_test.h>
#include "testautomation_suites.h"
/* Test case functions */
/**
* \brief Call to SDL_GetWindowWMInfo
*/
static int syswm_getWindowWMInfo(void *arg)
{
int result;
SDL_Window *window;
SDL_SysWMinfo info;
window = SDL_CreateWindow("", 0, 0, SDL_WINDOW_HIDDEN);
SDLTest_AssertPass("Call to SDL_CreateWindow()");
SDLTest_AssertCheck(window != NULL, "Check that value returned from SDL_CreateWindow is not NULL");
if (window == NULL) {
return TEST_ABORTED;
}
/* Make call */
result = SDL_GetWindowWMInfo(window, &info, SDL_SYSWM_CURRENT_VERSION);
SDLTest_AssertPass("Call to SDL_GetWindowWMInfo()");
SDLTest_Log((result == 0) ? "Got window information" : "Couldn't get window information");
SDL_DestroyWindow(window);
SDLTest_AssertPass("Call to SDL_DestroyWindow()");
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* SysWM test cases */
static const SDLTest_TestCaseReference syswmTest1 = {
(SDLTest_TestCaseFp)syswm_getWindowWMInfo, "syswm_getWindowWMInfo", "Call to SDL_GetWindowWMInfo", TEST_ENABLED
};
/* Sequence of SysWM test cases */
static const SDLTest_TestCaseReference *syswmTests[] = {
&syswmTest1, NULL
};
/* SysWM test suite (global) */
SDLTest_TestSuiteReference syswmTestSuite = {
"SysWM",
NULL,
syswmTests,
NULL
};

View File

@ -30,7 +30,7 @@ static void timerSetUp(void *arg)
/* Test case functions */
/**
* \brief Call to SDL_GetPerformanceCounter
* Call to SDL_GetPerformanceCounter
*/
static int timer_getPerformanceCounter(void *arg)
{
@ -44,7 +44,7 @@ static int timer_getPerformanceCounter(void *arg)
}
/**
* \brief Call to SDL_GetPerformanceFrequency
* Call to SDL_GetPerformanceFrequency
*/
static int timer_getPerformanceFrequency(void *arg)
{
@ -58,7 +58,7 @@ static int timer_getPerformanceFrequency(void *arg)
}
/**
* \brief Call to SDL_Delay and SDL_GetTicks
* Call to SDL_Delay and SDL_GetTicks
*/
static int timer_delayAndGetTicks(void *arg)
{
@ -92,7 +92,10 @@ static int timer_delayAndGetTicks(void *arg)
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);
#if 0
/* Disabled because this might fail on non-interactive systems. Moved to testtimer. */
SDLTest_AssertCheck(difference < (testDelay + marginOfError), "Check difference, expected: <%d, got: %" SDL_PRIu64, testDelay + marginOfError, difference);
#endif
return TEST_COMPLETED;
}
@ -113,7 +116,7 @@ static Uint32 SDLCALL timerTestCallback(Uint32 interval, void *param)
}
/**
* \brief Call to SDL_AddTimer and SDL_RemoveTimer
* Call to SDL_AddTimer and SDL_RemoveTimer
*/
static int timer_addRemoveTimer(void *arg)
{

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -22,7 +22,7 @@ int main(int argc, char **argv)
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
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-2024 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
@ -86,6 +86,7 @@ static SDL_JoystickID mapping_controller = 0;
static int binding_element = SDL_GAMEPAD_ELEMENT_INVALID;
static int last_binding_element = SDL_GAMEPAD_ELEMENT_INVALID;
static SDL_bool binding_flow = SDL_FALSE;
static int binding_flow_direction = 0;
static Uint64 binding_advance_time = 0;
static SDL_FRect title_area;
static SDL_bool title_highlighted;
@ -102,10 +103,10 @@ static SDL_GamepadButton virtual_button_active = SDL_GAMEPAD_BUTTON_INVALID;
static int s_arrBindingOrder[] = {
/* Standard sequence */
SDL_GAMEPAD_BUTTON_A,
SDL_GAMEPAD_BUTTON_B,
SDL_GAMEPAD_BUTTON_X,
SDL_GAMEPAD_BUTTON_Y,
SDL_GAMEPAD_BUTTON_SOUTH,
SDL_GAMEPAD_BUTTON_EAST,
SDL_GAMEPAD_BUTTON_WEST,
SDL_GAMEPAD_BUTTON_NORTH,
SDL_GAMEPAD_BUTTON_DPAD_LEFT,
SDL_GAMEPAD_BUTTON_DPAD_RIGHT,
SDL_GAMEPAD_BUTTON_DPAD_UP,
@ -331,12 +332,13 @@ static void SetCurrentBindingElement(int element, SDL_bool flow)
}
if (element == SDL_GAMEPAD_ELEMENT_INVALID) {
binding_flow_direction = 0;
last_binding_element = SDL_GAMEPAD_ELEMENT_INVALID;
} else {
last_binding_element = binding_element;
}
binding_element = element;
binding_flow = flow || (element == SDL_GAMEPAD_BUTTON_A);
binding_flow = flow || (element == SDL_GAMEPAD_BUTTON_SOUTH);
binding_advance_time = 0;
for (i = 0; i < controller->num_axes; ++i) {
@ -356,6 +358,7 @@ static void SetNextBindingElement(void)
for (i = 0; i < SDL_arraysize(s_arrBindingOrder); ++i) {
if (binding_element == s_arrBindingOrder[i]) {
binding_flow_direction = 1;
SetCurrentBindingElement(s_arrBindingOrder[i + 1], SDL_TRUE);
return;
}
@ -373,6 +376,7 @@ static void SetPrevBindingElement(void)
for (i = 1; i < SDL_arraysize(s_arrBindingOrder); ++i) {
if (binding_element == s_arrBindingOrder[i]) {
binding_flow_direction = -1;
SetCurrentBindingElement(s_arrBindingOrder[i - 1], SDL_TRUE);
return;
}
@ -456,8 +460,8 @@ static void CommitBindingElement(const char *binding, SDL_bool force)
}
}
if (native_axis) {
AxisInfo current_axis_info;
AxisInfo proposed_axis_info;
AxisInfo current_axis_info = { 0, 0 };
AxisInfo proposed_axis_info = { 0, 0 };
SDL_bool current_axis = ParseAxisInfo(current, &current_axis_info);
SDL_bool proposed_axis = ParseAxisInfo(binding, &proposed_axis_info);
@ -498,32 +502,50 @@ static void CommitBindingElement(const char *binding, SDL_bool force)
if (!ignore_binding && binding_flow && !force) {
int existing = GetElementForBinding(mapping, binding);
if (existing != SDL_GAMEPAD_ELEMENT_INVALID) {
if (existing == SDL_GAMEPAD_BUTTON_A) {
if (binding_element == SDL_GAMEPAD_BUTTON_A) {
/* Just move on to the next one */
SDL_GamepadButton action_forward = SDL_GAMEPAD_BUTTON_SOUTH;
SDL_GamepadButton action_backward = SDL_GAMEPAD_BUTTON_EAST;
SDL_GamepadButton action_delete = SDL_GAMEPAD_BUTTON_WEST;
if (binding_element == action_forward) {
/* Bind it! */
} else if (binding_element == action_backward) {
if (existing == action_forward) {
SDL_bool bound_backward = MappingHasElement(controller->mapping, action_backward);
if (bound_backward) {
/* Just move on to the next one */
ignore_binding = SDL_TRUE;
SetNextBindingElement();
} else {
/* You can't skip the backward action, go back and start over */
ignore_binding = SDL_TRUE;
SetPrevBindingElement();
}
} else if (existing == action_backward && binding_flow_direction == -1) {
/* Keep going backwards */
ignore_binding = SDL_TRUE;
SetNextBindingElement();
SetPrevBindingElement();
} else {
/* Clear the current binding and move to the next one */
binding = NULL;
direction = 1;
force = SDL_TRUE;
}
} else if (existing == SDL_GAMEPAD_BUTTON_B) {
if (binding_element != SDL_GAMEPAD_BUTTON_A &&
last_binding_element != SDL_GAMEPAD_BUTTON_A) {
/* Clear the current binding and move to the previous one */
binding = NULL;
direction = -1;
force = SDL_TRUE;
/* Bind it! */
}
} else if (existing == action_forward) {
/* Just move on to the next one */
ignore_binding = SDL_TRUE;
SetNextBindingElement();
} else if (existing == action_backward) {
ignore_binding = SDL_TRUE;
SetPrevBindingElement();
} else if (existing == binding_element) {
/* We're rebinding the same thing, just move to the next one */
ignore_binding = SDL_TRUE;
SetNextBindingElement();
} else if (binding_element != SDL_GAMEPAD_BUTTON_A &&
binding_element != SDL_GAMEPAD_BUTTON_B) {
ignore_binding = SDL_TRUE;
} else if (existing == action_delete) {
/* Clear the current binding and move to the next one */
binding = NULL;
direction = 1;
force = SDL_TRUE;
} else if (binding_element != action_forward &&
binding_element != action_backward) {
/* Actually, we'll just clear the existing binding */
/*ignore_binding = SDL_TRUE;*/
}
}
}
@ -572,7 +594,7 @@ static void SetDisplayMode(ControllerDisplayMode mode)
if (MappingHasBindings(backup_mapping)) {
SetCurrentBindingElement(SDL_GAMEPAD_ELEMENT_INVALID, SDL_FALSE);
} else {
SetCurrentBindingElement(SDL_GAMEPAD_BUTTON_A, SDL_TRUE);
SetCurrentBindingElement(SDL_GAMEPAD_BUTTON_SOUTH, SDL_TRUE);
}
} else {
if (backup_mapping) {
@ -701,30 +723,31 @@ static const char *GetBindingInstruction(void)
switch (binding_element) {
case SDL_GAMEPAD_ELEMENT_INVALID:
return "Select an element to bind from the list on the left";
case SDL_GAMEPAD_BUTTON_A:
if (GetGamepadImageFaceStyle(image) == GAMEPAD_IMAGE_FACE_SONY) {
return "Press the Cross (X) button";
} else {
case SDL_GAMEPAD_BUTTON_SOUTH:
case SDL_GAMEPAD_BUTTON_EAST:
case SDL_GAMEPAD_BUTTON_WEST:
case SDL_GAMEPAD_BUTTON_NORTH:
switch (SDL_GetGamepadButtonLabelForType(GetGamepadImageType(image), (SDL_GamepadButton)binding_element)) {
case SDL_GAMEPAD_BUTTON_LABEL_A:
return "Press the A button";
}
case SDL_GAMEPAD_BUTTON_B:
if (GetGamepadImageFaceStyle(image) == GAMEPAD_IMAGE_FACE_SONY) {
return "Press the Circle button";
} else {
case SDL_GAMEPAD_BUTTON_LABEL_B:
return "Press the B button";
}
case SDL_GAMEPAD_BUTTON_X:
if (GetGamepadImageFaceStyle(image) == GAMEPAD_IMAGE_FACE_SONY) {
return "Press the Square button";
} else {
case SDL_GAMEPAD_BUTTON_LABEL_X:
return "Press the X button";
}
case SDL_GAMEPAD_BUTTON_Y:
if (GetGamepadImageFaceStyle(image) == GAMEPAD_IMAGE_FACE_SONY) {
return "Press the Triangle button";
} else {
case SDL_GAMEPAD_BUTTON_LABEL_Y:
return "Press the Y button";
case SDL_GAMEPAD_BUTTON_LABEL_CROSS:
return "Press the Cross (X) button";
case SDL_GAMEPAD_BUTTON_LABEL_CIRCLE:
return "Press the Circle button";
case SDL_GAMEPAD_BUTTON_LABEL_SQUARE:
return "Press the Square button";
case SDL_GAMEPAD_BUTTON_LABEL_TRIANGLE:
return "Press the Triangle button";
default:
return "";
}
break;
case SDL_GAMEPAD_BUTTON_BACK:
return "Press the left center button (Back/View/Share)";
case SDL_GAMEPAD_BUTTON_GUIDE:
@ -829,7 +852,7 @@ static void AddController(SDL_JoystickID id, SDL_bool verbose)
}
new_controllers = (Controller *)SDL_realloc(controllers, (num_controllers + 1) * sizeof(*controllers));
if (new_controllers == NULL) {
if (!new_controllers) {
return;
}
@ -846,9 +869,12 @@ static void AddController(SDL_JoystickID id, SDL_bool verbose)
joystick = new_controller->joystick;
if (joystick) {
if (verbose && !SDL_IsGamepad(id)) {
const char *name = SDL_GetJoystickName(new_controller->joystick);
const char *path = SDL_GetJoystickPath(new_controller->joystick);
const char *name = SDL_GetJoystickName(joystick);
const char *path = SDL_GetJoystickPath(joystick);
char guid[33];
SDL_Log("Opened joystick %s%s%s\n", name, path ? ", " : "", path ? path : "");
SDL_GetJoystickGUIDString(SDL_GetJoystickGUID(joystick), guid, sizeof(guid));
SDL_Log("No gamepad mapping for %s\n", guid);
}
} else {
SDL_Log("Couldn't open joystick: %s", SDL_GetError());
@ -941,8 +967,6 @@ static void HandleGamepadAdded(SDL_JoystickID id, SDL_bool verbose)
int i;
i = FindController(id);
SDL_assert(i >= 0);
if (i < 0) {
return;
}
@ -969,6 +993,10 @@ static void HandleGamepadAdded(SDL_JoystickID id, SDL_bool verbose)
if (SDL_GamepadHasRumbleTriggers(gamepad)) {
SDL_Log("Trigger rumble supported");
}
if (SDL_GetGamepadPlayerIndex(gamepad) >= 0) {
SDL_Log("Player index: %d\n", SDL_GetGamepadPlayerIndex(gamepad));
}
}
for (i = 0; i < SDL_arraysize(sensors); ++i) {
@ -981,6 +1009,14 @@ static void HandleGamepadAdded(SDL_JoystickID id, SDL_bool verbose)
SDL_SetGamepadSensorEnabled(gamepad, sensor, SDL_TRUE);
}
}
if (verbose) {
char *mapping = SDL_GetGamepadMapping(gamepad);
if (mapping) {
SDL_Log("Mapping: %s\n", mapping);
SDL_free(mapping);
}
}
} else {
SDL_Log("Couldn't open gamepad: %s", SDL_GetError());
}
@ -1084,7 +1120,7 @@ static void OpenVirtualGamepad(void)
SDL_Log("Couldn't attach virtual device: %s\n", SDL_GetError());
} else {
virtual_joystick = SDL_OpenJoystick(virtual_id);
if (virtual_joystick == NULL) {
if (!virtual_joystick) {
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
}
}
@ -1254,6 +1290,13 @@ static void DrawGamepadInfo(SDL_Renderer *renderer)
SDL_SetRenderDrawColor(renderer, r, g, b, a);
}
if (controller->joystick) {
SDL_snprintf(text, sizeof(text), "(%" SDL_PRIu32 ")", SDL_GetJoystickInstanceID(controller->joystick));
x = (float)SCREEN_WIDTH - (FONT_CHARACTER_SIZE * SDL_strlen(text)) - 8.0f;
y = 8.0f;
SDLTest_DrawString(renderer, x, y, text);
}
if (controller_name && *controller_name) {
x = title_area.x + title_area.w / 2 - (FONT_CHARACTER_SIZE * SDL_strlen(controller_name)) / 2;
y = title_area.y + title_area.h / 2 - FONT_CHARACTER_SIZE / 2;
@ -1273,6 +1316,14 @@ static void DrawGamepadInfo(SDL_Renderer *renderer)
SDLTest_DrawString(renderer, x, y, type);
if (display_mode == CONTROLLER_MODE_TESTING) {
Uint64 steam_handle = SDL_GetGamepadSteamHandle(controller->gamepad);
if (steam_handle) {
SDL_snprintf(text, SDL_arraysize(text), "Steam: 0x%.16" SDL_PRIx64 "", steam_handle);
y = (float)SCREEN_HEIGHT - 2 * (8.0f + FONT_LINE_HEIGHT);
x = (float)SCREEN_WIDTH - 8.0f - (FONT_CHARACTER_SIZE * SDL_strlen(text));
SDLTest_DrawString(renderer, x, y, text);
}
SDL_snprintf(text, SDL_arraysize(text), "VID: 0x%.4x PID: 0x%.4x",
SDL_GetJoystickVendor(controller->joystick),
SDL_GetJoystickProduct(controller->joystick));
@ -1290,6 +1341,30 @@ static void DrawGamepadInfo(SDL_Renderer *renderer)
}
}
static const char *GetButtonLabel(SDL_GamepadType type, SDL_GamepadButton button)
{
switch (SDL_GetGamepadButtonLabelForType(type, button)) {
case SDL_GAMEPAD_BUTTON_LABEL_A:
return "A";
case SDL_GAMEPAD_BUTTON_LABEL_B:
return "B";
case SDL_GAMEPAD_BUTTON_LABEL_X:
return "X";
case SDL_GAMEPAD_BUTTON_LABEL_Y:
return "Y";
case SDL_GAMEPAD_BUTTON_LABEL_CROSS:
return "Cross (X)";
case SDL_GAMEPAD_BUTTON_LABEL_CIRCLE:
return "Circle";
case SDL_GAMEPAD_BUTTON_LABEL_SQUARE:
return "Square";
case SDL_GAMEPAD_BUTTON_LABEL_TRIANGLE:
return "Triangle";
default:
return "UNKNOWN";
}
}
static void DrawBindingTips(SDL_Renderer *renderer)
{
const char *text;
@ -1309,7 +1384,12 @@ static void DrawBindingTips(SDL_Renderer *renderer)
} else {
Uint8 r, g, b, a;
SDL_FRect rect;
SDL_bool bound_A, bound_B;
SDL_GamepadButton action_forward = SDL_GAMEPAD_BUTTON_SOUTH;
SDL_bool bound_forward = MappingHasElement(controller->mapping, action_forward);
SDL_GamepadButton action_backward = SDL_GAMEPAD_BUTTON_EAST;
SDL_bool bound_backward = MappingHasElement(controller->mapping, action_backward);
SDL_GamepadButton action_delete = SDL_GAMEPAD_BUTTON_WEST;
SDL_bool bound_delete = MappingHasElement(controller->mapping, action_delete);
y -= (FONT_CHARACTER_SIZE + BUTTON_MARGIN) / 2;
@ -1328,15 +1408,22 @@ static void DrawBindingTips(SDL_Renderer *renderer)
if (binding_element == SDL_GAMEPAD_ELEMENT_NAME) {
text = "(press RETURN to complete)";
} else if (binding_element == SDL_GAMEPAD_ELEMENT_TYPE) {
} else if (binding_element == SDL_GAMEPAD_ELEMENT_TYPE ||
binding_element == action_forward ||
binding_element == action_backward) {
text = "(press ESC to cancel)";
} else {
bound_A = MappingHasElement(controller->mapping, SDL_GAMEPAD_BUTTON_A);
bound_B = MappingHasElement(controller->mapping, SDL_GAMEPAD_BUTTON_B);
if (binding_flow && bound_A && bound_B) {
text = "(press A to skip, B to go back, and ESC to cancel)";
static char dynamic_text[128];
SDL_GamepadType type = GetGamepadImageType(image);
if (binding_flow && bound_forward && bound_backward) {
if (binding_element != action_delete && bound_delete) {
SDL_snprintf(dynamic_text, sizeof(dynamic_text), "(press %s to skip, %s to go back, %s to delete, and ESC to cancel)", GetButtonLabel(type, action_forward), GetButtonLabel(type, action_backward), GetButtonLabel(type, action_delete));
} else {
SDL_snprintf(dynamic_text, sizeof(dynamic_text), "(press %s to skip, %s to go back, SPACE to delete, and ESC to cancel)", GetButtonLabel(type, action_forward), GetButtonLabel(type, action_backward));
}
text = dynamic_text;
} else {
text = "(press SPACE to clear binding and ESC to cancel)";
text = "(press SPACE to delete and ESC to cancel)";
}
}
SDLTest_DrawString(renderer, (float)x - (FONT_CHARACTER_SIZE * SDL_strlen(text)) / 2, (float)y, text);
@ -1521,6 +1608,10 @@ static void loop(void *arg)
HandleGamepadRemapped(event.gdevice.which);
break;
case SDL_EVENT_GAMEPAD_STEAM_HANDLE_UPDATED:
RefreshControllerName();
break;
#ifdef VERBOSE_TOUCHPAD
case SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN:
case SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION:
@ -1801,6 +1892,7 @@ static void loop(void *arg)
int main(int argc, char *argv[])
{
SDL_bool show_mappings = SDL_FALSE;
int i;
float content_scale;
int screen_width, screen_height;
@ -1810,7 +1902,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
if (state == NULL) {
if (!state) {
return 1;
}
@ -1832,16 +1924,7 @@ int main(int argc, char *argv[])
consumed = SDLTest_CommonArg(state, i);
if (!consumed) {
if (SDL_strcmp(argv[i], "--mappings") == 0) {
int map_i;
SDL_Log("Supported mappings:\n");
for (map_i = 0; map_i < SDL_GetNumGamepadMappings(); ++map_i) {
char *mapping = SDL_GetGamepadMappingForIndex(map_i);
if (mapping) {
SDL_Log("\t%s\n", mapping);
SDL_free(mapping);
}
}
SDL_Log("\n");
show_mappings = SDL_TRUE;
consumed = 1;
} else if (SDL_strcmp(argv[i], "--virtual") == 0) {
OpenVirtualGamepad();
@ -1874,6 +1957,18 @@ int main(int argc, char *argv[])
SDL_AddGamepadMappingsFromFile("gamecontrollerdb.txt");
if (show_mappings) {
int count = 0;
char **mappings = SDL_GetGamepadMappings(&count);
int map_i;
SDL_Log("Supported mappings:\n");
for (map_i = 0; map_i < count; ++map_i) {
SDL_Log("\t%s\n", mappings[map_i]);
}
SDL_Log("\n");
SDL_free(mappings);
}
/* Create a window to display gamepad state */
content_scale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay());
if (content_scale == 0.0f) {
@ -1882,13 +1977,13 @@ int main(int argc, char *argv[])
screen_width = (int)SDL_ceilf(SCREEN_WIDTH * content_scale);
screen_height = (int)SDL_ceilf(SCREEN_HEIGHT * content_scale);
window = SDL_CreateWindow("SDL Controller Test", 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, NULL, 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;
@ -1915,7 +2010,7 @@ int main(int argc, char *argv[])
type_area.y = (float)TITLE_HEIGHT / 2 - type_area.h / 2;
image = CreateGamepadImage(screen);
if (image == NULL) {
if (!image) {
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-2024 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,6 +65,50 @@ static const char *arrow[] = {
"0,0"
};
static const char *cross[] = {
/* width height num_colors chars_per_pixel */
" 32 32 3 1",
/* colors */
"o c #000000",
". c #ffffff",
" c None",
/* pixels */
/* pixels */
" ",
" ",
" ",
" ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oooooooooooooooooooooooo ",
" oooooooooooooooooooooooo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" oo ",
" ",
" ",
" ",
" ",
"0,0"
};
static SDL_Cursor *
init_color_cursor(const char *file)
{
@ -72,7 +116,12 @@ init_color_cursor(const char *file)
SDL_Surface *surface = SDL_LoadBMP(file);
if (surface) {
if (surface->format->palette) {
SDL_SetSurfaceColorKey(surface, 1, *(Uint8 *)surface->pixels);
const Uint8 bpp = surface->format->BitsPerPixel;
const Uint8 mask = (1 << bpp) - 1;
if (SDL_PIXELORDER(surface->format->format) == SDL_BITMAPORDER_4321)
SDL_SetSurfaceColorKey(surface, 1, (*(Uint8 *)surface->pixels) & mask);
else
SDL_SetSurfaceColorKey(surface, 1, ((*(Uint8 *)surface->pixels) >> (8 - bpp)) & mask);
} else {
switch (surface->format->BitsPerPixel) {
case 15:
@ -122,6 +171,9 @@ init_system_cursor(const char *image[])
case '.':
mask[i] |= 0x01;
break;
case 'o':
data[i] |= 0x01;
break;
case ' ':
break;
}
@ -133,8 +185,8 @@ init_system_cursor(const char *image[])
static SDLTest_CommonState *state;
static int done;
static SDL_Cursor *cursors[1 + SDL_NUM_SYSTEM_CURSORS];
static SDL_SystemCursor cursor_types[1 + SDL_NUM_SYSTEM_CURSORS];
static SDL_Cursor *cursors[3 + SDL_NUM_SYSTEM_CURSORS];
static SDL_SystemCursor cursor_types[3 + SDL_NUM_SYSTEM_CURSORS];
static int num_cursors;
static int current_cursor;
static SDL_bool show_cursor;
@ -210,6 +262,30 @@ static void loop(void)
case SDL_SYSTEM_CURSOR_HAND:
SDL_Log("Hand");
break;
case SDL_SYSTEM_CURSOR_WINDOW_TOPLEFT:
SDL_Log("Window resize top-left");
break;
case SDL_SYSTEM_CURSOR_WINDOW_TOP:
SDL_Log("Window resize top");
break;
case SDL_SYSTEM_CURSOR_WINDOW_TOPRIGHT:
SDL_Log("Window resize top-right");
break;
case SDL_SYSTEM_CURSOR_WINDOW_RIGHT:
SDL_Log("Window resize right");
break;
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMRIGHT:
SDL_Log("Window resize bottom-right");
break;
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOM:
SDL_Log("Window resize bottom");
break;
case SDL_SYSTEM_CURSOR_WINDOW_BOTTOMLEFT:
SDL_Log("Window resize bottom-left");
break;
case SDL_SYSTEM_CURSOR_WINDOW_LEFT:
SDL_Log("Window resize left");
break;
default:
SDL_Log("UNKNOWN CURSOR TYPE, FIX THIS PROGRAM.");
break;
@ -228,7 +304,29 @@ static void loop(void)
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
SDL_RenderClear(renderer);
SDL_FRect rect;
int x, y, row;
int window_w = 0, window_h = 0;
SDL_GetWindowSize(state->windows[i], &window_w, &window_h);
rect.w = 128.0f;
rect.h = 128.0f;
for (y = 0, row = 0; y < window_h; y += (int)rect.h, ++row) {
SDL_bool black = ((row % 2) == 0) ? SDL_TRUE : SDL_FALSE;
for (x = 0; x < window_w; x += (int)rect.w) {
rect.x = (float)x;
rect.y = (float)y;
if (black) {
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
} else {
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
}
SDL_RenderFillRect(renderer, &rect);
black = !black;
}
}
SDL_RenderPresent(renderer);
}
#ifdef __EMSCRIPTEN__
@ -242,13 +340,14 @@ int main(int argc, char *argv[])
{
int i;
const char *color_cursor = NULL;
SDL_Cursor *cursor;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
for (i = 1; i < argc;) {
@ -270,23 +369,10 @@ int main(int argc, char *argv[])
quit(2);
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
}
num_cursors = 0;
if (color_cursor) {
SDL_Cursor *cursor = init_color_cursor(color_cursor);
if (cursor) {
cursors[num_cursors] = cursor;
cursor_types[num_cursors] = (SDL_SystemCursor)-1;
num_cursors++;
}
} else {
SDL_Cursor *cursor = init_system_cursor(arrow);
cursor = init_color_cursor(color_cursor);
if (cursor) {
cursors[num_cursors] = cursor;
cursor_types[num_cursors] = (SDL_SystemCursor)-1;
@ -294,8 +380,22 @@ int main(int argc, char *argv[])
}
}
cursor = init_system_cursor(arrow);
if (cursor) {
cursors[num_cursors] = cursor;
cursor_types[num_cursors] = (SDL_SystemCursor)-1;
num_cursors++;
}
cursor = init_system_cursor(cross);
if (cursor) {
cursors[num_cursors] = cursor;
cursor_types[num_cursors] = (SDL_SystemCursor)-1;
num_cursors++;
}
for (i = 0; i < SDL_NUM_SYSTEM_CURSORS; ++i) {
SDL_Cursor *cursor = SDL_CreateSystemCursor((SDL_SystemCursor)i);
cursor = SDL_CreateSystemCursor((SDL_SystemCursor)i);
if (cursor) {
cursors[num_cursors] = cursor;
cursor_types[num_cursors] = i;

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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 @@
static void
print_mode(const char *prefix, const SDL_DisplayMode *mode)
{
if (mode == NULL) {
if (!mode) {
return;
}
@ -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

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -229,7 +229,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-2024 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,6 +57,7 @@ static void DrawChessBoard(void)
}
}
}
SDL_RenderPresent(renderer);
}
static void loop(void)
@ -106,7 +107,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
if (state == NULL) {
if (!state) {
return 1;
}
@ -126,13 +127,13 @@ int main(int argc, char *argv[])
/* Create window and renderer for given surface */
window = SDL_CreateWindow("Chess Board", 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;
}
surface = SDL_GetWindowSurface(window);
renderer = SDL_CreateSoftwareRenderer(surface);
if (renderer == NULL) {
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n", SDL_GetError());
return 1;
}
@ -151,6 +152,9 @@ int main(int argc, char *argv[])
}
#endif
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
SDLTest_CommonDestroyState(state);
return 0;

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 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
@ -26,7 +26,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
if (!state) {
return 1;
}
@ -56,9 +56,6 @@ int main(int argc, char *argv[])
goto quit;
}
SDL_SetEventEnabled(SDL_EVENT_DROP_FILE, SDL_TRUE);
/* Main render loop */
done = 0;
while (!done) {
@ -71,16 +68,13 @@ int main(int argc, char *argv[])
SDL_Log("Drop complete on window %u at (%f, %f)", (unsigned int)event.drop.windowID, event.drop.x, event.drop.y);
} else if ((event.type == SDL_EVENT_DROP_FILE) || (event.type == SDL_EVENT_DROP_TEXT)) {
const char *typestr = (event.type == SDL_EVENT_DROP_FILE) ? "File" : "Text";
char *dropped_filedir = event.drop.file;
SDL_Log("%s dropped on window %u: %s at (%f, %f)", typestr, (unsigned int)event.drop.windowID, dropped_filedir, event.drop.x, event.drop.y);
/* Normally you'd have to do this, but this is freed in SDLTest_CommonEvent() */
/*SDL_free(dropped_filedir);*/
SDL_Log("%s dropped on window %u: %s at (%f, %f)", typestr, (unsigned int)event.drop.windowID, event.drop.data, event.drop.x, event.drop.y);
} else if (event.type == SDL_EVENT_DROP_POSITION) {
is_hover = SDL_TRUE;
x = event.drop.x;
y = event.drop.y;
windowID = event.drop.windowID;
SDL_Log("Drop position on window %u at (%f, %f) file = %s", (unsigned int)event.drop.windowID, event.drop.x, event.drop.y, event.drop.file);
SDL_Log("Drop position on window %u at (%f, %f) data = %s", (unsigned int)event.drop.windowID, event.drop.x, event.drop.y, event.drop.data);
}
SDLTest_CommonEvent(state, &event, &done);

View File

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

View File

@ -1,5 +1,5 @@
/*
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
Copyright (C) 2020-2022 Collabora Ltd.
This software is provided 'as-is', without any express or implied
@ -1940,7 +1940,7 @@ int main(int argc, char *argv[])
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, 0);
if (state == NULL) {
if (!state) {
return 1;
}

1139
external/sdl/SDL/test/testffmpeg.c vendored Normal file

File diff suppressed because it is too large Load Diff

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