Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added identation to the output of XML logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkauppila committed Jun 27, 2011
1 parent f7633bd commit add4c01
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 107 deletions.
21 changes: 1 addition & 20 deletions test/test-automation/logger.c
Expand Up @@ -57,25 +57,6 @@ SetupPlainLogger()
Log = PlainLog;
}

/*!
* Prints the given message to stderr. Function adds nesting
* to the output.
*
* \return Possible error value (\todo)
*/
int
LogGenericOutput(const char *message, ...)
{
va_list list;
va_start(list, message);

char buffer[1024];
SDL_vsnprintf(buffer, sizeof(buffer), message, list);

fprintf(stderr, "%s\n", buffer);
fflush(stderr);
}

#if 0
/*!
* Test app for logging functionality
Expand All @@ -91,7 +72,7 @@ main(int argc, char *argv[])
SetupPlainLogger();
}

RunStarted(LogGenericOutput, "some_<data_>here&here", 0);
RunStarted(Output, "some_<data_>here&here", 0);
SuiteStarted("Suite data here", 0);

TestStarted("test1", "suite", "desc", 0);
Expand Down
2 changes: 1 addition & 1 deletion test/test-automation/logger.h
Expand Up @@ -54,7 +54,7 @@ typedef void (*AssertSummaryFp)(int numAsserts, int numAssertsFailed, int numAss

typedef void (*LogFp)(const char *logMessage, time_t eventTime);

int LogGenericOutput(const char *message, ...);
int Output(const char *message, ...);

extern RunStartedFp RunStarted;
extern RunEndedFp RunEnded;
Expand Down
46 changes: 31 additions & 15 deletions test/test-automation/plain_logger.c
Expand Up @@ -4,73 +4,89 @@

#include <stdio.h>

#include <SDL/SDL.h>

#include "plain_logger.h"


LogOutputFp logger = 0;
/*!
* Pritns out the output of the logger
* \return Possible error value (\todo)
*/
int
Output(const char *message, ...)
{
va_list list;
va_start(list, message);

char buffer[1024];
SDL_vsnprintf(buffer, sizeof(buffer), message, list);

fprintf(stderr, "%s\n", buffer);
fflush(stderr);
}

void
PlainRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime)
PlainRunStarted(const char *runnerParameters, time_t eventTime)
{
logger = outputFn;
logger("Test run started");
logger("Given command line options: %s", "add options");
Output("Test run started");
Output("Given command line options: %s", "add options");
}

void
PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
time_t endTime, time_t totalRuntime)
{
logger("Ran %d tests in %0.5f seconds.", testCount, totalRuntime);
Output("Ran %d tests in %0.5f seconds.", testCount, totalRuntime);

logger("%d tests passed", testPassCount);
logger("%d tests failed", testFailCount);
Output("%d tests passed", testPassCount);
Output("%d tests failed", testFailCount);
}

void
PlainSuiteStarted(const char *suiteName, time_t eventTime)
{
logger("Executing tests in %s", suiteName);
Output("Executing tests in %s", suiteName);
}

void
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
double endTime, time_t totalRuntime)
{
logger("Suite executed. %d passed, %d failed and %d skipped", testsPassed, testsFailed, testsSkipped);
Output("Suite executed. %d passed, %d failed and %d skipped", testsPassed, testsFailed, testsSkipped);
}

void
PlainTestStarted(const char *testName, const char *suiteName, const char *testDescription, time_t startTime)
{
logger("test %s (in %s) started", testName, suiteName);
Output("test %s (in %s) started", testName, suiteName);
}

void
PlainTestEnded(const char *testName, const char *suiteName,
int testResult, time_t endTime, time_t totalRuntime)
{
logger("%s: ok", testName);
Output("%s: ok", testName);
}

void
PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
time_t eventTime)
{
const char *result = (assertResult) ? "passed" : "failed";
logger("%s %d: %s", assertName, assertResult, assertMessage);
Output("%s %d: %s", assertName, assertResult, assertMessage);
}

void
PlainAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass)
{
logger("Asserts:%d", numAsserts);
Output("Asserts:%d", numAsserts);
}

void
PlainLog(const char *logMessage, time_t eventTime)
{
logger("%s %d", logMessage, eventTime);
Output("%s %d", logMessage, eventTime);
}

#endif
2 changes: 1 addition & 1 deletion test/test-automation/plain_logger.h
Expand Up @@ -3,7 +3,7 @@

#include "logger.h"

void PlainRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime);
void PlainRunStarted(const char *runnerParameters, time_t eventTime);

void PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
time_t endTime, time_t totalRuntime);
Expand Down
4 changes: 3 additions & 1 deletion test/test-automation/runner.c
Expand Up @@ -670,7 +670,7 @@ main(int argc, char *argv[])
return 0;
}

RunStarted(LogGenericOutput, NULL, 0);
RunStarted(Output, NULL, 0);

char *currentSuiteName = NULL;

Expand Down Expand Up @@ -708,6 +708,8 @@ main(int argc, char *argv[])
}
}

SuiteEnded(0, 0, 0, 0.0f, 0);

UnloadTestCases(testCases);
UnloadTestSuites(suites);

Expand Down
21 changes: 16 additions & 5 deletions test/test-automation/xml.c
Expand Up @@ -153,8 +153,14 @@ const char *EscapeString(const char *string) {
while(token) {
char *nextToken = strtok(NULL, character);

//! \todo use strncat and count the bytes left in the buffer
strcat(buffer, token);
int bytesLeft = bufferSize - SDL_strlen(buffer);
if(bytesLeft) {
strncat(buffer, token, bytesLeft);
} else {
// \! todo there's probably better way to report an error?
fprintf(stderr, "xml.c | EscapingString: Buffer is full");
}

if(nextToken)
strcat(buffer, entity);

Expand Down Expand Up @@ -211,7 +217,7 @@ static char buffer[bufferSize];
char *
XMLOpenDocument(const char *rootTag)
{
const char *doctype = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
const char *doctype = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";

memset(buffer, 0, bufferSize);
snprintf(buffer, bufferSize, "<%s>", rootTag);
Expand Down Expand Up @@ -303,8 +309,13 @@ XMLCloseElement(const char *tag)
SDL_free(lowOpenTag);
SDL_free(lowTag);

// \todo use strNcat
strcat(ret, buffer);
int bytesLeft = bufferSize - SDL_strlen(ret);
if(bytesLeft) {
strncat(ret, buffer, bytesLeft);
} else {
// \! todo there's probably better way to report an error?
fprintf(stderr, "xml.c | XMLCloseElement: Buffer is full");
}

RemoveOpenTag(openTag->tag);

Expand Down

0 comments on commit add4c01

Please sign in to comment.