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

Latest commit

 

History

History
131 lines (109 loc) · 3.26 KB

plain_logger.c

File metadata and controls

131 lines (109 loc) · 3.26 KB
 
1
2
3
4
5
6
#ifndef _PLAIN_LOGGER
#define _PLAIN_LOGGER
#include <stdio.h>
Jun 27, 2011
Jun 27, 2011
7
8
#include <SDL/SDL.h>
Jul 5, 2011
Jul 5, 2011
9
#include "logger_helpers.h"
10
11
#include "plain_logger.h"
Jul 4, 2011
Jul 4, 2011
12
13
static int indentLevel;
Jun 27, 2011
Jun 27, 2011
14
/*!
Jun 27, 2011
Jun 27, 2011
15
16
17
* Prints out the output of the logger
*
* \param message The message to be printed out
Jun 27, 2011
Jun 27, 2011
18
19
*/
int
Jul 4, 2011
Jul 4, 2011
20
Output(const int currentIdentLevel, const char *message, ...)
Jun 27, 2011
Jun 27, 2011
21
22
23
24
{
va_list list;
va_start(list, message);
Jul 4, 2011
Jul 4, 2011
25
26
27
28
29
int ident = 0;
for( ; ident < currentIdentLevel; ++ident) {
fprintf(stdout, " "); // \todo make configurable?
}
Jun 27, 2011
Jun 27, 2011
30
31
32
char buffer[1024];
SDL_vsnprintf(buffer, sizeof(buffer), message, list);
Jun 27, 2011
Jun 27, 2011
33
34
fprintf(stdout, "%s\n", buffer);
fflush(stdout);
Jun 27, 2011
Jun 27, 2011
35
}
36
37
void
Jun 30, 2011
Jun 30, 2011
38
39
PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
void *data)
Jul 5, 2011
Jul 5, 2011
41
42
43
44
Output(indentLevel, "Test run started at %s", TimestampToString(eventTime));
Output(indentLevel, "");
/*
Output(indentLevel, "Runner: ");
Jun 27, 2011
Jun 27, 2011
45
46
47
48
int counter = 0;
for(counter = 0; counter < parameterCount; counter++) {
char *parameter = runnerParameters[counter];
Jul 5, 2011
Jul 5, 2011
49
Output(indentLevel, "\t%s", parameter);
Jun 27, 2011
Jun 27, 2011
50
51
}
*/
52
53
54
}
void
Jun 22, 2011
Jun 22, 2011
55
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
Jun 27, 2011
Jun 27, 2011
56
time_t endTime, double totalRuntime)
Jul 5, 2011
Jul 5, 2011
58
Output(indentLevel, "Ran %d tests in %0.5f seconds from %d suites.",
Jun 27, 2011
Jun 27, 2011
59
testCount, totalRuntime, suiteCount);
Jun 26, 2011
Jun 26, 2011
60
Jul 4, 2011
Jul 4, 2011
61
62
Output(indentLevel, "%d tests passed", testPassCount);
Output(indentLevel, "%d tests failed", testFailCount);
63
64
65
66
67
}
void
PlainSuiteStarted(const char *suiteName, time_t eventTime)
{
Jul 4, 2011
Jul 4, 2011
68
Output(indentLevel++, "Executing tests from %s", suiteName);
69
70
71
72
}
void
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
Jun 27, 2011
Jun 27, 2011
73
time_t endTime, double totalRuntime)
Jul 4, 2011
Jul 4, 2011
75
76
77
Output(--indentLevel, "Suite executed. %d passed, %d failed and %d skipped. Total runtime %0.5f seconds",
testsPassed, testsFailed, testsSkipped, totalRuntime);
Output(indentLevel, "");
78
79
80
}
void
Jun 22, 2011
Jun 22, 2011
81
PlainTestStarted(const char *testName, const char *suiteName, const char *testDescription, time_t startTime)
Jul 5, 2011
Jul 5, 2011
83
Output(indentLevel++, "Executing test: %s (in %s)", testName, suiteName);
84
85
86
}
void
Jun 22, 2011
Jun 22, 2011
87
PlainTestEnded(const char *testName, const char *suiteName,
Jun 27, 2011
Jun 27, 2011
88
int testResult, time_t endTime, double totalRuntime)
Jun 27, 2011
Jun 27, 2011
90
91
if(testResult) {
if(testResult == 2) {
Jul 4, 2011
Jul 4, 2011
92
Output(--indentLevel, "%s: failed -> no assert", testName);
Jun 27, 2011
Jun 27, 2011
93
} else {
Jul 4, 2011
Jul 4, 2011
94
Output(--indentLevel, "%s: failed", testName);
Jun 27, 2011
Jun 27, 2011
95
96
}
} else {
Jul 4, 2011
Jul 4, 2011
97
Output(--indentLevel, "%s: ok", testName);
Jun 27, 2011
Jun 27, 2011
98
}
99
100
101
102
}
void
PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
Jun 27, 2011
Jun 27, 2011
103
104
105
time_t eventTime)
{
const char *result = (assertResult) ? "passed" : "failed";
Jul 4, 2011
Jul 4, 2011
106
Output(indentLevel, "%s: %s", assertName, assertMessage);
Jun 27, 2011
Jun 27, 2011
107
108
109
110
}
void
PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
Jul 5, 2011
Jul 5, 2011
111
int actualValue, int expected, time_t eventTime)
112
113
{
const char *result = (assertResult) ? "passed" : "failed";
Jul 5, 2011
Jul 5, 2011
114
115
Output(indentLevel, "%s %d (expected %d, actualValue &d): %s",
assertName, assertResult, expected, actualValue, assertMessage);
Jun 26, 2011
Jun 26, 2011
116
117
118
}
void
Jun 27, 2011
Jun 27, 2011
119
PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime)
Jun 26, 2011
Jun 26, 2011
120
{
Jul 4, 2011
Jul 4, 2011
121
Output(indentLevel, "Assert summary: %d failed, %d passed (total: %d)",
Jun 27, 2011
Jun 27, 2011
122
numAssertsFailed, numAssertsPass, numAsserts);
123
124
125
126
127
}
void
PlainLog(const char *logMessage, time_t eventTime)
{
Jul 4, 2011
Jul 4, 2011
128
Output(indentLevel, "%s %d", logMessage, eventTime);
129
130
131
}
#endif