test: unify all the command line usage logging.

Ryan C. Gordon 2019-05-28 17:39:13 -04:00
parent 9b5811592d
commit b5d3b6fc25
14 changed files with 71 additions and 41 deletions

View File

@ -140,14 +140,20 @@ SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, Uint32 flags);
*/ */
int SDLTest_CommonArg(SDLTest_CommonState * state, int index); int SDLTest_CommonArg(SDLTest_CommonState * state, int index);
/** /**
* \brief Returns common usage information * \brief Logs command line usage info.
* *
* \param state The common state describing the test window to create. * This logs the appropriate command line options for the subsystems in use
* plus other common options, and then any application-specific options.
* This uses the SDL_Log() function and splits up output to be friendly to
* 80-character-wide terminals.
* *
* \returns String with usage information * \param state The common state describing the test window for the app.
* \param argv0 argv[0], as passed to main/SDL_main.
* \param options an array of strings for application specific options. The last element of the array should be NULL.
*/ */
const char *SDLTest_CommonUsage(SDLTest_CommonState * state); void SDLTest_CommonLogUsage(SDLTest_CommonState * state, const char *argv0, const char **options);
/** /**
* \brief Open test window. * \brief Open test window.

View File

@ -26,11 +26,22 @@
#include <stdio.h> #include <stdio.h>
#define VIDEO_USAGE \ static const char *video_usage[] = {
"[--video driver] [--renderer driver] [--gldebug] [--info all|video|modes|render|event] [--log all|error|system|audio|video|render|input] [--display N] [--fullscreen | --fullscreen-desktop | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--min-geometry WxH] [--max-geometry WxH] [--logical WxH] [--scale N] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--allow-highdpi]" "[--video driver]", "[--renderer driver]", "[--gldebug]",
"[--info all|video|modes|render|event]",
"[--log all|error|system|audio|video|render|input]", "[--display N]",
"[--fullscreen | --fullscreen-desktop | --windows N]", "[--title title]",
"[--icon icon.bmp]", "[--center | --position X,Y]", "[--geometry WxH]",
"[--min-geometry WxH]", "[--max-geometry WxH]", "[--logical WxH]",
"[--scale N]", "[--depth N]", "[--refresh R]", "[--vsync]", "[--noframe]",
"[--resize]", "[--minimize]", "[--maximize]", "[--grab]",
"[--allow-highdpi]"
};
#define AUDIO_USAGE \ static const char *audio_usage[] = {
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]" "[--rate N]", "[--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE]",
"[--channels N]", "[--samples N]"
};
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, ... )
{ {
@ -474,18 +485,30 @@ SDLTest_CommonArg(SDLTest_CommonState * state, int index)
return 0; return 0;
} }
const char * void
SDLTest_CommonUsage(SDLTest_CommonState * state) SDLTest_CommonLogUsage(SDLTest_CommonState * state, const char *argv0, const char **options)
{ {
switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { int i;
case SDL_INIT_VIDEO:
return "[--trackmem] " VIDEO_USAGE; SDL_Log("USAGE: %s", argv0);
case SDL_INIT_AUDIO: SDL_Log(" %s", "[--trackmem]");
return "[--trackmem] " AUDIO_USAGE;
case (SDL_INIT_VIDEO | SDL_INIT_AUDIO): if (state->flags & SDL_INIT_VIDEO) {
return "[--trackmem] " VIDEO_USAGE " " AUDIO_USAGE; for (i = 0; i < SDL_arraysize(video_usage); i++) {
default: SDL_Log(" %s", video_usage[i]);
return "[--trackmem]"; }
}
if (state->flags & SDL_INIT_AUDIO) {
for (i = 0; i < SDL_arraysize(audio_usage); i++) {
SDL_Log(" %s", audio_usage[i]);
}
}
if (options) {
for (i = 0; options[i] != NULL; i++) {
SDL_Log(" %s", options[i]);
}
} }
} }
@ -496,7 +519,7 @@ SDLTest_CommonDefaultArgs(SDLTest_CommonState *state, const int argc, char **arg
while (i < argc) { while (i < argc) {
const int consumed = SDLTest_CommonArg(state, i); const int consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) { if (consumed == 0) {
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); SDLTest_CommonLogUsage(state, argv[0], NULL);
return SDL_FALSE; return SDL_FALSE;
} }
i += consumed; i += consumed;

View File

@ -80,8 +80,8 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
SDL_Log("Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n", static const char *options[] = { "[--iterations #]", "[--execKey #]", "[--seed string]", "[--filter suite_name|test_name]", NULL };
argv[0], SDLTest_CommonUsage(state)); SDLTest_CommonLogUsage(state, argv[0], options);
quit(1); quit(1);
} }

View File

@ -203,7 +203,7 @@ main(int argc, char *argv[])
break; break;
} }
if (consumed < 0) { if (consumed < 0) {
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); SDLTest_CommonLogUsage(state, argv[0], NULL);
quit(1); quit(1);
} }
i += consumed; i += consumed;

View File

@ -256,8 +256,8 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n", static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", NULL };
argv[0], SDLTest_CommonUsage(state)); SDLTest_CommonLogUsage(state, argv[0], options);
return 1; return 1;
} }
i += consumed; i += consumed;

View File

@ -52,7 +52,7 @@ main(int argc, char *argv[])
consumed = -1; consumed = -1;
} }
if (consumed < 0) { if (consumed < 0) {
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state)); SDLTest_CommonLogUsage(state, argv[0], NULL);
quit(1); quit(1);
} }
i += consumed; i += consumed;

View File

@ -248,8 +248,8 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
SDL_Log("Usage: %s %s [--fsaa n] [--accel n]\n", argv[0], static const char *options[] = { "[--fsaa n]", "[--accel n]", NULL };
SDLTest_CommonUsage(state)); SDLTest_CommonLogUsage(state, argv[0], options);
quit(1); quit(1);
} }
i += consumed; i += consumed;

View File

@ -146,8 +146,8 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
SDL_Log("Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0], static const char *options[] = { "[--fsaa]", "[--accel]", "[--zdepth %d]", NULL };
SDLTest_CommonUsage(state)); SDLTest_CommonLogUsage(state, argv[0], options);
quit(1); quit(1);
} }
i += consumed; i += consumed;

View File

@ -518,8 +518,8 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
SDL_Log ("Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0], static const char *options[] = { "[--fsaa]", "[--accel]", "[--zdepth %d]", NULL };
SDLTest_CommonUsage(state)); SDLTest_CommonLogUsage(state, argv[0], options);
quit(1); quit(1);
} }
i += consumed; i += consumed;

View File

@ -315,8 +315,8 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n", static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", NULL };
argv[0], SDLTest_CommonUsage(state)); SDLTest_CommonLogUsage(state, argv[0], options);
return 1; return 1;
} }
i += consumed; i += consumed;

View File

@ -275,8 +275,8 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
SDL_Log("Usage: %s %s [--composite]\n", static const char *options[] = { "[--composite]", NULL };
argv[0], SDLTest_CommonUsage(state)); SDLTest_CommonLogUsage(state, argv[0], options);
quit(1); quit(1);
} }
i += consumed; i += consumed;

View File

@ -340,8 +340,8 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n", static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", "[--iterations N]", "[num_sprites]", "[icon.bmp]", NULL };
argv[0], SDLTest_CommonUsage(state)); SDLTest_CommonLogUsage(state, argv[0], options);
quit(1); quit(1);
} }
i += consumed; i += consumed;

View File

@ -161,8 +161,8 @@ main(int argc, char *argv[])
} }
} }
if (consumed < 0) { if (consumed < 0) {
SDL_Log("Usage: %s %s [--target]\n", static const char *options[] = { "[--target]", NULL };
argv[0], SDLTest_CommonUsage(state)); SDLTest_CommonLogUsage(state, argv[0], options);
quit(1); quit(1);
} }
i += consumed; i += consumed;

View File

@ -64,7 +64,8 @@ main(int argc, char** argv)
if(consumed < 0) if(consumed < 0)
{ {
SDLTest_Log("Usage: %s %s [--exit-code N] [--crash] [--hang]", argv[0], SDLTest_CommonUsage(state)); static const char *options = { "[--exit-code N]", "[--crash]", "[--hang]", NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
SDLTest_CommonQuit(state); SDLTest_CommonQuit(state);
return 1; return 1;
} }