test: unify all the command line usage logging.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
diff --git a/include/SDL_test_common.h b/include/SDL_test_common.h
index feb70ac..c34d0d1 100644
--- a/include/SDL_test_common.h
+++ b/include/SDL_test_common.h
@@ -140,14 +140,20 @@ SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, Uint32 flags);
*/
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.
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index f7e94ab..95e6f6e 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -26,11 +26,22 @@
#include <stdio.h>
-#define 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]"
-
-#define AUDIO_USAGE \
-"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
+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]"
+};
+
+static const char *audio_usage[] = {
+ "[--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, ... )
{
@@ -474,18 +485,30 @@ SDLTest_CommonArg(SDLTest_CommonState * state, int index)
return 0;
}
-const char *
-SDLTest_CommonUsage(SDLTest_CommonState * state)
+void
+SDLTest_CommonLogUsage(SDLTest_CommonState * state, const char *argv0, const char **options)
{
- switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
- case SDL_INIT_VIDEO:
- return "[--trackmem] " VIDEO_USAGE;
- case SDL_INIT_AUDIO:
- return "[--trackmem] " AUDIO_USAGE;
- case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
- return "[--trackmem] " VIDEO_USAGE " " AUDIO_USAGE;
- default:
- return "[--trackmem]";
+ int i;
+
+ SDL_Log("USAGE: %s", argv0);
+ SDL_Log(" %s", "[--trackmem]");
+
+ if (state->flags & SDL_INIT_VIDEO) {
+ for (i = 0; i < SDL_arraysize(video_usage); i++) {
+ SDL_Log(" %s", video_usage[i]);
+ }
+ }
+
+ 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) {
const int consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) {
- SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
+ SDLTest_CommonLogUsage(state, argv[0], NULL);
return SDL_FALSE;
}
i += consumed;
diff --git a/test/testautomation.c b/test/testautomation.c
index d761325..1a0ecbd 100644
--- a/test/testautomation.c
+++ b/test/testautomation.c
@@ -80,8 +80,8 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
- SDL_Log("Usage: %s %s [--iterations #] [--execKey #] [--seed string] [--filter suite_name|test_name]\n",
- argv[0], SDLTest_CommonUsage(state));
+ static const char *options[] = { "[--iterations #]", "[--execKey #]", "[--seed string]", "[--filter suite_name|test_name]", NULL };
+ SDLTest_CommonLogUsage(state, argv[0], options);
quit(1);
}
diff --git a/test/testcustomcursor.c b/test/testcustomcursor.c
index ba0d6b2..b0b7fa7 100644
--- a/test/testcustomcursor.c
+++ b/test/testcustomcursor.c
@@ -203,7 +203,7 @@ main(int argc, char *argv[])
break;
}
if (consumed < 0) {
- SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
+ SDLTest_CommonLogUsage(state, argv[0], NULL);
quit(1);
}
i += consumed;
diff --git a/test/testdraw2.c b/test/testdraw2.c
index 0df6642..77a0f11 100644
--- a/test/testdraw2.c
+++ b/test/testdraw2.c
@@ -256,8 +256,8 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
- SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
- argv[0], SDLTest_CommonUsage(state));
+ static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", NULL };
+ SDLTest_CommonLogUsage(state, argv[0], options);
return 1;
}
i += consumed;
diff --git a/test/testdropfile.c b/test/testdropfile.c
index 778f10c..c0cc7a5 100644
--- a/test/testdropfile.c
+++ b/test/testdropfile.c
@@ -52,7 +52,7 @@ main(int argc, char *argv[])
consumed = -1;
}
if (consumed < 0) {
- SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
+ SDLTest_CommonLogUsage(state, argv[0], NULL);
quit(1);
}
i += consumed;
diff --git a/test/testgl2.c b/test/testgl2.c
index fdffa7c..a8bc181 100644
--- a/test/testgl2.c
+++ b/test/testgl2.c
@@ -248,8 +248,8 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
- SDL_Log("Usage: %s %s [--fsaa n] [--accel n]\n", argv[0],
- SDLTest_CommonUsage(state));
+ static const char *options[] = { "[--fsaa n]", "[--accel n]", NULL };
+ SDLTest_CommonLogUsage(state, argv[0], options);
quit(1);
}
i += consumed;
diff --git a/test/testgles.c b/test/testgles.c
index 4c69a28..c4ea45f 100644
--- a/test/testgles.c
+++ b/test/testgles.c
@@ -146,8 +146,8 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
- SDL_Log("Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
- SDLTest_CommonUsage(state));
+ static const char *options[] = { "[--fsaa]", "[--accel]", "[--zdepth %d]", NULL };
+ SDLTest_CommonLogUsage(state, argv[0], options);
quit(1);
}
i += consumed;
diff --git a/test/testgles2.c b/test/testgles2.c
index b4484bc..641a897 100644
--- a/test/testgles2.c
+++ b/test/testgles2.c
@@ -518,8 +518,8 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
- SDL_Log ("Usage: %s %s [--fsaa] [--accel] [--zdepth %%d]\n", argv[0],
- SDLTest_CommonUsage(state));
+ static const char *options[] = { "[--fsaa]", "[--accel]", "[--zdepth %d]", NULL };
+ SDLTest_CommonLogUsage(state, argv[0], options);
quit(1);
}
i += consumed;
diff --git a/test/testintersections.c b/test/testintersections.c
index 0382bb7..0c824cb 100644
--- a/test/testintersections.c
+++ b/test/testintersections.c
@@ -315,8 +315,8 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
- SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha]\n",
- argv[0], SDLTest_CommonUsage(state));
+ static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", NULL };
+ SDLTest_CommonLogUsage(state, argv[0], options);
return 1;
}
i += consumed;
diff --git a/test/testrendertarget.c b/test/testrendertarget.c
index 21e3d67..bc50007 100644
--- a/test/testrendertarget.c
+++ b/test/testrendertarget.c
@@ -275,8 +275,8 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
- SDL_Log("Usage: %s %s [--composite]\n",
- argv[0], SDLTest_CommonUsage(state));
+ static const char *options[] = { "[--composite]", NULL };
+ SDLTest_CommonLogUsage(state, argv[0], options);
quit(1);
}
i += consumed;
diff --git a/test/testsprite2.c b/test/testsprite2.c
index f6db6bb..76ac7eb 100644
--- a/test/testsprite2.c
+++ b/test/testsprite2.c
@@ -340,8 +340,8 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
- SDL_Log("Usage: %s %s [--blend none|blend|add|mod] [--cyclecolor] [--cyclealpha] [--iterations N] [num_sprites] [icon.bmp]\n",
- argv[0], SDLTest_CommonUsage(state));
+ static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", "[--iterations N]", "[num_sprites]", "[icon.bmp]", NULL };
+ SDLTest_CommonLogUsage(state, argv[0], options);
quit(1);
}
i += consumed;
diff --git a/test/testviewport.c b/test/testviewport.c
index 2468b3a..2706ab2 100644
--- a/test/testviewport.c
+++ b/test/testviewport.c
@@ -161,8 +161,8 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
- SDL_Log("Usage: %s %s [--target]\n",
- argv[0], SDLTest_CommonUsage(state));
+ static const char *options[] = { "[--target]", NULL };
+ SDLTest_CommonLogUsage(state, argv[0], options);
quit(1);
}
i += consumed;
diff --git a/visualtest/unittest/testquit.c b/visualtest/unittest/testquit.c
index 4393700..6cf4536 100644
--- a/visualtest/unittest/testquit.c
+++ b/visualtest/unittest/testquit.c
@@ -64,7 +64,8 @@ main(int argc, char** argv)
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);
return 1;
}