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

Latest commit

 

History

History
155 lines (130 loc) · 4.1 KB

plain_logger.c

File metadata and controls

155 lines (130 loc) · 4.1 KB
 
1
2
3
4
#ifndef _PLAIN_LOGGER
#define _PLAIN_LOGGER
Jul 5, 2011
Jul 5, 2011
5
#include "logger_helpers.h"
6
#include "plain_logger.h"
Jul 13, 2011
Jul 13, 2011
7
#include "SDL_test.h"
Jul 4, 2011
Jul 4, 2011
9
10
static int indentLevel;
Jun 27, 2011
Jun 27, 2011
11
/*!
Jun 27, 2011
Jun 27, 2011
12
13
* Prints out the output of the logger
*
Jul 14, 2011
Jul 14, 2011
14
* \param currentIndentLevel The currently used indentation level
Jun 27, 2011
Jun 27, 2011
15
* \param message The message to be printed out
Jun 27, 2011
Jun 27, 2011
16
17
*/
int
Jul 14, 2011
Jul 14, 2011
18
Output(const int currentIndentLevel, const char *message, ...)
Jun 27, 2011
Jun 27, 2011
19
{
Jul 4, 2011
Jul 4, 2011
20
int ident = 0;
Jul 14, 2011
Jul 14, 2011
21
for( ; ident < currentIndentLevel; ++ident) {
Jul 4, 2011
Jul 4, 2011
22
23
24
fprintf(stdout, " "); // \todo make configurable?
}
Jul 14, 2011
Jul 14, 2011
25
26
27
28
29
30
31
32
33
34
char buffer[1024];
memset(buffer, 0, 1024);
va_list list;
va_start(list, message);
SDL_vsnprintf(buffer, 1024, message, list);
va_end(list);
Jun 27, 2011
Jun 27, 2011
35
36
fprintf(stdout, "%s\n", buffer);
fflush(stdout);
Jun 27, 2011
Jun 27, 2011
37
}
38
39
void
Jul 25, 2011
Jul 25, 2011
40
41
PlainRunStarted(int parameterCount, char *runnerParameters[], char *runSeed,
time_t eventTime, void *data)
Jul 5, 2011
Jul 5, 2011
43
Output(indentLevel, "Test run started at %s", TimestampToString(eventTime));
Jul 25, 2011
Jul 25, 2011
44
Output(indentLevel, "Fuzzer seed is %s", runSeed);
Jul 12, 2011
Jul 12, 2011
45
Output(indentLevel, "Runner parameters: ");
Jun 27, 2011
Jun 27, 2011
46
47
48
49
int counter = 0;
for(counter = 0; counter < parameterCount; counter++) {
char *parameter = runnerParameters[counter];
Jul 5, 2011
Jul 5, 2011
50
Output(indentLevel, "\t%s", parameter);
Jun 27, 2011
Jun 27, 2011
51
}
Jul 12, 2011
Jul 12, 2011
52
53
Output(indentLevel, "");
54
55
56
}
void
Jun 22, 2011
Jun 22, 2011
57
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
Jul 11, 2011
Jul 11, 2011
58
int testSkippedCount, time_t endTime, double totalRuntime)
Jul 5, 2011
Jul 5, 2011
60
Output(indentLevel, "Ran %d tests in %0.5f seconds from %d suites.",
Jun 27, 2011
Jun 27, 2011
61
testCount, totalRuntime, suiteCount);
Jun 26, 2011
Jun 26, 2011
62
Jul 4, 2011
Jul 4, 2011
63
64
Output(indentLevel, "%d tests passed", testPassCount);
Output(indentLevel, "%d tests failed", testFailCount);
Jul 11, 2011
Jul 11, 2011
65
Output(indentLevel, "%d tests skipped", testSkippedCount);
66
67
68
69
70
}
void
PlainSuiteStarted(const char *suiteName, time_t eventTime)
{
Jul 4, 2011
Jul 4, 2011
71
Output(indentLevel++, "Executing tests from %s", suiteName);
72
73
74
75
}
void
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
Jun 27, 2011
Jun 27, 2011
76
time_t endTime, double totalRuntime)
Jul 4, 2011
Jul 4, 2011
78
79
80
Output(--indentLevel, "Suite executed. %d passed, %d failed and %d skipped. Total runtime %0.5f seconds",
testsPassed, testsFailed, testsSkipped, totalRuntime);
Output(indentLevel, "");
81
82
83
}
void
Jul 24, 2011
Jul 24, 2011
84
PlainTestStarted(const char *testName, const char *suiteName,
Jul 25, 2011
Jul 25, 2011
85
const char *testDescription, char *execKey, time_t startTime)
Jul 25, 2011
Jul 25, 2011
87
Output(indentLevel++, "Executing test: %s (in %s). Exec key: %X", testName, suiteName, execKey);
88
89
90
}
void
Jun 22, 2011
Jun 22, 2011
91
PlainTestEnded(const char *testName, const char *suiteName,
Jun 27, 2011
Jun 27, 2011
92
int testResult, time_t endTime, double totalRuntime)
Jul 13, 2011
Jul 13, 2011
94
95
96
97
98
99
100
101
switch(testResult) {
case TEST_RESULT_PASS:
Output(--indentLevel, "%s: ok", testName);
break;
case TEST_RESULT_FAILURE:
Output(--indentLevel, "%s: failed", testName);
break;
case TEST_RESULT_NO_ASSERT:
Jul 4, 2011
Jul 4, 2011
102
Output(--indentLevel, "%s: failed -> no assert", testName);
Jul 13, 2011
Jul 13, 2011
103
104
break;
case TEST_RESULT_SKIPPED:
Jul 11, 2011
Jul 11, 2011
105
Output(--indentLevel, "%s: skipped", testName);
Jul 13, 2011
Jul 13, 2011
106
107
108
109
110
111
112
break;
case TEST_RESULT_KILLED:
Output(--indentLevel, "%s: killed, exceeded timeout", testName);
break;
case TEST_RESULT_SETUP_FAILURE:
Output(--indentLevel, "%s: killed, setup failure", testName);
break;
Jun 27, 2011
Jun 27, 2011
113
}
114
115
116
117
}
void
PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
Jun 27, 2011
Jun 27, 2011
118
119
120
time_t eventTime)
{
const char *result = (assertResult) ? "passed" : "failed";
Jul 11, 2011
Jul 11, 2011
121
Output(indentLevel, "%s: %s - %s", assertName, result, assertMessage);
Jun 27, 2011
Jun 27, 2011
122
123
124
125
}
void
PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
Jul 14, 2011
Jul 14, 2011
126
int actualValue, int expectedValue, time_t eventTime)
127
128
{
const char *result = (assertResult) ? "passed" : "failed";
Jul 14, 2011
Jul 14, 2011
129
130
Output(indentLevel, "%s: %s (expected %d, actualValue %d) - %s",
assertName, result, expectedValue, actualValue, assertMessage);
Jun 26, 2011
Jun 26, 2011
131
132
133
}
void
Jun 27, 2011
Jun 27, 2011
134
PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime)
Jun 26, 2011
Jun 26, 2011
135
{
Jul 4, 2011
Jul 4, 2011
136
Output(indentLevel, "Assert summary: %d failed, %d passed (total: %d)",
Jun 27, 2011
Jun 27, 2011
137
numAssertsFailed, numAssertsPass, numAsserts);
138
139
140
}
void
Jul 18, 2011
Jul 18, 2011
141
PlainLog(time_t eventTime, char *fmt, ...)
Jul 18, 2011
Jul 18, 2011
143
144
145
146
147
148
149
150
151
// create the log message
va_list args;
char logMessage[1024];
memset(logMessage, 0, sizeof(logMessage));
va_start( args, fmt );
SDL_vsnprintf( logMessage, sizeof(logMessage), fmt, args );
va_end( args );
Jul 18, 2011
Jul 18, 2011
152
Output(indentLevel, "%s", logMessage);
153
154
155
}
#endif