XML component no longer outputs the generated XML.
Fixed a bunch of compiler warnings.
This commit is contained in:
parent
eb1a182654
commit
7b600bf889
4 changed files with 162 additions and 54 deletions
|
@ -53,7 +53,7 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
|
||||||
time_t eventTime)
|
time_t eventTime)
|
||||||
{
|
{
|
||||||
const char *result = (assertResult) ? "passed" : "failed";
|
const char *result = (assertResult) ? "passed" : "failed";
|
||||||
printf("%s %s: %s\n", assertName, assertResult, assertMessage);
|
printf("%s %d: %s\n", assertName, assertResult, assertMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -118,7 +118,7 @@ const char *EscapeString(const char *string) {
|
||||||
memset(buffer, 0, bufferSize);
|
memset(buffer, 0, bufferSize);
|
||||||
|
|
||||||
// prevents the code doing a 'bus error'
|
// prevents the code doing a 'bus error'
|
||||||
char stringBuffer[bufferSize];
|
char *stringBuffer = SDL_malloc(bufferSize);
|
||||||
strncpy(stringBuffer, string, bufferSize);
|
strncpy(stringBuffer, string, bufferSize);
|
||||||
|
|
||||||
// Ampersand (&) must be first, otherwise it'll mess up the other entities
|
// Ampersand (&) must be first, otherwise it'll mess up the other entities
|
||||||
|
@ -170,40 +170,55 @@ static const char *root;
|
||||||
/*! Buffer for storing the xml element under construction */
|
/*! Buffer for storing the xml element under construction */
|
||||||
static char buffer[bufferSize];
|
static char buffer[bufferSize];
|
||||||
|
|
||||||
void
|
char *
|
||||||
XMLOpenDocument(const char *rootTag, LogOutputFp log)
|
XMLOpenDocument(const char *rootTag)
|
||||||
{
|
{
|
||||||
assert(log != NULL);
|
const char *doctype = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
|
||||||
logger = log;
|
|
||||||
|
|
||||||
logger("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
|
|
||||||
|
|
||||||
memset(buffer, 0, bufferSize);
|
memset(buffer, 0, bufferSize);
|
||||||
snprintf(buffer, bufferSize, "<%s>", rootTag);
|
snprintf(buffer, bufferSize, "<%s>", rootTag);
|
||||||
logger(buffer);
|
//logger(buffer);
|
||||||
|
|
||||||
AddOpenTag(rootTag);
|
AddOpenTag(rootTag);
|
||||||
|
|
||||||
root = rootTag; // it's fine, as long as rootTag points to static memory?
|
root = rootTag; // it's fine, as long as rootTag points to static memory?
|
||||||
|
|
||||||
|
const int doctypeSize = SDL_strlen(doctype);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
char *
|
||||||
XMLCloseDocument() {
|
XMLCloseDocument() {
|
||||||
XMLCloseElement(root);
|
return XMLCloseElement(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
char *
|
||||||
XMLOpenElement(const char *tag)
|
XMLOpenElement(const char *tag)
|
||||||
{
|
{
|
||||||
memset(buffer, 0, bufferSize);
|
memset(buffer, 0, bufferSize);
|
||||||
snprintf(buffer, bufferSize, "<%s>", tag);
|
snprintf(buffer, bufferSize, "<%s>", tag);
|
||||||
logger(buffer);
|
|
||||||
|
|
||||||
AddOpenTag(tag);
|
AddOpenTag(tag);
|
||||||
|
|
||||||
|
const int size = SDL_strlen(buffer);
|
||||||
|
char *ret = SDL_malloc(size + 1);
|
||||||
|
strncpy(ret, buffer, size);
|
||||||
|
ret[size] = '\0';
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
char *
|
||||||
XMLOpenElementWithAttribute(const char *tag, Attribute *attribute)
|
XMLOpenElementWithAttribute(const char *tag, Attribute *attribute)
|
||||||
{
|
{
|
||||||
memset(buffer, 0, bufferSize);
|
memset(buffer, 0, bufferSize);
|
||||||
|
@ -212,21 +227,38 @@ XMLOpenElementWithAttribute(const char *tag, Attribute *attribute)
|
||||||
logger(buffer);
|
logger(buffer);
|
||||||
|
|
||||||
AddOpenTag(tag);
|
AddOpenTag(tag);
|
||||||
|
|
||||||
|
const int size = SDL_strlen(buffer);
|
||||||
|
char *ret = SDL_malloc(size + 1);
|
||||||
|
strncpy(ret, buffer, size);
|
||||||
|
ret[size] = '\0';
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
char *
|
||||||
XMLAddContent(const char *content)
|
XMLAddContent(const char *content)
|
||||||
{
|
{
|
||||||
const char *escapedContent = EscapeString(content);
|
const char *escapedContent = EscapeString(content);
|
||||||
|
|
||||||
memset(buffer, 0, bufferSize);
|
memset(buffer, 0, bufferSize);
|
||||||
snprintf(buffer, bufferSize, "%s", escapedContent);
|
snprintf(buffer, bufferSize, "%s", escapedContent);
|
||||||
logger(buffer);
|
SDL_free((char *)escapedContent);
|
||||||
|
|
||||||
|
const int size = SDL_strlen(buffer);
|
||||||
|
char *ret = SDL_malloc(size + 1);
|
||||||
|
strncpy(ret, buffer, size);
|
||||||
|
ret[size] = '\0';
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
char *
|
||||||
XMLCloseElement(const char *tag)
|
XMLCloseElement(const char *tag)
|
||||||
{
|
{
|
||||||
|
char *ret = SDL_malloc(bufferSize);
|
||||||
|
memset(ret, 0, bufferSize);
|
||||||
|
|
||||||
// Close the open tags with proper nesting. Closes tags until it finds
|
// Close the open tags with proper nesting. Closes tags until it finds
|
||||||
// the given tag which is the last tag that will be closed
|
// the given tag which is the last tag that will be closed
|
||||||
TagList *openTag = openTags;
|
TagList *openTag = openTags;
|
||||||
|
@ -235,7 +267,10 @@ XMLCloseElement(const char *tag)
|
||||||
|
|
||||||
memset(buffer, 0, bufferSize);
|
memset(buffer, 0, bufferSize);
|
||||||
snprintf(buffer, bufferSize, "</%s>", openTag->tag);
|
snprintf(buffer, bufferSize, "</%s>", openTag->tag);
|
||||||
logger(buffer);
|
|
||||||
|
// \todo use strNcat
|
||||||
|
strcat(ret, buffer);
|
||||||
|
//logger(buffer);
|
||||||
|
|
||||||
const int openTagSize = SDL_strlen(openTag->tag);
|
const int openTagSize = SDL_strlen(openTag->tag);
|
||||||
const int tagSize = SDL_strlen(tag);
|
const int tagSize = SDL_strlen(tag);
|
||||||
|
@ -254,5 +289,7 @@ XMLCloseElement(const char *tag)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,34 +35,35 @@ typedef struct Attribute {
|
||||||
* Creates header and start tag for root element.
|
* Creates header and start tag for root element.
|
||||||
*
|
*
|
||||||
* \param rootTag Root tag for the XML document
|
* \param rootTag Root tag for the XML document
|
||||||
|
* \return The generated XML output
|
||||||
*/
|
*/
|
||||||
void XMLOpenDocument(const char *rootTag, LogOutputFp log);
|
char *XMLOpenDocument(const char *rootTag);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Closes the XML-document.
|
* Closes the XML-document.
|
||||||
* Creates end tag for root element and closes other open elements
|
* Creates end tag for root element and closes other open elements
|
||||||
* with correct nesting.
|
* with correct nesting.
|
||||||
*/
|
*/
|
||||||
void XMLCloseDocument();
|
char *XMLCloseDocument();
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Opens XML-element.
|
* Opens XML-element.
|
||||||
*
|
*
|
||||||
* \param tag Element to be opened
|
* \param tag Element to be opened
|
||||||
*/
|
*/
|
||||||
void XMLOpenElement(const char *tag);
|
char *XMLOpenElement(const char *tag);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Opens XML-element with given attributes
|
* Opens XML-element with given attributes
|
||||||
*/
|
*/
|
||||||
void XMLOpenElementWithAttribute(const char *tag, Attribute *attribute);
|
char *XMLOpenElementWithAttribute(const char *tag, Attribute *attribute);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Add content to currently open element.
|
* Add content to currently open element.
|
||||||
*
|
*
|
||||||
* \param content Content for the currently open element
|
* \param content Content for the currently open element
|
||||||
*/
|
*/
|
||||||
void XMLAddContent(const char *content);
|
char *XMLAddContent(const char *content);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Closes previously opened element until tag given as parameter is met.
|
* Closes previously opened element until tag given as parameter is met.
|
||||||
|
@ -73,7 +74,7 @@ void XMLAddContent(const char *content);
|
||||||
*
|
*
|
||||||
* \param tag Element to close
|
* \param tag Element to close
|
||||||
*/
|
*/
|
||||||
void XMLCloseElement(const char *tag);
|
char *XMLCloseElement(const char *tag);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -18,95 +18,165 @@
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <SDL/SDL.h>
|
||||||
|
|
||||||
#include "xml.h"
|
#include "xml.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
#include "xml_logger.h"
|
#include "xml_logger.h"
|
||||||
|
|
||||||
|
LogOutputFp logger;
|
||||||
|
|
||||||
void
|
void
|
||||||
XMLRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime)
|
XMLRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime)
|
||||||
{
|
{
|
||||||
//! \todo Giving outputFn to the function is awful, fix it
|
logger = outputFn;
|
||||||
//! Make the outputting differently
|
|
||||||
XMLOpenDocument("testlog", outputFn);
|
|
||||||
|
|
||||||
XMLOpenElement("parameters");
|
char *output = XMLOpenDocument("testlog");
|
||||||
XMLAddContent(runnerParameters);
|
logger(output);
|
||||||
XMLCloseElement("parameters");
|
SDL_free(output);
|
||||||
|
|
||||||
|
output = XMLOpenElement("parameters");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
|
output = XMLAddContent(runnerParameters);
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
|
output = XMLCloseElement("parameters");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
|
XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
|
||||||
time_t endTime, time_t totalRuntime)
|
time_t endTime, time_t totalRuntime)
|
||||||
{
|
{
|
||||||
XMLCloseDocument("testlog");
|
char *output = XMLCloseDocument("testlog");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
XMLSuiteStarted(const char *suiteName, time_t eventTime)
|
XMLSuiteStarted(const char *suiteName, time_t eventTime)
|
||||||
{
|
{
|
||||||
XMLOpenElement("suite");
|
char *output = XMLOpenElement("suite");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
|
output = XMLOpenElement("eventTime");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
XMLOpenElement("eventTime");
|
|
||||||
//XMLAddContent(evenTime);
|
//XMLAddContent(evenTime);
|
||||||
XMLCloseElement("eventTime");
|
output = XMLCloseElement("eventTime");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
|
XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
|
||||||
double endTime, time_t totalRuntime)
|
double endTime, time_t totalRuntime)
|
||||||
{
|
{
|
||||||
XMLCloseElement("suite");
|
char *output = XMLCloseElement("suite");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
XMLTestStarted(const char *testName, const char *suiteName, const char *testDescription, time_t startTime)
|
XMLTestStarted(const char *testName, const char *suiteName, const char *testDescription, time_t startTime)
|
||||||
{
|
{
|
||||||
XMLOpenElement("test");
|
char * output = XMLOpenElement("test");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
Attribute attribute = {"test", "value"};
|
|
||||||
|
|
||||||
XMLOpenElementWithAttribute("name", &attribute);
|
//Attribute attribute = {"test", "value"};
|
||||||
XMLAddContent(testName);
|
//XMLOpenElementWithAttribute("name", &attribute);
|
||||||
XMLCloseElement("name");
|
output = XMLOpenElement("name");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
XMLOpenElement("description");
|
output = XMLAddContent(testName);
|
||||||
XMLAddContent(testDescription);
|
logger(output);
|
||||||
XMLCloseElement("description");
|
SDL_free(output);
|
||||||
|
|
||||||
|
output = XMLCloseElement("name");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
|
|
||||||
|
output = XMLOpenElement("description");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
|
|
||||||
|
output = XMLAddContent(testDescription);
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
|
output = XMLCloseElement("description");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
|
output = XMLOpenElement("starttime");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
XMLOpenElement("starttime");
|
|
||||||
//XMLAddContent(startTime);
|
//XMLAddContent(startTime);
|
||||||
XMLCloseElement("starttime");
|
output = XMLCloseElement("starttime");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
XMLTestEnded(const char *testName, const char *suiteName,
|
XMLTestEnded(const char *testName, const char *suiteName,
|
||||||
int testResult, int numAsserts, time_t endTime, time_t totalRuntime)
|
int testResult, int numAsserts, time_t endTime, time_t totalRuntime)
|
||||||
{
|
{
|
||||||
XMLCloseElement("test");
|
char *output = XMLCloseElement("test");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
|
XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
|
||||||
time_t eventTime)
|
time_t eventTime)
|
||||||
{
|
{
|
||||||
XMLOpenElement("assert");
|
char *output = XMLOpenElement("assert");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
XMLOpenElement("result");
|
output = XMLOpenElement("result");
|
||||||
XMLAddContent((assertResult) ? "pass" : "failure");
|
logger(output);
|
||||||
XMLOpenElement("result");
|
SDL_free(output);
|
||||||
|
|
||||||
|
output = XMLAddContent((assertResult) ? "pass" : "failure");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
XMLCloseElement("assert");
|
output = XMLOpenElement("result");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
|
output = XMLCloseElement("assert");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
XMLLog(const char *logMessage, time_t eventTime)
|
XMLLog(const char *logMessage, time_t eventTime)
|
||||||
{
|
{
|
||||||
XMLOpenElement("log");
|
char *output = XMLOpenElement("log");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
XMLAddContent(logMessage);
|
output = XMLAddContent(logMessage);
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
|
|
||||||
XMLCloseElement("log");
|
output = XMLCloseElement("log");
|
||||||
|
logger(output);
|
||||||
|
SDL_free(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue