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

Commit

Permalink
Fixed a few mistakes from XML logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkauppila committed Jun 28, 2011
1 parent dfd6a83 commit 5f206ae
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
21 changes: 13 additions & 8 deletions test/test-automation/xml.c
Expand Up @@ -197,6 +197,9 @@ XMLOpenDocument(const char *rootTag)
{
const char *doctype = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";

//! \todo make this optional (and let the user supply the filename?)
const char *style = "<?xml-stylesheet type=\"text/xsl\" href=\"style.xsl\"?>\n";

memset(buffer, 0, bufferSize);
snprintf(buffer, bufferSize, "<%s>", rootTag);

Expand All @@ -205,16 +208,18 @@ XMLOpenDocument(const char *rootTag)
root = rootTag; // it's fine, as long as rootTag points to static memory?

const int doctypeSize = SDL_strlen(doctype);
const int styleSize = SDL_strlen(style);
const int tagSize = SDL_strlen(buffer);

const int size = doctypeSize + tagSize + 1; // extra byte for '\0'
char *ret = SDL_malloc(size);
// copy doctype
strncpy(ret, doctype, doctypeSize);
// copy tag
strncpy(ret + doctypeSize, buffer, tagSize);
ret[size] = '\0';
return ret;
const int size = doctypeSize + styleSize + tagSize + 1; // extra byte for '\0'
char *retBuf = SDL_malloc(size);

// fill in the previous allocated retBuf
strcat(retBuf, doctype);
strcat(retBuf, style);
strcat(retBuf, buffer);

return retBuf;
}

char *
Expand Down
33 changes: 32 additions & 1 deletion test/test-automation/xml_logger.c
Expand Up @@ -52,7 +52,7 @@ const char *assertElementName = "assert";
const char *messageElementName = "message";
const char *timeElementName = "time";
const char *assertSummaryElementName = "assertSummary";
const char *assertCountElementName = "assertName";
const char *assertCountElementName = "assertCount";
const char *assertsPassedElementName = "assertsPassed";
const char *assertsFailedElementName = "assertsFailed";
const char *logElementName = "log";
Expand Down Expand Up @@ -214,6 +214,15 @@ XMLSuiteStarted(const char *suiteName, time_t eventTime)
char *output = XMLOpenElement(suiteElementName);
XMLOutputter(indentLevel++, YES, output);

output = XMLOpenElement(nameElementName);
XMLOutputter(indentLevel++, NO, output);

output = XMLAddContent(suiteName);
XMLOutputter(indentLevel, NO, output);

output = XMLCloseElement(nameElementName);
XMLOutputter(--indentLevel, YES, output);

output = XMLOpenElement(startTimeElementName);
XMLOutputter(indentLevel++, NO, output);

Expand Down Expand Up @@ -373,6 +382,17 @@ XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
char *output = XMLOpenElement(assertElementName);
XMLOutputter(indentLevel++, YES, output);

// log assert name
output = XMLOpenElement(nameElementName);
XMLOutputter(indentLevel++, NO, output);

output = XMLAddContent(assertName);
XMLOutputter(indentLevel, NO, output);

output = XMLCloseElement(nameElementName);
XMLOutputter(--indentLevel, YES, output);


// log assert result
output = XMLOpenElement(resultElementName);
XMLOutputter(indentLevel++, NO, output);
Expand Down Expand Up @@ -414,6 +434,17 @@ XMLAssertWithValues(const char *assertName, int assertResult, const char *assert
char *output = XMLOpenElement(assertElementName);
XMLOutputter(indentLevel++, YES, output);

// log assert name
output = XMLOpenElement(nameElementName);
XMLOutputter(indentLevel++, NO, output);

output = XMLAddContent(assertName);
XMLOutputter(indentLevel, NO, output);

output = XMLCloseElement(nameElementName);
XMLOutputter(--indentLevel, YES, output);


// log assert result
output = XMLOpenElement(resultElementName);
XMLOutputter(indentLevel++, NO, output);
Expand Down

0 comments on commit 5f206ae

Please sign in to comment.