Add option "--quit-after-ms N" to automatically quit application after N ms
This commit is contained in:
@@ -153,6 +153,10 @@ typedef struct
|
|||||||
SDL_Rect confine;
|
SDL_Rect confine;
|
||||||
bool hide_cursor;
|
bool hide_cursor;
|
||||||
|
|
||||||
|
/* Misc. */
|
||||||
|
int quit_after_ms_interval;
|
||||||
|
SDL_TimerID quit_after_ms_timer;
|
||||||
|
|
||||||
/* Options info */
|
/* Options info */
|
||||||
SDLTest_ArgumentParser common_argparser;
|
SDLTest_ArgumentParser common_argparser;
|
||||||
SDLTest_ArgumentParser video_argparser;
|
SDLTest_ArgumentParser video_argparser;
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ static const char *video_usage[] = {
|
|||||||
"[--minimize]",
|
"[--minimize]",
|
||||||
"[--mouse-focus]",
|
"[--mouse-focus]",
|
||||||
"[--noframe]",
|
"[--noframe]",
|
||||||
|
"[--quit-after-ms N]",
|
||||||
"[--refresh R]",
|
"[--refresh R]",
|
||||||
"[--renderer driver]",
|
"[--renderer driver]",
|
||||||
"[--resizable]",
|
"[--resizable]",
|
||||||
@@ -86,6 +87,16 @@ static const char *audio_usage[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// tests can quit after N ms
|
||||||
|
static Uint32 SDLCALL quit_after_ms_cb(void *userdata, SDL_TimerID timerID, Uint32 interval)
|
||||||
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
event.type = SDL_EVENT_QUIT;
|
||||||
|
event.common.timestamp = 0;
|
||||||
|
SDL_PushEvent(&event);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void SDL_snprintfcat(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
|
static void SDL_snprintfcat(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
|
||||||
{
|
{
|
||||||
size_t length = SDL_strlen(text);
|
size_t length = SDL_strlen(text);
|
||||||
@@ -509,6 +520,17 @@ static int SDLCALL SDLTest_CommonStateParseVideoArguments(void *data, char **arg
|
|||||||
state->window_flags |= SDL_WINDOW_BORDERLESS;
|
state->window_flags |= SDL_WINDOW_BORDERLESS;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if (SDL_strcasecmp(argv[index], "--quit-after-ms") == 0) {
|
||||||
|
++index;
|
||||||
|
if (!argv[index]) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
state->quit_after_ms_interval = SDL_atoi(argv[index]);
|
||||||
|
if (state->quit_after_ms_interval <= 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
if (SDL_strcasecmp(argv[index], "--resizable") == 0) {
|
if (SDL_strcasecmp(argv[index], "--resizable") == 0) {
|
||||||
state->window_flags |= SDL_WINDOW_RESIZABLE;
|
state->window_flags |= SDL_WINDOW_RESIZABLE;
|
||||||
return 1;
|
return 1;
|
||||||
@@ -1525,6 +1547,11 @@ bool SDLTest_CommonInit(SDLTest_CommonState *state)
|
|||||||
|
|
||||||
SDL_InitSubSystem(state->flags);
|
SDL_InitSubSystem(state->flags);
|
||||||
|
|
||||||
|
|
||||||
|
if (state->quit_after_ms_interval) {
|
||||||
|
state->quit_after_ms_timer = SDL_AddTimer(state->quit_after_ms_interval, quit_after_ms_cb, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2725,6 +2752,10 @@ void SDLTest_CommonQuit(SDLTest_CommonState *state)
|
|||||||
}
|
}
|
||||||
SDL_free(state->windows);
|
SDL_free(state->windows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state->quit_after_ms_timer) {
|
||||||
|
SDL_RemoveTimer(state->quit_after_ms_timer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
SDLTest_CommonDestroyState(state);
|
SDLTest_CommonDestroyState(state);
|
||||||
|
|||||||
Reference in New Issue
Block a user