aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/debugger/shared/debugutil.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-08-15 17:23:35 +0200
committerUlf Hermann <ulf.hermann@qt.io>2017-08-18 08:41:25 +0000
commit4b731207dfb42a499d6a061adbbb13cd58d817a9 (patch)
tree7c8541b8308cf149314f7f1e2801f9160b8473c4 /tests/auto/qml/debugger/shared/debugutil.cpp
parent74ca31771f9f936cf4c4bbe9216183d46fcf3617 (diff)
Tests: Unify debugger tests' connection mechanisms
All the tests do pretty much the same thing in their init() or connect() methods: Create a process, create a debug connection, create some clients and make sure they're all running. We can deduplicate the code by moving all this into a common base class. Furthermore, the QSKIP in the qqmlenginedebuginspectorintegration test was obviously done because the BLACKLIST mechanism doesn't cover failures from internally called methods. As we don't have that problem anymore now, we can use BLACKLIST instead. Change-Id: I6d45d3b4e9645558ecc783a81fd740b00235cdc1 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/debugger/shared/debugutil.cpp')
-rw-r--r--tests/auto/qml/debugger/shared/debugutil.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/auto/qml/debugger/shared/debugutil.cpp b/tests/auto/qml/debugger/shared/debugutil.cpp
index 7b9e935678..d3bb25ee89 100644
--- a/tests/auto/qml/debugger/shared/debugutil.cpp
+++ b/tests/auto/qml/debugger/shared/debugutil.cpp
@@ -302,3 +302,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;
+ }
+}