| 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:GPL-EXCEPT$ | 
| 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 General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
| 21 | ** included in the packaging of this file. Please review the following | 
| 22 | ** information to ensure the GNU General Public License requirements will | 
| 23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. | 
| 24 | ** | 
| 25 | ** $QT_END_LICENSE$ | 
| 26 | ** | 
| 27 | ****************************************************************************/ | 
| 28 |  | 
| 29 | #ifndef DEBUGUTIL_P_H | 
| 30 | #define DEBUGUTIL_P_H | 
| 31 |  | 
| 32 | // | 
| 33 | //  W A R N I N G | 
| 34 | //  ------------- | 
| 35 | // | 
| 36 | // This file is not part of the Qt API.  It exists purely as an | 
| 37 | // implementation detail.  This header file may change from version to | 
| 38 | // version without notice, or even be removed. | 
| 39 | // | 
| 40 | // We mean it. | 
| 41 | // | 
| 42 |  | 
| 43 | #include <../../../shared/util.h> | 
| 44 | #include <private/qqmldebugclient_p.h> | 
| 45 |  | 
| 46 | class QQmlDebugProcess; | 
| 47 | class QQmlDebugTest : public QQmlDataTest | 
| 48 | { | 
| 49 |     Q_OBJECT | 
| 50 | public: | 
| 51 |     static bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000); | 
| 52 |     static QList<QQmlDebugClient *> createOtherClients(QQmlDebugConnection *connection); | 
| 53 |     static QString clientStateString(const QQmlDebugClient *client); | 
| 54 |     static QString connectionStateString(const QQmlDebugConnection *connection); | 
| 55 |  | 
| 56 |     enum ConnectResult { | 
| 57 |         ConnectSuccess, | 
| 58 |         ProcessFailed, | 
| 59 |         SessionFailed, | 
| 60 |         ConnectionFailed, | 
| 61 |         ClientsFailed, | 
| 62 |         EnableFailed, | 
| 63 |         RestrictFailed | 
| 64 |     }; | 
| 65 |  | 
| 66 |     Q_ENUM(ConnectResult) | 
| 67 | protected: | 
| 68 |     ConnectResult connectTo(const QString &executable, const QString &services, | 
| 69 |                           const QString &, bool block); | 
| 70 |  | 
| 71 |     virtual QQmlDebugProcess *createProcess(const QString &executable); | 
| 72 |     virtual QQmlDebugConnection *createConnection(); | 
| 73 |     virtual QList<QQmlDebugClient *> createClients(); | 
| 74 |  | 
| 75 |     QQmlDebugProcess *m_process = nullptr; | 
| 76 |     QQmlDebugConnection *m_connection = nullptr; | 
| 77 |     QList<QQmlDebugClient *> m_clients; | 
| 78 |  | 
| 79 | protected slots: | 
| 80 |     virtual void cleanup(); | 
| 81 | }; | 
| 82 |  | 
| 83 | class QQmlDebugTestClient : public QQmlDebugClient | 
| 84 | { | 
| 85 |     Q_OBJECT | 
| 86 | public: | 
| 87 |     QQmlDebugTestClient(const QString &s, QQmlDebugConnection *c); | 
| 88 |  | 
| 89 |     QByteArray waitForResponse(); | 
| 90 |  | 
| 91 | signals: | 
| 92 |     void serverMessage(const QByteArray &); | 
| 93 |  | 
| 94 | protected: | 
| 95 |     virtual void messageReceived(const QByteArray &ba); | 
| 96 |  | 
| 97 | private: | 
| 98 |     QByteArray lastMsg; | 
| 99 | }; | 
| 100 |  | 
| 101 | class QQmlInspectorResultRecipient : public QObject | 
| 102 | { | 
| 103 |     Q_OBJECT | 
| 104 | public: | 
| 105 |     QQmlInspectorResultRecipient(QObject *parent = 0) : | 
| 106 |         QObject(parent), lastResponseId(-1), lastResult(false) {} | 
| 107 |  | 
| 108 |     int lastResponseId; | 
| 109 |     bool lastResult; | 
| 110 |  | 
| 111 |     void recordResponse(int requestId, bool result) | 
| 112 |     { | 
| 113 |         lastResponseId = requestId; | 
| 114 |         lastResult = result; | 
| 115 |     } | 
| 116 | }; | 
| 117 |  | 
| 118 | class ClientStateHandler : public QObject | 
| 119 | { | 
| 120 |     Q_OBJECT | 
| 121 | public: | 
| 122 |     ClientStateHandler(const QList<QQmlDebugClient *> &clients, | 
| 123 |                        const QList<QQmlDebugClient *> &others, | 
| 124 |                        QQmlDebugClient::State expectedOthers); | 
| 125 |  | 
| 126 |     ~ClientStateHandler(); | 
| 127 |  | 
| 128 |     bool allEnabled() const { return m_allEnabled; } | 
| 129 |     bool othersAsExpected() const { return m_othersAsExpected; } | 
| 130 |  | 
| 131 | signals: | 
| 132 |     void allOk(); | 
| 133 |  | 
| 134 | private: | 
| 135 |     void checkStates(); | 
| 136 |  | 
| 137 |     const QList<QQmlDebugClient *> m_clients; | 
| 138 |     const QList<QQmlDebugClient *> m_others; | 
| 139 |     const QQmlDebugClient::State m_expectedOthers; | 
| 140 |  | 
| 141 |     bool m_allEnabled = false; | 
| 142 |     bool m_othersAsExpected = false; | 
| 143 | }; | 
| 144 |  | 
| 145 | QString debugJsServerPath(const QString &selfPath); | 
| 146 |  | 
| 147 | #endif // DEBUGUTIL_P_H | 
| 148 |  |