diff options
Diffstat (limited to 'tests/auto/qml/debugger/shared')
-rw-r--r-- | tests/auto/qml/debugger/shared/debugutil.cpp | 112 | ||||
-rw-r--r-- | tests/auto/qml/debugger/shared/debugutil.pri | 3 | ||||
-rw-r--r-- | tests/auto/qml/debugger/shared/debugutil_p.h | 30 |
3 files changed, 144 insertions, 1 deletions
diff --git a/tests/auto/qml/debugger/shared/debugutil.cpp b/tests/auto/qml/debugger/shared/debugutil.cpp index d31efc84cf..40e51f3a05 100644 --- a/tests/auto/qml/debugger/shared/debugutil.cpp +++ b/tests/auto/qml/debugger/shared/debugutil.cpp @@ -305,3 +305,115 @@ void QQmlDebugProcess::processError(QProcess::ProcessError error) m_eventLoop.exit(); } + +template<typename F> +struct Finalizer { + F m_lambda; + Finalizer(F &&lambda) : m_lambda(std::forward<F>(lambda)) {} + ~Finalizer() { m_lambda(); } +}; + +template<typename F> +static Finalizer<F> defer(F &&lambda) +{ + return Finalizer<F>(std::forward<F>(lambda)); +} + +QQmlDebugTest::ConnectResult QQmlDebugTest::connect( + const QString &executable, const QString &services, const QString &extraArgs, + bool block) +{ + QStringList arguments; + arguments << QString::fromLatin1("-qmljsdebugger=port:13773,13783%3%4") + .arg(block ? QStringLiteral(",block") : QString()) + .arg(services.isEmpty() ? services : (QStringLiteral(",services:") + services)) + << extraArgs; + + m_process = createProcess(executable); + if (!m_process) + return ProcessFailed; + + m_process->start(QStringList() << arguments); + if (!m_process->waitForSessionStart()) + return SessionFailed; + + m_connection = createConnection(); + if (!m_connection) + return ConnectionFailed; + + m_clients = createClients(); + if (m_clients.contains(nullptr)) + return ClientsFailed; + + auto allEnabled = [this]() { + for (QQmlDebugClient *client : m_clients) { + if (client->state() != QQmlDebugClient::Enabled) + return false; + } + return true; + }; + + QList<QQmlDebugClient *> others = createOtherClients(m_connection); + auto deleter = defer([&others]() { qDeleteAll(others); }); + Q_UNUSED(deleter); + + const int port = m_process->debugPort(); + m_connection->connectToHost(QLatin1String("127.0.0.1"), port); + for (int tries = 0; tries < 100 && !allEnabled(); ++tries) + QTest::qWait(50); + if (!allEnabled()) + return EnableFailed; + + const QQmlDebugClient::State expectedState = services.isEmpty() ? QQmlDebugClient::Enabled + : QQmlDebugClient::Unavailable; + for (QQmlDebugClient *other : others) { + if (other->state() != expectedState) + return RestrictFailed; + } + + return ConnectSuccess; +} + +QList<QQmlDebugClient *> QQmlDebugTest::createClients() +{ + return QList<QQmlDebugClient *>(); +} + +QQmlDebugProcess *QQmlDebugTest::createProcess(const QString &executable) +{ + return new QQmlDebugProcess(executable, this); +} + +QQmlDebugConnection *QQmlDebugTest::createConnection() +{ + return new QQmlDebugConnection(this); +} + +void QQmlDebugTest::cleanup() +{ + if (QTest::currentTestFailed()) { + const QString null = QStringLiteral("null"); + + qDebug() << "Process State:" << (m_process ? m_process->state() : null); + qDebug() << "Application Output:" << (m_process ? m_process->output() : null); + qDebug() << "Connection State:" << QQmlDebugTest::connectionStateString(m_connection); + for (QQmlDebugClient *client : m_clients) { + if (client) + qDebug() << client->name() << "State:" << QQmlDebugTest::clientStateString(client); + else + qDebug() << "Failed Client:" << null; + } + } + + qDeleteAll(m_clients); + m_clients.clear(); + + delete m_connection; + m_connection = nullptr; + + if (m_process) { + m_process->stop(); + delete m_process; + m_process = nullptr; + } +} diff --git a/tests/auto/qml/debugger/shared/debugutil.pri b/tests/auto/qml/debugger/shared/debugutil.pri index 1983f3583e..44e8e0f999 100644 --- a/tests/auto/qml/debugger/shared/debugutil.pri +++ b/tests/auto/qml/debugger/shared/debugutil.pri @@ -1,4 +1,7 @@ QT += qmldebug-private +INCLUDEPATH += $$PWD +include($$PWD/../../../shared/util.pri) + HEADERS += $$PWD/debugutil_p.h SOURCES += $$PWD/debugutil.cpp diff --git a/tests/auto/qml/debugger/shared/debugutil_p.h b/tests/auto/qml/debugger/shared/debugutil_p.h index 1ec0a6513d..f1b25d5f6d 100644 --- a/tests/auto/qml/debugger/shared/debugutil_p.h +++ b/tests/auto/qml/debugger/shared/debugutil_p.h @@ -41,6 +41,7 @@ // We mean it. // +#include <../../../shared/util.h> #include <private/qqmldebugclient_p.h> #include <QtCore/qeventloop.h> @@ -51,13 +52,40 @@ #include <QtTest/qtest.h> #include <QtQml/qqmlengine.h> -class QQmlDebugTest +class QQmlDebugProcess; +class QQmlDebugTest : public QQmlDataTest { + Q_OBJECT public: static bool waitForSignal(QObject *receiver, const char *member, int timeout = 5000); static QList<QQmlDebugClient *> createOtherClients(QQmlDebugConnection *connection); static QString clientStateString(const QQmlDebugClient *client); static QString connectionStateString(const QQmlDebugConnection *connection); + +protected: + enum ConnectResult { + ConnectSuccess, + ProcessFailed, + SessionFailed, + ConnectionFailed, + ClientsFailed, + EnableFailed, + RestrictFailed + }; + + ConnectResult connect(const QString &executable, const QString &services, + const QString &extraArgs, bool block); + + virtual QQmlDebugProcess *createProcess(const QString &executable); + virtual QQmlDebugConnection *createConnection(); + virtual QList<QQmlDebugClient *> createClients(); + + QQmlDebugProcess *m_process = nullptr; + QQmlDebugConnection *m_connection = nullptr; + QList<QQmlDebugClient *> m_clients; + +protected slots: + virtual void cleanup(); }; class QQmlDebugTestClient : public QQmlDebugClient |