2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2015-01-28 11:55:39 +00:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
** Contact: http://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2014-08-22 06:13:59 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL21$
|
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
|
|
|
|
** and conditions see http://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at http://www.qt.io/contact-us.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-20 05:21:40 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-08-22 06:13:59 +00:00
|
|
|
** 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.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2015-01-28 11:55:39 +00:00
|
|
|
** As a special exception, The Qt Company gives you certain additional
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** 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>
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <QtQml/qqmlengine.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
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>
|
|
|
|
|
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"));
|
|
|
|
QTest::ignoreMessage(QtWarningMsg,
|
|
|
|
"QML debugger: Cannot set plugin key after loading the plugin.");
|
|
|
|
|
|
|
|
m_service = new QQmlDebugTestService("tst_QQmlDebugClient::handshake()");
|
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
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugClient client3("tst_QQmlDebugClient::state3()", 0);
|
|
|
|
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);
|
2011-09-19 10:29:10 +00:00
|
|
|
QTRY_COMPARE(connection2.state(), QAbstractSocket::UnconnectedState);
|
|
|
|
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());
|
|
|
|
QCOMPARE(m_conn->state(), QAbstractSocket::UnconnectedState);
|
|
|
|
|
|
|
|
// 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
|
|
|
|