Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added user-supplied XSL style sheets for XML-based test reports.

Added new command line option: --xsl.
  • Loading branch information
mkauppila committed Jun 30, 2011
1 parent ef89e24 commit 0de0e7a5350fefb448f7f5be8d51559d2bd5926b
@@ -25,9 +25,10 @@

/*!
* Typedefs for function pointers that implement the generic
* logging interface
* logging interface. See the headers of implementations (plain_logger.h or
* xml_logger.h) for more information.
*/
typedef void (*RunStartedFp)(int parameterCount, char *runnerParameters[], time_t eventTime);
typedef void (*RunStartedFp)(int parameterCount, char *runnerParameters[], time_t eventTime, void *data);
typedef void (*RunEndedFp)(int testCount, int suiteCount, int testPassCount, int testFailCount,
time_t endTime, double totalRuntime);

@@ -28,7 +28,8 @@ Output(const char *message, ...)
}

void
PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime)
PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
void *data)
{
/*
Output("Test run started with following parameters\n");
@@ -9,8 +9,11 @@
* \param parameterCount How many parameters were given
* \param runnerParameters What parameters were given to the runner
* \param eventTime When the execution started
* \param data Any additional data logger needs
*
*/
void PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime);
void PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
void *data);

/*!
* Prints out information about ending the test run.
@@ -51,6 +51,8 @@ static int only_selected_suite = 0;
static int only_tests_with_string = 0;
//!< Flag for enabling XML logging
static int xml_enabled = 0;
//! Flag for enabling user-supplied style sheet for XML test report
static int custom_xsl_enabled = 0;


//!< Size of the test and suite name buffers
@@ -63,6 +65,9 @@ char selected_suite_name[NAME_BUFFER_SIZE];
//!< substring of test case name
char testcase_name_substring[NAME_BUFFER_SIZE];

//! Name for user-supplied XSL style sheet name
char xsl_stylesheet_name[NAME_BUFFER_SIZE];

//! Default directory of the test suites
#define DEFAULT_TEST_DIRECTORY "tests/"

@@ -535,6 +540,7 @@ printUsage() {
printf(" --in-proc Executes tests in-process\n");
printf(" --show-tests Prints out all the executable tests\n");
printf(" --xml Enables XML logger\n");
printf(" --xsl FILENAME Use the given file as XSL style sheet for XML\n"); // \todo add to wiki
printf(" -t --test TEST Executes only tests with given name\n");
printf(" -ts --name-contains SUBSTR Executes only tests that have given\n");
printf(" substring in test name\n");
@@ -581,6 +587,21 @@ ParseOptions(int argc, char *argv[])
memset(selected_test_name, 0, NAME_BUFFER_SIZE);
strcpy(selected_test_name, testName);
}
else if(SDL_strcmp(arg, "--xsl") == 0) {
custom_xsl_enabled = 1;
char *stylesheet = NULL;

if( (i + 1) < argc) {
stylesheet = argv[++i];
} else {
printf("runner: filename of XSL stylesheet is missing\n");
printUsage();
exit(1);
}

memset(xsl_stylesheet_name, 0, NAME_BUFFER_SIZE);
strncpy(xsl_stylesheet_name, stylesheet, NAME_BUFFER_SIZE);
}
else if(SDL_strcmp(arg, "--name-contains") == 0 || SDL_strcmp(arg, "-ts") == 0) {
only_tests_with_string = 1;
char *substring = NULL;
@@ -649,8 +670,12 @@ main(int argc, char *argv[])
#endif
if(xml_enabled) {
SetupXMLLogger();

RunStarted(argc, argv, time(0), xsl_stylesheet_name);
} else {
SetupPlainLogger();

RunStarted(argc, argv, time(0), NULL);
}

const Uint32 startTicks = SDL_GetTicks();
@@ -671,8 +696,6 @@ main(int argc, char *argv[])
return 0;
}

RunStarted(argc, argv, time(0));

char *currentSuiteName = NULL;

int suiteStartTime = SDL_GetTicks();
@@ -193,12 +193,22 @@ EscapeString(const char *string)
*/

char *
XMLOpenDocument(const char *rootTag)
XMLOpenDocument(const char *rootTag, const char *xslStyle)
{
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";
const char *styleStart = "<?xml-stylesheet type=\"text/xsl\" href=\"";
const char *styleEnd = "\"?>\n";

const int sizeStyleStart = SDL_strlen(styleStart);
const int sizeStyleEnd = SDL_strlen(styleEnd);
const int sizeStyleSheetName = SDL_strlen(xslStyle);

const int tempSize = sizeStyleStart + sizeStyleEnd + sizeStyleSheetName + 1;
char *style = SDL_malloc(tempSize);
memset(style, 0, tempSize);
snprintf(style, tempSize, "%s%s%s", styleStart, xslStyle, styleEnd);

memset(buffer, 0, bufferSize);
snprintf(buffer, bufferSize, "<%s>", rootTag);
@@ -219,6 +229,8 @@ XMLOpenDocument(const char *rootTag)
strcat(retBuf, style);
strcat(retBuf, buffer);

SDL_free(style);

return retBuf;
}

@@ -39,7 +39,7 @@ typedef struct Attribute {
* \param rootTag Root tag for the XML document
* \return The generated XML output
*/
char *XMLOpenDocument(const char *rootTag);
char *XMLOpenDocument(const char *rootTag, const char *xslStyle);

/*!
* Closes the XML-document.
@@ -105,9 +105,18 @@ XMLOutputter(const int currentIdentLevel,
}

void
XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime)
XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
void *data)
{
char *output = XMLOpenDocument(documentRoot);
char *xslStylesheet = "style.xsl";
if(data != NULL) {
char *tmp = (char *)data;
if(SDL_strlen(tmp) > 0) {
xslStylesheet = tmp;
}
}

char *output = XMLOpenDocument(documentRoot, xslStylesheet);
XMLOutputter(indentLevel++, YES, output);

output = XMLOpenElement(parametersElementName);
@@ -9,8 +9,9 @@
* \param parameterCount How many parameters were given
* \param runnerParameters What parameters were given to the runner
* \param eventTime When the execution started
* \param data Any additional data logger needs
*/
void XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime);
void XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime, void *data);

/*!
* Prints out information about ending the test run in XML

0 comments on commit 0de0e7a

Please sign in to comment.