SDL/test
DS ac5b9bc4ee
Add support for X11 primary selection (#6132)
X11 has a so-called primary selection, which you can use by marking text and middle-clicking elsewhere to copy the marked text.

There are 3 new API functions in `SDL_clipboard.h`, which work exactly like their clipboard equivalents.

## Test Instructions

* Run the tests (just a copy of the clipboard tests): `$ ./test/testautomation --filter Clipboard`
* Build and run this small application:
<details>
```C
#include <SDL.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void print_error(const char *where)
{
	const char *errstr = SDL_GetError();
	if (errstr == NULL || errstr[0] == '\0')
		return;
	fprintf(stderr, "SDL Error after '%s': %s\n", where, errstr);
	SDL_ClearError();
}

int main()
{
	char text_buf[256];

	srand(time(NULL));

	SDL_Init(SDL_INIT_VIDEO);
	print_error("SDL_INIT()");
	SDL_Window *window = SDL_CreateWindow("Primary Selection Test", SDL_WINDOWPOS_UNDEFINED,
			SDL_WINDOWPOS_UNDEFINED, 400, 400, SDL_WINDOW_SHOWN);
	print_error("SDL_CreateWindow()");
	SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
	print_error("SDL_CreateRenderer()");

	bool quit = false;
	unsigned int do_render = 0;
	while (!quit) {
		SDL_Event event;
		while (SDL_PollEvent(&event)) {
			print_error("SDL_PollEvent()");
			switch (event.type) {
			case SDL_QUIT: {
				quit = true;
				break;
			} case SDL_KEYDOWN: {
				switch (event.key.keysym.sym) {
				case SDLK_ESCAPE:
				case SDLK_q:
					quit = true;
					break;
				case SDLK_c:
					snprintf(text_buf, sizeof(text_buf), "foo%d", rand());
					SDL_SetClipboardText(text_buf);
					print_error("SDL_SetClipboardText()");
					printf("clipboard: set_to=\"%s\"\n", text_buf);
					break;
				case SDLK_v: {
					printf("clipboard: has=%d, ", SDL_HasClipboardText());
					print_error("SDL_HasClipboardText()");
					char *text = SDL_GetClipboardText();
					print_error("SDL_GetClipboardText()");
					printf("text=\"%s\"\n", text);
					SDL_free(text);
					break;
				} case SDLK_d:
					snprintf(text_buf, sizeof(text_buf), "bar%d", rand());
					SDL_SetPrimarySelectionText(text_buf);
					print_error("SDL_SetPrimarySelectionText()");
					printf("primselec: set_to=\"%s\"\n", text_buf);
					break;
				case SDLK_f: {
					printf("primselec: has=%d, ", SDL_HasPrimarySelectionText());
					print_error("SDL_HasPrimarySelectionText()");
					char *text = SDL_GetPrimarySelectionText();
					print_error("SDL_GetPrimarySelectionText()");
					printf("text=\"%s\"\n", text);
					SDL_free(text);
					break;
				} default:
					break;
				}
				break;
			} default: {
				break;
			}}
		}
		// create less noise with WAYLAND_DEBUG=1
		if (do_render == 0) {
			SDL_RenderPresent(renderer);
			print_error("SDL_RenderPresent()");
		}
		do_render += 1;
		usleep(12000);
	}

	SDL_DestroyRenderer(renderer);
	SDL_DestroyWindow(window);
	SDL_Quit();
	print_error("quit");
	return 0;
}
```
</details>

* Use c,v,d,f to get and set the clipboard and primary selection.
* Mark text and middle-click also in other applications.
* For wayland under x:
  * `$ mutter --wayland --no-x11 --nested`
  * `$ XDG_SESSION_TYPE=wayland SDL_VIDEODRIVER=wayland ./<path_to_test_appl_binary>`
2022-09-14 09:28:35 -07:00
..
emscripten
nacl
shapes
CMakeLists.txt cmake: Enable CET compatibility for x86/x64 targets using VS 16.7+ 2022-08-24 11:29:36 -07:00
COPYING
Makefile.in Added a virtual joystick automated test 2022-07-13 08:58:15 -07:00
Makefile.os2 Split the common code in test/Makefile.os2 into a separate file 2022-05-19 20:11:10 +03:00
Makefile.w32 test/Makefile.w32: fix minor typo 2022-05-20 21:10:56 +03:00
README testsurround: Add surround sound channel tester 2021-10-30 21:26:03 -07:00
acinclude.m4 tests: minor update to acinclude.m4::pkg.m4 2021-10-31 08:47:00 +03:00
autogen.sh minor tidy-up to configury. 2022-06-15 17:00:02 +03:00
axis.bmp
button.bmp
checkkeys.c Don't spin as quickly as possible in the checkkeys rendering loop 2022-07-01 13:35:41 -07:00
checkkeysthreads.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
configure Updated to autoconf 2.71 2022-06-08 10:14:36 -07:00
configure.ac configure.ac: remove unnecessary AC_SUBST's added by commit 38ef678990 2022-05-05 18:55:02 +03:00
controllermap.bmp Be explicit about mapping the new game controller paddle buttons 2020-11-07 02:22:15 -08:00
controllermap.c Allow mapping a controller other than the first one 2022-09-07 01:58:42 -07:00
controllermap_back.bmp Be explicit about mapping the new game controller paddle buttons 2020-11-07 02:22:15 -08:00
icon.bmp
loopwave.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
loopwavequeue.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
moose.dat
picture.xbm
relative_mode.markdown
sample.bmp
sample.wav
template.test.in test: Install GNOME-style installed-tests metadata 2022-05-04 18:17:55 -07:00
testatomic.c Wait for all the threads to actually finish before exiting 2022-06-03 08:46:08 -07:00
testaudiocapture.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testaudiohotplug.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testaudioinfo.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testautomation.c No need to cast from char* to const char* 2022-06-18 06:52:46 -07:00
testautomation_audio.c tests: several -Wwrite-strings fixes. 2021-11-20 01:02:02 +03:00
testautomation_clipboard.c Add support for X11 primary selection (#6132) 2022-09-14 09:28:35 -07:00
testautomation_events.c Fixed up legacy MoinMoin URLs at wiki.libsdl.org 2021-04-01 12:20:33 -04:00
testautomation_guid.c Merge testguid into testautomation (#5873) 2022-07-01 16:27:51 -07:00
testautomation_hints.c Added SDL_ResetHint() to reset a hint to the default value 2022-08-10 08:01:24 -07:00
testautomation_joystick.c Added a virtual joystick automated test 2022-07-13 08:58:15 -07:00
testautomation_keyboard.c tests: several -Wwrite-strings fixes. 2021-11-20 01:02:02 +03:00
testautomation_main.c Removed the limit on the size of the SDL error message 2022-06-27 16:59:50 -07:00
testautomation_math.c Test: Fix Exp base case for Win32. 2022-08-09 21:39:46 -07:00
testautomation_mouse.c You may need to wait a bit for SDL_WarpMouseInWindow() to complete 2021-09-22 09:56:06 -07:00
testautomation_pixels.c tests: several -Wwrite-strings fixes. 2021-11-20 01:02:02 +03:00
testautomation_platform.c Fix some typos in diagnostic messages 2022-06-13 08:33:27 -07:00
testautomation_rect.c Removed two distracting gcc-11 warnings 2022-06-05 14:11:10 +03:00
testautomation_render.c Fixed bug #2426 - SDL_RenderReadPixels result is unspecified and fails testautomation 2022-03-21 10:20:04 +01:00
testautomation_rwops.c Don't run the stdio automated tests if libc isn't available 2022-08-10 09:05:55 -07:00
testautomation_sdltest.c use SDL's functions version inplace of libc version 2021-11-22 08:38:46 -08:00
testautomation_stdlib.c Added test for digit count in sscanf, e.g. "%1x" 2022-06-18 06:53:05 -07:00
testautomation_suites.h Added a virtual joystick automated test 2022-07-13 08:58:15 -07:00
testautomation_surface.c test: Add test coverage for surface size overflows 2022-06-13 11:53:53 -07:00
testautomation_syswm.c
testautomation_timer.c
testautomation_video.c testautomation: add video_setWindowCenteredOnDisplay test 2022-06-11 14:19:01 -07:00
testbounds.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testcustomcursor.c testcustomcursor: Allow running without custom or system cursors 2022-05-25 14:25:54 -07:00
testdisplayinfo.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testdraw2.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testdrawchessboard.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testdropfile.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testerror.c test: Add a mode to skip tests that involve arbitrary delays 2022-05-04 18:17:55 -07:00
testevdev.c test: Make testevdev succeed if the feature is disabled 2022-05-04 18:17:55 -07:00
testfile.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testfilesystem.c Rename folder created in test_filesystem 2022-07-03 09:24:55 -07:00
testgamecontroller.c Added left and right sensors for Nintendo Joy-Con and Wii controllers 2022-09-07 00:00:27 -07:00
testgeometry.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testgesture.c testgesture: display device name with SDL_GetTouchName() 2022-02-08 11:40:39 +01:00
testgl2.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testgles.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testgles2.c testgles2: Fix typo in help text 2022-08-16 20:38:55 -07:00
testgles2_sdf.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07: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 testhaptic.c, testjoystick.c: fixed -Wshadow warnings. 2021-11-23 15:10:50 +03:00
testhittesting.c
testhotplug.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testiconv.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testime.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testintersections.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testjoystick.c Fixed spinning at a very high framerate 2022-09-02 17:04:53 -07:00
testkeys.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testloadso.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testlocale.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testlock.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testmessage.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testmouse.c testmouse: Allow drawing rectangles as well as lines 2022-09-05 08:51:36 -07:00
testmultiaudio.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testnative.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testnative.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testnativecocoa.m
testnativeos2.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testnativew32.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testnativex11.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testoffscreen.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testoverlay2.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testplatform.c testplatform: Add LSX and LASX checks 2022-09-05 08:50:28 -07:00
testpower.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testqsort.c Use SDLCALL for callbacks in public APIs 2022-05-18 15:01:27 -07:00
testrelative.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testrendercopyex.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testrendertarget.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testresample.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testrumble.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testscale.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testsem.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testsensor.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testshader.c testshader: use SDL_malloc instead of SDL_stack_alloc. 2022-03-26 08:42:09 -04:00
testshape.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testsprite2.c Windows GDK Support (#5830) 2022-06-27 10:19:39 -07:00
testspriteminimal.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
teststreaming.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testsurround.c test: Add a mode to skip tests that involve arbitrary delays 2022-05-04 18:17:55 -07:00
testthread.c test: Add a mode to skip tests that involve arbitrary delays 2022-05-04 18:17:55 -07:00
testtimer.c test: Add a mode to skip tests that involve arbitrary delays 2022-05-04 18:17:55 -07:00
testurl.c Add a default URL in testurl 2022-07-01 13:54:17 -07:00
testutils.c Remove extra path separator in GetNearbyFilename 2022-05-19 15:25:49 -07:00
testutils.h test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testver.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testviewport.c test: Add some common code to load test resources 2022-05-04 18:17:55 -07:00
testvulkan.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testwm2.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testyuv.bmp
testyuv.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testyuv_cvt.c Updated copyright for 2022 2022-01-03 09:40:21 -08:00
testyuv_cvt.h Updated copyright for 2022 2022-01-03 09:40:21 -08:00
torturethread.c Updated copyright for 2022 2022-01-03 09:40:21 -08: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
versioning.sh fix DYLIB version inconsistencies and test failures after #6188. 2022-09-06 03:15:02 +03:00
watcom.mif Added a virtual joystick automated test 2022-07-13 08:58:15 -07: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
	loopwavequeue	Audio test -- loop playing a WAV file with SDL_QueueAudio
	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
	testgl2		A very simple example of using OpenGL with SDL
	testiconv	Tests international string conversion
	testjoystick	List joysticks and watch joystick events
	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
	testoverlay2	Tests the overlay flickering/scaling during playback.
	testplatform	Tests types, endianness and cpu capabilities
	testsem		Tests SDL's semaphore implementation
	testshape	Tests shaped windows
	testsprite2	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
	testwm2		Test window manager -- title, icon, events
	torturethread	Simple test for thread creation/destruction
	controllermap   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!