early-access version 2847

This commit is contained in:
pineappleEA
2022-07-19 05:48:31 +02:00
parent ba74a2373c
commit 05e3c38e7f
498 changed files with 16027 additions and 27028 deletions

View File

@@ -1,10 +1,5 @@
cmake_minimum_required(VERSION 3.0.0)
project(SDL2 C)
include(CTest)
if(SDL_INSTALL_TESTS)
include(GNUInstallDirs)
endif()
# Global settings for all of the test targets
# FIXME: is this wrong?
@@ -44,8 +39,6 @@ endif()
# CMake incorrectly detects opengl32.lib being present on MSVC ARM64
if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
# Prefer GLVND, if present
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL)
endif()
@@ -55,8 +48,8 @@ endif()
add_executable(checkkeys checkkeys.c)
add_executable(checkkeysthreads checkkeysthreads.c)
add_executable(loopwave loopwave.c testutils.c)
add_executable(loopwavequeue loopwavequeue.c testutils.c)
add_executable(loopwave loopwave.c)
add_executable(loopwavequeue loopwavequeue.c)
add_executable(testsurround testsurround.c)
add_executable(testresample testresample.c)
add_executable(testaudioinfo testaudioinfo.c)
@@ -64,8 +57,8 @@ add_executable(testaudioinfo testaudioinfo.c)
file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
add_executable(testautomation ${TESTAUTOMATION_SOURCE_FILES})
add_executable(testmultiaudio testmultiaudio.c testutils.c)
add_executable(testaudiohotplug testaudiohotplug.c testutils.c)
add_executable(testmultiaudio testmultiaudio.c)
add_executable(testaudiohotplug testaudiohotplug.c)
add_executable(testaudiocapture testaudiocapture.c)
add_executable(testatomic testatomic.c)
add_executable(testintersections testintersections.c)
@@ -75,191 +68,73 @@ add_executable(testdraw2 testdraw2.c)
add_executable(testdrawchessboard testdrawchessboard.c)
add_executable(testdropfile testdropfile.c)
add_executable(testerror testerror.c)
if(LINUX)
add_executable(testevdev testevdev.c)
endif()
add_executable(testfile testfile.c)
add_executable(testgamecontroller testgamecontroller.c testutils.c)
add_executable(testgeometry testgeometry.c testutils.c)
add_executable(testgamecontroller testgamecontroller.c)
add_executable(testgeometry testgeometry.c)
add_executable(testgesture testgesture.c)
add_executable(testgl2 testgl2.c)
add_executable(testgles testgles.c)
add_executable(testgles2 testgles2.c)
add_executable(testguid testguid.c)
add_executable(testhaptic testhaptic.c)
add_executable(testhotplug testhotplug.c)
add_executable(testrumble testrumble.c)
add_executable(testthread testthread.c)
add_executable(testiconv testiconv.c testutils.c)
add_executable(testime testime.c testutils.c)
add_executable(testiconv testiconv.c)
add_executable(testime testime.c)
add_executable(testjoystick testjoystick.c)
add_executable(testkeys testkeys.c)
add_executable(testloadso testloadso.c)
add_executable(testlocale testlocale.c)
add_executable(testlock testlock.c)
add_executable(testmouse testmouse.c)
if(APPLE)
add_executable(testnative testnative.c
testnativecocoa.m
testnativex11.c
testutils.c)
testnativex11.c)
elseif(WINDOWS)
add_executable(testnative testnative.c testnativew32.c testutils.c)
elseif(SDL_X11)
add_executable(testnative testnative.c testnativex11.c testutils.c)
target_link_libraries(testnative X11)
add_executable(testnative testnative.c testnativew32.c)
elseif(UNIX)
add_executable(testnative testnative.c testnativex11.c)
endif()
add_executable(testoverlay2 testoverlay2.c testyuv_cvt.c testutils.c)
add_executable(testoverlay2 testoverlay2.c testyuv_cvt.c)
add_executable(testplatform testplatform.c)
add_executable(testpower testpower.c)
add_executable(testfilesystem testfilesystem.c)
add_executable(testrendertarget testrendertarget.c testutils.c)
add_executable(testscale testscale.c testutils.c)
add_executable(testrendertarget testrendertarget.c)
add_executable(testscale testscale.c)
add_executable(testsem testsem.c)
add_executable(testsensor testsensor.c)
add_executable(testshader testshader.c)
add_executable(testshape testshape.c)
add_executable(testsprite2 testsprite2.c testutils.c)
add_executable(testspriteminimal testspriteminimal.c testutils.c)
add_executable(teststreaming teststreaming.c testutils.c)
add_executable(testsprite2 testsprite2.c)
add_executable(testspriteminimal testspriteminimal.c)
add_executable(teststreaming teststreaming.c)
add_executable(testtimer testtimer.c)
add_executable(testurl testurl.c)
add_executable(testver testver.c)
add_executable(testviewport testviewport.c testutils.c)
add_executable(testviewport testviewport.c)
add_executable(testwm2 testwm2.c)
add_executable(testyuv testyuv.c testyuv_cvt.c)
add_executable(torturethread torturethread.c)
add_executable(testrendercopyex testrendercopyex.c testutils.c)
add_executable(testrendercopyex testrendercopyex.c)
add_executable(testmessage testmessage.c)
add_executable(testdisplayinfo testdisplayinfo.c)
add_executable(testqsort testqsort.c)
add_executable(testbounds testbounds.c)
add_executable(testcustomcursor testcustomcursor.c)
add_executable(controllermap controllermap.c testutils.c)
add_executable(controllermap controllermap.c)
add_executable(testvulkan testvulkan.c)
add_executable(testoffscreen testoffscreen.c)
SET(ALL_TESTS
checkkeys
checkkeysthreads
controllermap
loopwave
loopwavequeue
testatomic
testaudiocapture
testaudiohotplug
testaudioinfo
testautomation
testbounds
testcustomcursor
testdisplayinfo
testdraw2
testdrawchessboard
testdropfile
testerror
testfile
testfilesystem
testgamecontroller
testgeometry
testgesture
testgl2
testgles
testgles2
testguid
testhaptic
testhittesting
testhotplug
testiconv
testime
testintersections
testjoystick
testkeys
testloadso
testlocale
testlock
testmessage
testmouse
testmultiaudio
testoffscreen
testoverlay2
testplatform
testpower
testqsort
testrelative
testrendercopyex
testrendertarget
testresample
testrumble
testscale
testsem
testsensor
testshader
testshape
testsprite2
testspriteminimal
teststreaming
testsurround
testthread
testtimer
testurl
testver
testviewport
testvulkan
testwm2
testyuv
torturethread
)
set(NONINTERACTIVE
testatomic
testerror
testfilesystem
testguid
testlocale
testplatform
testpower
testqsort
testthread
testtimer
testver
)
if(WINDOWS OR APPLE OR SDL_X11)
list(APPEND ALL_TESTS testnative)
endif()
if(LINUX)
list(APPEND ALL_TESTS testevdev)
list(APPEND NONINTERACTIVE testevdev)
endif()
if(SDL_DUMMYAUDIO)
set(NEEDS_AUDIO
testaudioinfo
testsurround
)
endif()
if(SDL_DUMMYVIDEO)
set(NEEDS_DISPLAY
testkeys
testbounds
testdisplayinfo
)
endif()
if(OPENGL_FOUND)
target_link_libraries(testshader OpenGL::GL)
target_link_libraries(testgl2 OpenGL::GL)
add_dependencies(testshader OpenGL::GL)
add_dependencies(testgl2 OpenGL::GL)
target_link_libraries(testshader OpenGL::GL)
target_link_libraries(testgl2 OpenGL::GL)
endif()
file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
if(PSP OR PS2)
if(PSP)
set(NEEDS_RESOURCES
testscale
testrendercopyex
@@ -302,50 +177,48 @@ else()
testaudiohotplug
testmultiaudio
testime
testnative
testiconv
testoverlay2
teststreaming
testviewport
)
if(WINDOWS OR APPLE OR SDL_X11)
list(APPEND NEEDS_RESOURCES testnative)
endif()
endif()
if(PSP)
# Build EBOOT files if building for PSP
set(BUILD_EBOOT
${NEEDS_RESOURCES}
testatomic
testaudiocapture
testaudioinfo
testbounds
testdisplayinfo
testdraw2
testdrawchessboard
testerror
testfile
testfilesystem
testgeometry
testgl2
testguid
testhittesting
testiconv
testintersections
testjoystick
testlock
testmessage
testoverlay2
testplatform
testpower
testqsort
testsem
testdisplayinfo
teststreaming
testsurround
testthread
testtimer
testver
testgeometry
testfile
testdraw2
testviewport
testhittesting
testoverlay2
testver
testdrawchessboard
testsurround
testintersections
testmessage
testaudiocapture
testerror
testatomic
testjoystick
testiconv
testfilesystem
testplatform
testthread
testloadso
testqsort
testaudioinfo
testlock
testtimer
testpower
testwm2
torturethread
)
@@ -390,23 +263,9 @@ if(PSP)
endforeach()
endif()
if(RISCOS)
set(ALL_TESTS_AIF "")
foreach(APP IN LISTS ALL_TESTS)
target_link_options(${APP} PRIVATE -static)
add_custom_command(
OUTPUT ${APP},ff8
COMMAND elf2aif ${APP} ${APP},ff8
DEPENDS ${APP}
)
add_custom_target(${APP}-aif ALL DEPENDS ${APP},ff8)
list(APPEND ALL_TESTS_AIF ${CMAKE_CURRENT_BINARY_DIR}/${APP},ff8)
endforeach()
endif()
foreach(APP IN LISTS NEEDS_RESOURCES)
foreach(RESOURCE_FILE ${RESOURCE_FILES})
if(PSP OR PS2)
if(PSP)
add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>/sdl-${APP})
else()
add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
@@ -440,47 +299,3 @@ if(APPLE)
endforeach()
endif()
endif()
set(TESTS_ENVIRONMENT
SDL_AUDIODRIVER=dummy
SDL_VIDEODRIVER=dummy
)
foreach(TESTCASE ${NONINTERACTIVE} ${NEEDS_AUDIO} ${NEEDS_DISPLAY})
add_test(
NAME ${TESTCASE}
COMMAND ${TESTCASE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set_tests_properties(
${TESTCASE}
PROPERTIES ENVIRONMENT "${TESTS_ENVIRONMENT}"
)
if(SDL_INSTALL_TESTS)
set(exe ${TESTCASE})
set(installedtestsdir "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL2")
configure_file(template.test.in "${exe}.test" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${exe}.test"
DESTINATION ${CMAKE_INSTALL_DATADIR}/installed-tests/SDL2
)
endif()
endforeach()
if(SDL_INSTALL_TESTS)
if(RISCOS)
install(
FILES ${ALL_TESTS_AIF}
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
)
else()
install(
TARGETS ${ALL_TESTS}
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
)
endif()
install(
FILES ${RESOURCE_FILES}
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2
)
endif()

View File

@@ -2,15 +2,6 @@
srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
libexecdir = @libexecdir@
includedir = @includedir@
datarootdir = @datarootdir@
datadir = @datadir@
CC = @CC@
EXE = @EXE@
CFLAGS = @CFLAGS@ -g
@@ -40,7 +31,6 @@ TARGETS = \
testgamecontroller$(EXE) \
testgeometry$(EXE) \
testgesture$(EXE) \
testguid$(EXE) \
testhaptic$(EXE) \
testhittesting$(EXE) \
testhotplug$(EXE) \
@@ -89,26 +79,7 @@ TARGETS = \
@OPENGLES2_TARGETS@ += testgles2$(EXE)
all: Makefile $(TARGETS) copydatafiles generatetestmeta
installedtestsdir = $(libexecdir)/installed-tests/SDL2
installedtestsmetadir = $(datadir)/installed-tests/SDL2
generatetestmeta:
rm -f *.test
set -e; for exe in $(noninteractive) $(needs_audio) $(needs_display); do \
sed \
-e 's#@installedtestsdir@#$(installedtestsdir)#g' \
-e "s#@exe@#$$exe#g" \
< $(srcdir)/template.test.in > $$exe.test; \
done
install: all
install -d $(DESTDIR)$(installedtestsdir)
install $(TARGETS) $(DESTDIR)$(installedtestsdir)
install -m644 $(DATA) $(DESTDIR)$(installedtestsdir)
install -d $(DESTDIR)$(installedtestsmetadir)
install -m644 *.test $(DESTDIR)$(installedtestsmetadir)
all: Makefile $(TARGETS) copydatafiles
Makefile: $(srcdir)/Makefile.in
$(SHELL) config.status $@
@@ -119,10 +90,10 @@ checkkeys$(EXE): $(srcdir)/checkkeys.c
checkkeysthreads$(EXE): $(srcdir)/checkkeysthreads.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
loopwave$(EXE): $(srcdir)/loopwave.c $(srcdir)/testutils.c
loopwave$(EXE): $(srcdir)/loopwave.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
loopwavequeue$(EXE): $(srcdir)/loopwavequeue.c $(srcdir)/testutils.c
loopwavequeue$(EXE): $(srcdir)/loopwavequeue.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testsurround$(EXE): $(srcdir)/testsurround.c
@@ -152,14 +123,13 @@ testautomation$(EXE): $(srcdir)/testautomation.c \
$(srcdir)/testautomation_syswm.c \
$(srcdir)/testautomation_timer.c \
$(srcdir)/testautomation_video.c \
$(srcdir)/testautomation_hints.c \
$(srcdir)/testautomation_math.c
$(srcdir)/testautomation_hints.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c $(srcdir)/testutils.c
testmultiaudio$(EXE): $(srcdir)/testmultiaudio.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testaudiohotplug$(EXE): $(srcdir)/testaudiohotplug.c $(srcdir)/testutils.c
testaudiohotplug$(EXE): $(srcdir)/testaudiohotplug.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testaudiocapture$(EXE): $(srcdir)/testaudiocapture.c
@@ -195,15 +165,15 @@ testevdev$(EXE): $(srcdir)/testevdev.c
testfile$(EXE): $(srcdir)/testfile.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testgamecontroller$(EXE): $(srcdir)/testgamecontroller.c $(srcdir)/testutils.c
testgamecontroller$(EXE): $(srcdir)/testgamecontroller.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testgeometry$(EXE): $(srcdir)/testgeometry.c $(srcdir)/testutils.c
testgeometry$(EXE): $(srcdir)/testgeometry.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testgesture$(EXE): $(srcdir)/testgesture.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
testgl2$(EXE): $(srcdir)/testgl2.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
@@ -213,12 +183,9 @@ testgles$(EXE): $(srcdir)/testgles.c
testgles2$(EXE): $(srcdir)/testgles2.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
testgles2_sdf$(EXE): $(srcdir)/testgles2_sdf.c $(srcdir)/testutils.c
testgles2_sdf$(EXE): $(srcdir)/testgles2_sdf.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
testguid$(EXE): $(srcdir)/testguid.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testhaptic$(EXE): $(srcdir)/testhaptic.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
@@ -231,10 +198,10 @@ testrumble$(EXE): $(srcdir)/testrumble.c
testthread$(EXE): $(srcdir)/testthread.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testiconv$(EXE): $(srcdir)/testiconv.c $(srcdir)/testutils.c
testiconv$(EXE): $(srcdir)/testiconv.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testime$(EXE): $(srcdir)/testime.c $(srcdir)/testutils.c
testime$(EXE): $(srcdir)/testime.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @SDL_TTF_LIB@
testjoystick$(EXE): $(srcdir)/testjoystick.c
@@ -252,21 +219,18 @@ testlock$(EXE): $(srcdir)/testlock.c
ifeq (@ISMACOSX@,true)
testnative$(EXE): $(srcdir)/testnative.c \
$(srcdir)/testnativecocoa.m \
$(srcdir)/testutils.c \
$(srcdir)/testnativex11.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) -framework Cocoa @XLIB@
endif
ifeq (@ISWINDOWS@,true)
testnative$(EXE): $(srcdir)/testnative.c \
$(srcdir)/testutils.c \
$(srcdir)/testnativew32.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
endif
ifeq (@ISUNIX@,true)
testnative$(EXE): $(srcdir)/testnative.c \
$(srcdir)/testutils.c \
$(srcdir)/testnativex11.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @XLIB@
endif
@@ -288,7 +252,7 @@ endif
endif
endif
testoverlay2$(EXE): $(srcdir)/testoverlay2.c $(srcdir)/testyuv_cvt.c $(srcdir)/testutils.c
testoverlay2$(EXE): $(srcdir)/testoverlay2.c $(srcdir)/testyuv_cvt.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testplatform$(EXE): $(srcdir)/testplatform.c
@@ -300,10 +264,10 @@ testpower$(EXE): $(srcdir)/testpower.c
testfilesystem$(EXE): $(srcdir)/testfilesystem.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testrendertarget$(EXE): $(srcdir)/testrendertarget.c $(srcdir)/testutils.c
testrendertarget$(EXE): $(srcdir)/testrendertarget.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testscale$(EXE): $(srcdir)/testscale.c $(srcdir)/testutils.c
testscale$(EXE): $(srcdir)/testscale.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testsem$(EXE): $(srcdir)/testsem.c
@@ -318,13 +282,13 @@ testshader$(EXE): $(srcdir)/testshader.c
testshape$(EXE): $(srcdir)/testshape.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testsprite2$(EXE): $(srcdir)/testsprite2.c $(srcdir)/testutils.c
testsprite2$(EXE): $(srcdir)/testsprite2.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testspriteminimal$(EXE): $(srcdir)/testspriteminimal.c $(srcdir)/testutils.c
testspriteminimal$(EXE): $(srcdir)/testspriteminimal.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
teststreaming$(EXE): $(srcdir)/teststreaming.c $(srcdir)/testutils.c
teststreaming$(EXE): $(srcdir)/teststreaming.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
testtimer$(EXE): $(srcdir)/testtimer.c
@@ -336,7 +300,7 @@ testurl$(EXE): $(srcdir)/testurl.c
testver$(EXE): $(srcdir)/testver.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testviewport$(EXE): $(srcdir)/testviewport.c $(srcdir)/testutils.c
testviewport$(EXE): $(srcdir)/testviewport.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testwm2$(EXE): $(srcdir)/testwm2.c
@@ -348,7 +312,7 @@ testyuv$(EXE): $(srcdir)/testyuv.c $(srcdir)/testyuv_cvt.c
torturethread$(EXE): $(srcdir)/torturethread.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testrendercopyex$(EXE): $(srcdir)/testrendercopyex.c $(srcdir)/testutils.c
testrendercopyex$(EXE): $(srcdir)/testrendercopyex.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
testmessage$(EXE): $(srcdir)/testmessage.c
@@ -366,7 +330,7 @@ testbounds$(EXE): $(srcdir)/testbounds.c
testcustomcursor$(EXE): $(srcdir)/testcustomcursor.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
controllermap$(EXE): $(srcdir)/controllermap.c $(srcdir)/testutils.c
controllermap$(EXE): $(srcdir)/controllermap.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
testvulkan$(EXE): $(srcdir)/testvulkan.c
@@ -380,56 +344,13 @@ testmouse$(EXE): $(srcdir)/testmouse.c
clean:
rm -f $(TARGETS) *.test
rm -f $(TARGETS)
distclean: clean
rm -f Makefile
rm -f config.status config.cache config.log
rm -rf $(srcdir)/autom4te*
noninteractive = \
testatomic$(EXE) \
testerror$(EXE) \
testevdev$(EXE) \
testfilesystem$(EXE) \
testkeys$(EXE) \
testlocale$(EXE) \
testplatform$(EXE) \
testpower$(EXE) \
testqsort$(EXE) \
testthread$(EXE) \
testtimer$(EXE) \
testver$(EXE) \
$(NULL)
needs_audio = \
testaudioinfo$(EXE) \
testsurround$(EXE) \
$(NULL)
needs_display = \
testbounds$(EXE) \
testdisplayinfo$(EXE) \
$(NULL)
TESTS = $(noninteractive) $(needs_audio) $(needs_display)
check:
@set -e; \
status=0; \
export SDL_AUDIODRIVER=dummy; \
export SDL_VIDEODRIVER=dummy; \
for exe in $(TESTS); do \
echo "$$exe..."; \
if ./"$$exe"; then \
echo "$$exe: OK"; \
else \
echo "$$exe: FAILED: $$?"; \
status=1; \
fi; \
done; \
exit "$$status"
DATA = \
axis.bmp \
button.bmp \
@@ -443,7 +364,6 @@ DATA = \
testgles2_sdf_img_sdf.bmp \
testyuv.bmp \
unifont-13.0.06.hex \
utf8.txt \
$(NULL)
ifneq ($(srcdir), .)

View File

@@ -1,13 +1,77 @@
# Open Watcom makefile to build SDL2 tests for OS/2
# wmake -f Makefile.os2
SYSTEM = os2v2
INCPATH = -I"$(%WATCOM)/h/os2" -I"$(%WATCOM)/h" -I"../include"
INCPATH = -I"$(%WATCOM)/h/os2" -I"$(%WATCOM)/h"
CFLAGS = -bt=os2 -d0 -q -bm -5s -fp5 -fpi87 -sg -oteanbmier -ei
CFLAGS = $(INCPATH) -bt=os2 -d0 -q -bm -5s -fp5 -fpi87 -sg -oteanbmier -ei
CFLAGS+= -wx -wcd=303
TNSRCS = testnative.c testnativeos2.c
LIBPATH = ..
LIBS = SDL2.lib SDL2test.lib
!include watcom.mif
#CFLAGS+= -DHAVE_SDL_TTF
#TTFLIBS = SDL2ttf.lib
TARGETS = testatomic.exe testdisplayinfo.exe testbounds.exe testdraw2.exe &
testdrawchessboard.exe testdropfile.exe testerror.exe testfile.exe &
testfilesystem.exe testgamecontroller.exe testgeometry.exe testgesture.exe &
testhittesting.exe testhotplug.exe testiconv.exe testime.exe testlocale.exe &
testintersections.exe testjoystick.exe testkeys.exe testloadso.exe &
testlock.exe testmessage.exe testoverlay2.exe testplatform.exe &
testpower.exe testsensor.exe testrelative.exe testrendercopyex.exe &
testrendertarget.exe testrumble.exe testscale.exe testsem.exe &
testshader.exe testshape.exe testsprite2.exe testspriteminimal.exe &
teststreaming.exe testthread.exe testtimer.exe testver.exe &
testviewport.exe testwm2.exe torturethread.exe checkkeys.exe &
checkkeysthreads.exe testmouse.exe &
controllermap.exe testhaptic.exe testqsort.exe testresample.exe &
testaudioinfo.exe testaudiocapture.exe loopwave.exe loopwavequeue.exe &
testsurround.exe testyuv.exe testgl2.exe testvulkan.exe testnative.exe &
testautomation.exe
# testautomation sources
TASRCS = testautomation.c testautomation_audio.c testautomation_clipboard.c &
testautomation_events.c testautomation_hints.c &
testautomation_keyboard.c testautomation_main.c &
testautomation_mouse.c testautomation_pixels.c &
testautomation_platform.c testautomation_rect.c &
testautomation_render.c testautomation_rwops.c &
testautomation_sdltest.c testautomation_stdlib.c &
testautomation_surface.c testautomation_syswm.c &
testautomation_timer.c testautomation_video.c
OBJS = $(TARGETS:.exe=.obj)
COBJS = $(CSRCS:.c=.obj)
TAOBJS = $(TASRCS:.c=.obj)
all: $(TARGETS)
.c: ../src/test
.obj.exe:
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
.c.obj:
wcc386 $(CFLAGS) -fo=$^@ $<
# specials
testautomation.exe: $(TAOBJS)
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
testnative.exe: testnative.obj testnativeos2.obj
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
testoverlay2.exe: testoverlay2.obj testyuv_cvt.obj
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
testyuv.exe: testyuv.obj testyuv_cvt.obj
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
testime.exe: testime.obj
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS) $(TTFLIBS)} op q op el file {$<} name $@
clean: .SYMBOLIC
@if exist *.obj rm *.obj
@if exist *.err rm *.err
distclean: .SYMBOLIC clean
@if exist *.exe rm *.exe

