aschiffler@6717
|
1 |
/*
|
aschiffler@6717
|
2 |
Simple DirectMedia Layer
|
slouken@9998
|
3 |
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
aschiffler@6717
|
4 |
|
aschiffler@6717
|
5 |
This software is provided 'as-is', without any express or implied
|
aschiffler@6717
|
6 |
warranty. In no event will the authors be held liable for any damages
|
aschiffler@6717
|
7 |
arising from the use of this software.
|
aschiffler@6717
|
8 |
|
aschiffler@6717
|
9 |
Permission is granted to anyone to use this software for any purpose,
|
aschiffler@6717
|
10 |
including commercial applications, and to alter it and redistribute it
|
aschiffler@6717
|
11 |
freely, subject to the following restrictions:
|
aschiffler@6717
|
12 |
|
aschiffler@6717
|
13 |
1. The origin of this software must not be misrepresented; you must not
|
aschiffler@6717
|
14 |
claim that you wrote the original software. If you use this software
|
aschiffler@6717
|
15 |
in a product, an acknowledgment in the product documentation would be
|
aschiffler@6717
|
16 |
appreciated but is not required.
|
aschiffler@6717
|
17 |
2. Altered source versions must be plainly marked as such, and must not be
|
aschiffler@6717
|
18 |
misrepresented as being the original software.
|
aschiffler@6717
|
19 |
3. This notice may not be removed or altered from any source distribution.
|
aschiffler@6717
|
20 |
*/
|
aschiffler@6717
|
21 |
|
aschiffler@6717
|
22 |
/*
|
aschiffler@6717
|
23 |
|
slouken@7191
|
24 |
Used by the test framework and test cases.
|
aschiffler@6717
|
25 |
|
aschiffler@6717
|
26 |
*/
|
aschiffler@6717
|
27 |
|
slouken@7191
|
28 |
/* quiet windows compiler warnings */
|
slouken@10616
|
29 |
#if defined(_MSC_VER)
|
slouken@10616
|
30 |
# define _CRT_SECURE_NO_WARNINGS
|
slouken@10616
|
31 |
#endif
|
aschiffler@6718
|
32 |
|
aschiffler@6717
|
33 |
#include "SDL_config.h"
|
aschiffler@6717
|
34 |
|
aschiffler@6717
|
35 |
#include <stdarg.h> /* va_list */
|
aschiffler@6772
|
36 |
#include <stdio.h>
|
aschiffler@6719
|
37 |
#include <string.h>
|
aschiffler@6717
|
38 |
#include <time.h>
|
aschiffler@6717
|
39 |
|
aschiffler@6772
|
40 |
#include "SDL.h"
|
aschiffler@6772
|
41 |
|
aschiffler@6717
|
42 |
#include "SDL_test.h"
|
aschiffler@6717
|
43 |
|
icculus@10643
|
44 |
/* work around compiler warning on older GCCs. */
|
icculus@10643
|
45 |
#if (defined(__GNUC__) && (__GNUC__ <= 2))
|
icculus@10643
|
46 |
static size_t
|
icculus@10643
|
47 |
strftime_gcc2_workaround(char *s, size_t max, const char *fmt, const struct tm *tm)
|
icculus@10643
|
48 |
{
|
icculus@10643
|
49 |
return strftime(s, max, fmt, tm);
|
icculus@10643
|
50 |
}
|
icculus@10643
|
51 |
#ifdef strftime
|
icculus@10643
|
52 |
#undef strftime
|
icculus@10643
|
53 |
#endif
|
icculus@10643
|
54 |
#define strftime strftime_gcc2_workaround
|
icculus@10643
|
55 |
#endif
|
icculus@10643
|
56 |
|
gabomdq@7678
|
57 |
/* !
|
aschiffler@6717
|
58 |
* Converts unix timestamp to its ascii representation in localtime
|
aschiffler@6717
|
59 |
*
|
aschiffler@6717
|
60 |
* Note: Uses a static buffer internally, so the return value
|
aschiffler@6717
|
61 |
* isn't valid after the next call of this function. If you
|
aschiffler@6717
|
62 |
* want to retain the return value, make a copy of it.
|
aschiffler@6717
|
63 |
*
|
aschiffler@6717
|
64 |
* \param timestamp A Timestamp, i.e. time(0)
|
aschiffler@6717
|
65 |
*
|
aschiffler@6756
|
66 |
* \return Ascii representation of the timestamp in localtime in the format '08/23/01 14:55:02'
|
aschiffler@6717
|
67 |
*/
|
slouken@10609
|
68 |
static char *SDLTest_TimestampToString(const time_t timestamp)
|
aschiffler@6717
|
69 |
{
|
slouken@7191
|
70 |
time_t copy;
|
slouken@7191
|
71 |
static char buffer[64];
|
slouken@7191
|
72 |
struct tm *local;
|
aschiffler@6717
|
73 |
|
icculus@7405
|
74 |
SDL_memset(buffer, 0, sizeof(buffer));
|
slouken@7191
|
75 |
copy = timestamp;
|
slouken@7191
|
76 |
local = localtime(©);
|
slouken@10397
|
77 |
strftime(buffer, sizeof(buffer), "%x %X", local);
|
aschiffler@6717
|
78 |
|
slouken@7191
|
79 |
return buffer;
|
aschiffler@6717
|
80 |
}
|
aschiffler@6717
|
81 |
|
aschiffler@6717
|
82 |
/*
|
aschiffler@6717
|
83 |
* Prints given message with a timestamp in the TEST category and INFO priority.
|
aschiffler@6717
|
84 |
*/
|
slouken@8820
|
85 |
void SDLTest_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
|
aschiffler@6717
|
86 |
{
|
slouken@7191
|
87 |
va_list list;
|
slouken@7191
|
88 |
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
|
aschiffler@6717
|
89 |
|
slouken@7191
|
90 |
/* Print log message into a buffer */
|
slouken@7191
|
91 |
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
|
slouken@7191
|
92 |
va_start(list, fmt);
|
slouken@7191
|
93 |
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
|
slouken@7191
|
94 |
va_end(list);
|
aschiffler@6717
|
95 |
|
slouken@7191
|
96 |
/* Log with timestamp and newline */
|
slouken@7191
|
97 |
SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_INFO, " %s: %s", SDLTest_TimestampToString(time(0)), logMessage);
|
aschiffler@6717
|
98 |
}
|
aschiffler@6717
|
99 |
|
aschiffler@6717
|
100 |
/*
|
aschiffler@6717
|
101 |
* Prints given message with a timestamp in the TEST category and the ERROR priority.
|
aschiffler@6717
|
102 |
*/
|
slouken@8820
|
103 |
void SDLTest_LogError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...)
|
aschiffler@6717
|
104 |
{
|
slouken@7191
|
105 |
va_list list;
|
slouken@7191
|
106 |
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
|
aschiffler@6717
|
107 |
|
slouken@7191
|
108 |
/* Print log message into a buffer */
|
slouken@7191
|
109 |
SDL_memset(logMessage, 0, SDLTEST_MAX_LOGMESSAGE_LENGTH);
|
slouken@7191
|
110 |
va_start(list, fmt);
|
slouken@7191
|
111 |
SDL_vsnprintf(logMessage, SDLTEST_MAX_LOGMESSAGE_LENGTH - 1, fmt, list);
|
slouken@7191
|
112 |
va_end(list);
|
aschiffler@6717
|
113 |
|
slouken@7191
|
114 |
/* Log with timestamp and newline */
|
slouken@7191
|
115 |
SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR, "%s: %s", SDLTest_TimestampToString(time(0)), logMessage);
|
aschiffler@6717
|
116 |
}
|