1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QUICKTESTRESULT_P_H
5#define QUICKTESTRESULT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuickTest/private/quicktestglobal_p.h>
19#include <QtCore/qobject.h>
20#include <QtCore/qstring.h>
21#include <QtCore/qstringlist.h>
22#include <QtCore/qscopedpointer.h>
23#include <QtQuick/qquickitem.h>
24#include <QtQuick/qquickwindow.h>
25
26QT_BEGIN_NAMESPACE
27
28class QUrl;
29class QuickTestResultPrivate;
30
31class Q_QUICK_TEST_PRIVATE_EXPORT QuickTestResult : public QObject
32{
33 Q_OBJECT
34 Q_PROPERTY(QString testCaseName READ testCaseName WRITE setTestCaseName NOTIFY testCaseNameChanged)
35 Q_PROPERTY(QString functionName READ functionName WRITE setFunctionName NOTIFY functionNameChanged)
36 Q_PROPERTY(QString dataTag READ dataTag WRITE setDataTag NOTIFY dataTagChanged)
37 Q_PROPERTY(bool failed READ isFailed)
38 Q_PROPERTY(bool skipped READ isSkipped WRITE setSkipped NOTIFY skippedChanged)
39 Q_PROPERTY(int passCount READ passCount)
40 Q_PROPERTY(int failCount READ failCount)
41 Q_PROPERTY(int skipCount READ skipCount)
42 Q_PROPERTY(QStringList functionsToRun READ functionsToRun)
43 Q_PROPERTY(QStringList tagsToRun READ tagsToRun)
44
45 QML_NAMED_ELEMENT(TestResult)
46 QML_ADDED_IN_VERSION(1, 0)
47
48public:
49 QuickTestResult(QObject *parent = nullptr);
50 ~QuickTestResult() override;
51
52 // Values must match QBenchmarkIterationController::RunMode.
53 enum RunMode
54 {
55 RepeatUntilValidMeasurement,
56 RunOnce
57 };
58 Q_ENUM(RunMode)
59
60 QString testCaseName() const;
61 void setTestCaseName(const QString &name);
62
63 QString functionName() const;
64 void setFunctionName(const QString &name);
65
66 QString dataTag() const;
67 void setDataTag(const QString &tag);
68
69 bool isFailed() const;
70
71 bool isSkipped() const;
72 void setSkipped(bool skip);
73
74 int passCount() const;
75 int failCount() const;
76 int skipCount() const;
77
78 QStringList functionsToRun() const;
79 QStringList tagsToRun() const;
80
81public Q_SLOTS:
82 void reset();
83
84 void startLogging();
85 void stopLogging();
86
87 void initTestTable();
88 void clearTestTable();
89
90 void finishTestData();
91 void finishTestDataCleanup();
92 void finishTestFunction();
93
94 void stringify(QQmlV4Function *args);
95
96 void fail(const QString &message, const QUrl &location, int line);
97 bool verify(bool success, const QString &message,
98 const QUrl &location, int line);
99 bool compare(bool success, const QString &message,
100 const QVariant &val1, const QVariant &val2,
101 const QUrl &location, int line);
102 bool fuzzyCompare(const QVariant &actual, const QVariant &expected, qreal delta);
103 void skip(const QString &message, const QUrl &location, int line);
104 bool expectFail(const QString &tag, const QString &comment,
105 const QUrl &location, int line);
106 bool expectFailContinue(const QString &tag, const QString &comment,
107 const QUrl &location, int line);
108 void warn(const QString &message, const QUrl &location, int line);
109
110 void ignoreWarning(const QJSValue &message);
111 Q_REVISION(6, 3) void failOnWarning(const QJSValue &message);
112
113 void wait(int ms);
114 void sleep(int ms);
115 bool waitForRendering(QQuickItem *item, int timeout = 5000);
116
117 void startMeasurement();
118 void beginDataRun();
119 void endDataRun();
120 bool measurementAccepted();
121 bool needsMoreMeasurements();
122
123 void startBenchmark(RunMode runMode, const QString &tag);
124 bool isBenchmarkDone() const;
125 void nextBenchmark();
126 void stopBenchmark();
127
128 QObject *grabImage(QQuickItem *item);
129
130 Q_REVISION(1, 1) QObject *findChild(QObject *parent, const QString &objectName);
131
132 Q_REVISION(1, 13) bool isPolishScheduled(QObject *itemOrWindow) const;
133 Q_REVISION(6, 5) bool waitForPolish(QObject *itemOrWindow, int timeout) const;
134
135public:
136 // Helper functions for the C++ main() shell.
137 static void parseArgs(int argc, char *argv[]);
138 static void setProgramName(const char *name);
139 static void setCurrentAppname(const char *appname);
140 static int exitCode();
141
142Q_SIGNALS:
143 void programNameChanged();
144 void testCaseNameChanged();
145 void functionNameChanged();
146 void dataTagChanged();
147 void skippedChanged();
148
149private:
150 QScopedPointer<QuickTestResultPrivate> d_ptr;
151
152 Q_DECLARE_PRIVATE(QuickTestResult)
153 Q_DISABLE_COPY(QuickTestResult)
154};
155
156QT_END_NAMESPACE
157
158#endif
159

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