View File

@@ -1,9 +1,11 @@
#!/bin/sh
set -e
cp acinclude.m4 aclocal.m4
"${AUTOCONF:-autoconf}"
if test "$AUTOCONF"x = x; then
AUTOCONF=autoconf
fi
$AUTOCONF || exit 1
rm aclocal.m4
rm -rf autom4te.cache

View File

@@ -165,11 +165,7 @@ loop()
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
break;
case SDL_TEXTEDITING:
PrintText("EDIT", event.edit.text);
break;
case SDL_TEXTEDITING_EXT:
PrintText("EDIT_EXT", event.editExt.text);
SDL_free(event.editExt.text);
PrintText("EDIT", event.text.text);
break;
case SDL_TEXTINPUT:
PrintText("INPUT", event.text.text);
@@ -211,9 +207,6 @@ main(int argc, char *argv[])
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Enable extended text editing events */
SDL_SetHint(SDL_HINT_IME_SUPPORT_EXTENDED_TEXT, "1");
/* Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());

File diff suppressed because it is too large Load Diff

View File

@@ -18,7 +18,6 @@
#include <string.h>
#include "SDL.h"
#include "testutils.h"
#ifndef SDL_JOYSTICK_DISABLED
@@ -170,6 +169,39 @@ static SDL_Renderer *screen;
static SDL_bool done = SDL_FALSE;
static SDL_bool bind_touchpad = SDL_FALSE;
SDL_Texture *
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
{
SDL_Surface *temp;
SDL_Texture *texture;
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return NULL;
}
/* Set transparent pixel as the pixel at (0,0) */
if (transparent) {
if (temp->format->palette) {
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
}
}
/* Create textures from the image */
texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!texture) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return NULL;
}
SDL_FreeSurface(temp);
/* We're ready to roll. :) */
return texture;
}
static int
StandardizeAxisValue(int nValue)
{
@@ -360,10 +392,10 @@ WatchJoystick(SDL_Joystick * joystick)
Uint32 alpha_ticks = 0;
SDL_JoystickID nJoystickID;
background_front = LoadTexture(screen, "controllermap.bmp", SDL_FALSE, NULL, NULL);
background_back = LoadTexture(screen, "controllermap_back.bmp", SDL_FALSE, NULL, NULL);
button = LoadTexture(screen, "button.bmp", SDL_TRUE, NULL, NULL);
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE, NULL, NULL);
background_front = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
background_back = LoadTexture(screen, "controllermap_back.bmp", SDL_FALSE);
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
SDL_RaiseWindow(window);
/* scale for platforms that don't give you the window size you asked for. */

View File

@@ -25,7 +25,6 @@
#endif
#include "SDL.h"
#include "testutils.h"
static struct
{
@@ -115,7 +114,7 @@ int
main(int argc, char *argv[])
{
int i;
char *filename = NULL;
char filename[4096];
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -126,13 +125,11 @@ main(int argc, char *argv[])
return (1);
}
filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
if (filename == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
quit(1);
if (argc > 1) {
SDL_strlcpy(filename, argv[1], sizeof(filename));
} else {
SDL_strlcpy(filename, "sample.wav", sizeof(filename));
}
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
@@ -175,7 +172,6 @@ main(int argc, char *argv[])
/* Clean up on signal */
close_audio();
SDL_FreeWAV(wave.sound);
SDL_free(filename);
SDL_Quit();
return (0);
}

View File

@@ -25,8 +25,6 @@
#include <signal.h>
#endif
#include "testutils.h"
static struct
{
SDL_AudioSpec spec;
@@ -76,7 +74,7 @@ loop()
int
main(int argc, char *argv[])
{
char *filename = NULL;
char filename[4096];
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -87,13 +85,11 @@ main(int argc, char *argv[])
return (1);
}
filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
if (filename == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
quit(1);
if (argc > 1) {
SDL_strlcpy(filename, argv[1], sizeof(filename));
} else {
SDL_strlcpy(filename, "sample.wav", sizeof(filename));
}
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
@@ -146,7 +142,6 @@ main(int argc, char *argv[])
/* Clean up on signal */
SDL_CloseAudio();
SDL_FreeWAV(wave.sound);
SDL_free(filename);
SDL_Quit();
return 0;
}

View File

@@ -471,6 +471,9 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event)
return status;
}
static SDL_sem *writersDone;
static SDL_sem *readersDone;
typedef struct
{
SDL_EventQueue *queue;
@@ -479,7 +482,6 @@ typedef struct
int waits;
SDL_bool lock_free;
char padding2[SDL_CACHELINE_SIZE-sizeof(int)-sizeof(SDL_bool)];
SDL_Thread *thread;
} WriterData;
typedef struct
@@ -489,7 +491,6 @@ typedef struct
int waits;
SDL_bool lock_free;
char padding[SDL_CACHELINE_SIZE-(sizeof(SDL_EventQueue*)+sizeof(int)*NUM_WRITERS+sizeof(int)+sizeof(SDL_bool))%SDL_CACHELINE_SIZE];
SDL_Thread *thread;
} ReaderData;
static int SDLCALL FIFO_Writer(void* _data)
@@ -522,6 +523,7 @@ static int SDLCALL FIFO_Writer(void* _data)
}
}
}
SDL_SemPost(writersDone);
return 0;
}
@@ -558,6 +560,7 @@ static int SDLCALL FIFO_Reader(void* _data)
}
}
}
SDL_SemPost(readersDone);
return 0;
}
@@ -587,7 +590,6 @@ static int SDLCALL FIFO_Watcher(void* _data)
static void RunFIFOTest(SDL_bool lock_free)
{
SDL_EventQueue queue;
SDL_Thread *fifo_thread = NULL;
WriterData writerData[NUM_WRITERS];
ReaderData readerData[NUM_READERS];
Uint32 start, end;
@@ -599,6 +601,9 @@ static void RunFIFOTest(SDL_bool lock_free)
SDL_Log("\nFIFO test---------------------------------------\n\n");
SDL_Log("Mode: %s\n", lock_free ? "LockFree" : "Mutex");
readersDone = SDL_CreateSemaphore(0);
writersDone = SDL_CreateSemaphore(0);
SDL_memset(&queue, 0xff, sizeof(queue));
InitEventQueue(&queue);
@@ -611,7 +616,7 @@ static void RunFIFOTest(SDL_bool lock_free)
#ifdef TEST_SPINLOCK_FIFO
/* Start a monitoring thread */
if (lock_free) {
fifo_thread = SDL_CreateThread(FIFO_Watcher, "FIFOWatcher", &queue);
SDL_CreateThread(FIFO_Watcher, "FIFOWatcher", &queue);
}
#endif
@@ -623,7 +628,7 @@ static void RunFIFOTest(SDL_bool lock_free)
SDL_snprintf(name, sizeof (name), "FIFOReader%d", i);
readerData[i].queue = &queue;
readerData[i].lock_free = lock_free;
readerData[i].thread = SDL_CreateThread(FIFO_Reader, name, &readerData[i]);
SDL_CreateThread(FIFO_Reader, name, &readerData[i]);
}
/* Start up the writers */
@@ -635,12 +640,12 @@ static void RunFIFOTest(SDL_bool lock_free)
writerData[i].queue = &queue;
writerData[i].index = i;
writerData[i].lock_free = lock_free;
writerData[i].thread = SDL_CreateThread(FIFO_Writer, name, &writerData[i]);
SDL_CreateThread(FIFO_Writer, name, &writerData[i]);
}
/* Wait for the writers */
for (i = 0; i < NUM_WRITERS; ++i) {
SDL_WaitThread(writerData[i].thread, NULL);
SDL_SemWait(writersDone);
}
/* Shut down the queue so readers exit */
@@ -648,15 +653,13 @@ static void RunFIFOTest(SDL_bool lock_free)
/* Wait for the readers */
for (i = 0; i < NUM_READERS; ++i) {
SDL_WaitThread(readerData[i].thread, NULL);
SDL_SemWait(readersDone);
}
end = SDL_GetTicks();
/* Wait for the FIFO thread */
if (fifo_thread) {
SDL_WaitThread(fifo_thread, NULL);
}
SDL_DestroySemaphore(readersDone);
SDL_DestroySemaphore(writersDone);
if (!lock_free) {
SDL_DestroyMutex(queue.mutex);
@@ -706,12 +709,6 @@ main(int argc, char *argv[])
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
RunBasicTest();
if (SDL_getenv("SDL_TESTS_QUICK") != NULL) {
SDL_Log("Not running slower tests");
return 0;
}
RunEpicTest();
/* This test is really slow, so don't run it by default */
#if 0

View File

@@ -26,7 +26,6 @@
#endif
#include "SDL.h"
#include "testutils.h"
static SDL_AudioSpec spec;
static Uint8 *sound = NULL; /* Pointer to wave data */
@@ -138,7 +137,7 @@ int
main(int argc, char *argv[])
{
int i;
char *filename = NULL;
char filename[4096];
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -152,13 +151,11 @@ main(int argc, char *argv[])
/* Some targets (Mac CoreAudio) need an event queue for audio hotplug, so make and immediately hide a window. */
SDL_MinimizeWindow(SDL_CreateWindow("testaudiohotplug", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0));
filename = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
if (filename == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
quit(1);
if (argc > 1) {
SDL_strlcpy(filename, argv[1], sizeof(filename));
} else {
SDL_strlcpy(filename, "sample.wav", sizeof(filename));
}
/* Load the wave file into memory */
if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError());
@@ -199,7 +196,6 @@ main(int argc, char *argv[])
/* Quit audio first, then free WAV. This prevents access violations in the audio threads. */
SDL_QuitSubSystem(SDL_INIT_AUDIO);
SDL_FreeWAV(sound);
SDL_free(filename);
SDL_Quit();
return (0);
}

View File

@@ -8,6 +8,7 @@
#include "SDL_test.h"
const int _numHintsEnum = 25;
const char* _HintsEnum[] =
{
SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
@@ -31,7 +32,9 @@ const char* _HintsEnum[] =
SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT,
SDL_HINT_VIDEO_WIN_D3DCOMPILER,
SDL_HINT_VIDEO_X11_XINERAMA,
SDL_HINT_VIDEO_X11_XRANDR,
SDL_HINT_VIDEO_X11_XVIDMODE,
SDL_HINT_XINPUT_ENABLED,
};
const char* _HintsVerbose[] =
@@ -57,13 +60,12 @@ const char* _HintsVerbose[] =
"SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
"SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
"SDL_VIDEO_WIN_D3DCOMPILER",
"SDL_VIDEO_X11_XINERAMA",
"SDL_VIDEO_X11_XRANDR",
"SDL_VIDEO_X11_XVIDMODE",
"SDL_XINPUT_ENABLED"
};
SDL_COMPILE_TIME_ASSERT(HintsEnum, SDL_arraysize(_HintsEnum) == SDL_arraysize(_HintsVerbose));
const int _numHintsEnum = SDL_arraysize(_HintsEnum);
/* Test case functions */

