Fixed line breaks in verbose test logging output
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
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 640474f..83ba6cc 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -32,6 +32,18 @@
#define 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, ... )
+{
+ size_t length = SDL_strlen(text);
+ va_list ap;
+
+ va_start(ap, fmt);
+ text += length;
+ maxlen -= length;
+ SDL_vsnprintf(text, maxlen, fmt, ap);
+ va_end(ap);
+}
+
SDLTest_CommonState *
SDLTest_CommonCreateState(char **argv, Uint32 flags)
{
@@ -463,123 +475,123 @@ SDLTest_CommonUsage(SDLTest_CommonState * state)
}
static void
-SDLTest_PrintRendererFlag(Uint32 flag)
+SDLTest_PrintRendererFlag(char *text, size_t maxlen, Uint32 flag)
{
switch (flag) {
case SDL_RENDERER_PRESENTVSYNC:
- SDL_Log("PresentVSync");
+ SDL_snprintfcat(text, maxlen, "PresentVSync");
break;
case SDL_RENDERER_ACCELERATED:
- SDL_Log("Accelerated");
+ SDL_snprintfcat(text, maxlen, "Accelerated");
break;
default:
- SDL_Log("0x%8.8x", flag);
+ SDL_snprintfcat(text, maxlen, "0x%8.8x", flag);
break;
}
}
static void
-SDLTest_PrintPixelFormat(Uint32 format)
+SDLTest_PrintPixelFormat(char *text, size_t maxlen, Uint32 format)
{
switch (format) {
case SDL_PIXELFORMAT_UNKNOWN:
- SDL_Log("Unknown");
+ SDL_snprintfcat(text, maxlen, "Unknown");
break;
case SDL_PIXELFORMAT_INDEX1LSB:
- SDL_Log("Index1LSB");
+ SDL_snprintfcat(text, maxlen, "Index1LSB");
break;
case SDL_PIXELFORMAT_INDEX1MSB:
- SDL_Log("Index1MSB");
+ SDL_snprintfcat(text, maxlen, "Index1MSB");
break;
case SDL_PIXELFORMAT_INDEX4LSB:
- SDL_Log("Index4LSB");
+ SDL_snprintfcat(text, maxlen, "Index4LSB");
break;
case SDL_PIXELFORMAT_INDEX4MSB:
- SDL_Log("Index4MSB");
+ SDL_snprintfcat(text, maxlen, "Index4MSB");
break;
case SDL_PIXELFORMAT_INDEX8:
- SDL_Log("Index8");
+ SDL_snprintfcat(text, maxlen, "Index8");
break;
case SDL_PIXELFORMAT_RGB332:
- SDL_Log("RGB332");
+ SDL_snprintfcat(text, maxlen, "RGB332");
break;
case SDL_PIXELFORMAT_RGB444:
- SDL_Log("RGB444");
+ SDL_snprintfcat(text, maxlen, "RGB444");
break;
case SDL_PIXELFORMAT_RGB555:
- SDL_Log("RGB555");
+ SDL_snprintfcat(text, maxlen, "RGB555");
break;
case SDL_PIXELFORMAT_BGR555:
- SDL_Log("BGR555");
+ SDL_snprintfcat(text, maxlen, "BGR555");
break;
case SDL_PIXELFORMAT_ARGB4444:
- SDL_Log("ARGB4444");
+ SDL_snprintfcat(text, maxlen, "ARGB4444");
break;
case SDL_PIXELFORMAT_ABGR4444:
- SDL_Log("ABGR4444");
+ SDL_snprintfcat(text, maxlen, "ABGR4444");
break;
case SDL_PIXELFORMAT_ARGB1555:
- SDL_Log("ARGB1555");
+ SDL_snprintfcat(text, maxlen, "ARGB1555");
break;
case SDL_PIXELFORMAT_ABGR1555:
- SDL_Log("ABGR1555");
+ SDL_snprintfcat(text, maxlen, "ABGR1555");
break;
case SDL_PIXELFORMAT_RGB565:
- SDL_Log("RGB565");
+ SDL_snprintfcat(text, maxlen, "RGB565");
break;
case SDL_PIXELFORMAT_BGR565:
- SDL_Log("BGR565");
+ SDL_snprintfcat(text, maxlen, "BGR565");
break;
case SDL_PIXELFORMAT_RGB24:
- SDL_Log("RGB24");
+ SDL_snprintfcat(text, maxlen, "RGB24");
break;
case SDL_PIXELFORMAT_BGR24:
- SDL_Log("BGR24");
+ SDL_snprintfcat(text, maxlen, "BGR24");
break;
case SDL_PIXELFORMAT_RGB888:
- SDL_Log("RGB888");
+ SDL_snprintfcat(text, maxlen, "RGB888");
break;
case SDL_PIXELFORMAT_BGR888:
- SDL_Log("BGR888");
+ SDL_snprintfcat(text, maxlen, "BGR888");
break;
case SDL_PIXELFORMAT_ARGB8888:
- SDL_Log("ARGB8888");
+ SDL_snprintfcat(text, maxlen, "ARGB8888");
break;
case SDL_PIXELFORMAT_RGBA8888:
- SDL_Log("RGBA8888");
+ SDL_snprintfcat(text, maxlen, "RGBA8888");
break;
case SDL_PIXELFORMAT_ABGR8888:
- SDL_Log("ABGR8888");
+ SDL_snprintfcat(text, maxlen, "ABGR8888");
break;
case SDL_PIXELFORMAT_BGRA8888:
- SDL_Log("BGRA8888");
+ SDL_snprintfcat(text, maxlen, "BGRA8888");
break;
case SDL_PIXELFORMAT_ARGB2101010:
- SDL_Log("ARGB2101010");
+ SDL_snprintfcat(text, maxlen, "ARGB2101010");
break;
case SDL_PIXELFORMAT_YV12:
- SDL_Log("YV12");
+ SDL_snprintfcat(text, maxlen, "YV12");
break;
case SDL_PIXELFORMAT_IYUV:
- SDL_Log("IYUV");
+ SDL_snprintfcat(text, maxlen, "IYUV");
break;
case SDL_PIXELFORMAT_YUY2:
- SDL_Log("YUY2");
+ SDL_snprintfcat(text, maxlen, "YUY2");
break;
case SDL_PIXELFORMAT_UYVY:
- SDL_Log("UYVY");
+ SDL_snprintfcat(text, maxlen, "UYVY");
break;
case SDL_PIXELFORMAT_YVYU:
- SDL_Log("YVYU");
+ SDL_snprintfcat(text, maxlen, "YVYU");
break;
case SDL_PIXELFORMAT_NV12:
- SDL_Log("NV12");
+ SDL_snprintfcat(text, maxlen, "NV12");
break;
case SDL_PIXELFORMAT_NV21:
- SDL_Log("NV21");
+ SDL_snprintfcat(text, maxlen, "NV21");
break;
default:
- SDL_Log("0x%8.8x", format);
+ SDL_snprintfcat(text, maxlen, "0x%8.8x", format);
break;
}
}
@@ -588,32 +600,34 @@ static void
SDLTest_PrintRenderer(SDL_RendererInfo * info)
{
int i, count;
+ char text[1024];
SDL_Log(" Renderer %s:\n", info->name);
- SDL_Log(" Flags: 0x%8.8X", info->flags);
- SDL_Log(" (");
+ SDL_snprintf(text, sizeof(text), " Flags: 0x%8.8X", info->flags);
+ SDL_snprintfcat(text, sizeof(text), " (");
count = 0;
for (i = 0; i < sizeof(info->flags) * 8; ++i) {
Uint32 flag = (1 << i);
if (info->flags & flag) {
if (count > 0) {
- SDL_Log(" | ");
+ SDL_snprintfcat(text, sizeof(text), " | ");
}
- SDLTest_PrintRendererFlag(flag);
+ SDLTest_PrintRendererFlag(text, sizeof(text), flag);
++count;
}
}
- SDL_Log(")\n");
+ SDL_snprintfcat(text, sizeof(text), ")");
+ SDL_Log("%s\n", text);
- SDL_Log(" Texture formats (%d): ", info->num_texture_formats);
+ SDL_snprintf(text, sizeof(text), " Texture formats (%d): ", info->num_texture_formats);
for (i = 0; i < (int) info->num_texture_formats; ++i) {
if (i > 0) {
- SDL_Log(", ");
+ SDL_snprintfcat(text, sizeof(text), ", ");
}
- SDLTest_PrintPixelFormat(info->texture_formats[i]);
+ SDLTest_PrintPixelFormat(text, sizeof(text), info->texture_formats[i]);
}
- SDL_Log("\n");
+ SDL_Log("%s\n", text);
if (info->max_texture_width || info->max_texture_height) {
SDL_Log(" Max Texture Size: %dx%d\n",
@@ -646,6 +660,7 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
{
int i, j, m, n, w, h;
SDL_DisplayMode fullscreen_mode;
+ char text[1024];
if (state->flags & SDL_INIT_VIDEO) {
if (state->verbose & VERBOSE_VIDEO) {
@@ -653,14 +668,14 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
if (n == 0) {
SDL_Log("No built-in video drivers\n");
} else {
- SDL_Log("Built-in video drivers:");
+ SDL_snprintf(text, sizeof(text), "Built-in video drivers:");
for (i = 0; i < n; ++i) {
if (i > 0) {
- SDL_Log(",");
+ SDL_snprintfcat(text, sizeof(text), ",");
}
- SDL_Log(" %s", SDL_GetVideoDriver(i));
+ SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetVideoDriver(i));
}
- SDL_Log("\n");
+ SDL_Log("%s\n", text);
}
}
if (SDL_VideoInit(state->videodriver) < 0) {
@@ -931,14 +946,14 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
if (n == 0) {
SDL_Log("No built-in audio drivers\n");
} else {
- SDL_Log("Built-in audio drivers:");
+ SDL_snprintf(text, sizeof(text), "Built-in audio drivers:");
for (i = 0; i < n; ++i) {
if (i > 0) {
- SDL_Log(",");
+ SDL_snprintfcat(text, sizeof(text), ",");
}
- SDL_Log(" %s", SDL_GetAudioDriver(i));
+ SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetAudioDriver(i));
}
- SDL_Log("\n");
+ SDL_Log("%s\n", text);
}
}
if (SDL_AudioInit(state->audiodriver) < 0) {