From c408dbb2902da75299388d183281d030cb07a074 Mon Sep 17 00:00:00 2001 From: Alberto Massari <amassari@apache.org> Date: Mon, 16 Oct 2006 07:14:21 +0000 Subject: [PATCH] Added test to run the XMLSchema Test Suite git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@464404 13f79535-47bb-0310-9956-ffa450edef68 --- .../xerces-all/XSTSHarness/XSTSHarness.dsp | 118 ++++++ Projects/Win32/VC6/xerces-all/xerces-all.dsw | 18 + tests/src/XSTSHarness/XSTSHarness.cpp | 194 ++++++++++ tests/src/XSTSHarness/XSTSHarness.hpp | 82 +++++ tests/src/XSTSHarness/XSTSHarnessHandlers.cpp | 347 ++++++++++++++++++ tests/src/XSTSHarness/XSTSHarnessHandlers.hpp | 138 +++++++ 6 files changed, 897 insertions(+) create mode 100644 Projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp create mode 100644 tests/src/XSTSHarness/XSTSHarness.cpp create mode 100644 tests/src/XSTSHarness/XSTSHarness.hpp create mode 100644 tests/src/XSTSHarness/XSTSHarnessHandlers.cpp create mode 100644 tests/src/XSTSHarness/XSTSHarnessHandlers.hpp diff --git a/Projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp b/Projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp new file mode 100644 index 000000000..d9bb6ae5b --- /dev/null +++ b/Projects/Win32/VC6/xerces-all/XSTSHarness/XSTSHarness.dsp @@ -0,0 +1,118 @@ +# Microsoft Developer Studio Project File - Name="XSTSHarness" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=XSTSHarness - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "XSTSHarness.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "XSTSHarness.mak" CFG="XSTSHarness - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "XSTSHarness - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "XSTSHarness - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "XSTSHarness - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\..\..\..\src" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /Fo"..\..\..\..\..\Build\Win32\VC6\Release\obj/" /Fd"..\..\..\..\..\Build\Win32\VC6\Release\obj/" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x410 /d "NDEBUG" +# ADD RSC /l 0x410 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib xerces-c_3.lib /subsystem:console /pdb:"..\..\..\..\..\Build\Win32\VC6\Release/XSTSHarness.pdb" /machine:I386 /out:"..\..\..\..\..\Build\Win32\VC6\Release/XSTSHarness.exe" /libpath:"..\..\..\..\..\Build\Win32\VC6\Release" +# SUBTRACT LINK32 /nologo + +!ELSEIF "$(CFG)" == "XSTSHarness - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\..\..\src" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /Fo"..\..\..\..\..\Build\Win32\VC6\Debug\obj/" /Fd"..\..\..\..\..\Build\Win32\VC6\Debug\obj/" /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x410 /d "_DEBUG" +# ADD RSC /l 0x410 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib xerces-c_3D.lib /subsystem:console /pdb:"..\..\..\..\..\Build\Win32\VC6\Debug/XSTSHarness.pdb" /debug /machine:I386 /out:"..\..\..\..\..\Build\Win32\VC6\Debug/XSTSHarness.exe" /pdbtype:sept /libpath:"..\..\..\..\..\Build\Win32\VC6\Debug" +# SUBTRACT LINK32 /nologo + +!ENDIF + +# Begin Target + +# Name "XSTSHarness - Win32 Release" +# Name "XSTSHarness - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=..\..\..\..\..\tests\src\XSTSHarness\XSTSHarness.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\..\tests\src\XSTSHarness\XSTSHarnessHandlers.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=..\..\..\..\..\tests\src\XSTSHarness\XSTSHarness.hpp +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\..\tests\src\XSTSHarness\XSTSHarnessHandlers.hpp +# End Source File +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/Projects/Win32/VC6/xerces-all/xerces-all.dsw b/Projects/Win32/VC6/xerces-all/xerces-all.dsw index 2e3adefe2..0e44ce7e2 100644 --- a/Projects/Win32/VC6/xerces-all/xerces-all.dsw +++ b/Projects/Win32/VC6/xerces-all/xerces-all.dsw @@ -378,6 +378,21 @@ Package=<4> ############################################################################### +Project: "XSTSHarness"=".\XSTSHarness\XSTSHarness.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name XercesLib + End Project Dependency +}}} + +############################################################################### + Project: "XSValueTest"=".\XSValueTest\XSValueTest.dsp" - Package Owner=<4> Package=<5> @@ -512,6 +527,9 @@ Package=<4> Begin Project Dependency Project_Dep_Name XSValueTest End Project Dependency + Begin Project Dependency + Project_Dep_Name XSTSHarness + End Project Dependency }}} ############################################################################### diff --git a/tests/src/XSTSHarness/XSTSHarness.cpp b/tests/src/XSTSHarness/XSTSHarness.cpp new file mode 100644 index 000000000..f086bd3b4 --- /dev/null +++ b/tests/src/XSTSHarness/XSTSHarness.cpp @@ -0,0 +1,194 @@ +/* + * Copyright 1999-2001,2004 The Apache Software Foundation. + * + * Licensed 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/util/PlatformUtils.hpp> +#include <xercesc/sax2/SAX2XMLReader.hpp> +#include <xercesc/sax2/XMLReaderFactory.hpp> +#if defined(XERCES_NEW_IOSTREAMS) +#include <fstream> +#else +#include <fstream.h> +#endif +#include <xercesc/util/OutOfMemoryException.hpp> + +// --------------------------------------------------------------------------- +// 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 endl; +} + + +// --------------------------------------------------------------------------- +// Program entry point +// --------------------------------------------------------------------------- +int main(int argC, char* argV[]) +{ + + // Check command line and extract arguments. + if (argC < 2) + { + usage(); + return 1; + } + + int argInd; + for (argInd = 1; argInd < argC; argInd++) + { + // Break out on first parm not starting with a dash + if (argV[argInd][0] != '-') + break; + + // Watch for special case help request + if (!strcmp(argV[argInd], "-?")) + { + usage(); + return 2; + } + // TODO: add option to generate the XML summarizing the result + else if (!strncmp(argV[argInd], "-v=", 3) + || !strncmp(argV[argInd], "-V=", 3)) + { + } + else + { + XERCES_STD_QUALIFIER cout << "Unknown option '" << argV[argInd] + << "', ignoring it\n" << XERCES_STD_QUALIFIER endl; + } + } + + // + // There should be only one and only one parameter left, and that + // should be the file name. + // + if (argInd != argC - 1) + { + usage(); + return 1; + } + + try + { + XMLPlatformUtils::Initialize(); + } + + catch (const XMLException& toCatch) + { + XERCES_STD_QUALIFIER cout << "Error during initialization! Message:\n" + << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl; + return 1; + } + + // + // Create a SAX parser object. Then, according to what we were told on + // the command line, set it to validate or not. + // + SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(); + parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); + + const char* xmlFile = argV[argInd]; + // + // Create our SAX handler object and install it on the parser, as the + // document and error handler. + // + XMLCh* uniFile = XMLString::transcode(xmlFile); + XMLCh* uri = new XMLCh[XMLString::stringLen(xmlFile) + 9]; + XMLString::fixURI(uniFile, uri); + XSTSHarnessHandlers* handler=new XSTSHarnessHandlers(uri); + XMLString::release(&uniFile); + delete [] uri; + parser->setContentHandler(handler); + parser->setErrorHandler(handler); + + // + // Get the starting time and kick off the parse of the indicated + // file. Catch any exceptions that might propogate out of it. + // + bool errorOccurred=false; + unsigned long duration; + try + { + const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); + parser->parse(xmlFile); + const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis(); + duration = endMillis - startMillis; + } + catch (const OutOfMemoryException&) + { + XERCES_STD_QUALIFIER cout << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl; + errorOccurred = true; + } + catch (const XMLException& e) + { + XERCES_STD_QUALIFIER cout << "\nError during parsing: '" << xmlFile << "'\n" + << "Exception message is: \n" + << StrX(e.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl; + errorOccurred = true; + } + catch (...) + { + XERCES_STD_QUALIFIER cout << "\nUnexpected exception during parsing: '" << xmlFile << "'\n"; + errorOccurred = true; + } + + if (handler->getSawErrors()) + errorOccurred = true; + + XERCES_STD_QUALIFIER cout << "Total tests: " << handler->getTotalTests() << XERCES_STD_QUALIFIER endl; + XERCES_STD_QUALIFIER cout << "Failed tests: " << handler->getFailedTests() << XERCES_STD_QUALIFIER endl; + XERCES_STD_QUALIFIER cout << "Success rate: " << ((double)(handler->getTotalTests()-handler->getFailedTests()))/(double)handler->getTotalTests()*100 << "%" << XERCES_STD_QUALIFIER endl; + XERCES_STD_QUALIFIER cout << "Duration: "; + if(duration > 60000) + { + XERCES_STD_QUALIFIER cout << duration/60000 << ":"; + duration=duration % 60000; + } + if(duration/1000 < 10) + XERCES_STD_QUALIFIER cout << "0"; + XERCES_STD_QUALIFIER cout << duration/1000 << "." << duration % 1000 << XERCES_STD_QUALIFIER endl; + + // + // Delete the parser itself. Must be done prior to calling Terminate, below. + // + delete parser; + delete handler; + + // And call the termination method + XMLPlatformUtils::Terminate(); + + if (errorOccurred) + return 4; + else + return 0; + +} + diff --git a/tests/src/XSTSHarness/XSTSHarness.hpp b/tests/src/XSTSHarness/XSTSHarness.hpp new file mode 100644 index 000000000..08c06123e --- /dev/null +++ b/tests/src/XSTSHarness/XSTSHarness.hpp @@ -0,0 +1,82 @@ +/* + * Copyright 1999-2000,2004 The Apache Software Foundation. + * + * Licensed 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: SAX2Count.hpp 191045 2005-06-17 01:29:55Z jberry $ + */ + + +// --------------------------------------------------------------------------- +// Includes for all the program files to see +// --------------------------------------------------------------------------- + +#include <xercesc/util/PlatformUtils.hpp> +#include <stdlib.h> +#include <string.h> +#if defined(XERCES_NEW_IOSTREAMS) +#include <iostream> +#else +#include <iostream.h> +#endif +#include "XSTSHarnessHandlers.hpp" +#include <xercesc/sax2/XMLReaderFactory.hpp> +#include <xercesc/sax2/SAX2XMLReader.hpp> + + +// --------------------------------------------------------------------------- +// This is a simple class that lets us do easy (though not terribly efficient) +// trancoding of XMLCh data to local code page for display. +// --------------------------------------------------------------------------- +class StrX +{ +public : + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + StrX(const XMLCh* const toTranscode) + { + // Call the private transcoding method + fLocalForm = XMLString::transcode(toTranscode); + } + + ~StrX() + { + XMLString::release(&fLocalForm); + } + + // ----------------------------------------------------------------------- + // Getter methods + // ----------------------------------------------------------------------- + const char* localForm() const + { + return fLocalForm; + } + +private : + // ----------------------------------------------------------------------- + // Private data members + // + // fLocalForm + // This is the local code page form of the string. + // ----------------------------------------------------------------------- + char* fLocalForm; +}; + +inline XERCES_STD_QUALIFIER ostream& operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump) +{ + target << toDump.localForm(); + return target; +} diff --git a/tests/src/XSTSHarness/XSTSHarnessHandlers.cpp b/tests/src/XSTSHarness/XSTSHarnessHandlers.cpp new file mode 100644 index 000000000..8eda5e5b1 --- /dev/null +++ b/tests/src/XSTSHarness/XSTSHarnessHandlers.cpp @@ -0,0 +1,347 @@ +/* + * Copyright 1999-2000,2004 The Apache Software Foundation. + * + * Licensed 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/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) +{ + fParser = XMLReaderFactory::createXMLReader(); + fParser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); + fParser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, true); + fParser->setFeature(XMLUni::fgSAX2CoreValidation, true); + fParser->setFeature(XMLUni::fgXercesSchema, true); + fParser->setFeature(XMLUni::fgXercesSchemaFullChecking, true); + fParser->setFeature(XMLUni::fgXercesDynamic, false); + fParser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true); + fParser->setFeature(XMLUni::fgXercesIdentityConstraintChecking, true); + fParser->setErrorHandler(&fErrorHandler); +} + +XSTSHarnessHandlers::~XSTSHarnessHandlers() +{ + delete fParser; +} + +static XMLCh urlW3C[]={ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash, + chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash, + chLatin_X, chLatin_M, chLatin_L, chForwardSlash, + chLatin_S, chLatin_c, chLatin_h, chLatin_e, chLatin_m, chLatin_a, chNull }; + +static XMLCh szTestSuite[]={ chLatin_T, chLatin_e, chLatin_s, chLatin_t, chLatin_S, chLatin_u, chLatin_i, chLatin_t, chLatin_e, chNull }; +static XMLCh szTestGroup[]={ chLatin_t, chLatin_e, chLatin_s, chLatin_t, chLatin_G, chLatin_r, chLatin_o, chLatin_u, chLatin_p, chNull }; +static XMLCh szSchemaTest[]={ chLatin_s, chLatin_c, chLatin_h, chLatin_e, chLatin_m, chLatin_a, chLatin_T, chLatin_e, chLatin_s, chLatin_t, chNull }; +static XMLCh szInstanceTest[]={ chLatin_i, chLatin_n, chLatin_s, chLatin_t, chLatin_a, chLatin_n, chLatin_c, chLatin_e, chLatin_T, chLatin_e, chLatin_s, chLatin_t, chNull }; +static XMLCh szDocumentationReference[]={ chLatin_d, chLatin_o, chLatin_c, chLatin_u, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chLatin_a, chLatin_t, chLatin_i, chLatin_o, chLatin_n, + chLatin_R, chLatin_e, chLatin_f, chLatin_e, chLatin_r, chLatin_e, chLatin_n, chLatin_c, chLatin_e, chNull }; +static XMLCh szSchemaDocument[]={ chLatin_s, chLatin_c, chLatin_h, chLatin_e, chLatin_m, chLatin_a, chLatin_D, chLatin_o, chLatin_c, chLatin_u, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chNull }; +static XMLCh szInstanceDocument[]={ chLatin_i, chLatin_n, chLatin_s, chLatin_t, chLatin_a, chLatin_n, chLatin_c, chLatin_e, chLatin_D, chLatin_o, chLatin_c, chLatin_u, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chNull }; +static XMLCh szExpected[]={ chLatin_e, chLatin_x, chLatin_p, chLatin_e, chLatin_c, chLatin_t, chLatin_e, chLatin_d, chNull }; +static XMLCh szValidity[]={ chLatin_v, chLatin_a, chLatin_l, chLatin_i, chLatin_d, chLatin_i, chLatin_t, chLatin_y, chNull }; + +static XMLCh szXLINK[]={ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash, chForwardSlash, + chLatin_w, chLatin_w, chLatin_w, chPeriod, chLatin_w, chDigit_3, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash, + chDigit_1, chDigit_9, chDigit_9, chDigit_9, chForwardSlash, + chLatin_x, chLatin_l, chLatin_i, chLatin_n, chLatin_k, chNull }; +static XMLCh szHREF[]={ chLatin_h, chLatin_r, chLatin_e, chLatin_f, chNull }; +static XMLCh szNAME[]={ chLatin_n, chLatin_a, chLatin_m, 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 dummy[]={ chLatin_f, chLatin_i, chLatin_l, chLatin_e, chColon, chForwardSlash, chForwardSlash, + chLatin_d, chLatin_u, chLatin_m, chLatin_m, chLatin_y, chNull }; + +// --------------------------------------------------------------------------- +// XSTSHarnessHandlers: Implementation of the SAX DocumentHandler interface +// --------------------------------------------------------------------------- +void XSTSHarnessHandlers::startElement(const XMLCh* const uri + , const XMLCh* const localname + , const XMLCh* const /* qname */ + , const Attributes& attrs) +{ + if(XMLString::equals(uri, szTestSuite)) + { + if(XMLString::equals(localname, szTestGroup)) + { + fCurrentTest.fExpectedResult=unknown; + fCurrentTest.fSpecReference.setURL(urlW3C); + fCurrentTest.fTestName[0]=0; + fCurrentTest.fXMLName.setURL(dummy); + fCurrentTest.fXSDName.setURL(dummy); + StrX x(attrs.getValue(szNAME)); + const char* groupName=x.localForm(); + if(XMLString::equals(groupName,"elemJ003") || + XMLString::equals(groupName,"elemJ011") || + XMLString::equals(groupName,"mgEa005") || + XMLString::equals(groupName,"mgG014") || + XMLString::equals(groupName,"mgHa005") || + XMLString::equals(groupName,"mgJ014") || + XMLString::equals(groupName,"particlesA012") || + XMLString::equals(groupName,"particlesA013") || + XMLString::equals(groupName,"particlesA014") || + XMLString::equals(groupName,"particlesA015") || + XMLString::equals(groupName,"particlesIe003") || + XMLString::equals(groupName,"particlesJb003") || + XMLString::equals(groupName,"particlesJd003") || + XMLString::equals(groupName,"particlesJf003") || + XMLString::equals(groupName,"particlesJk003") || + XMLString::equals(groupName,"particlesR005") || + XMLString::equals(groupName,"wildB011") || + XMLString::equals(groupName,"wildB019") || + XMLString::equals(groupName,"wildG032")) + fCurrentTest.fSkipped=true; + else + fCurrentTest.fSkipped=false; + fParser->resetCachedGrammarPool(); + } + else if(XMLString::equals(localname, szDocumentationReference)) + { + fCurrentTest.fSpecReference.setURL(attrs.getValue(szXLINK, szHREF)); + } + else if(XMLString::equals(localname, szSchemaTest) || + XMLString::equals(localname, szInstanceTest)) + { + XMLString::copyString(fCurrentTest.fTestName, attrs.getValue(szNAME)); + } + else if(XMLString::equals(localname, szSchemaDocument)) + { + fCurrentTest.fXSDName.setURL(fBaseURL, attrs.getValue(szXLINK, szHREF)); + } + else if(XMLString::equals(localname, szInstanceDocument)) + { + fCurrentTest.fXMLName.setURL(fBaseURL, attrs.getValue(szXLINK, szHREF)); + } + else if(XMLString::equals(localname, szExpected)) + { + const XMLCh* validity=attrs.getValue(szValidity); + if(XMLString::equals(validity, szVALID)) + fCurrentTest.fExpectedResult=valid; + else if(XMLString::equals(validity, szINVALID)) + fCurrentTest.fExpectedResult=invalid; + else + fCurrentTest.fExpectedResult=unknown; + } + } +} + +void XSTSHarnessHandlers::endElement(const XMLCh* const uri, + const XMLCh* const localname, + const XMLCh* const /*qname*/) +{ + if(XMLString::equals(uri, szTestSuite)) + { + if(XMLString::equals(localname, szSchemaTest)) + { + if(fCurrentTest.fSkipped) + { + fTests++; + fFailures++; + XERCES_STD_QUALIFIER cout << "Test " << StrX(fCurrentTest.fTestName) << " skipped" << XERCES_STD_QUALIFIER endl; + return; + } + bool success=true; + try + { + fErrorHandler.resetErrors(); + Grammar* grammar=fParser->loadGrammar(fCurrentTest.fXSDName.getURLText(), Grammar::SchemaGrammarType, true); + success=(grammar!=NULL); + } + catch (const OutOfMemoryException&) + { + XERCES_STD_QUALIFIER cout << "Test " << StrX(fCurrentTest.fTestName) << " ran out of memory" << XERCES_STD_QUALIFIER endl; + success=false; + } + catch(const XMLException& exc) + { + XERCES_STD_QUALIFIER cout << "Test " << StrX(fCurrentTest.fTestName) << " threw " << StrX(exc.getMessage()) << XERCES_STD_QUALIFIER endl; + success=false; + } + catch (...) + { + XERCES_STD_QUALIFIER cout << "Test " << StrX(fCurrentTest.fTestName) << " crashed" << XERCES_STD_QUALIFIER endl; + success=false; + } + fTests++; + if(success && !fErrorHandler.getSawErrors()) + { + if(fCurrentTest.fExpectedResult!=valid) + { + // skip the rest of the group, as we had problems with the schema itself + fCurrentTest.fSkipped=true; + fFailures++; + XERCES_STD_QUALIFIER cout << "Test " << StrX(fCurrentTest.fTestName) << " succeeded but was expected to fail" << XERCES_STD_QUALIFIER endl; + printFile(fCurrentTest.fXSDName); + } + } + else + { + if(fCurrentTest.fExpectedResult!=invalid) + { + // skip the rest of the group, as we had problems with the schema itself + fCurrentTest.fSkipped=true; + fFailures++; + XERCES_STD_QUALIFIER cout << "Test " << StrX(fCurrentTest.fTestName) << " failed but was expected to pass" << XERCES_STD_QUALIFIER endl; + XERCES_STD_QUALIFIER cout << "Reported error: " << StrX(fErrorHandler.getErrorText()) << XERCES_STD_QUALIFIER endl; + printFile(fCurrentTest.fXSDName); + } + } + } + else if(XMLString::equals(localname, szInstanceTest)) + { + if(fCurrentTest.fSkipped) + { + fTests++; + fFailures++; + XERCES_STD_QUALIFIER cout << "Test " << StrX(fCurrentTest.fTestName) << " skipped" << XERCES_STD_QUALIFIER endl; + return; + } + bool success=true; + try + { + fErrorHandler.resetErrors(); + fParser->parse(fCurrentTest.fXMLName.getURLText()); + } + catch (const OutOfMemoryException&) + { + XERCES_STD_QUALIFIER cout << "Test " << StrX(fCurrentTest.fTestName) << " ran out of memory" << XERCES_STD_QUALIFIER endl; + success=false; + } + catch(const XMLException& exc) + { + XERCES_STD_QUALIFIER cout << "Test " << StrX(fCurrentTest.fTestName) << " threw " << StrX(exc.getMessage()) << XERCES_STD_QUALIFIER endl; + success=false; + } + catch (...) + { + XERCES_STD_QUALIFIER cout << "Test " << StrX(fCurrentTest.fTestName) << " crashed" << XERCES_STD_QUALIFIER endl; + success=false; + } + fTests++; + if(success && !fErrorHandler.getSawErrors()) + { + if(fCurrentTest.fExpectedResult!=valid) + { + fFailures++; + XERCES_STD_QUALIFIER cout << "Test " << StrX(fCurrentTest.fTestName) << " succeeded but was expected to fail" << XERCES_STD_QUALIFIER endl; + printFile(fCurrentTest.fXSDName); + printFile(fCurrentTest.fXMLName); + } + } + else + { + if(fCurrentTest.fExpectedResult!=invalid) + { + fFailures++; + XERCES_STD_QUALIFIER cout << "Test " << StrX(fCurrentTest.fTestName) << " failed but was expected to pass" << XERCES_STD_QUALIFIER endl; + XERCES_STD_QUALIFIER cout << "Reported error: " << StrX(fErrorHandler.getErrorText()) << XERCES_STD_QUALIFIER endl; + printFile(fCurrentTest.fXSDName); + printFile(fCurrentTest.fXMLName); + } + } + } + } +} + +// --------------------------------------------------------------------------- +// 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) +{ + 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]; + unsigned int nRead; + while((nRead=stream->readBytes(buffer, 255)) >0) + { + buffer[nRead]=0; + 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 new file mode 100644 index 000000000..621bfb9e3 --- /dev/null +++ b/tests/src/XSTSHarness/XSTSHarnessHandlers.hpp @@ -0,0 +1,138 @@ +/* + * Copyright 1999-2000,2004 The Apache Software Foundation. + * + * Licensed 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: XSTSHarnessHandlers.hpp 314887 2005-10-12 13:18:24Z cargilld $ + */ + + +// --------------------------------------------------------------------------- +// Includes +// --------------------------------------------------------------------------- +#include <xercesc/sax2/SAX2XMLReader.hpp> +#include <xercesc/sax2/Attributes.hpp> +#include <xercesc/sax2/DefaultHandler.hpp> +#include <xercesc/util/XMLURL.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; + +struct XSTSTest +{ + XMLCh fTestName[256]; + XMLURL fXSDName, + fXMLName; + ValidityOutcome fExpectedResult; + XMLURL fSpecReference; + bool fSkipped; +}; + +class XSTSHarnessHandlers : public DefaultHandler +{ +public: + // ----------------------------------------------------------------------- + // Constructors and Destructor + // ----------------------------------------------------------------------- + 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; +}; + -- GitLab