View File

@@ -54,18 +54,12 @@ int platform_testTypes(void *arg)
int platform_testEndianessAndSwap(void *arg)
{
int real_byteorder;
int real_floatwordorder = 0;
Uint16 value = 0x1234;
Uint16 value16 = 0xCDAB;
Uint16 swapped16 = 0xABCD;
Uint32 value32 = 0xEFBEADDE;
Uint32 swapped32 = 0xDEADBEEF;
union {
double d;
Uint32 ui32[2];
} value_double;
Uint64 value64, swapped64;
value64 = 0xEFBEADDE;
value64 <<= 32;
@@ -73,7 +67,6 @@ int platform_testEndianessAndSwap(void *arg)
swapped64 = 0x1234ABCD;
swapped64 <<= 32;
swapped64 |= 0xDEADBEEF;
value_double.d = 3.141593;
if ((*((char *) &value) >> 4) == 0x1) {
real_byteorder = SDL_BIG_ENDIAN;
@@ -87,18 +80,6 @@ int platform_testEndianessAndSwap(void *arg)
(SDL_BYTEORDER == SDL_LIL_ENDIAN) ? "little" : "big",
(real_byteorder == SDL_LIL_ENDIAN) ? "little" : "big" );
if (value_double.ui32[0] == 0x82c2bd7f && value_double.ui32[1] == 0x400921fb) {
real_floatwordorder = SDL_LIL_ENDIAN;
} else if (value_double.ui32[0] == 0x400921fb && value_double.ui32[1] == 0x82c2bd7f) {
real_floatwordorder = SDL_BIG_ENDIAN;
}
/* Test endianness. */
SDLTest_AssertCheck( real_floatwordorder == SDL_FLOATWORDORDER,
"Machine detected as having %s endian float word order, appears to be %s endian.",
(SDL_FLOATWORDORDER == SDL_LIL_ENDIAN) ? "little" : "big",
(real_floatwordorder == SDL_LIL_ENDIAN) ? "little" : (real_floatwordorder == SDL_BIG_ENDIAN) ? "big" : "unknown" );
/* Test 16 swap. */
SDLTest_AssertCheck( SDL_Swap16(value16) == swapped16,
"SDL_Swap16(): 16 bit swapped: 0x%X => 0x%X",
@@ -544,7 +525,7 @@ static const SDLTest_TestCaseReference platformTest1 =
{ (SDLTest_TestCaseFp)platform_testTypes, "platform_testTypes", "Tests predefined types", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest2 =
{ (SDLTest_TestCaseFp)platform_testEndianessAndSwap, "platform_testEndianessAndSwap", "Tests endianness and swap functions", TEST_ENABLED};
{ (SDLTest_TestCaseFp)platform_testEndianessAndSwap, "platform_testEndianessAndSwap", "Tests endianess and swap functions", TEST_ENABLED};
static const SDLTest_TestCaseReference platformTest3 =
{ (SDLTest_TestCaseFp)platform_testGetFunctions, "platform_testGetFunctions", "Tests various SDL_GetXYZ functions", TEST_ENABLED};

View File

@@ -408,32 +408,6 @@ void _validateRectEqualsResults(
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
}
/* !
* \brief Private helper to check SDL_FRectEquals results
*/
void _validateFRectEqualsResults(
SDL_bool equals, SDL_bool expectedEquals,
SDL_FRect *rectA, SDL_FRect *rectB, SDL_FRect *refRectA, SDL_FRect *refRectB)
{
int cmpRes;
SDLTest_AssertCheck(equals == expectedEquals,
"Check for correct equals result: expected %s, got %s testing (%f,%f,%f,%f) and (%f,%f,%f,%f)",
(expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
(equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
rectA->x, rectA->y, rectA->w, rectA->h,
rectB->x, rectB->y, rectB->w, rectB->h);
cmpRes = SDL_memcmp(rectA, refRectA, sizeof(*rectA));
SDLTest_AssertCheck(cmpRes == 0,
"Check that source rectangle A was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
rectA->x, rectA->y, rectA->w, rectA->h,
refRectA->x, refRectA->y, refRectA->w, refRectA->h);
cmpRes = SDL_memcmp(rectB, refRectB, sizeof(*rectB));
SDLTest_AssertCheck(cmpRes == 0,
"Check that source rectangle B was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
rectB->x, rectB->y, rectB->w, rectB->h,
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
}
/* !
* \brief Tests SDL_IntersectRect() with B fully inside A
*
@@ -707,7 +681,7 @@ int rect_testIntersectRectEmpty (void *arg)
int rect_testIntersectRectParam(void *arg)
{
SDL_Rect rectA;
SDL_Rect rectB = {0};
SDL_Rect rectB;
SDL_Rect result;
SDL_bool intersection;
@@ -962,7 +936,7 @@ int rect_testHasIntersectionEmpty (void *arg)
int rect_testHasIntersectionParam(void *arg)
{
SDL_Rect rectA;
SDL_Rect rectB = {0};
SDL_Rect rectB;
SDL_bool intersection;
/* invalid parameter combinations */
@@ -1231,7 +1205,7 @@ int rect_testEnclosePointsParam(void *arg)
{
SDL_Point points[1];
int count;
SDL_Rect clip = { 0 };
SDL_Rect clip;
SDL_Rect result;
SDL_bool anyEnclosed;
@@ -1457,7 +1431,7 @@ int rect_testUnionRectInside(void *arg)
*/
int rect_testUnionRectParam(void *arg)
{
SDL_Rect rectA, rectB = { 0 };
SDL_Rect rectA, rectB;
SDL_Rect result;
/* invalid parameter combinations */
@@ -1600,69 +1574,6 @@ int rect_testRectEqualsParam(void *arg)
return TEST_COMPLETED;
}
/* !
* \brief Tests SDL_FRectEquals() with various inputs
*
* \sa
* http://wiki.libsdl.org/SDL_FRectEquals
*/
int rect_testFRectEquals(void *arg)
{
SDL_FRect refRectA;
SDL_FRect refRectB;
SDL_FRect rectA;
SDL_FRect rectB;
SDL_bool expectedResult;
SDL_bool result;
/* Equals */
refRectA.x=(float)SDLTest_RandomIntegerInRange(-1024, 1024);
refRectA.y=(float)SDLTest_RandomIntegerInRange(-1024, 1024);
refRectA.w=(float)SDLTest_RandomIntegerInRange(1, 1024);
refRectA.h=(float)SDLTest_RandomIntegerInRange(1, 1024);
refRectB = refRectA;
expectedResult = SDL_TRUE;
rectA = refRectA;
rectB = refRectB;
result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)&rectA, (const SDL_FRect *)&rectB);
_validateFRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
return TEST_COMPLETED;
}
/* !
* \brief Negative tests against SDL_FRectEquals() with invalid parameters
*
* \sa
* http://wiki.libsdl.org/SDL_FRectEquals
*/
int rect_testFRectEqualsParam(void *arg)
{
SDL_FRect rectA;
SDL_FRect rectB;
SDL_bool result;
/* data setup -- For the purpose of this test, the values don't matter. */
rectA.x=SDLTest_RandomFloat();
rectA.y=SDLTest_RandomFloat();
rectA.w=SDLTest_RandomFloat();
rectA.h=SDLTest_RandomFloat();
rectB.x=SDLTest_RandomFloat();
rectB.y=SDLTest_RandomFloat();
rectB.w=SDLTest_RandomFloat();
rectB.h=SDLTest_RandomFloat();
/* invalid parameter combinations */
result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)NULL, (const SDL_FRect *)&rectB);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)&rectA, (const SDL_FRect *)NULL);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)NULL, (const SDL_FRect *)NULL);
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL");
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Rect test cases */
@@ -1762,13 +1673,6 @@ static const SDLTest_TestCaseReference rectTest28 =
static const SDLTest_TestCaseReference rectTest29 =
{ (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED };
/* SDL_FRectEquals */
static const SDLTest_TestCaseReference rectTest30 =
{ (SDLTest_TestCaseFp)rect_testFRectEquals, "rect_testFRectEquals", "Tests SDL_FRectEquals with various inputs", TEST_ENABLED };
static const SDLTest_TestCaseReference rectTest31 =
{ (SDLTest_TestCaseFp)rect_testFRectEqualsParam, "rect_testFRectEqualsParam", "Negative tests against SDL_FRectEquals with invalid parameters", TEST_ENABLED };
/* !
* \brief Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
@@ -1779,7 +1683,7 @@ static const SDLTest_TestCaseReference rectTest31 =
static const SDLTest_TestCaseReference *rectTests[] = {
&rectTest1, &rectTest2, &rectTest3, &rectTest4, &rectTest5, &rectTest6, &rectTest7, &rectTest8, &rectTest9, &rectTest10, &rectTest11, &rectTest12, &rectTest13, &rectTest14,
&rectTest15, &rectTest16, &rectTest17, &rectTest18, &rectTest19, &rectTest20, &rectTest21, &rectTest22, &rectTest23, &rectTest24, &rectTest25, &rectTest26, &rectTest27,
&rectTest28, &rectTest29, &rectTest30, &rectTest31, NULL
&rectTest28, &rectTest29, NULL
};

View File

@@ -187,14 +187,14 @@ int render_testPrimitives (void *arg)
ret = SDL_RenderDrawLine(renderer, 79, 59, 50, 30 );
SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
/* Make current */
SDL_RenderPresent(renderer);
/* See if it's the same. */
referenceSurface = SDLTest_ImagePrimitives();
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
/* Make current */
SDL_RenderPresent(renderer);
/* Clean up. */
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
@@ -335,13 +335,13 @@ int render_testPrimitivesBlend (void *arg)
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_RenderDrawPoint, expected: 0, got: %i", checkFailCount3);
/* Make current */
SDL_RenderPresent(renderer);
/* See if it's the same. */
referenceSurface = SDLTest_ImagePrimitivesBlend();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
/* Make current */
SDL_RenderPresent(renderer);
/* Clean up. */
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
@@ -404,13 +404,13 @@ render_testBlit(void *arg)
}
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount1);
/* Make current */
SDL_RenderPresent(renderer);
/* See if it's the same */
referenceSurface = SDLTest_ImageBlit();
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
/* Make current */
SDL_RenderPresent(renderer);
/* Clean up. */
SDL_DestroyTexture( tface );
SDL_FreeSurface(referenceSurface);
@@ -478,13 +478,13 @@ render_testBlitColor (void *arg)
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
/* Make current */
SDL_RenderPresent(renderer);
/* See if it's the same. */
referenceSurface = SDLTest_ImageBlitColor();
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
/* Make current */
SDL_RenderPresent(renderer);
/* Clean up. */
SDL_DestroyTexture( tface );
SDL_FreeSurface(referenceSurface);
@@ -555,13 +555,13 @@ render_testBlitAlpha (void *arg)
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", checkFailCount1);
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
/* Make current */
SDL_RenderPresent(renderer);
/* See if it's the same. */
referenceSurface = SDLTest_ImageBlitAlpha();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
/* Make current */
SDL_RenderPresent(renderer);
/* Clean up. */
SDL_DestroyTexture( tface );
SDL_FreeSurface(referenceSurface);
@@ -674,10 +674,9 @@ render_testBlitBlend (void *arg)
_testBlitBlendMode( tface, SDL_BLENDMODE_NONE );
referenceSurface = SDLTest_ImageBlitBlendNone();
/* Compare, then Present */
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
/* Make current and compare */
SDL_RenderPresent(renderer);
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
@@ -685,10 +684,9 @@ render_testBlitBlend (void *arg)
_testBlitBlendMode( tface, SDL_BLENDMODE_BLEND );
referenceSurface = SDLTest_ImageBlitBlend();
/* Compare, then Present */
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
/* Make current and compare */
SDL_RenderPresent(renderer);
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
@@ -696,10 +694,9 @@ render_testBlitBlend (void *arg)
_testBlitBlendMode( tface, SDL_BLENDMODE_ADD );
referenceSurface = SDLTest_ImageBlitBlendAdd();
/* Compare, then Present */
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
/* Make current and compare */
SDL_RenderPresent(renderer);
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
@@ -707,10 +704,9 @@ render_testBlitBlend (void *arg)
_testBlitBlendMode( tface, SDL_BLENDMODE_MOD);
referenceSurface = SDLTest_ImageBlitBlendMod();
/* Compare, then Present */
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
/* Make current and compare */
SDL_RenderPresent(renderer);
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;
@@ -757,13 +753,12 @@ render_testBlitBlend (void *arg)
/* Clean up. */
SDL_DestroyTexture( tface );
/* Check to see if final image matches. */
referenceSurface = SDLTest_ImageBlitBlendAll();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
/* Make current */
SDL_RenderPresent(renderer);
/* Check to see if final image matches. */
referenceSurface = SDLTest_ImageBlitBlendAll();
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
SDL_FreeSurface(referenceSurface);
referenceSurface = NULL;

View File

