2011-06-19 18:07:37 +03:00
|
|
|
/*
|
|
|
|
Copyright (C) 2011 Markus Kauppila <markus.kauppila@gmail.com>
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
#include <SDL/SDL.h>
|
|
|
|
|
2011-06-21 22:04:44 +03:00
|
|
|
#include "xml.h"
|
2011-06-19 18:07:37 +03:00
|
|
|
#include "logger.h"
|
|
|
|
|
2011-06-21 22:04:44 +03:00
|
|
|
#include "xml_logger.h"
|
2011-06-19 18:07:37 +03:00
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
/*!
|
|
|
|
* Helper functions. Turns the given integer in to a string
|
|
|
|
*
|
|
|
|
* \param integer The converted integer
|
|
|
|
* \returns Given integer as string
|
|
|
|
*/
|
|
|
|
char *IntToString(const int integer) {
|
|
|
|
static char buffer[sizeof(int) * 8 + 1]; // malloc might work better
|
|
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
|
|
|
|
SDL_snprintf(buffer, sizeof(buffer), "%d", integer);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int indentLevel;
|
|
|
|
|
|
|
|
//! Constants for XMLOuputters EOL parameter
|
|
|
|
#define YES 1
|
|
|
|
#define NO 0
|
|
|
|
|
|
|
|
/*! Controls printing the identation in relation to line breaks */
|
|
|
|
static int prevEOL = YES;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prints out the given xml element etc.
|
|
|
|
*
|
|
|
|
* \param identLevel the indent level of the message
|
|
|
|
* \param EOL will it print end of line character or not
|
|
|
|
* \param the XML element itself
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void XMLOutputter(const int il, int EOL, const char *message) {
|
|
|
|
int ident = 0;
|
|
|
|
for( ; ident < il && prevEOL; ++ident) {
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
prevEOL = EOL;
|
|
|
|
|
|
|
|
if(EOL) {
|
|
|
|
printf("%s\n", message);
|
|
|
|
} else {
|
|
|
|
printf("%s", message);
|
|
|
|
}
|
|
|
|
}
|
2011-06-23 22:00:03 +03:00
|
|
|
|
2011-06-21 19:31:46 +03:00
|
|
|
void
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLRunStarted(const char *runnerParameters, time_t eventTime)
|
2011-06-19 18:07:37 +03:00
|
|
|
{
|
2011-06-26 23:04:37 +03:00
|
|
|
char *output = XMLOpenDocument("testlog");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
output = XMLOpenElement("parameters");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
output = XMLAddContent("Add: runner parameter");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
output = XMLCloseElement("parameters");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
}
|
|
|
|
|
2011-06-21 19:31:46 +03:00
|
|
|
void
|
2011-06-22 17:41:37 +03:00
|
|
|
XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
|
|
|
|
time_t endTime, time_t totalRuntime)
|
2011-06-19 18:07:37 +03:00
|
|
|
{
|
2011-06-26 23:04:37 +03:00
|
|
|
char *output = XMLCloseDocument("testlog");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
}
|
|
|
|
|
2011-06-21 19:31:46 +03:00
|
|
|
void
|
2011-06-21 22:04:44 +03:00
|
|
|
XMLSuiteStarted(const char *suiteName, time_t eventTime)
|
2011-06-19 18:07:37 +03:00
|
|
|
{
|
2011-06-23 22:00:03 +03:00
|
|
|
char *output = XMLOpenElement("suite");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, YES, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLOpenElement("eventTime");
|
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
output = XMLAddContent(IntToString(eventTime));
|
|
|
|
XMLOutputter(indentLevel, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
output = XMLCloseElement("eventTime");
|
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
}
|
|
|
|
|
2011-06-21 19:31:46 +03:00
|
|
|
void
|
2011-06-21 22:04:44 +03:00
|
|
|
XMLSuiteEnded(int testsPassed, int testsFailed, int testsSkipped,
|
2011-06-21 19:31:46 +03:00
|
|
|
double endTime, time_t totalRuntime)
|
2011-06-19 18:07:37 +03:00
|
|
|
{
|
2011-06-23 22:00:03 +03:00
|
|
|
char *output = XMLCloseElement("suite");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-27 11:53:14 +03:00
|
|
|
|
|
|
|
//! \todo endTime and totalRuntiem
|
2011-06-19 18:07:37 +03:00
|
|
|
}
|
|
|
|
|
2011-06-21 19:31:46 +03:00
|
|
|
void
|
2011-06-22 17:41:37 +03:00
|
|
|
XMLTestStarted(const char *testName, const char *suiteName, const char *testDescription, time_t startTime)
|
2011-06-19 18:07:37 +03:00
|
|
|
{
|
2011-06-23 22:00:03 +03:00
|
|
|
char * output = XMLOpenElement("test");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
//Attribute attribute = {"test", "value"};
|
|
|
|
//XMLOpenElementWithAttribute("name", &attribute);
|
|
|
|
output = XMLOpenElement("name");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-22 17:41:37 +03:00
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
output = XMLAddContent(testName);
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-21 22:04:44 +03:00
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
output = XMLCloseElement("name");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
|
|
output = XMLOpenElement("description");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLAddContent(testDescription);
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLCloseElement("description");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLOpenElement("startTime");
|
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLAddContent(IntToString(startTime));
|
|
|
|
XMLOutputter(indentLevel, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
output = XMLCloseElement("startTime");
|
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
}
|
|
|
|
|
2011-06-21 19:31:46 +03:00
|
|
|
void
|
2011-06-22 17:41:37 +03:00
|
|
|
XMLTestEnded(const char *testName, const char *suiteName,
|
2011-06-26 23:04:37 +03:00
|
|
|
int testResult, time_t endTime, time_t totalRuntime)
|
2011-06-19 18:07:37 +03:00
|
|
|
{
|
2011-06-26 23:04:37 +03:00
|
|
|
char *output = XMLOpenElement("result");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
if(testResult) {
|
|
|
|
if(testResult == 2) {
|
|
|
|
output = XMLAddContent("failed -> no assert");
|
|
|
|
} else {
|
|
|
|
output = XMLAddContent("failed");
|
|
|
|
}
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel, NO, output);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(output);
|
|
|
|
} else {
|
|
|
|
output = XMLAddContent("passed");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel, NO, output);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(output);
|
|
|
|
}
|
2011-06-27 11:53:14 +03:00
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
output = XMLCloseElement("result");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
//! \todo add endTime and TotalRuntime
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
output = XMLCloseElement("test");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
}
|
|
|
|
|
2011-06-21 19:31:46 +03:00
|
|
|
void
|
2011-06-21 22:04:44 +03:00
|
|
|
XMLAssert(const char *assertName, int assertResult, const char *assertMessage,
|
2011-06-21 19:31:46 +03:00
|
|
|
time_t eventTime)
|
2011-06-19 18:07:37 +03:00
|
|
|
{
|
2011-06-23 22:00:03 +03:00
|
|
|
char *output = XMLOpenElement("assert");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
// log assert result
|
2011-06-23 22:00:03 +03:00
|
|
|
output = XMLOpenElement("result");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
output = XMLAddContent((assertResult) ? "pass" : "failure");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
output = XMLCloseElement("result");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
// log assert message
|
|
|
|
output = XMLOpenElement("message");
|
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLAddContent(assertMessage);
|
|
|
|
XMLOutputter(indentLevel, NO, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLCloseElement("message");
|
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
// log event time
|
|
|
|
output = XMLOpenElement("eventTime");
|
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLAddContent(IntToString(eventTime));
|
|
|
|
XMLOutputter(indentLevel, NO, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLCloseElement("eventTime");
|
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
output = XMLCloseElement("assert");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 19:52:35 +03:00
|
|
|
}
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
void
|
|
|
|
XMLAssertSummary(int numAsserts, int numAssertsFailed, int numAssertsPass)
|
|
|
|
{
|
|
|
|
char *output = XMLOpenElement("assertSummary");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, YES, output);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLOpenElement("assertCount");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
output = XMLAddContent(IntToString(numAsserts));
|
|
|
|
XMLOutputter(indentLevel, NO, output);
|
|
|
|
SDL_free(output);
|
2011-06-26 23:04:37 +03:00
|
|
|
|
|
|
|
output = XMLCloseElement("assertCount");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLOpenElement("assertsPassed");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
output = XMLAddContent(IntToString(numAssertsPass));
|
|
|
|
XMLOutputter(indentLevel, NO, output);
|
|
|
|
SDL_free(output);
|
2011-06-26 23:04:37 +03:00
|
|
|
|
|
|
|
output = XMLCloseElement("assertsPassed");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLOpenElement("assertsFailed");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
2011-06-27 11:53:14 +03:00
|
|
|
output = XMLAddContent(IntToString(numAsserts));
|
|
|
|
XMLOutputter(indentLevel, NO, output);
|
|
|
|
SDL_free(output);
|
2011-06-26 23:04:37 +03:00
|
|
|
|
|
|
|
output = XMLCloseElement("assertsFailed");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLCloseElement("assertSummary");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-26 23:04:37 +03:00
|
|
|
SDL_free(output);
|
|
|
|
}
|
|
|
|
|
2011-06-21 22:04:44 +03:00
|
|
|
void
|
|
|
|
XMLLog(const char *logMessage, time_t eventTime)
|
2011-06-19 18:07:37 +03:00
|
|
|
{
|
2011-06-23 22:00:03 +03:00
|
|
|
char *output = XMLOpenElement("log");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
// log message
|
|
|
|
output = XMLOpenElement("message");
|
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-21 22:04:44 +03:00
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
output = XMLAddContent(logMessage);
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(indentLevel, NO, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLCloseElement("message");
|
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
// log eventTime
|
|
|
|
output = XMLOpenElement("eventTime");
|
|
|
|
XMLOutputter(indentLevel++, NO, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLAddContent(IntToString(eventTime));
|
|
|
|
XMLOutputter(indentLevel, NO, output);
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
output = XMLCloseElement("eventTime");
|
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
output = XMLCloseElement("log");
|
2011-06-27 11:53:14 +03:00
|
|
|
XMLOutputter(--indentLevel, YES, output);
|
2011-06-23 22:00:03 +03:00
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
}
|