1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
45 #include <QHostAddress>
48 #include <QtCore/QLibraryInfo>
50 #include "../shared/debugutil_p.h"
51 #include "../../../shared/util.h"
52 #include "qqmlinspectorclient.h"
53 #include "qqmlenginedebugclient.h"
56 #define STR_PORT "3776"
58 class tst_QQmlEngineDebugInspectorIntegration : public QQmlDataTest
63 tst_QQmlEngineDebugInspectorIntegration()
66 , m_inspectorClient(0)
67 , m_engineDebugClient(0)
73 QmlDebugObjectReference findRootObject();
75 QQmlDebugProcess *m_process;
76 QQmlDebugConnection *m_connection;
77 QQmlInspectorClient *m_inspectorClient;
78 QQmlEngineDebugClient *m_engineDebugClient;
85 void clearObjectReferenceHashonReloadQml();
89 QmlDebugObjectReference tst_QQmlEngineDebugInspectorIntegration::findRootObject()
92 m_engineDebugClient->queryAvailableEngines(&success);
94 QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()));
96 m_engineDebugClient->queryRootContexts(m_engineDebugClient->engines()[0].debugId, &success);
97 QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()));
98 int count = m_engineDebugClient->rootContext().contexts.count();
99 m_engineDebugClient->queryObject(
100 m_engineDebugClient->rootContext().contexts[count - 1].objects[0], &success);
101 QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()));
102 return m_engineDebugClient->object();
106 void tst_QQmlEngineDebugInspectorIntegration::init()
108 const QString argument = "-qmljsdebugger=port:" STR_PORT ",block";
110 m_process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath)
112 m_process->start(QStringList() << argument << testFile("qtquick2.qml"));
113 QVERIFY2(m_process->waitForSessionStart(),
114 "Could not launch application, or did not get 'Waiting for connection'.");
116 QQmlDebugConnection *m_connection = new QQmlDebugConnection(this);
117 m_inspectorClient = new QQmlInspectorClient(m_connection);
118 m_engineDebugClient = new QQmlEngineDebugClient(m_connection);
120 m_connection->connectToHost(QLatin1String("127.0.0.1"), PORT);
121 bool ok = m_connection->waitForConnected();
125 void tst_QQmlEngineDebugInspectorIntegration::cleanup()
127 if (QTest::currentTestFailed()) {
128 qDebug() << "Process State:" << m_process->state();
129 qDebug() << "Application Output:" << m_process->output();
132 delete m_engineDebugClient;
133 delete m_inspectorClient;
136 void tst_QQmlEngineDebugInspectorIntegration::connect()
138 QTRY_COMPARE(m_inspectorClient->state(), QQmlDebugClient::Enabled);
139 QTRY_COMPARE(m_engineDebugClient->state(), QQmlDebugClient::Enabled);
142 void tst_QQmlEngineDebugInspectorIntegration::clearObjectReferenceHashonReloadQml()
144 QTRY_COMPARE(m_engineDebugClient->state(), QQmlDebugClient::Enabled);
145 bool success = false;
146 QmlDebugObjectReference rootObject = findRootObject();
147 const QString fileName = QFileInfo(rootObject.source.url.toString()).fileName();
148 int lineNumber = rootObject.source.lineNumber;
149 int columnNumber = rootObject.source.columnNumber;
150 m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber,
151 columnNumber, &success);
153 QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())));
155 foreach (QmlDebugObjectReference child, rootObject.children) {
157 lineNumber = child.source.lineNumber;
158 columnNumber = child.source.columnNumber;
159 m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber,
160 columnNumber, &success);
162 QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())));
165 QTRY_COMPARE(m_inspectorClient->state(), QQmlDebugClient::Enabled);
168 contents.append("import QtQuick 2.0\n"
174 QHash<QString, QByteArray> changesHash;
175 changesHash.insert("test.qml", contents);
176 m_inspectorClient->reloadQml(changesHash);
177 QVERIFY(QQmlDebugTest::waitForSignal(m_inspectorClient, SIGNAL(responseReceived())));
179 lineNumber = rootObject.source.lineNumber;
180 columnNumber = rootObject.source.columnNumber;
182 m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber,
183 columnNumber, &success);
185 QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())));
187 foreach (QmlDebugObjectReference child, rootObject.children) {
189 lineNumber = child.source.lineNumber;
190 columnNumber = child.source.columnNumber;
191 m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber,
192 columnNumber, &success);
194 QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())));
198 QTEST_MAIN(tst_QQmlEngineDebugInspectorIntegration)
200 #include "tst_qqmlenginedebuginspectorintegration.moc"