Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
quicktest_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 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// Qt-Security score:significant reason:default
4
5#ifndef QUICKTEST_P_H
6#define QUICKTEST_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuickTest/private/quicktestglobal_p.h>
20#include <QtQuickTest/quicktest.h>
21
22#include <QtQml/qqmlpropertymap.h>
23#include <QtQml/qqml.h>
24
25#include <QtCore/qpointer.h>
26
28
29class Q_QMLTEST_EXPORT QTestRootObject : public QObject
30{
31 Q_OBJECT
32 Q_PROPERTY(bool windowShown READ windowShown NOTIFY windowShownChanged)
33 Q_PROPERTY(bool hasTestCase READ hasTestCase WRITE setHasTestCase NOTIFY hasTestCaseChanged)
34 Q_PROPERTY(QObject *defined READ defined)
35
36 QML_SINGLETON
37 QML_ELEMENT
38 QML_ADDED_IN_VERSION(1, 0)
39
40public:
41 static QTestRootObject *create(QQmlEngine *q, QJSEngine *)
42 {
43 QTestRootObject *result = instance();
44 QQmlEngine *engine = qmlEngine(result);
45 // You can only test on one engine at a time
46 return (engine == nullptr || engine == q) ? result : nullptr;
47 }
48
49 static QTestRootObject *instance() {
50 static QPointer<QTestRootObject> object = new QTestRootObject;
51 if (!object) {
52 // QTestRootObject was deleted when previous test ended, create a new one
53 object = new QTestRootObject;
54 }
55 return object;
56 }
57
58 bool hasQuit:1;
59 bool hasTestCase() const { return m_hasTestCase; }
60 void setHasTestCase(bool value) { m_hasTestCase = value; Q_EMIT hasTestCaseChanged(); }
61
62 bool windowShown() const { return m_windowShown; }
63 void setWindowShown(bool value) { m_windowShown = value; Q_EMIT windowShownChanged(); }
64 QQmlPropertyMap *defined() const { return m_defined; }
65
66 void init() { setWindowShown(false); setHasTestCase(false); hasQuit = false; }
67
68Q_SIGNALS:
69 void windowShownChanged();
70 void hasTestCaseChanged();
71
72private Q_SLOTS:
73 void quit() { hasQuit = true; }
74
75private:
76 QTestRootObject(QObject *parent = nullptr)
77 : QObject(parent), hasQuit(false), m_windowShown(false), m_hasTestCase(false) {
78 m_defined = QQmlPropertyMap::create(this);
79#if defined(QT_OPENGL_ES_2_ANGLE)
80 m_defined->insert(QLatin1String("QT_OPENGL_ES_2_ANGLE"), QVariant(true));
81#endif
82 }
83
84 bool m_windowShown : 1;
85 bool m_hasTestCase :1;
86 QQmlPropertyMap *m_defined;
87};
88
89bool qWaitForSignal(QObject *obj, const char* signal, int timeout = 5000);
90
91QT_END_NAMESPACE
92
93#endif // QUICKTEST_P_H
QList< QString > TestCaseList
QList< QQmlError > errors() const
TestCaseList testCases() const
TestCaseCollector(const QFileInfo &fileInfo, QQmlEngine *engine)
bool qWaitForSignal(QObject *obj, const char *signal, int timeout)
static QString stripQuotes(const QString &s)
int quick_test_main(int argc, char **argv, const char *name, const char *sourceDir)
static void handleCompileErrors(const QFileInfo &fi, const QList< QQmlError > &errors, QQmlEngine *engine, QQuickView *view=nullptr)
void maybeInvokeSetupMethod(QObject *setupObject, const char *member, Args &&... args)
int quick_test_main_with_setup(int argc, char **argv, const char *name, const char *sourceDir, QObject *setup)