test: Reimplemented SDLTest_CommonUsage() to restore binary compatibility. Fixes Bugzilla #4975.
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
diff --git a/include/SDL_test_common.h b/include/SDL_test_common.h
index 9e0aa8b..3ad2030 100644
--- a/include/SDL_test_common.h
+++ b/include/SDL_test_common.h
@@ -156,6 +156,19 @@ int SDLTest_CommonArg(SDLTest_CommonState * state, int index);
void SDLTest_CommonLogUsage(SDLTest_CommonState * state, const char *argv0, const char **options);
/**
+ * \brief Returns common usage information
+ *
+ * You should (probably) be using SDLTest_CommonLogUsage() instead, but this
+ * function remains for binary compatibility. Strings returned from this
+ * function are valid until SDLTest_CommonQuit() is called, in which case
+ * those strings' memory is freed and can no longer be used.
+ *
+ * \param state The common state describing the test window to create.
+ * \returns String with usage information
+ */
+const char *SDLTest_CommonUsage(SDLTest_CommonState * state);
+
+/**
* \brief Open test window.
*
* \param state The common state describing the test window to create.
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index cf1f9e5..b48c6a5 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -521,6 +521,65 @@ SDLTest_CommonLogUsage(SDLTest_CommonState * state, const char *argv0, const cha
}
}
+static const char *
+BuildCommonUsageString(char **pstr, const char **strlist, const int numitems, const char **strlist2, const int numitems2)
+{
+ char *str = *pstr;
+ if (!str) {
+ size_t len = SDL_strlen("[--trackmem]") + 2;
+ int i;
+ for (i = 0; i < numitems; i++) {
+ len += SDL_strlen(strlist[i]) + 1;
+ }
+ if (strlist2) {
+ for (i = 0; i < numitems2; i++) {
+ len += SDL_strlen(strlist2[i]) + 1;
+ }
+ }
+ str = (char *) SDL_calloc(1, len);
+ if (!str) {
+ return ""; /* oh well. */
+ }
+ SDL_strlcat(str, "[--trackmem] ", len);
+ for (i = 0; i < numitems-1; i++) {
+ SDL_strlcat(str, strlist[i], len);
+ SDL_strlcat(str, " ", len);
+ }
+ SDL_strlcat(str, strlist[i], len);
+ if (strlist2) {
+ SDL_strlcat(str, " ", len);
+ for (i = 0; i < numitems2-1; i++) {
+ SDL_strlcat(str, strlist2[i], len);
+ SDL_strlcat(str, " ", len);
+ }
+ SDL_strlcat(str, strlist2[i], len);
+ }
+ *pstr = str;
+ }
+ return str;
+}
+
+static char *common_usage_video = NULL;
+static char *common_usage_audio = NULL;
+static char *common_usage_videoaudio = NULL;
+
+const char *
+SDLTest_CommonUsage(SDLTest_CommonState * state)
+{
+
+ switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
+ case SDL_INIT_VIDEO:
+ return BuildCommonUsageString(&common_usage_video, video_usage, SDL_arraysize(video_usage), NULL, 0);
+ case SDL_INIT_AUDIO:
+ return BuildCommonUsageString(&common_usage_audio, audio_usage, SDL_arraysize(audio_usage), NULL, 0);
+ case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
+ return BuildCommonUsageString(&common_usage_videoaudio, video_usage, SDL_arraysize(video_usage), audio_usage, SDL_arraysize(audio_usage));
+ default:
+ return "[--trackmem]";
+ }
+}
+
+
SDL_bool
SDLTest_CommonDefaultArgs(SDLTest_CommonState *state, const int argc, char **argv)
{
@@ -1852,6 +1911,13 @@ SDLTest_CommonQuit(SDLTest_CommonState * state)
{
int i;
+ SDL_free(common_usage_video);
+ SDL_free(common_usage_audio);
+ SDL_free(common_usage_videoaudio);
+ common_usage_video = NULL;
+ common_usage_audio = NULL;
+ common_usage_videoaudio = NULL;
+
SDL_free(state->windows);
if (state->targets) {
for (i = 0; i < state->num_windows; ++i) {