1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
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 The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
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 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QUICKTESTRESULT_P_H
41#define QUICKTESTRESULT_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtQuickTest/quicktestglobal.h>
55#include <QtCore/qobject.h>
56#include <QtCore/qstring.h>
57#include <QtCore/qstringlist.h>
58#include <QtCore/qscopedpointer.h>
59#include <QtQuick/qquickitem.h>
60
61QT_BEGIN_NAMESPACE
62
63class QUrl;
64class QuickTestResultPrivate;
65
66class Q_QUICK_TEST_EXPORT QuickTestResult : public QObject
67{
68 Q_OBJECT
69 Q_PROPERTY(QString testCaseName READ testCaseName WRITE setTestCaseName NOTIFY testCaseNameChanged)
70 Q_PROPERTY(QString functionName READ functionName WRITE setFunctionName NOTIFY functionNameChanged)
71 Q_PROPERTY(QString dataTag READ dataTag WRITE setDataTag NOTIFY dataTagChanged)
72 Q_PROPERTY(bool failed READ isFailed)
73 Q_PROPERTY(bool skipped READ isSkipped WRITE setSkipped NOTIFY skippedChanged)
74 Q_PROPERTY(int passCount READ passCount)
75 Q_PROPERTY(int failCount READ failCount)
76 Q_PROPERTY(int skipCount READ skipCount)
77 Q_PROPERTY(QStringList functionsToRun READ functionsToRun)
78 Q_PROPERTY(QStringList tagsToRun READ tagsToRun)
79
80public:
81 QuickTestResult(QObject *parent = nullptr);
82 ~QuickTestResult() override;
83
84 // Values must match QBenchmarkIterationController::RunMode.
85 enum RunMode
86 {
87 RepeatUntilValidMeasurement,
88 RunOnce
89 };
90 Q_ENUM(RunMode)
91
92 QString testCaseName() const;
93 void setTestCaseName(const QString &name);
94
95 QString functionName() const;
96 void setFunctionName(const QString &name);
97
98 QString dataTag() const;
99 void setDataTag(const QString &tag);
100
101 bool isFailed() const;
102
103 bool isSkipped() const;
104 void setSkipped(bool skip);
105
106 int passCount() const;
107 int failCount() const;
108 int skipCount() const;
109
110 QStringList functionsToRun() const;
111 QStringList tagsToRun() const;
112
113public Q_SLOTS:
114 void reset();
115
116 void startLogging();
117 void stopLogging();
118
119 void initTestTable();
120 void clearTestTable();
121
122 void finishTestData();
123 void finishTestDataCleanup();
124 void finishTestFunction();
125
126 void stringify(QQmlV4Function *args);
127
128 void fail(const QString &message, const QUrl &location, int line);
129 bool verify(bool success, const QString &message,
130 const QUrl &location, int line);
131 bool compare(bool success, const QString &message,
132 const QVariant &val1, const QVariant &val2,
133 const QUrl &location, int line);
134 bool fuzzyCompare(const QVariant &actual, const QVariant &expected, qreal delta);
135 void skip(const QString &message, const QUrl &location, int line);
136 bool expectFail(const QString &tag, const QString &comment,
137 const QUrl &location, int line);
138 bool expectFailContinue(const QString &tag, const QString &comment,
139 const QUrl &location, int line);
140 void warn(const QString &message, const QUrl &location, int line);
141
142 void ignoreWarning(const QJSValue &message);
143
144 void wait(int ms);
145 void sleep(int ms);
146 bool waitForRendering(QQuickItem *item, int timeout = 5000);
147
148 void startMeasurement();
149 void beginDataRun();
150 void endDataRun();
151 bool measurementAccepted();
152 bool needsMoreMeasurements();
153
154 void startBenchmark(RunMode runMode, const QString &tag);
155 bool isBenchmarkDone() const;
156 void nextBenchmark();
157 void stopBenchmark();
158
159 QObject *grabImage(QQuickItem *item);
160
161 Q_REVISION(1) QObject *findChild(QObject *parent, const QString &objectName);
162
163 Q_REVISION(13) bool isPolishScheduled(QQuickItem *item) const;
164 Q_REVISION(13) bool waitForItemPolished(QQuickItem *item, int timeout);
165
166public:
167 // Helper functions for the C++ main() shell.
168 static void parseArgs(int argc, char *argv[]);
169 static void setProgramName(const char *name);
170 static void setCurrentAppname(const char *appname);
171 static int exitCode();
172
173Q_SIGNALS:
174 void programNameChanged();
175 void testCaseNameChanged();
176 void functionNameChanged();
177 void dataTagChanged();
178 void skippedChanged();
179
180private:
181 QScopedPointer<QuickTestResultPrivate> d_ptr;
182
183 Q_DECLARE_PRIVATE(QuickTestResult)
184 Q_DISABLE_COPY(QuickTestResult)
185};
186
187QT_END_NAMESPACE
188
189#endif
190

source code of qtdeclarative/src/qmltest/quicktestresult_p.h