1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
43 #include <QtTest/QtTest>
46 #include "TestSuite.h"
47 #include "TestSuiteResult.h"
48 #include "XMLWriter.h"
51 #include "private/qautoptr_p.h"
52 #include "tst_suitetest.h"
54 using namespace QPatternistSDK;
56 tst_SuiteTest::tst_SuiteTest(const SuiteType suiteType,
57 const bool alwaysRun) : m_existingBaseline(QFINDTESTDATA("Baseline.xml"))
58 , m_candidateBaseline(QDir::current().filePath("CandidateBaseline.xml"))
59 , m_abortRun(!alwaysRun && !QFile::exists(QLatin1String("runTests")))
60 , m_suiteType(suiteType)
65 Returns an absolute path to the XQTS catalog, or flags a failure using
66 QTestLib's mechanisms.
68 void tst_SuiteTest::initTestCase()
70 catalogPath(m_catalogPath);
74 Just runs the test suite and writes the result to m_candidateBaseline.
76 void tst_SuiteTest::runTestSuite() const
79 QSKIP("The test suite is not available, no tests are run.");
82 const QFileInfo fi(m_catalogPath);
83 const QUrl catalogPath(QUrl::fromLocalFile(fi.absoluteFilePath()));
85 TestSuite::SuiteType suiteType(TestSuite::XQuerySuite);
86 switch (m_suiteType) {
88 suiteType = TestSuite::XQuerySuite;
91 suiteType = TestSuite::XsltSuite;
94 suiteType = TestSuite::XsdSuite;
100 TestSuite *const ts = TestSuite::openCatalog(catalogPath, errMsg, true, suiteType);
102 QVERIFY2(ts, qPrintable(QString::fromLatin1("Failed to open the catalog, maybe it doesn't exist or is broken: %1").arg(errMsg)));
104 /* Run the tests, and serialize the result(as according to XQTSResult.xsd) to standard out. */
105 TestSuiteResult *const result = ts->runSuite();
108 QFile out(m_candidateBaseline);
109 QVERIFY(out.open(QIODevice::WriteOnly));
111 XMLWriter serializer(&out);
112 result->toXML(serializer);
118 void tst_SuiteTest::checkTestSuiteResult() const
121 QSKIP("This test takes too long time to run on the majority of platforms.");
123 typedef QList<QFileInfo> QFileInfoList;
125 const QFileInfo baseline(m_existingBaseline);
126 const QFileInfo result(m_candidateBaseline);
128 list.append(baseline);
131 const QFileInfoList::const_iterator end(list.constEnd());
133 QEventLoop eventLoop;
134 const QPatternist::AutoPtr<Worker> worker(new Worker(eventLoop, m_existingBaseline, result));
136 /* Passed to ResultThreader so it knows what kind of file it is handling. */
137 ResultThreader::Type type = ResultThreader::Baseline;
139 for(QFileInfoList::const_iterator it(list.constBegin()); it != end; ++it)
144 QVERIFY2(i.exists(), qPrintable(QString::fromLatin1("File %1 does not exist.")
145 .arg(i.fileName())));
147 QFile *const file = new QFile(i.absoluteFilePath(), worker.data());
149 QVERIFY2(file->open(QIODevice::ReadOnly), qPrintable(QString::fromLatin1("Could not open file %1 for reading.")
150 .arg(i.fileName())));
152 ResultThreader *handler = new ResultThreader(eventLoop, file, type, worker.data());
154 QObject::connect(handler, SIGNAL(finished()), worker.data(), SLOT(threadFinished()));
156 handler->start(); /* Start the thread. It now parses the file
157 and emits threadFinished() when done. */
158 type = ResultThreader::Result;
161 const int exitCode = eventLoop.exec();
163 QCOMPARE(exitCode, 0);
166 bool tst_SuiteTest::dontRun() const
171 // vim: et:ts=4:sw=4:sts=4