Separated test suite name from its directory path. Fixes
authorMarkus Kauppila
Fri, 01 Jul 2011 11:12:35 +0300
changeset 57305c094958a62f
parent 5729 27be98c43bbc
child 5731 507fffef86ad
Separated test suite name from its directory path. Fixes
usability issues concerning some command line options.
test/test-automation/runner.c
test/test-automation/xml.c
     1.1 --- a/test/test-automation/runner.c	Thu Jun 30 18:11:48 2011 +0300
     1.2 +++ b/test/test-automation/runner.c	Fri Jul 01 11:12:35 2011 +0300
     1.3 @@ -78,6 +78,7 @@
     1.4   */
     1.5  typedef struct TestSuiteReference {
     1.6  	char *name; //!< test suite name
     1.7 +	char *directoryPath; //!< test suites path (eg. tests/libtestsuite)
     1.8  	void *library; //!< pointer to shared/dynamic library implementing the suite
     1.9  
    1.10  	struct TestSuiteReference *next; //!< Pointer to next item in the list
    1.11 @@ -283,28 +284,37 @@
    1.12  			}
    1.13  
    1.14  			if(ok && SDL_strcmp(ext, extension)  == 0) {
    1.15 -				char buffer[NAME_BUFFER_SIZE];
    1.16 -				memset(buffer, 0, NAME_BUFFER_SIZE);
    1.17 -
    1.18 -				//! \todo change strcat's to strncats
    1.19 -				//strcat(buffer, directoryName);
    1.20 -				strcat(buffer, name);
    1.21 -				strcat(buffer, ".");
    1.22 -				strcat(buffer, ext);
    1.23 -
    1.24  				// create test suite reference
    1.25  				TestSuiteReference *reference = (TestSuiteReference *) SDL_malloc(sizeof(TestSuiteReference));
    1.26  				memset(reference, 0, sizeof(TestSuiteReference));
    1.27  
    1.28 -				int length = strlen(buffer) + 1; // + 1 for '\0'?
    1.29 -				reference->name = SDL_malloc(length * sizeof(char));
    1.30 +
    1.31 +				const int dirSize = SDL_strlen(directoryName);
    1.32 +				const int extSize = SDL_strlen(ext);
    1.33 +				const int nameSize = SDL_strlen(name) + 1;
    1.34 +
    1.35 +				// copy the name
    1.36 +				reference->name = SDL_malloc(nameSize * sizeof(char));
    1.37 +				if(reference->name == NULL) {
    1.38 +					SDL_free(reference);
    1.39 +					return NULL;
    1.40 +				}
    1.41  
    1.42 -				strcpy(reference->name, buffer);
    1.43 +				SDL_snprintf(reference->name, nameSize, "%s", name);
    1.44 +
    1.45 +				// copy the directory path
    1.46 +				const int dpSize = dirSize + nameSize + 1 + extSize + 1;
    1.47 +				reference->directoryPath = SDL_malloc(dpSize * sizeof(char));
    1.48 +				if(reference->directoryPath == NULL) {
    1.49 +					SDL_free(reference->name);
    1.50 +					SDL_free(reference);
    1.51 +					return NULL;
    1.52 +				}
    1.53 +				SDL_snprintf(reference->directoryPath, dpSize, "%s%s.%s",
    1.54 +						directoryName, name, ext);
    1.55  
    1.56  				reference->next = suites;
    1.57  				suites = reference;
    1.58 -
    1.59 -				//printf("Reference added to: %s\n", buffer);
    1.60  			}
    1.61  		}
    1.62  	}
    1.63 @@ -323,18 +333,11 @@
    1.64   * \return Pointer to loaded test suite, or NULL if library could not be loaded
    1.65   */
    1.66  void *
    1.67 -LoadTestSuite(const char *directory, const char *testSuiteName)
    1.68 +LoadTestSuite(const TestSuiteReference *suite)
    1.69  {
    1.70 -	const int nameSize = SDL_strlen(testSuiteName);
    1.71 -	const int dirSize = SDL_strlen(directory);
    1.72 -	const int size = nameSize + dirSize+ 1;
    1.73 -
    1.74 -	char *directoryPath = SDL_malloc(size);
    1.75 -	snprintf(directoryPath, size, "%s%s", directory, testSuiteName);
    1.76 -
    1.77 -	void *library = SDL_LoadObject(directoryPath);
    1.78 +	void *library = SDL_LoadObject(suite->directoryPath);
    1.79  	if(library == NULL) {
    1.80 -		fprintf(stderr, "Loading %s failed\n", testSuiteName);
    1.81 +		fprintf(stderr, "Loading %s failed\n", suite->name);
    1.82  		fprintf(stderr, "%s\n", SDL_GetError());
    1.83  	}
    1.84  
    1.85 @@ -352,11 +355,11 @@
    1.86   * \return Updated TestSuiteReferences with pointer to loaded libraries
    1.87   */
    1.88  TestSuiteReference *
    1.89 -LoadTestSuites(const char *directory, TestSuiteReference *suites)
    1.90 +LoadTestSuites(TestSuiteReference *suites)
    1.91  {
    1.92  	TestSuiteReference *reference = NULL;
    1.93  	for(reference = suites; reference; reference = reference->next) {
    1.94 -		reference->library = LoadTestSuite(directory, reference->name);
    1.95 +		reference->library = LoadTestSuite(reference);
    1.96  	}
    1.97  
    1.98  	return suites;
    1.99 @@ -375,6 +378,7 @@
   1.100  	TestSuiteReference *ref = suites;
   1.101  	while(ref) {
   1.102  		SDL_free(ref->name);
   1.103 +		SDL_free(ref->directoryPath);
   1.104  		SDL_UnloadObject(ref->library);
   1.105  
   1.106  		TestSuiteReference *temp = ref->next;
   1.107 @@ -691,7 +695,7 @@
   1.108  	const Uint32 startTicks = SDL_GetTicks();
   1.109  
   1.110  	TestSuiteReference *suites = ScanForTestSuites(DEFAULT_TEST_DIRECTORY, extension);
   1.111 -	suites = LoadTestSuites(DEFAULT_TEST_DIRECTORY, suites);
   1.112 +	suites = LoadTestSuites(suites);
   1.113  
   1.114  	TestCase *testCases = LoadTestCases(suites);
   1.115  
     2.1 --- a/test/test-automation/xml.c	Thu Jun 30 18:11:48 2011 +0300
     2.2 +++ b/test/test-automation/xml.c	Fri Jul 01 11:12:35 2011 +0300
     2.3 @@ -208,10 +208,10 @@
     2.4  	const int tempSize = sizeStyleStart + sizeStyleEnd + sizeStyleSheetName + 1;
     2.5  	char *style = SDL_malloc(tempSize);
     2.6  	memset(style, 0, tempSize);
     2.7 -	snprintf(style, tempSize, "%s%s%s", styleStart, xslStyle, styleEnd);
     2.8 +	SDL_snprintf(style, tempSize, "%s%s%s", styleStart, xslStyle, styleEnd);
     2.9  
    2.10  	memset(buffer, 0, bufferSize);
    2.11 -	snprintf(buffer, bufferSize, "<%s>", rootTag);
    2.12 +	SDL_snprintf(buffer, bufferSize, "<%s>", rootTag);
    2.13  
    2.14  	AddOpenTag(rootTag);
    2.15  
    2.16 @@ -243,7 +243,7 @@
    2.17  XMLOpenElement(const char *tag)
    2.18  {
    2.19  	memset(buffer, 0, bufferSize);
    2.20 -	snprintf(buffer, bufferSize, "<%s>", tag);
    2.21 +	SDL_snprintf(buffer, bufferSize, "<%s>", tag);
    2.22  
    2.23  	AddOpenTag(tag);
    2.24  
    2.25 @@ -269,7 +269,7 @@
    2.26  	}
    2.27  
    2.28  	memset(buffer, 0, bufferSize);
    2.29 -	snprintf(buffer, bufferSize, "%s", escapedContent);
    2.30 +	SDL_snprintf(buffer, bufferSize, "%s", escapedContent);
    2.31  	SDL_free((char *)escapedContent);
    2.32  
    2.33  	const int size = SDL_strlen(buffer);
    2.34 @@ -312,9 +312,9 @@
    2.35  		int breakOut = 0;
    2.36  		if(SDL_strncmp(lowOpenTag, lowTag, compSize) == 0) {
    2.37  			breakOut = 1;
    2.38 -			snprintf(buffer, bufferSize, "</%s>", tag);
    2.39 +			SDL_snprintf(buffer, bufferSize, "</%s>", tag);
    2.40  		} else {
    2.41 -			snprintf(buffer, bufferSize, "</%s>", openTag->tag);
    2.42 +			SDL_snprintf(buffer, bufferSize, "</%s>", openTag->tag);
    2.43  		}
    2.44  
    2.45  		SDL_free(lowOpenTag);