Plain logger refined.
This commit is contained in:
parent
fd3b97e2ff
commit
7494225e7b
7 changed files with 173 additions and 74 deletions
|
@ -57,7 +57,6 @@ _TestCaseInit(const int enable_xml_logging)
|
|||
int
|
||||
_TestCaseQuit()
|
||||
{
|
||||
//printf("Asserts: passed %d, failed %d\n", _testAssertsPassed, _testAssertsFailed);
|
||||
AssertSummary(_testAssertsFailed + _testAssertsPassed,
|
||||
_testAssertsFailed, _testAssertsPassed, time(0));
|
||||
|
||||
|
@ -78,14 +77,13 @@ AssertEquals(Uint32 expected, Uint32 actual, char* message, ...)
|
|||
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++;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ SuiteEndedFp SuiteEnded = 0;
|
|||
TestStartedFp TestStarted = 0;
|
||||
TestEndedFp TestEnded = 0;
|
||||
AssertFp Assert = 0;
|
||||
AssertWithValuesFp AssertWithValues = 0;
|
||||
AssertSummaryFp AssertSummary = 0;
|
||||
LogFp Log = 0;
|
||||
|
||||
|
@ -34,6 +35,7 @@ SetupXMLLogger()
|
|||
TestEnded = XMLTestEnded;
|
||||
|
||||
Assert = XMLAssert;
|
||||
AssertWithValues = XMLAssertWithValues;
|
||||
AssertSummary = XMLAssertSummary;
|
||||
|
||||
Log = XMLLog;
|
||||
|
@ -52,11 +54,45 @@ SetupPlainLogger()
|
|||
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(©);
|
||||
strftime(buffer, 1024, "%a %Y-%m-%d %H:%M:%S %Z", local);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*!
|
||||
* Test app for logging functionality
|
||||
|
|
|
@ -46,10 +46,14 @@ typedef void (*TestEndedFp)(const char *testName, const char *suiteName, int tes
|
|||
*/
|
||||
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 SuiteEndedFp SuiteEnded;
|
|||
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
|
||||
|
|
|
@ -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 @@ Output(const char *message, ...)
|
|||
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 @@ PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCoun
|
|||
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 @@ PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
|
|||
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 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
|
|||
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
|
||||
|
|
|
@ -21,7 +21,10 @@ void PlainTestEnded(const char *testName, const char *suiteName,
|
|||
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -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(©);
|
||||
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 @@ XMLTestEnded(const char *testName, const char *suiteName,
|
|||
|
||||
if(testResult) {
|
||||
if(testResult == 2) {
|
||||
output = XMLAddContent("failed -> no assert");
|
||||
output = XMLAddContent("failed. No assert");
|
||||
} else {
|
||||
output = XMLAddContent("failed");
|
||||
}
|
||||
|
@ -439,9 +390,6 @@ XMLTestEnded(const char *testName, const char *suiteName,
|
|||
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 @@ XMLTestEnded(const char *testName, const char *suiteName,
|
|||
|
||||
void
|
||||
XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
|
||||
time_t eventTime)
|
||||
time_t eventTime)
|
||||
{
|
||||
char *output = XMLOpenElement("assert");
|
||||
XMLOutputter(indentLevel++, YES, output);
|
||||
|
@ -499,6 +447,59 @@ XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
|
|||
SDL_free(output);
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -19,7 +19,11 @@ void XMLTestEnded(const char *testName, const char *suiteName,
|
|||
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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue