Plain logger refined.
authorMarkus Kauppila <markus.kauppila@gmail.com>
Mon, 27 Jun 2011 22:14:48 +0300
changeset 5717 a180e774b39b
parent 5716 384e20ac7425
child 5718 bdb85a46ff7d
Plain logger refined.
test/test-automation/SDL_test.c
test/test-automation/logger.c
test/test-automation/logger.h
test/test-automation/plain_logger.c
test/test-automation/plain_logger.h
test/test-automation/xml_logger.c
test/test-automation/xml_logger.h
--- a/test/test-automation/SDL_test.c	Mon Jun 27 21:41:34 2011 +0300
+++ b/test/test-automation/SDL_test.c	Mon Jun 27 22:14:48 2011 +0300
@@ -57,7 +57,6 @@
 int
 _TestCaseQuit()
 {
-	//printf("Asserts: passed %d, failed %d\n", _testAssertsPassed, _testAssertsFailed);
 	AssertSummary(_testAssertsFailed + _testAssertsPassed,
                   _testAssertsFailed, _testAssertsPassed, time(0));
 
@@ -78,14 +77,13 @@
       va_start( args, message );
       SDL_vsnprintf( buf, sizeof(buf), message, args );
       va_end( args );
-      //printf("AssertEquals failed: expected %d, got %d; %s\n", expected, actual, buf);
-      Assert("AssertEquals", 0, buf, time(0));
+      AssertWithValues("AssertEquals", 0, buf, actual, expected, time(0));
 
       _testReturnValue = 1;
       _testAssertsFailed++;
    } else {
-      //printf("AssertEquals passed\n");
-      Assert("AssertEquals", 1, "AssertEquals passed", time(0));
+      AssertWithValues("AssertEquals", 1, "AssertEquals passed",
+    		  actual, expected, time(0));
 
       _testAssertsPassed++;
    }
--- a/test/test-automation/logger.c	Mon Jun 27 21:41:34 2011 +0300
+++ b/test/test-automation/logger.c	Mon Jun 27 22:14:48 2011 +0300
@@ -18,6 +18,7 @@
 TestStartedFp TestStarted = 0;
 TestEndedFp TestEnded = 0;
 AssertFp Assert = 0;
+AssertWithValuesFp AssertWithValues = 0;
 AssertSummaryFp AssertSummary = 0;
 LogFp Log = 0;
 
@@ -34,6 +35,7 @@
 	TestEnded = XMLTestEnded;
 
 	Assert = XMLAssert;
+	AssertWithValues = XMLAssertWithValues;
 	AssertSummary = XMLAssertSummary;
 
 	Log = XMLLog;
@@ -52,11 +54,45 @@
 	TestEnded = PlainTestEnded;
 
 	Assert = PlainAssert;
+	AssertWithValues = PlainAssertWithValues;
 	AssertSummary = PlainAssertSummary;
 
 	Log = PlainLog;
 }
 
+
+char *IntToString(const int integer) {
+	static char buffer[sizeof(int) * 8 + 1]; // malloc might work better
+	memset(buffer, 0, sizeof(buffer));
+
+	SDL_snprintf(buffer, sizeof(buffer), "%d", integer);
+
+	return buffer;
+}
+
+
+char *DoubleToString(const double decimal) {
+	static char buffer[sizeof(double) * 8 + 1]; // malloc might work better
+	memset(buffer, 0, sizeof(buffer));
+
+	SDL_snprintf(buffer, sizeof(buffer), "%.5f", decimal);
+
+	return buffer;
+}
+
+char *TimestampToString(const time_t timestamp) {
+	static char buffer[1024];
+	//char *buffer = SDL_malloc(1024);
+	memset(buffer, 0, 1024);
+
+	time_t copy = timestamp;
+
+	struct tm *local = localtime(&copy);
+	strftime(buffer, 1024, "%a %Y-%m-%d %H:%M:%S %Z", local);
+
+	return buffer;
+}
+
 #if 0
 /*!
  * Test app for logging functionality
--- a/test/test-automation/logger.h	Mon Jun 27 21:41:34 2011 +0300
+++ b/test/test-automation/logger.h	Mon Jun 27 22:14:48 2011 +0300
@@ -46,10 +46,14 @@
  */
 typedef	void (*AssertFp)(const char *assertName, int assertResult,
 						 const char *assertMessage, time_t eventTime);
+
+typedef	void (*AssertWithValuesFp)(const char *assertName, int assertResult,
+						 const char *assertMessage, int actualValue, int excpected,
+						 time_t eventTime);
+
 typedef	void (*AssertSummaryFp)(int numAsserts, int numAssertsFailed,
 								int numAssertsPass, time_t eventTime);
 
-
 typedef	void (*LogFp)(const char *logMessage, time_t eventTime);
 
 
