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