test: use SDL_test for parsing arguments in all non-interactive tests

This commit is contained in:
Anonymous Maarten 2024-08-31 19:06:24 +02:00 committed by Anonymous Maarten
parent 47a525610c
commit 2ae8b4c651
21 changed files with 408 additions and 93 deletions

View File

@ -188,6 +188,12 @@
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\SDLtest\SDLtest.vcxproj">
<Project>{da956fd3-e143-46f2-9fe5-c77bebc56b1a}</Project>
<Private>false</Private>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\SDLmain\SDLmain.vcxproj">
<Project>{da956fd3-e142-46f2-9dd5-c78bebb56b7a}</Project>
<Private>false</Private>

View File

@ -216,6 +216,12 @@
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\SDLtest\SDLtest.vcxproj">
<Project>{da956fd3-e143-46f2-9fe5-c77bebc56b1a}</Project>
<Private>false</Private>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\SDLmain\SDLmain.vcxproj">
<Project>{da956fd3-e142-46f2-9dd5-c78bebb56b7a}</Project>
<Private>false</Private>

View File

@ -188,6 +188,12 @@
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\SDLtest\SDLtest.vcxproj">
<Project>{da956fd3-e143-46f2-9fe5-c77bebc56b1a}</Project>
<Private>false</Private>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\SDLmain\SDLmain.vcxproj">
<Project>{da956fd3-e142-46f2-9dd5-c78bebb56b7a}</Project>
<Private>false</Private>

View File

@ -194,6 +194,12 @@
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\SDLtest\SDLtest.vcxproj">
<Project>{da956fd3-e143-46f2-9fe5-c77bebc56b1a}</Project>
<Private>false</Private>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
<ReferenceOutputAssembly>true</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\SDLmain\SDLmain.vcxproj">
<Project>{da956fd3-e142-46f2-9dd5-c78bebb56b7a}</Project>
<Private>false</Private>

View File

