test/test-automation/plain_logger.c
author Markus Kauppila <markus.kauppila@gmail.com>
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.
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
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    12
static int indentLevel;
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    13
5714
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    14
/*!
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    15
 * Prints out the output of the logger
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    16
 *
5747
cba233c8f7fa Fixed doxygen markup.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5746
diff changeset
    17
 * \param currentIdentLevel The currently used indentation level
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    18
 * \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
    19
 */
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    20
int
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    21
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
    22
{
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    23
	va_list list;
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    24
	va_start(list, message);
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    25
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    26
	int ident = 0;
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    27
	for( ; ident < currentIdentLevel; ++ident) {
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    28
		fprintf(stdout, "  "); // \todo make configurable?
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    29
	}
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    30
5714
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    31
	char buffer[1024];
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    32
	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
    33
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    34
	fprintf(stdout, "%s\n", buffer);
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    35
	fflush(stdout);
5714
d35019d2dcfb Added identation to the output of XML logger.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5713
diff changeset
    36
}
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    37
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    38
void
5728
7cf47cdaf4ab Added user-supplied XSL style sheets for XML-based test reports.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5717
diff changeset
    39
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
    40
				void *data)
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    41
{
5743
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    42
	Output(indentLevel, "Test run started at %s", TimestampToString(eventTime));
5757
a97102f40230 Plain logger logs the used command line options.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5755
diff changeset
    43
	Output(indentLevel, "Runner parameters: ");
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    44
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    45
	int counter = 0;
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    46
	for(counter = 0; counter < parameterCount; counter++) {
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    47
		char *parameter = runnerParameters[counter];
5743
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    48
		Output(indentLevel, "\t%s", parameter);
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    49
	}
5757
a97102f40230 Plain logger logs the used command line options.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5755
diff changeset
    50
a97102f40230 Plain logger logs the used command line options.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5755
diff changeset
    51
	Output(indentLevel, "");
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    52
}
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    53
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    54
void
5707
67940bee217e XML elements now support single attribute. Fixes here and there.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5706
diff changeset
    55
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
    56
			  int testSkippedCount, time_t endTime, double totalRuntime)
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    57
{
5743
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    58
	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
    59
			testCount, totalRuntime, suiteCount);
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5712
diff changeset
    60
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    61
	Output(indentLevel, "%d tests passed", testPassCount);
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    62
	Output(indentLevel, "%d tests failed", testFailCount);
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
    63
	Output(indentLevel, "%d tests skipped", testSkippedCount);
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    64
}
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
void
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    67
PlainSuiteStarted(const char *suiteName, time_t eventTime)
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    68
{
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    69
	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
    70
}
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
void
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    73
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
    74
           time_t endTime, double totalRuntime)
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    75
{
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    76
	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
    77
			testsPassed, testsFailed, testsSkipped, totalRuntime);
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    78
	Output(indentLevel, "");
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
    79
}
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
void
5707
67940bee217e XML elements now support single attribute. Fixes here and there.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5706
diff changeset
    82
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
    83
{
5743
3f79a693acd3 Made the output of plain logger more readable.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5742
diff changeset
    84
	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
    85
}
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
void
5707
67940bee217e XML elements now support single attribute. Fixes here and there.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5706
diff changeset
    88
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
    89
          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
    90
{
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    91
	if(testResult) {
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    92
		if(testResult == 2) {
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    93
			Output(--indentLevel, "%s: failed -> no assert", testName);
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
    94
		}
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
    95
		else if(testResult == 3) {
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
    96
			Output(--indentLevel, "%s: skipped", testName);
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    97
		} else {
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
    98
			Output(--indentLevel, "%s: failed", testName);
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
    99
		}
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   100
	} else {
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
   101
		Output(--indentLevel, "%s: ok", testName);
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   102
	}
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   103
}
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   104
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   105
void
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   106
PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   107
		time_t eventTime)
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   108
{
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   109
	const char *result = (assertResult) ? "passed" : "failed";
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   110
	Output(indentLevel, "%s: %s - %s", assertName, result, assertMessage);
5717
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   111
}
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   112
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   113
void
a180e774b39b Plain logger refined.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5716
diff changeset
   114
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
   115
		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
   116
{
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   117
	const char *result = (assertResult) ? "passed" : "failed";
5755
35d4ae5dea90 If any assert in SetUp function fails that test will be skipped.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5751
diff changeset
   118
	Output(indentLevel, "%s: %s (expected %d, actualValue &d) - %s",
5750
337982ee35ac Ported surface tests.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5747
diff changeset
   119
			assertName, result, expected, actualValue, assertMessage);
5713
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5712
diff changeset
   120
}
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5712
diff changeset
   121
08edd9b3ec32 Logging system added to harness. Logging system doesn't
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5712
diff changeset
   122
void
5716
384e20ac7425 Added time, date and total runtime information to the output by
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5715
diff changeset
   123
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
   124
{
5742
443d356b5af8 Added command option --version
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5734
diff changeset
   125
	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
   126
			numAssertsFailed, numAssertsPass, numAsserts);
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   127
}
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   128
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   129
void
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   130
PlainLog(const char *logMessage, time_t eventTime)
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   131
{
5751
cbb921210496 Bunch of little fixes.
Markus Kauppila <markus.kauppila@gmail.com>
parents: 5750
diff changeset
   132
	Output(indentLevel, "%s %d", logMessage, TimestampToString(eventTime));
5706
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   133
}
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   134
9da43acca81f Various fixes and additions to logger system.
Markus Kauppila <markus.kauppila@gmail.com>
parents:
diff changeset
   135
#endif