@@ -60,7 +64,34 @@
 extern TestStartedFp TestStarted;
 extern TestEndedFp TestEnded;
 extern AssertFp Assert;
+extern AssertWithValuesFp AssertWithValues;
 extern AssertSummaryFp AssertSummary;
 extern LogFp Log;
 
+/*!
+ *  Helper functions. Turns the given integer in to a string
+ *
+ *  \param integer The converted integer
+ *  \returns Given integer as string
+ */
+char *IntToString(const int integer);
+
+/*!
+ *  Helper functions. Turns the given double value in to a string
+ *
+ *  \param integer The converted double value
+ *  \returns Given double value as string
+ */
+char *DoubleToString(const double decimal);
+
+
+/*!
+ * Converts unix timestamp to it's ascii presentation
+ *
+ * \param timestamp Timestamp
+ * \return Ascii presentation
+ */
+char *TimestampToString(const time_t timestamp);
+
+
 #endif
--- a/test/test-automation/plain_logger.c	Mon Jun 27 21:41:34 2011 +0300
+++ b/test/test-automation/plain_logger.c	Mon Jun 27 22:14:48 2011 +0300
@@ -10,8 +10,9 @@
 
 
 /*!
- * Pritns out the output of the logger
- * \return Possible error value (\todo)
+ * Prints out the output of the logger
+ *
+ * \param message The message to be printed out
  */
 int
 Output(const char *message, ...)
@@ -22,22 +23,30 @@
 	char buffer[1024];
 	SDL_vsnprintf(buffer, sizeof(buffer), message, list);
 
-	fprintf(stderr, "%s\n", buffer);
-	fflush(stderr);
+	fprintf(stdout, "%s\n", buffer);
+	fflush(stdout);
 }
 
 void
 PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime)
 {
-	Output("Test run started");
-	Output("Given command line options: %s", "add options");
+	/*
+    Output("Test run started with following parameters\n");
+
+	int counter = 0;
+	for(counter = 0; counter < parameterCount; counter++) {
+		char *parameter = runnerParameters[counter];
+		Output("\t%s", parameter);
+	}
+	*/
 }
 
 void
 PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
               time_t endTime, double totalRuntime)
 {
-	Output("Ran %d tests in %0.5f seconds.", testCount, totalRuntime);
+	Output("\nRan %d tests in %0.5f seconds from %d suites.",
+			testCount, totalRuntime, suiteCount);
 
 	Output("%d tests passed", testPassCount);
 	Output("%d tests failed", testFailCount);
@@ -46,7 +55,7 @@
 void
 PlainSuiteStarted(const char *suiteName, time_t eventTime)
 {
-	Output("Executing tests in %s", suiteName);
+	Output("Executing tests from %s", suiteName);
 }
 
 void
@@ -59,19 +68,35 @@
 void
 PlainTestStarted(const char *testName, const char *suiteName, const char *testDescription, time_t startTime)
 {
-	Output("test %s (in %s) started", testName, suiteName);
+	Output("%s (in %s) started", testName, suiteName);
 }
 
 void
 PlainTestEnded(const char *testName, const char *suiteName,
           int testResult, time_t endTime, double totalRuntime)
 {
-	Output("%s: ok", testName);
+	if(testResult) {
+		if(testResult == 2) {
+			Output("%s: failed -> no assert");
+		} else {
+			Output("%s: failed");
+		}
+	} else {
+		Output("%s: ok", testName);
+	}
 }
 
 void
 PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
-       time_t eventTime)
+		time_t eventTime)
+{
+	const char *result = (assertResult) ? "passed" : "failed";
+	Output("%s: %s", assertName, assertMessage);
+}
+
+void
+PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
+		int actualValue, int excpected, time_t eventTime)
 {
 	const char *result = (assertResult) ? "passed" : "failed";
 	Output("%s %d: %s", assertName, assertResult, assertMessage);
@@ -80,7 +105,8 @@
 void
 PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime)
 {
-	Output("Asserts:%d", numAsserts);
+	Output("Assert summary: %d failed, %d passed (total: %d)",
+			numAssertsFailed, numAssertsPass, numAsserts);
 }
 
 void
--- a/test/test-automation/plain_logger.h	Mon Jun 27 21:41:34 2011 +0300
+++ b/test/test-automation/plain_logger.h	Mon Jun 27 22:14:48 2011 +0300
@@ -21,7 +21,10 @@
 
 
 void PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
-       time_t eventTime);
+				time_t eventTime);
+
+void PlainAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
+		int actualValue, int excpected, time_t eventTime);
 
 void PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime);
 
--- a/test/test-automation/xml_logger.c	Mon Jun 27 21:41:34 2011 +0300
+++ b/test/test-automation/xml_logger.c	Mon Jun 27 22:14:48 2011 +0300
@@ -29,55 +29,6 @@
 
 #include "xml_logger.h"
 
