From 04f06f35a99cf83dd573718816a016345aa439dc Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Mon, 16 Jan 2012 13:35:07 +0100 Subject: [PATCH] Console API: Autotest reshuffling Move the console tests from qdeclarativeqt to qdeclarativeconsole, and the test for the QML_CONSOLE_EXTENDED property to debugger/qdebugmessageservice. Change-Id: I704bd0a4a28aa1b0eb51df67d32fd6865b114d41 Reviewed-by: Aurindam Jana --- .../debugger/qdebugmessageservice/data/test.qml | 5 +- .../tst_qdebugmessageservice.cpp | 46 ++++++++++-- .../qdeclarativeconsole/data/consoleLog.qml | 32 -------- .../qdeclarativeconsole/data/logging.qml | 80 ++++++++++++++++++++ .../qdeclarativeconsole/data/profiling.qml | 51 +++++++++++++ .../qdeclarativeconsole/data/tracing.qml | 56 ++++++++++++++ .../tst_qdeclarativeconsole.cpp | 85 +++++++++++++--------- .../declarative/qdeclarativeqt/data/console.qml | 36 --------- .../qdeclarativeqt/tst_qdeclarativeqt.cpp | 35 --------- 9 files changed, 277 insertions(+), 149 deletions(-) delete mode 100644 tests/auto/declarative/qdeclarativeconsole/data/consoleLog.qml create mode 100644 tests/auto/declarative/qdeclarativeconsole/data/logging.qml create mode 100644 tests/auto/declarative/qdeclarativeconsole/data/profiling.qml create mode 100644 tests/auto/declarative/qdeclarativeconsole/data/tracing.qml delete mode 100644 tests/auto/declarative/qdeclarativeqt/data/console.qml diff --git a/tests/auto/declarative/debugger/qdebugmessageservice/data/test.qml b/tests/auto/declarative/debugger/qdebugmessageservice/data/test.qml index 7377d45..f4c576c 100644 --- a/tests/auto/declarative/debugger/qdebugmessageservice/data/test.qml +++ b/tests/auto/declarative/debugger/qdebugmessageservice/data/test.qml @@ -44,8 +44,7 @@ import QtQuick 2.0 Item { width: 360 height: 360 - Timer { - interval: 100; running: true; repeat: true - onTriggered: console.log("Timer") + Component.onCompleted: { + console.log("console.log") } } diff --git a/tests/auto/declarative/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp b/tests/auto/declarative/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp index 62f89e9..f138cb2 100644 --- a/tests/auto/declarative/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp +++ b/tests/auto/declarative/debugger/qdebugmessageservice/tst_qdebugmessageservice.cpp @@ -48,7 +48,7 @@ #include #include -const char *NORMALMODE = "-qmljsdebugger=port:3777"; +const char *NORMALMODE = "-qmljsdebugger=port:3777,block"; const char *QMLFILE = "test.qml"; class QDeclarativeDebugMsgClient; @@ -74,6 +74,16 @@ private: QDeclarativeDebugConnection *m_connection; }; +struct LogEntry { + LogEntry(QtMsgType _type, QString _message) + : type(_type), message(_message) {} + + QtMsgType type; + QString message; + + QString toString() const { return QString::number(type) + ": " + message; } +}; + class QDeclarativeDebugMsgClient : public QDeclarativeDebugClient { Q_OBJECT @@ -83,6 +93,8 @@ public: { } + QList logBuffer; + protected: //inherited from QDeclarativeDebugClient void statusChanged(Status status); @@ -91,9 +103,6 @@ protected: signals: void enabled(); void debugOutput(); - -public: - QByteArray debugMessage; }; void QDeclarativeDebugMsgClient::statusChanged(Status status) @@ -110,9 +119,24 @@ void QDeclarativeDebugMsgClient::messageReceived(const QByteArray &data) ds >> command; if (command == "MESSAGE") { + QByteArray container; + ds >> container; + + QVERIFY(ds.atEnd()); + + QDataStream containerDs(container); int type; - ds >> type >> debugMessage; + QByteArray message; + containerDs >> type >> message; + QVERIFY(containerDs.atEnd()); + + QVERIFY(type >= QtDebugMsg); + QVERIFY(type <= QtFatalMsg); + + logBuffer << LogEntry((QtMsgType)type, QString::fromUtf8(message)); emit debugOutput(); + } else { + QFAIL("Unknown message"); } } @@ -146,6 +170,7 @@ void tst_QDebugMessageService::init() m_process = new QDeclarativeDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene"); m_client = new QDeclarativeDebugMsgClient(m_connection); + 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()); @@ -177,8 +202,15 @@ void tst_QDebugMessageService::cleanup() void tst_QDebugMessageService::retrieveDebugOutput() { - if (m_client->debugMessage.isEmpty()) - QVERIFY(QDeclarativeDebugTest::waitForSignal(m_client, SIGNAL(debugOutput()))); + if (m_client->logBuffer.isEmpty()) + QDeclarativeDebugTest::waitForSignal(m_client, SIGNAL(debugOutput())); + QVERIFY(!m_client->logBuffer.isEmpty()); + + + 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()); } QTEST_MAIN(tst_QDebugMessageService) diff --git a/tests/auto/declarative/qdeclarativeconsole/data/consoleLog.qml b/tests/auto/declarative/qdeclarativeconsole/data/consoleLog.qml deleted file mode 100644 index 2692abb..0000000 --- a/tests/auto/declarative/qdeclarativeconsole/data/consoleLog.qml +++ /dev/null @@ -1,32 +0,0 @@ -import QtQuick 2.0 - -QtObject { - id: root - Component.onCompleted: { - var a = [1, 2] - var b = {a: "hello", d: 1 } - var c - var d = 12 - var e = function() { return 5;} - var f = true - var g = {toString: function() { throw new Error('toString'); }} - - - console.log("completed", "ok") - console.log("completed ok") - console.debug("completed ok") - console.warn("completed ok") - console.error("completed ok") - console.log(a) - console.log(b) - console.log(c) - console.log(d) - console.log(e) - console.log(f) - console.log(root) - console.log(g) - console.log(1, "pong!", new Object) - console.log(1, ["ping","pong"], new Object, 2) - console.log(exception) //This has to be at the end - } -} diff --git a/tests/auto/declarative/qdeclarativeconsole/data/logging.qml b/tests/auto/declarative/qdeclarativeconsole/data/logging.qml new file mode 100644 index 0000000..3b3f946 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeconsole/data/logging.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +import QtQuick 2.0 + +QtObject { + id:root + Component.onCompleted: { + console.debug("console.debug"); + console.log("console.log"); + console.warn("console.warn"); + console.error("console.error"); + + var a = [1, 2]; + var b = {a: "hello", d: 1 }; + var c + var d = 12; + var e = function() { return 5;}; + var f = true; + var g = {toString: function() { throw new Error('toString'); }}; + + console.log(a); + console.log(b); + console.log(c); + console.log(d); + console.log(e); + console.log(f); + console.log(root); + console.log(g); + console.log(1, "pong!", new Object); + console.log(1, ["ping","pong"], new Object, 2); + + try { + console.log(exception); + } catch (e) { + return; + } + + throw ("console.log(exception) should have raised an exception"); + } +} diff --git a/tests/auto/declarative/qdeclarativeconsole/data/profiling.qml b/tests/auto/declarative/qdeclarativeconsole/data/profiling.qml new file mode 100644 index 0000000..cf69231 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeconsole/data/profiling.qml @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +QtObject { + Component.onCompleted: { + console.profile("profile1"); + console.time("timer1"); + console.timeEnd("timer1"); + console.profileEnd("profile1"); + } +} diff --git a/tests/auto/declarative/qdeclarativeconsole/data/tracing.qml b/tests/auto/declarative/qdeclarativeconsole/data/tracing.qml new file mode 100644 index 0000000..298d7d9 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeconsole/data/tracing.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +// moving lines in here requires fixing tst_qdeclarativeconsole.cpp +QtObject { + id: root + + function tracing() + { + console.trace(); + } + + Component.onCompleted: { + tracing(); + } +} diff --git a/tests/auto/declarative/qdeclarativeconsole/tst_qdeclarativeconsole.cpp b/tests/auto/declarative/qdeclarativeconsole/tst_qdeclarativeconsole.cpp index da725dd..48e9481 100644 --- a/tests/auto/declarative/qdeclarativeconsole/tst_qdeclarativeconsole.cpp +++ b/tests/auto/declarative/qdeclarativeconsole/tst_qdeclarativeconsole.cpp @@ -51,51 +51,49 @@ public: tst_qdeclarativeconsole() {} private slots: - void init(); - void consoleLogExtended(); + void logging(); + void tracing(); + void profiling(); private: QDeclarativeEngine engine; }; -void tst_qdeclarativeconsole::init() +void tst_qdeclarativeconsole::logging() { - qputenv("QML_CONSOLE_EXTENDED", QByteArray("1")); + QUrl testUrl = testFileUrl("logging.qml"); + + QTest::ignoreMessage(QtDebugMsg, "console.debug"); + QTest::ignoreMessage(QtDebugMsg, "console.log"); + QTest::ignoreMessage(QtWarningMsg, "console.warn"); + QTest::ignoreMessage(QtCriticalMsg, "console.error"); + + QTest::ignoreMessage(QtDebugMsg, "[1,2]"); + QTest::ignoreMessage(QtDebugMsg, "Object"); + QTest::ignoreMessage(QtDebugMsg, "undefined"); + QTest::ignoreMessage(QtDebugMsg, "12"); + QTest::ignoreMessage(QtDebugMsg, "function () { return 5;}"); + QTest::ignoreMessage(QtDebugMsg, "true"); + QTest::ignoreMessage(QtDebugMsg, "Object"); + QTest::ignoreMessage(QtDebugMsg, "Object"); + QTest::ignoreMessage(QtDebugMsg, "1 pong! Object"); + QTest::ignoreMessage(QtDebugMsg, "1 [ping,pong] Object 2"); + + + QDeclarativeComponent component(&engine, testUrl); + QObject *object = component.create(); + QVERIFY(object != 0); + delete object; } -void tst_qdeclarativeconsole::consoleLogExtended() +void tst_qdeclarativeconsole::tracing() { - int startLineNumber = 15; - QUrl testUrl = testFileUrl("consoleLog.qml"); - const QString testUrlString = testUrl.toString(); - QString testString = QString(QLatin1String("completed ok (%1:%2)")).arg(testUrlString); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testString.arg(startLineNumber++))); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testString.arg(startLineNumber++))); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testString.arg(startLineNumber++))); - QTest::ignoreMessage(QtWarningMsg, qPrintable(testString.arg(startLineNumber++))); - QTest::ignoreMessage(QtCriticalMsg, qPrintable(testString.arg(startLineNumber++))); - - QString testArray = QString(QLatin1String("[1,2] (%1:%2)")).arg(testUrlString); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testArray.arg(startLineNumber++))); - QString testObject = QString(QLatin1String("Object (%1:%2)")).arg(testUrlString); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testObject.arg(startLineNumber++))); - QString testUndefined = QString(QLatin1String("undefined (%1:%2)")).arg(testUrlString); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testUndefined.arg(startLineNumber++))); - QString testNumber = QString(QLatin1String("12 (%1:%2)")).arg(testUrlString); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testNumber.arg(startLineNumber++))); - QString testFunction = QString(QLatin1String("function () { return 5;} (%1:%2)")).arg(testUrlString); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testFunction.arg(startLineNumber++))); - QString testBoolean = QString(QLatin1String("true (%1:%2)")).arg(testUrlString); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testBoolean.arg(startLineNumber++))); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testObject.arg(startLineNumber++))); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testObject.arg(startLineNumber++))); - QString testMix = QString::fromLatin1("1 pong! Object (%1:%2)").arg(testUrlString); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testMix.arg(startLineNumber++))); - testMix = QString::fromLatin1("1 [ping,pong] Object 2 (%1:%2)").arg(testUrlString); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testMix.arg(startLineNumber++))); - - QString testException = QString(QLatin1String("%1:%2: ReferenceError: Can't find variable: exception")).arg(testUrlString); - QTest::ignoreMessage(QtWarningMsg, qPrintable(testException.arg(startLineNumber++))); + QUrl testUrl = testFileUrl("tracing.qml"); + + QString trace1 = QString::fromLatin1("tracing (%1:%2:%3)\n").arg(testUrl.toString()).arg(50).arg(17); + QString trace2 = QString::fromLatin1("onCompleted (%1:%2:%3)\n").arg(testUrl.toString()).arg(54).arg(9); + QTest::ignoreMessage(QtDebugMsg, qPrintable(trace1)); + QTest::ignoreMessage(QtDebugMsg, qPrintable(trace2)); QDeclarativeComponent component(&engine, testUrl); QObject *object = component.create(); @@ -103,6 +101,21 @@ void tst_qdeclarativeconsole::consoleLogExtended() delete object; } +void tst_qdeclarativeconsole::profiling() +{ + QUrl testUrl = testFileUrl("profiling.qml"); + + // profiling() + QTest::ignoreMessage(QtDebugMsg, "Profiling started."); + QTest::ignoreMessage(QtDebugMsg, "Profiling ended."); + + QDeclarativeComponent component(&engine, testUrl); + QObject *object = component.create(); + QVERIFY(object != 0); + delete object; +} + + QTEST_MAIN(tst_qdeclarativeconsole) #include "tst_qdeclarativeconsole.moc" diff --git a/tests/auto/declarative/qdeclarativeqt/data/console.qml b/tests/auto/declarative/qdeclarativeqt/data/console.qml deleted file mode 100644 index 634239c..0000000 --- a/tests/auto/declarative/qdeclarativeqt/data/console.qml +++ /dev/null @@ -1,36 +0,0 @@ -import QtQuick 2.0 - -QtObject { - id: root - Component.onCompleted: { - var a = [1, 2] - var b = {a: "hello", d: 1 } - var c - var d = 12 - var e = function() { return 5;} - var f = true - var g = {toString: function() { throw new Error('toString'); }} - - console.profile("profile1") - console.time("timer1") - console.log("completed", "ok") - console.log("completed ok") - console.debug("completed ok") - console.warn("completed ok") - console.error("completed ok") - console.log(a) - console.log(b) - console.log(c) - console.log(d) - console.log(e) - console.log(f) - console.log(root) - console.log(g) - console.log(1, "pong!", new Object) - console.log(1, ["ping","pong"], new Object, 2) - console.trace() - console.timeEnd("timer1") - console.profileEnd("profile1") - console.log(exception) //This has to be at the end - } -} diff --git a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp index 6a03af5..2734792 100644 --- a/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp +++ b/tests/auto/declarative/qdeclarativeqt/tst_qdeclarativeqt.cpp @@ -78,7 +78,6 @@ private slots: void createComponent(); void createComponent_pragmaLibrary(); void createQmlObject(); - void console(); void dateTimeConversion(); void dateTimeFormatting(); void dateTimeFormatting_data(); @@ -453,40 +452,6 @@ void tst_qdeclarativeqt::createQmlObject() delete object; } -void tst_qdeclarativeqt::console() -{ - QUrl testUrl = testFileUrl("console.qml"); - QString testException = QString(QLatin1String("%1:%2: ReferenceError: Can't find variable: exception")).arg(testUrl.toString()).arg(34); - QString testTrace = QString(QLatin1String("onCompleted (%1:%2:%3)\n")).arg(testUrl.toString()).arg(31).arg(17); - QTest::ignoreMessage(QtDebugMsg, qPrintable(testTrace)); - QTest::ignoreMessage(QtDebugMsg, "Profiling started."); - QTest::ignoreMessage(QtDebugMsg, "Profiling ended."); - QTest::ignoreMessage(QtDebugMsg, "completed ok"); - QTest::ignoreMessage(QtDebugMsg, "completed ok"); - QTest::ignoreMessage(QtDebugMsg, "completed ok"); - QTest::ignoreMessage(QtWarningMsg, "completed ok"); - QTest::ignoreMessage(QtCriticalMsg, "completed ok"); - - QTest::ignoreMessage(QtDebugMsg, "[1,2]"); - QTest::ignoreMessage(QtDebugMsg, "Object"); - QTest::ignoreMessage(QtDebugMsg, "undefined"); - QTest::ignoreMessage(QtDebugMsg, "12"); - QTest::ignoreMessage(QtDebugMsg, "function () { return 5;}"); - QTest::ignoreMessage(QtDebugMsg, "true"); - QTest::ignoreMessage(QtDebugMsg, "Object"); - QTest::ignoreMessage(QtDebugMsg, "Object"); - QTest::ignoreMessage(QtDebugMsg, "1 pong! Object"); - QTest::ignoreMessage(QtDebugMsg, "1 [ping,pong] Object 2"); - - - QTest::ignoreMessage(QtWarningMsg, qPrintable(testException)); - - - QDeclarativeComponent component(&engine, testUrl); - QObject *object = component.create(); - QVERIFY(object != 0); - delete object; -} void tst_qdeclarativeqt::dateTimeConversion() { -- 2.7.4