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 ****************************************************************************/
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