test: unify all the command line usage logging.
1.1 --- a/include/SDL_test_common.h Sun May 26 18:53:36 2019 -0300
1.2 +++ b/include/SDL_test_common.h Tue May 28 17:39:13 2019 -0400
1.3 @@ -140,14 +140,20 @@
1.4 */
1.5 int SDLTest_CommonArg(SDLTest_CommonState * state, int index);
1.6
1.7 +
1.8 /**
1.9 - * \brief Returns common usage information
1.10 + * \brief Logs command line usage info.
1.11 *
1.12 - * \param state The common state describing the test window to create.
1.13 + * This logs the appropriate command line options for the subsystems in use
1.14 + * plus other common options, and then any application-specific options.
1.15 + * This uses the SDL_Log() function and splits up output to be friendly to
1.16 + * 80-character-wide terminals.
1.17 *
1.18 - * \returns String with usage information
1.19 + * \param state The common state describing the test window for the app.
1.20 + * \param argv0 argv[0], as passed to main/SDL_main.
1.21 + * \param options an array of strings for application specific options. The last element of the array should be NULL.
1.22 */
1.23 -const char *SDLTest_CommonUsage(SDLTest_CommonState * state);
1.24 +void SDLTest_CommonLogUsage(SDLTest_CommonState * state, const char *argv0, const char **options);
1.25
1.26 /**
1.27 * \brief Open test window.
2.1 --- a/src/test/SDL_test_common.c Sun May 26 18:53:36 2019 -0300
2.2 +++ b/src/test/SDL_test_common.c Tue May 28 17:39:13 2019 -0400
2.3 @@ -26,11 +26,22 @@
2.4
2.5 #include <stdio.h>
2.6
2.7 -#define VIDEO_USAGE \
2.8 -"[--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]"
2.9 +static const char *video_usage[] = {
2.10 + "[--video driver]", "[--renderer driver]", "[--gldebug]",
2.11 + "[--info all|video|modes|render|event]",
2.12 + "[--log all|error|system|audio|video|render|input]", "[--display N]",
2.13 + "[--fullscreen | --fullscreen-desktop | --windows N]", "[--title title]",
2.14 + "[--icon icon.bmp]", "[--center | --position X,Y]", "[--geometry WxH]",
2.15 + "[--min-geometry WxH]", "[--max-geometry WxH]", "[--logical WxH]",
2.16 + "[--scale N]", "[--depth N]", "[--refresh R]", "[--vsync]", "[--noframe]",
2.17 + "[--resize]", "[--minimize]", "[--maximize]", "[--grab]",
2.18 + "[--allow-highdpi]"
2.19 +};
2.20
2.21 -#define AUDIO_USAGE \
2.22 -"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
2.23 +static const char *audio_usage[] = {
2.24 + "[--rate N]", "[--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE]",
2.25 + "[--channels N]", "[--samples N]"
2.26 +};
2.27
2.28 static void SDL_snprintfcat(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ... )
2.29 {
2.30 @@ -474,18 +485,30 @@
2.31 return 0;
2.32 }
2.33
2.34 -const char *
2.35 -SDLTest_CommonUsage(SDLTest_CommonState * state)
2.36 +void
2.37 +SDLTest_CommonLogUsage(SDLTest_CommonState * state, const char *argv0, const char **options)
2.38 {
2.39 - switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
2.40 - case SDL_INIT_VIDEO:
2.41 - return "[--trackmem] " VIDEO_USAGE;
2.42 - case SDL_INIT_AUDIO:
2.43 - return "[--trackmem] " AUDIO_USAGE;
2.44 - case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
2.45 - return "[--trackmem] " VIDEO_USAGE " " AUDIO_USAGE;
2.46 - default:
2.47 - return "[--trackmem]";
2.48 + int i;
2.49 +
2.50 + SDL_Log("USAGE: %s", argv0);
2.51 + SDL_Log(" %s", "[--trackmem]");
2.52 +
2.53 + if (state->flags & SDL_INIT_VIDEO) {
2.54 + for (i = 0; i < SDL_arraysize(video_usage); i++) {
2.55 + SDL_Log(" %s", video_usage[i]);
2.56 + }
2.57 + }
2.58 +
2.59 + if (state->flags & SDL_INIT_AUDIO) {
2.60 + for (i = 0; i < SDL_arraysize(audio_usage); i++) {
2.61 + SDL_Log(" %s", audio_usage[i]);
2.62 + }
2.63 + }
2.64 +
2.65 + if (options) {
2.66 + for (i = 0; options[i] != NULL; i++) {
2.67 + SDL_Log(" %s", options[i]);
2.68 + }
2.69 }
2.70 }
2.71
2.72 @@ -496,7 +519,7 @@
2.73 while (i < argc) {
2.74 const int consumed = SDLTest_CommonArg(state, i);
2.75 if (consumed == 0) {
2.76 - SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
2.77 + SDLTest_CommonLogUsage(state, argv[0], NULL);
2.78 return SDL_FALSE;
2.79 }
2.80 i += consumed;
3.1 --- a/test/testautomation.c Sun May 26 18:53:36 2019 -0300
3.2 +++ b/test/testautomation.c Tue May 28 17:39:13 2019 -0400
3.3 @@ -80,8 +80,8 @@
3.4 }
3.5 }
3.6 if (consumed < 0) {
3.7 - SDL_Log("Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n",
3.8 - argv[0], SDLTest_CommonUsage(state));
3.9 + static const char *options[] = { "[--iterations #]", "[--execKey #]", "[--seed string]", "[--filter suite_name|test_name]", NULL };
3.10 + SDLTest_CommonLogUsage(state, argv[0], options);
3.11 quit(1);
3.12 }
3.13
4.1 --- a/test/testcustomcursor.c Sun May 26 18:53:36 2019 -0300
4.2 +++ b/test/testcustomcursor.c Tue May 28 17:39:13 2019 -0400
4.3 @@ -203,7 +203,7 @@
4.4 break;
4.5 }
4.6 if (consumed < 0) {
4.7 - SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
4.8 + SDLTest_CommonLogUsage(state, argv[0], NULL);
4.9 quit(1);
4.10 }
4.11 i += consumed;
5.1 --- a/test/testdraw2.c Sun May 26 18:53:36 2019 -0300
5.2 +++ b/test/testdraw2.c Tue May 28 17:39:13 2019 -0400
5.3 @@ -256,8 +256,8 @@
5.4 }
5.5 }
5.6 if (consumed < 0) {
5.7 - SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
5.8 - argv[0], SDLTest_CommonUsage(state));
5.9 + static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", NULL };
5.10 + SDLTest_CommonLogUsage(state, argv[0], options);
5.11 return 1;
5.12 }
5.13 i += consumed;
6.1 --- a/test/testdropfile.c Sun May 26 18:53:36 2019 -0300
6.2 +++ b/test/testdropfile.c Tue May 28 17:39:13 2019 -0400
6.3 @@ -52,7 +52,7 @@
6.4 consumed = -1;
6.5 }
6.6 if (consumed < 0) {
6.7 - SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
6.8 + SDLTest_CommonLogUsage(state, argv[0], NULL);
6.9 quit(1);
6.10 }
6.11 i += consumed;
7.1 --- a/test/testgl2.c Sun May 26 18:53:36 2019 -0300
7.2 +++ b/test/testgl2.c Tue May 28 17:39:13 2019 -0400
7.3 @@ -248,8 +248,8 @@
7.4 }
7.5 }
7.6 if (consumed < 0) {
7.7 - SDL_Log("Usage: %s %s [--fsaa n] [--accel n]\n", argv[0],
7.8 - SDLTest_CommonUsage(state));
7.9 + static const char *options[] = { "[--fsaa n]", "[--accel n]", NULL };
7.10 + SDLTest_CommonLogUsage(state, argv[0], options);
7.11 quit(1);
7.12 }
7.13 i += consumed;
8.1 --- a/test/testgles.c Sun May 26 18:53:36 2019 -0300
8.2 +++ b/test/testgles.c Tue May 28 17:39:13 2019 -0400
8.3 @@ -146,8 +146,8 @@
8.4 }
8.5 }
8.6 if (consumed < 0) {
8.7 - SDL_Log("Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
8.8 - SDLTest_CommonUsage(state));
8.9 + static const char *options[] = { "[--fsaa]", "[--accel]", "[--zdepth %d]", NULL };
8.10 + SDLTest_CommonLogUsage(state, argv[0], options);
8.11 quit(1);
8.12 }
8.13 i += consumed;
9.1 --- a/test/testgles2.c Sun May 26 18:53:36 2019 -0300
9.2 +++ b/test/testgles2.c Tue May 28 17:39:13 2019 -0400
9.3 @@ -518,8 +518,8 @@
9.4 }
9.5 }
9.6 if (consumed < 0) {
9.7 - SDL_Log ("Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
9.8 - SDLTest_CommonUsage(state));
9.9 + static const char *options[] = { "[--fsaa]", "[--accel]", "[--zdepth %d]", NULL };
9.10 + SDLTest_CommonLogUsage(state, argv[0], options);
9.11 quit(1);
9.12 }
9.13 i += consumed;
10.1 --- a/test/testintersections.c Sun May 26 18:53:36 2019 -0300
10.2 +++ b/test/testintersections.c Tue May 28 17:39:13 2019 -0400
10.3 @@ -315,8 +315,8 @@
10.4 }
10.5 }
10.6 if (consumed < 0) {
10.7 - SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
10.8 - argv[0], SDLTest_CommonUsage(state));
10.9 + static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", NULL };
10.10 + SDLTest_CommonLogUsage(state, argv[0], options);
10.11 return 1;
10.12 }
10.13 i += consumed;
11.1 --- a/test/testrendertarget.c Sun May 26 18:53:36 2019 -0300
11.2 +++ b/test/testrendertarget.c Tue May 28 17:39:13 2019 -0400
11.3 @@ -275,8 +275,8 @@
11.4 }
11.5 }
11.6 if (consumed < 0) {
11.7 - SDL_Log("Usage: %s %s [--composite]\n",
11.8 - argv[0], SDLTest_CommonUsage(state));
11.9 + static const char *options[] = { "[--composite]", NULL };
11.10 + SDLTest_CommonLogUsage(state, argv[0], options);
11.11 quit(1);
11.12 }
11.13 i += consumed;
12.1 --- a/test/testsprite2.c Sun May 26 18:53:36 2019 -0300
12.2 +++ b/test/testsprite2.c Tue May 28 17:39:13 2019 -0400
12.3 @@ -340,8 +340,8 @@
12.4 }
12.5 }
12.6 if (consumed < 0) {
12.7 - SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n",
12.8 - argv[0], SDLTest_CommonUsage(state));
12.9 + static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", "[--iterations N]", "[num_sprites]", "[icon.bmp]", NULL };
12.10 + SDLTest_CommonLogUsage(state, argv[0], options);
12.11 quit(1);
12.12 }
12.13 i += consumed;
13.1 --- a/test/testviewport.c Sun May 26 18:53:36 2019 -0300
13.2 +++ b/test/testviewport.c Tue May 28 17:39:13 2019 -0400
13.3 @@ -161,8 +161,8 @@
13.4 }
13.5 }
13.6 if (consumed < 0) {
13.7 - SDL_Log("Usage: %s %s [--target]\n",
13.8 - argv[0], SDLTest_CommonUsage(state));
13.9 + static const char *options[] = { "[--target]", NULL };
13.10 + SDLTest_CommonLogUsage(state, argv[0], options);
13.11 quit(1);
13.12 }
13.13 i += consumed;
14.1 --- a/visualtest/unittest/testquit.c Sun May 26 18:53:36 2019 -0300
14.2 +++ b/visualtest/unittest/testquit.c Tue May 28 17:39:13 2019 -0400
14.3 @@ -64,7 +64,8 @@
14.4
14.5 if(consumed < 0)
14.6 {
14.7 - SDLTest_Log("Usage: %s %s [--exit-code N] [--crash] [--hang]", argv[0], SDLTest_CommonUsage(state));
14.8 + static const char *options = { "[--exit-code N]", "[--crash]", "[--hang]", NULL };
14.9 + SDLTest_CommonLogUsage(state, argv[0], options);
14.10 SDLTest_CommonQuit(state);
14.11 return 1;
14.12 }