SDL/test
Ryan C. Gordon 9c664b0062
main: Added _optional_ callback entry points.
This lets apps optionally have a handful of callbacks for their entry points instead of a single main function. If used, the actual main/SDL_main/whatever entry point will be implemented in the single-header library SDL_main.h and the app will implement four separate functions:

First:

    int SDL_AppInit(int argc, char **argv);

This will be called once before anything else. argc/argv work like they always do. If this returns 0, the app runs. If it returns < 0, the app calls SDL_AppQuit and terminates with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. This function should not go into an infinite mainloop; it should do any one-time startup it requires and then return.

Then:

     int SDL_AppIterate(void);

This is called over and over, possibly at the refresh rate of the display or some other metric that the platform dictates. This is where the heart of your app runs. It should return as quickly as reasonably possible, but it's not a "run one memcpy and that's all the time you have" sort of thing. The app should do any game updates, and render a frame of video. If it returns < 0, SDL will call SDL_AppQuit and terminate the process with an exit code that reports an error to the platform. If it returns > 0, the app calls SDL_AppQuit and terminates with an exit code that reports success to the platform. If it returns 0, then SDL_AppIterate will be called again at some regular frequency. The platform may choose to run this more or less (perhaps less in the background, etc), or it might just call this function in a loop as fast as possible. You do not check the event queue in this function (SDL_AppEvent exists for that).

Next:

    int SDL_AppEvent(const SDL_Event *event);

This will be called once for each event pushed into the SDL queue. This may be called from any thread, and possibly in parallel to SDL_AppIterate. The fields in event do not need to be free'd (as you would normally need to do for SDL_EVENT_DROP_FILE, etc), and your app should not call SDL_PollEvent, SDL_PumpEvent, etc, as SDL will manage this for you. Return values are the same as from SDL_AppIterate(), so you can terminate in response to SDL_EVENT_QUIT, etc.

Finally:

    void SDL_AppQuit(void);