@@ -322,168 +322,6 @@ stdlib_sscanf(void *arg)
return TEST_COMPLETED;
}
#if defined(_WIN64)
# define SIZE_FORMAT "I64u"
#elif defined(__WIN32__)
# define SIZE_FORMAT "I32u"
#else
# define SIZE_FORMAT "zu"
#endif
typedef struct
{
size_t a;
size_t b;
size_t result;
int status;
} overflow_test;
static const overflow_test multiplications[] =
{
{ 1, 1, 1, 0 },
{ 0, 0, 0, 0 },
{ SDL_SIZE_MAX, 0, 0, 0 },
{ SDL_SIZE_MAX, 1, SDL_SIZE_MAX, 0 },
{ SDL_SIZE_MAX / 2, 2, SDL_SIZE_MAX - (SDL_SIZE_MAX % 2), 0 },
{ SDL_SIZE_MAX / 23, 23, SDL_SIZE_MAX - (SDL_SIZE_MAX % 23), 0 },
{ (SDL_SIZE_MAX / 2) + 1, 2, 0, -1 },
{ (SDL_SIZE_MAX / 23) + 42, 23, 0, -1 },
{ SDL_SIZE_MAX, SDL_SIZE_MAX, 0, -1 },
};
static const overflow_test additions[] =
{
{ 1, 1, 2, 0 },
{ 0, 0, 0, 0 },
{ SDL_SIZE_MAX, 0, SDL_SIZE_MAX, 0 },
{ SDL_SIZE_MAX - 1, 1, SDL_SIZE_MAX, 0 },
{ SDL_SIZE_MAX - 42, 23, SDL_SIZE_MAX - (42 - 23), 0 },
{ SDL_SIZE_MAX, 1, 0, -1 },
{ SDL_SIZE_MAX, 23, 0, -1 },
{ SDL_SIZE_MAX, SDL_SIZE_MAX, 0, -1 },
};
static int
stdlib_overflow(void *arg)
{
size_t i;
size_t useBuiltin;
for (useBuiltin = 0; useBuiltin < 2; useBuiltin++) {
if (useBuiltin) {
SDLTest_Log("Using gcc/clang builtins if possible");
} else {
SDLTest_Log("Not using gcc/clang builtins");
}
for (i = 0; i < SDL_arraysize(multiplications); i++) {
const overflow_test *t = &multiplications[i];
int status;
size_t result = ~t->result;
if (useBuiltin) {
status = SDL_size_mul_overflow(t->a, t->b, &result);
} else {
/* This disables the macro that tries to use a gcc/clang
* builtin, so we test the fallback implementation instead. */
status = (SDL_size_mul_overflow)(t->a, t->b, &result);
}
if (t->status == 0) {
SDLTest_AssertCheck(status == 0,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should succeed",
t->a, t->b);
SDLTest_AssertCheck(result == t->result,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
t->a, t->b, t->result, result);
} else {
SDLTest_AssertCheck(status == -1,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should fail",
t->a, t->b);
}
if (t->a == t->b) {
continue;
}
result = ~t->result;
if (useBuiltin) {
status = SDL_size_mul_overflow(t->b, t->a, &result);
} else {
status = (SDL_size_mul_overflow)(t->b, t->a, &result);
}
if (t->status == 0) {
SDLTest_AssertCheck(status == 0,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should succeed",
t->b, t->a);
SDLTest_AssertCheck(result == t->result,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
t->b, t->a, t->result, result);
} else {
SDLTest_AssertCheck(status == -1,
"(%" SIZE_FORMAT " * %" SIZE_FORMAT ") should fail",
t->b, t->a);
}
}
for (i = 0; i < SDL_arraysize(additions); i++) {
const overflow_test *t = &additions[i];
int status;
size_t result = ~t->result;
if (useBuiltin) {
status = SDL_size_add_overflow(t->a, t->b, &result);
} else {
status = (SDL_size_add_overflow)(t->a, t->b, &result);
}
if (t->status == 0) {
SDLTest_AssertCheck(status == 0,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should succeed",
t->a, t->b);
SDLTest_AssertCheck(result == t->result,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
t->a, t->b, t->result, result);
} else {
SDLTest_AssertCheck(status == -1,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should fail",
t->a, t->b);
}
if (t->a == t->b) {
continue;
}
result = ~t->result;
if (useBuiltin) {
status = SDL_size_add_overflow(t->b, t->a, &result);
} else {
status = (SDL_size_add_overflow)(t->b, t->a, &result);
}
if (t->status == 0) {
SDLTest_AssertCheck(status == 0,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should succeed",
t->b, t->a);
SDLTest_AssertCheck(result == t->result,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT "): expected %" SIZE_FORMAT ", got %" SIZE_FORMAT,
t->b, t->a, t->result, result);
} else {
SDLTest_AssertCheck(status == -1,
"(%" SIZE_FORMAT " + %" SIZE_FORMAT ") should fail",
t->b, t->a);
}
}
}
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Standard C routine test cases */
@@ -499,17 +337,9 @@ static const SDLTest_TestCaseReference stdlibTest3 =
static const SDLTest_TestCaseReference stdlibTest4 =
{ (SDLTest_TestCaseFp)stdlib_sscanf, "stdlib_sscanf", "Call to SDL_sscanf", TEST_ENABLED };
static const SDLTest_TestCaseReference stdlibTestOverflow =
{ stdlib_overflow, "stdlib_overflow", "Overflow detection", TEST_ENABLED };
/* Sequence of Standard C routine test cases */
static const SDLTest_TestCaseReference *stdlibTests[] = {
&stdlibTest1,
&stdlibTest2,
&stdlibTest3,
&stdlibTest4,
&stdlibTestOverflow,
NULL
&stdlibTest1, &stdlibTest2, &stdlibTest3, &stdlibTest4, NULL
};
/* Standard C routine test suite (global) */

View File

@@ -27,7 +27,6 @@ extern SDLTest_TestSuiteReference syswmTestSuite;
extern SDLTest_TestSuiteReference timerTestSuite;
extern SDLTest_TestSuiteReference videoTestSuite;
extern SDLTest_TestSuiteReference hintsTestSuite;
extern SDLTest_TestSuiteReference mathTestSuite;
/* All test suites */
SDLTest_TestSuiteReference *testSuites[] = {
@@ -49,7 +48,6 @@ SDLTest_TestSuiteReference *testSuites[] = {
&timerTestSuite,
&videoTestSuite,
&hintsTestSuite,
&mathTestSuite,
NULL
};

View File

@@ -178,10 +178,6 @@ void _testBlitBlendMode(int mode)
bmode = SDL_BLENDMODE_ADD;
} else if (nmode==3) {
bmode = SDL_BLENDMODE_MOD;
} else {
/* Should be impossible, but some static checkers are too imprecise and will complain */
SDLTest_LogError("Invalid: nmode=%d", nmode);
return;
}
ret = SDL_SetSurfaceBlendMode( face, bmode );
if (ret != 0) checkFailCount4++;
@@ -337,7 +333,7 @@ surface_testCompleteSurfaceConversion(void *arg)
SDL_PIXELFORMAT_RGBA8888,
SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_ARGB2101010,
/*SDL_PIXELFORMAT_ARGB2101010,*/ /* SDL_PIXELFORMAT_ARGB2101010 isn't fully supported yet */
};
SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
SDL_PixelFormat *fmt1, *fmt2;
@@ -593,177 +589,6 @@ surface_testBlitBlendLoop(void *arg) {
}
int
surface_testOverflow(void *arg)
{
char buf[1024];
const char *expectedError;
SDL_Surface *surface;
SDL_memset(buf, '\0', sizeof(buf));
expectedError = "Parameter 'width' is invalid";
surface = SDL_CreateRGBSurfaceWithFormat(0, -3, 100, 8, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, -1, 1, 8, 4, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceFrom(buf, -1, 1, 32, 4, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
expectedError = "Parameter 'height' is invalid";
surface = SDL_CreateRGBSurfaceWithFormat(0, 100, -3, 8, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 1, -1, 8, 4, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceFrom(buf, 1, -1, 32, 4, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
expectedError = "Parameter 'pitch' is invalid";
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 4, 1, 8, -1, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceFrom(buf, 1, 1, 32, -1, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
/* 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_INDEX4* needs 1 byte per 2 pixels. */
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 6, 1, 4, 3, SDL_PIXELFORMAT_INDEX4LSB);
SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceFrom(buf, 6, 1, 4, 3, 0, 0, 0, 0);
SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 7, 1, 4, 3, SDL_PIXELFORMAT_INDEX4LSB);
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_CreateRGBSurfaceFrom(buf, 7, 1, 4, 3, 0, 0, 0, 0);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 7, 1, 4, 4, SDL_PIXELFORMAT_INDEX4LSB);
SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceFrom(buf, 7, 1, 4, 4, 0, 0, 0, 0);
SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
/* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 16, 1, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceFrom(buf, 16, 1, 1, 2, 0, 0, 0, 0);
SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 17, 1, 1, 2, SDL_PIXELFORMAT_INDEX1LSB);
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_CreateRGBSurfaceFrom(buf, 17, 1, 1, 2, 0, 0, 0, 0);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 17, 1, 1, 3, SDL_PIXELFORMAT_INDEX1LSB);
SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceFrom(buf, 7, 1, 1, 3, 0, 0, 0, 0);
SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
/* SDL_PIXELFORMAT_INDEX8 and SDL_PIXELFORMAT_RGB332 require 1 byte per pixel. */
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 5, 1, 8, 5, SDL_PIXELFORMAT_RGB332);
SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceFrom(buf, 5, 1, 8, 5, 0, 0, 0, 0);
SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 6, 1, 8, 5, SDL_PIXELFORMAT_RGB332);
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_CreateRGBSurfaceFrom(buf, 6, 1, 8, 5, 0, 0, 0, 0);
SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
/* Everything else requires more than 1 byte per pixel, and rounds up
* each pixel to an integer number of bytes (e.g. RGB555 is really
* XRGB1555, with 1 bit per pixel wasted). */
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 3, 1, 15, 6, SDL_PIXELFORMAT_RGB555);
SDLTest_AssertCheck(surface != NULL, "3px * 15 (really 16) bits per px fits in 6 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceFrom(buf, 3, 1, 15, 6, 0, 0, 0, 0);
SDLTest_AssertCheck(surface != NULL, "5px * 15 (really 16) bits per px fits in 6 bytes: %s",
surface != NULL ? "(success)" : SDL_GetError());
SDL_FreeSurface(surface);
surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 4, 1, 15, 6, SDL_PIXELFORMAT_RGB555);
SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceFrom(buf, 4, 1, 15, 6, 0, 0, 0, 0);
SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
if (sizeof (size_t) == 4 && sizeof (int) >= 4) {
expectedError = "Out of memory";
surface = SDL_CreateRGBSurfaceWithFormat(0, SDL_MAX_SINT32, 1, 8, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width + alignment");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormat(0, SDL_MAX_SINT32 / 2, 1, 32, SDL_PIXELFORMAT_ARGB8888);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * bytes per pixel");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormat(0, (1 << 29) - 1, (1 << 29) - 1, 8, SDL_PIXELFORMAT_INDEX8);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
surface = SDL_CreateRGBSurfaceWithFormat(0, (1 << 15) + 1, (1 << 15) + 1, 32, SDL_PIXELFORMAT_ARGB8888);
SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height * bytes per pixel");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
"Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
}
else {
SDLTest_Log("Can't easily overflow size_t on this platform");
}
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Surface test cases */
@@ -806,14 +631,11 @@ static const SDLTest_TestCaseReference surfaceTest11 =
static const SDLTest_TestCaseReference surfaceTest12 =
{ (SDLTest_TestCaseFp)surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED};
static const SDLTest_TestCaseReference surfaceTestOverflow =
{ surface_testOverflow, "surface_testOverflow", "Test overflow detection.", TEST_ENABLED};
/* Sequence of Surface test cases */
static const SDLTest_TestCaseReference *surfaceTests[] = {
&surfaceTest1, &surfaceTest2, &surfaceTest3, &surfaceTest4, &surfaceTest5,
&surfaceTest6, &surfaceTest7, &surfaceTest8, &surfaceTest9, &surfaceTest10,
&surfaceTest11, &surfaceTest12, &surfaceTestOverflow, NULL
&surfaceTest11, &surfaceTest12, NULL
};
/* Surface test suite (global) */

View File

