/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
**
** This file is part of the test suite of the Qt Toolkit.
**
**
**
**
+**
** $QT_END_LICENSE$
**
****************************************************************************/
public:
tst_QDebugMessageService();
+ void init(bool extendedOutput);
+
private slots:
void initTestCase();
void cleanupTestCase();
- void init();
void cleanup();
void retrieveDebugOutput();
+ void retrieveDebugOutputExtended();
private:
QDeclarativeDebugProcess *m_process;
QString toString() const { return QString::number(type) + ": " + message; }
};
+bool operator==(const LogEntry &t1, const LogEntry &t2)
+{
+ return t1.type == t2.type && t1.message == t2.message;
+}
+
class QDeclarativeDebugMsgClient : public QDeclarativeDebugClient
{
Q_OBJECT
protected:
//inherited from QDeclarativeDebugClient
- void statusChanged(Status status);
+ void stateChanged(State state);
void messageReceived(const QByteArray &data);
signals:
void debugOutput();
};
-void QDeclarativeDebugMsgClient::statusChanged(Status status)
+void QDeclarativeDebugMsgClient::stateChanged(State state)
{
- if (status == Enabled) {
+ if (state == Enabled) {
emit enabled();
}
}
ds >> command;
if (command == "MESSAGE") {
- QByteArray container;
- ds >> container;
-
- QVERIFY(ds.atEnd());
-
- QDataStream containerDs(container);
int type;
QByteArray message;
- containerDs >> type >> message;
- QVERIFY(containerDs.atEnd());
+ ds >> type >> message;
+ QVERIFY(ds.atEnd());
QVERIFY(type >= QtDebugMsg);
QVERIFY(type <= QtFatalMsg);
delete m_connection;
}
-void tst_QDebugMessageService::init()
+void tst_QDebugMessageService::init(bool extendedOutput)
{
m_connection = new QDeclarativeDebugConnection();
m_process = new QDeclarativeDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene");
m_client = new QDeclarativeDebugMsgClient(m_connection);
- m_process->setEnvironment(QProcess::systemEnvironment() << "QML_CONSOLE_EXTENDED=1");
+ if (extendedOutput)
+ m_process->setEnvironment(QProcess::systemEnvironment() << "QML_CONSOLE_EXTENDED=1");
m_process->start(QStringList() << QLatin1String(NORMALMODE) << QDeclarativeDataTest::instance()->testFile(QMLFILE));
if (!m_process->waitForSessionStart()) {
QFAIL(QString("Could not launch app. Application output: \n%1").arg(m_process->output()).toAscii());
void tst_QDebugMessageService::retrieveDebugOutput()
{
- if (m_client->logBuffer.isEmpty())
- QDeclarativeDebugTest::waitForSignal(m_client, SIGNAL(debugOutput()));
- QVERIFY(!m_client->logBuffer.isEmpty());
+ init(false);
+
+ int maxTries = 2;
+ while ((m_client->logBuffer.size() < 2)
+ || (maxTries-- > 0))
+ QDeclarativeDebugTest::waitForSignal(m_client, SIGNAL(debugOutput()), 1000);
+
+ QVERIFY(m_client->logBuffer.size() >= 2);
+
+ QVERIFY(m_client->logBuffer.contains(LogEntry(QtDebugMsg, QLatin1String("console.log"))));
+ QVERIFY(m_client->logBuffer.contains(LogEntry(QtDebugMsg, QLatin1String("console.count: 1"))));
+}
+
+void tst_QDebugMessageService::retrieveDebugOutputExtended()
+{
+ init(true);
+
+ int maxTries = 2;
+ while ((m_client->logBuffer.size() < 2)
+ || (maxTries-- > 0))
+ QDeclarativeDebugTest::waitForSignal(m_client, SIGNAL(debugOutput()), 1000);
+
+ QVERIFY(m_client->logBuffer.size() >= 2);
+
+ const QString path =
+ QUrl::fromLocalFile(QDeclarativeDataTest::instance()->testFile(QMLFILE)).toString();
+ QString logMsg = QString::fromLatin1("console.log (%1:%2)").arg(path).arg(48);
+ QString countMsg = QString::fromLatin1("console.count: 1 (%1:%2)").arg(path).arg(49);
- QString msg = QString::fromLatin1("console.log (%1:%2)").arg(
- QUrl::fromLocalFile(QDeclarativeDataTest::instance()->testFile(QMLFILE)).toString()).arg(48);
- QCOMPARE(m_client->logBuffer.last().toString(),
- LogEntry(QtDebugMsg, msg).toString());
+ QVERIFY(m_client->logBuffer.contains(LogEntry(QtDebugMsg, logMsg)));
+ QVERIFY(m_client->logBuffer.contains(LogEntry(QtDebugMsg, countMsg)));
}
QTEST_MAIN(tst_QDebugMessageService)