-/*!
- *  Helper functions. Turns the given integer in to a string
- *
- *  \param integer The converted integer
- *  \returns Given integer as string
- */
-char *IntToString(const int integer) {
-	static char buffer[sizeof(int) * 8 + 1]; // malloc might work better
-	memset(buffer, 0, sizeof(buffer));
-
-	SDL_snprintf(buffer, sizeof(buffer), "%d", integer);
-
-	return buffer;
-}
-
-/*!
- *  Helper functions. Turns the given double value in to a string
- *
- *  \param integer The converted double value
- *  \returns Given double value as string
- */
-char *DoubleToString(const double decimal) {
-	static char buffer[sizeof(double) * 8 + 1]; // malloc might work better
-	memset(buffer, 0, sizeof(buffer));
-
-	SDL_snprintf(buffer, sizeof(buffer), "%.5f", decimal);
-
-	return buffer;
-}
-
-/*!
- * Converts unix timestamp to it's ascii presentation
- *
- * \param timestamp Timestamp
- * \return Ascii presentation
- */
-char *TimestampToString(const time_t timestamp) {
-	static char buffer[1024];
-	//char *buffer = SDL_malloc(1024);
-	memset(buffer, 0, 1024);
-
-	time_t copy = timestamp;
-
-	struct tm *local = localtime(&copy);
-	strftime(buffer, 1024, "%a %Y-%m-%d %H:%M:%S %Z", local);
-
-	return buffer;
-}
-
 static int indentLevel;
 
 //! Constants for XMLOuputters EOL parameter
@@ -397,7 +348,7 @@
 
 	if(testResult) {
 		if(testResult == 2) {
-			output = XMLAddContent("failed -> no assert");
+			output = XMLAddContent("failed. No assert");
 		} else {
 			output = XMLAddContent("failed");
 		}
@@ -439,9 +390,6 @@
 	XMLOutputter(--indentLevel, YES, output);
 	SDL_free(output);
 
-
-	//! \todo add endTime and TotalRuntime
-
 	output = XMLCloseElement("test");
 	XMLOutputter(--indentLevel, YES, output);
 	SDL_free(output);
@@ -449,7 +397,7 @@
 
 void
 XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
-       time_t eventTime)
+		  time_t eventTime)
 {
 	char *output = XMLOpenElement("assert");
 	XMLOutputter(indentLevel++, YES, output);
@@ -500,6 +448,59 @@
 }
 
 void
+XMLAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
+		int actualValue, int excpected, time_t eventTime)
+{
+	char *output = XMLOpenElement("assert");
+	XMLOutputter(indentLevel++, YES, output);
+	SDL_free(output);
+
+	// log assert result
+	output = XMLOpenElement("result");
+	XMLOutputter(indentLevel++, NO, output);
+	SDL_free(output);
+
+	output = XMLAddContent((assertResult) ? "pass" : "failure");
+	XMLOutputter(indentLevel, NO, output);
+	SDL_free(output);
+
+	output = XMLCloseElement("result");
+	XMLOutputter(--indentLevel, YES, output);
+	SDL_free(output);
+
+	// log assert message
+	output = XMLOpenElement("message");
+	XMLOutputter(indentLevel++, NO, output);
+	SDL_free(output);
+
+	output = XMLAddContent(assertMessage);
+	XMLOutputter(indentLevel, NO, output);
+	SDL_free(output);
+
+	output = XMLCloseElement("message");
+	XMLOutputter(--indentLevel, YES, output);
+	SDL_free(output);
+
+	// log event time
+	output = XMLOpenElement("eventTime");
+	XMLOutputter(indentLevel++, NO, output);
+	SDL_free(output);
+
+	output = XMLAddContent(TimestampToString(eventTime));
+	XMLOutputter(indentLevel, NO, output);
+	SDL_free(output);
+
+	output = XMLCloseElement("eventTime");
+	XMLOutputter(--indentLevel, YES, output);
+	SDL_free(output);
+
+	output = XMLCloseElement("assert");
+	XMLOutputter(--indentLevel, YES, output);
+	SDL_free(output);
+}
+
+
+void
 XMLAssertSummary(int numAsserts, int numAssertsFailed,
 				 int numAssertsPass, time_t eventTime)
 {
--- a/test/test-automation/xml_logger.h	Mon Jun 27 21:41:34 2011 +0300
+++ b/test/test-automation/xml_logger.h	Mon Jun 27 22:14:48 2011 +0300
@@ -19,7 +19,11 @@
           int testResult, time_t endTime, double totalRuntime);
 
 void XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
-       time_t eventTime);
+			time_t eventTime);
+
+void XMLAssertWithValues(const char *assertName, int assertResult, const char *assertMessage,
+		int actualValue, int excpected, time_t eventTime);
+
 
 void XMLAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass, time_t eventTime);