Ejemplo n.º 1
0
/* carry out all tests. Tests are specified via a file name
 * wildcard. Each of the files is read and the test carried
 * out.
 * Returns the number of tests that failed. Zero means all
 * success.
 */
int
doTests(int fd, char *files)
{
	int ret;
	char *testFile;
	glob_t testFiles;
	size_t i = 0;
	struct stat fileInfo;

	glob(files, GLOB_MARK, NULL, &testFiles);

	for(i = 0; i < testFiles.gl_pathc; i++) {
		testFile = testFiles.gl_pathv[i];

		if(stat((char*) testFile, &fileInfo) != 0) 
			continue; /* continue with the next file if we can't stat() the file */

		/* all regular files are run through the test logic. Symlinks don't work. */
		if(S_ISREG(fileInfo.st_mode)) { /* config file */
			if(verbose) printf("processing test case '%s' ... ", testFile);
			ret = processTestFile(fd, testFile);
			if(ret == 0) {
				if(verbose) printf("successfully completed\n");
			} else {
				if(!verbose)
					printf("test '%s' ", testFile);
				printf("failed!\n");
			}
		}
	}
	globfree(&testFiles);

	if(iTests == 0) {
		printf("Error: no test cases found, no tests executed.\n");
		iFailed = 1;
	} else {
		printf("Number of tests run: %d, number of failures: %d\n", iTests, iFailed);
	}

	return(iFailed);
}
int main(int argc, char ** argv) {

   //
    // Initialize the Xerces-c environment
    //
	try
    {
        XMLPlatformUtils::Initialize();
    }

    catch (const XMLException& toCatch)
    {
        fprintf(stderr, "Error during initialization of xerces-c: %s\n",
            XMLString::transcode(toCatch.getMessage()));
         return 1;
    }

    //
    // Parse the command line, which should specify exactly one file, which is an
    //   xml file containing the list of test files to be processed.
    //
    if (argc != 2) {
        printf("usage: %s file_name \n"
               "   where file name is the xml file specifying the list of test files.", argv[0]);
        return 1;
    }
    DOMDocument* fileListDoc = parseFile(argv[1]);
    if (fileListDoc == 0) return 1;


    //
    // Iterate over the list of files, running each as a test.
    //
    XMLCh tempStr[4000];
    XMLString::transcode("testFile", tempStr, 3999);
    DOMNodeList* list = fileListDoc->getElementsByTagName(tempStr);
    int i;
    int numFiles = list->getLength();
    for (i=0; i<numFiles; i++)
    {
        ++gTestsRun;
        DOMNode* tmpNode3 = list->item(i);
        XMLString::transcode("name", tempStr, 3999);
        const XMLCh* fileName = ((DOMElement*) tmpNode3)->getAttribute(tempStr);
        if (processTestFile(fileName) == false)
            ++gTestsFailed;
    };



    //
    // We are done.  Print out a summary of the results
    //
    printf("Encoding Tests Results Summary: \n"
           "   %d encoding tests run.\n"
           "   %d tests passed,\n"
           "   %d tests failed\n", gTestsRun, gTestsRun-gTestsFailed, gTestsFailed);

    delete parser;
    parser = 0;
   return 0;
};