diff options
Diffstat (limited to 'tests/auto/xmlpatternssdk')
-rw-r--r-- | tests/auto/xmlpatternssdk/ResultThreader.cpp | 6 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/TestBaseLine.cpp | 35 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/TestResultHandler.cpp | 15 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/TestResultHandler.h | 12 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/TestSuite.cpp | 13 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/TestSuiteHandler.cpp | 75 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/TestSuiteHandler.h | 19 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/Worker.h | 1 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp | 26 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h | 19 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp | 60 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h | 19 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/XmlParseHelper.cpp | 106 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/XmlParseHelper.h | 57 | ||||
-rw-r--r-- | tests/auto/xmlpatternssdk/xmlpatternssdk.pro | 6 |
15 files changed, 307 insertions, 162 deletions
diff --git a/tests/auto/xmlpatternssdk/ResultThreader.cpp b/tests/auto/xmlpatternssdk/ResultThreader.cpp index 749a2dd..abdac88 100644 --- a/tests/auto/xmlpatternssdk/ResultThreader.cpp +++ b/tests/auto/xmlpatternssdk/ResultThreader.cpp @@ -45,11 +45,7 @@ ResultThreader::ResultThreader(QFile *file, void ResultThreader::run() { - QXmlSimpleReader reader; - reader.setContentHandler(this); - - QXmlInputSource source(m_file); - reader.parse(source); + parse(m_file); m_file->close(); } diff --git a/tests/auto/xmlpatternssdk/TestBaseLine.cpp b/tests/auto/xmlpatternssdk/TestBaseLine.cpp index e257c42..78232cd 100644 --- a/tests/auto/xmlpatternssdk/TestBaseLine.cpp +++ b/tests/auto/xmlpatternssdk/TestBaseLine.cpp @@ -310,19 +310,11 @@ TestResult::Status TestBaseLine::verify(const QString &serializedInput) const * QDomDocument does whitespace stripping when calling setContent(QString). In other words, * this workarounds a bug. */ - QXmlInputSource source; - source.setData((m_type == XML ? serializedInput : QLatin1String("<r>") + - serializedInput + - QLatin1String("</r>")).toUtf8()); - - QString outputReadingError; - - QXmlSimpleReader reader; - reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); - - const bool success = output.setContent(&source, - &reader, - &outputReadingError); + const bool success = + output.setContent((m_type == XML ? serializedInput + : QLatin1String("<r>") + serializedInput + + QLatin1String("</r>")) + .toUtf8()); if(!success) return TestResult::Fail; @@ -332,19 +324,12 @@ TestResult::Status TestBaseLine::verify(const QString &serializedInput) const QDomDocument baseline; { - QXmlInputSource source; - source.setData((m_type == XML ? details() : QLatin1String("<r>") + - details() + - QLatin1String("</r>")).toUtf8()); QString baselineReadingError; - - QXmlSimpleReader reader; - reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); - - const bool success = baseline.setContent(&source, - &reader, - &baselineReadingError); - + const bool success = baseline.setContent( + (m_type == XML ? details() + : QLatin1String("<r>") + details() + QLatin1String("</r>")) + .toUtf8(), + &baselineReadingError); if(!success) return TestResult::Fail; diff --git a/tests/auto/xmlpatternssdk/TestResultHandler.cpp b/tests/auto/xmlpatternssdk/TestResultHandler.cpp index 92f0c01..d578f3a 100644 --- a/tests/auto/xmlpatternssdk/TestResultHandler.cpp +++ b/tests/auto/xmlpatternssdk/TestResultHandler.cpp @@ -41,10 +41,8 @@ TestResultHandler::TestResultHandler() m_comments.reserve(1000); /* Comments are only used for stuff that crash, more or less. */ } -bool TestResultHandler::startElement(const QString &namespaceURI, - const QString &localName, - const QString &, - const QXmlAttributes &atts) +bool TestResultHandler::startElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef &, const QXmlStreamAttributes &atts) { /* We only care about 'test-case', ignore everything else. */ if(localName != QLatin1String("test-case") || @@ -55,12 +53,13 @@ bool TestResultHandler::startElement(const QString &namespaceURI, Q_ASSERT_X(atts.count() == 2 || atts.count() == 3, Q_FUNC_INFO, "The input appears to not conform to XQTSResult.xsd"); - Q_ASSERT_X(!m_result.contains(atts.value(QLatin1String("name"))), - Q_FUNC_INFO, + Q_ASSERT_X(!m_result.contains(atts.value(QLatin1String("name")).toString()), Q_FUNC_INFO, qPrintable(QString::fromLatin1("A test result for test case %1 has " - "already been read(duplicate entry it seems).").arg(atts.value(QLatin1String("name"))))); + "already been read(duplicate entry it seems).") + .arg(atts.value(QLatin1String("name"))))); - m_result.insert(atts.value(0), TestResult::statusFromString(atts.value(QLatin1String("result")))); + m_result.insert(atts.at(0).value().toString(), + TestResult::statusFromString(atts.value(QLatin1String("result")).toString())); return true; } diff --git a/tests/auto/xmlpatternssdk/TestResultHandler.h b/tests/auto/xmlpatternssdk/TestResultHandler.h index 728b7e8..014c739 100644 --- a/tests/auto/xmlpatternssdk/TestResultHandler.h +++ b/tests/auto/xmlpatternssdk/TestResultHandler.h @@ -31,9 +31,9 @@ #include <QHash> #include <QString> -#include <QtXml/QXmlDefaultHandler> #include "TestResult.h" +#include "XmlParseHelper.h" QT_BEGIN_NAMESPACE @@ -46,7 +46,7 @@ namespace QPatternistSDK * @author Frans Englich <frans.englich@nokia.com> * @ingroup PatternistSDK */ - class TestResultHandler : public QXmlDefaultHandler + class TestResultHandler : public XmlParseHelper { public: /** @@ -68,15 +68,13 @@ namespace QPatternistSDK /** * Performs finalization. */ - virtual bool endDocument(); + bool endDocument() override; /** * Reads the <tt>test-case</tt> element and its attributes, everything else is ignored. */ - virtual bool startElement(const QString &namespaceURI, - const QString &localName, - const QString &qName, - const QXmlAttributes &atts); + bool startElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef &qName, const QXmlStreamAttributes &atts) override; /** * @note Do not reimplement this function. * @returns the result obtained from reading the XML file. diff --git a/tests/auto/xmlpatternssdk/TestSuite.cpp b/tests/auto/xmlpatternssdk/TestSuite.cpp index 004fba5..973fe40 100644 --- a/tests/auto/xmlpatternssdk/TestSuite.cpp +++ b/tests/auto/xmlpatternssdk/TestSuite.cpp @@ -28,13 +28,12 @@ #include <QFileInfo> #include <QVariant> -#include <QXmlInputSource> -#include <QXmlSimpleReader> #include <QtDebug> #include "Global.h" #include "TestSuiteHandler.h" #include "TestSuiteResult.h" +#include "XmlParseHelper.h" #include "XMLWriter.h" #include "XSLTTestSuiteHandler.h" #include "XSDTestSuiteHandler.h" @@ -125,8 +124,7 @@ TestSuite *TestSuite::openCatalog(QIODevice *input, { Q_ASSERT(input); - QXmlSimpleReader reader; - typedef QPatternist::AutoPtr<QXmlDefaultHandler> HandlerPtr; + typedef QPatternist::AutoPtr<XmlParseHelper> HandlerPtr; HandlerPtr loader; @@ -137,12 +135,7 @@ TestSuite *TestSuite::openCatalog(QIODevice *input, default: Q_ASSERT(false); break; } - reader.setContentHandler(loader.data()); - - QXmlInputSource source(input); - - if(!reader.parse(source)) - { + if (!loader.data()->parse(input)) { errorMsg = QString::fromLatin1("Couldn't parse %1").arg(fileName.toString()); return 0; } diff --git a/tests/auto/xmlpatternssdk/TestSuiteHandler.cpp b/tests/auto/xmlpatternssdk/TestSuiteHandler.cpp index 68bedca..ba4dc8a 100644 --- a/tests/auto/xmlpatternssdk/TestSuiteHandler.cpp +++ b/tests/auto/xmlpatternssdk/TestSuiteHandler.cpp @@ -89,10 +89,8 @@ QStringList TestSuiteHandler::readExclusionList(const bool useExclusionList) con return avoid; } -bool TestSuiteHandler::startElement(const QString &namespaceURI, - const QString &localName, - const QString &/*qName*/, - const QXmlAttributes &atts) +bool TestSuiteHandler::startElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef & /*qName*/, const QXmlStreamAttributes &atts) { if(namespaceURI != Global::xqtsCatalogNS) return true; @@ -100,7 +98,7 @@ bool TestSuiteHandler::startElement(const QString &namespaceURI, { if(localName == QLatin1String("test-group")) { - m_testGroupName.push(atts.value(QLatin1String("name"))); + m_testGroupName.push(atts.value(QLatin1String("name")).toString()); return true; } else @@ -111,16 +109,20 @@ bool TestSuiteHandler::startElement(const QString &namespaceURI, if(localName == QLatin1String("test-case")) { XQTSTestCase *const c = new XQTSTestCase( - TestCase::scenarioFromString(atts.value(QLatin1String("scenario"))), m_container); - - c->setName(atts.value(QLatin1String("name"))); - c->setCreator(atts.value(QLatin1String("Creator"))); - c->setIsXPath(Global::readBoolean(atts.value(QLatin1String("is-XPath2")))); - c->setLastModified(QDate::fromString(atts.value(QLatin1String("version-drop")), Qt::ISODate)); + TestCase::scenarioFromString(atts.value(QLatin1String("scenario")).toString()), + m_container); + + c->setName(atts.value(QLatin1String("name")).toString()); + c->setCreator(atts.value(QLatin1String("Creator")).toString()); + c->setIsXPath(Global::readBoolean(atts.value(QLatin1String("is-XPath2")).toString())); + c->setLastModified(QDate::fromString(atts.value(QLatin1String("version-drop")).toString(), + Qt::ISODate)); Q_ASSERT(c->lastModified().isNull() || c->lastModified().isValid()); - m_currentQueryPath = m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); - m_currentBaselinePath = m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); + m_currentQueryPath = + m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")).toString())); + m_currentBaselinePath = + m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")).toString())); m_container->appendChild(c); m_tc = c; @@ -133,11 +135,12 @@ bool TestSuiteHandler::startElement(const QString &namespaceURI, else if(localName == QLatin1String("input-file") || localName == QLatin1String("input-URI")) { - m_currentInputVariable = atts.value(QLatin1String("variable")); + m_currentInputVariable = atts.value(QLatin1String("variable")).toString(); } else if(localName == QLatin1String("output-file")) { - m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString(atts.value(QLatin1String("compare")))); + m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString( + atts.value(QLatin1String("compare")).toString())); } else if(localName == QLatin1String("expected-error")) { @@ -145,7 +148,7 @@ bool TestSuiteHandler::startElement(const QString &namespaceURI, } else if(localName == QLatin1String("test-group")) { - m_testGroupName.push(atts.value(QLatin1String("name"))); + m_testGroupName.push(atts.value(QLatin1String("name")).toString()); if(m_exclusionList.contains(m_testGroupName.top())) { @@ -164,35 +167,43 @@ bool TestSuiteHandler::startElement(const QString &namespaceURI, } else if(localName == QLatin1String("source")) { - m_sourceMap.insert(atts.value(QLatin1String("ID")), - m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("FileName"))))); + m_sourceMap.insert( + atts.value(QLatin1String("ID")).toString(), + m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("FileName")).toString()))); } else if(localName == QLatin1String("test-suite")) { m_ts = new TestSuite(); - m_ts->setVersion(atts.value(QLatin1String("version"))); - m_ts->setDesignDate(QDate::fromString(atts.value(QLatin1String("CatalogDesignDate")), Qt::ISODate)); + m_ts->setVersion(atts.value(QLatin1String("version")).toString()); + m_ts->setDesignDate(QDate::fromString( + atts.value(QLatin1String("CatalogDesignDate")).toString(), Qt::ISODate)); Q_ASSERT(m_ts->designDate().isValid()); m_container = m_ts; - m_xqueryFileExtension = atts.value(QLatin1String("XQueryFileExtension")); - m_queryOffset = m_catalogFile.resolved(atts.value(QLatin1String("XQueryQueryOffsetPath"))); - m_baselineOffset = m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath"))); - m_sourceOffset = m_catalogFile.resolved(atts.value(QLatin1String("SourceOffsetPath"))); + m_xqueryFileExtension = atts.value(QLatin1String("XQueryFileExtension")).toString(); + m_queryOffset = m_catalogFile.resolved( + atts.value(QLatin1String("XQueryQueryOffsetPath")).toString()); + m_baselineOffset = + m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath")).toString()); + m_sourceOffset = + m_catalogFile.resolved(atts.value(QLatin1String("SourceOffsetPath")).toString()); } else if(localName == QLatin1String("input-query")) { - m_tcSourceInputs.insert(atts.value(QLatin1String("variable")), - ExternalSourceLoader::VariableValue(m_currentQueryPath.resolved(atts.value(QLatin1String("name")) + m_xqueryFileExtension), - ExternalSourceLoader::Query)); + m_tcSourceInputs.insert( + atts.value(QLatin1String("variable")).toString(), + ExternalSourceLoader::VariableValue( + m_currentQueryPath.resolved(atts.value(QLatin1String("name")) + + m_xqueryFileExtension), + ExternalSourceLoader::Query)); } return true; } -bool TestSuiteHandler::endElement(const QString &namespaceURI, - const QString &localName, - const QString &/*qName*/) +bool TestSuiteHandler::endElement(const QStringRef &namespaceURI, + const QStringRef &localName, + const QStringRef &/*qName*/) { if(namespaceURI != Global::xqtsCatalogNS) return true; @@ -299,9 +310,9 @@ bool TestSuiteHandler::endElement(const QString &namespaceURI, return true; } -bool TestSuiteHandler::characters(const QString &ch) +bool TestSuiteHandler::characters(const QStringRef &ch) { - m_ch = ch; + m_ch = ch.toString(); return true; } diff --git a/tests/auto/xmlpatternssdk/TestSuiteHandler.h b/tests/auto/xmlpatternssdk/TestSuiteHandler.h index 25c2f0c..504bd3f 100644 --- a/tests/auto/xmlpatternssdk/TestSuiteHandler.h +++ b/tests/auto/xmlpatternssdk/TestSuiteHandler.h @@ -31,10 +31,10 @@ #include <QStack> #include <QUrl> -#include <QXmlDefaultHandler> #include "ExternalSourceLoader.h" #include "TestSuite.h" +#include "XmlParseHelper.h" #include "XQTSTestCase.h" QT_BEGIN_NAMESPACE @@ -57,7 +57,7 @@ namespace QPatternistSDK * @ingroup PatternistSDK * @author Frans Englich <frans.englich@nokia.com> */ - class TestSuiteHandler : public QXmlDefaultHandler + class TestSuiteHandler : public XmlParseHelper { public: /** @@ -69,17 +69,14 @@ namespace QPatternistSDK */ TestSuiteHandler(const QUrl &catalogFile, const bool useExclusionList); - virtual bool characters(const QString &ch); + bool characters(const QStringRef &ch) override; - virtual bool endElement(const QString &namespaceURI, - const QString &localName, - const QString &qName); - virtual bool startElement(const QString &namespaceURI, - const QString &localName, - const QString &qName, - const QXmlAttributes &atts); + bool endElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef &qName) override; + bool startElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef &qName, const QXmlStreamAttributes &atts) override; - virtual TestSuite *testSuite() const; + TestSuite *testSuite() const; private: QStringList readExclusionList(const bool useExclusionList) const; diff --git a/tests/auto/xmlpatternssdk/Worker.h b/tests/auto/xmlpatternssdk/Worker.h index 1d84408..b56a57a 100644 --- a/tests/auto/xmlpatternssdk/Worker.h +++ b/tests/auto/xmlpatternssdk/Worker.h @@ -33,6 +33,7 @@ #include <QList> #include <QObject> #include <QStringList> +#include <QTextStream> #include "ResultThreader.h" diff --git a/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp b/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp index 854fef6..4e56af6 100644 --- a/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp +++ b/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp @@ -782,10 +782,8 @@ XSDTestSuiteHandler::XSDTestSuiteHandler(const QUrl &catalogFile) : m_ts(0) << QLatin1String("wildZ010"); } -bool XSDTestSuiteHandler::startElement(const QString &namespaceURI, - const QString &localName, - const QString &/*qName*/, - const QXmlAttributes &atts) +bool XSDTestSuiteHandler::startElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef & /*qName*/, const QXmlStreamAttributes &atts) { if(namespaceURI != QString::fromLatin1("http://www.w3.org/XML/2004/xml-schema-test-suite/")) return true; @@ -793,16 +791,16 @@ bool XSDTestSuiteHandler::startElement(const QString &namespaceURI, if (localName == QLatin1String("testSet")) { m_currentTestSet = new TestGroup(m_topLevelGroup); Q_ASSERT(m_currentTestSet); - m_currentTestSet->setTitle(atts.value("name")); + m_currentTestSet->setTitle(atts.value("name").toString()); m_topLevelGroup->appendChild(m_currentTestSet); } else if (localName == QLatin1String("testGroup")) { m_currentTestGroup = new TestGroup(m_currentTestSet); Q_ASSERT(m_currentTestGroup); - m_currentTestGroup->setTitle(atts.value("name")); + m_currentTestGroup->setTitle(atts.value("name").toString()); m_currentTestSet->appendChild(m_currentTestGroup); m_inTestGroup = true; } else if (localName == QLatin1String("schemaTest")) { - if (m_blackList.contains(atts.value("name"))) { + if (m_blackList.contains(atts.value("name").toString())) { m_currentTestCase = 0; m_schemaBlacklisted = true; return true; @@ -832,12 +830,12 @@ bool XSDTestSuiteHandler::startElement(const QString &namespaceURI, m_inInstanceTest = true; } else if (localName == QLatin1String("schemaDocument") || localName == QLatin1String("instanceDocument")) { if (m_inSchemaTest) { - m_currentTestCase->setSchemaUri(QUrl(atts.value("xlink:href"))); + m_currentTestCase->setSchemaUri(QUrl(atts.value("xlink:href").toString())); if (m_currentSchemaLink.isEmpty()) // we only use the first schema document for validation - m_currentSchemaLink = atts.value("xlink:href"); + m_currentSchemaLink = atts.value("xlink:href").toString(); } if (m_inInstanceTest) { - m_currentTestCase->setInstanceUri(QUrl(atts.value("xlink:href"))); + m_currentTestCase->setInstanceUri(QUrl(atts.value("xlink:href").toString())); m_currentTestCase->setSchemaUri(QUrl(m_currentSchemaLink)); } } else if (localName == QLatin1String("expected") && (m_inSchemaTest || m_inInstanceTest)) { @@ -858,9 +856,9 @@ bool XSDTestSuiteHandler::startElement(const QString &namespaceURI, return true; } -bool XSDTestSuiteHandler::endElement(const QString &/*namespaceURI*/, - const QString &localName, - const QString &/*qName*/) +bool XSDTestSuiteHandler::endElement(const QStringRef &/*namespaceURI*/, + const QStringRef &localName, + const QStringRef &/*qName*/) { if (localName == QLatin1String("testGroup")) { m_inTestGroup = false; @@ -880,7 +878,7 @@ bool XSDTestSuiteHandler::endElement(const QString &/*namespaceURI*/, return true; } -bool XSDTestSuiteHandler::characters(const QString &ch) +bool XSDTestSuiteHandler::characters(const QStringRef &ch) { if (m_inDescription) m_documentation += ch; diff --git a/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h b/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h index 3015d8c..2affbab 100644 --- a/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h +++ b/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h @@ -30,10 +30,10 @@ #define PatternistSDK_XSDTestSuiteHandler_H #include <QUrl> -#include <QXmlDefaultHandler> #include "ExternalSourceLoader.h" #include "TestSuite.h" +#include "XmlParseHelper.h" #include "XQTSTestCase.h" QT_BEGIN_NAMESPACE @@ -57,7 +57,7 @@ namespace QPatternistSDK * @ingroup PatternistSDK * @author Tobias Koenig <tobias.koenig@nokia.com> */ - class XSDTestSuiteHandler : public QXmlDefaultHandler + class XSDTestSuiteHandler : public XmlParseHelper { public: /** @@ -68,17 +68,14 @@ namespace QPatternistSDK * test groups when loading */ XSDTestSuiteHandler(const QUrl &catalogFile); - virtual bool characters(const QString &ch); + bool characters(const QStringRef &ch) override; - virtual bool endElement(const QString &namespaceURI, - const QString &localName, - const QString &qName); - virtual bool startElement(const QString &namespaceURI, - const QString &localName, - const QString &qName, - const QXmlAttributes &atts); + bool endElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef &qName) override; + bool startElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef &qName, const QXmlStreamAttributes &atts) override; - virtual TestSuite *testSuite() const; + TestSuite *testSuite() const; private: TestSuite* m_ts; diff --git a/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp b/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp index 5d2a3db..e690dd2 100644 --- a/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp +++ b/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp @@ -69,11 +69,9 @@ XSLTTestSuiteHandler::XSLTTestSuiteHandler(const QUrl &catalogFile) : m_ts(0) Q_ASSERT(!m_catalogFile.isRelative()); } -bool XSLTTestSuiteHandler::startElement(const QString &namespaceURI, - const QString &localName, - const QString &/*qName*/, - const QXmlAttributes &atts) - { +bool XSLTTestSuiteHandler::startElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef & /*qName*/, const QXmlStreamAttributes &atts) +{ if(namespaceURI != Global::xsltsCatalogNS) return true; @@ -83,40 +81,50 @@ bool XSLTTestSuiteHandler::startElement(const QString &namespaceURI, /* We pass m_ts temporarily, and change it later. */ m_tc = new XQTSTestCase(TestCase::Standard, 0, QXmlQuery::XSLT20); - m_currentQueryPath = m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); - m_currentBaselinePath = m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); + m_currentQueryPath = + m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")).toString())); + m_currentBaselinePath = + m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")).toString())); } else if(localName == QLatin1String("stylesheet")) - m_tc->setQueryPath(m_currentQueryPath.resolved(atts.value(QLatin1String("file")))); + m_tc->setQueryPath( + m_currentQueryPath.resolved(atts.value(QLatin1String("file")).toString())); else if(localName == QLatin1String("error")) { m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError); - m_baseLine->setDetails(atts.value(QLatin1String("error-id"))); + m_baseLine->setDetails(atts.value(QLatin1String("error-id")).toString()); m_tc->addBaseLine(m_baseLine); } else if(localName == QLatin1String("testcases")) { m_ts = new TestSuite(); - m_ts->setVersion(atts.value(QLatin1String("testSuiteVersion"))); - - m_queryOffset = m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath"))); - m_baselineOffset = m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath"))); - m_sourceOffset = m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath"))); + m_ts->setVersion(atts.value(QLatin1String("testSuiteVersion")).toString()); + + m_queryOffset = + m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath")).toString()); + m_baselineOffset = + m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath")).toString()); + m_sourceOffset = + m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath")).toString()); } else if(localName == QLatin1String("source-document")) { if(atts.value(QLatin1String("role")) == QLatin1String("principal")) - m_tc->setContextItemSource(m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("file"))))); + m_tc->setContextItemSource( + m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("file")).toString()))); } else if(localName == QLatin1String("result-document")) { - m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString(atts.value(QLatin1String("type")))); - m_baseLine->setDetails(m_currentBaselinePath.resolved(atts.value(QLatin1String("file"))).toString()); + m_baseLine = new TestBaseLine( + TestBaseLine::identifierFromString(atts.value(QLatin1String("type")).toString())); + m_baseLine->setDetails( + m_currentBaselinePath.resolved(atts.value(QLatin1String("file")).toString()) + .toString()); m_tc->addBaseLine(m_baseLine); } else if(localName == QLatin1String("discretionary-feature")) { - const QString feature(atts.value(QLatin1String("name"))); + const QString feature(atts.value(QLatin1String("name")).toString()); m_removeTestcase = feature == QLatin1String("schema_aware") || feature == QLatin1String("namespace_axis") || @@ -126,9 +134,9 @@ bool XSLTTestSuiteHandler::startElement(const QString &namespaceURI, else if(localName == QLatin1String("discretionary-choice")) { m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError); - m_baseLine->setDetails(atts.value(QLatin1String("name"))); + m_baseLine->setDetails(atts.value(QLatin1String("name")).toString()); m_tc->addBaseLine(m_baseLine); - const QString feature(atts.value(QLatin1String("name"))); + const QString feature(atts.value(QLatin1String("name")).toString()); m_removeTestcase = feature == QLatin1String("schema_aware") || feature == QLatin1String("namespace_axis") || @@ -137,7 +145,7 @@ bool XSLTTestSuiteHandler::startElement(const QString &namespaceURI, } else if(localName == QLatin1String("entry-named-template")) { - const QString name(atts.value(QLatin1String("qname"))); + const QString name(atts.value(QLatin1String("qname")).toString()); if(!name.contains(QLatin1Char(':'))) { @@ -166,9 +174,9 @@ TestGroup *XSLTTestSuiteHandler::containerFor(const QString &name) return c; } -bool XSLTTestSuiteHandler::endElement(const QString &namespaceURI, - const QString &localName, - const QString &/*qName*/) +bool XSLTTestSuiteHandler::endElement(const QStringRef &namespaceURI, + const QStringRef &localName, + const QStringRef &/*qName*/) { if(namespaceURI != Global::xsltsCatalogNS) return true; @@ -221,9 +229,9 @@ bool XSLTTestSuiteHandler::endElement(const QString &namespaceURI, return true; } -bool XSLTTestSuiteHandler::characters(const QString &ch) +bool XSLTTestSuiteHandler::characters(const QStringRef &ch) { - m_ch = ch; + m_ch = ch.toString(); return true; } diff --git a/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h b/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h index 231b55d..b5879c1 100644 --- a/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h +++ b/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h @@ -31,10 +31,10 @@ #include <QStack> #include <QUrl> -#include <QXmlDefaultHandler> #include "ExternalSourceLoader.h" #include "TestSuite.h" +#include "XmlParseHelper.h" #include "XQTSTestCase.h" QT_BEGIN_NAMESPACE @@ -59,7 +59,7 @@ namespace QPatternistSDK * @ingroup PatternistSDK * @author Frans Englich <frans.englich@nokia.com> */ - class XSLTTestSuiteHandler : public QXmlDefaultHandler + class XSLTTestSuiteHandler : public XmlParseHelper { public: /** @@ -70,17 +70,14 @@ namespace QPatternistSDK * test groups when loading */ XSLTTestSuiteHandler(const QUrl &catalogFile); - virtual bool characters(const QString &ch); + bool characters(const QStringRef &ch) override; - virtual bool endElement(const QString &namespaceURI, - const QString &localName, - const QString &qName); - virtual bool startElement(const QString &namespaceURI, - const QString &localName, - const QString &qName, - const QXmlAttributes &atts); + bool endElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef &qName) override; + bool startElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef &qName, const QXmlStreamAttributes &atts) override; - virtual TestSuite *testSuite() const; + TestSuite *testSuite() const; private: TestGroup *containerFor(const QString &name); diff --git a/tests/auto/xmlpatternssdk/XmlParseHelper.cpp b/tests/auto/xmlpatternssdk/XmlParseHelper.cpp new file mode 100644 index 0000000..7629753 --- /dev/null +++ b/tests/auto/xmlpatternssdk/XmlParseHelper.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "XmlParseHelper.h" + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK { + +bool XmlParseHelper::parse(QIODevice *input) +{ + QXmlStreamReader reader(input); + + while (!reader.atEnd()) { + reader.readNext(); + if (reader.hasError()) + return false; + + switch (reader.tokenType()) { + case QXmlStreamReader::StartElement: + if (!startElement(reader.namespaceUri(), reader.name(), + reader.qualifiedName(), reader.attributes())) { + return false; + } + break; + case QXmlStreamReader::EndElement: + if (!endElement(reader.namespaceUri(), reader.name(), + reader.qualifiedName())) { + return false; + } + break; + case QXmlStreamReader::Characters: + if (!reader.isWhitespace() && !reader.text().toString().trimmed().isEmpty()) { + if (!characters(reader.text())) + return false; + } + break; + default: + break; + } + } + + if (reader.isEndDocument() && !endDocument()) + return false; + + return true; +} + +bool XmlParseHelper::startElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef &qName, const QXmlStreamAttributes &atts) +{ + Q_UNUSED(namespaceURI) + Q_UNUSED(localName) + Q_UNUSED(qName) + Q_UNUSED(atts) + return true; +} + +bool XmlParseHelper::endElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef &qName) +{ + Q_UNUSED(namespaceURI) + Q_UNUSED(localName) + Q_UNUSED(qName) + return true; +} + +bool XmlParseHelper::characters(const QStringRef &text) +{ + Q_UNUSED(text) + return true; +} + +bool XmlParseHelper::endDocument() +{ + return true; +} + +} // namespace QPatternistSDK + +QT_END_NAMESPACE diff --git a/tests/auto/xmlpatternssdk/XmlParseHelper.h b/tests/auto/xmlpatternssdk/XmlParseHelper.h new file mode 100644 index 0000000..2bf6314 --- /dev/null +++ b/tests/auto/xmlpatternssdk/XmlParseHelper.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XMLPARSEHELPER_H +#define XMLPARSEHELPER_H + +#include <qxmlstream.h> + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK { +class XmlParseHelper +{ +public: + virtual ~XmlParseHelper() = default; + + bool parse(QIODevice *input); + +protected: + virtual bool startElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef &qName, const QXmlStreamAttributes &atts); + virtual bool endElement(const QStringRef &namespaceURI, const QStringRef &localName, + const QStringRef &qName); + virtual bool characters(const QStringRef &text); + virtual bool endDocument(); +}; + +} // namespace QPatternistSDK + +QT_END_NAMESPACE + +#endif // XMLPARSEHELPER_H diff --git a/tests/auto/xmlpatternssdk/xmlpatternssdk.pro b/tests/auto/xmlpatternssdk/xmlpatternssdk.pro index e52962c..5512aec 100644 --- a/tests/auto/xmlpatternssdk/xmlpatternssdk.pro +++ b/tests/auto/xmlpatternssdk/xmlpatternssdk.pro @@ -53,7 +53,8 @@ HEADERS = ASTItem.h \ XQTSTestCase.h \ XSDTestSuiteHandler.h \ XSDTSTestCase.h \ - XSLTTestSuiteHandler.h + XSLTTestSuiteHandler.h \ + XmlParseHelper.h SOURCES = ASTItem.cpp \ DebugExpressionFactory.cpp \ @@ -80,4 +81,5 @@ SOURCES = ASTItem.cpp \ XQTSTestCase.cpp \ XSDTestSuiteHandler.cpp \ XSDTSTestCase.cpp \ - XSLTTestSuiteHandler.cpp + XSLTTestSuiteHandler.cpp \ + XmlParseHelper.cpp |