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 | |
4 | #ifndef QUICKTEST_P_H |
5 | #define QUICKTEST_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 <QtQuickTest/quicktest.h> |
20 | |
21 | #include <QtQml/qqmlpropertymap.h> |
22 | #include <QtQml/qqml.h> |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class Q_QUICK_TEST_PRIVATE_EXPORT QTestRootObject : public QObject |
27 | { |
28 | Q_OBJECT |
29 | Q_PROPERTY(bool windowShown READ windowShown NOTIFY windowShownChanged) |
30 | Q_PROPERTY(bool hasTestCase READ hasTestCase WRITE setHasTestCase NOTIFY hasTestCaseChanged) |
31 | Q_PROPERTY(QObject *defined READ defined) |
32 | |
33 | QML_SINGLETON |
34 | QML_ELEMENT |
35 | QML_ADDED_IN_VERSION(1, 0) |
36 | |
37 | public: |
38 | static QTestRootObject *create(QQmlEngine *q, QJSEngine *) |
39 | { |
40 | QTestRootObject *result = instance(); |
41 | QQmlEngine *engine = qmlEngine(result); |
42 | // You can only test on one engine at a time |
43 | return (engine == nullptr || engine == q) ? result : nullptr; |
44 | } |
45 | |
46 | static QTestRootObject *instance() { |
47 | static QPointer<QTestRootObject> object = new QTestRootObject; |
48 | if (!object) { |
49 | // QTestRootObject was deleted when previous test ended, create a new one |
50 | object = new QTestRootObject; |
51 | } |
52 | return object; |
53 | } |
54 | |
55 | bool hasQuit:1; |
56 | bool hasTestCase() const { return m_hasTestCase; } |
57 | void setHasTestCase(bool value) { m_hasTestCase = value; Q_EMIT hasTestCaseChanged(); } |
58 | |
59 | bool windowShown() const { return m_windowShown; } |
60 | void setWindowShown(bool value) { m_windowShown = value; Q_EMIT windowShownChanged(); } |
61 | QQmlPropertyMap *defined() const { return m_defined; } |
62 | |
63 | void init() { setWindowShown(false); setHasTestCase(false); hasQuit = false; } |
64 | |
65 | Q_SIGNALS: |
66 | void windowShownChanged(); |
67 | void hasTestCaseChanged(); |
68 | |
69 | private Q_SLOTS: |
70 | void quit() { hasQuit = true; } |
71 | |
72 | private: |
73 | QTestRootObject(QObject *parent = nullptr) |
74 | : QObject(parent), hasQuit(false), m_windowShown(false), m_hasTestCase(false) { |
75 | m_defined = new QQmlPropertyMap(this); |
76 | #if defined(QT_OPENGL_ES_2_ANGLE) |
77 | m_defined->insert(QLatin1String("QT_OPENGL_ES_2_ANGLE" ), QVariant(true)); |
78 | #endif |
79 | } |
80 | |
81 | bool m_windowShown : 1; |
82 | bool m_hasTestCase :1; |
83 | QQmlPropertyMap *m_defined; |
84 | }; |
85 | |
86 | bool qWaitForSignal(QObject *obj, const char* signal, int timeout = 5000); |
87 | |
88 | QT_END_NAMESPACE |
89 | |
90 | #endif // QUICKTEST_P_H |
91 | |