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-23 22:00:03 +03:00
|
|
|
|
LogOutputFp logger;
|
|
|
|
|
|
2011-06-21 19:31:46 +03:00
|
|
|
|
void
|
2011-06-21 22:04:44 +03:00
|
|
|
|
XMLRunStarted(LogOutputFp outputFn, const char *runnerParameters, time_t eventTime)
|
2011-06-19 18:07:37 +03:00
|
|
|
|
{
|
2011-06-23 22:00:03 +03:00
|
|
|
|
logger = outputFn;
|
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
|
char *output = XMLOpenDocument("testlog");
|
2011-06-23 22:00:03 +03:00
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
|
output = XMLOpenElement("parameters");
|
2011-06-23 22:00:03 +03:00
|
|
|
|
logger(output);
|
|
|
|
|
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-23 22:00:03 +03:00
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
|
output = XMLCloseElement("parameters");
|
2011-06-23 22:00:03 +03:00
|
|
|
|
logger(output);
|
|
|
|
|
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-23 22:00:03 +03:00
|
|
|
|
logger(output);
|
|
|
|
|
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");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
|
output = XMLOpenElement("eventtime");
|
2011-06-23 22:00:03 +03:00
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
|
2011-06-21 19:31:46 +03:00
|
|
|
|
//XMLAddContent(evenTime);
|
2011-06-26 23:04:37 +03:00
|
|
|
|
output = XMLCloseElement("eventtime");
|
2011-06-23 22:00:03 +03:00
|
|
|
|
logger(output);
|
|
|
|
|
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");
|
|
|
|
|
logger(output);
|
|
|
|
|
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
|
|
|
|
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");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
//Attribute attribute = {"test", "value"};
|
|
|
|
|
//XMLOpenElementWithAttribute("name", &attribute);
|
|
|
|
|
output = XMLOpenElement("name");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
2011-06-22 17:41:37 +03:00
|
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
|
output = XMLAddContent(testName);
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
2011-06-21 22:04:44 +03:00
|
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
|
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);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
|
2011-06-21 22:04:44 +03:00
|
|
|
|
//XMLAddContent(startTime);
|
2011-06-23 22:00:03 +03:00
|
|
|
|
output = XMLCloseElement("starttime");
|
|
|
|
|
logger(output);
|
|
|
|
|
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");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
if(testResult) {
|
|
|
|
|
if(testResult == 2) {
|
|
|
|
|
output = XMLAddContent("failed -> no assert");
|
|
|
|
|
} else {
|
|
|
|
|
output = XMLAddContent("failed");
|
|
|
|
|
}
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
} else {
|
|
|
|
|
output = XMLAddContent("passed");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
output = XMLCloseElement("result");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
output = XMLCloseElement("test");
|
2011-06-23 22:00:03 +03:00
|
|
|
|
logger(output);
|
|
|
|
|
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");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
output = XMLOpenElement("result");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
|
output = XMLAddContent((assertResult) ? "pass" : "failure");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
|
2011-06-26 23:04:37 +03:00
|
|
|
|
output = XMLCloseElement("result");
|
2011-06-23 22:00:03 +03:00
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
|
output = XMLCloseElement("assert");
|
|
|
|
|
logger(output);
|
|
|
|
|
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");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
output = XMLOpenElement("assertCount");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
//XMLAddContent() \todo add string conversion
|
|
|
|
|
|
|
|
|
|
output = XMLCloseElement("assertCount");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
output = XMLOpenElement("assertsPassed");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
const int bufferSize = sizeof(int) * 8 + 1;
|
|
|
|
|
//char buffer[bufferSize];
|
|
|
|
|
char *buffer = SDL_malloc(bufferSize);
|
|
|
|
|
memset(buffer, 'a', bufferSize);
|
|
|
|
|
|
|
|
|
|
//SDL_vsnprintf(buffer, bufferSize, "%d", numAssertsPass);
|
|
|
|
|
snprintf(buffer, sizeof(buffer), "%d", numAssertsPass);
|
|
|
|
|
buffer[3] = 'a';
|
|
|
|
|
//printf("DEBUG |<7C>%s == %d of size %d", buffer, numAssertsPass, bufferSize);
|
|
|
|
|
XMLAddContent(buffer);
|
|
|
|
|
|
|
|
|
|
output = XMLCloseElement("assertsPassed");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
output = XMLOpenElement("assertsFailed");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
//XMLAddContent() \todo add string conversion
|
|
|
|
|
|
|
|
|
|
output = XMLCloseElement("assertsFailed");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
|
|
|
|
|
|
|
|
|
output = XMLCloseElement("assertSummary");
|
|
|
|
|
logger(output);
|
|
|
|
|
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");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
2011-06-21 22:04:44 +03:00
|
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
|
output = XMLAddContent(logMessage);
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
|
2011-06-23 22:00:03 +03:00
|
|
|
|
output = XMLCloseElement("log");
|
|
|
|
|
logger(output);
|
|
|
|
|
SDL_free(output);
|
2011-06-19 18:07:37 +03:00
|
|
|
|
}
|
|
|
|
|
|