aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/debugger
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@theqtcompany.com>2014-12-02 15:57:06 +0100
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2015-06-26 14:13:46 +0000
commitf23d4fafbff44bcb6fb1e259ca1021a4c4326084 (patch)
tree8fd6c26460d3dd9f268e64a92ad6e6ec4b375c56 /tests/auto/qml/debugger
parent49d3cbfa171902ae2dc61bcdadfdac1305c50a2a (diff)
Add option to use a local socket for QML debugging
Using a TCP debug server comes with a number of drawbacks. It has a larger overhead than other connection types, the application has to be able to access the network and there has to be an open port we can find somehow. Change-Id: Ia7fb24006b89419988c6504797303d84c3aa1bbc Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tests/auto/qml/debugger')
-rw-r--r--tests/auto/qml/debugger/debugger.pro1
-rw-r--r--tests/auto/qml/debugger/qqmldebuglocal/qqmldebuglocal.pro16
-rw-r--r--tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp161
-rw-r--r--tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.pro0
-rw-r--r--tests/auto/qml/debugger/shared/qqmldebugclient.cpp61
-rw-r--r--tests/auto/qml/debugger/shared/qqmldebugclient.h1
6 files changed, 232 insertions, 8 deletions
diff --git a/tests/auto/qml/debugger/debugger.pro b/tests/auto/qml/debugger/debugger.pro
index fc1c0b537b..5a08418be1 100644
--- a/tests/auto/qml/debugger/debugger.pro
+++ b/tests/auto/qml/debugger/debugger.pro
@@ -12,6 +12,7 @@ PUBLICTESTS += \
PRIVATETESTS += \
qqmldebugclient \
+ qqmldebuglocal \
qqmldebugservice
SUBDIRS += $$PUBLICTESTS
diff --git a/tests/auto/qml/debugger/qqmldebuglocal/qqmldebuglocal.pro b/tests/auto/qml/debugger/qqmldebuglocal/qqmldebuglocal.pro
new file mode 100644
index 0000000000..b612da11de
--- /dev/null
+++ b/tests/auto/qml/debugger/qqmldebuglocal/qqmldebuglocal.pro
@@ -0,0 +1,16 @@
+CONFIG += testcase
+TARGET = tst_qqmldebuglocal
+osx:CONFIG -= app_bundle
+
+HEADERS += ../shared/qqmldebugtestservice.h
+
+SOURCES += tst_qqmldebuglocal.cpp \
+ ../shared/qqmldebugtestservice.cpp
+
+INCLUDEPATH += ../shared
+include(../shared/debugutil.pri)
+
+CONFIG += parallel_test
+QT += qml-private testlib gui-private core-private
+
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 QT_QML_DEBUG_NO_WARNING
diff --git a/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp
new file mode 100644
index 0000000000..b1219eabe4
--- /dev/null
+++ b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.cpp
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QSignalSpy>
+#include <QTimer>
+#include <QHostAddress>
+#include <QDebug>
+#include <QThread>
+#include <ctime>
+
+#include "debugutil_p.h"
+#include "qqmldebugtestservice.h"
+
+QString fileName;
+
+class tst_QQmlDebugLocal : public QObject
+{
+ Q_OBJECT
+
+private:
+ QQmlDebugConnection *m_conn;
+
+ bool connect();
+
+signals:
+ void waiting();
+ void parallel();
+
+private slots:
+ void initTestCase();
+
+ void name();
+ void state();
+ void sendMessage();
+};
+
+void tst_QQmlDebugLocal::initTestCase()
+{
+ const QString waitingMsg = QString("QML Debugger: Connecting to socket %1...").arg(fileName);
+ QTest::ignoreMessage(QtDebugMsg, waitingMsg.toLatin1().constData());
+
+ m_conn = new QQmlDebugConnection(this);
+ m_conn->startLocalServer(fileName);
+
+ new QQmlEngine(this);
+
+ QQmlDebugTestClient client("tst_QQmlDebugLocal::handshake()", m_conn);
+ QQmlDebugTestService service("tst_QQmlDebugLocal::handshake()");
+
+ for (int i = 0; i < 50; ++i) {
+ // try for 5 seconds ...
+ if (m_conn->waitForConnected(100))
+ break;
+ }
+
+ QVERIFY(m_conn->isConnected());
+
+ QTRY_VERIFY(QQmlDebugService::hasDebuggingClient());
+ QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled);
+}
+
+void tst_QQmlDebugLocal::name()
+{
+ QString name = "tst_QQmlDebugLocal::name()";
+
+ QQmlDebugClient client(name, m_conn);
+ QCOMPARE(client.name(), name);
+}
+
+void tst_QQmlDebugLocal::state()
+{
+ {
+ QQmlDebugConnection dummyConn;
+ QQmlDebugClient client("tst_QQmlDebugLocal::state()", &dummyConn);
+ QCOMPARE(client.state(), QQmlDebugClient::NotConnected);
+ QCOMPARE(client.serviceVersion(), -1.0f);
+ }
+
+ QQmlDebugTestClient client("tst_QQmlDebugLocal::state()", m_conn);
+ QCOMPARE(client.state(), QQmlDebugClient::Unavailable);
+
+ {
+ QQmlDebugTestService service("tst_QQmlDebugLocal::state()", 2);
+ QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled);
+ QCOMPARE(client.serviceVersion(), 2.0f);
+ }
+
+ QTRY_COMPARE(client.state(), QQmlDebugClient::Unavailable);
+
+ // duplicate plugin name
+ QTest::ignoreMessage(QtWarningMsg, "QQmlDebugClient: Conflicting plugin name \"tst_QQmlDebugLocal::state()\"");
+ QQmlDebugClient client2("tst_QQmlDebugLocal::state()", m_conn);
+ QCOMPARE(client2.state(), QQmlDebugClient::NotConnected);
+
+ QQmlDebugClient client3("tst_QQmlDebugLocal::state3()", 0);
+ QCOMPARE(client3.state(), QQmlDebugClient::NotConnected);
+}
+
+void tst_QQmlDebugLocal::sendMessage()
+{
+ QQmlDebugTestService service("tst_QQmlDebugLocal::sendMessage()");
+ QQmlDebugTestClient client("tst_QQmlDebugLocal::sendMessage()", m_conn);
+
+ QByteArray msg = "hello!";
+
+ QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled);
+
+ client.sendMessage(msg);
+ QByteArray resp = client.waitForResponse();
+ QCOMPARE(resp, msg);
+}
+
+int main(int argc, char *argv[])
+{
+ fileName = QString::fromLatin1("tst_QQmlDebugLocal%1").arg(time(0));
+
+ int _argc = argc + 1;
+ char **_argv = new char*[_argc];
+ for (int i = 0; i < argc; ++i)
+ _argv[i] = argv[i];
+ char *arg = strdup((QString::fromLatin1("-qmljsdebugger=file:") + fileName).toLatin1().data());
+ _argv[_argc - 1] = arg;
+
+ QGuiApplication app(_argc, _argv);
+ tst_QQmlDebugLocal tc;
+ return QTest::qExec(&tc, _argc, _argv);
+ delete _argv;
+}
+
+#include "tst_qqmldebuglocal.moc"
diff --git a/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.pro b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.pro
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/qml/debugger/qqmldebuglocal/tst_qqmldebuglocal.pro
diff --git a/tests/auto/qml/debugger/shared/qqmldebugclient.cpp b/tests/auto/qml/debugger/shared/qqmldebugclient.cpp
index c7281dec69..0f7e572e02 100644
--- a/tests/auto/qml/debugger/shared/qqmldebugclient.cpp
+++ b/tests/auto/qml/debugger/shared/qqmldebugclient.cpp
@@ -39,6 +39,8 @@
#include <QtCore/qstringlist.h>
#include <QtCore/qtimer.h>
#include <QtNetwork/qnetworkproxy.h>
+#include <QtNetwork/qlocalserver.h>
+#include <QtNetwork/qlocalsocket.h>
const int protocolVersion = 1;
const QString serverId = QLatin1String("QDeclarativeDebugServer");
@@ -61,6 +63,7 @@ public:
QQmlDebugConnection *q;
QPacketProtocol *protocol;
QIODevice *device;
+ QLocalServer *server;
QEventLoop handshakeEventLoop;
QTimer handshakeTimer;
@@ -72,6 +75,10 @@ public:
void connectDeviceSignals();
public Q_SLOTS:
+ void forwardStateChange(QLocalSocket::LocalSocketState state);
+ void forwardError(QLocalSocket::LocalSocketError error);
+
+ void newConnection();
void connected();
void readyRead();
void deviceAboutToClose();
@@ -79,7 +86,7 @@ public Q_SLOTS:
};
QQmlDebugConnectionPrivate::QQmlDebugConnectionPrivate(QQmlDebugConnection *c)
- : QObject(c), q(c), protocol(0), device(0), gotHello(false)
+ : QObject(c), q(c), protocol(0), device(0), server(0), gotHello(false)
{
protocol = new QPacketProtocol(q, this);
QObject::connect(c, SIGNAL(connected()), this, SLOT(connected()));
@@ -307,10 +314,13 @@ void QQmlDebugConnection::close()
bool QQmlDebugConnection::waitForConnected(int msecs)
{
QAbstractSocket *socket = qobject_cast<QAbstractSocket*>(d->device);
- if (!socket)
- return false;
- if (!socket->waitForConnected(msecs))
+ if (!socket) {
+ if (!d->server || (!d->server->hasPendingConnections() &&
+ !d->server->waitForNewConnection(msecs)))
+ return false;
+ } else if (!socket->waitForConnected(msecs)) {
return false;
+ }
// wait for handshake
d->handshakeTimer.start();
d->handshakeEventLoop.exec();
@@ -336,9 +346,13 @@ QString QQmlDebugConnection::stateString() const
QAbstractSocket::SocketState QQmlDebugConnection::state() const
{
- QAbstractSocket *socket = qobject_cast<QAbstractSocket*>(d->device);
- if (socket)
- return socket->state();
+ QAbstractSocket *abstractSocket = qobject_cast<QAbstractSocket*>(d->device);
+ if (abstractSocket)
+ return abstractSocket->state();
+
+ QLocalSocket *localSocket = qobject_cast<QLocalSocket*>(d->device);
+ if (localSocket)
+ return static_cast<QAbstractSocket::SocketState>(localSocket->state());
return QAbstractSocket::UnconnectedState;
}
@@ -366,6 +380,29 @@ void QQmlDebugConnection::connectToHost(const QString &hostName, quint16 port)
QIODevice::open(ReadWrite | Unbuffered);
}
+void QQmlDebugConnection::startLocalServer(const QString &fileName)
+{
+ d->gotHello = false;
+ d->server = new QLocalServer(d);
+ // QueuedConnection so that waitForNewConnection() returns true.
+ connect(d->server, SIGNAL(newConnection()), d, SLOT(newConnection()), Qt::QueuedConnection);
+ d->server->listen(fileName);
+ QIODevice::open(ReadWrite | Unbuffered);
+}
+
+void QQmlDebugConnectionPrivate::newConnection()
+{
+ QLocalSocket *socket = server->nextPendingConnection();
+ server->close();
+ device = socket;
+ connectDeviceSignals();
+ connect(socket, SIGNAL(stateChanged(QLocalSocket::LocalSocketState)),
+ this, SLOT(forwardStateChange(QLocalSocket::LocalSocketState)));
+ connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)),
+ this, SLOT(forwardError(QLocalSocket::LocalSocketError)));
+ emit q->connected();
+}
+
void QQmlDebugConnectionPrivate::connectDeviceSignals()
{
connect(device, SIGNAL(bytesWritten(qint64)), q, SIGNAL(bytesWritten(qint64)));
@@ -373,7 +410,15 @@ void QQmlDebugConnectionPrivate::connectDeviceSignals()
connect(device, SIGNAL(aboutToClose()), this, SLOT(deviceAboutToClose()));
}
-//
+void QQmlDebugConnectionPrivate::forwardStateChange(QLocalSocket::LocalSocketState state)
+{
+ emit q->stateChanged(static_cast<QAbstractSocket::SocketState>(state));
+}
+
+void QQmlDebugConnectionPrivate::forwardError(QLocalSocket::LocalSocketError error)
+{
+ emit q->error(static_cast<QAbstractSocket::SocketError>(error));
+}
QQmlDebugClientPrivate::QQmlDebugClientPrivate()
: connection(0)
diff --git a/tests/auto/qml/debugger/shared/qqmldebugclient.h b/tests/auto/qml/debugger/shared/qqmldebugclient.h
index 52f428cca7..fe9da693c8 100644
--- a/tests/auto/qml/debugger/shared/qqmldebugclient.h
+++ b/tests/auto/qml/debugger/shared/qqmldebugclient.h
@@ -46,6 +46,7 @@ public:
~QQmlDebugConnection();
void connectToHost(const QString &hostName, quint16 port);
+ void startLocalServer(const QString &fileName);
void setDataStreamVersion(int dataStreamVersion);
int dataStreamVersion();