diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2011-06-21 14:38:44 (GMT) |
---|---|---|
committer | Kai Koehne <kai.koehne@nokia.com> | 2011-06-22 08:05:33 (GMT) |
commit | d349c879e1d55e4cd2b7d31c08e2796c0fec4020 (patch) | |
tree | f1e5ba4f3d71f3ef607e1b81ba53c506963eb41e /tests | |
parent | 6cb43a9b72c67b71409a59fdeb419f390441f0c7 (diff) | |
download | Qt-d349c879e1d55e4cd2b7d31c08e2796c0fec4020.zip Qt-d349c879e1d55e4cd2b7d31c08e2796c0fec4020.tar.gz Qt-d349c879e1d55e4cd2b7d31c08e2796c0fec4020.tar.bz2 |
QDeclarativeDebug: Add code coverage information
Add messages to track the lines of JavaScript that are executed.
Patch done by Janne Virranmaki <ext-janne.1.virranmaki@nokia.com>
Reviewed-by: kkoehne
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp b/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp index a40bcc0..1990c0d 100644 --- a/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp +++ b/tests/auto/declarative/qdeclarativedebugjs/tst_qdeclarativedebugjs.cpp @@ -69,6 +69,8 @@ public: void expandObjectById(const QByteArray& objectName, quint64 objectId); void setProperty(const QByteArray& id, qint64 objectId, const QString &property, const QString &value); void activateFrame(int frameId); + void startCoverageCompleted(); + void startCoverageRun(); // info from last exec JSAgentWatchData exec_data; @@ -94,6 +96,11 @@ signals: void stopped(); void expanded(); void watchTriggered(); + void coverageScriptLoaded(); + void coverageFuncEntered(); + void coverageFuncExited(); + void coveragePosChanged(); + void coverageCompleted(); protected: virtual void statusChanged(Status status); @@ -156,6 +163,9 @@ private slots: void setProperty4(); void activateFrame2(); void verifyQMLOptimizerDisabled(); + void testCoverageCompleted(); + void testCoverageRun(); + }; @@ -280,6 +290,28 @@ void QJSDebugClient::activateFrame(int frameId) sendMessage(reply); } +void QJSDebugClient::startCoverageRun() +{ + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + QByteArray cmd = "COVERAGE"; + bool enabled = true; + rs << cmd + << enabled; + sendMessage(reply); +} + +void QJSDebugClient::startCoverageCompleted() +{ + QByteArray reply; + QDataStream rs(&reply, QIODevice::WriteOnly); + QByteArray cmd = "COVERAGE"; + bool enabled = false; + rs << cmd + << enabled; + sendMessage(reply); +} + void QJSDebugClient::statusChanged(Status /*status*/) { emit statusHasChanged(); @@ -317,6 +349,30 @@ void QJSDebugClient::messageReceived(const QByteArray &data) stream >> ping; QCOMPARE(ping, m_ping); emit pong(); + } else if (command == "COVERAGE") { + qint64 time; + int messageType; + qint64 scriptId; + QString program; + QString fileName; + int baseLineNumber; + int lineNumber; + int columnNumber; + QString returnValue; + + stream >> time >> messageType >> scriptId >> program >> fileName >> baseLineNumber + >> lineNumber >> columnNumber >> returnValue; + if (messageType == CoverageComplete) { + emit coverageCompleted(); + } else if (messageType == CoverageScriptLoad) { + emit coverageScriptLoaded(); + } else if (messageType == CoveragePosChange) { + emit coveragePosChanged(); + } else if (messageType == CoverageFuncEntry) { + emit coverageFuncEntered(); + } else if (messageType == CoverageFuncExit) { + emit coverageFuncExited(); + } } else { QFAIL("Unknown message :" + command); } @@ -1336,6 +1392,51 @@ void tst_QDeclarativeDebugJS::verifyQMLOptimizerDisabled() QVERIFY(QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(stopped()))); } + +void tst_QDeclarativeDebugJS::testCoverageCompleted() +{ + QJSDebugProcess process; + process.start(QStringList() << "-qmljsdebugger=port:3771,block" << TEST_FILE("backtrace1.qml")); + QVERIFY(process.waitForStarted()); + + QDeclarativeDebugConnection connection; + connection.connectToHost("127.0.0.1", 3771); + QVERIFY(connection.waitForConnected()); + + QJSDebugClient client(&connection); + QVERIFY(QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(statusHasChanged()))); + if (client.status() == QJSDebugClient::Unavailable) + QVERIFY(QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(statusHasChanged()))); + QCOMPARE(client.status(), QJSDebugClient::Enabled); + + client.startCoverageCompleted(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(coverageCompleted()))); +} + +void tst_QDeclarativeDebugJS::testCoverageRun() +{ + QJSDebugProcess process; + process.start(QStringList() << "-qmljsdebugger=port:3771,block" << TEST_FILE("backtrace1.qml")); + QVERIFY(process.waitForStarted()); + + QDeclarativeDebugConnection connection; + connection.connectToHost("127.0.0.1", 3771); + QVERIFY(connection.waitForConnected()); + + QJSDebugClient client(&connection); + QVERIFY(QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(statusHasChanged()))); + if (client.status() == QJSDebugClient::Unavailable) + QVERIFY(QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(statusHasChanged()))); + QCOMPARE(client.status(), QJSDebugClient::Enabled); + + client.startCoverageRun(); + client.startCoverageCompleted(); + QVERIFY(QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(coverageScriptLoaded()))); + QVERIFY(QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(coveragePosChanged()))); + //QVERIFY(QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(coverageFuncEntered()))); + //QVERIFY(QDeclarativeDebugTest::waitForSignal(&client, SIGNAL(coverageFuncExited()))); +} + QTEST_MAIN(tst_QDeclarativeDebugJS) #include "tst_qdeclarativedebugjs.moc" |