|
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 |
|
43 #include <QtTest/QtTest> |
|
44 |
|
45 #ifdef QTEST_XMLPATTERNS |
|
46 |
|
47 #include <QProcess> |
|
48 #include "TestSuite.h" |
|
49 #include "TestSuiteResult.h" |
|
50 #include "XMLWriter.h" |
|
51 #include "ExitCode.h" |
|
52 #include "Worker.h" |
|
53 #include "private/qautoptr_p.h" |
|
54 #include "tst_suitetest.h" |
|
55 |
|
56 using namespace QPatternistSDK; |
|
57 |
|
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) |
|
63 { |
|
64 } |
|
65 |
|
66 /*! |
|
67 Returns an absolute path to the XQTS catalog, or flags a failure using |
|
68 QTestLib's mechanisms. |
|
69 |
|
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. |
|
72 */ |
|
73 void tst_SuiteTest::initTestCase() |
|
74 { |
|
75 catalogPath(m_catalogPath); |
|
76 } |
|
77 |
|
78 /*! |
|
79 Just runs the test suite and writes the result to m_candidateBaseline. |
|
80 */ |
|
81 void tst_SuiteTest::runTestSuite() const |
|
82 { |
|
83 if(m_abortRun) |
|
84 QSKIP("The test suite is not available, no tests are run.", SkipAll); |
|
85 |
|
86 QString errMsg; |
|
87 const QFileInfo fi(m_catalogPath); |
|
88 const QUrl catalogPath(QUrl::fromLocalFile(fi.absoluteFilePath())); |
|
89 |
|
90 TestSuite::SuiteType suiteType; |
|
91 switch (m_suiteType) { |
|
92 case XQuerySuite: suiteType = TestSuite::XQuerySuite; |
|
93 case XsltSuite: suiteType = TestSuite::XsltSuite; |
|
94 case XsdSuite: suiteType = TestSuite::XsdSuite; |
|
95 default: break; |
|
96 } |
|
97 |
|
98 TestSuite *const ts = TestSuite::openCatalog(catalogPath, errMsg, true, suiteType); |
|
99 |
|
100 QVERIFY2(ts, qPrintable(QString::fromLatin1("Failed to open the catalog, maybe it doesn't exist or is broken: %1").arg(errMsg))); |
|
101 |
|
102 /* Run the tests, and serialize the result(as according to XQTSResult.xsd) to standard out. */ |
|
103 TestSuiteResult *const result = ts->runSuite(); |
|
104 Q_ASSERT(result); |
|
105 |
|
106 QFile out(m_candidateBaseline); |
|
107 QVERIFY(out.open(QIODevice::WriteOnly)); |
|
108 |
|
109 XMLWriter serializer(&out); |
|
110 result->toXML(serializer); |
|
111 |
|
112 delete result; |
|
113 delete ts; |
|
114 } |
|
115 |
|
116 void tst_SuiteTest::checkTestSuiteResult() const |
|
117 { |
|
118 if(m_abortRun) |
|
119 QSKIP("This test takes too long time to run on the majority of platforms.", SkipAll); |
|
120 |
|
121 typedef QList<QFileInfo> QFileInfoList; |
|
122 |
|
123 const QFileInfo baseline(m_existingBaseline); |
|
124 const QFileInfo result(m_candidateBaseline); |
|
125 QFileInfoList list; |
|
126 list.append(baseline); |
|
127 list.append(result); |
|
128 |
|
129 const QFileInfoList::const_iterator end(list.constEnd()); |
|
130 |
|
131 QEventLoop eventLoop; |
|
132 const QPatternist::AutoPtr<Worker> worker(new Worker(eventLoop, m_existingBaseline, result)); |
|
133 |
|
134 /* Passed to ResultThreader so it knows what kind of file it is handling. */ |
|
135 ResultThreader::Type type = ResultThreader::Baseline; |
|
136 |
|
137 QProcess::execute(QLatin1String("p4 edit ") + m_existingBaseline); |
|
138 |
|
139 for(QFileInfoList::const_iterator it(list.constBegin()); it != end; ++it) |
|
140 { |
|
141 QFileInfo i(*it); |
|
142 i.makeAbsolute(); |
|
143 |
|
144 QVERIFY2(i.exists(), qPrintable(QString::fromLatin1("File %1 does not exist.") |
|
145 .arg(i.fileName()))); |
|
146 |
|
147 QFile *const file = new QFile(i.absoluteFilePath(), worker.data()); |
|
148 |
|
149 QVERIFY2(file->open(QIODevice::ReadOnly), qPrintable(QString::fromLatin1("Could not open file %1 for reading.") |
|
150 .arg(i.fileName()))); |
|
151 |
|
152 ResultThreader *handler = new ResultThreader(eventLoop, file, type, worker.data()); |
|
153 |
|
154 QObject::connect(handler, SIGNAL(finished()), worker.data(), SLOT(threadFinished())); |
|
155 |
|
156 handler->start(); /* Start the thread. It now parses the file |
|
157 and emits threadFinished() when done. */ |
|
158 type = ResultThreader::Result; |
|
159 } |
|
160 |
|
161 const int exitCode = eventLoop.exec(); |
|
162 |
|
163 QProcess::execute(QLatin1String("p4 revert -a ") + m_existingBaseline); |
|
164 |
|
165 QCOMPARE(exitCode, 0); |
|
166 } |
|
167 |
|
168 bool tst_SuiteTest::dontRun() const |
|
169 { |
|
170 return m_abortRun; |
|
171 } |
|
172 #endif |
|
173 |
|
174 |
|
175 // vim: et:ts=4:sw=4:sts=4 |