|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
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 |
|
14 ** this package. |
|
15 ** |
|
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. |
|
23 ** |
|
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. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtDebug> |
|
43 |
|
44 #include "qacceltreeresourceloader_p.h" |
|
45 #include "qnetworkaccessdelegator_p.h" |
|
46 |
|
47 #include "Global.h" |
|
48 #include "TestBaseLine.h" |
|
49 #include "TestGroup.h" |
|
50 |
|
51 #include "TestSuiteHandler.h" |
|
52 |
|
53 using namespace QPatternistSDK; |
|
54 |
|
55 QNetworkAccessManager s_networkManager; |
|
56 |
|
57 TestSuiteHandler::TestSuiteHandler(const QUrl &catalogFile, |
|
58 const bool useEList) : m_ts(0) |
|
59 , m_container(0) |
|
60 , m_tc(0) |
|
61 , m_baseLine(0) |
|
62 , m_catalogFile(catalogFile) |
|
63 , m_exclusionList(readExclusionList(useEList)) |
|
64 , m_isExcluding(false) |
|
65 { |
|
66 Q_ASSERT(!m_catalogFile.isRelative()); |
|
67 } |
|
68 |
|
69 QStringList TestSuiteHandler::readExclusionList(const bool useExclusionList) const |
|
70 { |
|
71 if(!useExclusionList) |
|
72 return QStringList(); |
|
73 |
|
74 QStringList avoid; |
|
75 |
|
76 /* These test groups are for features we don't support. |
|
77 * |
|
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. */ |
|
80 |
|
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. |
|
86 |
|
87 return avoid; |
|
88 } |
|
89 |
|
90 bool TestSuiteHandler::startElement(const QString &namespaceURI, |
|
91 const QString &localName, |
|
92 const QString &/*qName*/, |
|
93 const QXmlAttributes &atts) |
|
94 { |
|
95 if(namespaceURI != Global::xqtsCatalogNS) |
|
96 return true; |
|
97 else if(m_isExcluding) |
|
98 { |
|
99 if(localName == QLatin1String("test-group")) |
|
100 { |
|
101 m_testGroupName.push(atts.value(QLatin1String("name"))); |
|
102 return true; |
|
103 } |
|
104 else |
|
105 return true; |
|
106 } |
|
107 |
|
108 /* The elements are handled roughly in the order of highest occurrence in the catalog file. */ |
|
109 if(localName == QLatin1String("test-case")) |
|
110 { |
|
111 XQTSTestCase *const c = new XQTSTestCase( |
|
112 TestCase::scenarioFromString(atts.value(QLatin1String("scenario"))), m_container); |
|
113 |
|
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()); |
|
119 |
|
120 m_currentQueryPath = m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); |
|
121 m_currentBaselinePath = m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); |
|
122 |
|
123 m_container->appendChild(c); |
|
124 m_tc = c; |
|
125 } |
|
126 else if(localName == QLatin1String("query")) |
|
127 { |
|
128 m_tc->setQueryPath(m_currentQueryPath.resolved(atts.value(QLatin1String("name")) + |
|
129 m_xqueryFileExtension)); |
|
130 } |
|
131 else if(localName == QLatin1String("input-file") || |
|
132 localName == QLatin1String("input-URI")) |
|
133 { |
|
134 m_currentInputVariable = atts.value(QLatin1String("variable")); |
|
135 } |
|
136 else if(localName == QLatin1String("output-file")) |
|
137 { |
|
138 m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString(atts.value(QLatin1String("compare")))); |
|
139 } |
|
140 else if(localName == QLatin1String("expected-error")) |
|
141 { |
|
142 m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError); |
|
143 } |
|
144 else if(localName == QLatin1String("test-group")) |
|
145 { |
|
146 m_testGroupName.push(atts.value(QLatin1String("name"))); |
|
147 |
|
148 if(m_exclusionList.contains(m_testGroupName.top())) |
|
149 { |
|
150 /* Ok, this group is supposed to be excluded, we don't |
|
151 * insert it into the tree. */ |
|
152 m_isExcluding = true; |
|
153 return true; |
|
154 } |
|
155 else |
|
156 { |
|
157 Q_ASSERT(m_container); |
|
158 TestGroup *const newGroup = new TestGroup(m_container); |
|
159 m_container->appendChild(newGroup); |
|
160 m_container = newGroup; |
|
161 } |
|
162 } |
|
163 else if(localName == QLatin1String("source")) |
|
164 { |
|
165 m_sourceMap.insert(atts.value(QLatin1String("ID")), |
|
166 m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("FileName"))))); |
|
167 } |
|
168 else if(localName == QLatin1String("test-suite")) |
|
169 { |
|
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()); |
|
174 m_container = m_ts; |
|
175 |
|
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"))); |
|
180 } |
|
181 else if(localName == QLatin1String("input-query")) |
|
182 { |
|
183 m_tcSourceInputs.insert(atts.value(QLatin1String("variable")), |
|
184 ExternalSourceLoader::VariableValue(m_currentQueryPath.resolved(atts.value(QLatin1String("name")) + m_xqueryFileExtension), |
|
185 ExternalSourceLoader::Query)); |
|
186 } |
|
187 |
|
188 return true; |
|
189 } |
|
190 |
|
191 bool TestSuiteHandler::endElement(const QString &namespaceURI, |
|
192 const QString &localName, |
|
193 const QString &/*qName*/) |
|
194 { |
|
195 if(namespaceURI != Global::xqtsCatalogNS) |
|
196 return true; |
|
197 |
|
198 if(m_isExcluding) |
|
199 { |
|
200 if(localName == QLatin1String("test-group")) |
|
201 { |
|
202 const QString myName(m_testGroupName.pop()); |
|
203 |
|
204 if(m_exclusionList.contains(myName)) |
|
205 { |
|
206 /* This test-group is being excluded and now we're exiting from it. */ |
|
207 m_isExcluding = false; |
|
208 } |
|
209 } |
|
210 |
|
211 return true; |
|
212 } |
|
213 |
|
214 /* The elements are handled roughly in the order of highest occurrence in the catalog file. */ |
|
215 if(localName == QLatin1String("description")) |
|
216 { |
|
217 if(m_tc) |
|
218 { |
|
219 /* We're inside a <test-case>, so the <description> belongs |
|
220 * to the test-case. */ |
|
221 m_tc->setDescription(m_ch.simplified()); |
|
222 } |
|
223 else |
|
224 m_container->setDescription(m_ch.simplified()); |
|
225 } |
|
226 else if(localName == QLatin1String("test-case")) |
|
227 { |
|
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, |
|
232 m_resourceLoader))); |
|
233 m_tcSourceInputs.clear(); |
|
234 |
|
235 if(!m_contextItemSource.isEmpty()) |
|
236 { |
|
237 m_tc->setContextItemSource(QUrl(m_sourceMap.value(m_contextItemSource))); |
|
238 m_contextItemSource.clear(); |
|
239 } |
|
240 |
|
241 m_tc = 0; |
|
242 } |
|
243 else if(localName == QLatin1String("output-file")) |
|
244 { |
|
245 m_baseLine->setDetails(m_currentBaselinePath.resolved(m_ch).toString()); |
|
246 m_tc->addBaseLine(m_baseLine); |
|
247 } |
|
248 else if(localName == QLatin1String("input-file")) |
|
249 { |
|
250 m_tcSourceInputs.insert(m_currentInputVariable, ExternalSourceLoader::VariableValue(m_sourceMap.value(m_ch), |
|
251 ExternalSourceLoader::Document)); |
|
252 } |
|
253 else if(localName == QLatin1String("expected-error")) |
|
254 { |
|
255 m_baseLine->setDetails(m_ch); |
|
256 m_tc->addBaseLine(m_baseLine); |
|
257 } |
|
258 else if(localName == QLatin1String("title")) |
|
259 { |
|
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()); |
|
263 } |
|
264 else if(localName == QLatin1String("test-group")) |
|
265 { |
|
266 m_testGroupName.pop(); |
|
267 Q_ASSERT(m_container); |
|
268 m_container = static_cast<TestContainer *>(m_container->parent()); |
|
269 Q_ASSERT(m_container); |
|
270 } |
|
271 else if(localName == QLatin1String("test-suite")) |
|
272 { |
|
273 Q_ASSERT(m_container); |
|
274 m_container = static_cast<TestContainer *>(m_container->parent()); |
|
275 } |
|
276 else if(localName == QLatin1String("sources")) |
|
277 { |
|
278 const QPatternist::NetworkAccessDelegator::Ptr networkDelegator(new QPatternist::NetworkAccessDelegator(&s_networkManager, &s_networkManager)); |
|
279 |
|
280 m_resourceLoader = QPatternist::ResourceLoader::Ptr(new QPatternist::AccelTreeResourceLoader(Global::namePool(), |
|
281 networkDelegator)); |
|
282 |
|
283 const ExternalSourceLoader::SourceMap::const_iterator end(m_sourceMap.constEnd()); |
|
284 ExternalSourceLoader::SourceMap::const_iterator it(m_sourceMap.constBegin()); |
|
285 |
|
286 for(; it != end; ++it) |
|
287 m_resourceLoader->announceDocument(it.value(), QPatternist::ResourceLoader::WillUse); |
|
288 } |
|
289 else if(localName == QLatin1String("input-URI")) |
|
290 { |
|
291 m_tcSourceInputs.insert(m_currentInputVariable, ExternalSourceLoader::VariableValue(m_sourceMap.value(m_ch), |
|
292 ExternalSourceLoader::URI)); |
|
293 } |
|
294 else if(localName == QLatin1String("contextItem")) |
|
295 m_contextItemSource = m_ch; |
|
296 |
|
297 return true; |
|
298 } |
|
299 |
|
300 bool TestSuiteHandler::characters(const QString &ch) |
|
301 { |
|
302 m_ch = ch; |
|
303 return true; |
|
304 } |
|
305 |
|
306 TestSuite *TestSuiteHandler::testSuite() const |
|
307 { |
|
308 return m_ts; |
|
309 } |
|
310 |
|
311 // vim: et:ts=4:sw=4:sts=4 |
|
312 |