2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2012-09-20 05:21:40 +00:00
|
|
|
** 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
|
2015-01-28 11:55:39 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-19 11:23:05 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-03-06 13:59:29 +00:00
|
|
|
#include "debugutil_p.h"
|
2012-03-06 22:35:27 +00:00
|
|
|
#include "qqmldebugtestservice.h"
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2015-07-13 14:38:25 +00:00
|
|
|
#include <private/qqmldebugconnector_p.h>
|
2015-09-16 14:28:24 +00:00
|
|
|
#include <private/qqmldebugconnection_p.h>
|
|
|
|
|
|
|
|
#include <QtTest/qtest.h>
|
|
|
|
#include <QtTest/qsignalspy.h>
|
|
|
|
#include <QtCore/qtimer.h>
|
|
|
|
#include <QtCore/qdebug.h>
|
|
|
|
#include <QtCore/qthread.h>
|
|
|
|
#include <QtNetwork/qhostaddress.h>
|
|
|
|
#include <QtQml/qqmlengine.h>
|
2015-07-13 14:38:25 +00:00
|
|
|
|
2011-09-19 10:29:10 +00:00
|
|
|
#define PORT 13770
|
|
|
|
#define STR_PORT "13770"
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
class tst_QQmlDebugClient : public QObject
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugConnection *m_conn;
|
2015-07-13 14:38:25 +00:00
|
|
|
QQmlDebugTestService *m_service;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initTestCase();
|
|
|
|
|
|
|
|
void name();
|
2012-02-02 10:18:08 +00:00
|
|
|
void state();
|
2011-04-27 10:05:43 +00:00
|
|
|
void sendMessage();
|
2011-09-19 10:29:10 +00:00
|
|
|
void parallelConnect();
|
|
|
|
void sequentialConnect();
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_QQmlDebugClient::initTestCase()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-07-13 14:38:25 +00:00
|
|
|
QQmlDebugConnector::setPluginKey(QLatin1String("QQmlDebugServer"));
|
2015-08-10 14:06:49 +00:00
|
|
|
QQmlDebugConnector::setServices(QStringList()
|
|
|
|
<< QStringLiteral("tst_QQmlDebugClient::handshake()"));
|
2015-07-13 14:38:25 +00:00
|
|
|
|
|
|
|
m_service = new QQmlDebugTestService("tst_QQmlDebugClient::handshake()");
|
2015-08-10 14:06:49 +00:00
|
|
|
|
|
|
|
foreach (const QString &service, QQmlDebuggingEnabler::debuggerServices())
|
2018-02-21 09:41:54 +00:00
|
|
|
QCOMPARE(QQmlDebugConnector::instance()->service(service), (QQmlDebugService *)nullptr);
|
2015-08-10 14:06:49 +00:00
|
|
|
foreach (const QString &service, QQmlDebuggingEnabler::inspectorServices())
|
2018-02-21 09:41:54 +00:00
|
|
|
QCOMPARE(QQmlDebugConnector::instance()->service(service), (QQmlDebugService *)nullptr);
|
2015-08-10 14:06:49 +00:00
|
|
|
foreach (const QString &service, QQmlDebuggingEnabler::profilerServices())
|
2018-02-21 09:41:54 +00:00
|
|
|
QCOMPARE(QQmlDebugConnector::instance()->service(service), (QQmlDebugService *)nullptr);
|
2015-08-10 14:06:49 +00:00
|
|
|
|
2012-03-07 13:53:24 +00:00
|
|
|
const QString waitingMsg = QString("QML Debugger: Waiting for connection on port %1...").arg(PORT);
|
2012-05-03 12:42:53 +00:00
|
|
|
QTest::ignoreMessage(QtDebugMsg, waitingMsg.toLatin1().constData());
|
2015-07-13 14:38:25 +00:00
|
|
|
QQmlDebuggingEnabler::startTcpDebugServer(PORT);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
new QQmlEngine(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
m_conn = new QQmlDebugConnection(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugTestClient client("tst_QQmlDebugClient::handshake()", m_conn);
|
2015-07-13 14:38:25 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-08-24 11:51:07 +00:00
|
|
|
for (int i = 0; i < 50; ++i) {
|
|
|
|
// try for 5 seconds ...
|
|
|
|
m_conn->connectToHost("127.0.0.1", PORT);
|
2015-06-12 15:21:19 +00:00
|
|
|
if (m_conn->waitForConnected(100))
|
2011-08-24 11:51:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY(m_conn->isConnected());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_QQmlDebugClient::name()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QString name = "tst_QQmlDebugClient::name()";
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugClient client(name, m_conn);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(client.name(), name);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_QQmlDebugClient::state()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugConnection dummyConn;
|
|
|
|
QQmlDebugClient client("tst_QQmlDebugClient::state()", &dummyConn);
|
|
|
|
QCOMPARE(client.state(), QQmlDebugClient::NotConnected);
|
2011-12-15 16:52:22 +00:00
|
|
|
QCOMPARE(client.serviceVersion(), -1.0f);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugTestClient client("tst_QQmlDebugClient::state()", m_conn);
|
|
|
|
QCOMPARE(client.state(), QQmlDebugClient::Unavailable);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// duplicate plugin name
|
2013-10-30 15:59:04 +00:00
|
|
|
QTest::ignoreMessage(QtWarningMsg, "QQmlDebugClient: Conflicting plugin name \"tst_QQmlDebugClient::state()\"");
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugClient client2("tst_QQmlDebugClient::state()", m_conn);
|
|
|
|
QCOMPARE(client2.state(), QQmlDebugClient::NotConnected);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2018-02-21 09:41:54 +00:00
|
|
|
QQmlDebugClient client3("tst_QQmlDebugClient::state3()", nullptr);
|
2012-02-16 04:43:03 +00:00
|
|
|
QCOMPARE(client3.state(), QQmlDebugClient::NotConnected);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_QQmlDebugClient::sendMessage()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2015-07-13 14:38:25 +00:00
|
|
|
QQmlDebugTestClient client("tst_QQmlDebugClient::handshake()", m_conn);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QByteArray msg = "hello!";
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
client.sendMessage(msg);
|
|
|
|
QByteArray resp = client.waitForResponse();
|
|
|
|
QCOMPARE(resp, msg);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_QQmlDebugClient::parallelConnect()
|
2011-09-19 10:29:10 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugConnection connection2;
|
2011-09-19 10:29:10 +00:00
|
|
|
|
2012-03-07 13:53:24 +00:00
|
|
|
QTest::ignoreMessage(QtWarningMsg, "QML Debugger: Another client is already connected.");
|
2011-09-19 10:29:10 +00:00
|
|
|
// will connect & immediately disconnect
|
2011-11-25 22:03:24 +00:00
|
|
|
connection2.connectToHost("127.0.0.1", PORT);
|
2015-09-16 14:28:24 +00:00
|
|
|
QTest::ignoreMessage(QtWarningMsg, "QQmlDebugConnection: Did not get handshake answer in time");
|
|
|
|
QVERIFY(!connection2.waitForConnected(1000));
|
|
|
|
QVERIFY(!connection2.isConnected());
|
2011-09-19 10:29:10 +00:00
|
|
|
QVERIFY(m_conn->isConnected());
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void tst_QQmlDebugClient::sequentialConnect()
|
2011-09-19 10:29:10 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugConnection connection2;
|
|
|
|
QQmlDebugTestClient client2("tst_QQmlDebugClient::handshake()", &connection2);
|
2011-09-19 10:29:10 +00:00
|
|
|
|
|
|
|
m_conn->close();
|
|
|
|
QVERIFY(!m_conn->isConnected());
|
|
|
|
|
|
|
|
// Make sure that the disconnect is actually delivered to the server
|
2011-11-10 05:59:50 +00:00
|
|
|
QTest::qWait(100);
|
2011-09-19 10:29:10 +00:00
|
|
|
|
|
|
|
connection2.connectToHost("127.0.0.1", PORT);
|
|
|
|
QVERIFY(connection2.waitForConnected());
|
|
|
|
QVERIFY(connection2.isConnected());
|
2015-07-24 13:27:58 +00:00
|
|
|
QTRY_COMPARE(client2.state(), QQmlDebugClient::Enabled);
|
2011-09-19 10:29:10 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 14:38:25 +00:00
|
|
|
QTEST_MAIN(tst_QQmlDebugClient)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include "tst_qqmldebugclient.moc"
|
2011-04-27 10:05:43 +00:00
|
|
|
|