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 ** 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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
43 #include <QtTest/QtTest>
45 #ifdef QTEST_XMLPATTERNS
48 #include "TestSuite.h"
49 #include "TestSuiteResult.h"
50 #include "XMLWriter.h"
53 #include "private/qautoptr_p.h"
54 #include "tst_suitetest.h"
56 using namespace QPatternistSDK;
58 tst_SuiteTest::tst_SuiteTest(const SuiteType suiteType,
59 const bool alwaysRun) : m_existingBaseline(inputFile(QLatin1String("Baseline.xml")))
60 , m_candidateBaseline(inputFile(QLatin1String("CandidateBaseline.xml")))
61 , m_abortRun(!alwaysRun && !QFile::exists(QLatin1String("runTests")))
62 , m_suiteType(suiteType)
67 Returns an absolute path to the XQTS catalog, or flags a failure using
68 QTestLib's mechanisms.
70 Finding the location of the catalog is done with `p4 where` such that we don't have
71 to care about where it is checked out.
73 void tst_SuiteTest::initTestCase()
75 catalogPath(m_catalogPath);
79 Just runs the test suite and writes the result to m_candidateBaseline.
81 void tst_SuiteTest::runTestSuite() const
84 QSKIP("The test suite is not available, no tests are run.", SkipAll);
87 const QFileInfo fi(m_catalogPath);
88 const QUrl catalogPath(QUrl::fromLocalFile(fi.absoluteFilePath()));
90 TestSuite::SuiteType suiteType;
91 switch (m_suiteType) {
93 suiteType = TestSuite::XQuerySuite;
96 suiteType = TestSuite::XsltSuite;
99 suiteType = TestSuite::XsdSuite;
105 TestSuite *const ts = TestSuite::openCatalog(catalogPath, errMsg, true, suiteType);
107 QVERIFY2(ts, qPrintable(QString::fromLatin1("Failed to open the catalog, maybe it doesn't exist or is broken: %1").arg(errMsg)));
109 /* Run the tests, and serialize the result(as according to XQTSResult.xsd) to standard out. */
110 TestSuiteResult *const result = ts->runSuite();
113 QFile out(m_candidateBaseline);
114 QVERIFY(out.open(QIODevice::WriteOnly));
116 XMLWriter serializer(&out);
117 result->toXML(serializer);
123 void tst_SuiteTest::checkTestSuiteResult() const
126 QSKIP("This test takes too long time to run on the majority of platforms.", SkipAll);
128 typedef QList<QFileInfo> QFileInfoList;
130 const QFileInfo baseline(m_existingBaseline);
131 const QFileInfo result(m_candidateBaseline);
133 list.append(baseline);
136 const QFileInfoList::const_iterator end(list.constEnd());
138 QEventLoop eventLoop;
139 const QPatternist::AutoPtr<Worker> worker(new Worker(eventLoop, m_existingBaseline, result));
141 /* Passed to ResultThreader so it knows what kind of file it is handling. */
142 ResultThreader::Type type = ResultThreader::Baseline;
144 for(QFileInfoList::const_iterator it(list.constBegin()); it != end; ++it)
149 QVERIFY2(i.exists(), qPrintable(QString::fromLatin1("File %1 does not exist.")
150 .arg(i.fileName())));
152 QFile *const file = new QFile(i.absoluteFilePath(), worker.data());
154 QVERIFY2(file->open(QIODevice::ReadOnly), qPrintable(QString::fromLatin1("Could not open file %1 for reading.")
155 .arg(i.fileName())));
157 ResultThreader *handler = new ResultThreader(eventLoop, file, type, worker.data());
159 QObject::connect(handler, SIGNAL(finished()), worker.data(), SLOT(threadFinished()));
161 handler->start(); /* Start the thread. It now parses the file
162 and emits threadFinished() when done. */
163 type = ResultThreader::Result;
166 const int exitCode = eventLoop.exec();
168 QCOMPARE(exitCode, 0);
171 bool tst_SuiteTest::dontRun() const
178 // vim: et:ts=4:sw=4:sts=4