@ -112,23 +112,23 @@ add_sdl_test_executable(checkkeys checkkeys.c)
add_sdl_test_executable(checkkeysthreads checkkeysthreads.c)
add_sdl_test_executable(loopwave NEEDS_RESOURCES loopwave.c testutils.c)
add_sdl_test_executable(loopwavequeue NEEDS_RESOURCES loopwavequeue.c testutils.c)
add_sdl_test_executable(testsurround NOTRACKMEM testsurround.c)
add_sdl_test_executable(testsurround testsurround.c)
add_sdl_test_executable(testresample NEEDS_RESOURCES testresample.c)
add_sdl_test_executable(testaudioinfo NOTRACKMEM testaudioinfo.c)
add_sdl_test_executable(testaudioinfo testaudioinfo.c)
file(GLOB TESTAUTOMATION_SOURCE_FILES testautomation*.c)
add_sdl_test_executable(testautomation NONINTERACTIVE NEEDS_RESOURCES ${TESTAUTOMATION_SOURCE_FILES})
add_sdl_test_executable(testmultiaudio NEEDS_RESOURCES testmultiaudio.c testutils.c)
add_sdl_test_executable(testaudiohotplug NEEDS_RESOURCES testaudiohotplug.c testutils.c)
add_sdl_test_executable(testaudiocapture testaudiocapture.c)
add_sdl_test_executable(testatomic NOTRACKMEM NONINTERACTIVE testatomic.c)
add_sdl_test_executable(testatomic NONINTERACTIVE testatomic.c)
add_sdl_test_executable(testintersections testintersections.c)
add_sdl_test_executable(testrelative testrelative.c)
add_sdl_test_executable(testhittesting testhittesting.c)
add_sdl_test_executable(testdraw2 testdraw2.c)
add_sdl_test_executable(testdrawchessboard testdrawchessboard.c)
add_sdl_test_executable(testdropfile testdropfile.c)
add_sdl_test_executable(testerror NOTRACKMEM NONINTERACTIVE testerror.c)
add_sdl_test_executable(testerror NONINTERACTIVE testerror.c)
if(LINUX)
add_sdl_test_executable(testevdev NOTRACKMEM NONINTERACTIVE testevdev.c)
@ -148,13 +148,13 @@ endif()
add_sdl_test_executable(testhaptic testhaptic.c)
add_sdl_test_executable(testhotplug testhotplug.c)
add_sdl_test_executable(testrumble testrumble.c)
add_sdl_test_executable(testthread NOTRACKMEM NONINTERACTIVE testthread.c)
add_sdl_test_executable(testthread NONINTERACTIVE testthread.c)
add_sdl_test_executable(testiconv NEEDS_RESOURCES testiconv.c testutils.c)
add_sdl_test_executable(testime NEEDS_RESOURCES testime.c testutils.c)
add_sdl_test_executable(testjoystick testjoystick.c)
add_sdl_test_executable(testkeys NOTRACKMEM testkeys.c)
add_sdl_test_executable(testkeys testkeys.c)
add_sdl_test_executable(testloadso testloadso.c)
add_sdl_test_executable(testlocale NOTRACKMEM NONINTERACTIVE testlocale.c)
add_sdl_test_executable(testlocale NONINTERACTIVE testlocale.c)
add_sdl_test_executable(testlock testlock.c)
add_sdl_test_executable(testmouse testmouse.c)
@ -182,11 +182,11 @@ elseif(OS2)
endif()
add_sdl_test_executable(testoverlay2 NEEDS_RESOURCES testoverlay2.c testyuv_cvt.c testutils.c)
add_sdl_test_executable(testplatform NOTRACKMEM NONINTERACTIVE testplatform.c)
add_sdl_test_executable(testpower NOTRACKMEM NONINTERACTIVE testpower.c)
add_sdl_test_executable(testfilesystem NOTRACKMEM NONINTERACTIVE testfilesystem.c)
add_sdl_test_executable(testplatform NONINTERACTIVE testplatform.c)
add_sdl_test_executable(testpower NONINTERACTIVE testpower.c)
add_sdl_test_executable(testfilesystem NONINTERACTIVE testfilesystem.c)
if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
add_sdl_test_executable(testfilesystem_pre NOTRACKMEM NONINTERACTIVE testfilesystem_pre.c)
add_sdl_test_executable(testfilesystem_pre NONINTERACTIVE testfilesystem_pre.c)
endif()
add_sdl_test_executable(testrendertarget NEEDS_RESOURCES testrendertarget.c testutils.c)
add_sdl_test_executable(testscale NEEDS_RESOURCES testscale.c testutils.c)
@ -197,18 +197,18 @@ add_sdl_test_executable(testshape NEEDS_RESOURCES testshape.c)
add_sdl_test_executable(testsprite2 NEEDS_RESOURCES testsprite2.c testutils.c)
add_sdl_test_executable(testspriteminimal NEEDS_RESOURCES testspriteminimal.c testutils.c)
add_sdl_test_executable(teststreaming NEEDS_RESOURCES teststreaming.c testutils.c)
add_sdl_test_executable(testtimer NOTRACKMEM NONINTERACTIVE testtimer.c)
add_sdl_test_executable(testtimer NONINTERACTIVE testtimer.c)
add_sdl_test_executable(testurl testurl.c)
add_sdl_test_executable(testver NOTRACKMEM NONINTERACTIVE testver.c)
add_sdl_test_executable(testver NONINTERACTIVE testver.c)
add_sdl_test_executable(testviewport NEEDS_RESOURCES testviewport.c testutils.c)
add_sdl_test_executable(testwm2 testwm2.c)
add_sdl_test_executable(testyuv NEEDS_RESOURCES testyuv.c testyuv_cvt.c)
add_sdl_test_executable(torturethread torturethread.c)
add_sdl_test_executable(testrendercopyex NEEDS_RESOURCES testrendercopyex.c testutils.c)
add_sdl_test_executable(testmessage testmessage.c)
add_sdl_test_executable(testdisplayinfo NOTRACKMEM testdisplayinfo.c)
add_sdl_test_executable(testqsort NOTRACKMEM NONINTERACTIVE testqsort.c)
add_sdl_test_executable(testbounds NOTRACKMEM testbounds.c)
add_sdl_test_executable(testdisplayinfo testdisplayinfo.c)
add_sdl_test_executable(testqsort NONINTERACTIVE testqsort.c)
add_sdl_test_executable(testbounds testbounds.c)
add_sdl_test_executable(testcustomcursor testcustomcursor.c)
add_sdl_test_executable(controllermap NEEDS_RESOURCES controllermap.c testutils.c)
add_sdl_test_executable(testvulkan testvulkan.c)

View File