@@ -1372,8 +1372,7 @@ video_getSetWindowMinimumSize(void *arg)
int wVariation, hVariation;
int referenceW, referenceH;
int currentW, currentH;
int desiredW = 1;
int desiredH = 1;
int desiredW, desiredH;
/* Get display bounds for size range */
result = SDL_GetDisplayBounds(0, &display);
@@ -1849,129 +1848,6 @@ video_getSetWindowData(void *arg)
return returnValue;
}
/**
* @brief Tests the functionality of the SDL_WINDOWPOS_CENTERED_DISPLAY along with SDL_WINDOW_FULLSCREEN_DESKTOP.
*
* Espeically useful when run on a multi-monitor system with different DPI scales per monitor,
* to test that the window size is maintained when moving between monitors.
*/
int
video_setWindowCenteredOnDisplay(void *arg)
{
SDL_Window *window;
const char *title = "video_setWindowCenteredOnDisplay Test Window";
int x, y, w, h;
int xVariation, yVariation;
int displayNum;
int result;
SDL_Rect display0, display1;
displayNum = SDL_GetNumVideoDisplays();
/* Get display bounds */
result = SDL_GetDisplayBounds(0 % displayNum, &display0);
SDLTest_AssertPass("SDL_GetDisplayBounds()");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
if (result != 0)
return TEST_ABORTED;
result = SDL_GetDisplayBounds(1 % displayNum, &display1);
SDLTest_AssertPass("SDL_GetDisplayBounds()");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
if (result != 0)
return TEST_ABORTED;
for (xVariation = 0; xVariation < 2; xVariation++) {
for (yVariation = 0; yVariation < 2; yVariation++) {
int currentX = 0, currentY = 0;
int currentW = 0, currentH = 0;
int expectedX = 0, expectedY = 0;
int currentDisplay;
int expectedDisplay;
SDL_Rect expectedDisplayRect;
/* xVariation is the display we start on */
expectedDisplay = xVariation % displayNum;
x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
w = SDLTest_RandomIntegerInRange(640, 800);
h = SDLTest_RandomIntegerInRange(400, 600);
expectedDisplayRect = (xVariation == 0) ? display0 : display1;
expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
window = SDL_CreateWindow(title, x, y, w, h, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
SDLTest_AssertPass("Call to SDL_CreateWindow('Title',%d,%d,%d,%d,SHOWN)", x, y, w, h);
SDLTest_AssertCheck(window != NULL, "Validate that returned window struct is not NULL");
/* Check the window is centered on the requested display */
currentDisplay = SDL_GetWindowDisplayIndex(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
/* Enter fullscreen desktop */
result = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
/* Check we are filling the full display */
currentDisplay = SDL_GetWindowDisplayIndex(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
SDLTest_AssertCheck(currentW == expectedDisplayRect.w, "Validate width (current: %d, expected: %d)", currentW, expectedDisplayRect.w);
SDLTest_AssertCheck(currentH == expectedDisplayRect.h, "Validate height (current: %d, expected: %d)", currentH, expectedDisplayRect.h);
SDLTest_AssertCheck(currentX == expectedDisplayRect.x, "Validate x (current: %d, expected: %d)", currentX, expectedDisplayRect.x);
SDLTest_AssertCheck(currentY == expectedDisplayRect.y, "Validate y (current: %d, expected: %d)", currentY, expectedDisplayRect.y);
/* Leave fullscreen desktop */
result = SDL_SetWindowFullscreen(window, 0);
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
/* Check window was restored correctly */
currentDisplay = SDL_GetWindowDisplayIndex(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
/* Center on display yVariation, and check window properties */
expectedDisplay = yVariation % displayNum;
x = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
y = SDL_WINDOWPOS_CENTERED_DISPLAY(expectedDisplay);
expectedDisplayRect = (expectedDisplay == 0) ? display0 : display1;
expectedX = (expectedDisplayRect.x + ((expectedDisplayRect.w - w) / 2));
expectedY = (expectedDisplayRect.y + ((expectedDisplayRect.h - h) / 2));
SDL_SetWindowPosition(window, x, y);
currentDisplay = SDL_GetWindowDisplayIndex(window);
SDL_GetWindowSize(window, &currentW, &currentH);
SDL_GetWindowPosition(window, &currentX, &currentY);
SDLTest_AssertCheck(currentDisplay == expectedDisplay, "Validate display index (current: %d, expected: %d)", currentDisplay, expectedDisplay);
SDLTest_AssertCheck(currentW == w, "Validate width (current: %d, expected: %d)", currentW, w);
SDLTest_AssertCheck(currentH == h, "Validate height (current: %d, expected: %d)", currentH, h);
SDLTest_AssertCheck(currentX == expectedX, "Validate x (current: %d, expected: %d)", currentX, expectedX);
SDLTest_AssertCheck(currentY == expectedY, "Validate y (current: %d, expected: %d)", currentY, expectedY);
/* Clean up */
_destroyVideoSuiteTestWindow(window);
}
}
return TEST_COMPLETED;
}
/* ================= Test References ================== */
@@ -2045,16 +1921,13 @@ static const SDLTest_TestCaseReference videoTest22 =
static const SDLTest_TestCaseReference videoTest23 =
{ (SDLTest_TestCaseFp)video_getSetWindowData, "video_getSetWindowData", "Checks SDL_SetWindowData and SDL_GetWindowData positive and negative cases", TEST_ENABLED };
static const SDLTest_TestCaseReference videoTest24 =
{ (SDLTest_TestCaseFp) video_setWindowCenteredOnDisplay, "video_setWindowCenteredOnDisplay", "Checks using SDL_WINDOWPOS_CENTERED_DISPLAY centers the window on a display", TEST_ENABLED };
/* Sequence of Video test cases */
static const SDLTest_TestCaseReference *videoTests[] = {
&videoTest1, &videoTest2, &videoTest3, &videoTest4, &videoTest5, &videoTest6,
&videoTest7, &videoTest8, &videoTest9, &videoTest10, &videoTest11, &videoTest12,
&videoTest13, &videoTest14, &videoTest15, &videoTest16, &videoTest17,
&videoTest18, &videoTest19, &videoTest20, &videoTest21, &videoTest22,
&videoTest23, &videoTest24, NULL
&videoTest23, NULL
};
/* Video test suite (global) */

View File

@@ -135,8 +135,6 @@ init_system_cursor(const char *image[])
static SDLTest_CommonState *state;
int done;
static SDL_Cursor *cursors[1+SDL_NUM_SYSTEM_CURSORS];
static SDL_SystemCursor cursor_types[1+SDL_NUM_SYSTEM_CURSORS];
static int num_cursors;
static int current_cursor;
static int show_cursor;
@@ -158,34 +156,11 @@ loop()
SDLTest_CommonEvent(state, &event, &done);
if (event.type == SDL_MOUSEBUTTONDOWN) {
if (event.button.button == SDL_BUTTON_LEFT) {
if (num_cursors == 0) {
continue;
}
++current_cursor;
if (current_cursor == num_cursors) {
if (current_cursor == SDL_arraysize(cursors)) {
current_cursor = 0;
}
SDL_SetCursor(cursors[current_cursor]);
switch (cursor_types[current_cursor]) {
case (SDL_SystemCursor)-1: SDL_Log("Custom cursor"); break;
case SDL_SYSTEM_CURSOR_ARROW: SDL_Log("Arrow"); break;
case SDL_SYSTEM_CURSOR_IBEAM: SDL_Log("I-beam"); break;
case SDL_SYSTEM_CURSOR_WAIT: SDL_Log("Wait"); break;
case SDL_SYSTEM_CURSOR_CROSSHAIR: SDL_Log("Crosshair"); break;
case SDL_SYSTEM_CURSOR_WAITARROW: SDL_Log("Small wait cursor (or Wait if not available)"); break;
case SDL_SYSTEM_CURSOR_SIZENWSE: SDL_Log("Double arrow pointing northwest and southeast"); break;
case SDL_SYSTEM_CURSOR_SIZENESW: SDL_Log("Double arrow pointing northeast and southwest"); break;
case SDL_SYSTEM_CURSOR_SIZEWE: SDL_Log("Double arrow pointing west and east"); break;
case SDL_SYSTEM_CURSOR_SIZENS: SDL_Log("Double arrow pointing north and south"); break;
case SDL_SYSTEM_CURSOR_SIZEALL: SDL_Log("Four pointed arrow pointing north, south, east, and west"); break;
case SDL_SYSTEM_CURSOR_NO: SDL_Log("Slashed circle or crossbones"); break;
case SDL_SYSTEM_CURSOR_HAND: SDL_Log("Hand"); break;
default: SDL_Log("UNKNOWN CURSOR TYPE, FIX THIS PROGRAM."); break;
}
} else {
show_cursor = !show_cursor;
SDL_ShowCursor(show_cursor);
@@ -244,38 +219,23 @@ main(int argc, char *argv[])
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++;
}
cursors[0] = init_color_cursor(color_cursor);
} else {
SDL_Cursor *cursor = init_system_cursor(arrow);
if (cursor) {
cursors[num_cursors] = cursor;
cursor_types[num_cursors] = (SDL_SystemCursor)-1;
num_cursors++;
}
cursors[0] = init_system_cursor(arrow);
}
if (!cursors[0]) {
SDL_Log("Error, couldn't create cursor\n");
quit(2);
}
for (i = 0; i < SDL_NUM_SYSTEM_CURSORS; ++i) {
SDL_Cursor *cursor = SDL_CreateSystemCursor((SDL_SystemCursor)i);
if (cursor) {
cursors[num_cursors] = cursor;
cursor_types[num_cursors] = i;
num_cursors++;
cursors[1+i] = SDL_CreateSystemCursor((SDL_SystemCursor)i);
if (!cursors[1+i]) {
SDL_Log("Error, couldn't create system cursor %d\n", i);
quit(2);
}
}
if (num_cursors > 0) {
SDL_SetCursor(cursors[0]);
}
show_cursor = SDL_ShowCursor(SDL_QUERY);
SDL_SetCursor(cursors[0]);
/* Main render loop */
done = 0;
@@ -287,7 +247,7 @@ main(int argc, char *argv[])
}
#endif
for (i = 0; i < num_cursors; ++i) {
for (i = 0; i < SDL_arraysize(cursors); ++i) {
SDL_FreeCursor(cursors[i]);
}
quit(0);

View File

@@ -58,12 +58,6 @@ main(int argc, char *argv[])
/* Set the error value for the main thread */
SDL_SetError("No worries");
if (SDL_getenv("SDL_TESTS_QUICK") != NULL) {
SDL_Log("Not running slower tests");
SDL_Quit();
return 0;
}
alive = 1;
thread = SDL_CreateThread(ThreadFunc, NULL, "#1");
if (thread == NULL) {

View File

@@ -41,7 +41,6 @@ static const struct
CLS(SOUND),
CLS(TOUCHSCREEN),
CLS(ACCELEROMETER),
CLS(TOUCHPAD),
#undef CLS
{ 0, NULL }
};
@@ -186,7 +185,9 @@ static const GuessTest guess_tests[] =
.bus_type = 0x0003,
.vendor_id = 0x054c,
.product_id = 0x09cc,
.expected = SDL_UDEV_DEVICE_TOUCHPAD,
/* TODO: Should this be MOUSE? That's what it most closely
* resembles */
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SYN, KEY, ABS */
.ev = { 0x0b },
/* X, Y, multitouch */
@@ -595,7 +596,7 @@ static const GuessTest guess_tests[] =
* to the arrow, page up and page down keys, so it's a joystick
* with a subset of a keyboard attached. */
/* TODO: Should this be JOYSTICK, or even JOYSTICK|KEYBOARD? */
.expected = SDL_UDEV_DEVICE_KEYBOARD,
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SYN, KEY */
.ev = { 0x03 },
.keys = {
@@ -607,7 +608,7 @@ static const GuessTest guess_tests[] =
/* BTN_1, BTN_2, BTN_A, BTN_B, BTN_MODE */
/* 0x100 */ 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x10,
/* 0x140 */ ZEROx8,
/* next (keyboard page down), previous (keyboard page up) */
/* next, previous */
/* 0x180 */ 0x00, 0x00, 0x80, 0x10, ZEROx4,
},
},
@@ -658,7 +659,7 @@ static const GuessTest guess_tests[] =
.name = "Wiimote - Classic Controller",
/* TODO: Should this be JOYSTICK, or maybe JOYSTICK|KEYBOARD?
* It's unusual in the same ways as the Wiimote */
.expected = SDL_UDEV_DEVICE_KEYBOARD,
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SYN, KEY, ABS */
.ev = { 0x0b },
/* Hat 1-3 */
@@ -672,7 +673,7 @@ static const GuessTest guess_tests[] =
/* A, B, X, Y, MODE, TL, TL2, TR, TR2 */
/* 0x100 */ ZEROx4, 0x00, 0x13, 0xdb, 0x10,
/* 0x140 */ ZEROx8,
/* next (keyboard page down), previous (keyboard page up) */
/* next, previous */
/* 0x180 */ 0x00, 0x00, 0x80, 0x10, ZEROx4,
},
},
@@ -717,7 +718,9 @@ static const GuessTest guess_tests[] =
.vendor_id = 0x06cb,
.product_id = 0x0000,
.version = 0x0000,
.expected = SDL_UDEV_DEVICE_TOUCHPAD,
/* TODO: Should this be MOUSE? That's what it most closely
* resembles */
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SYN, KEY, ABS */
.ev = { 0x0b },
/* X, Y, pressure, multitouch */
@@ -753,8 +756,7 @@ static const GuessTest guess_tests[] =
},
{
.name = "Thinkpad ACPI buttons",
/* SDL treats this as a keyboard because it has a power button */
.expected = SDL_UDEV_DEVICE_KEYBOARD,
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SYN, KEY, MSC, SW */
.ev = { 0x33 },
.keys = {
@@ -813,8 +815,7 @@ static const GuessTest guess_tests[] =
.vendor_id = 0x0000,
.product_id = 0x0003,
.version = 0x0000,
/* SDL treats KEY_SLEEP as indicating a keyboard */
.expected = SDL_UDEV_DEVICE_KEYBOARD,
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SYN, KEY */
.ev = { 0x03 },
.keys = {
@@ -840,8 +841,7 @@ static const GuessTest guess_tests[] =
.vendor_id = 0x0000,
.product_id = 0x0001,
.version = 0x0000,
/* SDL treats KEY_POWER as indicating a keyboard */
.expected = SDL_UDEV_DEVICE_KEYBOARD,
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SYN, KEY */
.ev = { 0x03 },
.keys = {
@@ -856,8 +856,7 @@ static const GuessTest guess_tests[] =
.vendor_id = 0x0000,
.product_id = 0x0006,
.version = 0x0000,
/* SDL treats brightness control, etc. as keyboard keys */
.expected = SDL_UDEV_DEVICE_KEYBOARD,
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SYN, KEY */
.ev = { 0x03 },
.keys = {
@@ -874,7 +873,7 @@ static const GuessTest guess_tests[] =
.vendor_id = 0x17aa,
.product_id = 0x5054,
.version = 0x4101,
.expected = SDL_UDEV_DEVICE_KEYBOARD,
.expected = SDL_UDEV_DEVICE_UNKNOWN,
/* SYN, KEY */
.ev = { 0x03 },
.keys = {
@@ -912,8 +911,9 @@ static const GuessTest guess_tests[] =
.product_id = 0x6009,
/* For some reason the special keys like mute and wlan toggle
* show up here instead of, or in addition to, as part of
* the keyboard - so both udev and SDL report this as having keys too. */
.expected = SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD,
* the keyboard - so udev reports this as having keys too.
* SDL currently doesn't. */
.expected = SDL_UDEV_DEVICE_MOUSE,
/* SYN, KEY, REL, MSC, LED */
.ev = { 0x17, 0x00, 0x02 },
/* X, Y */
@@ -1019,7 +1019,7 @@ static int
run_test(void)
{
printf("SDL compiled without evdev capability check.\n");
return 1;
return 0;
}
#endif

View File

@@ -17,7 +17,6 @@
#include <string.h>
#include "SDL.h"
#include "testutils.h"
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
@@ -28,10 +27,6 @@
#define SCREEN_WIDTH 512
#define SCREEN_HEIGHT 320
#define BUTTON_SIZE 50
#define AXIS_SIZE 50
/* This is indexed by SDL_GameControllerButton. */
static const struct { int x; int y; } button_positions[] = {
{387, 167}, /* SDL_CONTROLLER_BUTTON_A */
@@ -54,9 +49,7 @@ static const struct { int x; int y; } button_positions[] = {
{330, 135}, /* SDL_CONTROLLER_BUTTON_PADDLE2 */
{132, 175}, /* SDL_CONTROLLER_BUTTON_PADDLE3 */
{330, 175}, /* SDL_CONTROLLER_BUTTON_PADDLE4 */
{0, 0}, /* SDL_CONTROLLER_BUTTON_TOUCHPAD */
};
SDL_COMPILE_TIME_ASSERT(button_positions, SDL_arraysize(button_positions) == SDL_CONTROLLER_BUTTON_MAX);
/* This is indexed by SDL_GameControllerAxis. */
static const struct { int x; int y; double angle; } axis_positions[] = {
@@ -67,7 +60,6 @@ static const struct { int x; int y; double angle; } axis_positions[] = {
{91, -20, 0.0}, /* TRIGGERLEFT */
{375, -20, 0.0}, /* TRIGGERRIGHT */
};
SDL_COMPILE_TIME_ASSERT(axis_positions, SDL_arraysize(axis_positions) == SDL_CONTROLLER_AXIS_MAX);
static SDL_Window *window = NULL;
static SDL_Renderer *screen = NULL;
@@ -79,11 +71,6 @@ static SDL_Texture *background_front, *background_back, *button, *axis;
static SDL_GameController *gamecontroller;
static SDL_GameController **gamecontrollers;
static int num_controllers = 0;
static SDL_Joystick *virtual_joystick = NULL;
static SDL_GameControllerAxis virtual_axis_active = SDL_CONTROLLER_AXIS_INVALID;
static int virtual_axis_start_x;
static int virtual_axis_start_y;
static SDL_GameControllerButton virtual_button_active = SDL_CONTROLLER_BUTTON_INVALID;
static void UpdateWindowTitle()
{
@@ -133,7 +120,6 @@ static void AddController(int device_index, SDL_bool verbose)
SDL_JoystickID controller_id = SDL_JoystickGetDeviceInstanceID(device_index);
SDL_GameController *controller;
SDL_GameController **controllers;
Uint16 firmware_version;
controller_id = SDL_JoystickGetDeviceInstanceID(device_index);
if (controller_id < 0) {
@@ -165,15 +151,7 @@ static void AddController(int device_index, SDL_bool verbose)
if (verbose) {
const char *name = SDL_GameControllerName(gamecontroller);
const char *path = SDL_GameControllerPath(gamecontroller);
SDL_Log("Opened game controller %s%s%s\n", name, path ? ", " : "", path ? path : "");
}
firmware_version = SDL_GameControllerGetFirmwareVersion(gamecontroller);
if (firmware_version) {
if (verbose) {
SDL_Log("Firmware version: 0x%x (%d)\n", firmware_version, firmware_version);
}
SDL_Log("Opened game controller %s\n", name);
}
if (SDL_GameControllerHasSensor(gamecontroller, SDL_SENSOR_ACCEL)) {
@@ -238,6 +216,34 @@ static void DelController(SDL_JoystickID controller)
UpdateWindowTitle();
}
static SDL_Texture *
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
{
SDL_Surface *temp = NULL;
SDL_Texture *texture = NULL;
temp = SDL_LoadBMP(file);
if (temp == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
} else {
/* Set transparent pixel as the pixel at (0,0) */
if (transparent) {
if (temp->format->BytesPerPixel == 1) {
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *)temp->pixels);
}
}
texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!texture) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
}
}
if (temp) {
SDL_FreeSurface(temp);
}
return texture;
}
static Uint16 ConvertAxisToRumble(Sint16 axisval)
{
/* Only start rumbling if the axis is past the halfway point */
@@ -300,223 +306,12 @@ static void CyclePS5TriggerEffect()
SDL_GameControllerSendEffect(gamecontroller, &state, sizeof(state));
}
static SDL_bool ShowingFront()
{
SDL_bool showing_front = SDL_TRUE;
int i;
if (gamecontroller) {
/* Show the back of the controller if the paddles are being held */
for (i = SDL_CONTROLLER_BUTTON_PADDLE1; i <= SDL_CONTROLLER_BUTTON_PADDLE4; ++i) {
if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
showing_front = SDL_FALSE;
break;
}
}
}
if ((SDL_GetModState() & KMOD_SHIFT) != 0) {
showing_front = SDL_FALSE;
}
return showing_front;
}
static void SDLCALL VirtualControllerSetPlayerIndex(void *userdata, int player_index)
{
SDL_Log("Virtual Controller: player index set to %d\n", player_index);
}
static int SDLCALL VirtualControllerRumble(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
SDL_Log("Virtual Controller: rumble set to %d/%d\n", low_frequency_rumble, high_frequency_rumble);
return 0;
}
static int SDLCALL VirtualControllerRumbleTriggers(void *userdata, Uint16 left_rumble, Uint16 right_rumble)
{
SDL_Log("Virtual Controller: trigger rumble set to %d/%d\n", left_rumble, right_rumble);
return 0;
}
static int SDLCALL VirtualControllerSetLED(void *userdata, Uint8 red, Uint8 green, Uint8 blue)
{
SDL_Log("Virtual Controller: LED set to RGB %d,%d,%d\n", red, green, blue);
return 0;
}
static void OpenVirtualController()
{
SDL_VirtualJoystickDesc desc;
int virtual_index;
SDL_zero(desc);
desc.version = SDL_VIRTUAL_JOYSTICK_DESC_VERSION;
desc.type = SDL_JOYSTICK_TYPE_GAMECONTROLLER;
desc.naxes = SDL_CONTROLLER_AXIS_MAX;
desc.nbuttons = SDL_CONTROLLER_BUTTON_MAX;
desc.SetPlayerIndex = VirtualControllerSetPlayerIndex;
desc.Rumble = VirtualControllerRumble;
desc.RumbleTriggers = VirtualControllerRumbleTriggers;
desc.SetLED = VirtualControllerSetLED;
virtual_index = SDL_JoystickAttachVirtualEx(&desc);
if (virtual_index < 0) {
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
} else {
virtual_joystick = SDL_JoystickOpen(virtual_index);
if (!virtual_joystick) {
SDL_Log("Couldn't open virtual device: %s\n", SDL_GetError());
}
}
}
static void CloseVirtualController()
{
int i;
for (i = SDL_NumJoysticks(); i--; ) {
if (SDL_JoystickIsVirtual(i)) {
SDL_JoystickDetachVirtual(i);
}
}
if (virtual_joystick) {
SDL_JoystickClose(virtual_joystick);
virtual_joystick = NULL;
}
}
static SDL_GameControllerButton FindButtonAtPosition(int x, int y)
{
SDL_Point point;
int i;
SDL_bool showing_front = ShowingFront();
point.x = x;
point.y = y;
for (i = 0; i < SDL_CONTROLLER_BUTTON_TOUCHPAD; ++i) {
SDL_bool on_front = (i < SDL_CONTROLLER_BUTTON_PADDLE1 || i > SDL_CONTROLLER_BUTTON_PADDLE4);
if (on_front == showing_front) {
SDL_Rect rect;
rect.x = button_positions[i].x;
rect.y = button_positions[i].y;
rect.w = BUTTON_SIZE;
rect.h = BUTTON_SIZE;
if (SDL_PointInRect(&point, &rect)) {
return (SDL_GameControllerButton)i;
}
}
}
return SDL_CONTROLLER_BUTTON_INVALID;
}
static SDL_GameControllerAxis FindAxisAtPosition(int x, int y)
{
SDL_Point point;
int i;
SDL_bool showing_front = ShowingFront();
point.x = x;
point.y = y;
for (i = 0; i < SDL_CONTROLLER_AXIS_MAX; ++i) {
if (showing_front) {
SDL_Rect rect;
rect.x = axis_positions[i].x;
rect.y = axis_positions[i].y;
rect.w = AXIS_SIZE;
rect.h = AXIS_SIZE;
if (SDL_PointInRect(&point, &rect)) {
return (SDL_GameControllerAxis)i;
}
}
}
return SDL_CONTROLLER_AXIS_INVALID;
}
static void VirtualControllerMouseMotion(int x, int y)
{
if (virtual_button_active != SDL_CONTROLLER_BUTTON_INVALID) {
if (virtual_axis_active != SDL_CONTROLLER_AXIS_INVALID) {
const int MOVING_DISTANCE = 2;
if (SDL_abs(x - virtual_axis_start_x) >= MOVING_DISTANCE ||
SDL_abs(y - virtual_axis_start_y) >= MOVING_DISTANCE) {
SDL_JoystickSetVirtualButton(virtual_joystick, virtual_button_active, SDL_RELEASED);
virtual_button_active = SDL_CONTROLLER_BUTTON_INVALID;
}
}
}
if (virtual_axis_active != SDL_CONTROLLER_AXIS_INVALID) {
if (virtual_axis_active == SDL_CONTROLLER_AXIS_TRIGGERLEFT ||
virtual_axis_active == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) {
int range = (SDL_JOYSTICK_AXIS_MAX - SDL_JOYSTICK_AXIS_MIN);
float distance = SDL_clamp(((float)y - virtual_axis_start_y) / AXIS_SIZE, 0.0f, 1.0f);
Sint16 value = (Sint16)(SDL_JOYSTICK_AXIS_MIN + (distance * range));
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, value);
} else {
float distanceX = SDL_clamp(((float)x - virtual_axis_start_x) / AXIS_SIZE, -1.0f, 1.0f);
float distanceY = SDL_clamp(((float)y - virtual_axis_start_y) / AXIS_SIZE, -1.0f, 1.0f);
Sint16 valueX, valueY;
if (distanceX >= 0) {
valueX = (Sint16)(distanceX * SDL_JOYSTICK_AXIS_MAX);
} else {
valueX = (Sint16)(distanceX * -SDL_JOYSTICK_AXIS_MIN);
}
if (distanceY >= 0) {
valueY = (Sint16)(distanceY * SDL_JOYSTICK_AXIS_MAX);
} else {
valueY = (Sint16)(distanceY * -SDL_JOYSTICK_AXIS_MIN);
}
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, valueX);
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active+1, valueY);
}
}
}
static void VirtualControllerMouseDown(int x, int y)
{
SDL_GameControllerButton button;
SDL_GameControllerAxis axis;
button = FindButtonAtPosition(x, y);
if (button != SDL_CONTROLLER_BUTTON_INVALID) {
virtual_button_active = button;
SDL_JoystickSetVirtualButton(virtual_joystick, virtual_button_active, SDL_PRESSED);
}
axis = FindAxisAtPosition(x, y);
if (axis != SDL_CONTROLLER_AXIS_INVALID) {
virtual_axis_active = axis;
virtual_axis_start_x = x;
virtual_axis_start_y = y;
}
}
static void VirtualControllerMouseUp(int x, int y)
{
if (virtual_button_active != SDL_CONTROLLER_BUTTON_INVALID) {
SDL_JoystickSetVirtualButton(virtual_joystick, virtual_button_active, SDL_RELEASED);
virtual_button_active = SDL_CONTROLLER_BUTTON_INVALID;
}
if (virtual_axis_active != SDL_CONTROLLER_AXIS_INVALID) {
if (virtual_axis_active == SDL_CONTROLLER_AXIS_TRIGGERLEFT ||
virtual_axis_active == SDL_CONTROLLER_AXIS_TRIGGERRIGHT) {
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, SDL_JOYSTICK_AXIS_MIN);
} else {
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active, 0);
SDL_JoystickSetVirtualAxis(virtual_joystick, virtual_axis_active+1, 0);
}
virtual_axis_active = SDL_CONTROLLER_AXIS_INVALID;
}
}
void
loop(void *arg)
{
SDL_Event event;
int i;
SDL_bool showing_front;
SDL_bool showing_front = SDL_TRUE;
/* Update to get the current event state */
SDL_PumpEvents();
@@ -587,24 +382,6 @@ loop(void *arg)
}
break;
case SDL_MOUSEBUTTONDOWN:
if (virtual_joystick) {
VirtualControllerMouseDown(event.button.x, event.button.y);
}
break;
case SDL_MOUSEBUTTONUP:
if (virtual_joystick) {
VirtualControllerMouseUp(event.button.x, event.button.y);
}
break;
case SDL_MOUSEMOTION:
if (virtual_joystick) {
VirtualControllerMouseMotion(event.motion.x, event.motion.y);
}
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym >= SDLK_0 && event.key.keysym.sym <= SDLK_9) {
if (gamecontroller) {
@@ -614,14 +391,6 @@ loop(void *arg)
}
break;
}
if (event.key.keysym.sym == SDLK_a) {
OpenVirtualController();
break;
}
if (event.key.keysym.sym == SDLK_d) {
CloseVirtualController();
break;
}
if (event.key.keysym.sym != SDLK_ESCAPE) {
break;
}
@@ -634,7 +403,15 @@ loop(void *arg)
}
}
showing_front = ShowingFront();
if (gamecontroller) {
/* Show the back of the controller if the paddles are being held */
for (i = SDL_CONTROLLER_BUTTON_PADDLE1; i <= SDL_CONTROLLER_BUTTON_PADDLE4; ++i) {
if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
showing_front = SDL_FALSE;
break;
}
}
}
/* blank screen, set up for drawing this frame. */
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
@@ -650,8 +427,8 @@ loop(void *arg)
SDL_Rect dst;
dst.x = button_positions[i].x;
dst.y = button_positions[i].y;
dst.w = BUTTON_SIZE;
dst.h = BUTTON_SIZE;
dst.w = 50;
dst.h = 50;
SDL_RenderCopyEx(screen, button, NULL, &dst, 0, NULL, SDL_FLIP_NONE);
}
}
@@ -666,16 +443,16 @@ loop(void *arg)
SDL_Rect dst;
dst.x = axis_positions[i].x;
dst.y = axis_positions[i].y;
dst.w = AXIS_SIZE;
dst.h = AXIS_SIZE;
dst.w = 50;
dst.h = 50;
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
} else if (value > deadzone) {
const double angle = axis_positions[i].angle + 180.0;
SDL_Rect dst;
dst.x = axis_positions[i].x;
dst.y = axis_positions[i].y;
dst.w = AXIS_SIZE;
dst.h = AXIS_SIZE;
dst.w = 50;
dst.h = 50;
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
}
}
@@ -730,7 +507,7 @@ loop(void *arg)
}
}
}
SDL_Delay(16);
SDL_RenderPresent(screen);
#ifdef __EMSCRIPTEN__
@@ -752,7 +529,6 @@ main(int argc, char *argv[])
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1");
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
SDL_SetHint(SDL_HINT_JOYSTICK_ROG_CHAKRAM, "1");
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
SDL_SetHint(SDL_HINT_LINUX_JOYSTICK_DEADZONES, "1");
@@ -783,7 +559,6 @@ main(int argc, char *argv[])
/* Print information about the controller */
for (i = 0; i < SDL_NumJoysticks(); ++i) {
const char *name;
const char *path;
const char *description;
SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(i),
@@ -792,7 +567,6 @@ main(int argc, char *argv[])
if (SDL_IsGameController(i)) {
controller_count++;
name = SDL_GameControllerNameForIndex(i);
path = SDL_GameControllerPathForIndex(i);
switch (SDL_GameControllerTypeForIndex(i)) {
case SDL_CONTROLLER_TYPE_AMAZON_LUNA:
description = "Amazon Luna Controller";
@@ -828,11 +602,10 @@ main(int argc, char *argv[])
AddController(i, SDL_FALSE);
} else {
name = SDL_JoystickNameForIndex(i);
path = SDL_JoystickPathForIndex(i);
description = "Joystick";
}
SDL_Log("%s %d: %s%s%s (guid %s, VID 0x%.4x, PID 0x%.4x, player index = %d)\n",
description, i, name ? name : "Unknown", path ? ", " : "", path ? path : "", guid,
SDL_Log("%s %d: %s (guid %s, VID 0x%.4x, PID 0x%.4x, player index = %d)\n",
description, i, name ? name : "Unknown", guid,
SDL_JoystickGetDeviceVendor(i), SDL_JoystickGetDeviceProduct(i), SDL_JoystickGetDevicePlayerIndex(i));
}
SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", controller_count, SDL_NumJoysticks());
@@ -860,10 +633,10 @@ main(int argc, char *argv[])
/* scale for platforms that don't give you the window size you asked for. */
SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);
background_front = LoadTexture(screen, "controllermap.bmp", SDL_FALSE, NULL, NULL);
background_back = LoadTexture(screen, "controllermap_back.bmp", SDL_FALSE, NULL, NULL);
button = LoadTexture(screen, "button.bmp", SDL_TRUE, NULL, NULL);
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE, NULL, NULL);
background_front = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
background_back = LoadTexture(screen, "controllermap_back.bmp", SDL_FALSE);
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
if (!background_front || !background_back || !button || !axis) {
SDL_DestroyRenderer(screen);
@@ -876,14 +649,8 @@ main(int argc, char *argv[])
/* !!! FIXME: */
/*SDL_RenderSetLogicalSize(screen, background->w, background->h);*/
for (i = 1; i < argc; ++i) {
if (SDL_strcmp(argv[i], "--virtual") == 0) {
OpenVirtualController();
}
if (argv[i] && *argv[i] != '-') {
controller_index = SDL_atoi(argv[i]);
break;
}
if (argv[1] && *argv[1] != '-') {
controller_index = SDL_atoi(argv[1]);
}
if (controller_index < num_controllers) {
gamecontroller = gamecontrollers[controller_index];
@@ -907,7 +674,6 @@ main(int argc, char *argv[])
CyclePS5TriggerEffect();
}
CloseVirtualController();
SDL_DestroyRenderer(screen);
SDL_DestroyWindow(window);
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);

View File

@@ -21,7 +21,6 @@
#endif
#include "SDL_test_common.h"
#include "testutils.h"
static SDLTest_CommonState *state;
static SDL_bool use_texture = SDL_FALSE;
@@ -45,19 +44,54 @@ int
LoadSprite(const char *file)
{
int i;
SDL_Surface *temp;
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return (-1);
}
sprite_w = temp->w;
sprite_h = temp->h;
/* Set transparent pixel as the pixel at (0,0) */
if (temp->format->palette) {
SDL_SetColorKey(temp, 1, *(Uint8 *) temp->pixels);
} else {
switch (temp->format->BitsPerPixel) {
case 15:
SDL_SetColorKey(temp, 1, (*(Uint16 *) temp->pixels) & 0x00007FFF);
break;
case 16:
SDL_SetColorKey(temp, 1, *(Uint16 *) temp->pixels);
break;
case 24:
SDL_SetColorKey(temp, 1, (*(Uint32 *) temp->pixels) & 0x00FFFFFF);
break;
case 32:
SDL_SetColorKey(temp, 1, *(Uint32 *) temp->pixels);
break;
}
}
/* Create textures from the image */
for (i = 0; i < state->num_windows; ++i) {
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h);
SDL_Renderer *renderer = state->renderers[i];
sprites[i] = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprites[i]) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return (-1);
}
if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
SDL_DestroyTexture(sprites[i]);
return (-1);
}
}
SDL_FreeSurface(temp);
/* We're ready to roll. :) */
return (0);

