2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2012-01-05 04:29:18 +00:00
|
|
|
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2012-01-20 04:04:27 +00:00
|
|
|
** Contact: http://www.qt-project.org/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-05-24 11:43:28 +00:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU Lesser
|
|
|
|
** General Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-05-24 11:43:28 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 11:43:28 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License version 3.0 as published by the Free Software Foundation
|
|
|
|
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU General
|
|
|
|
** Public License version 3.0 requirements will be met:
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2011-05-24 11:43:28 +00:00
|
|
|
** Other Usage
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
2012-01-24 03:37:23 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $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"
|
2011-04-27 10:05:43 +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;
|
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
|
|
|
{
|
2012-03-07 13:53:24 +00:00
|
|
|
const QString waitingMsg = QString("QML Debugger: Waiting for connection on port %1...").arg(PORT);
|
2012-03-08 14:15:10 +00:00
|
|
|
QTest::ignoreMessage(QtDebugMsg, waitingMsg.toAscii().constData());
|
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);
|
|
|
|
QQmlDebugTestService service("tst_QQmlDebugClient::handshake()");
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-08 14:15:10 +00:00
|
|
|
QTest::ignoreMessage(QtDebugMsg, "QML Debugger: Connection established.");
|
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);
|
|
|
|
if (m_conn->waitForConnected())
|
|
|
|
break;
|
|
|
|
QTest::qSleep(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY(m_conn->isConnected());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QTRY_VERIFY(QQmlDebugService::hasDebuggingClient());
|
|
|
|
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
|
|
|
|
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugTestService service("tst_QQmlDebugClient::state()", 2);
|
|
|
|
QTRY_COMPARE(client.state(), QQmlDebugClient::Enabled);
|
2011-12-15 16:52:22 +00:00
|
|
|
QCOMPARE(client.serviceVersion(), 2.0f);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QTRY_COMPARE(client.state(), QQmlDebugClient::Unavailable);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// duplicate plugin name
|
2012-02-16 04:43:03 +00:00
|
|
|
QTest::ignoreMessage(QtWarningMsg, "QQmlDebugClient: Conflicting plugin name \"tst_QQmlDebugClient::state()\" ");
|
|
|
|
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
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlDebugTestService service("tst_QQmlDebugClient::sendMessage()");
|
|
|
|
QQmlDebugTestClient client("tst_QQmlDebugClient::sendMessage()", 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
|
|
|
QVERIFY(connection2.waitForConnected());
|
|
|
|
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);
|
|
|
|
QQmlDebugTestService service("tst_QQmlDebugClient::handshake()");
|
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);
|
2012-03-08 14:15:10 +00:00
|
|
|
QTest::ignoreMessage(QtDebugMsg, "QML Debugger: Connection established.");
|
2011-09-19 10:29:10 +00:00
|
|
|
QVERIFY(connection2.waitForConnected());
|
|
|
|
QVERIFY(connection2.isConnected());
|
2012-02-16 04:43:03 +00:00
|
|
|
QTRY_VERIFY(client2.state() == QQmlDebugClient::Enabled);
|
2011-09-19 10:29:10 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int _argc = argc + 1;
|
|
|
|
char **_argv = new char*[_argc];
|
|
|
|
for (int i = 0; i < argc; ++i)
|
|
|
|
_argv[i] = argv[i];
|
2011-12-06 14:16:55 +00:00
|
|
|
char arg[] = "-qmljsdebugger=port:" STR_PORT;
|
|
|
|
_argv[_argc - 1] = arg;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-09-16 10:07:14 +00:00
|
|
|
QGuiApplication app(_argc, _argv);
|
2012-02-16 04:43:03 +00:00
|
|
|
tst_QQmlDebugClient tc;
|
2011-04-27 10:05:43 +00:00
|
|
|
return QTest::qExec(&tc, _argc, _argv);
|
|
|
|
delete _argv;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include "tst_qqmldebugclient.moc"
|
2011-04-27 10:05:43 +00:00
|
|
|
|