2
Simple DirectMedia Layer
3
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
5
This software is provided 'as-is', without any express or implied
6
warranty. In no event will the authors be held liable for any damages
7
arising from the use of this software.
9
Permission is granted to anyone to use this software for any purpose,
10
including commercial applications, and to alter it and redistribute it
11
freely, subject to the following restrictions:
13
1. The origin of this software must not be misrepresented; you must not
14
claim that you wrote the original software. If you use this software
15
in a product, an acknowledgment in the product documentation would be
16
appreciated but is not required.
17
2. Altered source versions must be plainly marked as such, and must not be
18
misrepresented as being the original software.
19
3. This notice may not be removed or altered from any source distribution.
24
Used by the test framework and test cases.
28
/* quiet windows compiler warnings */
29
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
30
#define _CRT_SECURE_NO_WARNINGS
32
#include <SDL3/SDL_test.h>
34
#include <time.h> /* Needed for localtime() */
36
/* work around compiler warning on older GCCs. */
37
#if (defined(__GNUC__) && (__GNUC__ <= 2))
38
static size_t strftime_gcc2_workaround(char *s, size_t max, const char *fmt, const struct tm *tm)
40
return strftime(s, max, fmt, tm);
45
#define strftime strftime_gcc2_workaround
49
* Converts unix timestamp to its ascii representation in localtime
51
* Note: Uses a static buffer internally, so the return value
52
* isn't valid after the next call of this function. If you
53
* want to retain the return value, make a copy of it.
55
* \param timestamp A Timestamp, i.e. time(0)
57
* \return Ascii representation of the timestamp in localtime in the format '08/23/01 14:55:02'
59
static const char *SDLTest_TimestampToString(const time_t timestamp)
62
static char buffer[64];
66
SDL_memset(buffer, 0, sizeof(buffer));
68
local = localtime(©);
69
result = strftime(buffer, sizeof(buffer), "%x %X", local);
78
* Prints given message with a timestamp in the TEST category and INFO priority.
80
void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
83
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
85
/* Print log message into a buffer */
86
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
88
(void)SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
91
/* Log with timestamp and newline */
92
SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_INFO, " %s: %s", SDLTest_TimestampToString(time(0)), logMessage);
96
* Prints given message with a timestamp in the TEST category and the ERROR priority.
98
void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
101
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
103
/* Print log message into a buffer */
104
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
106
(void)SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
109
/* Log with timestamp and newline */
110
SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR, "%s: %s", SDLTest_TimestampToString(time(0)), logMessage);