View File

@@ -190,8 +190,7 @@ loop(void)
case SDLK_i: {
for (i = 0; i < SDL_GetNumTouchDevices(); ++i) {
const SDL_TouchID id = SDL_GetTouchDevice(i);
const char *name = SDL_GetTouchName(i);
SDL_Log("Fingers Down on device %"SDL_PRIs64" (%s): %d", id, name, SDL_GetNumTouchFingers(id));
SDL_Log("Fingers Down on device %"SDL_PRIs64": %d", id, SDL_GetNumTouchFingers(id));
}
break;
}

View File

@@ -38,18 +38,6 @@ typedef struct GLES2_Context
#undef SDL_PROC
} GLES2_Context;
typedef struct shader_data
{
GLuint shader_program, shader_frag, shader_vert;
GLint attr_position;
GLint attr_color, attr_mvp;
int angle_x, angle_y, angle_z;
GLuint position_buffer;
GLuint color_buffer;
} shader_data;
static SDLTest_CommonState *state;
static SDL_GLContext *context = NULL;
@@ -209,13 +197,13 @@ multiply_matrix(float *lhs, float *rhs, float *r)
* source: Passed-in shader source code.
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
*/
static void
void
process_shader(GLuint *shader, const char * source, GLint shader_type)
{
GLint status = GL_FALSE;
const char *shaders[1] = { NULL };
char buffer[1024];
GLsizei length = 0;
GLsizei length;
/* Create shader and load into GL. */
*shader = GL_CHECK(ctx.glCreateShader(shader_type));
@@ -233,35 +221,13 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
/* Dump debug info (source and log) if compilation failed. */
if(status != GL_TRUE) {
ctx.glGetShaderInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
ctx.glGetProgramInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
buffer[length] = '\0';
SDL_Log("Shader compilation failed: %s", buffer);
fflush(stderr);
SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr);
quit(-1);
}
}
static void
link_program(struct shader_data *data)
{
GLint status = GL_FALSE;
char buffer[1024];
GLsizei length = 0;
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_vert));
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_frag));
GL_CHECK(ctx.glLinkProgram(data->shader_program));
GL_CHECK(ctx.glGetProgramiv(data->shader_program, GL_LINK_STATUS, &status));
if(status != GL_TRUE) {
ctx.glGetProgramInfoLog(data->shader_program, sizeof(buffer), &length, &buffer[0]);
buffer[length] = '\0';
SDL_Log("Program linking failed: %s", buffer);
fflush(stderr);
quit(-1);
}
}
/* 3D data. Vertex range -0.5..0.5 in all axes.
* Z -0.5 is near, 0.5 is far. */
const float _vertices[] =
@@ -397,6 +363,17 @@ const char* _shader_frag_src =
" gl_FragColor = vec4(vv3color, 1.0); "
" } ";
typedef struct shader_data
{
GLuint shader_program, shader_frag, shader_vert;
GLint attr_position;
GLint attr_color, attr_mvp;
int angle_x, angle_y, angle_z;
} shader_data;
static void
Render(unsigned int width, unsigned int height, shader_data* data)
{
@@ -454,7 +431,7 @@ void loop()
switch (event.type) {
case SDL_WINDOWEVENT:
switch (event.window.event) {
case SDL_WINDOWEVENT_SIZE_CHANGED:
case SDL_WINDOWEVENT_RESIZED:
for (i = 0; i < state->num_windows; ++i) {
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
int w, h;
@@ -693,7 +670,9 @@ main(int argc, char *argv[])
data->shader_program = GL_CHECK(ctx.glCreateProgram());
/* Attach shaders and link shader_program */
link_program(data);
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_vert));
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_frag));
GL_CHECK(ctx.glLinkProgram(data->shader_program));
/* Get attribute locations of non-fixed attributes like color and texture coordinates. */
data->attr_position = GL_CHECK(ctx.glGetAttribLocation(data->shader_program, "av4position"));
@@ -709,18 +688,8 @@ main(int argc, char *argv[])
GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_color));
/* Populate attributes for position, color and texture coordinates etc. */
GL_CHECK(ctx.glGenBuffers(1, &data->position_buffer));
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, data->position_buffer));
GL_CHECK(ctx.glBufferData(GL_ARRAY_BUFFER, sizeof(_vertices), _vertices, GL_STATIC_DRAW));
GL_CHECK(ctx.glVertexAttribPointer(data->attr_position, 3, GL_FLOAT, GL_FALSE, 0, 0));
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, 0));
GL_CHECK(ctx.glGenBuffers(1, &data->color_buffer));
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, data->color_buffer));
GL_CHECK(ctx.glBufferData(GL_ARRAY_BUFFER, sizeof(_colors), _colors, GL_STATIC_DRAW));
GL_CHECK(ctx.glVertexAttribPointer(data->attr_color, 3, GL_FLOAT, GL_FALSE, 0, 0));
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, 0));
GL_CHECK(ctx.glVertexAttribPointer(data->attr_position, 3, GL_FLOAT, GL_FALSE, 0, _vertices));
GL_CHECK(ctx.glVertexAttribPointer(data->attr_color, 3, GL_FLOAT, GL_FALSE, 0, _colors));
GL_CHECK(ctx.glEnable(GL_CULL_FACE));
GL_CHECK(ctx.glEnable(GL_DEPTH_TEST));

