1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
44 #include <QHostAddress>
48 #include <QtDeclarative/qdeclarativeengine.h>
50 #include <private/qdeclarativedebug_p.h>
51 #include <private/qdeclarativeenginedebug_p.h>
52 #include <private/qdeclarativedebugclient_p.h>
53 #include <private/qdeclarativedebugservice_p.h>
54 #include <private/qdeclarativedebughelper_p.h>
56 #include "../../../shared/util.h"
57 #include "../shared/debugutil_p.h"
59 class tst_QDeclarativeDebugClient : public QObject
64 QDeclarativeDebugConnection *m_conn;
74 void tst_QDeclarativeDebugClient::initTestCase()
76 QTest::ignoreMessage(QtWarningMsg, "Qml debugging is enabled. Only use this in a safe environment!");
77 QDeclarativeDebugHelper::enableDebugging();
79 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 13770...");
80 new QDeclarativeEngine(this);
82 m_conn = new QDeclarativeDebugConnection(this);
84 QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::handshake()", m_conn);
85 QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::handshake()");
87 m_conn->connectToHost("127.0.0.1", 13770);
89 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established");
90 bool ok = m_conn->waitForConnected();
93 QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient());
94 QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled);
97 void tst_QDeclarativeDebugClient::name()
99 QString name = "tst_QDeclarativeDebugClient::name()";
101 QDeclarativeDebugClient client(name, m_conn);
102 QCOMPARE(client.name(), name);
105 void tst_QDeclarativeDebugClient::status()
108 QDeclarativeDebugConnection dummyConn;
109 QDeclarativeDebugClient client("tst_QDeclarativeDebugClient::status()", &dummyConn);
110 QCOMPARE(client.status(), QDeclarativeDebugClient::NotConnected);
113 QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::status()", m_conn);
114 QCOMPARE(client.status(), QDeclarativeDebugClient::Unavailable);
117 QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::status()");
118 QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled);
121 QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Unavailable);
123 // duplicate plugin name
124 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugClient: Conflicting plugin name \"tst_QDeclarativeDebugClient::status()\" ");
125 QDeclarativeDebugClient client2("tst_QDeclarativeDebugClient::status()", m_conn);
126 QCOMPARE(client2.status(), QDeclarativeDebugClient::NotConnected);
128 QDeclarativeDebugClient client3("tst_QDeclarativeDebugClient::status3()", 0);
129 QCOMPARE(client3.status(), QDeclarativeDebugClient::NotConnected);
132 void tst_QDeclarativeDebugClient::sendMessage()
134 QDeclarativeDebugTestService service("tst_QDeclarativeDebugClient::sendMessage()");
135 QDeclarativeDebugTestClient client("tst_QDeclarativeDebugClient::sendMessage()", m_conn);
137 QByteArray msg = "hello!";
139 QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled);
141 client.sendMessage(msg);
142 QByteArray resp = client.waitForResponse();
146 int main(int argc, char *argv[])
148 int _argc = argc + 1;
149 char **_argv = new char*[_argc];
150 for (int i = 0; i < argc; ++i)
152 _argv[_argc - 1] = "-qmljsdebugger=port:13770";
154 QApplication app(_argc, _argv);
155 tst_QDeclarativeDebugClient tc;
156 return QTest::qExec(&tc, _argc, _argv);
160 #include "tst_qdeclarativedebugclient.moc"