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>
49 #include <private/qdeclarativedebughelper_p.h>
51 #include <private/qdeclarativedebug_p.h>
52 #include <private/qdeclarativeenginedebug_p.h>
53 #include <private/qdeclarativedebugclient_p.h>
54 #include <private/qdeclarativedebugservice_p.h>
56 #include "../../../shared/util.h"
57 #include "../shared/debugutil_p.h"
60 class tst_QDeclarativeDebugService : public QObject
64 QDeclarativeDebugConnection *m_conn;
74 void objectToString();
77 void tst_QDeclarativeDebugService::initTestCase()
79 QTest::ignoreMessage(QtWarningMsg, "Qml debugging is enabled. Only use this in a safe environment!");
80 QDeclarativeDebugHelper::enableDebugging();
82 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Waiting for connection on port 13769...");
83 new QDeclarativeEngine(this);
85 m_conn = new QDeclarativeDebugConnection(this);
86 m_conn->connectToHost("127.0.0.1", 13769);
88 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugServer: Connection established");
89 bool ok = m_conn->waitForConnected();
92 QTRY_VERIFY(QDeclarativeDebugService::hasDebuggingClient());
95 void tst_QDeclarativeDebugService::name()
97 QString name = "tst_QDeclarativeDebugService::name()";
99 QDeclarativeDebugService service(name);
100 QCOMPARE(service.name(), name);
103 void tst_QDeclarativeDebugService::status()
105 QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::status()");
106 QCOMPARE(service.status(), QDeclarativeDebugService::Unavailable);
109 QDeclarativeDebugTestClient client("tst_QDeclarativeDebugService::status()", m_conn);
110 QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled);
111 QTRY_COMPARE(service.status(), QDeclarativeDebugService::Enabled);
115 QTRY_COMPARE(service.status(), QDeclarativeDebugService::Unavailable);
117 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugService: Conflicting plugin name \"tst_QDeclarativeDebugService::status()\" ");
119 QDeclarativeDebugService duplicate("tst_QDeclarativeDebugService::status()");
120 QCOMPARE(duplicate.status(), QDeclarativeDebugService::NotConnected);
123 void tst_QDeclarativeDebugService::sendMessage()
125 QDeclarativeDebugTestService service("tst_QDeclarativeDebugService::sendMessage()");
126 QDeclarativeDebugTestClient client("tst_QDeclarativeDebugService::sendMessage()", m_conn);
128 QByteArray msg = "hello!";
130 QTRY_COMPARE(client.status(), QDeclarativeDebugClient::Enabled);
131 QTRY_COMPARE(service.status(), QDeclarativeDebugService::Enabled);
133 client.sendMessage(msg);
134 QByteArray resp = client.waitForResponse();
137 QTest::ignoreMessage(QtWarningMsg, "QDeclarativeDebugService: Conflicting plugin name \"tst_QDeclarativeDebugService::sendMessage()\" ");
138 QDeclarativeDebugService duplicate("tst_QDeclarativeDebugService::sendMessage()");
139 duplicate.sendMessage("msg");
142 void tst_QDeclarativeDebugService::idForObject()
144 QCOMPARE(QDeclarativeDebugService::idForObject(0), -1);
146 QObject *objA = new QObject;
148 int idA = QDeclarativeDebugService::idForObject(objA);
150 QCOMPARE(QDeclarativeDebugService::objectForId(idA), objA);
152 int idAA = QDeclarativeDebugService::idForObject(objA);
155 QObject *objB = new QObject;
156 int idB = QDeclarativeDebugService::idForObject(objB);
158 QCOMPARE(QDeclarativeDebugService::objectForId(idB), objB);
164 void tst_QDeclarativeDebugService::objectForId()
166 QCOMPARE(QDeclarativeDebugService::objectForId(-1), static_cast<QObject*>(0));
167 QCOMPARE(QDeclarativeDebugService::objectForId(1), static_cast<QObject*>(0));
169 QObject *obj = new QObject;
170 int id = QDeclarativeDebugService::idForObject(obj);
171 QCOMPARE(QDeclarativeDebugService::objectForId(id), obj);
174 QCOMPARE(QDeclarativeDebugService::objectForId(id), static_cast<QObject*>(0));
177 void tst_QDeclarativeDebugService::objectToString()
179 QCOMPARE(QDeclarativeDebugService::objectToString(0), QString("NULL"));
181 QObject *obj = new QObject;
182 QCOMPARE(QDeclarativeDebugService::objectToString(obj), QString("QObject: <unnamed>"));
184 obj->setObjectName("Hello");
185 QCOMPARE(QDeclarativeDebugService::objectToString(obj), QString("QObject: Hello"));
190 int main(int argc, char *argv[])
192 int _argc = argc + 1;
193 char **_argv = new char*[_argc];
194 for (int i = 0; i < argc; ++i)
196 _argv[_argc - 1] = "-qmljsdebugger=port:13769";
198 QApplication app(_argc, _argv);
199 tst_QDeclarativeDebugService tc;
200 return QTest::qExec(&tc, _argc, _argv);
204 #include "tst_qdeclarativedebugservice.moc"