View File

@@ -458,7 +458,6 @@ main(int argc, char *argv[])
Uint32 then, now;
int status;
shader_data *data;
char *path = NULL;
/* Initialize parameters */
fsaa = 0;
@@ -562,25 +561,14 @@ main(int argc, char *argv[])
/* Load SDF BMP image */
#if 1
path = GetNearbyFilename(f);
if (path == NULL)
path = SDL_strdup(f);
if (path == NULL) {
SDL_Log("out of memory\n");
exit(-1);
}
tmp = SDL_LoadBMP(path);
tmp = SDL_LoadBMP(f);
if (tmp == NULL) {
SDL_Log("missing image file: %s", path);
SDL_Log("missing image file: %s", f);
exit(-1);
} else {
SDL_Log("Load image file: %s", path);
SDL_Log("Load image file: %s", f);
}
SDL_free(path);
#else
/* Generate SDF image using SDL_ttf */

View File

@@ -13,7 +13,6 @@
#include <stdio.h>
#include "SDL.h"
#include "testutils.h"
static size_t
widelen(char *data)
@@ -44,7 +43,7 @@ main(int argc, char *argv[])
"UCS-4",
};
char * fname;
const char * fname;
char buffer[BUFSIZ];
char *ucs4;
char *test[2];
@@ -55,13 +54,12 @@ main(int argc, char *argv[])
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
fname = GetResourceFilename(argc > 1 ? argv[1] : NULL, "utf8.txt");
fname = (argc < 2) ? "utf8.txt" : argv[1];
file = fopen(fname, "rb");
if (!file) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", fname);
return (1);
}
SDL_free(fname);
while (fgets(buffer, sizeof(buffer), file)) {
/* Convert to UCS-4 */

View File

@@ -23,7 +23,6 @@
#endif
#include "SDL_test_common.h"
#include "testutils.h"
#define DEFAULT_PTSIZE 30
#ifdef HAVE_SDL_TTF
@@ -109,7 +108,6 @@ static int unifont_init(const char *fontname)
SDL_RWops *hexFile;
const size_t unifontGlyphSize = UNIFONT_NUM_GLYPHS * sizeof(struct UnifontGlyph);
const size_t unifontTextureSize = UNIFONT_NUM_TEXTURES * state->num_windows * sizeof(void *);
char *filename;
/* Allocate memory for the glyph data so the file can be closed after initialization. */
unifontGlyph = (struct UnifontGlyph *)SDL_malloc(unifontGlyphSize);
@@ -129,13 +127,7 @@ static int unifont_init(const char *fontname)
}
SDL_memset(unifontTexture, 0, unifontTextureSize);
filename = GetResourceFilename(NULL, fontname);
if (filename == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory\n");
return -1;
}
hexFile = SDL_RWFromFile(filename, "rb");
SDL_free(filename);
hexFile = SDL_RWFromFile(fontname, "rb");
if (hexFile == NULL)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "unifont: Failed to open font file: %s\n", fontname);

View File

