Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Various fixes and additions to logger system.
- Loading branch information
|
@@ -8,7 +8,7 @@ runner_CLAGS = -W -Wall -Wextra -g `sdl-config --cflags` -DSDL_NO_COMPAT |
|
|
runner_LDFLAGS = `sdl-config --libs` |
|
|
|
|
|
bin_PROGRAMS = logger |
|
|
logger_SOURCES = xml_logger.c xml.c |
|
|
logger_SOURCES = xml_logger.c xml.c plain_logger.c logger.c |
|
|
logger_CLAGS = -W -Wall -Wextra -g `sdl-config --cflags` -DSDL_NO_COMPAT |
|
|
logger_LDFLAGS = `sdl-config --libs` |
|
|
|
|
|
|
|
@@ -0,0 +1,89 @@ |
|
|
|
|
|
#include <stdio.h> |
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
#include <stdarg.h> |
|
|
|
|
|
#include "logger.h" |
|
|
#include "xml_logger.h" |
|
|
#include "plain_logger.h" |
|
|
|
|
|
// Pointers to selected logger implementation |
|
|
RunStartedFp RunStarted = 0; |
|
|
RunEndedFp RunEnded = 0; |
|
|
SuiteStartedFp SuiteStarted = 0; |
|
|
SuiteEndedFp SuiteEnded = 0; |
|
|
TestStartedFp TestStarted = 0; |
|
|
TestEndedFp TestEnded = 0; |
|
|
AssertFp Assert = 0; |
|
|
LogFp Log = 0; |
|
|
|
|
|
/*! |
|
|
* Prints the given message to stderr. Function adds nesting |
|
|
* to the output. |
|
|
* |
|
|
* \return Possible error value (\todo) |
|
|
*/ |
|
|
int |
|
|
LogGenericOutput(const char *message) |
|
|
{ |
|
|
/* |
|
|
int depth = indentDepth; |
|
|
while(depth--) { |
|
|
fprintf(stderr, " "); |
|
|
} |
|
|
*/ |
|
|
|
|
|
fprintf(stderr, "%s\n", message); |
|
|
fflush(stderr); |
|
|
} |
|
|
|
|
|
|
|
|
/*! |
|
|
* Test app for logging functionality |
|
|
*/ |
|
|
int |
|
|
main(int argc, char *argv[]) |
|
|
{ |
|
|
int xml_enabled = 1; |
|
|
|
|
|
if(xml_enabled) { |
|
|
RunStarted = XMLRunStarted; |
|
|
RunEnded = XMLRunEnded; |
|
|
|
|
|
SuiteStarted = XMLSuiteStarted; |
|
|
SuiteEnded = XMLSuiteEnded; |
|
|
|
|
|
TestStarted = XMLTestStarted; |
|
|
TestEnded = XMLTestEnded; |
|
|
|
|
|
Assert = XMLAssert; |
|
|
Log = XMLLog; |
|
|
} else { |
|
|
RunStarted = PlainRunStarted; |
|
|
RunEnded = PlainRunEnded; |
|
|
|
|
|
SuiteStarted = PlainSuiteStarted; |
|
|
SuiteEnded = PlainSuiteEnded; |
|
|
|
|
|
TestStarted = PlainTestStarted; |
|
|
TestEnded = PlainTestEnded; |
|
|
|
|
|
Assert = PlainAssert; |
|
|
Log = PlainLog; |
|
|
} |
|
|
|
|
|
RunStarted(LogGenericOutput, "All the data from harness", 0); |
|
|
SuiteStarted("Suite data here", 0); |
|
|
|
|
|
TestStarted("test1", "desc", 0); |
|
|
TestEnded("test1", "desc", 0, 0, 0, 0); |
|
|
|
|
|
//XMLTestStarted("test2", "desc", 0); |
|
|
//XMLTestEnded("test2", "desc", 0, 0, 0, 0); |
|
|
|
|
|
SuiteEnded(0, 0, 0, 0.0f, 0); |
|
|
RunEnded(0, 0); |
|
|
|
|
|
return 0; |
|
|
} |
|
@@ -26,25 +26,26 @@ |
|
|
// Function pointer to function which handles to output |
|
|
typedef int (*LogOutputFp)(const char *); |
|
|
|
|
|
|
|
|
/*! |
|
|
* Generic logger interface |
|
|
* |
|
|
*/ |
|
|
void RunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime); |
|
|
void RunEnded(time_t endTime, time_t totalRuntime); |
|
|
typedef void (*RunStartedFp)(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime); |
|
|
typedef void (*RunEndedFp)(time_t endTime, time_t totalRuntime); |
|
|
|
|
|
void SuiteStarted(const char *suiteName, time_t eventTime); |
|
|
void SuiteEnded(int testsPassed, int testsFailed, int testsSkipped, |
|
|
double endTime, time_t totalRuntime); |
|
|
typedef void (*SuiteStartedFp)(const char *suiteName, time_t eventTime); |
|
|
typedef void (*SuiteEndedFp)(int testsPassed, int testsFailed, int testsSkipped, |
|
|
double endTime, time_t totalRuntime); |
|
|
|
|
|
void TestStarted(const char *testName, const char *testDescription, time_t startTime); |
|
|
void TestEnded(const char *testName, const char *testDescription, int testResult, |
|
|
int numAsserts, time_t endTime, time_t totalRuntime); |
|
|
typedef void (*TestStartedFp)(const char *testName, const char *testDescription, time_t startTime); |
|
|
typedef void (*TestEndedFp)(const char *testName, const char *testDescription, int testResult, |
|
|
int numAsserts, time_t endTime, time_t totalRuntime); |
|
|
|
|
|
void Assert(const char *assertName, int assertResult, const char *assertMessage, |
|
|
time_t eventTime); |
|
|
typedef void (*AssertFp)(const char *assertName, int assertResult, const char *assertMessage, |
|
|
time_t eventTime); |
|
|
|
|
|
void Log(const char *logMessage, time_t eventTime); |
|
|
typedef void (*LogFp)(const char *logMessage, time_t eventTime); |
|
|
|
|
|
|
|
|
#endif |
|
|
@@ -0,0 +1,63 @@ |
|
|
|
|
|
#ifndef _PLAIN_LOGGER |
|
|
#define _PLAIN_LOGGER |
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
#include "plain_logger.h" |
|
|
|
|
|
|
|
|
LogOutputFp logger = 0; |
|
|
|
|
|
void |
|
|
PlainRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime) |
|
|
{ |
|
|
logger = outputFn; |
|
|
} |
|
|
|
|
|
void |
|
|
PlainRunEnded(time_t endTime, time_t totalRuntime) |
|
|
{ |
|
|
// \todo add total number of tests, suites, pass/failure test count |
|
|
} |
|
|
|
|
|
void |
|
|
PlainSuiteStarted(const char *suiteName, time_t eventTime) |
|
|
{ |
|
|
printf("Executing tests in %s\n", suiteName); |
|
|
} |
|
|
|
|
|
void |
|
|
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, |
|
|
double endTime, time_t totalRuntime) |
|
|
{ |
|
|
printf("Suite executed. %d passed, %d failed and %d skipped\n", testsPassed, testsFailed, testsSkipped); |
|
|
} |
|
|
|
|
|
void |
|
|
PlainTestStarted(const char *testName, const char *testDescription, time_t startTime) |
|
|
{ |
|
|
} |
|
|
|
|
|
void |
|
|
PlainTestEnded(const char *testName, const char *testDescription, |
|
|
int testResult, int numAsserts, time_t endTime, time_t totalRuntime) |
|
|
{ |
|
|
printf("Asserts:%d\n", numAsserts); |
|
|
printf("%s: ok\n", testName); |
|
|
} |
|
|
|
|
|
void |
|
|
PlainAssert(const char *assertName, int assertResult, const char *assertMessage, |
|
|
time_t eventTime) |
|
|
{ |
|
|
const char *result = (assertResult) ? "passed" : "failed"; |
|
|
printf("%s %s: %s\n", assertName, assertResult, assertMessage); |
|
|
} |
|
|
|
|
|
void |
|
|
PlainLog(const char *logMessage, time_t eventTime) |
|
|
{ |
|
|
} |
|
|
|
|
|
#endif |
|
|
@@ -0,0 +1,25 @@ |
|
|
#ifndef _PLAIN_LOGGER_H |
|
|
#define _PLAIN_LOGGER_H |
|
|
|
|
|
#include "logger.h" |
|
|
|
|
|
void PlainRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime); |
|
|
|
|
|
void PlainRunEnded(time_t endTime, time_t totalRuntime); |
|
|
|
|
|
void PlainSuiteStarted(const char *suiteName, time_t eventTime); |
|
|
|
|
|
void PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, |
|
|
double endTime, time_t totalRuntime); |
|
|
|
|
|
void PlainTestStarted(const char *testName, const char *testDescription, time_t startTime); |
|
|
|
|
|
void PlainTestEnded(const char *testName, const char *testDescription, |
|
|
int testResult, int numAsserts, time_t endTime, time_t totalRuntime); |
|
|
|
|
|
void PlainAssert(const char *assertName, int assertResult, const char *assertMessage, |
|
|
time_t eventTime); |
|
|
|
|
|
void PlainLog(const char *logMessage, time_t eventTime); |
|
|
|
|
|
#endif |
|
@@ -19,10 +19,11 @@ |
|
|
*/ |
|
|
|
|
|
|
|
|
#ifndef _XML_C |
|
|
#define _XML_C |
|
|
|
|
|
#include <stdio.h> |
|
|
//#include <stdlib.h> |
|
|
#include <string.h> |
|
|
//#include <stdarg.h> |
|
|
#include <assert.h> |
|
|
|
|
|
#include <SDL/SDL.h> |
|
@@ -110,12 +111,12 @@ PrintOpenTags() |
|
|
/* |
|
|
=================== |
|
|
|
|
|
XML |
|
|
Functions to handle XML creation |
|
|
|
|
|
=================== |
|
|
*/ |
|
|
|
|
|
static int has_open_element = 0; |
|
|
static const char *root; |
|
|
|
|
|
void |
|
|
XMLOpenDocument(const char *rootTag, LogOutputFp log) |
|
@@ -133,29 +134,15 @@ XMLOpenDocument(const char *rootTag, LogOutputFp log) |
|
|
|
|
|
// add open tag |
|
|
AddOpenTag(rootTag); |
|
|
|
|
|
root = rootTag; // it's fine, as long as rootTag points to static memory? |
|
|
} |
|
|
|
|
|
void |
|
|
XMLCloseDocument() { |
|
|
// Close the open tags with proper nesting |
|
|
TagList *openTag = openTags; |
|
|
while(openTag) { |
|
|
TagList *temp = openTag->next; |
|
|
|
|
|
size_t size = SDL_strlen(openTag->tag) + 4 + 1; /* one extra for '\0', '<', '/' and '>' */ |
|
|
char *buffer = SDL_malloc(size); |
|
|
snprintf(buffer, size, "%s%s%s", "</", openTag->tag, ">"); |
|
|
logger(buffer); |
|
|
SDL_free(buffer); |
|
|
|
|
|
RemoveOpenTag(openTag->tag); |
|
|
|
|
|
openTag = temp; |
|
|
} |
|
|
XMLCloseElement(root); |
|
|
} |
|
|
|
|
|
static const char *currentTag = NULL; |
|
|
|
|
|
void |
|
|
XMLOpenElement(const char *tag) |
|
|
{ |
|
@@ -165,10 +152,6 @@ XMLOpenElement(const char *tag) |
|
|
logger(buffer); |
|
|
SDL_free(buffer); |
|
|
|
|
|
currentTag = tag; |
|
|
|
|
|
has_open_element = 1; |
|
|
|
|
|
AddOpenTag(tag); |
|
|
} |
|
|
|
|
@@ -183,21 +166,13 @@ XMLOpenElementWithAttribute(const char *tag, Attribute attribute) |
|
|
logger(buffer); |
|
|
SDL_free(buffer); |
|
|
|
|
|
currentTag = tag; |
|
|
|
|
|
has_open_element = 1; |
|
|
|
|
|
AddOpenTag(tag); |
|
|
} |
|
|
|
|
|
//! \todo make this static and remove from interface? |
|
|
void |
|
|
XMLAddAttribute(const char *attribute, const char *value) |
|
|
{ |
|
|
// Requires open element |
|
|
if(has_open_element == 0) { |
|
|
return ; |
|
|
} |
|
|
size_t attributeSize = SDL_strlen(attribute); |
|
|
size_t valueSize = SDL_strlen(value); |
|
|
|
|
@@ -249,6 +224,7 @@ XMLCloseElement(const char *tag) |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
has_open_element = 0; |
|
|
} |
|
|
|
|
|
|
|
|
#endif |
|
@@ -67,10 +67,11 @@ void XMLAddAttribute(const char *attribute, const char *value); |
|
|
void XMLAddContent(const char *content); |
|
|
|
|
|
/*! |
|
|
* Closes previously opened element. |
|
|
* Enforces proper nesting by not allowing end elements haphazardly. |
|
|
* Closes previously opened element until tag given as parameter is met. |
|
|
* Enforces proper nesting by not allowing to close elements out-of-order. |
|
|
* |
|
|
* Closes all the opened elements until the given element/tag is found |
|
|
* which will be the last tag to be closed |
|
|
* |
|
|
* \param tag Element to close |
|
|
*/ |
|
|
Oops, something went wrong.