Redefined the usage of --xsl command option.
authorMarkus Kauppila
Fri, 01 Jul 2011 12:36:57 +0300
changeset 5731507fffef86ad
parent 5730 5c094958a62f
child 5732 1da5af48b964
Redefined the usage of --xsl command option.
test/test-automation/runner.c
test/test-automation/xml.c
test/test-automation/xml.h
test/test-automation/xml_logger.c
     1.1 --- a/test/test-automation/runner.c	Fri Jul 01 11:12:35 2011 +0300
     1.2 +++ b/test/test-automation/runner.c	Fri Jul 01 12:36:57 2011 +0300
     1.3 @@ -53,6 +53,8 @@
     1.4  static int xml_enabled = 0;
     1.5  //! Flag for enabling user-supplied style sheet for XML test report
     1.6  static int custom_xsl_enabled = 0;
     1.7 +//! Flag for disabling xsl-style from xml report
     1.8 +static int xsl_enabled = 0;
     1.9  
    1.10  
    1.11  //!< Size of the test and suite name buffers
    1.12 @@ -548,12 +550,13 @@
    1.13  printUsage() {
    1.14  	  printf("Usage: ./runner [--in-proc] [--suite SUITE] [--test TEST]\n");
    1.15  	  printf("                [--name-contains SUBSTR] [--show-tests\n");
    1.16 -	  printf("                [--xml] [--xsl STYLESHEET] [--help]\n");
    1.17 +	  printf("                [--xml] [--xsl] [--xsl STYLESHEET] [--help]\n");
    1.18  	  printf("Options:\n");
    1.19  	  printf("     --in-proc                Executes tests in-process\n");
    1.20  	  printf("     --show-tests             Prints out all the executable tests\n");
    1.21 -	  printf("     --xml             		Enables XML logger\n");
    1.22 -	  printf("     --xsl STYLESHEET    		Use the given file as XSL style sheet for XML\n");
    1.23 +	  printf("     --xml                    Enables XML logger\n");
    1.24 +	  printf("     --xsl                    Adds default XSL stylesheet to XML test reports\n");
    1.25 +	  printf("     --xsl STYLESHEET         Use the given file as XSL style sheet for XML\n");
    1.26  	  printf(" -t  --test TEST              Executes only tests with given name\n");
    1.27  	  printf(" -ts --name-contains SUBSTR   Executes only tests that have given\n");
    1.28  	  printf("                              substring in test name\n");
    1.29 @@ -601,19 +604,17 @@
    1.30      	  strcpy(selected_test_name, testName);
    1.31        }
    1.32        else if(SDL_strcmp(arg, "--xsl") == 0) {
    1.33 -    	  custom_xsl_enabled = 1;
    1.34 -    	  char *stylesheet = NULL;
    1.35 +    	  xsl_enabled = 1;
    1.36  
    1.37      	  if( (i + 1) < argc)  {
    1.38 -    		  stylesheet = argv[++i];
    1.39 -    	  }  else {
    1.40 -    		  printf("runner: filename of XSL stylesheet is missing\n");
    1.41 -    		  printUsage();
    1.42 -    		  exit(1);
    1.43 +    		  char *stylesheet = argv[++i];
    1.44 +    		  if(stylesheet[0] != '-') {
    1.45 +    	    	  custom_xsl_enabled = 1;
    1.46 +
    1.47 +    	    	  memset(xsl_stylesheet_name, 0, NAME_BUFFER_SIZE);
    1.48 +    	    	  strncpy(xsl_stylesheet_name, stylesheet, NAME_BUFFER_SIZE);
    1.49 +    		  }
    1.50      	  }
    1.51 -
    1.52 -    	  memset(xsl_stylesheet_name, 0, NAME_BUFFER_SIZE);
    1.53 -    	  strncpy(xsl_stylesheet_name, stylesheet, NAME_BUFFER_SIZE);
    1.54        }
    1.55        else if(SDL_strcmp(arg, "--name-contains") == 0 || SDL_strcmp(arg, "-ts") == 0) {
    1.56      	  only_tests_with_string = 1;
    1.57 @@ -685,7 +686,16 @@
    1.58  	if(xml_enabled) {
    1.59  		SetupXMLLogger();
    1.60  
    1.61 -		RunStarted(argc, argv, time(0), xsl_stylesheet_name);
    1.62 +		char *sheet = NULL;
    1.63 +		if(xsl_enabled) {
    1.64 +			sheet = "style.xsl"; // default style sheet;
    1.65 +		}
    1.66 +
    1.67 +		if(custom_xsl_enabled) {
    1.68 +			sheet = xsl_stylesheet_name;
    1.69 +		}
    1.70 +
    1.71 +		RunStarted(argc, argv, time(0), sheet);
    1.72  	} else {
    1.73  		SetupPlainLogger();
    1.74  
     2.1 --- a/test/test-automation/xml.c	Fri Jul 01 11:12:35 2011 +0300
     2.2 +++ b/test/test-automation/xml.c	Fri Jul 01 12:36:57 2011 +0300
     2.3 @@ -197,18 +197,21 @@
     2.4  {
     2.5  	const char *doctype = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
     2.6  
     2.7 -	//! \todo make this optional (and let the user supply the filename?)
     2.8 -	const char *styleStart = "<?xml-stylesheet type=\"text/xsl\" href=\"";
     2.9 -	const char *styleEnd = "\"?>\n";
    2.10 +	//! \todo refactor this mess
    2.11 +	char *style = NULL;
    2.12 +	if(xslStyle) {
    2.13 +		const char *styleStart = "<?xml-stylesheet type=\"text/xsl\" href=\"";
    2.14 +		const char *styleEnd = "\"?>\n";
    2.15  
    2.16 -	const int sizeStyleStart = SDL_strlen(styleStart);
    2.17 -	const int sizeStyleEnd = SDL_strlen(styleEnd);
    2.18 -	const int sizeStyleSheetName = SDL_strlen(xslStyle);
    2.19 +		const int sizeStyleStart = SDL_strlen(styleStart);
    2.20 +		const int sizeStyleEnd = SDL_strlen(styleEnd);
    2.21 +		const int sizeStyleSheetName = SDL_strlen(xslStyle);
    2.22  
    2.23 -	const int tempSize = sizeStyleStart + sizeStyleEnd + sizeStyleSheetName + 1;
    2.24 -	char *style = SDL_malloc(tempSize);
    2.25 -	memset(style, 0, tempSize);
    2.26 -	SDL_snprintf(style, tempSize, "%s%s%s", styleStart, xslStyle, styleEnd);
    2.27 +		const int tempSize = sizeStyleStart + sizeStyleEnd + sizeStyleSheetName + 1;
    2.28 +		style = SDL_malloc(tempSize);
    2.29 +		memset(style, 0, tempSize);
    2.30 +		SDL_snprintf(style, tempSize, "%s%s%s", styleStart, xslStyle, styleEnd);
    2.31 +	}
    2.32  
    2.33  	memset(buffer, 0, bufferSize);
    2.34  	SDL_snprintf(buffer, bufferSize, "<%s>", rootTag);
    2.35 @@ -217,19 +220,27 @@
    2.36  
    2.37  	root = rootTag; // it's fine, as long as rootTag points to static memory?
    2.38  
    2.39 -	const int doctypeSize = SDL_strlen(doctype);
    2.40 -	const int styleSize = SDL_strlen(style);
    2.41 -	const int tagSize = SDL_strlen(buffer);
    2.42 +	char *retBuf = NULL;
    2.43 +	if(xslStyle) {
    2.44 +		const int doctypeSize = SDL_strlen(doctype);
    2.45 +		const int styleSize = SDL_strlen(style);
    2.46 +		const int tagSize = SDL_strlen(buffer);
    2.47  
    2.48 -	const int size = doctypeSize + styleSize + tagSize + 1; // extra byte for '\0'
    2.49 -	char *retBuf = SDL_malloc(size);
    2.50 +		const int size = doctypeSize + styleSize + tagSize + 1; // extra byte for '\0'
    2.51 +		retBuf = SDL_malloc(size);
    2.52 +
    2.53 +		SDL_snprintf(retBuf, size, "%s%s%s", doctype, style, buffer);
    2.54  
    2.55 -	// fill in the previous allocated retBuf
    2.56 -	strcat(retBuf, doctype);
    2.57 -	strcat(retBuf, style);
    2.58 -	strcat(retBuf, buffer);
    2.59 +		SDL_free(style);
    2.60 +	} else {
    2.61 +		const int doctypeSize = SDL_strlen(doctype);
    2.62 +		const int tagSize = SDL_strlen(buffer);
    2.63  
    2.64 -	SDL_free(style);
    2.65 +		const int size = doctypeSize + tagSize + 1; // extra byte for '\0'
    2.66 +		retBuf = SDL_malloc(size);
    2.67 +
    2.68 +		SDL_snprintf(retBuf, size, "%s%s", doctype, buffer);
    2.69 +	}
    2.70  
    2.71  	return retBuf;
    2.72  }
     3.1 --- a/test/test-automation/xml.h	Fri Jul 01 11:12:35 2011 +0300
     3.2 +++ b/test/test-automation/xml.h	Fri Jul 01 12:36:57 2011 +0300
     3.3 @@ -37,6 +37,7 @@
     3.4   * Note: XML creation is not thread-safe!
     3.5   *
     3.6   * \param rootTag Root tag for the XML document
     3.7 + * \param xslStyle Name of the style sheet file. (empty string if no style is used)
     3.8   * \return The generated XML output
     3.9   */
    3.10  char *XMLOpenDocument(const char *rootTag, const char *xslStyle);
     4.1 --- a/test/test-automation/xml_logger.c	Fri Jul 01 11:12:35 2011 +0300
     4.2 +++ b/test/test-automation/xml_logger.c	Fri Jul 01 12:36:57 2011 +0300
     4.3 @@ -101,20 +101,14 @@
     4.4  		fprintf(stdout, "Error: Tried to output invalid string!");
     4.5  	}
     4.6  
     4.7 -	SDL_free(message);
     4.8 +	SDL_free((char *)message);
     4.9  }
    4.10  
    4.11  void
    4.12  XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
    4.13  			 void *data)
    4.14  {
    4.15 -	char *xslStylesheet = "style.xsl";
    4.16 -	if(data != NULL) {
    4.17 -		char *tmp = (char *)data;
    4.18 -		if(SDL_strlen(tmp) > 0) {
    4.19 -			xslStylesheet = tmp;
    4.20 -		}
    4.21 -	}
    4.22 +	char *xslStylesheet = (char *)data;
    4.23  
    4.24  	char *output = XMLOpenDocument(documentRoot, xslStylesheet);
    4.25  	XMLOutputter(indentLevel++, YES, output);