Doc: Enabling Qt QML linking to Qt Quick.
[profile/ivi/qtdeclarative.git] / src / qmltest / quicktestresult_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QUICKTESTRESULT_P_H
43 #define QUICKTESTRESULT_P_H
44
45 #include <QtQuickTest/quicktestglobal.h>
46 #include <QtCore/qobject.h>
47 #include <QtCore/qstring.h>
48 #include <QtCore/qstringlist.h>
49 #include <QtCore/qscopedpointer.h>
50 #include <QtQuick/qquickitem.h>
51 #include <QtQml/private/qv8engine_p.h>
52
53 QT_BEGIN_NAMESPACE
54
55 class QUrl;
56 class QuickTestResultPrivate;
57
58 class Q_QUICK_TEST_EXPORT QuickTestResult : public QObject
59 {
60     Q_OBJECT
61     Q_ENUMS(RunMode)
62     Q_PROPERTY(QString testCaseName READ testCaseName WRITE setTestCaseName NOTIFY testCaseNameChanged)
63     Q_PROPERTY(QString functionName READ functionName WRITE setFunctionName NOTIFY functionNameChanged)
64     Q_PROPERTY(QString dataTag READ dataTag WRITE setDataTag NOTIFY dataTagChanged)
65     Q_PROPERTY(bool failed READ isFailed)
66     Q_PROPERTY(bool skipped READ isSkipped WRITE setSkipped NOTIFY skippedChanged)
67     Q_PROPERTY(int passCount READ passCount)
68     Q_PROPERTY(int failCount READ failCount)
69     Q_PROPERTY(int skipCount READ skipCount)
70     Q_PROPERTY(QStringList functionsToRun READ functionsToRun)
71 public:
72     QuickTestResult(QObject *parent = 0);
73     ~QuickTestResult();
74
75     // Values must match QBenchmarkIterationController::RunMode.
76     enum RunMode
77     {
78         RepeatUntilValidMeasurement,
79         RunOnce
80     };
81
82     QString testCaseName() const;
83     void setTestCaseName(const QString &name);
84
85     QString functionName() const;
86     void setFunctionName(const QString &name);
87
88     QString dataTag() const;
89     void setDataTag(const QString &tag);
90
91     bool isFailed() const;
92
93     bool isSkipped() const;
94     void setSkipped(bool skip);
95
96     int passCount() const;
97     int failCount() const;
98     int skipCount() const;
99
100     QStringList functionsToRun() const;
101
102 public Q_SLOTS:
103     void reset();
104
105     void startLogging();
106     void stopLogging();
107
108     void initTestTable();
109     void clearTestTable();
110
111     void finishTestData();
112     void finishTestDataCleanup();
113     void finishTestFunction();
114
115     void stringify(QQmlV8Function *args);
116
117     void fail(const QString &message, const QUrl &location, int line);
118     bool verify(bool success, const QString &message,
119                 const QUrl &location, int line);
120     bool compare(bool success, const QString &message,
121                  const QVariant &val1, const QVariant &val2,
122                  const QUrl &location, int line);
123     bool fuzzyCompare(const QVariant &actual, const QVariant &expected, qreal delta);
124     void skip(const QString &message, const QUrl &location, int line);
125     bool expectFail(const QString &tag, const QString &comment,
126                     const QUrl &location, int line);
127     bool expectFailContinue(const QString &tag, const QString &comment,
128                             const QUrl &location, int line);
129     void warn(const QString &message, const QUrl &location, int line);
130
131     void ignoreWarning(const QString &message);
132
133     void wait(int ms);
134     void sleep(int ms);
135     bool waitForRendering(QQuickItem *item, int timeout = 5000);
136
137     void startMeasurement();
138     void beginDataRun();
139     void endDataRun();
140     bool measurementAccepted();
141     bool needsMoreMeasurements();
142
143     void startBenchmark(RunMode runMode, const QString &tag);
144     bool isBenchmarkDone() const;
145     void nextBenchmark();
146     void stopBenchmark();
147
148     QObject *grabImage(QQuickItem *item);
149
150 public:
151     // Helper functions for the C++ main() shell.
152     static void parseArgs(int argc, char *argv[]);
153     static void setProgramName(const char *name);
154     static void setCurrentAppname(const char *appname);
155     static int exitCode();
156
157 Q_SIGNALS:
158     void programNameChanged();
159     void testCaseNameChanged();
160     void functionNameChanged();
161     void dataTagChanged();
162     void skippedChanged();
163
164 private:
165     QScopedPointer<QuickTestResultPrivate> d_ptr;
166
167     Q_DECLARE_PRIVATE(QuickTestResult)
168     Q_DISABLE_COPY(QuickTestResult)
169 };
170
171 QT_END_NAMESPACE
172
173 #endif