@@ -39,11 +39,6 @@ static Line *active = NULL;
static Line *lines = NULL;
static int buttons = 0;
static SDL_bool wheel_x_active = SDL_FALSE;
static SDL_bool wheel_y_active = SDL_FALSE;
static float wheel_x = SCREEN_WIDTH * 0.5f;
static float wheel_y = SCREEN_HEIGHT * 0.5f;
static SDL_bool done = SDL_FALSE;
void
@@ -86,25 +81,6 @@ loop(void *arg)
/* Check for events */
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_MOUSEWHEEL:
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
event.wheel.preciseX *= -1.0f;
event.wheel.preciseY *= -1.0f;
event.wheel.x *= -1;
event.wheel.y *= -1;
}
if (event.wheel.preciseX != 0.0f) {
wheel_x_active = SDL_TRUE;
/* "positive to the right and negative to the left" */
wheel_x += event.wheel.preciseX * 10.0f;
}
if (event.wheel.preciseY != 0.0f) {
wheel_y_active = SDL_TRUE;
/* "positive away from the user and negative towards the user" */
wheel_y -= event.wheel.preciseY * 10.0f;
}
break;
case SDL_MOUSEMOTION:
if (!active)
break;
@@ -124,8 +100,6 @@ loop(void *arg)
case SDL_BUTTON_LEFT: active->r = 255; buttons |= SDL_BUTTON_LMASK; break;
case SDL_BUTTON_MIDDLE: active->g = 255; buttons |= SDL_BUTTON_MMASK; break;
case SDL_BUTTON_RIGHT: active->b = 255; buttons |= SDL_BUTTON_RMASK; break;
case SDL_BUTTON_X1: active->r = 255; active->b = 255; buttons |= SDL_BUTTON_X1MASK; break;
case SDL_BUTTON_X2: active->g = 255; active->b = 255; buttons |= SDL_BUTTON_X2MASK; break;
}
break;
case SDL_MOUSEBUTTONUP:
@@ -136,8 +110,6 @@ loop(void *arg)
case SDL_BUTTON_LEFT: buttons &= ~SDL_BUTTON_LMASK; break;
case SDL_BUTTON_MIDDLE: buttons &= ~SDL_BUTTON_MMASK; break;
case SDL_BUTTON_RIGHT: buttons &= ~SDL_BUTTON_RMASK; break;
case SDL_BUTTON_X1: buttons &= ~SDL_BUTTON_X1MASK; break;
case SDL_BUTTON_X2: buttons &= ~SDL_BUTTON_X2MASK; break;
}
if (buttons == 0) {
@@ -158,16 +130,6 @@ loop(void *arg)
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
SDL_RenderClear(renderer);
/* Mouse wheel */
SDL_SetRenderDrawColor(renderer, 0, 255, 128, 255);
if (wheel_x_active) {
SDL_RenderDrawLine(renderer, wheel_x, 0, wheel_x, SCREEN_HEIGHT);
}
if (wheel_y_active) {
SDL_RenderDrawLine(renderer, 0, wheel_y, SCREEN_WIDTH, wheel_y);
}
/* Lines from mouse clicks */
DrawLines(renderer);
if (active)
DrawLine(renderer, active);

View File

@@ -17,8 +17,6 @@
#include <emscripten/emscripten.h>
#endif
#include "testutils.h"
static SDL_AudioSpec spec;
static Uint8 *sound = NULL; /* Pointer to wave data */
static Uint32 soundlen = 0; /* Length of wave data */
@@ -182,7 +180,7 @@ main(int argc, char **argv)
if (devcount < 1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!\n");
} else {
char *file = GetResourceFilename(argc > 1 ? argv[1] : NULL, "sample.wav");
const char *file = (argc < 2) ? "sample.wav" : argv[1];
/* Load the wave file into memory */
if (SDL_LoadWAV(file, &spec, &sound, &soundlen) == NULL) {
@@ -192,8 +190,6 @@ main(int argc, char **argv)
test_multi_audio(devcount);
SDL_FreeWAV(sound);
}
SDL_free(file);
}
SDL_Quit();

View File

@@ -16,7 +16,6 @@
#include <time.h> /* for time() */
#include "testnative.h"
#include "testutils.h"
#define WINDOW_W 640
#define WINDOW_H 480
@@ -53,6 +52,37 @@ quit(int rc)
exit(rc);
}
SDL_Texture *
LoadSprite(SDL_Renderer *renderer, const char *file)
{
SDL_Surface *temp;
SDL_Texture *sprite;
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return 0;
}
/* Set transparent pixel as the pixel at (0,0) */
if (temp->format->palette) {
SDL_SetColorKey(temp, 1, *(Uint8 *) temp->pixels);
}
/* Create textures from the image */
sprite = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprite) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return 0;
}
SDL_FreeSurface(temp);
/* We're ready to roll. :) */
return sprite;
}
void
MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
{
@@ -150,7 +180,7 @@ main(int argc, char *argv[])
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
sprite = LoadTexture(renderer, "icon.bmp", SDL_TRUE, NULL, NULL);
sprite = LoadSprite(renderer, "icon.bmp");
if (!sprite) {
quit(6);
}

View File

@@ -25,7 +25,6 @@
#include "SDL.h"
#include "testyuv_cvt.h"
#include "testutils.h"
#define MOOSEPIC_W 64
#define MOOSEPIC_H 88
@@ -244,7 +243,6 @@ main(int argc, char **argv)
int fps = 12;
int nodelay = 0;
int scale = 5;
char *filename = NULL;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -317,13 +315,7 @@ main(int argc, char **argv)
}
/* load the trojan moose images */
filename = GetResourceFilename(NULL, "moose.dat");
if (filename == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory\n");
return -1;
}
handle = SDL_RWFromFile(filename, "rb");
SDL_free(filename);
handle = SDL_RWFromFile("moose.dat", "rb");
if (handle == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
SDL_free(RawMooseData);

View File

@@ -25,31 +25,31 @@ badsize(size_t sizeoftype, size_t hardcodetype)
return sizeoftype != hardcodetype;
}
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT8, SDL_MAX_SINT8 == 127);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT8, SDL_MIN_SINT8 == -128);
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT8, SDL_MAX_UINT8 == 255);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT8, SDL_MIN_UINT8 == 0);
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT16, SDL_MAX_SINT16 == 32767);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT16, SDL_MIN_SINT16 == -32768);
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT16, SDL_MAX_UINT16 == 65535);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT16, SDL_MIN_UINT16 == 0);
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT32, SDL_MAX_SINT32 == 2147483647);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT32, SDL_MIN_SINT32 == ~0x7fffffff); /* Instead of -2147483648, which is treated as unsigned by some compilers */
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT32, SDL_MAX_UINT32 == 4294967295u);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT32, SDL_MIN_UINT32 == 0);
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT64, SDL_MAX_SINT64 == 9223372036854775807ll);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT64, SDL_MIN_SINT64 == ~0x7fffffffffffffffll); /* Instead of -9223372036854775808, which is treated as unsigned by compilers */
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT64, SDL_MAX_UINT64 == 18446744073709551615ull);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT64, SDL_MIN_UINT64 == 0);
int
TestTypes(SDL_bool verbose)
{
int error = 0;
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT8, SDL_MAX_SINT8 == 127);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT8, SDL_MIN_SINT8 == -128);
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT8, SDL_MAX_UINT8 == 255);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT8, SDL_MIN_UINT8 == 0);
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT16, SDL_MAX_SINT16 == 32767);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT16, SDL_MIN_SINT16 == -32768);
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT16, SDL_MAX_UINT16 == 65535);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT16, SDL_MIN_UINT16 == 0);
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT32, SDL_MAX_SINT32 == 2147483647);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT32, SDL_MIN_SINT32 == ~0x7fffffff); /* Instead of -2147483648, which is treated as unsigned by some compilers */
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT32, SDL_MAX_UINT32 == 4294967295u);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT32, SDL_MIN_UINT32 == 0);
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT64, SDL_MAX_SINT64 == 9223372036854775807ll);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT64, SDL_MIN_SINT64 == ~0x7fffffffffffffffll); /* Instead of -9223372036854775808, which is treated as unsigned by compilers */
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT64, SDL_MAX_UINT64 == 18446744073709551615ull);
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT64, SDL_MIN_UINT64 == 0);
if (badsize(sizeof(Uint8), 1)) {
if (verbose)
SDL_Log("sizeof(Uint8) != 1, instead = %u\n",
@@ -86,25 +86,18 @@ TestEndian(SDL_bool verbose)
int error = 0;
Uint16 value = 0x1234;
int real_byteorder;
int real_floatwordorder = 0;
Uint16 value16 = 0xCDAB;
Uint16 swapped16 = 0xABCD;
Uint32 value32 = 0xEFBEADDE;
Uint32 swapped32 = 0xDEADBEEF;
Uint64 value64, swapped64;
union {
double d;
Uint32 ui32[2];
} value_double;
value64 = 0xEFBEADDE;
value64 <<= 32;
value64 |= 0xCDAB3412;
swapped64 = 0x1234ABCD;
swapped64 <<= 32;
swapped64 |= 0xDEADBEEF;
value_double.d = 3.141593;
if (verbose) {
SDL_Log("Detected a %s endian machine.\n",
@@ -122,22 +115,6 @@ TestEndian(SDL_bool verbose)
}
++error;
}
if (verbose) {
SDL_Log("Detected a %s endian float word order machine.\n",
(SDL_FLOATWORDORDER == SDL_LIL_ENDIAN) ? "little" : "big");
}
if (value_double.ui32[0] == 0x82c2bd7f && value_double.ui32[1] == 0x400921fb) {
real_floatwordorder = SDL_LIL_ENDIAN;
} else if (value_double.ui32[0] == 0x400921fb && value_double.ui32[1] == 0x82c2bd7f) {
real_floatwordorder = SDL_BIG_ENDIAN;
}
if (real_floatwordorder != SDL_FLOATWORDORDER) {
if (verbose) {
SDL_Log("Actually a %s endian float word order machine!\n",
(real_floatwordorder == SDL_LIL_ENDIAN) ? "little" : (real_floatwordorder == SDL_BIG_ENDIAN) ? "big" : "unknown" );
}
++error;
}
if (verbose) {
SDL_Log("Value 16 = 0x%X, swapped = 0x%X\n", value16,
SDL_Swap16(value16));

View File

@@ -12,7 +12,7 @@
#include "SDL_test.h"
static int SDLCALL
static int
num_compare(const void *_a, const void *_b)
{
const int a = *((const int *) _a);

View File

@@ -20,7 +20,7 @@
#endif
#include "SDL_test_common.h"
#include "testutils.h"
static SDLTest_CommonState *state;
@@ -44,6 +44,56 @@ quit(int rc)
exit(rc);
}
SDL_Texture *
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
{
SDL_Surface *temp;
SDL_Texture *texture;
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return NULL;
}
/* Set transparent pixel as the pixel at (0,0) */
if (transparent) {
if (temp->format->palette) {
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
} else {
switch (temp->format->BitsPerPixel) {
case 15:
SDL_SetColorKey(temp, SDL_TRUE,
(*(Uint16 *) temp->pixels) & 0x00007FFF);
break;
case 16:
SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
break;
case 24:
SDL_SetColorKey(temp, SDL_TRUE,
(*(Uint32 *) temp->pixels) & 0x00FFFFFF);
break;
case 32:
SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
break;
}
}
}
/* Create textures from the image */
texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!texture) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return NULL;
}
SDL_FreeSurface(temp);
/* We're ready to roll. :) */
return texture;
}
void
Draw(DrawState *s)
{
@@ -136,8 +186,8 @@ main(int argc, char *argv[])
drawstate->window = state->windows[i];
drawstate->renderer = state->renderers[i];
drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", SDL_TRUE, NULL, NULL);
drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", SDL_FALSE, NULL, NULL);
drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", SDL_TRUE);
drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", SDL_FALSE);
if (!drawstate->sprite || !drawstate->background) {
quit(2);
}

View File

@@ -20,7 +20,7 @@
#endif
#include "SDL_test_common.h"
#include "testutils.h"
static SDLTest_CommonState *state;
@@ -45,6 +45,56 @@ quit(int rc)
exit(rc);
}
SDL_Texture *
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
{
SDL_Surface *temp;
SDL_Texture *texture;
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return NULL;
}
/* Set transparent pixel as the pixel at (0,0) */
if (transparent) {
if (temp->format->palette) {
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
} else {
switch (temp->format->BitsPerPixel) {
case 15:
SDL_SetColorKey(temp, SDL_TRUE,
(*(Uint16 *) temp->pixels) & 0x00007FFF);
break;
case 16:
SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
break;
case 24:
SDL_SetColorKey(temp, SDL_TRUE,
(*(Uint32 *) temp->pixels) & 0x00FFFFFF);
break;
case 32:
SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
break;
}
}
}
/* Create textures from the image */
texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!texture) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return NULL;
}
SDL_FreeSurface(temp);
/* We're ready to roll. :) */
return texture;
}
SDL_bool
DrawComposite(DrawState *s)
{
@@ -242,11 +292,11 @@ main(int argc, char *argv[])
drawstate->window = state->windows[i];
drawstate->renderer = state->renderers[i];
if (test_composite) {
drawstate->sprite = LoadTexture(drawstate->renderer, "icon-alpha.bmp", SDL_TRUE, NULL, NULL);
drawstate->sprite = LoadTexture(drawstate->renderer, "icon-alpha.bmp", SDL_TRUE);
} else {
drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", SDL_TRUE, NULL, NULL);
drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", SDL_TRUE);
}
drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", SDL_FALSE, NULL, NULL);
drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", SDL_FALSE);
if (!drawstate->sprite || !drawstate->background) {
quit(2);
}

View File

@@ -20,7 +20,6 @@
#endif
#include "SDL_test_common.h"
#include "testutils.h"
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480
@@ -47,6 +46,56 @@ quit(int rc)
exit(rc);
}
SDL_Texture *
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
{
SDL_Surface *temp;
SDL_Texture *texture;
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return NULL;
}
/* Set transparent pixel as the pixel at (0,0) */
if (transparent) {
if (temp->format->palette) {
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
} else {
switch (temp->format->BitsPerPixel) {
case 15:
SDL_SetColorKey(temp, SDL_TRUE,
(*(Uint16 *) temp->pixels) & 0x00007FFF);
break;
case 16:
SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
break;
case 24:
SDL_SetColorKey(temp, SDL_TRUE,
(*(Uint32 *) temp->pixels) & 0x00FFFFFF);
break;
case 32:
SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
break;
}
}
}
/* Create textures from the image */
texture = SDL_CreateTextureFromSurface(renderer, temp);
if (!texture) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return NULL;
}
SDL_FreeSurface(temp);
/* We're ready to roll. :) */
return texture;
}
void
Draw(DrawState *s)
{
@@ -127,8 +176,8 @@ main(int argc, char *argv[])
drawstate->window = state->windows[i];
drawstate->renderer = state->renderers[i];
drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", SDL_TRUE, NULL, NULL);
drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", SDL_FALSE, NULL, NULL);
drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", SDL_TRUE);
drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", SDL_FALSE);
if (!drawstate->sprite || !drawstate->background) {
quit(2);
}

View File

@@ -126,52 +126,21 @@ static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
static SDL_bool CompileShader(GLhandleARB shader, const char *source)
{
GLint status = 0;
GLint status;
glShaderSourceARB(shader, 1, &source, NULL);
glCompileShaderARB(shader);
glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
if (status == 0) {
GLint length = 0;
GLint length;
char *info;
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = (char *) SDL_malloc(length + 1);
if (!info) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
} else {
glGetInfoLogARB(shader, length, NULL, info);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info);
SDL_free(info);
}
return SDL_FALSE;
} else {
return SDL_TRUE;
}
}
info = SDL_stack_alloc(char, length+1);
glGetInfoLogARB(shader, length, NULL, info);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info);
SDL_stack_free(info);
static SDL_bool LinkProgram(ShaderData *data)
{
GLint status = 0;
glAttachObjectARB(data->program, data->vert_shader);
glAttachObjectARB(data->program, data->frag_shader);
glLinkProgramARB(data->program);
glGetObjectParameterivARB(data->program, GL_OBJECT_LINK_STATUS_ARB, &status);
if (status == 0) {
GLint length = 0;
char *info;
glGetObjectParameterivARB(data->program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
info = (char *) SDL_malloc(length + 1);
if (!info) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
} else {
glGetInfoLogARB(data->program, length, NULL, info);
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to link program:\n%s", info);
SDL_free(info);
}
return SDL_FALSE;
} else {
return SDL_TRUE;
@@ -202,9 +171,9 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
}
/* ... and in the darkness bind them */
if (!LinkProgram(data)) {
return SDL_FALSE;
}
glAttachObjectARB(data->program, data->vert_shader);
glAttachObjectARB(data->program, data->frag_shader);
glLinkProgramARB(data->program);
/* Set up some uniform variables */
glUseProgramObjectARB(data->program);

View File

@@ -21,7 +21,6 @@
#include "SDL_test.h"
#include "SDL_test_common.h"
#include "testutils.h"
#define NUM_SPRITES 100
#define MAX_SPEED 1
@@ -63,19 +62,54 @@ int
LoadSprite(const char *file)
{
int i;
SDL_Surface *temp;
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return (-1);
}
sprite_w = temp->w;
sprite_h = temp->h;
/* Set transparent pixel as the pixel at (0,0) */
if (temp->format->palette) {
SDL_SetColorKey(temp, 1, *(Uint8 *) temp->pixels);
} else {
switch (temp->format->BitsPerPixel) {
case 15:
SDL_SetColorKey(temp, 1, (*(Uint16 *) temp->pixels) & 0x00007FFF);
break;
case 16:
SDL_SetColorKey(temp, 1, *(Uint16 *) temp->pixels);
break;
case 24:
SDL_SetColorKey(temp, 1, (*(Uint32 *) temp->pixels) & 0x00FFFFFF);
break;
case 32:
SDL_SetColorKey(temp, 1, *(Uint32 *) temp->pixels);
break;
}
}
/* Create textures from the image */
for (i = 0; i < state->num_windows; ++i) {
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h);
SDL_Renderer *renderer = state->renderers[i];
sprites[i] = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprites[i]) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return (-1);
}
if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
SDL_DestroyTexture(sprites[i]);
return (-1);
}
}
SDL_FreeSurface(temp);
/* We're ready to roll. :) */
return (0);

View File

@@ -20,7 +20,6 @@
#endif
#include "SDL.h"
#include "testutils.h"
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480
@@ -43,6 +42,55 @@ quit(int rc)
exit(rc);
}
int
LoadSprite(const char *file)
{
SDL_Surface *temp;
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", file, SDL_GetError());
return (-1);
}
sprite_w = temp->w;
sprite_h = temp->h;
/* Set transparent pixel as the pixel at (0,0) */
if (temp->format->palette) {
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
} else {
switch (temp->format->BitsPerPixel) {
case 15:
SDL_SetColorKey(temp, SDL_TRUE,
(*(Uint16 *) temp->pixels) & 0x00007FFF);
break;
case 16:
SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
break;
case 24:
SDL_SetColorKey(temp, SDL_TRUE,
(*(Uint32 *) temp->pixels) & 0x00FFFFFF);
break;
case 32:
SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
break;
}
}
/* Create textures from the image */
sprite = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprite) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return (-1);
}
SDL_FreeSurface(temp);
/* We're ready to roll. :) */
return (0);
}
void
MoveSprites()
{
@@ -110,9 +158,7 @@ main(int argc, char *argv[])
quit(2);
}
sprite = LoadTexture(renderer, "icon.bmp", SDL_TRUE, &sprite_w, &sprite_h);
if (sprite == NULL) {
if (LoadSprite("icon.bmp") < 0) {
quit(2);
}

View File

@@ -23,7 +23,6 @@
#endif
#include "SDL.h"
#include "testutils.h"
#define MOOSEPIC_W 64
#define MOOSEPIC_H 88
@@ -129,7 +128,6 @@ main(int argc, char **argv)
{
SDL_Window *window;
SDL_RWops *handle;
char *filename = NULL;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@@ -140,13 +138,7 @@ main(int argc, char **argv)
}
/* load the moose images */
filename = GetResourceFilename(NULL, "moose.dat");
if (filename == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory\n");
return -1;
}
handle = SDL_RWFromFile(filename, "rb");
SDL_free(filename);
handle = SDL_RWFromFile("moose.dat", "rb");
if (handle == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Can't find the file moose.dat !\n");
quit(2);

View File

@@ -19,7 +19,6 @@ static int total_channels;
static int active_channel;
#define SAMPLE_RATE_HZ 48000
#define QUICK_TEST_TIME_MSEC 100
#define CHANNEL_TEST_TIME_SEC 5
#define MAX_AMPLITUDE SDL_MAX_SINT16
@@ -189,11 +188,7 @@ main(int argc, char *argv[])
SDL_Log("Playing %d Hz test tone on channel: %s\n", sine_freq, get_channel_name(j, total_channels));
/* fill_buffer() will increment the active channel */
if (SDL_getenv("SDL_TESTS_QUICK") != NULL) {
SDL_Delay(QUICK_TEST_TIME_MSEC);
} else {
SDL_Delay(CHANNEL_TEST_TIME_SEC * 1000);
}
SDL_Delay(CHANNEL_TEST_TIME_SEC * 1000);
}
SDL_CloseAudioDevice(dev);

View File

@@ -91,12 +91,6 @@ main(int argc, char *argv[])
return (1);
}
if (SDL_getenv("SDL_TESTS_QUICK") != NULL) {
SDL_Log("Not running slower tests");
SDL_Quit();
return 0;
}
while (argv[arg] && *argv[arg] == '-') {
if (SDL_strcmp(argv[arg], "--prio") == 0) {
testprio = 1;

View File

@@ -54,12 +54,6 @@ main(int argc, char *argv[])
return (1);
}
if (SDL_getenv("SDL_TESTS_QUICK") != NULL) {
SDL_Log("Not running slower tests");
SDL_Quit();
return 0;
}
/* Verify SDL_GetTicks* acts monotonically increasing, and not erratic. */
SDL_Log("Sanity-checking GetTicks\n");
for (i = 0; i < 1000; ++i) {

View File

@@ -21,7 +21,7 @@
#include "SDL_test.h"
#include "SDL_test_common.h"
#include "testutils.h"
static SDLTest_CommonState *state;
@@ -42,6 +42,55 @@ quit(int rc)
exit(rc);
}
int
LoadSprite(const char *file, SDL_Renderer *renderer)
{
SDL_Surface *temp;
/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", file, SDL_GetError());
return (-1);
}
sprite_w = temp->w;
sprite_h = temp->h;
/* Set transparent pixel as the pixel at (0,0) */
if (temp->format->palette) {
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
} else {
switch (temp->format->BitsPerPixel) {
case 15:
SDL_SetColorKey(temp, SDL_TRUE,
(*(Uint16 *) temp->pixels) & 0x00007FFF);
break;
case 16:
SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
break;
case 24:
SDL_SetColorKey(temp, SDL_TRUE,
(*(Uint32 *) temp->pixels) & 0x00FFFFFF);
break;
case 32:
SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
break;
}
}
/* Create textures from the image */
sprite = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprite) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return (-1);
}
SDL_FreeSurface(temp);
/* We're ready to roll. :) */
return (0);
}
void
DrawOnViewport(SDL_Renderer * renderer)
{
@@ -180,9 +229,7 @@ main(int argc, char *argv[])
quit(2);
}
sprite = LoadTexture(state->renderers[0], "icon.bmp", SDL_TRUE, &sprite_w, &sprite_h);
if (sprite == NULL) {
if (LoadSprite("icon.bmp", state->renderers[0]) < 0) {
quit(2);
}