From 29beac9aa1daf9a044dc62e567283779e68b3724 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 8 Oct 2013 11:02:24 +0200 Subject: [PATCH] Improve output of test case Change-Id: Ib36583120ca42835534f0f8494637aeb9618f317 Reviewed-by: Aurindam Jana --- .../tst_qqmlprofilerservice.cpp | 12 ++++++++-- tests/auto/qml/debugger/shared/debugutil.cpp | 22 +++++++++++++++++- tests/auto/qml/debugger/shared/debugutil_p.h | 1 + tests/auto/qml/debugger/shared/qqmldebugclient.cpp | 26 ++++++++++++++++++++++ tests/auto/qml/debugger/shared/qqmldebugclient.h | 3 +++ 5 files changed, 61 insertions(+), 3 deletions(-) diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp index b6fab53..b9aefb3 100644 --- a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp +++ b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp @@ -323,8 +323,10 @@ void tst_QQmlProfilerService::connect(bool block, const QString &testFile) void tst_QQmlProfilerService::cleanup() { if (QTest::currentTestFailed()) { - qDebug() << "Process State:" << m_process->state(); - qDebug() << "Application Output:" << m_process->output(); + qDebug() << "Process State:" << (m_process ? m_process->state() : QLatin1String("null")); + qDebug() << "Application Output:" << (m_process ? m_process->output() : QLatin1String("null")); + qDebug() << "Connection State:" << (m_connection ? m_connection->stateString() : QLatin1String("null")); + qDebug() << "Client State:" << (m_client ? m_client->stateString() : QLatin1String("null")); } delete m_process; m_process = 0; @@ -337,6 +339,7 @@ void tst_QQmlProfilerService::cleanup() void tst_QQmlProfilerService::blockingConnectWithTraceEnabled() { connect(true, "test.qml"); + QVERIFY(m_client); QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setTraceState(true); @@ -356,6 +359,7 @@ void tst_QQmlProfilerService::blockingConnectWithTraceEnabled() void tst_QQmlProfilerService::blockingConnectWithTraceDisabled() { connect(true, "test.qml"); + QVERIFY(m_client); QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setTraceState(false); @@ -377,6 +381,7 @@ void tst_QQmlProfilerService::blockingConnectWithTraceDisabled() void tst_QQmlProfilerService::nonBlockingConnect() { connect(false, "test.qml"); + QVERIFY(m_client); QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setTraceState(true); @@ -395,6 +400,7 @@ void tst_QQmlProfilerService::nonBlockingConnect() void tst_QQmlProfilerService::pixmapCacheData() { connect(true, "pixmapCacheTest.qml"); + QVERIFY(m_client); QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setTraceState(true); @@ -440,6 +446,7 @@ void tst_QQmlProfilerService::pixmapCacheData() void tst_QQmlProfilerService::scenegraphData() { connect(true, "scenegraphTest.qml"); + QVERIFY(m_client); QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setTraceState(true); @@ -473,6 +480,7 @@ void tst_QQmlProfilerService::scenegraphData() void tst_QQmlProfilerService::profileOnExit() { connect(true, "exit.qml"); + QVERIFY(m_client); QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); m_client->setTraceState(true); diff --git a/tests/auto/qml/debugger/shared/debugutil.cpp b/tests/auto/qml/debugger/shared/debugutil.cpp index 99647cd..560c9ca 100644 --- a/tests/auto/qml/debugger/shared/debugutil.cpp +++ b/tests/auto/qml/debugger/shared/debugutil.cpp @@ -97,6 +97,8 @@ QQmlDebugProcess::QQmlDebugProcess(const QString &executable, QObject *parent) m_timer.setSingleShot(true); m_timer.setInterval(5000); connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(processAppOutput())); + connect(&m_process, SIGNAL(error(QProcess::ProcessError)), + this, SLOT(processError(QProcess::ProcessError))); connect(&m_timer, SIGNAL(timeout()), SLOT(timeout())); } @@ -161,7 +163,7 @@ void QQmlDebugProcess::stop() void QQmlDebugProcess::timeout() { qWarning() << "Timeout while waiting for QML debugging messages " - "in application output. Process is in state" << m_process.state() << "."; + "in application output. Process is in state" << m_process.state() << ", Output:" << m_output << "."; m_eventLoop.quit(); } @@ -246,3 +248,21 @@ void QQmlDebugProcess::processAppOutput() if (outputFromAppItself) emit readyReadStandardOutput(); } + +void QQmlDebugProcess::processError(QProcess::ProcessError error) +{ + if (!m_eventLoop.isRunning()) + return; + + qDebug() << "An error occurred while waiting for debug process to become available:"; + switch (error) { + case QProcess::FailedToStart: qDebug() << "Process failed to start."; break; + case QProcess::Crashed: qDebug() << "Process crashed."; break; + case QProcess::Timedout: qDebug() << "Process timed out."; break; + case QProcess::WriteError: qDebug() << "Error while writing to process."; break; + case QProcess::ReadError: qDebug() << "Error while reading from process."; break; + case QProcess::UnknownError: qDebug() << "Unknown process error."; break; + } + + m_eventLoop.exit(); +} diff --git a/tests/auto/qml/debugger/shared/debugutil_p.h b/tests/auto/qml/debugger/shared/debugutil_p.h index 9f9a852..8ac9f9a 100644 --- a/tests/auto/qml/debugger/shared/debugutil_p.h +++ b/tests/auto/qml/debugger/shared/debugutil_p.h @@ -107,6 +107,7 @@ signals: private slots: void timeout(); void processAppOutput(); + void processError(QProcess::ProcessError error); private: QString m_executable; diff --git a/tests/auto/qml/debugger/shared/qqmldebugclient.cpp b/tests/auto/qml/debugger/shared/qqmldebugclient.cpp index be30423..95674ce 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugclient.cpp +++ b/tests/auto/qml/debugger/shared/qqmldebugclient.cpp @@ -325,6 +325,23 @@ bool QQmlDebugConnection::waitForConnected(int msecs) return d->gotHello; } +QString QQmlDebugConnection::stateString() const +{ + QString state; + + if (isConnected()) + state = "Connected"; + else + state = "Not connected"; + + if (d->gotHello) + state += ", got hello"; + else + state += ", did not get hello!"; + + return state; +} + QAbstractSocket::SocketState QQmlDebugConnection::state() const { QAbstractSocket *socket = qobject_cast(d->device); @@ -425,6 +442,15 @@ QQmlDebugClient::State QQmlDebugClient::state() const return Unavailable; } +QString QQmlDebugClient::stateString() const +{ + switch (state()) { + case NotConnected: return QLatin1String("Not connected"); + case Unavailable: return QLatin1String("Unavailable"); + case Enabled: return QLatin1String("Enabled"); + } +} + void QQmlDebugClient::sendMessage(const QByteArray &message) { if (state() != Enabled) diff --git a/tests/auto/qml/debugger/shared/qqmldebugclient.h b/tests/auto/qml/debugger/shared/qqmldebugclient.h index fc0a80d..b5f5bdd 100644 --- a/tests/auto/qml/debugger/shared/qqmldebugclient.h +++ b/tests/auto/qml/debugger/shared/qqmldebugclient.h @@ -66,6 +66,8 @@ public: void close(); bool waitForConnected(int msecs = 30000); + QString stateString() const; + signals: void connected(); void stateChanged(QAbstractSocket::SocketState socketState); @@ -98,6 +100,7 @@ public: QString name() const; float serviceVersion() const; State state() const; + QString stateString() const; virtual void sendMessage(const QByteArray &); -- 2.7.4