Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
101 lines (81 loc) · 3.05 KB

SDL_test_log.c

File metadata and controls

101 lines (81 loc) · 3.05 KB
 
1
2
/*
Simple DirectMedia Layer
Feb 15, 2013
Feb 15, 2013
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
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.
*/
/*
May 18, 2013
May 18, 2013
24
Used by the test framework and test cases.
May 18, 2013
May 18, 2013
28
/* quiet windows compiler warnings */
Dec 1, 2012
Dec 1, 2012
29
30
#define _CRT_SECURE_NO_WARNINGS
31
32
33
#include "SDL_config.h"
#include <stdarg.h> /* va_list */
Dec 24, 2012
Dec 24, 2012
34
#include <stdio.h>
Dec 2, 2012
Dec 2, 2012
35
#include <string.h>
36
37
#include <time.h>
Dec 24, 2012
Dec 24, 2012
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)
*
Dec 15, 2012
Dec 15, 2012
51
* \return Ascii representation of the timestamp in localtime in the format '08/23/01 14:55:02'
May 18, 2013
May 18, 2013
53
char *SDLTest_TimestampToString(const time_t timestamp)
May 18, 2013
May 18, 2013
55
56
57
time_t copy;
static char buffer[64];
struct tm *local;
May 18, 2013
May 18, 2013
59
60
61
62
SDL_memset(buffer, 0, sizeof(buffer));\
copy = timestamp;
local = localtime(&copy);
strftime(buffer, sizeof(buffer), "%x %X", local);
May 18, 2013
May 18, 2013
64
return buffer;
65
66
67
68
69
}
/*
* Prints given message with a timestamp in the TEST category and INFO priority.
*/
Dec 24, 2012
Dec 24, 2012
70
void SDLTest_Log(const char *fmt, ...)
May 18, 2013
May 18, 2013
72
73
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
May 18, 2013
May 18, 2013
75
76
77
78
79
/* 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);
va_end(list);
May 18, 2013
May 18, 2013
81
82
/* Log with timestamp and newline */
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.
*/
Dec 24, 2012
Dec 24, 2012
88
void SDLTest_LogError(const char *fmt, ...)
May 18, 2013
May 18, 2013
90
91
va_list list;
char logMessage[SDLTEST_MAX_LOGMESSAGE_LENGTH];
May 18, 2013
May 18, 2013
93
94
95
96
97
/* 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);
va_end(list);
May 18, 2013
May 18, 2013
99
100
/* Log with timestamp and newline */
SDL_LogMessage(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR, "%s: %s", SDLTest_TimestampToString(time(0)), logMessage);