@ -12,6 +12,7 @@
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
/*
Absolutely basic tests just to see if we get the expected value
@ -699,9 +700,26 @@ static void RunFIFOTest(SDL_bool lock_free)
int main(int argc, char *argv[])
{
SDLTest_CommonState *state;
state = SDLTest_CommonCreateState(argv, 0);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return 1;
}
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
RunBasicTest();
if (SDL_getenv("SDL_TESTS_QUICK") != NULL) {
@ -715,6 +733,7 @@ int main(int argc, char *argv[])
RunFIFOTest(SDL_FALSE);
#endif
RunFIFOTest(SDL_TRUE);
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -11,6 +11,7 @@
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
static void
print_devices(int iscapture)
@ -50,12 +51,22 @@ int main(int argc, char **argv)
char *deviceName = NULL;
SDL_AudioSpec spec;
int n;
SDLTest_CommonState *state;
state = SDLTest_CommonCreateState(argv, SDL_INIT_AUDIO);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return 1;
}
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
@ -98,6 +109,6 @@ int main(int argc, char **argv)
SDL_Log("SDL_AudioFormat: %X\n", spec.format);
}
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -11,12 +11,27 @@
*/
#include "SDL.h"
#include "SDL_test.h"
int main(int argc, char **argv)
{
int total, i;
SDLTest_CommonState *state;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return 1;
}
if (!SDLTest_CommonInit(state)) {
SDL_Log("SDL_Init(SDL_INIT_VIDEO) failed: %s", SDL_GetError());
return 1;
}
@ -32,7 +47,7 @@ int main(int argc, char **argv)
usable.x, usable.y, usable.w, usable.h);
}
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -13,6 +13,7 @@
/* Program to test querying of display info */
#include "SDL.h"
#include "SDL_test.h"
#include <stdio.h>
#include <stdlib.h>
@ -33,12 +34,22 @@ int main(int argc, char *argv[])
{
SDL_DisplayMode mode;
int num_displays, dpy;
SDLTest_CommonState *state;
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return 1;
}
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
@ -88,7 +99,7 @@ int main(int argc, char *argv[])
SDL_Log("\n");
}
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -16,6 +16,7 @@
#include <stdlib.h>
#include "SDL.h"
#include "SDL_test.h"
static int alive = 0;
@ -44,12 +45,22 @@ ThreadFunc(void *data)
int main(int argc, char *argv[])
{
SDL_Thread *thread;
SDLTest_CommonState *state;
state = SDLTest_CommonCreateState(argv, 0);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(0) < 0) {
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return 1;
}
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
@ -76,6 +87,6 @@ int main(int argc, char *argv[])
SDL_Log("Main thread error string: %s\n", SDL_GetError());
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -13,17 +13,29 @@
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
int main(int argc, char *argv[])
{
char *base_path;
char *pref_path;
SDLTest_CommonState *state;
state = SDLTest_CommonCreateState(argv, 0);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(0) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return 1;
}
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
@ -54,6 +66,6 @@ int main(int argc, char *argv[])
SDL_free(pref_path);
}
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -17,16 +17,35 @@
*/
#include "SDL.h"
#include "SDL_test.h"
int main(int argc, char *argv[])
{
SDLTest_CommonState *state;
Uint64 start;
(void)argc;
(void)argv;
SDL_Init(0);
char *path;
state = SDLTest_CommonCreateState(argv, 0);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return 1;
}
start = SDL_GetTicks();
SDL_GetPrefPath("libsdl", "test_filesystem");
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
path = SDL_GetPrefPath("libsdl", "test_filesystem");
SDL_free(path);
SDL_Log("SDL_GetPrefPath took %" SDL_PRIu64 "ms", SDL_GetTicks() - start);
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -18,14 +18,31 @@
#include <string.h>
#include "SDL.h"
#include "SDL_test.h"
int main(int argc, char *argv[])
{
SDLTest_CommonState *state;
SDL_Scancode scancode;
state = SDLTest_CommonCreateState(argv, 0);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return 1;
}
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
@ -34,6 +51,6 @@ int main(int argc, char *argv[])
SDL_Log("Scancode #%d, \"%s\"\n", scancode,
SDL_GetScancodeName(scancode));
}
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -11,6 +11,7 @@
*/
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
/* !!! FIXME: move this to the test framework */
@ -35,32 +36,64 @@ static void log_locales(void)
int main(int argc, char **argv)
{
SDLTest_CommonState *state;
SDL_bool listen = SDL_FALSE;
int i = 1;
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Print locales and languages */
if (SDL_Init(SDL_INIT_VIDEO) != -1) {
log_locales();
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
if ((argc == 2) && (SDL_strcmp(argv[1], "--listen") == 0)) {
SDL_bool keep_going = SDL_TRUE;
while (keep_going) {
SDL_Event e;
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) {
keep_going = SDL_FALSE;
} else if (e.type == SDL_LOCALECHANGED) {
SDL_Log("Saw SDL_LOCALECHANGED event!");
log_locales();
}
}
SDL_Delay(10);
consumed = SDLTest_CommonArg(state, i);
if (!consumed) {
if (SDL_strcmp("--listen", argv[i]) == 0) {
listen = SDL_TRUE;
consumed = 1;
}
}
if (consumed <= 0) {
static const char *options[] = { "[--listen]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
exit(1);
}
SDL_Quit();
i += consumed;
}
if (!SDLTest_CommonInit(state)) {
return 1;
}
/* Print locales and languages */
log_locales();
if (listen) {
SDL_bool keep_going = SDL_TRUE;
while (keep_going) {
SDL_Event e;
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) {
keep_going = SDL_FALSE;
} else if (e.type == SDL_LOCALECHANGED) {
SDL_Log("Saw SDL_LOCALECHANGED event!");
log_locales();
}
}
SDL_Delay(10);
}
}
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -13,6 +13,7 @@
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
/*
* Watcom C flags these as Warning 201: "Unreachable code" if you just
@ -445,13 +446,42 @@ int main(int argc, char *argv[])
{
SDL_bool verbose = SDL_TRUE;
int status = 0;
int i;
SDLTest_CommonState *state;
state = SDLTest_CommonCreateState(argv, 0);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (argv[1] && (SDL_strcmp(argv[1], "-q") == 0)) {
verbose = SDL_FALSE;
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (!consumed) {
if (SDL_strcmp("-q", argv[i]) == 0) {
verbose = SDL_FALSE;
consumed = 1;
}
}
if (consumed <= 0) {
static const char *options[] = { "[-q]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
exit(1);
}
i += consumed;
}
if (!SDLTest_CommonInit(state)) {
return 1;
}
if (verbose) {
SDL_Log("This system is running %s\n", SDL_GetPlatform());
}
@ -462,5 +492,6 @@ int main(int argc, char *argv[])
status += TestCPUInfo(verbose);
status += TestAssertions(verbose);
SDLTest_CommonQuit(state);
return status;
}

View File

@ -13,6 +13,7 @@
#include <stdio.h>
#include "SDL.h"
#include "SDL_test.h"
static void
report_power(void)
@ -60,17 +61,29 @@ report_power(void)
int main(int argc, char *argv[])
{
SDLTest_CommonState *state;
state = SDLTest_CommonCreateState(argv, 0);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(0) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError());
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return 1;
}
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
report_power();
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -43,36 +43,73 @@ test_sort(const char *desc, int *nums, const int arraylen)
int main(int argc, char *argv[])
{
SDLTest_CommonState *state;
static int nums[1024 * 100];
static const int itervals[] = { SDL_arraysize(nums), 12 };
int iteration;
int i;
SDL_bool custom_seed = SDL_FALSE;
Uint64 seed;
SDLTest_RandomContext rndctx;
if (argc > 1) {
int success;
Uint64 seed = 0;
if (argv[1][0] == '0' && argv[1][1] == 'x') {
success = SDL_sscanf(argv[1] + 2, "%" SDL_PRIx64, &seed);
} else {
success = SDL_sscanf(argv[1], "%" SDL_PRIu64, &seed);
state = SDLTest_CommonCreateState(argv, 0);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (!consumed) {
if (!custom_seed) {
int success;
if (argv[i][0] == '0' && argv[i][1] == 'x') {
success = SDL_sscanf(argv[i] + 2, "%" SDL_PRIx64, &seed);
} else {
success = SDL_sscanf(argv[i], "%" SDL_PRIu64, &seed);
}
if (!success) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid seed. Use a decimal or hexadecimal number.\n");
return 1;
}
if (seed <= ((Uint64)0xffffffff)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Seed must be equal or greater than 0x100000000.\n");
return 1;
}
custom_seed = SDL_TRUE;
consumed = 1;
}
}
if (!success) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid seed. Use a decimal or hexadecimal number.\n");
return 1;
}
if (seed <= ((Uint64)0xffffffff)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Seed must be equal or greater than 0x100000000.\n");
return 1;
if (consumed <= 0) {
static const char *options[] = { "[SEED]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
exit(1);
}
i += consumed;
}
if (custom_seed) {
SDLTest_RandomInit(&rndctx, (unsigned int)(seed >> 32), (unsigned int)(seed & 0xffffffff));
} else {
SDLTest_RandomInitTime(&rndctx);
}
SDL_Log("Using random seed 0x%08x%08x\n", rndctx.x, rndctx.c);
if (!SDLTest_CommonInit(state)) {
return 1;
}
for (iteration = 0; iteration < SDL_arraysize(itervals); iteration++) {
const int arraylen = itervals[iteration];
int i;
for (i = 0; i < arraylen; i++) {
nums[i] = i;
@ -96,6 +133,8 @@ int main(int argc, char *argv[])
test_sort("random sorted", nums, arraylen);
}
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -14,6 +14,7 @@
#include "SDL_config.h"
#include "SDL.h"
#include "SDL_test.h"
static int total_channels;
static int active_channel;
@ -141,11 +142,22 @@ fill_buffer(void *unused, Uint8 *stream, int len)
int main(int argc, char *argv[])
{
int i;
SDLTest_CommonState *state;
state = SDLTest_CommonCreateState(argv, SDL_INIT_AUDIO);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return 1;
}
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
@ -204,7 +216,7 @@ int main(int argc, char *argv[])
SDL_CloseAudioDevice(dev);
}
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}

View File

@ -17,15 +17,18 @@
#include <signal.h>
#include "SDL.h"
#include "SDL_test.h"
static SDL_TLSID tls;
static int alive = 0;
static int testprio = 0;
static SDLTest_CommonState *state;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
SDLTest_CommonQuit(state);
SDL_Quit();
exit(rc);
}
@ -82,14 +85,39 @@ killed(int sig)
int main(int argc, char *argv[])
{
int arg = 1;
int i = 1;
SDL_Thread *thread;
state = SDLTest_CommonCreateState(argv, 0);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(0) < 0) {
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (!consumed) {
if (SDL_strcmp("--prio", argv[i]) == 0) {
testprio = 1;
consumed = 1;
}
}
if (consumed <= 0) {
static const char *options[] = { "[--prio]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
exit(1);
}
i += consumed;
}
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
@ -100,13 +128,6 @@ int main(int argc, char *argv[])
return 0;
}
while (argv[arg] && *argv[arg] == '-') {
if (SDL_strcmp(argv[arg], "--prio") == 0) {
testprio = 1;
}
++arg;
}
tls = SDL_TLSCreate();
SDL_assert(tls);
SDL_TLSSet(tls, "main thread", NULL);
@ -134,6 +155,6 @@ int main(int argc, char *argv[])
}
(void)raise(SIGTERM);
SDL_Quit(); /* Never reached */
SDLTest_CommonQuit(state); /* Never reached */
return 0; /* Never reached */
}

