1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 #include <private/qacceltreeresourceloader_p.h>
45 #include <private/qnetworkaccessdelegator_p.h>
48 #include "TestBaseLine.h"
49 #include "TestGroup.h"
51 #include "TestSuiteHandler.h"
53 using namespace QPatternistSDK;
55 QNetworkAccessManager s_networkManager;
57 TestSuiteHandler::TestSuiteHandler(const QUrl &catalogFile,
58 const bool useEList) : m_ts(0)
62 , m_catalogFile(catalogFile)
63 , m_exclusionList(readExclusionList(useEList))
64 , m_isExcluding(false)
66 Q_ASSERT(!m_catalogFile.isRelative());
69 QStringList TestSuiteHandler::readExclusionList(const bool useExclusionList) const
76 /* These test groups are for features we don't support.
78 * Originally these were stored in a text file pulled in with Qt resources, but
79 * it was not possible to get it to link on some HP-UX and Intel-icc platforms. */
81 avoid << "SchemaImport"; // The schema import feature
82 avoid << "SchemaValidation"; // The validate expression(requires schema import)
83 avoid << "StaticTyping"; // Pessimistic static typing checking
84 avoid << "TrivialEmbedding"; // XQueryX inside XQuery
85 avoid << "XMark"; // We're currently too buggy for running these tests.
90 bool TestSuiteHandler::startElement(const QString &namespaceURI,
91 const QString &localName,
92 const QString &/*qName*/,
93 const QXmlAttributes &atts)
95 if(namespaceURI != Global::xqtsCatalogNS)
97 else if(m_isExcluding)
99 if(localName == QLatin1String("test-group"))
101 m_testGroupName.push(atts.value(QLatin1String("name")));
108 /* The elements are handled roughly in the order of highest occurrence in the catalog file. */
109 if(localName == QLatin1String("test-case"))
111 XQTSTestCase *const c = new XQTSTestCase(
112 TestCase::scenarioFromString(atts.value(QLatin1String("scenario"))), m_container);
114 c->setName(atts.value(QLatin1String("name")));
115 c->setCreator(atts.value(QLatin1String("Creator")));
116 c->setIsXPath(Global::readBoolean(atts.value(QLatin1String("is-XPath2"))));
117 c->setLastModified(QDate::fromString(atts.value(QLatin1String("version-drop")), Qt::ISODate));
118 Q_ASSERT(c->lastModified().isNull() || c->lastModified().isValid());
120 m_currentQueryPath = m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath"))));
121 m_currentBaselinePath = m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath"))));
123 m_container->appendChild(c);
126 else if(localName == QLatin1String("query"))
128 m_tc->setQueryPath(m_currentQueryPath.resolved(atts.value(QLatin1String("name")) +
129 m_xqueryFileExtension));
131 else if(localName == QLatin1String("input-file") ||
132 localName == QLatin1String("input-URI"))
134 m_currentInputVariable = atts.value(QLatin1String("variable"));
136 else if(localName == QLatin1String("output-file"))
138 m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString(atts.value(QLatin1String("compare"))));
140 else if(localName == QLatin1String("expected-error"))
142 m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError);
144 else if(localName == QLatin1String("test-group"))
146 m_testGroupName.push(atts.value(QLatin1String("name")));
148 if(m_exclusionList.contains(m_testGroupName.top()))
150 /* Ok, this group is supposed to be excluded, we don't
151 * insert it into the tree. */
152 m_isExcluding = true;
157 Q_ASSERT(m_container);
158 TestGroup *const newGroup = new TestGroup(m_container);
159 m_container->appendChild(newGroup);
160 m_container = newGroup;
163 else if(localName == QLatin1String("source"))
165 m_sourceMap.insert(atts.value(QLatin1String("ID")),
166 m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("FileName")))));
168 else if(localName == QLatin1String("test-suite"))
170 m_ts = new TestSuite();
171 m_ts->setVersion(atts.value(QLatin1String("version")));
172 m_ts->setDesignDate(QDate::fromString(atts.value(QLatin1String("CatalogDesignDate")), Qt::ISODate));
173 Q_ASSERT(m_ts->designDate().isValid());
176 m_xqueryFileExtension = atts.value(QLatin1String("XQueryFileExtension"));
177 m_queryOffset = m_catalogFile.resolved(atts.value(QLatin1String("XQueryQueryOffsetPath")));
178 m_baselineOffset = m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath")));
179 m_sourceOffset = m_catalogFile.resolved(atts.value(QLatin1String("SourceOffsetPath")));
181 else if(localName == QLatin1String("input-query"))
183 m_tcSourceInputs.insert(atts.value(QLatin1String("variable")),
184 ExternalSourceLoader::VariableValue(m_currentQueryPath.resolved(atts.value(QLatin1String("name")) + m_xqueryFileExtension),
185 ExternalSourceLoader::Query));
191 bool TestSuiteHandler::endElement(const QString &namespaceURI,
192 const QString &localName,
193 const QString &/*qName*/)
195 if(namespaceURI != Global::xqtsCatalogNS)
200 if(localName == QLatin1String("test-group"))
202 const QString myName(m_testGroupName.pop());
204 if(m_exclusionList.contains(myName))
206 /* This test-group is being excluded and now we're exiting from it. */
207 m_isExcluding = false;
214 /* The elements are handled roughly in the order of highest occurrence in the catalog file. */
215 if(localName == QLatin1String("description"))
219 /* We're inside a <test-case>, so the <description> belongs
220 * to the test-case. */
221 m_tc->setDescription(m_ch.simplified());
224 m_container->setDescription(m_ch.simplified());
226 else if(localName == QLatin1String("test-case"))
228 Q_ASSERT(m_tc->baseLines().count() >= 1);
229 Q_ASSERT(m_resourceLoader);
230 m_tc->setExternalVariableLoader(QPatternist::ExternalVariableLoader::Ptr
231 (new ExternalSourceLoader(m_tcSourceInputs,
233 m_tcSourceInputs.clear();
235 if(!m_contextItemSource.isEmpty())
237 m_tc->setContextItemSource(QUrl(m_sourceMap.value(m_contextItemSource)));
238 m_contextItemSource.clear();
243 else if(localName == QLatin1String("output-file"))
245 m_baseLine->setDetails(m_currentBaselinePath.resolved(m_ch).toString());
246 m_tc->addBaseLine(m_baseLine);
248 else if(localName == QLatin1String("input-file"))
250 m_tcSourceInputs.insert(m_currentInputVariable, ExternalSourceLoader::VariableValue(m_sourceMap.value(m_ch),
251 ExternalSourceLoader::Document));
253 else if(localName == QLatin1String("expected-error"))
255 m_baseLine->setDetails(m_ch);
256 m_tc->addBaseLine(m_baseLine);
258 else if(localName == QLatin1String("title"))
260 /* A bit dangerous, the only element with name title in the vocabulary
261 * is the the child of GroupInfo */
262 m_container->setTitle(m_ch.simplified());
264 else if(localName == QLatin1String("test-group"))
266 m_testGroupName.pop();
267 Q_ASSERT(m_container);
268 m_container = static_cast<TestContainer *>(m_container->parent());
269 Q_ASSERT(m_container);
271 else if(localName == QLatin1String("test-suite"))
273 Q_ASSERT(m_container);
274 m_container = static_cast<TestContainer *>(m_container->parent());
276 else if(localName == QLatin1String("sources"))
278 const QPatternist::NetworkAccessDelegator::Ptr networkDelegator(new QPatternist::NetworkAccessDelegator(&s_networkManager, &s_networkManager));
280 m_resourceLoader = QPatternist::ResourceLoader::Ptr(new QPatternist::AccelTreeResourceLoader(Global::namePool(),
283 const ExternalSourceLoader::SourceMap::const_iterator end(m_sourceMap.constEnd());
284 ExternalSourceLoader::SourceMap::const_iterator it(m_sourceMap.constBegin());
286 for(; it != end; ++it)
287 m_resourceLoader->announceDocument(it.value(), QPatternist::ResourceLoader::WillUse);
289 else if(localName == QLatin1String("input-URI"))
291 m_tcSourceInputs.insert(m_currentInputVariable, ExternalSourceLoader::VariableValue(m_sourceMap.value(m_ch),
292 ExternalSourceLoader::URI));
294 else if(localName == QLatin1String("contextItem"))
295 m_contextItemSource = m_ch;
300 bool TestSuiteHandler::characters(const QString &ch)
306 TestSuite *TestSuiteHandler::testSuite() const
311 // vim: et:ts=4:sw=4:sts=4