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