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 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 #include <QHostAddress>
48 #include "../../../../../src/plugins/qmltooling/shared/qdeclarativeinspectorprotocol.h"
49 #include "../shared/debugutil_p.h"
51 using namespace QmlJSDebugger;
54 #define STR_PORT "13772"
56 class QDeclarativeInspectorClient : public QDeclarativeDebugClient
61 QDeclarativeInspectorClient(QDeclarativeDebugConnection *connection)
62 : QDeclarativeDebugClient(QLatin1String("QDeclarativeObserverMode"), connection)
63 , m_showAppOnTop(false)
67 bool showAppOnTop() const { return m_showAppOnTop; }
68 void setShowAppOnTop(bool showOnTop);
71 void showAppOnTopChanged();
74 void messageReceived(const QByteArray &message);
80 class tst_QDeclarativeInspector : public QObject
85 tst_QDeclarativeInspector()
94 QDeclarativeDebugProcess *m_process;
95 QDeclarativeDebugConnection *m_connection;
96 QDeclarativeInspectorClient *m_client;
100 void cleanupTestCase();
109 void QDeclarativeInspectorClient::setShowAppOnTop(bool showOnTop)
112 QDataStream ds(&message, QIODevice::WriteOnly);
113 ds << InspectorProtocol::ShowAppOnTop << showOnTop;
115 sendMessage(message);
118 void QDeclarativeInspectorClient::messageReceived(const QByteArray &message)
120 QDataStream ds(message);
121 InspectorProtocol::Message type;
125 case InspectorProtocol::ShowAppOnTop:
126 ds >> m_showAppOnTop;
127 emit showAppOnTopChanged();
130 qDebug() << "Unhandled message " << (int)type;
134 void tst_QDeclarativeInspector::initTestCase()
138 void tst_QDeclarativeInspector::cleanupTestCase()
142 void tst_QDeclarativeInspector::init()
144 const QString executable = SRCDIR"/app/app";
145 const QString argument = "-qmljsdebugger=port:"STR_PORT",block";
147 m_process = new QDeclarativeDebugProcess(executable);
148 m_process->start(QStringList() << argument);
149 if (!m_process->waitForSessionStart()) {
150 QFAIL(QString("Could not launch app '%1'.\nApplication output:\n%2").arg(executable, m_process->output()).toAscii());
153 QDeclarativeDebugConnection *m_connection = new QDeclarativeDebugConnection();
154 m_client = new QDeclarativeInspectorClient(m_connection);
156 m_connection->connectToHost(QLatin1String("127.0.0.1"), PORT);
159 void tst_QDeclarativeInspector::cleanup()
166 void tst_QDeclarativeInspector::connect()
168 QTRY_COMPARE(m_client->status(), QDeclarativeDebugClient::Enabled);
171 void tst_QDeclarativeInspector::showAppOnTop()
173 QTRY_COMPARE(m_client->status(), QDeclarativeDebugClient::Enabled);
175 m_client->setShowAppOnTop(true);
176 QVERIFY(QDeclarativeDebugTest::waitForSignal(m_client, SIGNAL(showAppOnTopChanged())));
177 QCOMPARE(m_client->showAppOnTop(), true);
179 m_client->setShowAppOnTop(false);
180 QVERIFY(QDeclarativeDebugTest::waitForSignal(m_client, SIGNAL(showAppOnTopChanged())));
181 QCOMPARE(m_client->showAppOnTop(), false);
184 QTEST_MAIN(tst_QDeclarativeInspector)
186 #include "tst_qdeclarativeinspector.moc"