This is called once before terminating the app--assuming the app isn't being forcibly killed or crashed--as a last chance to clean up. After this returns, SDL will call SDL_Quit so the app doesn't have to (but it's safe for the app to call it, too). Process termination proceeds as if the app returned normally from main(), so atexit handles will run, if your platform supports that.

The app does not implement SDL_main if using this. To turn this on, define SDL_MAIN_USE_CALLBACKS before including SDL_main.h. Defines like SDL_MAIN_HANDLED and SDL_MAIN_NOIMPL are also respected for callbacks, if the app wants to do some sort of magic main implementation thing.

In theory, on most platforms these can be implemented in the app itself, but this saves some #ifdefs in the app and lets everyone struggle less against some platforms, and might be more efficient in the long run, too.

On some platforms, it's possible this is the only reasonable way to go, but we haven't actually hit one that 100% requires it yet (but we will, if we want to write a RetroArch backend, for example).

Using the callback entry points works on every platform, because on platforms that don't require them, we can fake them with a simple loop in an internal implementation of the usual SDL_main.

The primary way we expect people to write SDL apps is with SDL_main, and this is not intended to replace it. If the app chooses to use this, it just removes some platform-specific details they might have to otherwise manage, and maybe removes a barrier to entry on some future platform.

Fixes #6785.
Reference PR #8247.
2023-11-01 18:40:41 -04:00
..
android cmake: create Android jars + apks for tests 2023-07-20 16:54:29 +02:00
emscripten Disable cache in python http server 2023-08-14 03:50:06 +02:00
n3ds N3DS port (squashed) 2022-10-10 08:50:59 -07:00
shapes Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
uwp cmake: build tests for UWP 2023-08-12 17:37:52 +02:00
CMakeLists.txt main: Added _optional_ callback entry points. 2023-11-01 18:40:41 -04:00
COPYING Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
README test: Removed loopwavequeue.c; obsolete in SDL3. 2023-07-30 11:55:57 -04:00
audiofile.bmp test: Added testaudio 2023-08-02 15:02:32 -04:00
checkkeys.c tests: plug leaks when running with --trackmem 2023-09-19 17:58:25 +02:00
checkkeysthreads.c tests: plug leaks when running with --trackmem 2023-09-19 17:58:25 +02:00
gamepad_axis.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_axis.h Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_axis_arrow.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_axis_arrow.h Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_back.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_back.h Reduced the size of the gamepad front and back images 2023-07-11 10:20:08 -07:00
gamepad_battery_empty.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_battery_empty.h Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_battery_full.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_battery_full.h Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_battery_low.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_battery_low.h Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_battery_medium.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_battery_medium.h Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_battery_unknown.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_battery_unknown.h Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_battery_wired.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_battery_wired.h Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_button.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_button.h Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_button_background.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_button_background.h Added button background 2023-07-11 10:26:22 -07:00
gamepad_button_small.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_button_small.h Added joystick and gamepad element display in testgamepad 2023-07-10 17:06:42 -07:00
gamepad_face_abxy.bmp Use light text for button labels so they show up well over the activity highlight 2023-07-16 04:32:12 -07:00
gamepad_face_abxy.h Use light text for button labels so they show up well over the activity highlight 2023-07-16 04:32:12 -07:00
gamepad_face_bayx.bmp Use light text for button labels so they show up well over the activity highlight 2023-07-16 04:32:12 -07:00
gamepad_face_bayx.h Use light text for button labels so they show up well over the activity highlight 2023-07-16 04:32:12 -07:00
gamepad_face_sony.bmp Use light text for button labels so they show up well over the activity highlight 2023-07-16 04:32:12 -07:00
gamepad_face_sony.h Use light text for button labels so they show up well over the activity highlight 2023-07-16 04:32:12 -07:00
gamepad_front.bmp Use light text for button labels so they show up well over the activity highlight 2023-07-16 04:32:12 -07:00
gamepad_front.h Use light text for button labels so they show up well over the activity highlight 2023-07-16 04:32:12 -07:00
gamepad_touchpad.bmp Added gamepad BMP files used as sources for the header files 2023-07-16 04:32:12 -07:00
gamepad_touchpad.h Added touchpad visualization for testgamepad 2023-07-10 11:36:32 -07:00
gamepadutils.c Relabel back paddles as left or right 2023-08-09 11:03:30 -07:00
gamepadutils.h Added the ability to specify a gamepad type in the mapping 2023-07-17 12:59:56 -07:00
icon.bmp Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
icon.h testspriteminimal: make standalone by embedding icon.bmp 2023-09-19 17:58:25 +02:00
logaudiodev.bmp test: Added testaudio 2023-08-02 15:02:32 -04:00
loopwave.c main: Added _optional_ callback entry points. 2023-11-01 18:40:41 -04:00
main.cpp Make WinRT's SDL_main header-only 2022-12-15 08:01:01 -08:00
moose.dat Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
physaudiodev.bmp test: Added testaudio 2023-08-02 15:02:32 -04:00
picture.xbm Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
pretest.c cmake: let every test depends on pretest 2023-09-25 18:02:40 +02:00
relative_mode.markdown SDL_CreateWindow() has been simplified and no longer takes a window position. 2023-03-06 09:50:12 -08:00
sample.bmp Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
sample.wav Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
soundboard.bmp testaudio: Fixed soundboard icon, which had a colorkey issue. 2023-08-03 21:35:38 -04:00
soundboard_levels.bmp test: Added testaudio 2023-08-02 15:02:32 -04:00
speaker.bmp test: Added testaudio 2023-08-02 15:02:32 -04:00
template.test.in test/template.test.in: Pass SDL_NONINTERACTIVE_ARGUMENTS to installed-tests 2023-04-12 15:04:11 +00:00
testatomic.c Removed invalid assert in testatomic 2023-07-22 18:39:39 -07:00
testaudio-art.txt test: Added testaudio 2023-08-02 15:02:32 -04:00
testaudio.c main: Added _optional_ callback entry points. 2023-11-01 18:40:41 -04:00
testaudiocapture.c main: Added _optional_ callback entry points. 2023-11-01 18:40:41 -04:00
testaudiohotplug.c audio: Rename SDL_GetAudioStreamBinding to SDL_GetAudioStreamDevice. 2023-08-27 16:54:30 -04:00
testaudioinfo.c audio: Allow querying of device buffer size. 2023-09-13 11:03:17 -04:00
testaudiostreamdynamicresample.c tests: plug leaks when running with --trackmem 2023-09-19 17:58:25 +02:00
testautomation.c Added SDL properties API 2023-10-11 22:38:00 -07:00
testautomation_audio.c We don't require the audio system to be initialized for audio format conversion 2023-10-11 09:23:23 -07:00
testautomation_clipboard.c Expanded automated clipboard tests 2023-07-05 20:06:59 -07:00
testautomation_events.c testautomation_events.c: initialize "timestamp" to solve "conditional jump or move depends on uninitialised value" 2023-06-13 23:03:32 +02:00
testautomation_guid.c testautomation_guid.c: fix integer warning in 32 bit builds. 2023-05-31 04:50:02 +03:00
testautomation_hints.c testautomation_hints.c: free hint memory 2023-06-13 23:12:01 +02:00
testautomation_images.c More fix warnings about static function and prototype 2023-03-08 16:14:09 +01:00
testautomation_images.h Fix warning drop const qualifier 2023-03-08 22:22:34 +01:00
testautomation_intrinsics.c Use #ifdef/#ifndef instead of #if defined/#if \!defined 2023-03-30 21:35:01 +00:00
testautomation_joystick.c More fix warnings about static function and prototype 2023-03-08 16:14:09 +01:00
testautomation_keyboard.c Fix uses of undefined macro identifiers (-Wundef) 2023-03-29 21:49:01 +00:00
testautomation_main.c More fix warnings about static function and prototype 2023-03-08 16:14:09 +01:00
testautomation_math.c test: Accept small numerical differences in more mathematical tests 2023-09-28 09:37:12 -07:00
testautomation_mouse.c Fix log message spelling 2023-10-02 19:47:39 -04:00
testautomation_pixels.c Fixed testautomation --filter pixels_allocFreeFormat 2023-08-25 08:06:08 -07:00
testautomation_platform.c Use #ifdef/#ifndef instead of #if defined/#if \!defined 2023-03-30 21:35:01 +00:00
testautomation_properties.c Added SDL properties API 2023-10-11 22:38:00 -07:00
testautomation_rect.c Fix various typos (docs/build scripts/tests) 2023-07-03 08:35:37 -07:00
testautomation_render.c testautomation: only require accelated renderer with non-dummy video driver 2023-09-25 18:02:40 +02:00
testautomation_rwops.c SDL_rwops read/write functions return size_t again 2023-08-07 20:36:21 -07:00
testautomation_sdltest.c Fix warning drop const qualifier 2023-03-08 22:22:34 +01:00
testautomation_stdlib.c Added support for "%[]" sscanf syntax 2023-10-24 17:28:15 -07:00
testautomation_suites.h Added SDL properties API 2023-10-11 22:38:00 -07:00
testautomation_surface.c Fix various typos (docs/build scripts/tests) 2023-07-03 08:35:37 -07:00
testautomation_syswm.c cmake+tests: include SDL_build_config.h in select tests + add include paths 2023-03-21 23:03:02 +03:00
testautomation_timer.c Move check for SDL_Delay upper bounds to testtimer 2023-09-25 18:02:40 +02:00
testautomation_video.c Added properties to various SDL objects 2023-10-11 22:38:00 -07:00
testbounds.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testcontroller.c tests: plug leaks when running with --trackmem 2023-09-19 17:58:25 +02:00
testcustomcursor.c testprogram: let main() return normally, don't exit for platform (eg Android) where there is some cleanup afterward. 2023-04-12 11:37:26 +02:00
testdisplayinfo.c Updated SDL high DPI support 2023-05-17 12:58:00 -07:00
testdraw.c cmake: build tests for UWP 2023-08-12 17:37:52 +02:00
testdrawchessboard.c testdrawchessboard: clean up renderer and window 2023-10-05 13:41:01 +02:00
testdropfile.c tests: plug leaks when running with --trackmem 2023-09-19 17:58:25 +02:00
testerror.c testprogram: let main() return normally, don't exit for platform (eg Android) where there is some cleanup afterward. 2023-04-12 11:37:26 +02:00
testevdev.c testevdev: Add some examples of PDP third-party Switch controllers 2023-07-10 08:59:18 -07:00
testffmpeg.c testffmpeg: print usage of options to change audio/video codec 2023-10-13 02:30:14 +02:00
testffmpeg_videotoolbox.h Added support for 0-copy decode and display using Apple VideoToolbox 2023-10-10 03:32:46 -07:00
testffmpeg_videotoolbox.m Added support for 0-copy decode and display using Apple VideoToolbox 2023-10-10 03:32:46 -07:00
testfile.c tests: plug leaks when running with --trackmem 2023-09-19 17:58:25 +02:00
testfilesystem.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testgeometry.c testprogram: let main() return normally, don't exit for platform (eg Android) where there is some cleanup afterward. 2023-04-12 11:37:26 +02:00
testgl.c test: Add flag to suspend drawing when occluded 2023-07-18 16:42:05 -04:00
testgles.c testprogram: let main() return normally, don't exit for platform (eg Android) where there is some cleanup afterward. 2023-04-12 11:37:26 +02:00
testgles2.c test: Add flag to suspend drawing when occluded 2023-07-18 16:42:05 -04:00
testgles2_sdf.c tests: build tests with C90 standard 2023-05-27 01:49:07 +02:00
testgles2_sdf_img_normal.bmp Add basic testgles2_sdf program to demonstrate sign distance field with opengles2 2021-01-24 00:51:24 -05:00
testgles2_sdf_img_sdf.bmp Add basic testgles2_sdf program to demonstrate sign distance field with opengles2 2021-01-24 00:51:24 -05:00
testhaptic.c List the available haptic devices in testhaptic 2023-06-20 09:33:59 -07:00
testhittesting.c testhittesting: use SDLTest_Common for creating window(s) and renderer(s) 2023-03-17 17:54:16 +01:00
testhotplug.c Fix various typos (docs/build scripts/tests) 2023-07-03 08:35:37 -07:00
testiconv.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testime.c SDL_rwops read/write functions return size_t again 2023-08-07 20:36:21 -07:00
testintersections.c testintersections: check integer argument + no global done + get final tick before SDL shutdown 2023-03-17 17:54:16 +01:00
testkeys.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testloadso.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testlocale.c testlocale: only ininitialize video when needed 2023-07-19 00:14:38 +02:00
testlock.c thread: Locking mutexes and rwlocks are now void functions. 2023-10-26 08:57:34 -04:00
testmessage.c testprogram: let main() return normally, don't exit for platform (eg Android) where there is some cleanup afterward. 2023-04-12 11:37:26 +02:00
testmouse.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testmultiaudio.c audio: Rename SDL_GetAudioStreamBinding to SDL_GetAudioStreamDevice. 2023-08-27 16:54:30 -04:00
testnative.c tests: plug leaks when running with --trackmem 2023-09-19 17:58:25 +02:00
testnative.h Fix uses of undefined macro identifiers (-Wundef) 2023-03-29 21:49:01 +00:00
testnativecocoa.m fixed typo in prev. patch. 2023-07-28 07:35:04 +03:00
testnativew32.c Updated copyright for 2023 2023-01-09 09:41:41 -08:00
testnativex11.c Updated copyright for 2023 2023-01-09 09:41:41 -08:00
testoffscreen.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testoverlay.c Added SDL_GetTextureDXGIResource() to get the DXGI resource associated with a render texture. 2023-10-10 03:32:46 -07:00
testplatform.c Fix various typos (docs/build scripts/tests) 2023-07-03 08:35:37 -07:00
testpopup.c tests: build tests with C90 standard 2023-05-27 01:49:07 +02:00
testpower.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testqsort.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testrelative.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testrendercopyex.c testprogram: let main() return normally, don't exit for platform (eg Android) where there is some cleanup afterward. 2023-04-12 11:37:26 +02:00
testrendertarget.c testprogram: let main() return normally, don't exit for platform (eg Android) where there is some cleanup afterward. 2023-04-12 11:37:26 +02:00
testresample.c SDL_rwops read/write functions return size_t again 2023-08-07 20:36:21 -07:00
testrumble.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testrwlock.c thread: Locking mutexes and rwlocks are now void functions. 2023-10-26 08:57:34 -04:00
testscale.c testprogram: let main() return normally, don't exit for platform (eg Android) where there is some cleanup afterward. 2023-04-12 11:37:26 +02:00
testsem.c Rename SDL mutex, semaphore and condition variable types to match SDL 3.0 naming convention 2023-04-28 12:08:33 -07:00
testsensor.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testshader.c testprograms: parse arguments using SDLTest_CommonState 2023-03-17 17:54:16 +01:00
testshape.c shape: Use SDL[Test]_ReadSurfacePixel 2023-10-10 03:23:20 -07:00
testsprite.c main: Added _optional_ callback entry points. 2023-11-01 18:40:41 -04:00
testspriteminimal.c testspriteminimal: make standalone by embedding icon.bmp 2023-09-19 17:58:25 +02:00
teststreaming.c testprogram: let main() return normally, don't exit for platform (eg Android) where there is some cleanup afterward. 2023-04-12 11:37:26 +02:00
testsurround.c audio: Allow querying of device buffer size. 2023-09-13 11:03:17 -04:00
testthread.c SDL API renaming: SDL TLS functions 2023-05-26 08:33:15 -07:00
testtimer.c Move check for SDL_Delay upper bounds to testtimer 2023-09-25 18:02:40 +02:00
testurl.c Updated copyright for 2023 2023-01-09 09:41:41 -08:00
testutils.c Relicensed testutils to match other test code 2023-07-16 04:32:12 -07:00
testutils.h Relicensed testutils to match other test code 2023-07-16 04:32:12 -07:00
testver.c testver: don't allow any arguments 2023-03-17 17:54:16 +01:00
testviewport.c testprogram: let main() return normally, don't exit for platform (eg Android) where there is some cleanup afterward. 2023-04-12 11:37:26 +02:00
testvulkan.c tests: build tests with C90 standard 2023-05-27 01:49:07 +02:00
testwm.c tests: plug leaks when running with --trackmem 2023-09-19 17:58:25 +02:00
testyuv.bmp Updated SDL's YUV support, many thanks to Adrien Descamps 2017-11-12 22:51:12 -08:00
testyuv.c tests: plug leaks when running with --trackmem 2023-09-19 17:58:25 +02:00
testyuv_cvt.c tests: build tests with C90 standard 2023-05-27 01:49:07 +02:00
testyuv_cvt.h Updated copyright for 2023 2023-01-09 09:41:41 -08:00
torturethread.c testprogram: let main() return normally, don't exit for platform (eg Android) where there is some cleanup afterward. 2023-04-12 11:37:26 +02:00
trashcan.bmp test: Added testaudio 2023-08-02 15:02:32 -04:00
unifont-13.0.06-license.txt Latest Unifont with OFL is now bundled. (#4268) 2021-07-08 14:51:16 -07:00
unifont-13.0.06.hex Latest Unifont with OFL is now bundled. (#4268) 2021-07-08 14:51:16 -07:00
utf8.txt Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00

README

These are test programs for the SDL library:

	checkkeys	Watch the key events to check the keyboard
	loopwave	Audio test -- loop playing a WAV file
	testsurround	Audio test -- play test tone on each audio channel
	testaudioinfo	Lists audio device capabilities
	testerror	Tests multi-threaded error handling
	testfile	Tests RWops layer
	testgl		A very simple example of using OpenGL with SDL
	testiconv	Tests international string conversion
	testkeys	List the available keyboard keys
	testloadso	Tests the loadable library layer
	testlocale  Test Locale API
	testlock	Hacked up test of multi-threading and locking
	testmouse	Tests mouse coordinates
	testmultiaudio	Tests using several audio devices
	testoverlay	Tests the overlay flickering/scaling during playback.
	testplatform	Tests types, endianness and cpu capabilities
	testsem		Tests SDL's semaphore implementation
	testshape	Tests shaped windows
	testsprite	Example of fast sprite movement on the screen
	testthread	Hacked up test of multi-threading
	testtimer	Test the timer facilities
	testver		Check the version and dynamic loading and endianness
	testwm		Test window manager -- title, icon, events
	torturethread	Simple test for thread creation/destruction
	gamepadmap   Useful to generate Game Controller API compatible maps



This directory contains sample.wav, which is a sample from Will Provost's
song, The Living Proof:

     From the album The Living Proof
     Publisher: 5 Guys Named Will
     Copyright 1996 Will Provost

You can get a copy of the full song (and album!) from iTunes...

    https://itunes.apple.com/us/album/the-living-proof/id4153978

or Amazon...

    http://www.amazon.com/The-Living-Proof-Will-Provost/dp/B00004R8RH

Thanks to Will for permitting us to distribute this sample with SDL!