You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by am...@apache.org on 2009/06/03 18:59:46 UTC
svn commit: r781474 - in /xerces/c/branches/xerces-3.0:
projects/Win32/VC6/xerces-all/XSTSHarness/
projects/Win32/VC8/xerces-all/XSTSHarness/
projects/Win32/VC9/xerces-all/XSTSHarness/ tests/ tests/src/XSTSHarness/
Author: amassari
Date: Wed Jun 3 16:59:46 2009
New Revision: 781474
URL: http://svn.apache.org/viewvc?rev=781474&view=rev
Log:
Improve XSTSHarness to also run the XML Test Suite
Added:
xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.cpp (with props)
xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.hpp (with props)
Modified:
xerces/c/branches/xerces-3.0/projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp
xerces/c/branches/xerces-3.0/projects/Win32/VC8/xerces-all/XSTSHarness/XSTSHarness.vcproj
xerces/c/branches/xerces-3.0/projects/Win32/VC9/xerces-all/XSTSHarness/XSTSHarness.vcproj
xerces/c/branches/xerces-3.0/tests/Makefile.am
xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarness.cpp
xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarness.hpp
xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarnessHandlers.cpp
xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarnessHandlers.hpp
Modified: xerces/c/branches/xerces-3.0/projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp?rev=781474&r1=781473&r2=781474&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.0/projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp (original)
+++ xerces/c/branches/xerces-3.0/projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp Wed Jun 3 16:59:46 2009
@@ -97,6 +97,10 @@
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\XSTSHarnessHandlers.hpp
# End Source File
+# Begin Source File
+
+SOURCE=..\..\..\..\..\tests\src\XSTSHarness\XMLHarnessHandlers.hpp
+# End Source File
# End Group
# Begin Group "Resource Files"
Modified: xerces/c/branches/xerces-3.0/projects/Win32/VC8/xerces-all/XSTSHarness/XSTSHarness.vcproj
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/projects/Win32/VC8/xerces-all/XSTSHarness/XSTSHarness.vcproj?rev=781474&r1=781473&r2=781474&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.0/projects/Win32/VC8/xerces-all/XSTSHarness/XSTSHarness.vcproj (original)
+++ xerces/c/branches/xerces-3.0/projects/Win32/VC8/xerces-all/XSTSHarness/XSTSHarness.vcproj Wed Jun 3 16:59:46 2009
@@ -976,6 +976,10 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
+ RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XMLHarnessHandlers.cpp"
+ >
+ </File>
+ <File
RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XSTSHarness.cpp"
>
</File>
@@ -990,6 +994,10 @@
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
+ RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XMLHarnessHandlers.hpp"
+ >
+ </File>
+ <File
RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XSTSHarness.hpp"
>
</File>
Modified: xerces/c/branches/xerces-3.0/projects/Win32/VC9/xerces-all/XSTSHarness/XSTSHarness.vcproj
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/projects/Win32/VC9/xerces-all/XSTSHarness/XSTSHarness.vcproj?rev=781474&r1=781473&r2=781474&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.0/projects/Win32/VC9/xerces-all/XSTSHarness/XSTSHarness.vcproj (original)
+++ xerces/c/branches/xerces-3.0/projects/Win32/VC9/xerces-all/XSTSHarness/XSTSHarness.vcproj Wed Jun 3 16:59:46 2009
@@ -983,6 +983,10 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
+ RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XMLHarnessHandlers.cpp"
+ >
+ </File>
+ <File
RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XSTSHarness.cpp"
>
</File>
@@ -997,6 +1001,10 @@
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
+ RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XMLHarnessHandlers.hpp"
+ >
+ </File>
+ <File
RelativePath="..\..\..\..\..\tests\src\XSTSHarness\XSTSHarness.hpp"
>
</File>
Modified: xerces/c/branches/xerces-3.0/tests/Makefile.am
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/tests/Makefile.am?rev=781474&r1=781473&r2=781474&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.0/tests/Makefile.am (original)
+++ xerces/c/branches/xerces-3.0/tests/Makefile.am Wed Jun 3 16:59:46 2009
@@ -115,7 +115,9 @@
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
Added: xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.cpp?rev=781474&view=auto
==============================================================================
--- xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.cpp (added)
+++ xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.cpp Wed Jun 3 16:59:46 2009
@@ -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();
+ }
+}
Propchange: xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.hpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.hpp?rev=781474&view=auto
==============================================================================
--- xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.hpp (added)
+++ xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.hpp Wed Jun 3 16:59:46 2009
@@ -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;
+};
+
Propchange: xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XMLHarnessHandlers.hpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarness.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarness.cpp?rev=781474&r1=781473&r2=781474&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarness.cpp (original)
+++ xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarness.cpp Wed Jun 3 16:59:46 2009
@@ -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 @@
}
//
- // 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);
Modified: xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarness.hpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarness.hpp?rev=781474&r1=781473&r2=781474&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarness.hpp (original)
+++ xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarness.hpp Wed Jun 3 16:59:46 2009
@@ -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 @@
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
Modified: xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarnessHandlers.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarnessHandlers.cpp?rev=781474&r1=781473&r2=781474&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarnessHandlers.cpp (original)
+++ xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarnessHandlers.cpp Wed Jun 3 16:59:46 2009
@@ -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 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 @@
}
}
-// ---------------------------------------------------------------------------
-// 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);
-}
-
Modified: xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarnessHandlers.hpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarnessHandlers.hpp?rev=781474&r1=781473&r2=781474&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarnessHandlers.hpp (original)
+++ xerces/c/branches/xerces-3.0/tests/src/XSTSHarness/XSTSHarnessHandlers.hpp Wed Jun 3 16:59:46 2009
@@ -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 @@
bool fSkipped;
};
-class XSTSHarnessHandlers : public DefaultHandler
+class XSTSHarnessHandlers : public BaseHarnessHandlers
{
public:
// -----------------------------------------------------------------------
@@ -100,50 +59,15 @@
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;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org