1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "debugutil_p.h"
47 #include <private/qdeclarativedebugclient_p.h>
48 #include <private/qdeclarativedebugservice_p.h>
50 bool QDeclarativeDebugTest::waitForSignal(QObject *receiver, const char *member, int timeout) {
53 timer.setSingleShot(true);
54 QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
55 QObject::connect(receiver, member, &loop, SLOT(quit()));
58 return timer.isActive();
61 QDeclarativeDebugTestService::QDeclarativeDebugTestService(const QString &s, float version, QObject *parent)
62 : QDeclarativeDebugService(s, version, parent)
67 void QDeclarativeDebugTestService::messageReceived(const QByteArray &ba)
72 void QDeclarativeDebugTestService::statusChanged(Status)
74 emit statusHasChanged();
78 QDeclarativeDebugTestClient::QDeclarativeDebugTestClient(const QString &s, QDeclarativeDebugConnection *c)
79 : QDeclarativeDebugClient(s, c)
83 QByteArray QDeclarativeDebugTestClient::waitForResponse()
86 QDeclarativeDebugTest::waitForSignal(this, SIGNAL(serverMessage(QByteArray)));
87 if (lastMsg.isEmpty()) {
88 qWarning() << "tst_QDeclarativeDebugClient: no response from server!";
94 void QDeclarativeDebugTestClient::statusChanged(Status stat)
96 QCOMPARE(stat, status());
97 emit statusHasChanged();
100 void QDeclarativeDebugTestClient::messageReceived(const QByteArray &ba)
103 emit serverMessage(ba);
106 QDeclarativeDebugProcess::QDeclarativeDebugProcess(const QString &executable)
107 : m_executable(executable)
110 m_process.setProcessChannelMode(QProcess::MergedChannels);
111 m_timer.setSingleShot(true);
112 m_timer.setInterval(5000);
113 connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(processAppOutput()));
114 connect(&m_timer, SIGNAL(timeout()), &m_eventLoop, SLOT(quit()));
117 QDeclarativeDebugProcess::~QDeclarativeDebugProcess()
122 void QDeclarativeDebugProcess::start(const QStringList &arguments)
125 m_process.setEnvironment(m_environment);
126 m_process.start(m_executable, arguments);
127 m_process.waitForStarted();
132 void QDeclarativeDebugProcess::stop()
134 if (m_process.state() != QProcess::NotRunning) {
136 m_process.waitForFinished(5000);
140 bool QDeclarativeDebugProcess::waitForSessionStart()
142 if (m_process.state() != QProcess::Running) {
143 qWarning() << "Could not start up " << m_executable;
146 m_eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
151 void QDeclarativeDebugProcess::setEnvironment(const QStringList &environment)
153 m_environment = environment;
156 QString QDeclarativeDebugProcess::output() const
161 void QDeclarativeDebugProcess::processAppOutput()
165 QString newOutput = m_process.readAll();
166 m_output.append(newOutput);
167 m_outputBuffer.append(newOutput);
170 const int nlIndex = m_outputBuffer.indexOf(QLatin1Char('\n'));
171 if (nlIndex < 0) // no further complete lines
173 const QString line = m_outputBuffer.left(nlIndex);
174 m_outputBuffer = m_outputBuffer.right(m_outputBuffer.size() - nlIndex - 1);
176 if (line.startsWith("Qml debugging is enabled")) // ignore
178 if (line.startsWith("QDeclarativeDebugServer:")) {
179 if (line.contains("Waiting for connection ")) {
184 if (line.contains("Connection established")) {