dbertoni 02/01/22 10:46:01
Modified: c/Tests/Conf conf.cpp
Log:
Better exception handling.
Revision Changes Path
1.22 +153 -124 xml-xalan/c/Tests/Conf/conf.cpp
Index: conf.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/Tests/Conf/conf.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- conf.cpp 4 Jan 2002 18:43:38 -0000 1.21
+++ conf.cpp 22 Jan 2002 18:46:01 -0000 1.22
@@ -76,14 +76,15 @@
#endif
-// XERCES HEADERS...
-// Most are included by HarnessInit.hpp
#include <parsers/DOMParser.hpp>
-// XALAN HEADERS...
-// Most are included by FileUtility.hpp
+
+
+#include <XalanTransformer/XalanTransformer.hpp>
#include <XalanTransformer/XercesDOMWrapperParsedSource.hpp>
+
+
// HARNESS HEADERS...
#include <Harness/XMLFileReporter.hpp>
#include <Harness/FileUtility.hpp>
@@ -101,12 +102,11 @@
#endif
-FileUtility h;
void
-setHelp()
+setHelp(FileUtility& h)
{
- h.args.help << endl
+ h.args.getHelpStream() << endl
<< "conf dir [-category -out -gold -source (XST | XPL | DOM)]"
<< endl
<< endl
@@ -122,6 +122,8 @@
<< endl;
}
+
+
static const char* const excludeStylesheets[] =
{
"output22.xsl", // Excluded because it outputs EBCDIC
@@ -148,9 +150,14 @@
void
-parseWithTransformer(int sourceType, XalanTransformer &xalan, const
XSLTInputSource &xmlInput,
- const XalanCompiledStylesheet*
styleSheet, const XSLTResultTarget &output,
- XMLFileReporter &logFile)
+parseWithTransformer(
+ int
sourceType,
+ XalanTransformer& xalan,
+ const XSLTInputSource& xmlInput,
+ const XalanCompiledStylesheet* styleSheet,
+ const XSLTResultTarget& output,
+ XMLFileReporter& logFile,
+ FileUtility& h)
{
const XalanParsedSource* parsedSource = 0;
@@ -187,9 +194,13 @@
void
-parseWithXerces(XalanTransformer &xalan, const XSLTInputSource &xmlInput,
- const XalanCompiledStylesheet* styleSheet,
const XSLTResultTarget &output,
- XMLFileReporter &logFile)
+parseWithXerces(
+ XalanTransformer& xalan,
+ const XSLTInputSource& xmlInput,
+ const XalanCompiledStylesheet* styleSheet,
+ const XSLTResultTarget& output,
+ XMLFileReporter& logFile,
+ FileUtility& h)
{
h.data.xmlFormat = XalanDOMString("Xerces_DOM");
@@ -200,6 +211,7 @@
theParser.setDoNamespaces(true);
theParser.parse(xmlInput);
+
DOM_Document theDOM = theParser.getDocument();
theDOM.normalize();
@@ -238,143 +250,160 @@
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
#endif
- // Set the program help string, then get the command line parameters.
- //
- setHelp();
-
- if (h.getParams(argc, argv, "CONF-RESULTS") == true)
+ try
{
- // Call the static initializers for xerces and xalan, and
create a transformer
- //
- HarnessInit xmlPlatformUtils;
- XalanTransformer::initialize();
- XalanTransformer xalan;
+ HarnessInit xmlPlatformUtils;
- // Get drive designation for final analysis and generate Unique
name for results log.
- //
- const XalanDOMString drive(h.getDrive());
// This is used to get stylesheet for final analysis
- const XalanDOMString resultFilePrefix("conf"); // This
& UniqRunid used for log file name.
- const XalanDOMString UniqRunid = h.generateUniqRunid();
- const XalanDOMString resultsFile(drive + h.args.output +
resultFilePrefix + UniqRunid + XMLSuffix);
+ FileUtility h;
- // Open results log, and do some initialization of result data.
+ // Set the program help string, then get the command line
parameters.
//
- XMLFileReporter logFile(resultsFile);
- logFile.logTestFileInit("Conformance Testing:");
- h.data.xmlFormat = XalanDOMString("NotSet");
+ setHelp(h);
- // Get the list of Directories that are below conf and iterate
through them
- //
- bool foundDir = false; // Flag indicates directory
found. Used in conjunction with -sub cmd-line arg.
- const FileNameVectorType dirs =
h.getDirectoryNames(h.args.base);
-
- for(FileNameVectorType::size_type j = 0; j < dirs.size();
++j)
+ if (h.getParams(argc, argv, "CONF-RESULTS") == true)
{
- // Skip all but the specified directory if the -sub
cmd-line option was used.
- //
- const XalanDOMString currentDir(dirs[j]);
- if (length(h.args.sub) > 0 && !equals(currentDir,
h.args.sub))
- {
- continue;
- }
-
- // Check that output directory is there.
- //
- const XalanDOMString theOutputDir = h.args.output +
currentDir;
- h.checkAndCreateDir(theOutputDir);
-
- // Indicate that directory was processed and get test
files from the directory
+ // Call the static initializers for xerces and xalan,
and create a transformer
//
- foundDir = true;
- const FileNameVectorType files =
h.getTestFileNames(h.args.base, currentDir, true);
-
- // Log directory in results log and process it's files.
- //
- logFile.logTestCaseInit(currentDir);
- for(FileNameVectorType::size_type i = 0; i <
files.size(); i++)
+ XalanTransformer::initialize();
+
{
- Hashtable attrs;
- const XalanDOMString currentFile(files[i]);
- if (checkForExclusion(currentFile))
- continue;
-
- h.data.testOrFile = currentFile;
- const XalanDOMString theXSLFile = h.args.base
+ currentDir + pathSep + currentFile;
-
- // Check and see if the .xml file exists. If
not skip this .xsl file and continue.
- bool fileStatus = true;
- const XalanDOMString theXMLFile =
h.generateFileName(theXSLFile, "xml", &fileStatus);
- if (!fileStatus)
- continue;
+ XalanTransformer xalan;
- h.data.xmlFileURL = theXMLFile;
- h.data.xslFileURL = theXSLFile;
-
+ // Get drive designation for final analysis and
generate Unique name for results log.
+ //
+ const XalanDOMString drive(h.getDrive());
// This is used to get stylesheet for final analysis
+ const XalanDOMString resultFilePrefix("conf");
// This & UniqRunid used for log file name.
+ const XalanDOMString UniqRunid =
h.generateUniqRunid();
+ const XalanDOMString resultsFile(drive +
h.args.output + resultFilePrefix + UniqRunid + FileUtility::s_xmlSuffix);
+
+ // Open results log, and do some initialization
of result data.
+ //
+ XMLFileReporter logFile(resultsFile);
+ logFile.logTestFileInit("Conformance Testing:");
+ h.data.xmlFormat = XalanDOMString("NotSet");
- XalanDOMString theGoldFile = h.args.gold +
currentDir + pathSep + currentFile;
- theGoldFile = h.generateFileName(theGoldFile,
"out");
+ // Get the list of Directories that are below
conf and iterate through them
+ //
- const XalanDOMString outbase = h.args.output
+ currentDir + pathSep + currentFile;
- const XalanDOMString theOutputFile =
h.generateFileName(outbase, "out");
+ // Flag indicates directory found. Used in
conjunction with -sub cmd-line arg.
+ bool foundDir = false;
- const XSLTInputSource
xslInputSource(c_wstr(theXSLFile));
- const XSLTInputSource
xmlInputSource(c_wstr(theXMLFile));
- const XSLTResultTarget
resultFile(theOutputFile);
+ const FileNameVectorType dirs =
h.getDirectoryNames(h.args.base);
- // Parsing(compile) the XSL stylesheet and
report the results..
- //
- const XalanCompiledStylesheet* compiledSS = 0;
- xalan.compileStylesheet(xslInputSource,
compiledSS);
- if (compiledSS == 0 )
+ for(FileNameVectorType::size_type j = 0;
j < dirs.size(); ++j)
{
- // Report the failure and be sure to
increment fail count.
+ // Skip all but the specified directory
if the -sub cmd-line option was used.
//
- cout << "Failed to PARSE stylesheet for
" << currentFile << endl;
- h.data.fail += 1;
- logFile.logErrorResult(currentFile,
XalanDOMString("Failed to PARSE stylesheet."));
- continue;
+ const XalanDOMString
currentDir(dirs[j]);
+
+ if (length(h.args.sub) > 0 &&
!equals(currentDir, h.args.sub))
+ {
+ continue;
+ }
+
+ // Check that output directory is there.
+ //
+ const XalanDOMString theOutputDir =
h.args.output + currentDir;
+ h.checkAndCreateDir(theOutputDir);
+
+ // Indicate that directory was
processed and get test files from the directory
+ //
+ foundDir = true;
+ const FileNameVectorType files =
h.getTestFileNames(h.args.base, currentDir, true);
+
+ // Log directory in results log and
process it's files.
+ //
+ logFile.logTestCaseInit(currentDir);
+
+ for(FileNameVectorType::size_type i =
0; i < files.size(); i++)
+ {
+ Hashtable attrs;
+ const XalanDOMString
currentFile(files[i]);
+ if
(checkForExclusion(currentFile))
+ continue;
+
+ h.data.testOrFile = currentFile;
+ const XalanDOMString
theXSLFile = h.args.base + currentDir + FileUtility::s_pathSep + currentFile;
+
+ // Check and see if the .xml
file exists. If not skip this .xsl file and continue.
+ bool fileStatus = true;
+ const XalanDOMString
theXMLFile = h.generateFileName(theXSLFile, "xml", &fileStatus);
+ if (!fileStatus)
+ continue;
+
+ h.data.xmlFileURL = theXMLFile;
+ h.data.xslFileURL = theXSLFile;
+
+
+ XalanDOMString theGoldFile =
h.args.gold + currentDir + FileUtility::s_pathSep + currentFile;
+ theGoldFile =
h.generateFileName(theGoldFile, "out");
+
+ const XalanDOMString outbase =
h.args.output + currentDir + FileUtility::s_pathSep + currentFile;
+ const XalanDOMString
theOutputFile = h.generateFileName(outbase, "out");
+
+ const XSLTInputSource
xslInputSource(c_wstr(theXSLFile));
+ const XSLTInputSource
xmlInputSource(c_wstr(theXMLFile));
+ const XSLTResultTarget
resultFile(theOutputFile);
+
+ // Parsing(compile) the XSL
stylesheet and report the results..
+ //
+ const XalanCompiledStylesheet*
compiledSS = 0;
+
xalan.compileStylesheet(xslInputSource, compiledSS);
+ if (compiledSS == 0 )
+ {
+ // Report the failure
and be sure to increment fail count.
+ //
+ cout << "Failed to
PARSE stylesheet for " << currentFile << endl;
+ h.data.fail += 1;
+
logFile.logErrorResult(currentFile, XalanDOMString("Failed to PARSE
stylesheet."));
+ continue;
+ }
+
+ // Parse the Source XML based
on input parameters, and then perform transform.
+ //
+ switch (h.args.source)
+ {
+ case 0:
+ case 1:
+
parseWithTransformer(h.args.source, xalan, xmlInputSource, compiledSS,
resultFile, logFile, h);
+ break;
+
+ case 2:
+
parseWithXerces(xalan, xmlInputSource, compiledSS, resultFile, logFile, h);
+ break;
+ }
+
+ // Check and report results...
Then delete compiled stylesheet.
+ //
+ h.checkResults(theOutputFile,
theGoldFile, logFile);
+
xalan.destroyStylesheet(compiledSS);
+ }
+
+ logFile.logTestCaseClose("Done",
"Pass");
}
- // Parse the Source XML based on input
parameters, and then perform transform.
+ // Check to see if -sub cmd-line directory was
processed correctly.
//
- switch (h.args.source)
+ if (!foundDir)
{
- case 0:
- case 1:
-
parseWithTransformer(h.args.source, xalan, xmlInputSource, compiledSS,
resultFile, logFile);
- break;
-
- case 2:
- parseWithXerces(xalan,
xmlInputSource, compiledSS, resultFile, logFile);
- break;
+ cout << "Specified test directory: \""
<< c_str(TranscodeToLocalCodePage(h.args.sub)) << "\" not found" << endl;
}
- // Check and report results... Then delete
compiled stylesheet.
- //
- h.checkResults(theOutputFile, theGoldFile,
logFile);
- xalan.destroyStylesheet(compiledSS);
- }
+ h.reportPassFail(logFile, UniqRunid);
+ logFile.logTestFileClose("Conformance ",
"Done");
+ logFile.close();
- logFile.logTestCaseClose("Done", "Pass");
- }
+ h.analyzeResults(xalan, resultsFile);
+ }
- // Check to see if -sub cmd-line directory was processed
correctly.
- //
- if (!foundDir)
- {
- cout << "Specified test directory: \"" <<
c_str(TranscodeToLocalCodePage(h.args.sub)) << "\" not found" << endl;
}
- h.reportPassFail(logFile, UniqRunid);
- logFile.logTestFileClose("Conformance ", "Done");
- logFile.close();
-
- h.analyzeResults(xalan, resultsFile);
-
+ XalanTransformer::terminate();
+ }
+ catch(...)
+ {
+ cerr << "Initialization failed!!!" << endl << endl;
}
-
-
- XalanTransformer::terminate();
return 0;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]