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/qmldbg_inspector/qdeclarativeinspectorprotocol.h"
49 #include "../../../../shared/util.h"
50 #include "../shared/debugutil_p.h"
52 using namespace QmlJSDebugger;
55 #define STR_PORT "13772"
57 class QDeclarativeInspectorClient : public QDeclarativeDebugClient
62 QDeclarativeInspectorClient(QDeclarativeDebugConnection *connection)
63 : QDeclarativeDebugClient(QLatin1String("QDeclarativeObserverMode"), connection)
64 , m_showAppOnTop(false)
68 bool showAppOnTop() const { return m_showAppOnTop; }
69 void setShowAppOnTop(bool showOnTop);
72 void showAppOnTopChanged();
75 void messageReceived(const QByteArray &message);
81 class tst_QDeclarativeInspector : public QObject
86 tst_QDeclarativeInspector()
95 QDeclarativeDebugProcess *m_process;
96 QDeclarativeDebugConnection *m_connection;
97 QDeclarativeInspectorClient *m_client;
101 void cleanupTestCase();
110 void QDeclarativeInspectorClient::setShowAppOnTop(bool showOnTop)
113 QDataStream ds(&message, QIODevice::WriteOnly);
114 ds << InspectorProtocol::ShowAppOnTop << showOnTop;
116 sendMessage(message);
119 void QDeclarativeInspectorClient::messageReceived(const QByteArray &message)
121 QDataStream ds(message);
122 InspectorProtocol::Message type;
126 case InspectorProtocol::ShowAppOnTop:
127 ds >> m_showAppOnTop;
128 emit showAppOnTopChanged();
131 qDebug() << "Unhandled message " << (int)type;
135 void tst_QDeclarativeInspector::initTestCase()
139 void tst_QDeclarativeInspector::cleanupTestCase()
143 void tst_QDeclarativeInspector::init()
145 const QString executable = SRCDIR"/app/app";
146 const QString argument = "-qmljsdebugger=port:"STR_PORT",block";
148 m_process = new QDeclarativeDebugProcess(executable);
149 m_process->start(QStringList() << argument);
150 if (!m_process->waitForSessionStart()) {
151 QFAIL(QString("Could not launch app '%1'.\nApplication output:\n%2").arg(executable, m_process->output()).toAscii());
154 QDeclarativeDebugConnection *m_connection = new QDeclarativeDebugConnection();
155 m_client = new QDeclarativeInspectorClient(m_connection);
157 m_connection->connectToHost(QLatin1String("127.0.0.1"), PORT);
160 void tst_QDeclarativeInspector::cleanup()
167 void tst_QDeclarativeInspector::connect()
169 QTRY_COMPARE(m_client->status(), QDeclarativeDebugClient::Enabled);
172 void tst_QDeclarativeInspector::showAppOnTop()
174 QTRY_COMPARE(m_client->status(), QDeclarativeDebugClient::Enabled);
176 m_client->setShowAppOnTop(true);
177 QVERIFY(QDeclarativeDebugTest::waitForSignal(m_client, SIGNAL(showAppOnTopChanged())));
178 QCOMPARE(m_client->showAppOnTop(), true);
180 m_client->setShowAppOnTop(false);
181 QVERIFY(QDeclarativeDebugTest::waitForSignal(m_client, SIGNAL(showAppOnTopChanged())));
182 QCOMPARE(m_client->showAppOnTop(), false);
185 QTEST_MAIN(tst_QDeclarativeInspector)
187 #include "tst_qdeclarativeinspector.moc"