2011-06-21 22:04:44 +03:00
|
|
|
|
|
|
|
#ifndef _PLAIN_LOGGER
|
|
|
|
#define _PLAIN_LOGGER
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
#include <SDL/SDL.h>
|
|
|
|
|
2011-07-05 21:15:34 +03:00
|
|
|
#include "logger_helpers.h"
|
2011-06-21 22:04:44 +03:00
|
|
|
#include "plain_logger.h"
|
|
|
|
|
2011-07-04 20:46:06 +03:00
|
|
|
static int indentLevel;
|
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
/*!
|
2011-06-27 22:14:48 +03:00
|
|
|
* Prints out the output of the logger
|
|
|
|
*
|
2011-07-06 17:05:07 +03:00
|
|
|
* \param currentIdentLevel The currently used indentation level
|
2011-06-27 22:14:48 +03:00
|
|
|
* \param message The message to be printed out
|
2011-06-27 11:53:14 +03:00
|
|
|
*/
|
|
|
|
int
|
2011-07-04 20:46:06 +03:00
|
|
|
Output(const int currentIdentLevel, const char *message, ...)
|
2011-06-27 11:53:14 +03:00
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
va_start(list, message);
|
|
|
|
|
2011-07-04 20:46:06 +03:00
|
|
|
int ident = 0;
|
|
|
|
for( ; ident < currentIdentLevel; ++ident) {
|
|
|
|
fprintf(stdout, " "); // \todo make configurable?
|
|
|
|
}
|
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
char buffer[1024];
|
|
|
|
SDL_vsnprintf(buffer, sizeof(buffer), message, list);
|
|
|
|
|
2011-06-27 22:14:48 +03:00
|
|
|
fprintf(stdout, "%s\n", buffer);
|
|
|
|
fflush(stdout);
|
2011-06-27 11:53:14 +03:00
|
|
|
}
|
2011-06-21 22:04:44 +03:00
|
|
|
|
|
|
|
void
|
2011-06-30 17:11:39 +03:00
|
|
|
PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
|
|
|
|
void *data)
|
2011-06-21 22:04:44 +03:00
|
|
|
{
|
2011-07-05 21:15:34 +03:00
|
|
|
Output(indentLevel, "Test run started at %s", TimestampToString(eventTime));
|
2011-07-12 23:53:57 +03:00
|
|
|
Output(indentLevel, "Runner parameters: ");
|
2011-06-27 22:14:48 +03:00
|
|
|
|
|
|
|
int counter = 0;
|
|
|
|
for(counter = 0; counter < parameterCount; counter++) {
|
|
|
|
char *parameter = runnerParameters[counter];
|
2011-07-05 21:15:34 +03:00
|
|
|
Output(indentLevel, "\t%s", parameter);
|
2011-06-27 22:14:48 +03:00
|
|
|
}
|
2011-07-12 23:53:57 +03:00
|
|
|
|
|
|
|
Output(indentLevel, "");
|
2011-06-21 22:04:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-22 17:41:37 +03:00
|
|
|
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
|
2011-07-11 21:09:28 +03:00
|
|
|
int testSkippedCount, time_t endTime, double totalRuntime)
|
2011-06-21 22:04:44 +03:00
|
|
|
{
|
2011-07-05 21:15:34 +03:00
|
|
|
Output(indentLevel, "Ran %d tests in %0.5f seconds from %d suites.",
|
2011-06-27 22:14:48 +03:00
|
|
|
testCount, totalRuntime, suiteCount);
|
2011-06-26 23:04:37 +03:00
|
|
|
|
2011-07-04 20:46:06 +03:00
|
|
|
Output(indentLevel, "%d tests passed", testPassCount);
|
|
|
|
Output(indentLevel, "%d tests failed", testFailCount);
|
2011-07-11 21:09:28 +03:00
|
|
|
Output(indentLevel, "%d tests skipped", testSkippedCount);
|
2011-06-21 22:04:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PlainSuiteStarted(const char *suiteName, time_t eventTime)
|
|
|
|
{
|
2011-07-04 20:46:06 +03:00
|
|
|
Output(indentLevel++, "Executing tests from %s", suiteName);
|
2011-06-21 22:04:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
|
2011-06-27 21:41:34 +03:00
|
|
|
time_t endTime, double totalRuntime)
|
2011-06-21 22:04:44 +03:00
|
|
|
{
|
2011-07-04 20:46:06 +03:00
|
|
|
Output(--indentLevel, "Suite executed. %d passed, %d failed and %d skipped. Total runtime %0.5f seconds",
|
|
|
|
testsPassed, testsFailed, testsSkipped, totalRuntime);
|
|
|
|
Output(indentLevel, "");
|
2011-06-21 22:04:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-22 17:41:37 +03:00
|
|
|
PlainTestStarted(const char *testName, const char *suiteName, const char *testDescription, time_t startTime)
|
2011-06-21 22:04:44 +03:00
|
|
|
{
|
2011-07-05 21:15:34 +03:00
|
|
|
Output(indentLevel++, "Executing test: %s (in %s)", testName, suiteName);
|
2011-06-21 22:04:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-22 17:41:37 +03:00
|
|
|
PlainTestEnded(const char *testName, const char *suiteName,
|
2011-06-27 21:41:34 +03:00
|
|
|
int testResult, time_t endTime, double totalRuntime)
|
2011-06-21 22:04:44 +03:00
|
|
|
{
|
2011-06-27 22:14:48 +03:00
|
|
|
if(testResult) {
|
|
|
|
if(testResult == 2) {
|
2011-07-04 20:46:06 +03:00
|
|
|
Output(--indentLevel, "%s: failed -> no assert", testName);
|
2011-07-11 21:09:28 +03:00
|
|
|
}
|
|
|
|
else if(testResult == 3) {
|
|
|
|
Output(--indentLevel, "%s: skipped", testName);
|
2011-06-27 22:14:48 +03:00
|
|
|
} else {
|
2011-07-04 20:46:06 +03:00
|
|
|
Output(--indentLevel, "%s: failed", testName);
|
2011-06-27 22:14:48 +03:00
|
|
|
}
|
|
|
|
} else {
|
2011-07-04 20:46:06 +03:00
|
|
|
Output(--indentLevel, "%s: ok", testName);
|
2011-06-27 22:14:48 +03:00
|
|
|
}
|
2011-06-21 22:04:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
|
2011-06-27 22:14:48 +03:00
|
|
|
time_t eventTime)
|
|
|
|
{
|
|
|
|
const char *result = (assertResult) ? "passed" : "failed";
|
2011-07-11 21:09:28 +03:00
|
|
|
Output(indentLevel, "%s: %s - %s", assertName, result, assertMessage);
|
2011-06-27 22:14:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
|
2011-07-05 21:15:34 +03:00
|
|
|
int actualValue, int expected, time_t eventTime)
|
2011-06-21 22:04:44 +03:00
|
|
|
{
|
|
|
|
const char *result = (assertResult) ? "passed" : "failed";
|
2011-07-11 21:09:28 +03:00
|
|
|
Output(indentLevel, "%s: %s (expected %d, actualValue &d) - %s",
|
2011-07-09 17:55:35 +03:00
|
|
|
assertName, result, expected, actualValue, assertMessage);
|
2011-06-26 23:04:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-27 21:41:34 +03:00
|
|
|
PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime)
|
2011-06-26 23:04:37 +03:00
|
|
|
{
|
2011-07-04 20:46:06 +03:00
|
|
|
Output(indentLevel, "Assert summary: %d failed, %d passed (total: %d)",
|
2011-06-27 22:14:48 +03:00
|
|
|
numAssertsFailed, numAssertsPass, numAsserts);
|
2011-06-21 22:04:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PlainLog(const char *logMessage, time_t eventTime)
|
|
|
|
{
|
2011-07-10 18:42:52 +03:00
|
|
|
Output(indentLevel, "%s %d", logMessage, TimestampToString(eventTime));
|
2011-06-21 22:04:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|