1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
44 #include "qacceltreeresourceloader_p.h"
45 #include "qnetworkaccessdelegator_p.h"
48 #include "TestBaseLine.h"
49 #include "TestGroup.h"
51 #include "XSLTTestSuiteHandler.h"
53 using namespace QPatternistSDK;
55 extern QNetworkAccessManager s_networkManager;
57 XSLTTestSuiteHandler::XSLTTestSuiteHandler(const QUrl &catalogFile) : m_ts(0)
60 , m_catalogFile(catalogFile)
61 , m_removeTestcase(false)
63 const QPatternist::NetworkAccessDelegator::Ptr networkDelegator(new QPatternist::NetworkAccessDelegator(&s_networkManager, &s_networkManager));
65 m_resourceLoader = QPatternist::ResourceLoader::Ptr(new QPatternist::AccelTreeResourceLoader(Global::namePool(),
67 Q_ASSERT(!m_catalogFile.isRelative());
70 bool XSLTTestSuiteHandler::startElement(const QString &namespaceURI,
71 const QString &localName,
72 const QString &/*qName*/,
73 const QXmlAttributes &atts)
75 if(namespaceURI != Global::xsltsCatalogNS)
78 /* The elements are handled roughly in the order of highest occurrence in the catalog file. */
79 if(localName == QLatin1String("testcase"))
81 /* We pass m_ts temporarily, and change it later. */
82 m_tc = new XQTSTestCase(TestCase::Standard, 0, QXmlQuery::XSLT20);
84 m_currentQueryPath = m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath"))));
85 m_currentBaselinePath = m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath"))));
87 else if(localName == QLatin1String("stylesheet"))
88 m_tc->setQueryPath(m_currentQueryPath.resolved(atts.value(QLatin1String("file"))));
89 else if(localName == QLatin1String("error"))
91 m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError);
92 m_baseLine->setDetails(atts.value(QLatin1String("error-id")));
93 m_tc->addBaseLine(m_baseLine);
95 else if(localName == QLatin1String("testcases"))
97 m_ts = new TestSuite();
98 m_ts->setVersion(atts.value(QLatin1String("testSuiteVersion")));
100 m_queryOffset = m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath")));
101 m_baselineOffset = m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath")));
102 m_sourceOffset = m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath")));
104 else if(localName == QLatin1String("source-document"))
106 if(atts.value(QLatin1String("role")) == QLatin1String("principal"))
107 m_tc->setContextItemSource(m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("file")))));
109 else if(localName == QLatin1String("result-document"))
111 m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString(atts.value(QLatin1String("type"))));
112 m_baseLine->setDetails(m_currentBaselinePath.resolved(atts.value(QLatin1String("file"))).toString());
113 m_tc->addBaseLine(m_baseLine);
115 else if(localName == QLatin1String("discretionary-feature"))
117 const QString feature(atts.value(QLatin1String("name")));
119 m_removeTestcase = feature == QLatin1String("schema_aware") ||
120 feature == QLatin1String("namespace_axis") ||
121 feature == QLatin1String("disabling_output_escaping") ||
122 feature == QLatin1String("XML_1.1");
124 else if(localName == QLatin1String("discretionary-choice"))
126 m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError);
127 m_baseLine->setDetails(atts.value(QLatin1String("name")));
128 m_tc->addBaseLine(m_baseLine);
129 const QString feature(atts.value(QLatin1String("name")));
131 m_removeTestcase = feature == QLatin1String("schema_aware") ||
132 feature == QLatin1String("namespace_axis") ||
133 feature == QLatin1String("disabling_output_escaping") ||
134 feature == QLatin1String("XML_1.1");
136 else if(localName == QLatin1String("entry-named-template"))
138 const QString name(atts.value(QLatin1String("qname")));
140 if(!name.contains(QLatin1Char(':')))
142 // TODO do namespace processing
143 const QXmlName complete(Global::namePool()->allocateQName(QString(), name));
145 m_tc->setInitialTemplateName(complete);
152 TestGroup *XSLTTestSuiteHandler::containerFor(const QString &name)
154 TestGroup *& c = m_containers[name];
158 c = new TestGroup(m_ts);
161 m_ts->appendChild(c);
167 bool XSLTTestSuiteHandler::endElement(const QString &namespaceURI,
168 const QString &localName,
169 const QString &/*qName*/)
171 if(namespaceURI != Global::xsltsCatalogNS)
174 /* The elements are handled roughly in the order of highest occurrence in the catalog file. */
175 if(localName == QLatin1String("description"))
179 /* We're inside a <testcase>, so the <description> belongs
180 * to the testcase. */
181 m_tc->setDescription(m_ch.simplified());
184 else if(localName == QLatin1String("testcase"))
186 Q_ASSERT(m_tc->baseLines().count() >= 1);
187 Q_ASSERT(m_resourceLoader);
188 // TODO can this be removed?
189 m_tc->setExternalVariableLoader(QPatternist::ExternalVariableLoader::Ptr
190 (new ExternalSourceLoader(m_tcSourceInputs,
192 m_tcSourceInputs.clear();
194 if(!m_removeTestcase)
197 TestContainer *const container = containerFor(m_currentCategory);
199 container->removeLast();
201 TestContainer *const container = containerFor(m_currentCategory);
202 m_tc->setParent(container);
204 container->appendChild(m_tc);
208 m_removeTestcase = false;
210 else if(localName == QLatin1String("name"))
212 else if(localName == QLatin1String("creator"))
213 m_tc->setCreator(m_ch);
214 else if(localName == QLatin1String("contextItem"))
215 m_contextItemSource = m_ch;
216 else if(localName == QLatin1String("category"))
217 m_currentCategory = m_ch;
222 bool XSLTTestSuiteHandler::characters(const QString &ch)
228 TestSuite *XSLTTestSuiteHandler::testSuite() const
233 // vim: et:ts=4:sw=4:sts=4