mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-03-20 15:51:07 +01:00
testprograms: parse arguments using SDLTest_CommonState
This commit is contained in:
committed by
Anonymous Maarten
parent
8bea41f737
commit
4a6528e3f0
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <SDL3/SDL_test.h>
|
||||
|
||||
#define NUM_THREADS 10
|
||||
/* This value should be smaller than the maximum count of the */
|
||||
@@ -35,6 +36,11 @@ typedef struct Thread_State
|
||||
int content_count;
|
||||
} Thread_State;
|
||||
|
||||
static void log_usage(char *progname, SDLTest_CommonState *state) {
|
||||
static const char *options[] = { "init_value", NULL };
|
||||
SDLTest_CommonLogUsage(state, progname, options);
|
||||
}
|
||||
|
||||
static void
|
||||
killed(int sig)
|
||||
{
|
||||
@@ -248,13 +254,43 @@ TestOverheadContended(SDL_bool try_wait)
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int arg_count = 0;
|
||||
int i;
|
||||
int init_sem;
|
||||
SDLTest_CommonState *state;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, 0);
|
||||
if (state == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
if (argc < 2) {
|
||||
SDL_Log("Usage: %s init_value\n", argv[0]);
|
||||
/* Parse commandline */
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (arg_count == 0) {
|
||||
char *endptr;
|
||||
init_sem = SDL_strtol(argv[i], &endptr, 0);
|
||||
if (endptr != argv[i] && *endptr == '\0') {
|
||||
arg_count++;
|
||||
consumed = 1;
|
||||
}
|
||||
}
|
||||
if (consumed <= 0) {
|
||||
log_usage(argv[0], state);
|
||||
return 1;
|
||||
}
|
||||
|
||||
i += consumed;
|
||||
}
|
||||
|
||||
if (arg_count != 1) {
|
||||
log_usage(argv[0], state);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -280,5 +316,7 @@ int main(int argc, char **argv)
|
||||
TestOverheadContended(SDL_TRUE);
|
||||
|
||||
SDL_Quit();
|
||||
SDLTest_CommonDestroyState(state);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user