Commit e2799bbb authored by Markus Kauppila's avatar Markus Kauppila

Added case insensitivity to XML elements.

parent 7b600bf8
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <SDL/SDL.h>
#include "logger.h" #include "logger.h"
#include "xml_logger.h" #include "xml_logger.h"
#include "plain_logger.h" #include "plain_logger.h"
...@@ -25,9 +27,15 @@ LogFp Log = 0; ...@@ -25,9 +27,15 @@ LogFp Log = 0;
* \return Possible error value (\todo) * \return Possible error value (\todo)
*/ */
int int
LogGenericOutput(const char *message) LogGenericOutput(const char *message, ...)
{ {
fprintf(stderr, "%s\n", 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); fflush(stderr);
} }
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <time.h> #include <time.h>
// Function pointer to function which handles to output // Function pointer to function which handles to output
typedef int (*LogOutputFp)(const char *); typedef int (*LogOutputFp)(const char *, ...);
/*! /*!
......
...@@ -25,14 +25,14 @@ PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCoun ...@@ -25,14 +25,14 @@ PlainRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCoun
void void
PlainSuiteStarted(const char *suiteName, time_t eventTime) PlainSuiteStarted(const char *suiteName, time_t eventTime)
{ {
printf("Executing tests in %s\n", suiteName); logger("Executing tests in %s\n", suiteName);
} }
void void
PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped, PlainSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
double endTime, time_t totalRuntime) double endTime, time_t totalRuntime)
{ {
printf("Suite executed. %d passed, %d failed and %d skipped\n", testsPassed, testsFailed, testsSkipped); logger("Suite executed. %d passed, %d failed and %d skipped\n", testsPassed, testsFailed, testsSkipped);
} }
void void
...@@ -44,8 +44,8 @@ void ...@@ -44,8 +44,8 @@ void
PlainTestEnded(const char *testName, const char *suiteName, PlainTestEnded(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)
{ {
printf("Asserts:%d\n", numAsserts); logger("Asserts:%d\n", numAsserts);
printf("%s: ok\n", testName); logger("%s: ok\n", testName);
} }
void void
...@@ -53,7 +53,7 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage, ...@@ -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 %d: %s\n", assertName, assertResult, assertMessage); logger("%s %d: %s\n", assertName, assertResult, assertMessage);
} }
void void
......
...@@ -53,7 +53,10 @@ AddOpenTag(const char *tag) ...@@ -53,7 +53,10 @@ AddOpenTag(const char *tag)
} }
memset(openTag, 0, sizeof(TagList)); memset(openTag, 0, sizeof(TagList));
openTag->tag = tag; // Should be fine without malloc? const int tagSize = SDL_strlen(tag) + 1;
openTag->tag = SDL_malloc(tagSize);
strncpy(openTag->tag, tag, tagSize);
openTag->next = openTags; openTag->next = openTags;
openTags = openTag; openTags = openTag;
...@@ -75,15 +78,27 @@ RemoveOpenTag(const char *tag) ...@@ -75,15 +78,27 @@ RemoveOpenTag(const char *tag)
int retVal = 0; int retVal = 0;
const int size = SDL_strlen(tag);
char *tempTag = SDL_malloc(size);
strncpy(tempTag, tag, size);
// Tag should always be the same as previously opened tag // Tag should always be the same as previously opened tag
// It prevents opening and ending tag mismatch // It prevents opening and ending tag mismatch
if(SDL_strcmp(openTags->tag, tag) == 0) { if(SDL_strcmp(tempTag, tag) == 0) {
TagList *openTag = openTags; TagList *openTag = openTags;
openTags = openTags->next; SDL_free(openTag->tag);
free(openTag); /*
int counter = 0;
for(; counter < strlen(buffer); ++counter) {
buffer[counter] = tolower(buffer[counter]);
}
*/
openTags = openTags->next;
SDL_free(openTag);
} else { } else {
printf("Debug | RemoveOpenTag(): open/end tag mismatch"); //printf("Debug | xml.c:RemoveOpenTag(): open/end tag mismatch");
retVal = 1; retVal = 1;
} }
...@@ -153,7 +168,30 @@ const char *EscapeString(const char *string) { ...@@ -153,7 +168,30 @@ const char *EscapeString(const char *string) {
return stringBuffer; return stringBuffer;
} }
/*! Turns all the characters of the given
* string to lowercase and returns the resulting string.
*
* \param string String to be converted
* \return Lower-case version of the given string
*/
char *
ToLowerCase(char *string)
{
const int size = SDL_strlen(string);
char *ret = SDL_malloc(size + 1);
strncpy(ret, string, size);
ret[size] = '\0';
// turn the tag to lower case for case-insensitive comparation
int counter = 0;
for(; counter < size; ++counter) {
ret[counter] = tolower(ret[counter]);
}
// printf("Debug: %s == %s\n", string, ret);
return ret;
}
/* /*
=================== ===================
...@@ -177,7 +215,6 @@ XMLOpenDocument(const char *rootTag) ...@@ -177,7 +215,6 @@ XMLOpenDocument(const char *rootTag)
memset(buffer, 0, bufferSize); memset(buffer, 0, bufferSize);
snprintf(buffer, bufferSize, "<%s>", rootTag); snprintf(buffer, bufferSize, "<%s>", rootTag);
//logger(buffer);
AddOpenTag(rootTag); AddOpenTag(rootTag);
...@@ -217,25 +254,6 @@ XMLOpenElement(const char *tag) ...@@ -217,25 +254,6 @@ XMLOpenElement(const char *tag)
return ret; return ret;
} }
char *
XMLOpenElementWithAttribute(const char *tag, Attribute *attribute)
{
memset(buffer, 0, bufferSize);
snprintf(buffer, bufferSize, "<%s %s='%s'>", tag,
attribute->attribute, attribute->value);
logger(buffer);
AddOpenTag(tag);
const int size = SDL_strlen(buffer);
char *ret = SDL_malloc(size + 1);
strncpy(ret, buffer, size);
ret[size] = '\0';
return ret;
}
char * char *
XMLAddContent(const char *content) XMLAddContent(const char *content)
{ {
...@@ -265,22 +283,29 @@ XMLCloseElement(const char *tag) ...@@ -265,22 +283,29 @@ XMLCloseElement(const char *tag)
while(openTag) { while(openTag) {
TagList *temp = openTag->next; TagList *temp = openTag->next;
memset(buffer, 0, bufferSize); char *lowOpenTag = ToLowerCase(openTag->tag);
snprintf(buffer, bufferSize, "</%s>", openTag->tag); char *lowTag = ToLowerCase(tag);
// \todo use strNcat const int openTagSize = SDL_strlen(lowOpenTag);
strcat(ret, buffer); const int tagSize = SDL_strlen(lowTag);
//logger(buffer);
const int openTagSize = SDL_strlen(openTag->tag);
const int tagSize = SDL_strlen(tag);
const int compSize = (openTagSize > tagSize) ? openTagSize : tagSize; const int compSize = (openTagSize > tagSize) ? openTagSize : tagSize;
memset(buffer, 0, bufferSize);
int breakOut = 0; int breakOut = 0;
if(SDL_strncmp(openTag->tag, tag, compSize) == 0) { if(SDL_strncmp(lowOpenTag, lowTag, compSize) == 0) {
breakOut = 1; breakOut = 1;
snprintf(buffer, bufferSize, "</%s>", tag);
} else {
snprintf(buffer, bufferSize, "</%s>", openTag->tag);
} }
SDL_free(lowOpenTag);
SDL_free(lowTag);
// \todo use strNcat
strcat(ret, buffer);
RemoveOpenTag(openTag->tag); RemoveOpenTag(openTag->tag);
openTag = temp; openTag = temp;
......
...@@ -53,11 +53,6 @@ char *XMLCloseDocument(); ...@@ -53,11 +53,6 @@ char *XMLCloseDocument();
*/ */
char *XMLOpenElement(const char *tag); char *XMLOpenElement(const char *tag);
/*!
* Opens XML-element with given attributes
*/
char *XMLOpenElementWithAttribute(const char *tag, Attribute *attribute);
/*! /*!
* Add content to currently open element. * Add content to currently open element.
* *
......
...@@ -32,11 +32,11 @@ XMLRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTi ...@@ -32,11 +32,11 @@ XMLRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTi
{ {
logger = outputFn; logger = outputFn;
char *output = XMLOpenDocument("testlog"); char *output = XMLOpenDocument("teSTtlog");
logger(output); logger(output);
SDL_free(output); SDL_free(output);
output = XMLOpenElement("parameters"); output = XMLOpenElement("paRameters");
logger(output); logger(output);
SDL_free(output); SDL_free(output);
...@@ -44,7 +44,7 @@ XMLRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTi ...@@ -44,7 +44,7 @@ XMLRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTi
logger(output); logger(output);
SDL_free(output); SDL_free(output);
output = XMLCloseElement("parameters"); output = XMLCloseElement("Parameters");
logger(output); logger(output);
SDL_free(output); SDL_free(output);
} }
...@@ -53,7 +53,7 @@ void ...@@ -53,7 +53,7 @@ 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)
{ {
char *output = XMLCloseDocument("testlog"); char *output = XMLCloseDocument("testlOg");
logger(output); logger(output);
SDL_free(output); SDL_free(output);
} }
...@@ -65,12 +65,12 @@ XMLSuiteStarted(const char *suiteName, time_t eventTime) ...@@ -65,12 +65,12 @@ XMLSuiteStarted(const char *suiteName, time_t eventTime)
logger(output); logger(output);
SDL_free(output); SDL_free(output);
output = XMLOpenElement("eventTime"); output = XMLOpenElement("EVENTTime");
logger(output); logger(output);
SDL_free(output); SDL_free(output);
//XMLAddContent(evenTime); //XMLAddContent(evenTime);
output = XMLCloseElement("eventTime"); output = XMLCloseElement("eventTIME");
logger(output); logger(output);
SDL_free(output); SDL_free(output);
} }
...@@ -91,7 +91,6 @@ XMLTestStarted(const char *testName, const char *suiteName, const char *testDesc ...@@ -91,7 +91,6 @@ XMLTestStarted(const char *testName, const char *suiteName, const char *testDesc
logger(output); logger(output);
SDL_free(output); SDL_free(output);
//Attribute attribute = {"test", "value"}; //Attribute attribute = {"test", "value"};
//XMLOpenElementWithAttribute("name", &attribute); //XMLOpenElementWithAttribute("name", &attribute);
output = XMLOpenElement("name"); output = XMLOpenElement("name");
...@@ -111,7 +110,6 @@ XMLTestStarted(const char *testName, const char *suiteName, const char *testDesc ...@@ -111,7 +110,6 @@ XMLTestStarted(const char *testName, const char *suiteName, const char *testDesc
logger(output); logger(output);
SDL_free(output); SDL_free(output);
output = XMLAddContent(testDescription); output = XMLAddContent(testDescription);
logger(output); logger(output);
SDL_free(output); SDL_free(output);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment