Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qmltest/quicktestresult.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2017 Crimson AS <info@crimson.no> | - | ||||||||||||
4 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
6 | ** | - | ||||||||||||
7 | ** This file is part of the test suite of the Qt Toolkit. | - | ||||||||||||
8 | ** | - | ||||||||||||
9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
10 | ** Commercial License Usage | - | ||||||||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
17 | ** | - | ||||||||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
20 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
22 | ** packaging of this file. Please review the following information to | - | ||||||||||||
23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
25 | ** | - | ||||||||||||
26 | ** GNU General Public License Usage | - | ||||||||||||
27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
36 | ** | - | ||||||||||||
37 | ** $QT_END_LICENSE$ | - | ||||||||||||
38 | ** | - | ||||||||||||
39 | ****************************************************************************/ | - | ||||||||||||
40 | - | |||||||||||||
41 | #include "quicktestresult_p.h" | - | ||||||||||||
42 | #include <QtTest/qtestcase.h> | - | ||||||||||||
43 | #include <QtTest/qtestsystem.h> | - | ||||||||||||
44 | #include <QtTest/private/qtestblacklist_p.h> | - | ||||||||||||
45 | #include <QtTest/private/qtestresult_p.h> | - | ||||||||||||
46 | #include <QtTest/private/qtesttable_p.h> | - | ||||||||||||
47 | #include <QtTest/private/qtestlog_p.h> | - | ||||||||||||
48 | #include "qtestoptions_p.h" | - | ||||||||||||
49 | #include <QtTest/qbenchmark.h> | - | ||||||||||||
50 | // qbenchmark_p.h pulls windows.h via 3rd party; prevent it from defining | - | ||||||||||||
51 | // the min/max macros which would clash with qnumeric_p.h's usage of min()/max(). | - | ||||||||||||
52 | #if defined(Q_OS_WIN32) && !defined(NOMINMAX) | - | ||||||||||||
53 | # define NOMINMAX | - | ||||||||||||
54 | #endif | - | ||||||||||||
55 | #include <QtTest/private/qbenchmark_p.h> | - | ||||||||||||
56 | #include <QtCore/qset.h> | - | ||||||||||||
57 | #include <QtCore/qmap.h> | - | ||||||||||||
58 | #include <QtCore/qbytearray.h> | - | ||||||||||||
59 | #include <QtCore/qcoreapplication.h> | - | ||||||||||||
60 | #include <QtCore/qdatetime.h> | - | ||||||||||||
61 | #include <QtCore/qdebug.h> | - | ||||||||||||
62 | #include <QtCore/QUrl> | - | ||||||||||||
63 | #include <QtCore/QDir> | - | ||||||||||||
64 | #include <QtCore/qregularexpression.h> | - | ||||||||||||
65 | #include <QtQuick/qquickwindow.h> | - | ||||||||||||
66 | #include <QtGui/qvector3d.h> | - | ||||||||||||
67 | #include <QtGui/qimagewriter.h> | - | ||||||||||||
68 | #include <QtQml/private/qqmlglobal_p.h> | - | ||||||||||||
69 | #include <QtQml/QQmlEngine> | - | ||||||||||||
70 | #include <QtQml/QQmlContext> | - | ||||||||||||
71 | #include <private/qv4qobjectwrapper_p.h> | - | ||||||||||||
72 | - | |||||||||||||
73 | #include <algorithm> | - | ||||||||||||
74 | - | |||||||||||||
75 | QT_BEGIN_NAMESPACE | - | ||||||||||||
76 | - | |||||||||||||
77 | static const char *globalProgramName = nullptr; | - | ||||||||||||
78 | static bool loggingStarted = false; | - | ||||||||||||
79 | static QBenchmarkGlobalData globalBenchmarkData; | - | ||||||||||||
80 | - | |||||||||||||
81 | extern bool qWaitForSignal(QObject *obj, const char* signal, int timeout = 5000); | - | ||||||||||||
82 | - | |||||||||||||
83 | class Q_QUICK_TEST_EXPORT QuickTestImageObject : public QObject | - | ||||||||||||
84 | { | - | ||||||||||||
85 | Q_OBJECT | - | ||||||||||||
86 | - | |||||||||||||
87 | Q_PROPERTY(int width READ width CONSTANT) | - | ||||||||||||
88 | Q_PROPERTY(int height READ height CONSTANT) | - | ||||||||||||
89 | Q_PROPERTY(QSize size READ size CONSTANT) | - | ||||||||||||
90 | - | |||||||||||||
91 | public: | - | ||||||||||||
92 | QuickTestImageObject(const QImage& img, QObject *parent = nullptr) | - | ||||||||||||
93 | : QObject(parent) | - | ||||||||||||
94 | , m_image(img) | - | ||||||||||||
95 | { | - | ||||||||||||
96 | } never executed: end of block | 0 | ||||||||||||
97 | - | |||||||||||||
98 | ~QuickTestImageObject() {} | - | ||||||||||||
99 | - | |||||||||||||
100 | public Q_SLOTS: | - | ||||||||||||
101 | int red(int x, int y) const | - | ||||||||||||
102 | { | - | ||||||||||||
103 | return pixel(x, y).value<QColor>().red(); never executed: return pixel(x, y).value<QColor>().red(); | 0 | ||||||||||||
104 | } | - | ||||||||||||
105 | - | |||||||||||||
106 | int green(int x, int y) const | - | ||||||||||||
107 | { | - | ||||||||||||
108 | return pixel(x, y).value<QColor>().green(); never executed: return pixel(x, y).value<QColor>().green(); | 0 | ||||||||||||
109 | } | - | ||||||||||||
110 | - | |||||||||||||
111 | int blue(int x, int y) const | - | ||||||||||||
112 | { | - | ||||||||||||
113 | return pixel(x, y).value<QColor>().blue(); never executed: return pixel(x, y).value<QColor>().blue(); | 0 | ||||||||||||
114 | } | - | ||||||||||||
115 | - | |||||||||||||
116 | int alpha(int x, int y) const | - | ||||||||||||
117 | { | - | ||||||||||||
118 | return pixel(x, y).value<QColor>().alpha(); never executed: return pixel(x, y).value<QColor>().alpha(); | 0 | ||||||||||||
119 | } | - | ||||||||||||
120 | - | |||||||||||||
121 | QVariant pixel(int x, int y) const | - | ||||||||||||
122 | { | - | ||||||||||||
123 | if (m_image.isNull()
| 0 | ||||||||||||
124 | || x >= m_image.width()
| 0 | ||||||||||||
125 | || y >= m_image.height()
| 0 | ||||||||||||
126 | || x < 0
| 0 | ||||||||||||
127 | || y < 0
| 0 | ||||||||||||
128 | || x * y >= m_image.width() * m_image.height())
| 0 | ||||||||||||
129 | return QVariant(); never executed: return QVariant(); | 0 | ||||||||||||
130 | - | |||||||||||||
131 | return QColor::fromRgba(m_image.pixel(QPoint(x, y))); never executed: return QColor::fromRgba(m_image.pixel(QPoint(x, y))); | 0 | ||||||||||||
132 | } | - | ||||||||||||
133 | - | |||||||||||||
134 | bool equals(QuickTestImageObject *other) const | - | ||||||||||||
135 | { | - | ||||||||||||
136 | if (!other)
| 0 | ||||||||||||
137 | return m_image.isNull(); never executed: return m_image.isNull(); | 0 | ||||||||||||
138 | - | |||||||||||||
139 | return m_image == other->m_image; never executed: return m_image == other->m_image; | 0 | ||||||||||||
140 | } | - | ||||||||||||
141 | - | |||||||||||||
142 | void save(const QString &filePath) | - | ||||||||||||
143 | { | - | ||||||||||||
144 | QImageWriter writer(filePath); | - | ||||||||||||
145 | if (!writer.write(m_image)) {
| 0 | ||||||||||||
146 | QQmlEngine *engine = qmlContext(this)->engine(); | - | ||||||||||||
147 | QV4::ExecutionEngine *v4 = engine->handle(); | - | ||||||||||||
148 | v4->throwError(QStringLiteral("Can't save to %1: %2").arg(filePath, writer.errorString())); never executed: return qstring_literal_temp; | 0 | ||||||||||||
149 | } never executed: end of block | 0 | ||||||||||||
150 | } never executed: end of block | 0 | ||||||||||||
151 | - | |||||||||||||
152 | public: | - | ||||||||||||
153 | int width() const | - | ||||||||||||
154 | { | - | ||||||||||||
155 | return m_image.width(); never executed: return m_image.width(); | 0 | ||||||||||||
156 | } | - | ||||||||||||
157 | - | |||||||||||||
158 | int height() const | - | ||||||||||||
159 | { | - | ||||||||||||
160 | return m_image.height(); never executed: return m_image.height(); | 0 | ||||||||||||
161 | } | - | ||||||||||||
162 | - | |||||||||||||
163 | QSize size() const | - | ||||||||||||
164 | { | - | ||||||||||||
165 | return m_image.size(); never executed: return m_image.size(); | 0 | ||||||||||||
166 | } | - | ||||||||||||
167 | - | |||||||||||||
168 | private: | - | ||||||||||||
169 | QImage m_image; | - | ||||||||||||
170 | }; | - | ||||||||||||
171 | - | |||||||||||||
172 | class QuickTestResultPrivate | - | ||||||||||||
173 | { | - | ||||||||||||
174 | public: | - | ||||||||||||
175 | QuickTestResultPrivate() | - | ||||||||||||
176 | : table(nullptr) | - | ||||||||||||
177 | , benchmarkIter(nullptr) | - | ||||||||||||
178 | , benchmarkData(nullptr) | - | ||||||||||||
179 | , iterCount(0) | - | ||||||||||||
180 | { | - | ||||||||||||
181 | } executed 40 times by 5 tests: end of block Executed by:
| 40 | ||||||||||||
182 | ~QuickTestResultPrivate() | - | ||||||||||||
183 | { | - | ||||||||||||
184 | delete table; | - | ||||||||||||
185 | delete benchmarkIter; | - | ||||||||||||
186 | delete benchmarkData; | - | ||||||||||||
187 | } executed 40 times by 5 tests: end of block Executed by:
| 40 | ||||||||||||
188 | - | |||||||||||||
189 | QByteArray intern(const QString &str); | - | ||||||||||||
190 | - | |||||||||||||
191 | QString testCaseName; | - | ||||||||||||
192 | QString functionName; | - | ||||||||||||
193 | QSet<QByteArray> internedStrings; | - | ||||||||||||
194 | QTestTable *table; | - | ||||||||||||
195 | QTest::QBenchmarkIterationController *benchmarkIter; | - | ||||||||||||
196 | QBenchmarkTestMethodData *benchmarkData; | - | ||||||||||||
197 | int iterCount; | - | ||||||||||||
198 | QList<QBenchmarkResult> results; | - | ||||||||||||
199 | }; | - | ||||||||||||
200 | - | |||||||||||||
201 | QByteArray QuickTestResultPrivate::intern(const QString &str) | - | ||||||||||||
202 | { | - | ||||||||||||
203 | QByteArray bstr = str.toUtf8(); | - | ||||||||||||
204 | return *(internedStrings.insert(bstr)); executed 188 times by 4 tests: return *(internedStrings.insert(bstr)); Executed by:
| 188 | ||||||||||||
205 | } | - | ||||||||||||
206 | - | |||||||||||||
207 | QuickTestResult::QuickTestResult(QObject *parent) | - | ||||||||||||
208 | : QObject(parent), d_ptr(new QuickTestResultPrivate) | - | ||||||||||||
209 | { | - | ||||||||||||
210 | if (!QBenchmarkGlobalData::current)
| 0-40 | ||||||||||||
211 | QBenchmarkGlobalData::current = &globalBenchmarkData; never executed: QBenchmarkGlobalData::current = &globalBenchmarkData; | 0 | ||||||||||||
212 | } executed 40 times by 5 tests: end of block Executed by:
| 40 | ||||||||||||
213 | - | |||||||||||||
214 | QuickTestResult::~QuickTestResult() | - | ||||||||||||
215 | { | - | ||||||||||||
216 | } | - | ||||||||||||
217 | - | |||||||||||||
218 | /*! | - | ||||||||||||
219 | \qmlproperty string TestResult::testCaseName | - | ||||||||||||
220 | - | |||||||||||||
221 | This property defines the name of current TestCase element | - | ||||||||||||
222 | that is running test cases. | - | ||||||||||||
223 | - | |||||||||||||
224 | \sa functionName | - | ||||||||||||
225 | */ | - | ||||||||||||
226 | QString QuickTestResult::testCaseName() const | - | ||||||||||||
227 | { | - | ||||||||||||
228 | Q_D(const QuickTestResult); | - | ||||||||||||
229 | return d->testCaseName; executed 192 times by 2 tests: return d->testCaseName; Executed by:
| 192 | ||||||||||||
230 | } | - | ||||||||||||
231 | - | |||||||||||||
232 | void QuickTestResult::setTestCaseName(const QString &name) | - | ||||||||||||
233 | { | - | ||||||||||||
234 | Q_D(QuickTestResult); | - | ||||||||||||
235 | d->testCaseName = name; | - | ||||||||||||
236 | emit testCaseNameChanged(); | - | ||||||||||||
237 | } executed 64 times by 4 tests: end of block Executed by:
| 64 | ||||||||||||
238 | - | |||||||||||||
239 | /*! | - | ||||||||||||
240 | \qmlproperty string TestResult::functionName | - | ||||||||||||
241 | - | |||||||||||||
242 | This property defines the name of current test function | - | ||||||||||||
243 | within a TestCase element that is running. If this string is | - | ||||||||||||
244 | empty, then no function is currently running. | - | ||||||||||||
245 | - | |||||||||||||
246 | \sa testCaseName | - | ||||||||||||
247 | */ | - | ||||||||||||
248 | QString QuickTestResult::functionName() const | - | ||||||||||||
249 | { | - | ||||||||||||
250 | Q_D(const QuickTestResult); | - | ||||||||||||
251 | return d->functionName; executed 192 times by 2 tests: return d->functionName; Executed by:
| 192 | ||||||||||||
252 | } | - | ||||||||||||
253 | - | |||||||||||||
254 | void QuickTestResult::setFunctionName(const QString &name) | - | ||||||||||||
255 | { | - | ||||||||||||
256 | Q_D(QuickTestResult); | - | ||||||||||||
257 | if (!name.isEmpty()) {
| 32-188 | ||||||||||||
258 | if (d->testCaseName.isEmpty()) {
| 0-188 | ||||||||||||
259 | QTestResult::setCurrentTestFunction | - | ||||||||||||
260 | (d->intern(name).constData()); | - | ||||||||||||
261 | } else { never executed: end of block | 0 | ||||||||||||
262 | QString fullName = d->testCaseName + QLatin1String("::") + name; | - | ||||||||||||
263 | QTestResult::setCurrentTestFunction | - | ||||||||||||
264 | (d->intern(fullName).constData()); | - | ||||||||||||
265 | QTestPrivate::checkBlackLists(fullName.toUtf8().constData(), nullptr); | - | ||||||||||||
266 | } executed 188 times by 4 tests: end of block Executed by:
| 188 | ||||||||||||
267 | } else { | - | ||||||||||||
268 | QTestResult::setCurrentTestFunction(nullptr); | - | ||||||||||||
269 | } executed 32 times by 4 tests: end of block Executed by:
| 32 | ||||||||||||
270 | d->functionName = name; | - | ||||||||||||
271 | emit functionNameChanged(); | - | ||||||||||||
272 | } executed 220 times by 4 tests: end of block Executed by:
| 220 | ||||||||||||
273 | - | |||||||||||||
274 | /*! | - | ||||||||||||
275 | \qmlproperty string TestResult::dataTag | - | ||||||||||||
276 | - | |||||||||||||
277 | This property defines the tag for the current row in a | - | ||||||||||||
278 | data-driven test, or an empty string if not a data-driven test. | - | ||||||||||||
279 | */ | - | ||||||||||||
280 | QString QuickTestResult::dataTag() const | - | ||||||||||||
281 | { | - | ||||||||||||
282 | const char *tag = QTestResult::currentDataTag(); | - | ||||||||||||
283 | if (tag)
| 0 | ||||||||||||
284 | return QString::fromUtf8(tag); never executed: return QString::fromUtf8(tag); | 0 | ||||||||||||
285 | else | - | ||||||||||||
286 | return QString(); never executed: return QString(); | 0 | ||||||||||||
287 | } | - | ||||||||||||
288 | - | |||||||||||||
289 | void QuickTestResult::setDataTag(const QString &tag) | - | ||||||||||||
290 | { | - | ||||||||||||
291 | if (!tag.isEmpty()) {
| 192 | ||||||||||||
292 | QTestData *data = &(QTest::newRow(tag.toUtf8().constData())); | - | ||||||||||||
293 | QTestResult::setCurrentTestData(data); | - | ||||||||||||
294 | QTestPrivate::checkBlackLists((testCaseName() + QLatin1String("::") + functionName()).toUtf8().constData(), tag.toUtf8().constData()); | - | ||||||||||||
295 | emit dataTagChanged(); | - | ||||||||||||
296 | } else { executed 192 times by 2 tests: end of block Executed by:
| 192 | ||||||||||||
297 | QTestResult::setCurrentTestData(nullptr); | - | ||||||||||||
298 | } executed 192 times by 2 tests: end of block Executed by:
| 192 | ||||||||||||
299 | } | - | ||||||||||||
300 | - | |||||||||||||
301 | /*! | - | ||||||||||||
302 | \qmlproperty bool TestResult::failed | - | ||||||||||||
303 | - | |||||||||||||
304 | This property returns true if the current test function (or | - | ||||||||||||
305 | current test data row for a data-driven test) has failed; | - | ||||||||||||
306 | false otherwise. The fail state is reset when functionName | - | ||||||||||||
307 | is changed or finishTestDataCleanup() is called. | - | ||||||||||||
308 | - | |||||||||||||
309 | \sa skipped | - | ||||||||||||
310 | */ | - | ||||||||||||
311 | bool QuickTestResult::isFailed() const | - | ||||||||||||
312 | { | - | ||||||||||||
313 | return QTestResult::currentTestFailed(); executed 988 times by 4 tests: return QTestResult::currentTestFailed(); Executed by:
| 988 | ||||||||||||
314 | } | - | ||||||||||||
315 | - | |||||||||||||
316 | /*! | - | ||||||||||||
317 | \qmlproperty bool TestResult::skipped | - | ||||||||||||
318 | - | |||||||||||||
319 | This property returns true if the current test function was | - | ||||||||||||
320 | marked as skipped; false otherwise. | - | ||||||||||||
321 | - | |||||||||||||
322 | \sa failed | - | ||||||||||||
323 | */ | - | ||||||||||||
324 | bool QuickTestResult::isSkipped() const | - | ||||||||||||
325 | { | - | ||||||||||||
326 | return QTestResult::skipCurrentTest(); executed 304 times by 3 tests: return QTestResult::skipCurrentTest(); Executed by:
| 304 | ||||||||||||
327 | } | - | ||||||||||||
328 | - | |||||||||||||
329 | void QuickTestResult::setSkipped(bool skip) | - | ||||||||||||
330 | { | - | ||||||||||||
331 | QTestResult::setSkipCurrentTest(skip); | - | ||||||||||||
332 | if (!skip)
| 0-156 | ||||||||||||
333 | QTestResult::setBlacklistCurrentTest(false); executed 156 times by 4 tests: QTestResult::setBlacklistCurrentTest(false); Executed by:
| 156 | ||||||||||||
334 | emit skippedChanged(); | - | ||||||||||||
335 | } executed 156 times by 4 tests: end of block Executed by:
| 156 | ||||||||||||
336 | - | |||||||||||||
337 | /*! | - | ||||||||||||
338 | \qmlproperty int TestResult::passCount | - | ||||||||||||
339 | - | |||||||||||||
340 | This property returns the number of tests that have passed. | - | ||||||||||||
341 | - | |||||||||||||
342 | \sa failCount, skipCount | - | ||||||||||||
343 | */ | - | ||||||||||||
344 | int QuickTestResult::passCount() const | - | ||||||||||||
345 | { | - | ||||||||||||
346 | return QTestLog::passCount(); never executed: return QTestLog::passCount(); | 0 | ||||||||||||
347 | } | - | ||||||||||||
348 | - | |||||||||||||
349 | /*! | - | ||||||||||||
350 | \qmlproperty int TestResult::failCount | - | ||||||||||||
351 | - | |||||||||||||
352 | This property returns the number of tests that have failed. | - | ||||||||||||
353 | - | |||||||||||||
354 | \sa passCount, skipCount | - | ||||||||||||
355 | */ | - | ||||||||||||
356 | int QuickTestResult::failCount() const | - | ||||||||||||
357 | { | - | ||||||||||||
358 | return QTestLog::failCount(); never executed: return QTestLog::failCount(); | 0 | ||||||||||||
359 | } | - | ||||||||||||
360 | - | |||||||||||||
361 | /*! | - | ||||||||||||
362 | \qmlproperty int TestResult::skipCount | - | ||||||||||||
363 | - | |||||||||||||
364 | This property returns the number of tests that have been skipped. | - | ||||||||||||
365 | - | |||||||||||||
366 | \sa passCount, failCount | - | ||||||||||||
367 | */ | - | ||||||||||||
368 | int QuickTestResult::skipCount() const | - | ||||||||||||
369 | { | - | ||||||||||||
370 | return QTestLog::skipCount(); never executed: return QTestLog::skipCount(); | 0 | ||||||||||||
371 | } | - | ||||||||||||
372 | - | |||||||||||||
373 | /*! | - | ||||||||||||
374 | \qmlproperty list<string> TestResult::functionsToRun | - | ||||||||||||
375 | - | |||||||||||||
376 | This property returns the list of function names to be run. | - | ||||||||||||
377 | */ | - | ||||||||||||
378 | QStringList QuickTestResult::functionsToRun() const | - | ||||||||||||
379 | { | - | ||||||||||||
380 | return QTest::testFunctions; executed 186 times by 4 tests: return QTest::testFunctions; Executed by:
| 186 | ||||||||||||
381 | } | - | ||||||||||||
382 | - | |||||||||||||
383 | /*! | - | ||||||||||||
384 | \qmlmethod TestResult::reset() | - | ||||||||||||
385 | - | |||||||||||||
386 | Resets all pass/fail/skip counters and prepare for testing. | - | ||||||||||||
387 | */ | - | ||||||||||||
388 | void QuickTestResult::reset() | - | ||||||||||||
389 | { | - | ||||||||||||
390 | if (!globalProgramName) // Only if run via qmlviewer.
| 0-32 | ||||||||||||
391 | QTestResult::reset(); never executed: QTestResult::reset(); | 0 | ||||||||||||
392 | } executed 32 times by 4 tests: end of block Executed by:
| 32 | ||||||||||||
393 | - | |||||||||||||
394 | /*! | - | ||||||||||||
395 | \qmlmethod TestResult::startLogging() | - | ||||||||||||
396 | - | |||||||||||||
397 | Starts logging to the test output stream and writes the | - | ||||||||||||
398 | test header. | - | ||||||||||||
399 | - | |||||||||||||
400 | \sa stopLogging() | - | ||||||||||||
401 | */ | - | ||||||||||||
402 | void QuickTestResult::startLogging() | - | ||||||||||||
403 | { | - | ||||||||||||
404 | // The program name is used for logging headers and footers if it | - | ||||||||||||
405 | // is set. Otherwise the test case name is used. | - | ||||||||||||
406 | if (loggingStarted)
| 16 | ||||||||||||
407 | return; executed 16 times by 3 tests: return; Executed by:
| 16 | ||||||||||||
408 | QTestLog::startLogging(); | - | ||||||||||||
409 | loggingStarted = true; | - | ||||||||||||
410 | } executed 16 times by 4 tests: end of block Executed by:
| 16 | ||||||||||||
411 | - | |||||||||||||
412 | /*! | - | ||||||||||||
413 | \qmlmethod TestResult::stopLogging() | - | ||||||||||||
414 | - | |||||||||||||
415 | Writes the test footer to the test output stream and then stops logging. | - | ||||||||||||
416 | - | |||||||||||||
417 | \sa startLogging() | - | ||||||||||||
418 | */ | - | ||||||||||||
419 | void QuickTestResult::stopLogging() | - | ||||||||||||
420 | { | - | ||||||||||||
421 | Q_D(QuickTestResult); | - | ||||||||||||
422 | if (globalProgramName)
| 0-32 | ||||||||||||
423 | return; // Logging will be stopped by setProgramName(0). executed 32 times by 4 tests: return; Executed by:
| 32 | ||||||||||||
424 | QTestResult::setCurrentTestObject(d->intern(d->testCaseName).constData()); | - | ||||||||||||
425 | QTestLog::stopLogging(); | - | ||||||||||||
426 | } never executed: end of block | 0 | ||||||||||||
427 | - | |||||||||||||
428 | void QuickTestResult::initTestTable() | - | ||||||||||||
429 | { | - | ||||||||||||
430 | Q_D(QuickTestResult); | - | ||||||||||||
431 | delete d->table; | - | ||||||||||||
432 | d->table = new QTestTable; | - | ||||||||||||
433 | //qmltest does not really need the column for data driven test | - | ||||||||||||
434 | //add this to avoid warnings. | - | ||||||||||||
435 | d->table->addColumn(qMetaTypeId<QString>(), "qmltest_dummy_data_column"); | - | ||||||||||||
436 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||
437 | - | |||||||||||||
438 | void QuickTestResult::clearTestTable() | - | ||||||||||||
439 | { | - | ||||||||||||
440 | Q_D(QuickTestResult); | - | ||||||||||||
441 | delete d->table; | - | ||||||||||||
442 | d->table = nullptr; | - | ||||||||||||
443 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||||||||
444 | - | |||||||||||||
445 | void QuickTestResult::finishTestData() | - | ||||||||||||
446 | { | - | ||||||||||||
447 | QTestResult::finishedCurrentTestData(); | - | ||||||||||||
448 | } executed 368 times by 4 tests: end of block Executed by:
| 368 | ||||||||||||
449 | - | |||||||||||||
450 | void QuickTestResult::finishTestDataCleanup() | - | ||||||||||||
451 | { | - | ||||||||||||
452 | QTestResult::finishedCurrentTestDataCleanup(); | - | ||||||||||||
453 | } executed 368 times by 4 tests: end of block Executed by:
| 368 | ||||||||||||
454 | - | |||||||||||||
455 | void QuickTestResult::finishTestFunction() | - | ||||||||||||
456 | { | - | ||||||||||||
457 | QTestResult::finishedCurrentTestFunction(); | - | ||||||||||||
458 | } executed 188 times by 4 tests: end of block Executed by:
| 188 | ||||||||||||
459 | - | |||||||||||||
460 | static QString qtestFixUrl(const QUrl &location) | - | ||||||||||||
461 | { | - | ||||||||||||
462 | if (location.isLocalFile()) // Use QUrl's logic for Windows drive letters.
| 0-1840 | ||||||||||||
463 | return QDir::toNativeSeparators(location.toLocalFile()); executed 1840 times by 3 tests: return QDir::toNativeSeparators(location.toLocalFile()); Executed by:
| 1840 | ||||||||||||
464 | return location.toString(); never executed: return location.toString(); | 0 | ||||||||||||
465 | } | - | ||||||||||||
466 | - | |||||||||||||
467 | void QuickTestResult::fail | - | ||||||||||||
468 | (const QString &message, const QUrl &location, int line) | - | ||||||||||||
469 | { | - | ||||||||||||
470 | QTestResult::addFailure(message.toLatin1().constData(), | - | ||||||||||||
471 | qtestFixUrl(location).toLatin1().constData(), line); | - | ||||||||||||
472 | } never executed: end of block | 0 | ||||||||||||
473 | - | |||||||||||||
474 | bool QuickTestResult::verify | - | ||||||||||||
475 | (bool success, const QString &message, const QUrl &location, int line) | - | ||||||||||||
476 | { | - | ||||||||||||
477 | if (!success && message.isEmpty()) {
| 0-426 | ||||||||||||
478 | return QTestResult::verify never executed: return QTestResult::verify (success, "verify()", "", qtestFixUrl(location).toLatin1().constData(), line); | 0 | ||||||||||||
479 | (success, "verify()", "", never executed: return QTestResult::verify (success, "verify()", "", qtestFixUrl(location).toLatin1().constData(), line); | 0 | ||||||||||||
480 | qtestFixUrl(location).toLatin1().constData(), line); never executed: return QTestResult::verify (success, "verify()", "", qtestFixUrl(location).toLatin1().constData(), line); | 0 | ||||||||||||
481 | } else { | - | ||||||||||||
482 | return QTestResult::verify executed 426 times by 2 tests: return QTestResult::verify (success, message.toLatin1().constData(), "", qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 426 | ||||||||||||
483 | (success, message.toLatin1().constData(), "", executed 426 times by 2 tests: return QTestResult::verify (success, message.toLatin1().constData(), "", qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 426 | ||||||||||||
484 | qtestFixUrl(location).toLatin1().constData(), line); executed 426 times by 2 tests: return QTestResult::verify (success, message.toLatin1().constData(), "", qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 426 | ||||||||||||
485 | } | - | ||||||||||||
486 | } | - | ||||||||||||
487 | - | |||||||||||||
488 | bool QuickTestResult::fuzzyCompare(const QVariant &actual, const QVariant &expected, qreal delta) | - | ||||||||||||
489 | { | - | ||||||||||||
490 | if (actual.type() == QVariant::Color || expected.type() == QVariant::Color) {
| 0-66 | ||||||||||||
491 | if (!actual.canConvert(QVariant::Color) || !expected.canConvert(QVariant::Color))
| 0 | ||||||||||||
492 | return false; never executed: return false; | 0 | ||||||||||||
493 | - | |||||||||||||
494 | //fuzzy color comparison | - | ||||||||||||
495 | QColor act; | - | ||||||||||||
496 | QColor exp; | - | ||||||||||||
497 | bool ok(false); | - | ||||||||||||
498 | - | |||||||||||||
499 | QVariant var = QQml_colorProvider()->colorFromString(actual.toString(), &ok); | - | ||||||||||||
500 | if (!ok)
| 0 | ||||||||||||
501 | return false; never executed: return false; | 0 | ||||||||||||
502 | act = var.value<QColor>(); | - | ||||||||||||
503 | - | |||||||||||||
504 | QQml_colorProvider()->colorFromString(expected.toString(), &ok); | - | ||||||||||||
505 | if (!ok)
| 0 | ||||||||||||
506 | return false; never executed: return false; | 0 | ||||||||||||
507 | exp = var.value<QColor>(); | - | ||||||||||||
508 | - | |||||||||||||
509 | return ( qAbs(act.red() - exp.red()) <= delta never executed: return ( qAbs(act.red() - exp.red()) <= delta && qAbs(act.green() - exp.green()) <= delta && qAbs(act.blue() - exp.blue()) <= delta && qAbs(act.alpha() - exp.alpha()) <= delta); | 0 | ||||||||||||
510 | && qAbs(act.green() - exp.green()) <= delta never executed: return ( qAbs(act.red() - exp.red()) <= delta && qAbs(act.green() - exp.green()) <= delta && qAbs(act.blue() - exp.blue()) <= delta && qAbs(act.alpha() - exp.alpha()) <= delta); | 0 | ||||||||||||
511 | && qAbs(act.blue() - exp.blue()) <= delta never executed: return ( qAbs(act.red() - exp.red()) <= delta && qAbs(act.green() - exp.green()) <= delta && qAbs(act.blue() - exp.blue()) <= delta && qAbs(act.alpha() - exp.alpha()) <= delta); | 0 | ||||||||||||
512 | && qAbs(act.alpha() - exp.alpha()) <= delta); never executed: return ( qAbs(act.red() - exp.red()) <= delta && qAbs(act.green() - exp.green()) <= delta && qAbs(act.blue() - exp.blue()) <= delta && qAbs(act.alpha() - exp.alpha()) <= delta); | 0 | ||||||||||||
513 | } else { | - | ||||||||||||
514 | //number comparison | - | ||||||||||||
515 | bool ok = true; | - | ||||||||||||
516 | qreal act = actual.toFloat(&ok); | - | ||||||||||||
517 | if (!ok)
| 0-66 | ||||||||||||
518 | return false; never executed: return false; | 0 | ||||||||||||
519 | - | |||||||||||||
520 | qreal exp = expected.toFloat(&ok); | - | ||||||||||||
521 | if (!ok)
| 0-66 | ||||||||||||
522 | return false; never executed: return false; | 0 | ||||||||||||
523 | - | |||||||||||||
524 | return (qAbs(act - exp) <= delta); executed 66 times by 1 test: return (qAbs(act - exp) <= delta); Executed by:
| 66 | ||||||||||||
525 | } | - | ||||||||||||
526 | - | |||||||||||||
527 | return false; dead code: return false; | - | ||||||||||||
528 | } | - | ||||||||||||
529 | - | |||||||||||||
530 | void QuickTestResult::stringify(QQmlV4Function *args) | - | ||||||||||||
531 | { | - | ||||||||||||
532 | if (args->length() < 1)
| 0-2684 | ||||||||||||
533 | args->setReturnValue(QV4::Encode::null()); never executed: args->setReturnValue(QV4::Encode::null()); | 0 | ||||||||||||
534 | - | |||||||||||||
535 | QV4::Scope scope(args->v4engine()); | - | ||||||||||||
536 | QV4::ScopedValue value(scope, (*args)[0]); | - | ||||||||||||
537 | - | |||||||||||||
538 | QString result; | - | ||||||||||||
539 | - | |||||||||||||
540 | //Check for Object Type | - | ||||||||||||
541 | if (value->isObject()
| 532-2152 | ||||||||||||
542 | && !value->as<QV4::FunctionObject>()
| 0-532 | ||||||||||||
543 | && !value->as<QV4::ArrayObject>()) {
| 4-528 | ||||||||||||
544 | QVariant v = scope.engine->toVariant(value, QMetaType::UnknownType); | - | ||||||||||||
545 | if (v.isValid()) {
| 0-4 | ||||||||||||
546 | switch (v.type()) { | - | ||||||||||||
547 | case QVariant::Vector3D: never executed: case QVariant::Vector3D: | 0 | ||||||||||||
548 | { | - | ||||||||||||
549 | QVector3D v3d = v.value<QVector3D>(); | - | ||||||||||||
550 | result = QString::fromLatin1("Qt.vector3d(%1, %2, %3)").arg(v3d.x()).arg(v3d.y()).arg(v3d.z()); | - | ||||||||||||
551 | break; never executed: break; | 0 | ||||||||||||
552 | } | - | ||||||||||||
553 | case QVariant::Url: never executed: case QVariant::Url: | 0 | ||||||||||||
554 | { | - | ||||||||||||
555 | QUrl url = v.value<QUrl>(); | - | ||||||||||||
556 | result = QString::fromLatin1("Qt.url(%1)").arg(url.toString()); | - | ||||||||||||
557 | break; never executed: break; | 0 | ||||||||||||
558 | } | - | ||||||||||||
559 | case QVariant::DateTime: never executed: case QVariant::DateTime: | 0 | ||||||||||||
560 | { | - | ||||||||||||
561 | QDateTime dt = v.value<QDateTime>(); | - | ||||||||||||
562 | result = dt.toString(Qt::ISODateWithMs); | - | ||||||||||||
563 | break; never executed: break; | 0 | ||||||||||||
564 | } | - | ||||||||||||
565 | default: executed 4 times by 1 test: default: Executed by:
| 4 | ||||||||||||
566 | result = v.toString(); | - | ||||||||||||
567 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||
568 | - | |||||||||||||
569 | } else { | - | ||||||||||||
570 | result = QLatin1String("Object"); | - | ||||||||||||
571 | } never executed: end of block | 0 | ||||||||||||
572 | } | - | ||||||||||||
573 | - | |||||||||||||
574 | if (result.isEmpty()) {
| 4-2680 | ||||||||||||
575 | QString tmp = value->toQStringNoThrow(); | - | ||||||||||||
576 | if (value->as<QV4::ArrayObject>())
| 528-2152 | ||||||||||||
577 | result += QLatin1Char('[') + tmp + QLatin1Char(']'); executed 528 times by 1 test: result += QLatin1Char('[') + tmp + QLatin1Char(']'); Executed by:
| 528 | ||||||||||||
578 | else | - | ||||||||||||
579 | result.append(tmp); executed 2152 times by 2 tests: result.append(tmp); Executed by:
| 2152 | ||||||||||||
580 | } | - | ||||||||||||
581 | - | |||||||||||||
582 | args->setReturnValue(QV4::Encode(args->v4engine()->newString(result))); | - | ||||||||||||
583 | } executed 2684 times by 2 tests: end of block Executed by:
| 2684 | ||||||||||||
584 | - | |||||||||||||
585 | bool QuickTestResult::compare | - | ||||||||||||
586 | (bool success, const QString &message, | - | ||||||||||||
587 | const QVariant &val1, const QVariant &val2, | - | ||||||||||||
588 | const QUrl &location, int line) | - | ||||||||||||
589 | { | - | ||||||||||||
590 | return QTestResult::compare executed 1408 times by 2 tests: return QTestResult::compare (success, message.toLocal8Bit().constData(), QTest::toString(val1.toString().toLatin1().constData()), QTest::toString(val2.toString().toLatin1().constData()), "", "", qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 1408 | ||||||||||||
591 | (success, message.toLocal8Bit().constData(), executed 1408 times by 2 tests: return QTestResult::compare (success, message.toLocal8Bit().constData(), QTest::toString(val1.toString().toLatin1().constData()), QTest::toString(val2.toString().toLatin1().constData()), "", "", qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 1408 | ||||||||||||
592 | QTest::toString(val1.toString().toLatin1().constData()), executed 1408 times by 2 tests: return QTestResult::compare (success, message.toLocal8Bit().constData(), QTest::toString(val1.toString().toLatin1().constData()), QTest::toString(val2.toString().toLatin1().constData()), "", "", qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 1408 | ||||||||||||
593 | QTest::toString(val2.toString().toLatin1().constData()), executed 1408 times by 2 tests: return QTestResult::compare (success, message.toLocal8Bit().constData(), QTest::toString(val1.toString().toLatin1().constData()), QTest::toString(val2.toString().toLatin1().constData()), "", "", qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 1408 | ||||||||||||
594 | "", "", executed 1408 times by 2 tests: return QTestResult::compare (success, message.toLocal8Bit().constData(), QTest::toString(val1.toString().toLatin1().constData()), QTest::toString(val2.toString().toLatin1().constData()), "", "", qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 1408 | ||||||||||||
595 | qtestFixUrl(location).toLatin1().constData(), line); executed 1408 times by 2 tests: return QTestResult::compare (success, message.toLocal8Bit().constData(), QTest::toString(val1.toString().toLatin1().constData()), QTest::toString(val2.toString().toLatin1().constData()), "", "", qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 1408 | ||||||||||||
596 | } | - | ||||||||||||
597 | - | |||||||||||||
598 | void QuickTestResult::skip | - | ||||||||||||
599 | (const QString &message, const QUrl &location, int line) | - | ||||||||||||
600 | { | - | ||||||||||||
601 | QTestResult::addSkip(message.toLatin1().constData(), | - | ||||||||||||
602 | qtestFixUrl(location).toLatin1().constData(), line); | - | ||||||||||||
603 | QTestResult::setSkipCurrentTest(true); | - | ||||||||||||
604 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||
605 | - | |||||||||||||
606 | bool QuickTestResult::expectFail | - | ||||||||||||
607 | (const QString &tag, const QString &comment, const QUrl &location, int line) | - | ||||||||||||
608 | { | - | ||||||||||||
609 | return QTestResult::expectFail executed 4 times by 1 test: return QTestResult::expectFail (tag.toLatin1().constData(), QTest::toString(comment.toLatin1().constData()), QTest::Abort, qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 4 | ||||||||||||
610 | (tag.toLatin1().constData(), executed 4 times by 1 test: return QTestResult::expectFail (tag.toLatin1().constData(), QTest::toString(comment.toLatin1().constData()), QTest::Abort, qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 4 | ||||||||||||
611 | QTest::toString(comment.toLatin1().constData()), executed 4 times by 1 test: return QTestResult::expectFail (tag.toLatin1().constData(), QTest::toString(comment.toLatin1().constData()), QTest::Abort, qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 4 | ||||||||||||
612 | QTest::Abort, qtestFixUrl(location).toLatin1().constData(), line); executed 4 times by 1 test: return QTestResult::expectFail (tag.toLatin1().constData(), QTest::toString(comment.toLatin1().constData()), QTest::Abort, qtestFixUrl(location).toLatin1().constData(), line); Executed by:
| 4 | ||||||||||||
613 | } | - | ||||||||||||
614 | - | |||||||||||||
615 | bool QuickTestResult::expectFailContinue | - | ||||||||||||
616 | (const QString &tag, const QString &comment, const QUrl &location, int line) | - | ||||||||||||
617 | { | - | ||||||||||||
618 | return QTestResult::expectFail never executed: return QTestResult::expectFail (tag.toLatin1().constData(), QTest::toString(comment.toLatin1().constData()), QTest::Continue, qtestFixUrl(location).toLatin1().constData(), line); | 0 | ||||||||||||
619 | (tag.toLatin1().constData(), never executed: return QTestResult::expectFail (tag.toLatin1().constData(), QTest::toString(comment.toLatin1().constData()), QTest::Continue, qtestFixUrl(location).toLatin1().constData(), line); | 0 | ||||||||||||
620 | QTest::toString(comment.toLatin1().constData()), never executed: return QTestResult::expectFail (tag.toLatin1().constData(), QTest::toString(comment.toLatin1().constData()), QTest::Continue, qtestFixUrl(location).toLatin1().constData(), line); | 0 | ||||||||||||
621 | QTest::Continue, qtestFixUrl(location).toLatin1().constData(), line); never executed: return QTestResult::expectFail (tag.toLatin1().constData(), QTest::toString(comment.toLatin1().constData()), QTest::Continue, qtestFixUrl(location).toLatin1().constData(), line); | 0 | ||||||||||||
622 | } | - | ||||||||||||
623 | - | |||||||||||||
624 | void QuickTestResult::warn(const QString &message, const QUrl &location, int line) | - | ||||||||||||
625 | { | - | ||||||||||||
626 | QTestLog::warn(message.toLatin1().constData(), qtestFixUrl(location).toLatin1().constData(), line); | - | ||||||||||||
627 | } never executed: end of block | 0 | ||||||||||||
628 | - | |||||||||||||
629 | void QuickTestResult::ignoreWarning(const QJSValue &message) | - | ||||||||||||
630 | { | - | ||||||||||||
631 | if (message.isRegExp()) {
| 0-16 | ||||||||||||
632 | // ### we should probably handle QRegularExpression conversion engine-side | - | ||||||||||||
633 | QRegExp re = message.toVariant().toRegExp(); | - | ||||||||||||
634 | QRegularExpression::PatternOptions opts = re.caseSensitivity() ==
| 0 | ||||||||||||
635 | Qt::CaseInsensitive ? QRegularExpression::CaseInsensitiveOption : QRegularExpression::NoPatternOption;
| 0 | ||||||||||||
636 | QRegularExpression re2(re.pattern(), opts); | - | ||||||||||||
637 | QTestLog::ignoreMessage(QtWarningMsg, re2); | - | ||||||||||||
638 | } else { never executed: end of block | 0 | ||||||||||||
639 | QTestLog::ignoreMessage(QtWarningMsg, message.toString().toLatin1()); | - | ||||||||||||
640 | } executed 16 times by 1 test: end of block Executed by:
| 16 | ||||||||||||
641 | } | - | ||||||||||||
642 | - | |||||||||||||
643 | void QuickTestResult::wait(int ms) | - | ||||||||||||
644 | { | - | ||||||||||||
645 | QTest::qWait(ms); | - | ||||||||||||
646 | } executed 396 times by 3 tests: end of block Executed by:
| 396 | ||||||||||||
647 | - | |||||||||||||
648 | void QuickTestResult::sleep(int ms) | - | ||||||||||||
649 | { | - | ||||||||||||
650 | QTest::qSleep(ms); | - | ||||||||||||
651 | } never executed: end of block | 0 | ||||||||||||
652 | - | |||||||||||||
653 | bool QuickTestResult::waitForRendering(QQuickItem *item, int timeout) | - | ||||||||||||
654 | { | - | ||||||||||||
655 | Q_ASSERT(item); | - | ||||||||||||
656 | - | |||||||||||||
657 | return qWaitForSignal(item->window(), SIGNAL(frameSwapped()), timeout); executed 56 times by 1 test: return qWaitForSignal(item->window(), qFlagLocation("2""frameSwapped()" "\0" __FILE__ ":" "657"), timeout); Executed by:
| 56 | ||||||||||||
658 | } | - | ||||||||||||
659 | - | |||||||||||||
660 | void QuickTestResult::startMeasurement() | - | ||||||||||||
661 | { | - | ||||||||||||
662 | Q_D(QuickTestResult); | - | ||||||||||||
663 | delete d->benchmarkData; | - | ||||||||||||
664 | d->benchmarkData = new QBenchmarkTestMethodData(); | - | ||||||||||||
665 | QBenchmarkTestMethodData::current = d->benchmarkData; | - | ||||||||||||
666 | d->iterCount = (QBenchmarkGlobalData::current->measurer->needsWarmupIteration()) ? -1 : 0;
| 0 | ||||||||||||
667 | d->results.clear(); | - | ||||||||||||
668 | } never executed: end of block | 0 | ||||||||||||
669 | - | |||||||||||||
670 | void QuickTestResult::beginDataRun() | - | ||||||||||||
671 | { | - | ||||||||||||
672 | QBenchmarkTestMethodData::current->beginDataRun(); | - | ||||||||||||
673 | } never executed: end of block | 0 | ||||||||||||
674 | - | |||||||||||||
675 | void QuickTestResult::endDataRun() | - | ||||||||||||
676 | { | - | ||||||||||||
677 | Q_D(QuickTestResult); | - | ||||||||||||
678 | QBenchmarkTestMethodData::current->endDataRun(); | - | ||||||||||||
679 | if (d->iterCount > -1) // iteration -1 is the warmup iteration.
| 0 | ||||||||||||
680 | d->results.append(QBenchmarkTestMethodData::current->result); never executed: d->results.append(QBenchmarkTestMethodData::current->result); | 0 | ||||||||||||
681 | - | |||||||||||||
682 | if (QBenchmarkGlobalData::current->verboseOutput) {
| 0 | ||||||||||||
683 | if (d->iterCount == -1) {
| 0 | ||||||||||||
684 | qDebug() << "warmup stage result :" << QBenchmarkTestMethodData::current->result.value; | - | ||||||||||||
685 | } else { never executed: end of block | 0 | ||||||||||||
686 | qDebug() << "accumulation stage result:" << QBenchmarkTestMethodData::current->result.value; | - | ||||||||||||
687 | } never executed: end of block | 0 | ||||||||||||
688 | } | - | ||||||||||||
689 | } never executed: end of block | 0 | ||||||||||||
690 | - | |||||||||||||
691 | bool QuickTestResult::measurementAccepted() | - | ||||||||||||
692 | { | - | ||||||||||||
693 | return QBenchmarkTestMethodData::current->resultsAccepted(); never executed: return QBenchmarkTestMethodData::current->resultsAccepted(); | 0 | ||||||||||||
694 | } | - | ||||||||||||
695 | - | |||||||||||||
696 | static QBenchmarkResult qMedian(const QList<QBenchmarkResult> &container) | - | ||||||||||||
697 | { | - | ||||||||||||
698 | const int count = container.count(); | - | ||||||||||||
699 | if (count == 0)
| 0 | ||||||||||||
700 | return QBenchmarkResult(); never executed: return QBenchmarkResult(); | 0 | ||||||||||||
701 | - | |||||||||||||
702 | if (count == 1)
| 0 | ||||||||||||
703 | return container.at(0); never executed: return container.at(0); | 0 | ||||||||||||
704 | - | |||||||||||||
705 | QList<QBenchmarkResult> containerCopy = container; | - | ||||||||||||
706 | std::sort(containerCopy.begin(), containerCopy.end()); | - | ||||||||||||
707 | - | |||||||||||||
708 | const int middle = count / 2; | - | ||||||||||||
709 | - | |||||||||||||
710 | // ### handle even-sized containers here by doing an aritmetic mean of the two middle items. | - | ||||||||||||
711 | return containerCopy.at(middle); never executed: return containerCopy.at(middle); | 0 | ||||||||||||
712 | } | - | ||||||||||||
713 | - | |||||||||||||
714 | bool QuickTestResult::needsMoreMeasurements() | - | ||||||||||||
715 | { | - | ||||||||||||
716 | Q_D(QuickTestResult); | - | ||||||||||||
717 | ++(d->iterCount); | - | ||||||||||||
718 | if (d->iterCount < QBenchmarkGlobalData::current->adjustMedianIterationCount())
| 0 | ||||||||||||
719 | return true; never executed: return true; | 0 | ||||||||||||
720 | if (QBenchmarkTestMethodData::current->resultsAccepted())
| 0 | ||||||||||||
721 | QTestLog::addBenchmarkResult(qMedian(d->results)); never executed: QTestLog::addBenchmarkResult(qMedian(d->results)); | 0 | ||||||||||||
722 | return false; never executed: return false; | 0 | ||||||||||||
723 | } | - | ||||||||||||
724 | - | |||||||||||||
725 | void QuickTestResult::startBenchmark(RunMode runMode, const QString &tag) | - | ||||||||||||
726 | { | - | ||||||||||||
727 | QBenchmarkTestMethodData::current->result = QBenchmarkResult(); | - | ||||||||||||
728 | QBenchmarkTestMethodData::current->resultAccepted = false; | - | ||||||||||||
729 | QBenchmarkGlobalData::current->context.tag = tag; | - | ||||||||||||
730 | QBenchmarkGlobalData::current->context.slotName = functionName(); | - | ||||||||||||
731 | - | |||||||||||||
732 | Q_D(QuickTestResult); | - | ||||||||||||
733 | delete d->benchmarkIter; | - | ||||||||||||
734 | d->benchmarkIter = new QTest::QBenchmarkIterationController | - | ||||||||||||
735 | (QTest::QBenchmarkIterationController::RunMode(runMode)); | - | ||||||||||||
736 | } never executed: end of block | 0 | ||||||||||||
737 | - | |||||||||||||
738 | bool QuickTestResult::isBenchmarkDone() const | - | ||||||||||||
739 | { | - | ||||||||||||
740 | Q_D(const QuickTestResult); | - | ||||||||||||
741 | if (d->benchmarkIter)
| 0 | ||||||||||||
742 | return d->benchmarkIter->isDone(); never executed: return d->benchmarkIter->isDone(); | 0 | ||||||||||||
743 | else | - | ||||||||||||
744 | return true; never executed: return true; | 0 | ||||||||||||
745 | } | - | ||||||||||||
746 | - | |||||||||||||
747 | void QuickTestResult::nextBenchmark() | - | ||||||||||||
748 | { | - | ||||||||||||
749 | Q_D(QuickTestResult); | - | ||||||||||||
750 | if (d->benchmarkIter)
| 0 | ||||||||||||
751 | d->benchmarkIter->next(); never executed: d->benchmarkIter->next(); | 0 | ||||||||||||
752 | } never executed: end of block | 0 | ||||||||||||
753 | - | |||||||||||||
754 | void QuickTestResult::stopBenchmark() | - | ||||||||||||
755 | { | - | ||||||||||||
756 | Q_D(QuickTestResult); | - | ||||||||||||
757 | delete d->benchmarkIter; | - | ||||||||||||
758 | d->benchmarkIter = nullptr; | - | ||||||||||||
759 | } never executed: end of block | 0 | ||||||||||||
760 | - | |||||||||||||
761 | QObject *QuickTestResult::grabImage(QQuickItem *item) | - | ||||||||||||
762 | { | - | ||||||||||||
763 | if (item && item->window()) {
| 0 | ||||||||||||
764 | QQuickWindow *window = item->window(); | - | ||||||||||||
765 | QImage grabbed = window->grabWindow(); | - | ||||||||||||
766 | QRectF rf(item->x(), item->y(), item->width(), item->height()); | - | ||||||||||||
767 | rf = rf.intersected(QRectF(0, 0, grabbed.width(), grabbed.height())); | - | ||||||||||||
768 | QObject *o = new QuickTestImageObject(grabbed.copy(rf.toAlignedRect())); | - | ||||||||||||
769 | QQmlEngine::setContextForObject(o, qmlContext(this)); | - | ||||||||||||
770 | return o; never executed: return o; | 0 | ||||||||||||
771 | } | - | ||||||||||||
772 | return nullptr; never executed: return nullptr; | 0 | ||||||||||||
773 | } | - | ||||||||||||
774 | - | |||||||||||||
775 | QObject *QuickTestResult::findChild(QObject *parent, const QString &objectName) | - | ||||||||||||
776 | { | - | ||||||||||||
777 | return parent ? parent->findChild<QObject*>(objectName) : 0; never executed: return parent ? parent->findChild<QObject*>(objectName) : 0; | 0 | ||||||||||||
778 | } | - | ||||||||||||
779 | - | |||||||||||||
780 | namespace QTest { | - | ||||||||||||
781 | void qtest_qParseArgs(int argc, char *argv[], bool qml); | - | ||||||||||||
782 | }; | - | ||||||||||||
783 | - | |||||||||||||
784 | void QuickTestResult::parseArgs(int argc, char *argv[]) | - | ||||||||||||
785 | { | - | ||||||||||||
786 | if (!QBenchmarkGlobalData::current)
| 0-18 | ||||||||||||
787 | QBenchmarkGlobalData::current = &globalBenchmarkData; executed 18 times by 4 tests: QBenchmarkGlobalData::current = &globalBenchmarkData; Executed by:
| 18 | ||||||||||||
788 | QTest::qtest_qParseArgs(argc, argv, true); | - | ||||||||||||
789 | } executed 18 times by 4 tests: end of block Executed by:
| 18 | ||||||||||||
790 | - | |||||||||||||
791 | void QuickTestResult::setProgramName(const char *name) | - | ||||||||||||
792 | { | - | ||||||||||||
793 | if (name) {
| 18 | ||||||||||||
794 | QTestPrivate::parseBlackList(); | - | ||||||||||||
795 | QTestPrivate::parseGpuBlackList(); | - | ||||||||||||
796 | QTestResult::reset(); | - | ||||||||||||
797 | } else if (!name && loggingStarted) { executed 18 times by 4 tests: end of block Executed by:
| 0-18 | ||||||||||||
798 | QTestResult::setCurrentTestObject(globalProgramName); | - | ||||||||||||
799 | QTestLog::stopLogging(); | - | ||||||||||||
800 | QTestResult::setCurrentTestObject(nullptr); | - | ||||||||||||
801 | } executed 16 times by 4 tests: end of block Executed by:
| 16 | ||||||||||||
802 | globalProgramName = name; | - | ||||||||||||
803 | QTestResult::setCurrentTestObject(globalProgramName); | - | ||||||||||||
804 | } executed 36 times by 4 tests: end of block Executed by:
| 36 | ||||||||||||
805 | - | |||||||||||||
806 | void QuickTestResult::setCurrentAppname(const char *appname) | - | ||||||||||||
807 | { | - | ||||||||||||
808 | QTestResult::setCurrentAppName(appname); | - | ||||||||||||
809 | } executed 18 times by 4 tests: end of block Executed by:
| 18 | ||||||||||||
810 | - | |||||||||||||
811 | int QuickTestResult::exitCode() | - | ||||||||||||
812 | { | - | ||||||||||||
813 | #if defined(QTEST_NOEXITCODE) | - | ||||||||||||
814 | return 0; | - | ||||||||||||
815 | #else | - | ||||||||||||
816 | // make sure our exit code is never going above 127 | - | ||||||||||||
817 | // since that could wrap and indicate 0 test fails | - | ||||||||||||
818 | return qMin(QTestLog::failCount(), 127); executed 14 times by 4 tests: return qMin(QTestLog::failCount(), 127); Executed by:
| 14 | ||||||||||||
819 | #endif | - | ||||||||||||
820 | } | - | ||||||||||||
821 | - | |||||||||||||
822 | #include "quicktestresult.moc" | - | ||||||||||||
823 | #include "moc_quicktestresult_p.cpp" | - | ||||||||||||
824 | - | |||||||||||||
825 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |