test/test-automation/plain_logger.c
author Markus Kauppila <markus.kauppila@gmail.com>
Tue, 05 Jul 2011 21:15:34 +0300
changeset 5743 3f79a693acd3
parent 5742 443d356b5af8
child 5746 b7a0b33b08f4
permissions -rw-r--r--
Made the output of plain logger more readable.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     1
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     2
#ifndef _PLAIN_LOGGER
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     3
#define _PLAIN_LOGGER
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     4
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     5
#include <stdio.h>
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
     6
5714
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
     7
#include <SDL/SDL.h>
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
     8
5743
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
     9
#include "logger_helpers.h"
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    10
#include "plain_logger.h"
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    11
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    12
5743
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    13
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    14
static int indentLevel;
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    15
5714
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    16
/*!
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    17
 * Prints out the output of the logger
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    18
 *
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    19
 * \param message The message to be printed out
5714
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    20
 */
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    21
int
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    22
Output(const int currentIdentLevel, const char *message, ...)
5714
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    23
{
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    24
	va_list list;
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    25
	va_start(list, message);
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    26
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    27
	int ident = 0;
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    28
	for( ; ident < currentIdentLevel; ++ident) {
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    29
		fprintf(stdout, "  "); // \todo make configurable?
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    30
	}
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    31
5714
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    32
	char buffer[1024];
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    33
	SDL_vsnprintf(buffer, sizeof(buffer), message, list);
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    34
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    35
	fprintf(stdout, "%s\n", buffer);
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    36
	fflush(stdout);
5714
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    37
}
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    38
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    39
void
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5717
diff changeset
    40
PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5717
diff changeset
    41
				void *data)
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    42
{
5743
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    43
	Output(indentLevel, "Test run started at %s", TimestampToString(eventTime));
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    44
	Output(indentLevel, "");
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    45
    /*
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    46
	Output(indentLevel, "Runner: ");
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    47
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    48
	int counter = 0;
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    49
	for(counter = 0; counter < parameterCount; counter++) {
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    50
		char *parameter = runnerParameters[counter];
5743
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    51
		Output(indentLevel, "\t%s", parameter);
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    52
	}
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    53
	*/
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    54
}
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    55
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    56
void
5707
67940bee217e XML elements now support single attribute. Fixes here and there.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5706
diff changeset
    57
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    58
              time_t endTime, double totalRuntime)
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    59
{
5743
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    60
	Output(indentLevel, "Ran %d tests in %0.5f seconds from %d suites.",
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    61
			testCount, totalRuntime, suiteCount);
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5712
diff changeset
    62
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    63
	Output(indentLevel, "%d tests passed", testPassCount);
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    64
	Output(indentLevel, "%d tests failed", testFailCount);
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    65
}
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    66
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    67
void
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    68
PlainSuiteStarted(const char *suiteName, time_t eventTime)
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    69
{
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    70
	Output(indentLevel++, "Executing tests from %s", suiteName);
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    71
}
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    72
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    73
void
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    74
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    75
           time_t endTime, double totalRuntime)
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    76
{
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    77
	Output(--indentLevel, "Suite executed. %d passed, %d failed and %d skipped. Total runtime %0.5f seconds",
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    78
			testsPassed, testsFailed, testsSkipped, totalRuntime);
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    79
	Output(indentLevel, "");
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    80
}
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    81
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    82
void
5707
67940bee217e XML elements now support single attribute. Fixes here and there.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5706
diff changeset
    83
PlainTestStarted(const char *testName, const char *suiteName, const char *testDescription, time_t startTime)
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    84
{
5743
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    85
	Output(indentLevel++, "Executing test: %s (in %s)", testName, suiteName);
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    86
}
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    87
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    88
void
5707
67940bee217e XML elements now support single attribute. Fixes here and there.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5706
diff changeset
    89
PlainTestEnded(const char *testName, const char *suiteName,
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
    90
          int testResult, time_t endTime, double totalRuntime)
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    91
{
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    92
	if(testResult) {
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    93
		if(testResult == 2) {
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    94
			Output(--indentLevel, "%s: failed -> no assert", testName);
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    95
		} else {
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    96
			Output(--indentLevel, "%s: failed", testName);
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    97
		}
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    98
	} else {
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    99
		Output(--indentLevel, "%s: ok", testName);
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   100
	}
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   101
}
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   102
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   103
void
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   104
PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   105
		time_t eventTime)
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   106
{
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   107
	const char *result = (assertResult) ? "passed" : "failed";
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
   108
	Output(indentLevel, "%s: %s", assertName, assertMessage);
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   109
}
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   110
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   111
void
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   112
PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
5743
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   113
		int actualValue, int expected, time_t eventTime)
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   114
{
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   115
	const char *result = (assertResult) ? "passed" : "failed";
5743
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   116
	Output(indentLevel, "%s %d (expected %d, actualValue &d): %s",
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
   117
			assertName, assertResult, expected, actualValue, assertMessage);
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5712
diff changeset
   118
}
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5712
diff changeset
   119
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5712
diff changeset
   120
void
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   121
PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime)
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5712
diff changeset
   122
{
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
   123
	Output(indentLevel, "Assert summary: %d failed, %d passed (total: %d)",
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   124
			numAssertsFailed, numAssertsPass, numAsserts);
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   125
}
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   126
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   127
void
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   128
PlainLog(const char *logMessage, time_t eventTime)
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   129
{
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
   130
	Output(indentLevel, "%s %d", logMessage, eventTime);
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   131
}
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   132
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   133
#endif