Removed unnecessary function.
authorMarkus Kauppila
Wed, 08 Jun 2011 19:41:12 +0300
changeset 5691c0b4bcd901a0
parent 5690 82da33693536
child 5692 249e54c47b90
Removed unnecessary function.
test/test-automation/runner.c
     1.1 --- a/test/test-automation/runner.c	Wed Jun 08 18:38:38 2011 +0300
     1.2 +++ b/test/test-automation/runner.c	Wed Jun 08 19:41:12 2011 +0300
     1.3 @@ -45,7 +45,7 @@
     1.4  //!< Flag for executing only the selected test suite
     1.5  static int only_selected_suite = 0;
     1.6  
     1.7 -//<! Size of the test and suite name buffers
     1.8 +//!< Size of the test and suite name buffers
     1.9  #define NAME_BUFFER_SIZE 1024
    1.10  //!< Name of the selected test
    1.11  char selected_test_name[NAME_BUFFER_SIZE];
    1.12 @@ -53,6 +53,9 @@
    1.13  char selected_suite_name[NAME_BUFFER_SIZE];
    1.14  
    1.15  
    1.16 +//! Default directory of the test suites
    1.17 +#define DEFAULT_TEST_DIRECTORY "tests/"
    1.18 +
    1.19  /*!
    1.20   * Holds information about test suite. Implemented as
    1.21   * linked list. \todo write better doc
    1.22 @@ -62,20 +65,25 @@
    1.23  	struct TestSuiteReference *next; //!< Pointer to next item in the list
    1.24  } TestSuiteReference;
    1.25  
    1.26 -static TestSuiteReference *suites = NULL;
    1.27  
    1.28  /*!
    1.29   * Scans the tests/ directory and returns the names
    1.30   * of the dynamic libraries implementing the test suites.
    1.31 + *
    1.32   * Note: currently function assumes that test suites names
    1.33   * are in following format: libtestsuite.dylib or libtestsuite.so.
    1.34   *
    1.35 + * Note: if only_selected_suite flags is non-zero, only the selected
    1.36 + * test will be loaded.
    1.37 + *
    1.38 + * \param directoryName Name of the directory which will be scanned
    1.39 + *
    1.40   * \return Pointer to TestSuiteReference which holds all the info about suites
    1.41   */
    1.42  TestSuiteReference *
    1.43 -ScanForTestSuites(/*char *directoryName*/) {
    1.44 +ScanForTestSuites(char *directoryName, char *extension) {
    1.45  	typedef struct dirent Entry;
    1.46 -	DIR *directory = opendir("tests/");
    1.47 +	DIR *directory = opendir(directoryName);
    1.48  
    1.49  	TestSuiteReference *suites = NULL;
    1.50  
    1.51 @@ -83,19 +91,25 @@
    1.52  	if(directory) {
    1.53  		while(entry = readdir(directory)) {
    1.54  			if(entry->d_namlen > 2) { // discards . and ..
    1.55 -				const int bufferSize = 1024;
    1.56 -				char buffer[bufferSize];
    1.57 -				memset(buffer, 0, bufferSize);
    1.58 -
    1.59 -				strcat(buffer, "tests/"); // \todo convert to define or something
    1.60 +				char buffer[NAME_BUFFER_SIZE];
    1.61 +				memset(buffer, 0, NAME_BUFFER_SIZE);
    1.62  
    1.63  				char *name = strtok(entry->d_name, ".");
    1.64 -				char *extension = strtok(NULL, ".");
    1.65 -				if(strcmp(extension, "dylib") == 0 || strcmp(extension, "so") == 0) {
    1.66 +				char *ext = strtok(NULL, ".");
    1.67 +
    1.68 +				// filter out all other suites but the selected test suite
    1.69 +				int ok = 1;
    1.70 +				if(only_selected_suite) {
    1.71 +					ok = SDL_strncmp(selected_suite_name, name, NAME_BUFFER_SIZE) == 0;
    1.72 +				}
    1.73 +
    1.74 +				if(ok && SDL_strcmp(ext, extension)  == 0) {
    1.75 +					strcat(buffer, directoryName);
    1.76  					strcat(buffer, name);
    1.77  					strcat(buffer, ".");
    1.78 -					strcat(buffer, extension);
    1.79 +					strcat(buffer, ext);
    1.80  
    1.81 +					// create tes suite reference
    1.82  					TestSuiteReference *reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference));
    1.83  					memset(reference, 0, sizeof(TestSuiteReference));
    1.84  
    1.85 @@ -103,11 +117,12 @@
    1.86  					reference->name = SDL_malloc(length * sizeof(char));
    1.87  
    1.88  					strcpy(reference->name, buffer);
    1.89 +
    1.90  					reference->next = suites;
    1.91  
    1.92  					suites = reference;
    1.93  
    1.94 -					// printf("Reference added to: %s\n", buffer)
    1.95 +					printf("Reference added to: %s\n", buffer);
    1.96  				}
    1.97  			}
    1.98  		}
    1.99 @@ -373,43 +388,6 @@
   1.100  
   1.101  
   1.102  /*!
   1.103 - * Tests if the given test suite is selected for execution.
   1.104 - * If only_selected_suite flag is zero, then all the suites are
   1.105 - * automatically selected. If the flags is non-zero, only the suite
   1.106 - * which matches the selected suite is selected.
   1.107 - *
   1.108 - * \param testSuiteName Name of the test suite
   1.109 - *
   1.110 - * \return 1 if given suite is selected, otherwise 0
   1.111 - */
   1.112 -int
   1.113 -SuiteIsSelected(char *testSuiteName) {
   1.114 -	int retVal = 1;
   1.115 -
   1.116 -	if(only_selected_suite)	{
   1.117 -		// extract the suite name. Rips the tests/ and file extension from the suite name
   1.118 -		char buffer[NAME_BUFFER_SIZE];
   1.119 -		int len = strlen(testSuiteName);
   1.120 -
   1.121 -		const int dirNameLength = 6;
   1.122 -#if defined(linux) || defined( __linux)
   1.123 -		const int fileExtLength = 3;
   1.124 -#else
   1.125 -		const int fileExtLength = 6;
   1.126 -#endif
   1.127 -		int length = len - dirNameLength - fileExtLength;
   1.128 -
   1.129 -		memset(buffer, 0, NAME_BUFFER_SIZE);
   1.130 -		memcpy(buffer, testSuiteName + dirNameLength, length);
   1.131 -
   1.132 -		retVal = SDL_strncmp(selected_suite_name, buffer, NAME_BUFFER_SIZE) == 0;
   1.133 -	}
   1.134 -
   1.135 -	return retVal;
   1.136 -}
   1.137 -
   1.138 -
   1.139 -/*!
   1.140   * Entry point for test runner
   1.141   *
   1.142   * \param argc Count of command line arguments
   1.143 @@ -426,50 +404,58 @@
   1.144  	char *testSuiteName = NULL;
   1.145  	int suiteCounter = 0;
   1.146  
   1.147 +#if defined(linux) || defined( __linux)
   1.148 +	char *extension = "so";
   1.149 +#else
   1.150 +	char *extension = "dylib";
   1.151 +#endif
   1.152 +
   1.153  	const Uint32 startTicks = SDL_GetTicks();
   1.154 -	TestSuiteReference *suites = ScanForTestSuites();
   1.155 +	TestSuiteReference *suites = ScanForTestSuites(DEFAULT_TEST_DIRECTORY, extension);
   1.156 +
   1.157 +	// load the suites
   1.158 +	// load tests and filter them
   1.159 +	// end result: list of tests to run
   1.160  
   1.161  	TestSuiteReference *suiteReference = NULL;
   1.162  	for(suiteReference = suites; suiteReference; suiteReference = suiteReference->next) {
   1.163  		char *testSuiteName = suiteReference->name;
   1.164  
   1.165  		// if the current suite isn't selected, go to next suite
   1.166 -		if(SuiteIsSelected(testSuiteName)) {
   1.167 -			void *suite = LoadTestSuite(testSuiteName);
   1.168 -			TestCaseReference **tests = QueryTestCases(suite);
   1.169 -
   1.170 -			TestCaseReference *reference = NULL;
   1.171 -			int counter = 0;
   1.172 -			for(reference = tests[counter]; reference; reference = tests[++counter]) {
   1.173 -				if(only_selected_test && SDL_strncmp(selected_test_name, reference->name, NAME_BUFFER_SIZE) != 0) {
   1.174 -					continue;
   1.175 -				}
   1.176 -
   1.177 -				if(reference->enabled == TEST_DISABLED) {
   1.178 -					printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName);
   1.179 -				} else {
   1.180 -					printf("Executing %s (in %s):\n", reference->name, testSuiteName);
   1.181 +		void *suite = LoadTestSuite(testSuiteName);
   1.182 +		TestCaseReference **tests = QueryTestCases(suite);
   1.183  
   1.184 -					int retVal = ExecuteTest(suite, reference);
   1.185 -
   1.186 -					if(retVal) {
   1.187 -						failureCount++;
   1.188 -						if(retVal == 2) {
   1.189 -							printf("%s (in %s): FAILED -> No asserts\n", reference->name, testSuiteName);
   1.190 -						} else {
   1.191 -							printf("%s (in %s): FAILED\n", reference->name, testSuiteName);
   1.192 -						}
   1.193 -					} else {
   1.194 -						passCount++;
   1.195 -						printf("%s (in %s): ok\n", reference->name, testSuiteName);
   1.196 -					}
   1.197 -				}
   1.198 -
   1.199 -				printf("\n");
   1.200 +		TestCaseReference *reference = NULL;
   1.201 +		int counter = 0;
   1.202 +		for(reference = tests[counter]; reference; reference = tests[++counter]) {
   1.203 +			if(only_selected_test && SDL_strncmp(selected_test_name, reference->name, NAME_BUFFER_SIZE) != 0) {
   1.204 +				continue;
   1.205  			}
   1.206  
   1.207 -			SDL_UnloadObject(suite);
   1.208 +			if(reference->enabled == TEST_DISABLED) {
   1.209 +				printf("Test %s (in %s) disabled. Omitting...\n", reference->name, testSuiteName);
   1.210 +			} else {
   1.211 +				printf("Executing %s (in %s):\n", reference->name, testSuiteName);
   1.212 +
   1.213 +				int retVal = ExecuteTest(suite, reference);
   1.214 +
   1.215 +				if(retVal) {
   1.216 +					failureCount++;
   1.217 +					if(retVal == 2) {
   1.218 +						printf("%s (in %s): FAILED -> No asserts\n", reference->name, testSuiteName);
   1.219 +					} else {
   1.220 +						printf("%s (in %s): FAILED\n", reference->name, testSuiteName);
   1.221 +					}
   1.222 +				} else {
   1.223 +					passCount++;
   1.224 +					printf("%s (in %s): ok\n", reference->name, testSuiteName);
   1.225 +				}
   1.226 +			}
   1.227 +
   1.228 +			printf("\n");
   1.229  		}
   1.230 +
   1.231 +		SDL_UnloadObject(suite);
   1.232  	}
   1.233  
   1.234  	const Uint32 endTicks = SDL_GetTicks();