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 bool QQmlDebugTest::waitForSignal(QObject *receiver, const char *member, int timeout) {
50 timer.setSingleShot(true);
51 QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
52 QObject::connect(receiver, member, &loop, SLOT(quit()));
55 return timer.isActive();
58 QQmlDebugTestService::QQmlDebugTestService(const QString &s, float version, QObject *parent)
59 : QQmlDebugService(s, version, parent)
64 void QQmlDebugTestService::messageReceived(const QByteArray &ba)
69 void QQmlDebugTestService::stateChanged(State)
71 emit stateHasChanged();
75 QQmlDebugTestClient::QQmlDebugTestClient(const QString &s, QQmlDebugConnection *c)
76 : QQmlDebugClient(s, c)
80 QByteArray QQmlDebugTestClient::waitForResponse()
83 QQmlDebugTest::waitForSignal(this, SIGNAL(serverMessage(QByteArray)));
84 if (lastMsg.isEmpty()) {
85 qWarning() << "tst_QQmlDebugTestClient: no response from server!";
91 void QQmlDebugTestClient::stateChanged(State stat)
93 QCOMPARE(stat, state());
94 emit stateHasChanged();
97 void QQmlDebugTestClient::messageReceived(const QByteArray &ba)
100 emit serverMessage(ba);
103 QQmlDebugProcess::QQmlDebugProcess(const QString &executable)
104 : m_executable(executable)
107 m_process.setProcessChannelMode(QProcess::MergedChannels);
108 m_timer.setSingleShot(true);
109 m_timer.setInterval(5000);
110 connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(processAppOutput()));
111 connect(&m_timer, SIGNAL(timeout()), &m_eventLoop, SLOT(quit()));
114 QQmlDebugProcess::~QQmlDebugProcess()
119 void QQmlDebugProcess::start(const QStringList &arguments)
122 m_process.setEnvironment(m_environment);
123 m_process.start(m_executable, arguments);
124 m_process.waitForStarted();
129 void QQmlDebugProcess::stop()
131 if (m_process.state() != QProcess::NotRunning) {
133 m_process.waitForFinished(5000);
137 bool QQmlDebugProcess::waitForSessionStart()
139 if (m_process.state() != QProcess::Running) {
140 qWarning() << "Could not start up " << m_executable;
143 m_eventLoop.exec(QEventLoop::ExcludeUserInputEvents);
148 void QQmlDebugProcess::setEnvironment(const QStringList &environment)
150 m_environment = environment;
153 QString QQmlDebugProcess::output() const
158 void QQmlDebugProcess::processAppOutput()
162 QString newOutput = m_process.readAll();
163 m_output.append(newOutput);
164 m_outputBuffer.append(newOutput);
167 const int nlIndex = m_outputBuffer.indexOf(QLatin1Char('\n'));
168 if (nlIndex < 0) // no further complete lines
170 const QString line = m_outputBuffer.left(nlIndex);
171 m_outputBuffer = m_outputBuffer.right(m_outputBuffer.size() - nlIndex - 1);
173 if (line.startsWith("QML debugging is enabled")) // ignore
175 if (line.startsWith("QML Debugger:")) {
176 if (line.contains("Waiting for connection ")) {
181 if (line.contains("Connection established.")) {