Added user-supplied XSL style sheets for XML-based test reports.
Added new command line option: --xsl.
1.1 --- a/test/test-automation/logger.h Thu Jun 30 16:08:37 2011 +0300
1.2 +++ b/test/test-automation/logger.h Thu Jun 30 17:11:39 2011 +0300
1.3 @@ -25,9 +25,10 @@
1.4
1.5 /*!
1.6 * Typedefs for function pointers that implement the generic
1.7 - * logging interface
1.8 + * logging interface. See the headers of implementations (plain_logger.h or
1.9 + * xml_logger.h) for more information.
1.10 */
1.11 -typedef void (*RunStartedFp)(int parameterCount, char *runnerParameters[], time_t eventTime);
1.12 +typedef void (*RunStartedFp)(int parameterCount, char *runnerParameters[], time_t eventTime, void *data);
1.13 typedef void (*RunEndedFp)(int testCount, int suiteCount, int testPassCount, int testFailCount,
1.14 time_t endTime, double totalRuntime);
1.15
2.1 --- a/test/test-automation/plain_logger.c Thu Jun 30 16:08:37 2011 +0300
2.2 +++ b/test/test-automation/plain_logger.c Thu Jun 30 17:11:39 2011 +0300
2.3 @@ -28,7 +28,8 @@
2.4 }
2.5
2.6 void
2.7 -PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime)
2.8 +PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
2.9 + void *data)
2.10 {
2.11 /*
2.12 Output("Test run started with following parameters\n");
3.1 --- a/test/test-automation/plain_logger.h Thu Jun 30 16:08:37 2011 +0300
3.2 +++ b/test/test-automation/plain_logger.h Thu Jun 30 17:11:39 2011 +0300
3.3 @@ -9,8 +9,11 @@
3.4 * \param parameterCount How many parameters were given
3.5 * \param runnerParameters What parameters were given to the runner
3.6 * \param eventTime When the execution started
3.7 + * \param data Any additional data logger needs
3.8 + *
3.9 */
3.10 -void PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime);
3.11 +void PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
3.12 + void *data);
3.13
3.14 /*!
3.15 * Prints out information about ending the test run.
4.1 --- a/test/test-automation/runner.c Thu Jun 30 16:08:37 2011 +0300
4.2 +++ b/test/test-automation/runner.c Thu Jun 30 17:11:39 2011 +0300
4.3 @@ -51,6 +51,8 @@
4.4 static int only_tests_with_string = 0;
4.5 //!< Flag for enabling XML logging
4.6 static int xml_enabled = 0;
4.7 +//! Flag for enabling user-supplied style sheet for XML test report
4.8 +static int custom_xsl_enabled = 0;
4.9
4.10
4.11 //!< Size of the test and suite name buffers
4.12 @@ -63,6 +65,9 @@
4.13 //!< substring of test case name
4.14 char testcase_name_substring[NAME_BUFFER_SIZE];
4.15
4.16 +//! Name for user-supplied XSL style sheet name
4.17 +char xsl_stylesheet_name[NAME_BUFFER_SIZE];
4.18 +
4.19 //! Default directory of the test suites
4.20 #define DEFAULT_TEST_DIRECTORY "tests/"
4.21
4.22 @@ -535,6 +540,7 @@
4.23 printf(" --in-proc Executes tests in-process\n");
4.24 printf(" --show-tests Prints out all the executable tests\n");
4.25 printf(" --xml Enables XML logger\n");
4.26 + printf(" --xsl FILENAME Use the given file as XSL style sheet for XML\n"); // \todo add to wiki
4.27 printf(" -t --test TEST Executes only tests with given name\n");
4.28 printf(" -ts --name-contains SUBSTR Executes only tests that have given\n");
4.29 printf(" substring in test name\n");
4.30 @@ -581,6 +587,21 @@
4.31 memset(selected_test_name, 0, NAME_BUFFER_SIZE);
4.32 strcpy(selected_test_name, testName);
4.33 }
4.34 + else if(SDL_strcmp(arg, "--xsl") == 0) {
4.35 + custom_xsl_enabled = 1;
4.36 + char *stylesheet = NULL;
4.37 +
4.38 + if( (i + 1) < argc) {
4.39 + stylesheet = argv[++i];
4.40 + } else {
4.41 + printf("runner: filename of XSL stylesheet is missing\n");
4.42 + printUsage();
4.43 + exit(1);
4.44 + }
4.45 +
4.46 + memset(xsl_stylesheet_name, 0, NAME_BUFFER_SIZE);
4.47 + strncpy(xsl_stylesheet_name, stylesheet, NAME_BUFFER_SIZE);
4.48 + }
4.49 else if(SDL_strcmp(arg, "--name-contains") == 0 || SDL_strcmp(arg, "-ts") == 0) {
4.50 only_tests_with_string = 1;
4.51 char *substring = NULL;
4.52 @@ -649,8 +670,12 @@
4.53 #endif
4.54 if(xml_enabled) {
4.55 SetupXMLLogger();
4.56 +
4.57 + RunStarted(argc, argv, time(0), xsl_stylesheet_name);
4.58 } else {
4.59 SetupPlainLogger();
4.60 +
4.61 + RunStarted(argc, argv, time(0), NULL);
4.62 }
4.63
4.64 const Uint32 startTicks = SDL_GetTicks();
4.65 @@ -671,8 +696,6 @@
4.66 return 0;
4.67 }
4.68
4.69 - RunStarted(argc, argv, time(0));
4.70 -
4.71 char *currentSuiteName = NULL;
4.72
4.73 int suiteStartTime = SDL_GetTicks();
5.1 --- a/test/test-automation/xml.c Thu Jun 30 16:08:37 2011 +0300
5.2 +++ b/test/test-automation/xml.c Thu Jun 30 17:11:39 2011 +0300
5.3 @@ -193,12 +193,22 @@
5.4 */
5.5
5.6 char *
5.7 -XMLOpenDocument(const char *rootTag)
5.8 +XMLOpenDocument(const char *rootTag, const char *xslStyle)
5.9 {
5.10 const char *doctype = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
5.11
5.12 //! \todo make this optional (and let the user supply the filename?)
5.13 - const char *style = "<?xml-stylesheet type=\"text/xsl\" href=\"style.xsl\"?>\n";
5.14 + const char *styleStart = "<?xml-stylesheet type=\"text/xsl\" href=\"";
5.15 + const char *styleEnd = "\"?>\n";
5.16 +
5.17 + const int sizeStyleStart = SDL_strlen(styleStart);
5.18 + const int sizeStyleEnd = SDL_strlen(styleEnd);
5.19 + const int sizeStyleSheetName = SDL_strlen(xslStyle);
5.20 +
5.21 + const int tempSize = sizeStyleStart + sizeStyleEnd + sizeStyleSheetName + 1;
5.22 + char *style = SDL_malloc(tempSize);
5.23 + memset(style, 0, tempSize);
5.24 + snprintf(style, tempSize, "%s%s%s", styleStart, xslStyle, styleEnd);
5.25
5.26 memset(buffer, 0, bufferSize);
5.27 snprintf(buffer, bufferSize, "<%s>", rootTag);
5.28 @@ -219,6 +229,8 @@
5.29 strcat(retBuf, style);
5.30 strcat(retBuf, buffer);
5.31
5.32 + SDL_free(style);
5.33 +
5.34 return retBuf;
5.35 }
5.36
6.1 --- a/test/test-automation/xml.h Thu Jun 30 16:08:37 2011 +0300
6.2 +++ b/test/test-automation/xml.h Thu Jun 30 17:11:39 2011 +0300
6.3 @@ -39,7 +39,7 @@
6.4 * \param rootTag Root tag for the XML document
6.5 * \return The generated XML output
6.6 */
6.7 -char *XMLOpenDocument(const char *rootTag);
6.8 +char *XMLOpenDocument(const char *rootTag, const char *xslStyle);
6.9
6.10 /*!
6.11 * Closes the XML-document.
7.1 --- a/test/test-automation/xml_logger.c Thu Jun 30 16:08:37 2011 +0300
7.2 +++ b/test/test-automation/xml_logger.c Thu Jun 30 17:11:39 2011 +0300
7.3 @@ -105,9 +105,18 @@
7.4 }
7.5
7.6 void
7.7 -XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime)
7.8 +XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
7.9 + void *data)
7.10 {
7.11 - char *output = XMLOpenDocument(documentRoot);
7.12 + char *xslStylesheet = "style.xsl";
7.13 + if(data != NULL) {
7.14 + char *tmp = (char *)data;
7.15 + if(SDL_strlen(tmp) > 0) {
7.16 + xslStylesheet = tmp;
7.17 + }
7.18 + }
7.19 +
7.20 + char *output = XMLOpenDocument(documentRoot, xslStylesheet);
7.21 XMLOutputter(indentLevel++, YES, output);
7.22
7.23 output = XMLOpenElement(parametersElementName);
8.1 --- a/test/test-automation/xml_logger.h Thu Jun 30 16:08:37 2011 +0300
8.2 +++ b/test/test-automation/xml_logger.h Thu Jun 30 17:11:39 2011 +0300
8.3 @@ -9,8 +9,9 @@
8.4 * \param parameterCount How many parameters were given
8.5 * \param runnerParameters What parameters were given to the runner
8.6 * \param eventTime When the execution started
8.7 + * \param data Any additional data logger needs
8.8 */
8.9 -void XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime);
8.10 +void XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime, void *data);
8.11
8.12 /*!
8.13 * Prints out information about ending the test run in XML