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 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 #include <QXmlInputSource>
45 #include <QXmlSimpleReader>
49 #include "TestSuiteHandler.h"
50 #include "TestSuiteResult.h"
51 #include "XMLWriter.h"
52 #include "XSLTTestSuiteHandler.h"
53 #include "XSDTestSuiteHandler.h"
54 #include <private/qdebug_p.h>
56 #include "TestSuite.h"
58 using namespace QPatternistSDK;
59 using namespace QPatternist;
61 TestSuite::TestSuite()
65 QVariant TestSuite::data(const Qt::ItemDataRole role, int column) const
67 if(role != Qt::DisplayRole)
84 TestSuiteResult *TestSuite::runSuite()
86 const QDate date(QDate::currentDate());
87 TestResult::List result(execute(CompileAndRun, this));
89 return new TestSuiteResult(version(), date, result);
92 TestSuite *TestSuite::openCatalog(const QUrl &catalogURI,
94 const bool useExclusionList,
97 pDebug() << "Opening catalog:" << catalogURI.toString();
98 QFile ts(catalogURI.toLocalFile());
99 Q_ASSERT(catalogURI.isValid());
103 errorMsg = QString::fromLatin1("The test suite catalog \"%1\" could not be found.\n")
108 const QFileInfo info(ts);
110 if(!info.isReadable())
112 errorMsg = QString::fromLatin1("Cannot read the test suite catalog.\n");
115 else if(!info.isFile())
117 errorMsg = QString::fromLatin1("The specified test suite catalog \"%1\" is not a file. "
118 "The test suite catalog must be a file, it cannot be "
119 "a directory, for example.\n")
123 else if(!ts.open(QIODevice::ReadOnly | QIODevice::Text))
125 errorMsg = QString::fromLatin1("Failed to open the test suite catalog, \"%1\".\n")
130 return openCatalog(&ts, errorMsg, catalogURI, useExclusionList, suiteType);
133 TestSuite *TestSuite::openCatalog(QIODevice *input,
135 const QUrl &fileName,
136 const bool useExclusionList,
141 QXmlSimpleReader reader;
142 typedef QPatternist::AutoPtr<QXmlDefaultHandler> HandlerPtr;
147 case XQuerySuite: loader = HandlerPtr(new TestSuiteHandler(fileName, useExclusionList)); break;
148 case XsltSuite: loader = HandlerPtr(new XSLTTestSuiteHandler(fileName)); break;
149 case XsdSuite: loader = HandlerPtr(new XSDTestSuiteHandler(fileName)); break;
150 default: Q_ASSERT(false); break;
153 reader.setContentHandler(loader.data());
155 QXmlInputSource source(input);
157 if(!reader.parse(source))
159 errorMsg = QString::fromLatin1("Couldn't parse %1").arg(fileName.toString());
163 TestSuite *suite = 0;
165 case XQuerySuite: suite = static_cast<TestSuiteHandler *>(loader.data())->testSuite(); break;
166 case XsltSuite: suite = static_cast<XSLTTestSuiteHandler *>(loader.data())->testSuite(); break;
167 case XsdSuite: suite = static_cast<XSDTestSuiteHandler *>(loader.data())->testSuite(); break;
168 default: Q_ASSERT(false); break;
174 errorMsg = QString::fromLatin1("Failed to load \"%1\". "
175 "It appears to have no test-suite element.\n").arg(fileName.toString());
179 void TestSuite::toXML(XMLWriter &receiver, TestCase *const tc) const
181 // TODO startElement() endElement() calls can be simplified.
185 receiver.startDocument();
187 QXmlAttributes test_suiteAtts;
188 test_suiteAtts.append(QLatin1String("CatalogDesignDate"), QString(),
189 QLatin1String("CatalogDesignDate"), m_designDate.toString(Qt::ISODate));
190 test_suiteAtts.append(QLatin1String("version"), QString(),
191 QLatin1String("version"), m_version);
192 test_suiteAtts.append(QLatin1String("SourceOffsetPath"), QString(),
193 QLatin1String("SourceOffsetPath"), QString());
194 test_suiteAtts.append(QLatin1String("ResultOffsetPath"), QString(),
195 QLatin1String("ResultOffsetPath"), QString());
196 test_suiteAtts.append(QLatin1String("XQueryQueryOffsetPath"), QString(),
197 QLatin1String("XQueryQueryOffsetPath"), QString());
198 test_suiteAtts.append(QLatin1String("QueryXQueryOffsetPath"), QString(),
199 QLatin1String("QueryXQueryOffsetPath"), QString());
200 test_suiteAtts.append(QLatin1String("XQueryFileExtension"), QString(),
201 QLatin1String("XQueryFileExtension"), QString());
202 test_suiteAtts.append(QLatin1String("XQueryXFileExtension"), QString(),
203 QLatin1String("XQueryXFileExtension"), QString());
205 receiver.startPrefixMapping(QString(), Global::xqtsCatalogNS);
206 receiver.startElement(QLatin1String("test-suite"), test_suiteAtts);
207 receiver.endPrefixMapping(QString());
210 QXmlAttributes test_groupAtts;
211 test_groupAtts.append(QLatin1String("GeneratedGroupByPatternistSDKRunSuite"), QString(),
212 QLatin1String("GeneratedGroupByPatternistSDKRunSuite"), QString());
213 receiver.startElement(QLatin1String("test-group"), test_groupAtts);
216 receiver.startElement(QLatin1String("GroupInfo"), test_groupAtts);
219 receiver.startElement(QLatin1String("title"), test_groupAtts);
220 receiver.characters(QLatin1String("Contains the test case generated by PatternistSDKRunSuite."));
223 receiver.endElement(QLatin1String("title"));
226 receiver.startElement(QLatin1String("description"), test_groupAtts);
228 receiver.endElement(QLatin1String("description"));
231 receiver.endElement(QLatin1String("GroupInfo"));
238 receiver.endElement(QLatin1String("test-group"));
241 receiver.endElement(QLatin1String("test-suite"));
244 QString TestSuite::version() const
249 QDate TestSuite::designDate() const
254 void TestSuite::setVersion(const QString &ver)
259 void TestSuite::setDesignDate(const QDate &date)
264 TestContainer *TestSuite::parent() const
269 // vim: et:ts=4:sw=4:sts=4