diff options
Diffstat (limited to 'tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp')
-rw-r--r-- | tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp | 510 |
1 files changed, 221 insertions, 289 deletions
diff --git a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp index d248cf9708..59483d75da 100644 --- a/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp +++ b/tests/auto/qml/debugger/qqmldebugjs/qqmldebugjs/tst_qqmldebugjs.cpp @@ -136,7 +136,7 @@ const char *BREAKPOINTRELOCATION_QMLFILE = "breakpointRelocation.qml"; do {\ if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__)) {\ if (QTest::currentTestFailed()) \ - qDebug().nospace() << "\nDEBUGGEE OUTPUT:\n" << process->output();\ + qDebug().nospace() << "\nDEBUGGEE OUTPUT:\n" << m_process->output();\ return;\ }\ } while (0) @@ -144,18 +144,12 @@ do {\ class QJSDebugClient; -class tst_QQmlDebugJS : public QQmlDataTest +class tst_QQmlDebugJS : public QQmlDebugTest { Q_OBJECT - void init(bool qmlscene, const QString &qmlFile = QString(TEST_QMLFILE), bool blockMode = true, - bool restrictServices = false); - private slots: - void initTestCase(); - void cleanupTestCase(); - - void cleanup(); + void initTestCase() override; void connect_data(); void connect(); @@ -223,11 +217,12 @@ private slots: void getScripts(); private: - void targetData(); + ConnectResult init(bool qmlscene, const QString &qmlFile = QString(TEST_QMLFILE), + bool blockMode = true, bool restrictServices = false); + QList<QQmlDebugClient *> createClients() override; + QPointer<QJSDebugClient> m_client; - QQmlDebugProcess *process; - QJSDebugClient *client; - QQmlDebugConnection *connection; + void targetData(); QTime t; }; @@ -280,7 +275,6 @@ protected: void messageReceived(const QByteArray &data); signals: - void enabled(); void connected(); void interruptRequested(); void result(); @@ -667,10 +661,8 @@ void QJSDebugClient::disconnect() void QJSDebugClient::stateChanged(State state) { - if (state == Enabled) { + if (state == Enabled) flushSendBuffer(); - emit enabled(); - } } void QJSDebugClient::messageReceived(const QByteArray &data) @@ -763,85 +755,19 @@ QByteArray QJSDebugClient::packMessage(const QByteArray &type, const QByteArray void tst_QQmlDebugJS::initTestCase() { - QQmlDataTest::initTestCase(); + QQmlDebugTest::initTestCase(); t.start(); - process = 0; - client = 0; - connection = 0; -} - -void tst_QQmlDebugJS::cleanupTestCase() -{ - if (process) { - process->stop(); - delete process; - } - - if (client) - delete client; - - if (connection) - delete connection; } -void tst_QQmlDebugJS::init(bool qmlscene, const QString &qmlFile, bool blockMode, - bool restrictServices) +QQmlDebugTest::ConnectResult tst_QQmlDebugJS::init(bool qmlscene, const QString &qmlFile, + bool blockMode, bool restrictServices) { - connection = new QQmlDebugConnection(); - if (qmlscene) - process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + - "/qmlscene", this); - else - process = new QQmlDebugProcess(QCoreApplication::applicationDirPath() + - QLatin1String("/qqmldebugjsserver"), this); - client = new QJSDebugClient(connection); - QList<QQmlDebugClient *> others = QQmlDebugTest::createOtherClients(connection); - - const char *args = 0; - if (blockMode) - args = restrictServices ? BLOCKRESTRICTEDMODE : BLOCKMODE; - else - args = restrictServices ? NORMALRESTRICTEDMODE : NORMALMODE; - - process->start(QStringList() << QLatin1String(args) << testFile(qmlFile)); - - QVERIFY(process->waitForSessionStart()); - - const int port = process->debugPort(); - connection->connectToHost("127.0.0.1", port); - QVERIFY(connection->waitForConnected()); - - - if (client->state() != QQmlDebugClient::Enabled) - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(enabled()))); - - foreach (QQmlDebugClient *otherClient, others) - QCOMPARE(otherClient->state(), restrictServices ? QQmlDebugClient::Unavailable : - QQmlDebugClient::Enabled); - qDeleteAll(others); -} - -void tst_QQmlDebugJS::cleanup() -{ - if (QTest::currentTestFailed()) { - qDebug() << "Process State:" << process->state(); - qDebug() << "Application Output:" << process->output(); - } - - if (process) { - process->stop(); - delete process; - } - - if (client) - delete client; - - if (connection) - delete connection; - - process = 0; - client = 0; - connection = 0; + const QString executable = qmlscene + ? QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene" + : QCoreApplication::applicationDirPath() + QLatin1String("/qqmldebugjsserver"); + return QQmlDebugTest::connect( + executable, restrictServices ? QStringLiteral("V8Debugger") : QString(), + testFile(qmlFile), blockMode); } void tst_QQmlDebugJS::connect_data() @@ -864,9 +790,9 @@ void tst_QQmlDebugJS::connect() QFETCH(bool, blockMode); QFETCH(bool, restrictMode); QFETCH(bool, qmlscene); - init(qmlscene, QString(TEST_QMLFILE), blockMode, restrictMode); - client->connect(); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(connected()))); + QCOMPARE(init(qmlscene, QString(TEST_QMLFILE), blockMode, restrictMode), ConnectSuccess); + m_client->connect(); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(connected()))); } void tst_QQmlDebugJS::interrupt() @@ -876,11 +802,11 @@ void tst_QQmlDebugJS::interrupt() QFETCH(bool, qmlscene); QFETCH(bool, redundantRefs); QFETCH(bool, namesAsObjects); - init(qmlscene); - client->connect(redundantRefs, namesAsObjects); + QCOMPARE(init(qmlscene), ConnectSuccess); + m_client->connect(redundantRefs, namesAsObjects); - client->interrupt(); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(interruptRequested()))); + m_client->interrupt(); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(interruptRequested()))); } void tst_QQmlDebugJS::getVersion() @@ -890,12 +816,12 @@ void tst_QQmlDebugJS::getVersion() QFETCH(bool, qmlscene); QFETCH(bool, redundantRefs); QFETCH(bool, namesAsObjects); - init(qmlscene); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(connected()))); + QCOMPARE(init(qmlscene), ConnectSuccess); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(connected()))); - client->version(); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); + m_client->version(); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()))); } void tst_QQmlDebugJS::getVersionWhenAttaching() @@ -905,11 +831,11 @@ void tst_QQmlDebugJS::getVersionWhenAttaching() QFETCH(bool, redundantRefs); QFETCH(bool, namesAsObjects); - init(qmlscene, QLatin1String(TIMER_QMLFILE), false); - client->connect(redundantRefs, namesAsObjects); + QCOMPARE(init(qmlscene, QLatin1String(TIMER_QMLFILE), false), ConnectSuccess); + m_client->connect(redundantRefs, namesAsObjects); - client->version(); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); + m_client->version(); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()))); } void tst_QQmlDebugJS::disconnect() @@ -919,11 +845,11 @@ void tst_QQmlDebugJS::disconnect() QFETCH(bool, qmlscene); QFETCH(bool, redundantRefs); QFETCH(bool, namesAsObjects); - init(qmlscene); - client->connect(redundantRefs, namesAsObjects); + QCOMPARE(init(qmlscene), ConnectSuccess); + m_client->connect(redundantRefs, namesAsObjects); - client->disconnect(); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); + m_client->disconnect(); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()))); } void tst_QQmlDebugJS::setBreakpointInScriptOnCompleted() @@ -934,14 +860,14 @@ void tst_QQmlDebugJS::setBreakpointInScriptOnCompleted() QFETCH(bool, namesAsObjects); int sourceLine = 34; - init(qmlscene, ONCOMPLETED_QMLFILE); + QCOMPARE(init(qmlscene, ONCOMPLETED_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); @@ -957,14 +883,14 @@ void tst_QQmlDebugJS::setBreakpointInScriptOnComponentCreated() QFETCH(bool, namesAsObjects); int sourceLine = 34; - init(qmlscene, CREATECOMPONENT_QMLFILE); + QCOMPARE(init(qmlscene, CREATECOMPONENT_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); @@ -978,16 +904,16 @@ void tst_QQmlDebugJS::setBreakpointInScriptOnTimerCallback() QFETCH(bool, redundantRefs); QFETCH(bool, namesAsObjects); int sourceLine = 35; - init(qmlscene, TIMER_QMLFILE); + QCOMPARE(init(qmlscene, TIMER_QMLFILE), ConnectSuccess); - client->connect(redundantRefs, namesAsObjects); + m_client->connect(redundantRefs, namesAsObjects); //We can set the breakpoint after connect() here because the timer is repeating and if we miss //its first iteration we can still catch the second one. - client->setBreakpoint(QLatin1String(TIMER_QMLFILE), sourceLine, -1, true); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(TIMER_QMLFILE), sourceLine, -1, true); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); @@ -1003,14 +929,14 @@ void tst_QQmlDebugJS::setBreakpointInScriptInDifferentFile() QFETCH(bool, namesAsObjects); int sourceLine = 31; - init(qmlscene, LOADJSFILE_QMLFILE); + QCOMPARE(init(qmlscene, LOADJSFILE_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(TEST_JSFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(TEST_JSFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); @@ -1027,15 +953,15 @@ void tst_QQmlDebugJS::setBreakpointInScriptOnComment() int sourceLine = 34; int actualLine = 36; - init(qmlscene, BREAKPOINTRELOCATION_QMLFILE); + QCOMPARE(init(qmlscene, BREAKPOINTRELOCATION_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); + m_client->setBreakpoint(QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); QEXPECT_FAIL("", "Relocation of breakpoints is disabled right now", Abort); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()), 1)); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()), 1)); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); @@ -1052,15 +978,15 @@ void tst_QQmlDebugJS::setBreakpointInScriptOnEmptyLine() int sourceLine = 35; int actualLine = 36; - init(qmlscene, BREAKPOINTRELOCATION_QMLFILE); + QCOMPARE(init(qmlscene, BREAKPOINTRELOCATION_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); + m_client->setBreakpoint(QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); QEXPECT_FAIL("", "Relocation of breakpoints is disabled right now", Abort); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()), 1)); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()), 1)); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); @@ -1076,14 +1002,14 @@ void tst_QQmlDebugJS::setBreakpointInScriptOnOptimizedBinding() QFETCH(bool, namesAsObjects); int sourceLine = 39; - init(qmlscene, BREAKPOINTRELOCATION_QMLFILE); + QCOMPARE(init(qmlscene, BREAKPOINTRELOCATION_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(BREAKPOINTRELOCATION_QMLFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); @@ -1098,28 +1024,28 @@ void tst_QQmlDebugJS::setBreakpointInScriptWithCondition() QFETCH(bool, namesAsObjects); int out = 10; int sourceLine = 37; - init(qmlscene, CONDITION_QMLFILE); + QCOMPARE(init(qmlscene, CONDITION_QMLFILE), ConnectSuccess); - client->connect(redundantRefs, namesAsObjects); + m_client->connect(redundantRefs, namesAsObjects); //The breakpoint is in a timer loop so we can set it after connect(). - client->setBreakpoint(QLatin1String(CONDITION_QMLFILE), sourceLine, 1, true, QLatin1String("a > 10")); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(CONDITION_QMLFILE), sourceLine, 1, true, QLatin1String("a > 10")); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); //Get the frame index - QString jsonString = client->response; - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString = m_client->response; + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); { QVariantMap body = value.value("body").toMap(); int frameIndex = body.value("index").toInt(); //Verify the value of 'result' - client->evaluate(QLatin1String("a"),frameIndex); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); + m_client->evaluate(QLatin1String("a"),frameIndex); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()))); } - jsonString = client->response; - QJSValue val = client->parser.call(QJSValueList() << QJSValue(jsonString)); + jsonString = m_client->response; + QJSValue val = m_client->parser.call(QJSValueList() << QJSValue(jsonString)); QVERIFY(val.isObject()); QJSValue body = val.property(QStringLiteral("body")); QVERIFY(body.isObject()); @@ -1135,42 +1061,42 @@ void tst_QQmlDebugJS::setBreakpointInScriptThatQuits() QFETCH(bool, qmlscene); QFETCH(bool, redundantRefs); QFETCH(bool, namesAsObjects); - init(qmlscene, QUIT_QMLFILE); + QCOMPARE(init(qmlscene, QUIT_QMLFILE), ConnectSuccess); int sourceLine = 36; - client->setBreakpoint(QLatin1String(QUIT_QMLFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(QUIT_QMLFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); QCOMPARE(body.value("sourceLine").toInt(), sourceLine); QCOMPARE(QFileInfo(body.value("script").toMap().value("name").toString()).fileName(), QLatin1String(QUIT_QMLFILE)); - client->continueDebugging(QJSDebugClient::Continue); - QVERIFY(process->waitForFinished()); - QCOMPARE(process->exitStatus(), QProcess::NormalExit); + m_client->continueDebugging(QJSDebugClient::Continue); + QVERIFY(m_process->waitForFinished()); + QCOMPARE(m_process->exitStatus(), QProcess::NormalExit); } void tst_QQmlDebugJS::setBreakpointWhenAttaching() { int sourceLine = 35; - init(true, QLatin1String(TIMER_QMLFILE), false); + QCOMPARE(init(true, QLatin1String(TIMER_QMLFILE), false), ConnectSuccess); - client->connect(); + m_client->connect(); QSKIP("\nThe breakpoint may not hit because the engine may run in JIT mode or not have debug\n" "instructions, as we've connected in non-blocking mode above. That means we may have\n" "connected after the engine was already running, with all the QML already compiled."); //The breakpoint is in a timer loop so we can set it after connect(). - client->setBreakpoint(QLatin1String(TIMER_QMLFILE), sourceLine); + m_client->setBreakpoint(QLatin1String(TIMER_QMLFILE), sourceLine); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); } void tst_QQmlDebugJS::clearBreakpoint() @@ -1182,41 +1108,41 @@ void tst_QQmlDebugJS::clearBreakpoint() int sourceLine1 = 37; int sourceLine2 = 38; - init(qmlscene, CHANGEBREAKPOINT_QMLFILE); + QCOMPARE(init(qmlscene, CHANGEBREAKPOINT_QMLFILE), ConnectSuccess); - client->connect(redundantRefs, namesAsObjects); + m_client->connect(redundantRefs, namesAsObjects); //The breakpoints are in a timer loop so we can set them after connect(). //Furthermore the breakpoints should be hit in the right order because setting of breakpoints //can only occur in the QML event loop. (see QCOMPARE for sourceLine2 below) - client->setBreakpoint(QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine2, -1, true); + m_client->setBreakpoint(QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine1, -1, true); + m_client->setBreakpoint(QLatin1String(CHANGEBREAKPOINT_QMLFILE), sourceLine2, -1, true); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); //Will hit 1st brakpoint, change this breakpoint enable = false - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); QList<QVariant> breakpointsHit = body.value("breakpoints").toList(); int breakpoint = breakpointsHit.at(0).toInt(); - client->clearBreakpoint(breakpoint); + m_client->clearBreakpoint(breakpoint); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()))); //Continue with debugging - client->continueDebugging(QJSDebugClient::Continue); + m_client->continueDebugging(QJSDebugClient::Continue); //Hit 2nd breakpoint - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); //Continue with debugging - client->continueDebugging(QJSDebugClient::Continue); + m_client->continueDebugging(QJSDebugClient::Continue); //Should stop at 2nd breakpoint - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - jsonString = client->response; - value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + jsonString = m_client->response; + value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); body = value.value("body").toMap(); @@ -1230,10 +1156,10 @@ void tst_QQmlDebugJS::setExceptionBreak() QFETCH(bool, redundantRefs); QFETCH(bool, namesAsObjects); - init(qmlscene, EXCEPTION_QMLFILE); - client->setExceptionBreak(QJSDebugClient::All,true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + QCOMPARE(init(qmlscene, EXCEPTION_QMLFILE), ConnectSuccess); + m_client->setExceptionBreak(QJSDebugClient::All,true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); } void tst_QQmlDebugJS::stepNext() @@ -1244,17 +1170,17 @@ void tst_QQmlDebugJS::stepNext() QFETCH(bool, namesAsObjects); int sourceLine = 37; - init(qmlscene, STEPACTION_QMLFILE); + QCOMPARE(init(qmlscene, STEPACTION_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - client->continueDebugging(QJSDebugClient::Next); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->continueDebugging(QJSDebugClient::Next); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); @@ -1271,17 +1197,17 @@ void tst_QQmlDebugJS::stepIn() int sourceLine = 41; int actualLine = 37; - init(qmlscene, STEPACTION_QMLFILE); + QCOMPARE(init(qmlscene, STEPACTION_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(STEPACTION_QMLFILE), sourceLine, 1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(STEPACTION_QMLFILE), sourceLine, 1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - client->continueDebugging(QJSDebugClient::In); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->continueDebugging(QJSDebugClient::In); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); @@ -1298,17 +1224,17 @@ void tst_QQmlDebugJS::stepOut() int sourceLine = 37; int actualLine = 41; - init(qmlscene, STEPACTION_QMLFILE); + QCOMPARE(init(qmlscene, STEPACTION_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(STEPACTION_QMLFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - client->continueDebugging(QJSDebugClient::Out); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->continueDebugging(QJSDebugClient::Out); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); @@ -1325,18 +1251,18 @@ void tst_QQmlDebugJS::continueDebugging() int sourceLine1 = 41; int sourceLine2 = 38; - init(qmlscene, STEPACTION_QMLFILE); + QCOMPARE(init(qmlscene, STEPACTION_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(STEPACTION_QMLFILE), sourceLine1, -1, true); - client->setBreakpoint(QLatin1String(STEPACTION_QMLFILE), sourceLine2, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(STEPACTION_QMLFILE), sourceLine1, -1, true); + m_client->setBreakpoint(QLatin1String(STEPACTION_QMLFILE), sourceLine2, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - client->continueDebugging(QJSDebugClient::Continue); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->continueDebugging(QJSDebugClient::Continue); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); @@ -1352,14 +1278,14 @@ void tst_QQmlDebugJS::backtrace() QFETCH(bool, namesAsObjects); int sourceLine = 34; - init(qmlscene, ONCOMPLETED_QMLFILE); + QCOMPARE(init(qmlscene, ONCOMPLETED_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - client->backtrace(); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); + m_client->backtrace(); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()))); } void tst_QQmlDebugJS::getFrameDetails() @@ -1370,14 +1296,14 @@ void tst_QQmlDebugJS::getFrameDetails() QFETCH(bool, namesAsObjects); int sourceLine = 34; - init(qmlscene, ONCOMPLETED_QMLFILE); + QCOMPARE(init(qmlscene, ONCOMPLETED_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - client->frame(); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); + m_client->frame(); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()))); } void tst_QQmlDebugJS::getScopeDetails() @@ -1388,31 +1314,31 @@ void tst_QQmlDebugJS::getScopeDetails() QFETCH(bool, namesAsObjects); int sourceLine = 34; - init(qmlscene, ONCOMPLETED_QMLFILE); + QCOMPARE(init(qmlscene, ONCOMPLETED_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - client->scope(); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); + m_client->scope(); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()))); } void tst_QQmlDebugJS::evaluateInGlobalScope() { //void evaluate(QString expr, int frame = -1); - init(true); + QCOMPARE(init(true), ConnectSuccess); - client->connect(); + m_client->connect(); do { // The engine might not be initialized, yet. We just try until it shows up. - client->evaluate(QLatin1String("console.log('Hello World')")); - } while (!QQmlDebugTest::waitForSignal(client, SIGNAL(result()), 500)); + m_client->evaluate(QLatin1String("console.log('Hello World')")); + } while (!QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()), 500)); //Verify the return value of 'console.log()', which is "undefined" - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); QCOMPARE(body.value("type").toString(),QLatin1String("undefined")); } @@ -1425,29 +1351,29 @@ void tst_QQmlDebugJS::evaluateInLocalScope() QFETCH(bool, redundantRefs); QFETCH(bool, namesAsObjects); int sourceLine = 34; - init(qmlscene, ONCOMPLETED_QMLFILE); + QCOMPARE(init(qmlscene, ONCOMPLETED_QMLFILE), ConnectSuccess); - client->setBreakpoint(QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QLatin1String(ONCOMPLETED_QMLFILE), sourceLine, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - client->frame(); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); + m_client->frame(); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()))); //Get the frame index - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); int frameIndex = body.value("index").toInt(); - client->evaluate(QLatin1String("root.a"), frameIndex); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); + m_client->evaluate(QLatin1String("root.a"), frameIndex); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()))); //Verify the value of 'timer.interval' - jsonString = client->response; - value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + jsonString = m_client->response; + value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); body = value.value("body").toMap(); @@ -1456,25 +1382,25 @@ void tst_QQmlDebugJS::evaluateInLocalScope() void tst_QQmlDebugJS::evaluateInContext() { - connection = new QQmlDebugConnection(); - process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + m_connection = new QQmlDebugConnection(); + m_process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene", this); - client = new QJSDebugClient(connection); - QScopedPointer<QQmlEngineDebugClient> engineClient(new QQmlEngineDebugClient(connection)); - process->start(QStringList() << QLatin1String(BLOCKMODE) << testFile(ONCOMPLETED_QMLFILE)); + m_client = new QJSDebugClient(m_connection); + QScopedPointer<QQmlEngineDebugClient> engineClient(new QQmlEngineDebugClient(m_connection)); + m_process->start(QStringList() << QLatin1String(BLOCKMODE) << testFile(ONCOMPLETED_QMLFILE)); - QVERIFY(process->waitForSessionStart()); + QVERIFY(m_process->waitForSessionStart()); - connection->connectToHost("127.0.0.1", process->debugPort()); - QVERIFY(connection->waitForConnected()); + m_connection->connectToHost("127.0.0.1", m_process->debugPort()); + QVERIFY(m_connection->waitForConnected()); - QTRY_COMPARE(client->state(), QQmlEngineDebugClient::Enabled); + QTRY_COMPARE(m_client->state(), QQmlEngineDebugClient::Enabled); QTRY_COMPARE(engineClient->state(), QQmlEngineDebugClient::Enabled); - client->connect(); + m_client->connect(); // "a" not accessible without extra context - client->evaluate(QLatin1String("a + 10"), -1, -1); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(failure()))); + m_client->evaluate(QLatin1String("a + 10"), -1, -1); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(failure()))); bool success = false; engineClient->queryAvailableEngines(&success); @@ -1496,11 +1422,11 @@ void tst_QQmlDebugJS::evaluateInContext() auto object = engineClient->object(); // "a" accessible in context of surrounding object - client->evaluate(QLatin1String("a + 10"), -1, object.debugId); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); + m_client->evaluate(QLatin1String("a + 10"), -1, object.debugId); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()))); - QString jsonString = client->response; - QVariantMap value = client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); + QString jsonString = m_client->response; + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QVariantMap body = value.value("body").toMap(); QTRY_COMPARE(body.value("value").toInt(), 20); @@ -1513,16 +1439,16 @@ void tst_QQmlDebugJS::getScripts() QFETCH(bool, qmlscene); QFETCH(bool, redundantRefs); QFETCH(bool, namesAsObjects); - init(qmlscene); + QCOMPARE(init(qmlscene), ConnectSuccess); - client->setBreakpoint(QString(TEST_QMLFILE), 35, -1, true); - client->connect(redundantRefs, namesAsObjects); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped()))); + m_client->setBreakpoint(QString(TEST_QMLFILE), 35, -1, true); + m_client->connect(redundantRefs, namesAsObjects); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(stopped()))); - client->scripts(); - QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(result()))); - QString jsonString(client->response); - QVariantMap value = client->parser.call(QJSValueList() + m_client->scripts(); + QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(result()))); + QString jsonString(m_client->response); + QVariantMap value = m_client->parser.call(QJSValueList() << QJSValue(jsonString)).toVariant().toMap(); QList<QVariant> scripts = value.value("body").toList(); @@ -1531,6 +1457,12 @@ void tst_QQmlDebugJS::getScripts() QVERIFY(scripts.first().toMap()[QStringLiteral("name")].toString().endsWith(QStringLiteral("data/test.qml"))); } +QList<QQmlDebugClient *> tst_QQmlDebugJS::createClients() +{ + m_client = new QJSDebugClient(m_connection); + return QList<QQmlDebugClient *>({m_client}); +} + void tst_QQmlDebugJS::targetData() { QTest::addColumn<bool>("qmlscene"); |