test: added SDLTest_CommonDefaultArgs() This is for test apps that don't need custom command line arguments; it lets us reduce the boilerplate code a tiny bit.
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
diff --git a/include/SDL_test_common.h b/include/SDL_test_common.h
index c6f4cfb..feb70ac 100644
--- a/include/SDL_test_common.h
+++ b/include/SDL_test_common.h
@@ -159,6 +159,17 @@ const char *SDLTest_CommonUsage(SDLTest_CommonState * state);
SDL_bool SDLTest_CommonInit(SDLTest_CommonState * state);
/**
+ * \brief Easy argument handling when test app doesn't need any custom args.
+ *
+ * \param state The common state describing the test window to create.
+ * \param argc argc, as supplied to SDL_main
+ * \param argv argv, as supplied to SDL_main
+ *
+ * \returns False if app should quit, true otherwise.
+ */
+SDL_bool SDLTest_CommonDefaultArgs(SDLTest_CommonState * state, const int argc, char **argv);
+
+/**
* \brief Common event handler for test windows.
*
* \param state The common state used to create test window.
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 4c275b7..f7e94ab 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -489,6 +489,21 @@ SDLTest_CommonUsage(SDLTest_CommonState * state)
}
}
+SDL_bool
+SDLTest_CommonDefaultArgs(SDLTest_CommonState *state, const int argc, char **argv)
+{
+ int i = 1;
+ while (i < argc) {
+ const int consumed = SDLTest_CommonArg(state, i);
+ if (consumed == 0) {
+ SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
+ return SDL_FALSE;
+ }
+ i += consumed;
+ }
+ return SDL_TRUE;
+}
+
static void
SDLTest_PrintRendererFlag(char *text, size_t maxlen, Uint32 flag)
{
diff --git a/test/testgesture.c b/test/testgesture.c
index 90e7212..a41604a 100644
--- a/test/testgesture.c
+++ b/test/testgesture.c
@@ -268,9 +268,6 @@ loop(void)
int main(int argc, char* argv[])
{
- int i;
-
- /* !!! FIXME: there should be an SDLTest_CommonDefaultArgs() so apps don't need this. */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
return 1;
@@ -281,16 +278,8 @@ int main(int argc, char* argv[])
state->window_h = HEIGHT;
state->skip_renderer = SDL_TRUE;
- for (i = 1; i < argc;) {
- const int consumed = SDLTest_CommonArg(state, i);
- if (consumed == 0) {
- SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
- return 1;
- }
- i += consumed;
- }
-
- if (!SDLTest_CommonInit(state)) {
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv) || !SDLTest_CommonInit(state)) {
+ SDLTest_CommonQuit(state);
return 1;
}
diff --git a/test/testrendercopyex.c b/test/testrendercopyex.c
index 8dd67ce..fc01b65 100644
--- a/test/testrendercopyex.c
+++ b/test/testrendercopyex.c
@@ -174,18 +174,10 @@ main(int argc, char *argv[])
if (!state) {
return 1;
}
- for (i = 1; i < argc;) {
- int consumed;
- consumed = SDLTest_CommonArg(state, i);
- if (consumed == 0) {
- SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
- return 1;
- }
- i += consumed;
- }
- if (!SDLTest_CommonInit(state)) {
- quit(2);
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv) || !SDLTest_CommonInit(state)) {
+ SDLTest_CommonQuit(state);
+ return 1;
}
drawstates = SDL_stack_alloc(DrawState, state->num_windows);
diff --git a/test/testscale.c b/test/testscale.c
index a243641..3639277 100644
--- a/test/testscale.c
+++ b/test/testscale.c
@@ -164,18 +164,10 @@ main(int argc, char *argv[])
if (!state) {
return 1;
}
- for (i = 1; i < argc;) {
- int consumed;
- consumed = SDLTest_CommonArg(state, i);
- if (consumed == 0) {
- SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
- return 1;
- }
- i += consumed;
- }
- if (!SDLTest_CommonInit(state)) {
- quit(2);
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv) || !SDLTest_CommonInit(state)) {
+ SDLTest_CommonQuit(state);
+ return 1;
}
drawstates = SDL_stack_alloc(DrawState, state->num_windows);
diff --git a/test/testvulkan.c b/test/testvulkan.c
index 6514e68..a0c1113 100644
--- a/test/testvulkan.c
+++ b/test/testvulkan.c
@@ -1119,7 +1119,7 @@ static SDL_bool render(void)
int main(int argc, char *argv[])
{
int fsaa, accel;
- int i, done;
+ int done;
SDL_DisplayMode mode;
SDL_Event event;
Uint32 then, now, frames;
@@ -1138,27 +1138,15 @@ int main(int argc, char *argv[])
{
return 1;
}
- for(i = 1; i < argc;)
- {
- int consumed;
-
- consumed = SDLTest_CommonArg(state, i);
- if(consumed < 0)
- {
- SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
- quit(1);
- }
- i += consumed;
- }
/* Set Vulkan parameters */
state->window_flags |= SDL_WINDOW_VULKAN;
state->num_windows = 1;
state->skip_renderer = 1;
- if(!SDLTest_CommonInit(state))
- {
- quit(2);
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv) || !SDLTest_CommonInit(state)) {
+ SDLTest_CommonQuit(state);
+ return 1;
}
SDL_GetCurrentDisplayMode(0, &mode);
diff --git a/test/testwm2.c b/test/testwm2.c
index 2064aa6..9ec867b 100644
--- a/test/testwm2.c
+++ b/test/testwm2.c
@@ -129,21 +129,10 @@ main(int argc, char *argv[])
if (!state) {
return 1;
}
- for (i = 1; i < argc;) {
- int consumed;
- consumed = SDLTest_CommonArg(state, i);
- if (consumed == 0) {
- consumed = -1;
- }
- if (consumed < 0) {
- SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
- quit(1);
- }
- i += consumed;
- }
- if (!SDLTest_CommonInit(state)) {
- quit(2);
+ if (!SDLTest_CommonDefaultArgs(state, argc, argv) || !SDLTest_CommonInit(state)) {
+ SDLTest_CommonQuit(state);
+ return 1;
}
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);