mirror of https://github.com/libsdl-org/SDL.git
Add more SDL_Process tests
This commit is contained in:
parent
f6055432c8
commit
7241dd9ec3
|
|
@ -368,13 +368,6 @@ add_sdl_test_executable(testmouse SOURCES testmouse.c)
|
|||
add_sdl_test_executable(testoverlay NEEDS_RESOURCES TESTUTILS SOURCES testoverlay.c)
|
||||
add_sdl_test_executable(testplatform NONINTERACTIVE SOURCES testplatform.c)
|
||||
add_sdl_test_executable(testpower NONINTERACTIVE SOURCES testpower.c)
|
||||
add_sdl_test_executable(testprocess
|
||||
NONINTERACTIVE THREADS
|
||||
NONINTERACTIVE_ARGS $<TARGET_FILE:childprocess>
|
||||
INSTALLED_ARGS "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL3/childprocess${CMAKE_EXECUTABLE_SUFFIX}"
|
||||
SOURCES testprocess.c)
|
||||
add_sdl_test_executable(childprocess SOURCES childprocess.c)
|
||||
add_dependencies(testprocess childprocess)
|
||||
add_sdl_test_executable(testfilesystem NONINTERACTIVE SOURCES testfilesystem.c)
|
||||
if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
add_sdl_test_executable(pretest SOURCES pretest.c NONINTERACTIVE NONINTERACTIVE_TIMEOUT 60)
|
||||
|
|
@ -414,6 +407,16 @@ add_sdl_test_executable(testtime SOURCES testtime.c)
|
|||
add_sdl_test_executable(testmanymouse SOURCES testmanymouse.c)
|
||||
add_sdl_test_executable(testmodal SOURCES testmodal.c)
|
||||
|
||||
|
||||
add_sdl_test_executable(testprocess
|
||||
NONINTERACTIVE THREADS
|
||||
NONINTERACTIVE_ARGS $<TARGET_FILE:childprocess>
|
||||
INSTALLED_ARGS "${CMAKE_INSTALL_FULL_LIBEXECDIR}/installed-tests/SDL3/childprocess${CMAKE_EXECUTABLE_SUFFIX}"
|
||||
SOURCES testprocess.c
|
||||
)
|
||||
add_sdl_test_executable(childprocess SOURCES childprocess.c)
|
||||
add_dependencies(testprocess childprocess)
|
||||
|
||||
if (HAVE_WAYLAND)
|
||||
# Set the GENERATED property on the protocol file, since it is first created at build time
|
||||
set_property(SOURCE ${SDL3_BINARY_DIR}/wayland-generated-protocols/xdg-shell-protocol.c PROPERTY GENERATED 1)
|
||||
|
|
|
|||
|
|
@ -5,15 +5,20 @@
|
|||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef SDL_PLATFORM_WINDOWS
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
SDLTest_CommonState *state;
|
||||
int i;
|
||||
const char *expect_environment = NULL;
|
||||
bool expect_environment_match = false;
|
||||
bool print_arguments = false;
|
||||
bool print_environment = false;
|
||||
bool stdin_to_stdout = false;
|
||||
bool read_stdin = false;
|
||||
bool stdin_to_stderr = false;
|
||||
int exit_code = 0;
|
||||
|
||||
|
|
@ -21,50 +26,62 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed = SDLTest_CommonArg(state, i);
|
||||
if (SDL_strcmp(argv[i], "--print-arguments") == 0) {
|
||||
print_arguments = true;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcmp(argv[i], "--print-environment") == 0) {
|
||||
print_environment = true;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcmp(argv[i], "--expect-env") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
expect_environment = argv[i + 1];
|
||||
consumed = 2;
|
||||
}
|
||||
} else if (SDL_strcmp(argv[i], "--stdin-to-stdout") == 0) {
|
||||
stdin_to_stdout = true;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcmp(argv[i], "--stdin-to-stderr") == 0) {
|
||||
stdin_to_stderr = true;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcmp(argv[i], "--stdout") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
fprintf(stdout, "%s", argv[i + 1]);
|
||||
consumed = 2;
|
||||
}
|
||||
} else if (SDL_strcmp(argv[i], "--stderr") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
fprintf(stderr, "%s", argv[i + 1]);
|
||||
consumed = 2;
|
||||
}
|
||||
} else if (SDL_strcmp(argv[i], "--exit-code") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
char *endptr = NULL;
|
||||
exit_code = SDL_strtol(argv[i + 1], &endptr, 0);
|
||||
if (endptr && *endptr == '\0') {
|
||||
if (!consumed) {
|
||||
if (SDL_strcmp(argv[i], "--print-arguments") == 0) {
|
||||
print_arguments = true;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcmp(argv[i], "--print-environment") == 0) {
|
||||
print_environment = true;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcmp(argv[i], "--stdin-to-stdout") == 0) {
|
||||
stdin_to_stdout = true;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcmp(argv[i], "--stdin-to-stderr") == 0) {
|
||||
stdin_to_stderr = true;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcmp(argv[i], "--stdin") == 0) {
|
||||
read_stdin = true;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcmp(argv[i], "--stdout") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
fprintf(stdout, "%s", argv[i + 1]);
|
||||
consumed = 2;
|
||||
}
|
||||
} else if (SDL_strcmp(argv[i], "--stderr") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
fprintf(stderr, "%s", argv[i + 1]);
|
||||
consumed = 2;
|
||||
}
|
||||
} else if (SDL_strcmp(argv[i], "--exit-code") == 0) {
|
||||
if (i + 1 < argc) {
|
||||
char *endptr = NULL;
|
||||
exit_code = SDL_strtol(argv[i + 1], &endptr, 0);
|
||||
if (endptr && *endptr == '\0') {
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
} else if (SDL_strcmp(argv[i], "--version") == 0) {
|
||||
int version = SDL_GetVersion();
|
||||
fprintf(stdout, "SDL version %d.%d.%d",
|
||||
SDL_VERSIONNUM_MAJOR(version),
|
||||
SDL_VERSIONNUM_MINOR(version),
|
||||
SDL_VERSIONNUM_MICRO(version));
|
||||
fprintf(stderr, "SDL version %d.%d.%d",
|
||||
SDL_VERSIONNUM_MAJOR(version),
|
||||
SDL_VERSIONNUM_MINOR(version),
|
||||
SDL_VERSIONNUM_MICRO(version));
|
||||
consumed = 1;
|
||||
break;
|
||||
} else if (SDL_strcmp(argv[i], "--") == 0) {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
} else if (SDL_strcmp(argv[i], "--") == 0) {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
if (consumed <= 0) {
|
||||
const char *args[] = {
|
||||
"[--print-arguments]",
|
||||
"[--print-environment]",
|
||||
"[--expect-env KEY=VAL]",
|
||||
"[--stdin]",
|
||||
"[--stdin-to-stdout]",
|
||||
"[--stdout TEXT]",
|
||||
"[--stdin-to-stderr]",
|
||||
|
|
@ -86,48 +103,52 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
if (print_environment || expect_environment) {
|
||||
if (print_environment) {
|
||||
char **env = SDL_GetEnvironmentVariables(SDL_GetEnvironment());
|
||||
if (env) {
|
||||
for (i = 0; env[i]; ++i) {
|
||||
if (print_environment) {
|
||||
fprintf(stdout, "%s\n", env[i]);
|
||||
}
|
||||
if (expect_environment) {
|
||||
expect_environment_match |= SDL_strcmp(env[i], expect_environment) == 0;
|
||||
}
|
||||
fprintf(stdout, "%s\n", env[i]);
|
||||
}
|
||||
SDL_free(env);
|
||||
}
|
||||
}
|
||||
|
||||
if (stdin_to_stdout || stdin_to_stderr) {
|
||||
#ifdef SDL_PLATFORM_WINDOWS
|
||||
{
|
||||
DWORD mode;
|
||||
HANDLE stdout_handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
GetConsoleMode(stdout_handle, &mode);
|
||||
SetConsoleMode(stdout_handle, mode & ~(ENABLE_LINE_INPUT));
|
||||
}
|
||||
#else
|
||||
fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) & ~(O_NONBLOCK));
|
||||
#endif
|
||||
|
||||
if (stdin_to_stdout || stdin_to_stderr || read_stdin) {
|
||||
for (;;) {
|
||||
int c;
|
||||
c = fgetc(stdin);
|
||||
if (c == EOF) {
|
||||
char buffer[4 * 4096];
|
||||
size_t result;
|
||||
|
||||
result = fread(buffer, 1, sizeof(buffer), stdin);
|
||||
if (result == 0) {
|
||||
if (errno == EAGAIN) {
|
||||
clearerr(stdin);
|
||||
SDL_Delay(10);
|
||||
SDL_Delay(20);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (stdin_to_stdout) {
|
||||
fputc(c, stdout);
|
||||
fwrite(buffer, 1, result, stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
if (stdin_to_stderr) {
|
||||
fputc(c, stderr);
|
||||
fwrite(buffer, 1, result, stderr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDLTest_CommonDestroyState(state);
|
||||
|
||||
if (expect_environment && !expect_environment_match) {
|
||||
exit_code |= 0x1;
|
||||
}
|
||||
return exit_code;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue