Refactored a bit. Extracted the code which checks for
authorMarkus Kauppila
Sun, 05 Jun 2011 18:38:06 +0300
changeset 5684d67b7490be36
parent 5683 1905dcc7ad20
child 5685 731a7c70eded
Refactored a bit. Extracted the code which checks for
test suite selection to a function.
test/test-automation/runner.c
     1.1 --- a/test/test-automation/runner.c	Sun Jun 05 17:34:04 2011 +0300
     1.2 +++ b/test/test-automation/runner.c	Sun Jun 05 18:38:06 2011 +0300
     1.3 @@ -315,8 +315,6 @@
     1.4  
     1.5      	  memset(selected_suite_name, 0, NAME_BUFFER_SIZE);
     1.6      	  strcpy(selected_suite_name, suiteName);
     1.7 -
     1.8 -    	  printf("%s\n", selected_suite_name);
     1.9        }
    1.10        else {
    1.11      	  printf("runner: unknown command '%s'\n", arg);
    1.12 @@ -328,6 +326,44 @@
    1.13  
    1.14  
    1.15  /*!
    1.16 + * Tests if the given test suite is selected for execution.
    1.17 + * If only_selected_suite flag is zero, then all the suites are
    1.18 + * automatically selected. If the flags is non-zero, only the suite
    1.19 + * which matches the selected suite is selected.
    1.20 + *
    1.21 + * \param testSuiteName Name of the test suite
    1.22 + *
    1.23 + * \return 1 if given suite is selected, otherwise 0
    1.24 + */
    1.25 +int
    1.26 +SuiteIsSelected(char *testSuiteName) {
    1.27 +	int retVal = 1;
    1.28 +
    1.29 +	if(only_selected_suite)	{
    1.30 +		// extract the suite name. Rips the tests/ and file suffix from the suite name
    1.31 +		char buffer[NAME_BUFFER_SIZE];
    1.32 +		int len = strlen(testSuiteName);
    1.33 +
    1.34 +//! \todo Fix this, it's rather horrible way to do it
    1.35 +#define DIR_NAME_LENGTH 6
    1.36 +#if defined(linux) || defined( __linux)
    1.37 +#define FILE_EXT_LENGTH 3
    1.38 +#else
    1.39 +#define FILE_EXT_LENGTH 6
    1.40 +#endif
    1.41 +		int length = len - DIR_NAME_LENGTH - FILE_EXT_LENGTH;
    1.42 +
    1.43 +		memset(buffer, 0, NAME_BUFFER_SIZE);
    1.44 +		memcpy(buffer, testSuiteName + 6, length);
    1.45 +
    1.46 +		retVal = SDL_strncmp(selected_suite_name, buffer, NAME_BUFFER_SIZE) == 0;
    1.47 +	}
    1.48 +
    1.49 +	return retVal;
    1.50 +}
    1.51 +
    1.52 +
    1.53 +/*!
    1.54   * Entry point for test runner
    1.55   *
    1.56   * \param argc Count of command line arguments
    1.57 @@ -349,27 +385,9 @@
    1.58  	char *testSuiteName = NULL;
    1.59  	int suiteCounter = 0;
    1.60  	for(testSuiteName = testSuiteNames[suiteCounter]; testSuiteName; testSuiteName = testSuiteNames[++suiteCounter]) {
    1.61 -
    1.62 -		if(only_selected_suite)	{
    1.63 -			// extract the suite name. Rips the tests/ and file suffix from the suite name
    1.64 -			char buffer[NAME_BUFFER_SIZE];
    1.65 -			int len = strlen(testSuiteName);
    1.66 -
    1.67 -//! \todo Fix this, it's rather horrible way to do it
    1.68 -#define DIR_NAME_LENGTH 6
    1.69 -#if defined(linux) || defined( __linux)
    1.70 -#define FILE_EXT_LENGTH 3
    1.71 -#else
    1.72 -#define FILE_EXT_LENGTH 6
    1.73 -#endif
    1.74 -			int length = len - DIR_NAME_LENGTH - FILE_EXT_LENGTH;
    1.75 -
    1.76 -			memset(buffer, 0, NAME_BUFFER_SIZE);
    1.77 -			memcpy(buffer, testSuiteName + 6, length);
    1.78 -
    1.79 -			if(SDL_strncmp(selected_suite_name, buffer, NAME_BUFFER_SIZE) != 0) {
    1.80 -				continue;
    1.81 -			}
    1.82 +		// if the current suite isn't selected, go to next suite
    1.83 +		if(SuiteIsSelected(testSuiteName) == 0) {
    1.84 +			continue;
    1.85  		}
    1.86  
    1.87  		void *suite = LoadTestSuite(testSuiteName);
    1.88 @@ -378,11 +396,8 @@
    1.89  		TestCaseReference *reference = NULL;
    1.90  		int counter = 0;
    1.91  		for(reference = tests[counter]; reference; reference = tests[++counter]) {
    1.92 -
    1.93 -			if(only_selected_test) {
    1.94 -				if(SDL_strncmp(selected_test_name, reference->name, NAME_BUFFER_SIZE) != 0) {
    1.95 -					continue;
    1.96 -				}
    1.97 +			if(only_selected_test && SDL_strncmp(selected_test_name, reference->name, NAME_BUFFER_SIZE) != 0) {
    1.98 +				continue;
    1.99  			}
   1.100  
   1.101  			if(reference->enabled == TEST_DISABLED) {