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/qqmldebugclient_p.h>
48 #include <private/qqmldebugservice_p.h>
50 bool QQmlDebugTest::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 QQmlDebugTestService::QQmlDebugTestService(const QString &s, float version, QObject *parent)
62 : QQmlDebugService(s, version, parent)
67 void QQmlDebugTestService::messageReceived(const QByteArray &ba)
72 void QQmlDebugTestService::stateChanged(State)
74 emit stateHasChanged();
78 QQmlDebugTestClient::QQmlDebugTestClient(const QString &s, QQmlDebugConnection *c)
79 : QQmlDebugClient(s, c)
83 QByteArray QQmlDebugTestClient::waitForResponse()
86 QQmlDebugTest::waitForSignal(this, SIGNAL(serverMessage(QByteArray)));
87 if (lastMsg.isEmpty()) {
88 qWarning() << "tst_QQmlDebugTestClient: no response from server!";
94 void QQmlDebugTestClient::stateChanged(State stat)
96 QCOMPARE(stat, state());
97 emit stateHasChanged();
100 void QQmlDebugTestClient::messageReceived(const QByteArray &ba)
103 emit serverMessage(ba);
106 QQmlDebugProcess::QQmlDebugProcess(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 QQmlDebugProcess::~QQmlDebugProcess()
122 void QQmlDebugProcess::start(const QStringList &arguments)
125 m_process.setEnvironment(m_environment);
126 m_process.start(m_executable, arguments);
127 m_process.waitForStarted();
132 void QQmlDebugProcess::stop()
134 if (m_process.state() != QProcess::NotRunning) {
136 m_process.waitForFinished(5000);
140 bool QQmlDebugProcess::waitForSessionStart()
142 if (m_process.state() != QProcess::Running) {
143 qWarning() << "Could not start up " << m_executable;
146 m_eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
151 void QQmlDebugProcess::setEnvironment(const QStringList &environment)
153 m_environment = environment;
156 QString QQmlDebugProcess::output() const
161 void QQmlDebugProcess::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("QML Debugger:")) {
179 if (line.contains("Waiting for connection ")) {
184 if (line.contains("Connection established.")) {