diff --git a/projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp b/projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp index d9bb6ae5b38910a208b9c3be6bea0e66a92b1c06..4ffed56f68e9c8d4b6bd395ca1d4f7631cd7a4e3 100644 --- a/projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp +++ b/projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp @@ -97,6 +97,10 @@ SOURCE=..\..\..\..\..\tests\src\XSTSHarness\XSTSHarness.cpp SOURCE=..\..\..\..\..\tests\src\XSTSHarness\XSTSHarnessHandlers.cpp # End Source File +# Begin Source File + +SOURCE=..\..\..\..\..\tests\src\XSTSHarness\XMLHarnessHandlers.cpp +# End Source File # End Group # Begin Group "Header Files" @@ -109,6 +113,10 @@ SOURCE=..\..\..\..\..\tests\src\XSTSHarness\XSTSHarness.hpp SOURCE=..\..\..\..\..\tests\src\XSTSHarness\XSTSHarnessHandlers.hpp # End Source File +# Begin Source File + +SOURCE=..\..\..\..\..\tests\src\XSTSHarness\XMLHarnessHandlers.hpp +# End Source File # End Group # Begin Group "Resource Files" diff --git a/projects/Win32/VC8/xerces-all/XSTSHarness/XSTSHarness.vcproj b/projects/Win32/VC8/xerces-all/XSTSHarness/XSTSHarness.vcproj index faf8e29e3706ce4238b887147e37a9e7216e5ef4..a9174a40c497421ff6ae59990221df35a42814a1 100644 --- a/projects/Win32/VC8/xerces-all/XSTSHarness/XSTSHarness.vcproj +++ b/projects/Win32/VC8/xerces-all/XSTSHarness/XSTSHarness.vcproj @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="Windows-1252"?> <VisualStudioProject ProjectType="Visual C++" - Version="8,00" + Version="8.00" Name="XSTSHarness" ProjectGUID="{D92806DD-C591-4782-BCF2-8A0D0338D67A}" RootNamespace="XSTSHarness" @@ -975,6 +975,10 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > + <File + RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XMLHarnessHandlers.cpp" + > + </File> <File RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XSTSHarness.cpp" > @@ -989,6 +993,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + <File + RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XMLHarnessHandlers.hpp" + > + </File> <File RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XSTSHarness.hpp" > diff --git a/projects/Win32/VC9/xerces-all/XSTSHarness/XSTSHarness.vcproj b/projects/Win32/VC9/xerces-all/XSTSHarness/XSTSHarness.vcproj index 4c25555f7963563125b1d3d210a389f7377962b3..70ea1d9faf10136bdc2c4f5920d39054d4861ce4 100644 --- a/projects/Win32/VC9/xerces-all/XSTSHarness/XSTSHarness.vcproj +++ b/projects/Win32/VC9/xerces-all/XSTSHarness/XSTSHarness.vcproj @@ -982,6 +982,10 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > + <File + RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XMLHarnessHandlers.cpp" + > + </File> <File RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XSTSHarness.cpp" > @@ -996,6 +1000,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + <File + RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XMLHarnessHandlers.hpp" + > + </File> <File RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XSTSHarness.hpp" > diff --git a/tests/Makefile.am b/tests/Makefile.am index e9ec87ffef97dbbb672bd7180d4d62d79986055c..ad0122b819636fed18f6b0fd25a4b22efc11b227 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -115,7 +115,9 @@ testprogs += XSTSHarness XSTSHarness_SOURCES = src/XSTSHarness/XSTSHarness.cpp \ src/XSTSHarness/XSTSHarness.hpp \ src/XSTSHarness/XSTSHarnessHandlers.cpp \ - src/XSTSHarness/XSTSHarnessHandlers.hpp + src/XSTSHarness/XSTSHarnessHandlers.hpp \ + src/XSTSHarness/XMLHarnessHandlers.cpp \ + src/XSTSHarness/XMLHarnessHandlers.hpp # Fails to compile under gcc4 (values too long for long type) testprogs += XSValueTest diff --git a/tests/src/XSTSHarness/XMLHarnessHandlers.cpp b/tests/src/XSTSHarness/XMLHarnessHandlers.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4686194b2efc60062147a3ae5bf9135f2ba1ffb8 --- /dev/null +++ b/tests/src/XSTSHarness/XMLHarnessHandlers.cpp @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * $Id$ + */ + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include "XMLHarnessHandlers.hpp" +#include <xercesc/sax2/Attributes.hpp> +#include <xercesc/sax/SAXParseException.hpp> +#include <xercesc/sax/SAXException.hpp> +#include <xercesc/validators/common/Grammar.hpp> +#include <xercesc/util/OutOfMemoryException.hpp> +#include <xercesc/util/BinInputStream.hpp> + +// --------------------------------------------------------------------------- +// XMLHarnessHandlers: Constructors and Destructor +// --------------------------------------------------------------------------- +XMLHarnessHandlers::XMLHarnessHandlers(const XMLCh* baseURL) : BaseHarnessHandlers(baseURL) +, fTestBaseURL(5) +{ + fParser = XMLReaderFactory::createXMLReader(); + fParser->setFeature(XMLUni::fgSAX2CoreValidation, true); + fParser->setFeature(XMLUni::fgXercesDynamic, false); + fParser->setErrorHandler(&fErrorHandler); + + fTestBaseURL.push(new XMLURL(fBaseURL)); +} + +XMLHarnessHandlers::~XMLHarnessHandlers() +{ + delete fParser; +} + +static XMLCh szTest[]={ chLatin_T, chLatin_E, chLatin_S, chLatin_T, chNull }; +static XMLCh szTestCases[]={ chLatin_T, chLatin_E, chLatin_S, chLatin_T, chLatin_C, chLatin_A, chLatin_S, chLatin_E, chLatin_S, chNull }; +static XMLCh szID[]={ chLatin_I, chLatin_D, chNull }; +static XMLCh szURI[]={ chLatin_U, chLatin_R, chLatin_I, chNull }; +static XMLCh szType[]={ chLatin_T, chLatin_Y, chLatin_P, chLatin_E, chNull }; +static XMLCh szValid[]={ chLatin_v, chLatin_a, chLatin_l, chLatin_i, chLatin_d, chNull }; +static XMLCh szInvalid[]={ chLatin_i, chLatin_n, chLatin_v, chLatin_a, chLatin_l, chLatin_i, chLatin_d, chNull }; +static XMLCh szNotWellFormed[]={ chLatin_n, chLatin_o, chLatin_t, chDash, chLatin_w, chLatin_f, chNull }; +static XMLCh szError[]={ chLatin_e, chLatin_r, chLatin_r, chLatin_o, chLatin_r, chNull }; +static XMLCh szBase[]={ chLatin_x, chLatin_m, chLatin_l, chColon, chLatin_b, chLatin_a, chLatin_s, chLatin_e, chNull }; +static XMLCh szNamespace[]={ chLatin_N, chLatin_A, chLatin_M, chLatin_E, chLatin_S, chLatin_P, chLatin_A, chLatin_C, chLatin_E, chNull }; +static XMLCh szNO[]={ chLatin_n, chLatin_o, chNull }; + +// --------------------------------------------------------------------------- +// XMLHarnessHandlers: Implementation of the SAX DocumentHandler interface +// --------------------------------------------------------------------------- +void XMLHarnessHandlers::startElement(const XMLCh* const uri + , const XMLCh* const localname + , const XMLCh* const /* qname */ + , const Attributes& attrs) +{ + if(XMLString::equals(localname, szTestCases)) + { + const XMLCh* baseUrl=attrs.getValue(szBase); + XMLURL newBase; + XMLURL prevBase=*fTestBaseURL.peek(); + if(baseUrl!=NULL) + newBase.setURL(prevBase, baseUrl); + else + newBase=prevBase; + fTestBaseURL.push(new XMLURL(newBase)); + } + else if(XMLString::equals(localname, szTest)) + { + const XMLCh* useNS=attrs.getValue(szNamespace); + const XMLCh* testName=attrs.getValue(szID); + XMLURL testSet; + testSet.setURL(*fTestBaseURL.peek(), attrs.getValue(szURI)); + bool success=true, fatalFailure=false; + try + { + if(useNS!=NULL && XMLString::equals(useNS, szNO)) + { + fParser->setFeature(XMLUni::fgSAX2CoreNameSpaces, false); + fParser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false); + } + else + { + fParser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); + fParser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, true); + } + fErrorHandler.resetErrors(); + fParser->parse(testSet.getURLText()); + } + catch (const OutOfMemoryException&) + { + fatalFailure=true; + XERCES_STD_QUALIFIER cout << "Test " << StrX(testName) << " ran out of memory" << XERCES_STD_QUALIFIER endl; + success=false; + } + catch(const XMLException& exc) + { + XERCES_STD_QUALIFIER cout << "Test " << StrX(testName) << " threw " << StrX(exc.getMessage()) << XERCES_STD_QUALIFIER endl; + success=false; + } + catch (...) + { + fatalFailure=true; + XERCES_STD_QUALIFIER cout << "Test " << StrX(testName) << " crashed" << XERCES_STD_QUALIFIER endl; + success=false; + exit(1); + } + fTests++; + if(fatalFailure) + { + fFailures++; + printFile(testSet); + } + else + { + ValidityOutcome expResult=unknown; + const XMLCh* validity=attrs.getValue(szType); + if(XMLString::equals(validity, szValid)) + expResult=valid; + else if(XMLString::equals(validity, szInvalid) || XMLString::equals(validity, szNotWellFormed) || XMLString::equals(validity, szError) ) + expResult=invalid; + else + XERCES_STD_QUALIFIER cerr << "Unknown result type " << StrX(validity) << XERCES_STD_QUALIFIER endl; + if(success && !fErrorHandler.getSawErrors()) + { + if(expResult!=valid) + { + fFailures++; + XERCES_STD_QUALIFIER cout << "Test " << StrX(testName) << " succeeded but was expected to fail" << XERCES_STD_QUALIFIER endl; + printFile(testSet); + } + } + else + { + if(expResult!=invalid) + { + fFailures++; + XERCES_STD_QUALIFIER cout << "Test " << StrX(testName) << " failed but was expected to pass" << XERCES_STD_QUALIFIER endl; + XERCES_STD_QUALIFIER cout << "Reported error: " << StrX(fErrorHandler.getErrorText()) << XERCES_STD_QUALIFIER endl; + printFile(testSet); + } + } + } + } +} + +void XMLHarnessHandlers::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname) +{ + if(XMLString::equals(localname, szTestCases)) + { + fTestBaseURL.pop(); + } +} diff --git a/tests/src/XSTSHarness/XMLHarnessHandlers.hpp b/tests/src/XSTSHarness/XMLHarnessHandlers.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c12c1c3daebd2d5c0960b7d2f6fc425720dec95e --- /dev/null +++ b/tests/src/XSTSHarness/XMLHarnessHandlers.hpp @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * $Id$ + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include "XSTSHarness.hpp" +#include <xercesc/sax2/SAX2XMLReader.hpp> +#include <xercesc/sax2/Attributes.hpp> +#include <xercesc/util/XMLURL.hpp> +#include <xercesc/util/RefStackOf.hpp> + +XERCES_CPP_NAMESPACE_USE + +class XMLHarnessHandlers : public BaseHarnessHandlers +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + XMLHarnessHandlers(const XMLCh* baseURL); + ~XMLHarnessHandlers(); + + // ----------------------------------------------------------------------- + // Handlers for the SAX ContentHandler interface + // ----------------------------------------------------------------------- + void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs); + void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname); + +private: + SAX2XMLReader* fParser; + BaseErrorHandler fErrorHandler; + RefStackOf<XMLURL> fTestBaseURL; +}; + diff --git a/tests/src/XSTSHarness/XSTSHarness.cpp b/tests/src/XSTSHarness/XSTSHarness.cpp index 47c183441ce6ad05628ee3c60cdea4318aae599d..79ea85aa75f39fcd9cf5769db3999330053bea58 100644 --- a/tests/src/XSTSHarness/XSTSHarness.cpp +++ b/tests/src/XSTSHarness/XSTSHarness.cpp @@ -24,7 +24,11 @@ // Includes // --------------------------------------------------------------------------- #include "XSTSHarness.hpp" +#include "XSTSHarnessHandlers.hpp" +#include "XMLHarnessHandlers.hpp" #include <xercesc/util/PlatformUtils.hpp> +#include <xercesc/util/OutOfMemoryException.hpp> +#include <xercesc/util/BinInputStream.hpp> #include <xercesc/sax2/SAX2XMLReader.hpp> #include <xercesc/sax2/XMLReaderFactory.hpp> #if defined(XERCES_NEW_IOSTREAMS) @@ -34,20 +38,150 @@ #endif #include <xercesc/util/OutOfMemoryException.hpp> +static XMLCh sz_XMLTestSuiteRoot[]={ chLatin_T, chLatin_E, chLatin_S, chLatin_T, chLatin_S, chLatin_U, chLatin_I, chLatin_T, chLatin_E, chNull }; +const XMLCh dummy[]={ chLatin_f, chLatin_i, chLatin_l, chLatin_e, chColon, chForwardSlash, chForwardSlash, + chLatin_d, chLatin_u, chLatin_m, chLatin_m, chLatin_y, chForwardSlash, chNull }; + + // --------------------------------------------------------------------------- // Local helper methods // --------------------------------------------------------------------------- void usage() { - XERCES_STD_QUALIFIER cout << "\nUsage:\n" - " XSTSHarness <XSTS testSet>\n\n" - "This program runs the tests listed in the XMLSchema Test Suite:\n" - "download the suite from http://www.w3.org/XML/2004/xml-schema-test-suite\n" - "and uncompress it. Then run this executable against each .testSet\n" - "file found in the suite.\n\n" + XERCES_STD_QUALIFIER cout << + "\n" + "Usage:\n" + " XSTSHarness <testSet>\n" + "\n" + "This program runs the tests listed in the XMLSchema Test Suite, available at\n" + "http://www.w3.org/XML/2004/xml-schema-test-suite/xmlschema2006-11-06/xsts-2007-06-20.tar.gz\n" + "Run this executable against the suite.xml file found in the top directory\n" + "\n" + "It also runs the tests listed in the XML Test Suite, available at\n" + "http://www.w3.org/XML/Test/xmlts20080827.zip\n" + "Run this executable against the xmlconf.xml file found in the top directory\n" + "\n" << XERCES_STD_QUALIFIER endl; } +BaseHarnessHandlers::BaseHarnessHandlers(const XMLCh* baseURL) : + fSawErrors(false), + fBaseURL(baseURL), + fFailures(0), + fTests(0) +{ +} + +void BaseHarnessHandlers::error(const SAXParseException& e) +{ + fSawErrors = true; + XERCES_STD_QUALIFIER cout << "\nError at file " << StrX(e.getSystemId()) + << ", line " << e.getLineNumber() + << ", char " << e.getColumnNumber() + << "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; +} + +void BaseHarnessHandlers::fatalError(const SAXParseException& e) +{ + fSawErrors = true; + XERCES_STD_QUALIFIER cout << "\nFatal Error at file " << StrX(e.getSystemId()) + << ", line " << e.getLineNumber() + << ", char " << e.getColumnNumber() + << "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; +} + +void BaseHarnessHandlers::warning(const SAXParseException& e) +{ + XERCES_STD_QUALIFIER cout << "\nWarning at file " << StrX(e.getSystemId()) + << ", line " << e.getLineNumber() + << ", char " << e.getColumnNumber() + << "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; +} + +void BaseHarnessHandlers::printFile(XMLURL& url) +{ + if(XMLString::equals(url.getURLText(), dummy)) + return; + BinInputStream* stream=url.makeNewStream(); + if(stream==NULL) + { + XERCES_STD_QUALIFIER cout << "File " << StrX(url.getURLText()) << " is missing" << XERCES_STD_QUALIFIER endl; + return; + } + XERCES_STD_QUALIFIER cout << "Content of file " << StrX(url.getURLText()) << XERCES_STD_QUALIFIER endl; + XMLByte buffer[256]; + XMLSize_t nRead; + while((nRead=stream->readBytes(buffer, 255)) >0) + { + buffer[nRead]=0; + // sending data containing \n\r to cout generates \n\n\r, so strip any \r + XMLSize_t idx=0; + while(true) + { + int cr=XMLString::indexOf((const char*)buffer, '\r', idx); + if(cr==-1) + break; + memmove(&buffer[cr], &buffer[cr+1], XMLString::stringLen((const char*)&buffer[cr+1])+1); + idx=cr; + if(buffer[idx]==0) + break; + } + XERCES_STD_QUALIFIER cout << (const char*)buffer; + } + XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl; + delete stream; +} + +///////////////////////////////////////////////////////////////////// + +void BaseErrorHandler::error(const SAXParseException& exc) +{ + fSawErrors=true; + fErrorText.append(exc.getMessage()); + fErrorText.append(chLF); +} + +void BaseErrorHandler::fatalError(const SAXParseException& exc) +{ + fSawErrors=true; + fErrorText.append(exc.getMessage()); + fErrorText.append(chLF); +} + +///////////////////////////////////////////////////////////////////// + + +class RootExtractor : public DefaultHandler +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + RootExtractor() + { + fIsXMLSuite=false; + } + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + bool isXMLSuite() const + { + return fIsXMLSuite; + } + + // ----------------------------------------------------------------------- + // Handlers for the SAX DocumentHandler interface + // ----------------------------------------------------------------------- + void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs) + { + fIsXMLSuite=XMLString::equals(qname, sz_XMLTestSuiteRoot); + throw fIsXMLSuite; + } + +protected: + bool fIsXMLSuite; +}; // --------------------------------------------------------------------------- // Program entry point @@ -110,22 +244,39 @@ int main(int argC, char* argV[]) } // - // Create a SAX parser object. Then, according to what we were told on - // the command line, set it to validate or not. + // Create a SAX parser object. // SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(); parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); parser->setFeature(XMLUni::fgSAX2CoreValidation, false); const char* xmlFile = argV[argInd]; - // - // Create our SAX handler object and install it on the parser, as the - // document and error handler. - // + + // Discover if the test suite is the XML or XMLSchema one + RootExtractor rootExtractor; + parser->setContentHandler(&rootExtractor); + try + { + parser->parse(xmlFile); + } + catch (...) + { + } + XMLCh* uniFile = XMLString::transcode(xmlFile); XMLCh* uri = new XMLCh[XMLString::stringLen(xmlFile) + 9]; XMLString::fixURI(uniFile, uri); - XSTSHarnessHandlers* handler=new XSTSHarnessHandlers(uri); + BaseHarnessHandlers* handler=NULL; + if(rootExtractor.isXMLSuite()) + { + // XML Test Suite + handler=new XMLHarnessHandlers(uri); + } + else + { + // XMLSchema Test Suite + handler=new XSTSHarnessHandlers(uri); + } XMLString::release(&uniFile); delete [] uri; parser->setContentHandler(handler); diff --git a/tests/src/XSTSHarness/XSTSHarness.hpp b/tests/src/XSTSHarness/XSTSHarness.hpp index b4ff7af384dd2267180a828e1150c43fc7196a45..a23a112cef59a16267e1b9c4e835eec9f911e3c6 100644 --- a/tests/src/XSTSHarness/XSTSHarness.hpp +++ b/tests/src/XSTSHarness/XSTSHarness.hpp @@ -19,6 +19,8 @@ * $Id$ */ +#ifndef XSTS_HARNESS_HPP +#define XSTS_HARNESS_HPP // --------------------------------------------------------------------------- // Includes for all the program files to see @@ -32,10 +34,21 @@ #else #include <iostream.h> #endif -#include "XSTSHarnessHandlers.hpp" #include <xercesc/sax2/XMLReaderFactory.hpp> #include <xercesc/sax2/SAX2XMLReader.hpp> +#include <xercesc/sax2/DefaultHandler.hpp> +#include <xercesc/util/XMLURL.hpp> +XERCES_CPP_NAMESPACE_USE + +typedef enum +{ + unknown, + invalid, + valid +} ValidityOutcome; + +extern const XMLCh dummy[]; // --------------------------------------------------------------------------- // This is a simple class that lets us do easy (though not terribly efficient) @@ -81,3 +94,80 @@ inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& ta target << toDump.localForm(); return target; } + +class BaseHarnessHandlers : public DefaultHandler +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + BaseHarnessHandlers(const XMLCh* baseURL); + + unsigned int getTotalTests() const + { + return fTests; + } + unsigned int getFailedTests() const + { + return fFailures; + } + + bool getSawErrors() const + { + return fSawErrors; + } + + void printFile(XMLURL& url); + + // ----------------------------------------------------------------------- + // Handlers for the SAX ErrorHandler interface + // ----------------------------------------------------------------------- + void warning(const SAXParseException& exc); + void error(const SAXParseException& exc); + void fatalError(const SAXParseException& exc); + void resetErrors() + { + fSawErrors = false; + } + +protected: + XMLURL fBaseURL; + bool fSawErrors; + unsigned int fFailures, fTests; +}; + +class BaseErrorHandler : public ErrorHandler +{ +public: + BaseErrorHandler() : fSawErrors(false) {} + + bool getSawErrors() const + { + return fSawErrors; + } + const XMLCh* getErrorText() + { + return fErrorText.getRawBuffer(); + } + + // ----------------------------------------------------------------------- + // Handlers for the SAX ErrorHandler interface + // ----------------------------------------------------------------------- + void warning(const SAXParseException& exc) {} + void error(const SAXParseException& exc); + void fatalError(const SAXParseException& exc); + void resetErrors() { fSawErrors=false; fErrorText.reset(); } + +private: + // ----------------------------------------------------------------------- + // Private data members + // + // fSawErrors + // This is set by the error handlers, and is queryable later to + // see if any errors occured. + // ----------------------------------------------------------------------- + bool fSawErrors; + XMLBuffer fErrorText; +}; + +#endif diff --git a/tests/src/XSTSHarness/XSTSHarnessHandlers.cpp b/tests/src/XSTSHarness/XSTSHarnessHandlers.cpp index cc7e16c427ae010443484c46cde21a6e1edef292..bac701c15e3bc4129dba02bcd0e26e2ad2807f05 100644 --- a/tests/src/XSTSHarness/XSTSHarnessHandlers.cpp +++ b/tests/src/XSTSHarness/XSTSHarnessHandlers.cpp @@ -22,22 +22,17 @@ // --------------------------------------------------------------------------- // Includes // --------------------------------------------------------------------------- -#include "XSTSHarness.hpp" +#include "XSTSHarnessHandlers.hpp" #include <xercesc/sax2/Attributes.hpp> #include <xercesc/sax/SAXParseException.hpp> #include <xercesc/sax/SAXException.hpp> #include <xercesc/validators/common/Grammar.hpp> #include <xercesc/util/OutOfMemoryException.hpp> -#include <xercesc/util/BinInputStream.hpp> // --------------------------------------------------------------------------- // XSTSHarnessHandlers: Constructors and Destructor // --------------------------------------------------------------------------- -XSTSHarnessHandlers::XSTSHarnessHandlers(const XMLCh* baseURL) : - fSawErrors(false), - fBaseURL(baseURL), - fFailures(0), - fTests(0) +XSTSHarnessHandlers::XSTSHarnessHandlers(const XMLCh* baseURL) : BaseHarnessHandlers(baseURL) { fParser = XMLReaderFactory::createXMLReader(); fParser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); @@ -91,9 +86,6 @@ static XMLCh szTestSuite2[]={ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColo static XMLCh szTestSetRef[]={ chLatin_t, chLatin_e, chLatin_s, chLatin_t, chLatin_S, chLatin_e, chLatin_t, chLatin_R, chLatin_e, chLatin_f, chNull }; -static XMLCh dummy[]={ chLatin_f, chLatin_i, chLatin_l, chLatin_e, chColon, chForwardSlash, chForwardSlash, - chLatin_d, chLatin_u, chLatin_m, chLatin_m, chLatin_y, chForwardSlash, chNull }; - // --------------------------------------------------------------------------- // XSTSHarnessHandlers: Implementation of the SAX DocumentHandler interface // --------------------------------------------------------------------------- @@ -337,88 +329,3 @@ void XSTSHarnessHandlers::endElement(const XMLCh* const uri, } } -// --------------------------------------------------------------------------- -// XSTSHarnessHandlers: Overrides of the SAX ErrorHandler interface -// --------------------------------------------------------------------------- -void XSTSHarnessHandlers::error(const SAXParseException& e) -{ - fSawErrors = true; - XERCES_STD_QUALIFIER cout << "\nError at file " << StrX(e.getSystemId()) - << ", line " << e.getLineNumber() - << ", char " << e.getColumnNumber() - << "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; -} - -void XSTSHarnessHandlers::fatalError(const SAXParseException& e) -{ - fSawErrors = true; - XERCES_STD_QUALIFIER cout << "\nFatal Error at file " << StrX(e.getSystemId()) - << ", line " << e.getLineNumber() - << ", char " << e.getColumnNumber() - << "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; -} - -void XSTSHarnessHandlers::warning(const SAXParseException& e) -{ - XERCES_STD_QUALIFIER cout << "\nWarning at file " << StrX(e.getSystemId()) - << ", line " << e.getLineNumber() - << ", char " << e.getColumnNumber() - << "\n Message: " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl; -} - -void XSTSHarnessHandlers::resetErrors() -{ - fSawErrors = false; -} - -// --------------------------------------------------------------------------- -// XSTSHarnessHandlers: Helpers -// --------------------------------------------------------------------------- -void XSTSHarnessHandlers::printFile(XMLURL& url) -{ - if(XMLString::equals(url.getURLText(), dummy)) - return; - BinInputStream* stream=url.makeNewStream(); - if(stream==NULL) - { - XERCES_STD_QUALIFIER cout << "File " << StrX(url.getURLText()) << " is missing" << XERCES_STD_QUALIFIER endl; - return; - } - XERCES_STD_QUALIFIER cout << "Content of file " << StrX(url.getURLText()) << XERCES_STD_QUALIFIER endl; - XMLByte buffer[256]; - XMLSize_t nRead; - while((nRead=stream->readBytes(buffer, 255)) >0) - { - buffer[nRead]=0; - // sending data containing \n\r to cout generates \n\n\r, so strip any \r - XMLSize_t idx=0; - while(true) - { - int cr=XMLString::indexOf((const char*)buffer, '\r', idx); - if(cr==-1) - break; - memmove(&buffer[cr], &buffer[cr+1], XMLString::stringLen((const char*)&buffer[cr+1])+1); - idx=cr; - if(buffer[idx]==0) - break; - } - XERCES_STD_QUALIFIER cout << (const char*)buffer; - } - XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl; - delete stream; -} - -void XSTSErrorHandler::error(const SAXParseException& exc) -{ - fSawErrors=true; - fErrorText.append(exc.getMessage()); - fErrorText.append(chLF); -} - -void XSTSErrorHandler::fatalError(const SAXParseException& exc) -{ - fSawErrors=true; - fErrorText.append(exc.getMessage()); - fErrorText.append(chLF); -} - diff --git a/tests/src/XSTSHarness/XSTSHarnessHandlers.hpp b/tests/src/XSTSHarness/XSTSHarnessHandlers.hpp index bfc16d62cc2bf9dee60c5c00c47ceba5af7f98a5..7d61815c402060a71aa64784cb01781761d330df 100644 --- a/tests/src/XSTSHarness/XSTSHarnessHandlers.hpp +++ b/tests/src/XSTSHarness/XSTSHarnessHandlers.hpp @@ -23,55 +23,14 @@ // --------------------------------------------------------------------------- // Includes // --------------------------------------------------------------------------- +#include "XSTSHarness.hpp" #include <xercesc/sax2/SAX2XMLReader.hpp> #include <xercesc/sax2/Attributes.hpp> #include <xercesc/sax2/DefaultHandler.hpp> -#include <xercesc/util/XMLURL.hpp> #include <xercesc/util/RefVectorOf.hpp> XERCES_CPP_NAMESPACE_USE -class XSTSErrorHandler : public ErrorHandler -{ -public: - XSTSErrorHandler() : fSawErrors(false) {} - - bool getSawErrors() const - { - return fSawErrors; - } - const XMLCh* getErrorText() - { - return fErrorText.getRawBuffer(); - } - - // ----------------------------------------------------------------------- - // Handlers for the SAX ErrorHandler interface - // ----------------------------------------------------------------------- - void warning(const SAXParseException& exc) {} - void error(const SAXParseException& exc); - void fatalError(const SAXParseException& exc); - void resetErrors() { fSawErrors=false; fErrorText.reset(); } - -private: - // ----------------------------------------------------------------------- - // Private data members - // - // fSawErrors - // This is set by the error handlers, and is queryable later to - // see if any errors occured. - // ----------------------------------------------------------------------- - bool fSawErrors; - XMLBuffer fErrorText; -}; - -typedef enum -{ - unknown, - invalid, - valid -} ValidityOutcome; - class XSTSTest { public: @@ -91,7 +50,7 @@ public: bool fSkipped; }; -class XSTSHarnessHandlers : public DefaultHandler +class XSTSHarnessHandlers : public BaseHarnessHandlers { public: // ----------------------------------------------------------------------- @@ -100,50 +59,15 @@ public: XSTSHarnessHandlers(const XMLCh* baseURL); ~XSTSHarnessHandlers(); - unsigned int getTotalTests() const - { - return fTests; - } - unsigned int getFailedTests() const - { - return fFailures; - } - - bool getSawErrors() const - { - return fSawErrors; - } - // ----------------------------------------------------------------------- // Handlers for the SAX ContentHandler interface // ----------------------------------------------------------------------- void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs); void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname); - // ----------------------------------------------------------------------- - // Handlers for the SAX ErrorHandler interface - // ----------------------------------------------------------------------- - void warning(const SAXParseException& exc); - void error(const SAXParseException& exc); - void fatalError(const SAXParseException& exc); - void resetErrors(); - -protected: - void printFile(XMLURL& url); - private: - // ----------------------------------------------------------------------- - // Private data members - // - // fSawErrors - // This is set by the error handlers, and is queryable later to - // see if any errors occured. - // ----------------------------------------------------------------------- - bool fSawErrors; XSTSTest fCurrentTest; - XMLURL fBaseURL; - unsigned int fFailures, fTests; SAX2XMLReader* fParser; - XSTSErrorHandler fErrorHandler; + BaseErrorHandler fErrorHandler; };