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