View File

@ -78,16 +78,24 @@ int main(int argc, char *argv[])
Uint64 start, now;
SDL_bool run_interactive_tests = SDL_FALSE;
int return_code = 0;
SDLTest_CommonState *state;
state = SDLTest_CommonCreateState(argv, SDL_INIT_TIMER);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Parse commandline */
for (i = 1; i < argc;) {
int consumed = 0;
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (!consumed) {
if (SDL_strcmp(argv[i], "--interactive") == 0) {
if (SDL_strcmp("--interactive", argv[i]) == 0) {
run_interactive_tests = SDL_TRUE;
consumed = 1;
} else if (desired < 0) {
@ -100,14 +108,15 @@ int main(int argc, char *argv[])
}
}
if (consumed <= 0) {
SDL_Log("Usage: %s [--interactive] [interval]", argv[0]);
return 1;
static const char *options[] = { "[--interactive]", "[interval]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
exit(1);
}
i += consumed;
}
if (SDL_Init(SDL_INIT_TIMER) < 0) {
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
@ -203,7 +212,7 @@ int main(int argc, char *argv[])
if (run_interactive_tests) {
return_code |= test_sdl_delay_within_bounds();
}
SDL_Quit();
SDLTest_CommonQuit(state);
return return_code;
}

View File

@ -19,15 +19,32 @@
#include "SDL.h"
#include "SDL_revision.h"
#include "SDL_test.h"
int main(int argc, char *argv[])
{
SDL_version compiled;
SDL_version linked;
SDLTest_CommonState *state;
state = SDLTest_CommonCreateState(argv, 0);
if (!state) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
return 1;
}
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
return 1;
}
if (!SDLTest_CommonInit(state)) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_Log("Compiled with SDL 2.0 or newer\n");
#else
@ -41,6 +58,7 @@ int main(int argc, char *argv[])
SDL_Log("Linked version: %d.%d.%d (%s)\n",
linked.major, linked.minor, linked.patch,
SDL_GetRevision());
SDL_Quit();
SDLTest_CommonQuit(state);
return 0;
}