mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-14 07:38:24 +02:00
committed by
Sam Lantinga
parent
e29c0661cc
commit
d0bbfdbfb8
@@ -52,7 +52,7 @@ void SDLTest_Assert(int assertCondition, SDL_PRINTF_FORMAT_STRING const char *as
|
||||
/* Print assert description into a buffer */
|
||||
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
|
||||
va_start(list, assertDescription);
|
||||
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
|
||||
(void)SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
|
||||
va_end(list);
|
||||
|
||||
/* Log, then assert and break on failure */
|
||||
@@ -70,7 +70,7 @@ int SDLTest_AssertCheck(int assertCondition, SDL_PRINTF_FORMAT_STRING const char
|
||||
/* Print assert description into a buffer */
|
||||
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
|
||||
va_start(list, assertDescription);
|
||||
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
|
||||
(void)SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
|
||||
va_end(list);
|
||||
|
||||
/* Log pass or fail message */
|
||||
@@ -96,7 +96,7 @@ void SDLTest_AssertPass(SDL_PRINTF_FORMAT_STRING const char *assertDescription,
|
||||
/* Print assert description into a buffer */
|
||||
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
|
||||
va_start(list, assertDescription);
|
||||
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
|
||||
(void)SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, assertDescription, list);
|
||||
va_end(list);
|
||||
|
||||
/* Log pass message */
|
||||
|
||||
@@ -54,7 +54,7 @@ static void SDL_snprintfcat(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL
|
||||
va_start(ap, fmt);
|
||||
text += length;
|
||||
maxlen -= length;
|
||||
SDL_vsnprintf(text, maxlen, fmt, ap);
|
||||
(void)SDL_vsnprintf(text, maxlen, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
@@ -957,28 +957,28 @@ static void SDLTest_PrintRenderer(SDL_RendererInfo *info)
|
||||
|
||||
SDL_Log(" Renderer %s:\n", info->name);
|
||||
|
||||
SDL_snprintf(text, sizeof(text), " Flags: 0x%8.8" SDL_PRIX32, info->flags);
|
||||
SDL_snprintfcat(text, sizeof(text), " (");
|
||||
(void)SDL_snprintf(text, sizeof text, " Flags: 0x%8.8" SDL_PRIX32, info->flags);
|
||||
SDL_snprintfcat(text, sizeof text, " (");
|
||||
count = 0;
|
||||
for (i = 0; i < sizeof(info->flags) * 8; ++i) {
|
||||
for (i = 0; i < 8 * sizeof info->flags; ++i) {
|
||||
Uint32 flag = (1 << i);
|
||||
if (info->flags & flag) {
|
||||
if (count > 0) {
|
||||
SDL_snprintfcat(text, sizeof(text), " | ");
|
||||
SDL_snprintfcat(text, sizeof text, " | ");
|
||||
}
|
||||
SDLTest_PrintRendererFlag(text, sizeof(text), flag);
|
||||
SDLTest_PrintRendererFlag(text, sizeof text, flag);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
SDL_snprintfcat(text, sizeof(text), ")");
|
||||
SDL_snprintfcat(text, sizeof text, ")");
|
||||
SDL_Log("%s\n", text);
|
||||
|
||||
SDL_snprintf(text, sizeof(text), " Texture formats (%" SDL_PRIu32 "): ", info->num_texture_formats);
|
||||
(void)SDL_snprintf(text, sizeof text, " Texture formats (%" SDL_PRIu32 "): ", info->num_texture_formats);
|
||||
for (i = 0; i < (int)info->num_texture_formats; ++i) {
|
||||
if (i > 0) {
|
||||
SDL_snprintfcat(text, sizeof(text), ", ");
|
||||
SDL_snprintfcat(text, sizeof text, ", ");
|
||||
}
|
||||
SDLTest_PrintPixelFormat(text, sizeof(text), info->texture_formats[i]);
|
||||
SDLTest_PrintPixelFormat(text, sizeof text, info->texture_formats[i]);
|
||||
}
|
||||
SDL_Log("%s\n", text);
|
||||
|
||||
@@ -1065,12 +1065,12 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
|
||||
if (n == 0) {
|
||||
SDL_Log("No built-in video drivers\n");
|
||||
} else {
|
||||
SDL_snprintf(text, sizeof(text), "Built-in video drivers:");
|
||||
(void)SDL_snprintf(text, sizeof text, "Built-in video drivers:");
|
||||
for (i = 0; i < n; ++i) {
|
||||
if (i > 0) {
|
||||
SDL_snprintfcat(text, sizeof(text), ",");
|
||||
SDL_snprintfcat(text, sizeof text, ",");
|
||||
}
|
||||
SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetVideoDriver(i));
|
||||
SDL_snprintfcat(text, sizeof text, " %s", SDL_GetVideoDriver(i));
|
||||
}
|
||||
SDL_Log("%s\n", text);
|
||||
}
|
||||
@@ -1262,8 +1262,8 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
|
||||
}
|
||||
|
||||
if (state->num_windows > 1) {
|
||||
SDL_snprintf(title, SDL_arraysize(title), "%s %d",
|
||||
state->window_title, i + 1);
|
||||
(void)SDL_snprintf(title, SDL_arraysize(title), "%s %d",
|
||||
state->window_title, i + 1);
|
||||
} else {
|
||||
SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
|
||||
}
|
||||
@@ -1360,12 +1360,12 @@ SDLTest_CommonInit(SDLTest_CommonState *state)
|
||||
if (n == 0) {
|
||||
SDL_Log("No built-in audio drivers\n");
|
||||
} else {
|
||||
SDL_snprintf(text, sizeof(text), "Built-in audio drivers:");
|
||||
(void)SDL_snprintf(text, sizeof text, "Built-in audio drivers:");
|
||||
for (i = 0; i < n; ++i) {
|
||||
if (i > 0) {
|
||||
SDL_snprintfcat(text, sizeof(text), ",");
|
||||
SDL_snprintfcat(text, sizeof text, ",");
|
||||
}
|
||||
SDL_snprintfcat(text, sizeof(text), " %s", SDL_GetAudioDriver(i));
|
||||
SDL_snprintfcat(text, sizeof text, " %s", SDL_GetAudioDriver(i));
|
||||
}
|
||||
SDL_Log("%s\n", text);
|
||||
}
|
||||
@@ -2161,8 +2161,8 @@ void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done
|
||||
char message[256];
|
||||
SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
|
||||
|
||||
SDL_snprintf(message, sizeof(message), "(%" SDL_PRIs32 ", %" SDL_PRIs32 "), rel (%" SDL_PRIs32 ", %" SDL_PRIs32 ")\n",
|
||||
lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel);
|
||||
(void)SDL_snprintf(message, sizeof message, "(%" SDL_PRIs32 ", %" SDL_PRIs32 "), rel (%" SDL_PRIs32 ", %" SDL_PRIs32 ")\n",
|
||||
lastEvent.x, lastEvent.y, lastEvent.xrel, lastEvent.yrel);
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Last mouse position", message, window);
|
||||
break;
|
||||
}
|
||||
@@ -2246,7 +2246,7 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
|
||||
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetCurrentVideoDriver: %s", SDL_GetCurrentVideoDriver());
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetCurrentVideoDriver: %s", SDL_GetCurrentVideoDriver());
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
@@ -2259,31 +2259,31 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
|
||||
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
|
||||
|
||||
if (0 == SDL_GetRendererInfo(renderer, &info)) {
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetRendererInfo: name: %s", info.name);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetRendererInfo: name: %s", info.name);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
}
|
||||
|
||||
if (0 == SDL_GetRendererOutputSize(renderer, &w, &h)) {
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetRendererOutputSize: %dx%d", w, h);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetRendererOutputSize: %dx%d", w, h);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
}
|
||||
|
||||
SDL_RenderGetViewport(renderer, &rect);
|
||||
SDL_snprintf(text, sizeof(text), "SDL_RenderGetViewport: %d,%d, %dx%d",
|
||||
rect.x, rect.y, rect.w, rect.h);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_RenderGetViewport: %d,%d, %dx%d",
|
||||
rect.x, rect.y, rect.w, rect.h);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
SDL_RenderGetScale(renderer, &scaleX, &scaleY);
|
||||
SDL_snprintf(text, sizeof(text), "SDL_RenderGetScale: %f,%f",
|
||||
scaleX, scaleY);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_RenderGetScale: %f,%f",
|
||||
scaleX, scaleY);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
SDL_RenderGetLogicalSize(renderer, &w, &h);
|
||||
SDL_snprintf(text, sizeof(text), "SDL_RenderGetLogicalSize: %dx%d", w, h);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_RenderGetLogicalSize: %dx%d", w, h);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
@@ -2296,23 +2296,23 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
|
||||
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
|
||||
|
||||
SDL_GetWindowPosition(window, &x, &y);
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetWindowPosition: %d,%d", x, y);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowPosition: %d,%d", x, y);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetWindowSize: %dx%d", w, h);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowSize: %dx%d", w, h);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetWindowFlags: ");
|
||||
SDLTest_PrintWindowFlags(text, sizeof(text), SDL_GetWindowFlags(window));
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowFlags: ");
|
||||
SDLTest_PrintWindowFlags(text, sizeof text, SDL_GetWindowFlags(window));
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
if (0 == SDL_GetWindowDisplayMode(window, &mode)) {
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetWindowDisplayMode: %dx%d@%dHz (%s)",
|
||||
mode.w, mode.h, mode.refresh_rate, SDL_GetPixelFormatName(mode.format));
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowDisplayMode: %dx%d@%dHz (%s)",
|
||||
mode.w, mode.h, mode.refresh_rate, SDL_GetPixelFormatName(mode.format));
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
}
|
||||
@@ -2325,44 +2325,44 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
|
||||
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetWindowDisplayIndex: %d", windowDisplayIndex);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetWindowDisplayIndex: %d", windowDisplayIndex);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetDisplayName: %s", SDL_GetDisplayName(windowDisplayIndex));
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayName: %s", SDL_GetDisplayName(windowDisplayIndex));
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
if (0 == SDL_GetDisplayBounds(windowDisplayIndex, &rect)) {
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetDisplayBounds: %d,%d, %dx%d",
|
||||
rect.x, rect.y, rect.w, rect.h);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayBounds: %d,%d, %dx%d",
|
||||
rect.x, rect.y, rect.w, rect.h);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
}
|
||||
|
||||
if (0 == SDL_GetCurrentDisplayMode(windowDisplayIndex, &mode)) {
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetCurrentDisplayMode: %dx%d@%d",
|
||||
mode.w, mode.h, mode.refresh_rate);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetCurrentDisplayMode: %dx%d@%d",
|
||||
mode.w, mode.h, mode.refresh_rate);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
}
|
||||
|
||||
if (0 == SDL_GetDesktopDisplayMode(windowDisplayIndex, &mode)) {
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetDesktopDisplayMode: %dx%d@%d",
|
||||
mode.w, mode.h, mode.refresh_rate);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetDesktopDisplayMode: %dx%d@%d",
|
||||
mode.w, mode.h, mode.refresh_rate);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
}
|
||||
|
||||
if (0 == SDL_GetDisplayDPI(windowDisplayIndex, &ddpi, &hdpi, &vdpi)) {
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetDisplayDPI: ddpi: %f, hdpi: %f, vdpi: %f",
|
||||
ddpi, hdpi, vdpi);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayDPI: ddpi: %f, hdpi: %f, vdpi: %f",
|
||||
ddpi, hdpi, vdpi);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
}
|
||||
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetDisplayOrientation: ");
|
||||
SDLTest_PrintDisplayOrientation(text, sizeof(text), SDL_GetDisplayOrientation(windowDisplayIndex));
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetDisplayOrientation: ");
|
||||
SDLTest_PrintDisplayOrientation(text, sizeof text, SDL_GetDisplayOrientation(windowDisplayIndex));
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
@@ -2375,14 +2375,14 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, in
|
||||
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
|
||||
|
||||
flags = SDL_GetMouseState(&x, &y);
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetMouseState: %d,%d ", x, y);
|
||||
SDLTest_PrintButtonMask(text, sizeof(text), flags);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetMouseState: %d,%d ", x, y);
|
||||
SDLTest_PrintButtonMask(text, sizeof text, flags);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
flags = SDL_GetGlobalMouseState(&x, &y);
|
||||
SDL_snprintf(text, sizeof(text), "SDL_GetGlobalMouseState: %d,%d ", x, y);
|
||||
SDLTest_PrintButtonMask(text, sizeof(text), flags);
|
||||
(void)SDL_snprintf(text, sizeof text, "SDL_GetGlobalMouseState: %d,%d ", x, y);
|
||||
SDLTest_PrintButtonMask(text, sizeof text, flags);
|
||||
SDLTest_DrawString(renderer, 0, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
#include "SDL_test.h"
|
||||
|
||||
#define FILENAME_SIZE 128
|
||||
|
||||
/* Counter for _CompareSurface calls; used for filename creation when comparisons fail */
|
||||
static int _CompareSurfaceCount = 0;
|
||||
|
||||
@@ -45,8 +47,8 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface,
|
||||
int sampleErrorX = 0, sampleErrorY = 0, sampleDist = 0;
|
||||
Uint8 R, G, B, A;
|
||||
Uint8 Rd, Gd, Bd, Ad;
|
||||
char imageFilename[128];
|
||||
char referenceFilename[128];
|
||||
char imageFilename[FILENAME_SIZE];
|
||||
char referenceFilename[FILENAME_SIZE];
|
||||
|
||||
/* Validate input surfaces */
|
||||
if (surface == NULL || referenceSurface == NULL) {
|
||||
@@ -103,9 +105,9 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface,
|
||||
if (ret != 0) {
|
||||
SDLTest_LogError("Comparison of pixels with allowable error of %i failed %i times.", allowable_error, ret);
|
||||
SDLTest_LogError("First detected occurrence at position %i,%i with a squared RGB-difference of %i.", sampleErrorX, sampleErrorY, sampleDist);
|
||||
SDL_snprintf(imageFilename, 127, "CompareSurfaces%04d_TestOutput.bmp", _CompareSurfaceCount);
|
||||
(void)SDL_snprintf(imageFilename, FILENAME_SIZE - 1, "CompareSurfaces%04d_TestOutput.bmp", _CompareSurfaceCount);
|
||||
SDL_SaveBMP(surface, imageFilename);
|
||||
SDL_snprintf(referenceFilename, 127, "CompareSurfaces%04d_Reference.bmp", _CompareSurfaceCount);
|
||||
(void)SDL_snprintf(referenceFilename, FILENAME_SIZE - 1, "CompareSurfaces%04d_Reference.bmp", _CompareSurfaceCount);
|
||||
SDL_SaveBMP(referenceSurface, referenceFilename);
|
||||
SDLTest_LogError("Surfaces from failed comparison saved as '%s' and '%s'", imageFilename, referenceFilename);
|
||||
}
|
||||
|
||||
@@ -3393,7 +3393,7 @@ void SDLTest_TextWindowAddText(SDLTest_TextWindow *textwin, const char *fmt, ...
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
SDL_vsnprintf(text, sizeof(text), fmt, ap);
|
||||
(void)SDL_vsnprintf(text, sizeof text, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
SDLTest_TextWindowAddTextWithLength(textwin, text, SDL_strlen(text));
|
||||
|
||||
@@ -130,8 +130,8 @@ static Uint64 SDLTest_GenerateExecKey(const char *runSeed, const char *suiteName
|
||||
}
|
||||
|
||||
/* Convert iteration number into a string */
|
||||
SDL_memset(iterationString, 0, sizeof(iterationString));
|
||||
SDL_snprintf(iterationString, sizeof(iterationString) - 1, "%d", iteration);
|
||||
SDL_memset(iterationString, 0, sizeof iterationString);
|
||||
(void)SDL_snprintf(iterationString, sizeof iterationString - 1, "%d", iteration);
|
||||
|
||||
/* Combine the parameters into single string */
|
||||
runSeedLength = SDL_strlen(runSeed);
|
||||
@@ -145,7 +145,7 @@ static Uint64 SDLTest_GenerateExecKey(const char *runSeed, const char *suiteName
|
||||
SDL_Error(SDL_ENOMEM);
|
||||
return 0;
|
||||
}
|
||||
SDL_snprintf(buffer, entireStringLength, "%s%s%s%d", runSeed, suiteName, testName, iteration);
|
||||
(void)SDL_snprintf(buffer, entireStringLength, "%s%s%s%d", runSeed, suiteName, testName, iteration);
|
||||
|
||||
/* Hash string and use half of the digest as 64bit exec key */
|
||||
SDLTest_Md5Init(&md5Context);
|
||||
|
||||
@@ -65,16 +65,21 @@ strftime_gcc2_workaround(char *s, size_t max, const char *fmt, const struct tm *
|
||||
*
|
||||
* \return Ascii representation of the timestamp in localtime in the format '08/23/01 14:55:02'
|
||||
*/
|
||||
static char *SDLTest_TimestampToString(const time_t timestamp)
|
||||
static const char *
|
||||
SDLTest_TimestampToString(const time_t timestamp)
|
||||
{
|
||||
time_t copy;
|
||||
static char buffer[64];
|
||||
struct tm *local;
|
||||
size_t result = 0;
|
||||
|
||||
SDL_memset(buffer, 0, sizeof(buffer));
|
||||
copy = timestamp;
|
||||
local = localtime(©);
|
||||
strftime(buffer, sizeof(buffer), "%x %X", local);
|
||||
result = strftime(buffer, sizeof buffer, "%x %X", local);
|
||||
if (result == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
@@ -90,7 +95,7 @@ void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
|
||||
/* Print log message into a buffer */
|
||||
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
|
||||
va_start(list, fmt);
|
||||
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
|
||||
(void)SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
|
||||
va_end(list);
|
||||
|
||||
/* Log with timestamp and newline */
|
||||
@@ -108,7 +113,7 @@ void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
|
||||
/* Print log message into a buffer */
|
||||
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
|
||||
va_start(list, fmt);
|
||||
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
|
||||
(void)SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
|
||||
va_end(list);
|
||||
|
||||
/* Log with timestamp and newline */
|
||||
|
||||
@@ -242,30 +242,30 @@ void SDLTest_LogAllocations()
|
||||
message = tmp; \
|
||||
SDL_strlcat(message, line, message_size)
|
||||
|
||||
SDL_strlcpy(line, "Memory allocations:\n", sizeof(line));
|
||||
SDL_strlcpy(line, "Memory allocations:\n", sizeof line);
|
||||
ADD_LINE();
|
||||
SDL_strlcpy(line, "Expect 2 allocations from within SDL_GetErrBuf()\n", sizeof(line));
|
||||
SDL_strlcpy(line, "Expect 2 allocations from within SDL_GetErrBuf()\n", sizeof line);
|
||||
ADD_LINE();
|
||||
|
||||
count = 0;
|
||||
total_allocated = 0;
|
||||
for (index = 0; index < SDL_arraysize(s_tracked_allocations); ++index) {
|
||||
for (entry = s_tracked_allocations[index]; entry; entry = entry->next) {
|
||||
SDL_snprintf(line, sizeof(line), "Allocation %d: %d bytes\n", count, (int)entry->size);
|
||||
(void)SDL_snprintf(line, sizeof line, "Allocation %d: %d bytes\n", count, (int)entry->size);
|
||||
ADD_LINE();
|
||||
/* Start at stack index 1 to skip our tracking functions */
|
||||
for (stack_index = 1; stack_index < SDL_arraysize(entry->stack); ++stack_index) {
|
||||
if (!entry->stack[stack_index]) {
|
||||
break;
|
||||
}
|
||||
SDL_snprintf(line, sizeof(line), "\t0x%" SDL_PRIx64 ": %s\n", entry->stack[stack_index], entry->stack_names[stack_index]);
|
||||
(void)SDL_snprintf(line, sizeof line, "\t0x%" SDL_PRIx64 ": %s\n", entry->stack[stack_index], entry->stack_names[stack_index]);
|
||||
ADD_LINE();
|
||||
}
|
||||
total_allocated += entry->size;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
SDL_snprintf(line, sizeof(line), "Total: %.2f Kb in %d allocations\n", (float)total_allocated / 1024, count);
|
||||
(void)SDL_snprintf(line, sizeof line, "Total: %.2f Kb in %d allocations\n", total_allocated / 1024.0, count);
|
||||
ADD_LINE();
|
||||
#undef ADD_LINE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user