From 18ac01a7721f66902d61d6a2aad31377b1fdbeb8 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 16 Aug 2017 11:57:53 +0200 Subject: Base QQmlDebuggingEnabler test on QQmlDebugTest This allows us to reuse the centralized cleanup routine, avoiding leakage on test failures. Also drop the unused init() method and "t" member. Change-Id: I85bf5728599a20cd3a3afdbc1b3ef92432d7b92d Reviewed-by: Simon Hausmann --- .../tst_qqmldebuggingenabler.cpp | 152 +++++---------------- 1 file changed, 34 insertions(+), 118 deletions(-) (limited to 'tests') diff --git a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp index 3aa3a5c87e..134de44858 100644 --- a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp +++ b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp @@ -32,6 +32,8 @@ #include #include +#include + #include #include #include @@ -40,17 +42,11 @@ #include #include -class tst_QQmlDebuggingEnabler : public QQmlDataTest +class tst_QQmlDebuggingEnabler : public QQmlDebugTest { Q_OBJECT - bool init(bool blockMode, bool qmlscene, int portFrom, int portTo); - private slots: - void initTestCase(); - void cleanupTestCase(); - void cleanup(); - void qmlscene_data(); void qmlscene(); void custom_data(); @@ -58,88 +54,8 @@ private slots: private: void data(); - QQmlDebugProcess *process; - QQmlDebugConnection *connection; - QTime t; }; -void tst_QQmlDebuggingEnabler::initTestCase() -{ - QQmlDataTest::initTestCase(); - t.start(); - process = 0; - connection = 0; -} - -void tst_QQmlDebuggingEnabler::cleanupTestCase() -{ - if (process) { - process->stop(); - delete process; - } - - if (connection) - delete connection; -} - -bool tst_QQmlDebuggingEnabler::init(bool blockMode, bool qmlscene, int portFrom, int portTo) -{ - connection = new QQmlDebugConnection(); - - if (qmlscene) { - process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene", this); - process->setMaximumBindErrors(1); - } else { - process = new QQmlDebugProcess(QCoreApplication::applicationDirPath() + QLatin1String("/qqmldebuggingenablerserver"), this); - process->setMaximumBindErrors(portTo - portFrom); - } - - if (qmlscene) { - process->start(QStringList() << QLatin1String("-qmljsdebugger=port:") + - QString::number(portFrom) + QLatin1Char(',') + QString::number(portTo) + - QLatin1String(blockMode ? ",block": "") << - testFile(QLatin1String("test.qml"))); - } else { - QStringList args; - if (blockMode) - args << QLatin1String("-block"); - args << QString::number(portFrom) << QString::number(portTo); - process->start(args); - } - - if (!process->waitForSessionStart()) { - return false; - } - - const int port = process->debugPort(); - connection->connectToHost("127.0.0.1", port); - if (!connection->waitForConnected()) { - qDebug() << "could not connect to host!"; - return false; - } - return true; -} - -void tst_QQmlDebuggingEnabler::cleanup() -{ - if (QTest::currentTestFailed()) { - qDebug() << "Process State:" << process->state(); - qDebug() << "Application Output:" << process->output(); - } - - if (process) { - process->stop(); - delete process; - } - - - if (connection) - delete connection; - - process = 0; - connection = 0; -} - void tst_QQmlDebuggingEnabler::data() { QTest::addColumn("connector"); @@ -185,32 +101,32 @@ void tst_QQmlDebuggingEnabler::qmlscene() QFETCH(bool, blockMode); QFETCH(QStringList, services); - process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene", - this); - process->setMaximumBindErrors(1); - process->start(QStringList() - << QString::fromLatin1("-qmljsdebugger=connector:%1%2%3%4") - .arg(connector + (connector == QLatin1String("QQmlDebugServer") ? - QLatin1String(",port:5555,5565") : QString())) - .arg(blockMode ? QLatin1String(",block") : QString()) - .arg(services.isEmpty() ? QString() : QString::fromLatin1(",services:")) - .arg(services.isEmpty() ? QString() : services.join(",")) - << testFile(QLatin1String("test.qml"))); + m_process = new QQmlDebugProcess( + QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene", this); + m_process->setMaximumBindErrors(1); + m_process->start(QStringList() + << QString::fromLatin1("-qmljsdebugger=connector:%1%2%3%4") + .arg(connector + (connector == QLatin1String("QQmlDebugServer") + ? QLatin1String(",port:5555,5565") : QString())) + .arg(blockMode ? QLatin1String(",block") : QString()) + .arg(services.isEmpty() ? QString() : QString::fromLatin1(",services:")) + .arg(services.isEmpty() ? QString() : services.join(",")) + << testFile(QLatin1String("test.qml"))); if (connector == QLatin1String("QQmlDebugServer")) { - QVERIFY(process->waitForSessionStart()); - connection = new QQmlDebugConnection(); - QList clients = QQmlDebugTest::createOtherClients(connection); - connection->connectToHost("127.0.0.1", process->debugPort()); - QVERIFY(connection->waitForConnected()); - foreach (QQmlDebugClient *client, clients) + QVERIFY(m_process->waitForSessionStart()); + m_connection = new QQmlDebugConnection(); + m_clients = QQmlDebugTest::createOtherClients(m_connection); + m_connection->connectToHost("127.0.0.1", m_process->debugPort()); + QVERIFY(m_connection->waitForConnected()); + foreach (QQmlDebugClient *client, m_clients) QCOMPARE(client->state(), (services.isEmpty() || services.contains(client->name())) ? QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable); } - QCOMPARE(process->state(), QLatin1String("running")); + QCOMPARE(m_process->state(), QLatin1String("running")); if (!blockMode) - QTRY_VERIFY(process->output().contains(QLatin1String("qml: Component.onCompleted"))); + QTRY_VERIFY(m_process->output().contains(QLatin1String("qml: Component.onCompleted"))); } void tst_QQmlDebuggingEnabler::custom_data() @@ -226,9 +142,9 @@ void tst_QQmlDebuggingEnabler::custom() const int portFrom = 5555; const int portTo = 5565; - process = new QQmlDebugProcess(QCoreApplication::applicationDirPath() + - QLatin1String("/qqmldebuggingenablerserver"), this); - process->setMaximumBindErrors(portTo - portFrom); + m_process = new QQmlDebugProcess(QCoreApplication::applicationDirPath() + + QLatin1String("/qqmldebuggingenablerserver"), this); + m_process->setMaximumBindErrors(portTo - portFrom); QStringList args; if (blockMode) @@ -240,22 +156,22 @@ void tst_QQmlDebuggingEnabler::custom() if (!services.isEmpty()) args << QLatin1String("-services") << services; - process->start(args); + m_process->start(args); if (connector == QLatin1String("QQmlDebugServer")) { - QVERIFY(process->waitForSessionStart()); - connection = new QQmlDebugConnection(); - QList clients = QQmlDebugTest::createOtherClients(connection); - connection->connectToHost("127.0.0.1", process->debugPort()); - QVERIFY(connection->waitForConnected()); - foreach (QQmlDebugClient *client, clients) + QVERIFY(m_process->waitForSessionStart()); + m_connection = new QQmlDebugConnection(); + m_clients = QQmlDebugTest::createOtherClients(m_connection); + m_connection->connectToHost("127.0.0.1", m_process->debugPort()); + QVERIFY(m_connection->waitForConnected()); + for (QQmlDebugClient *client : qAsConst(m_clients)) QCOMPARE(client->state(), (services.isEmpty() || services.contains(client->name())) ? QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable); } - QCOMPARE(process->state(), QLatin1String("running")); + QCOMPARE(m_process->state(), QLatin1String("running")); if (!blockMode) - QTRY_VERIFY(process->output().contains(QLatin1String("QQmlEngine created"))); + QTRY_VERIFY(m_process->output().contains(QLatin1String("QQmlEngine created"))); } QTEST_MAIN(tst_QQmlDebuggingEnabler) -- cgit v1.2.3