diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2017-08-15 17:23:35 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2017-08-18 08:41:25 +0000 |
commit | 4b731207dfb42a499d6a061adbbb13cd58d817a9 (patch) | |
tree | 7c8541b8308cf149314f7f1e2801f9160b8473c4 /tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp | |
parent | 74ca31771f9f936cf4c4bbe9216183d46fcf3617 (diff) |
Tests: Unify debugger tests' connection mechanisms
All the tests do pretty much the same thing in their init() or
connect() methods: Create a process, create a debug connection, create
some clients and make sure they're all running. We can deduplicate the
code by moving all this into a common base class.
Furthermore, the QSKIP in the qqmlenginedebuginspectorintegration test
was obviously done because the BLACKLIST mechanism doesn't cover
failures from internally called methods. As we don't have that problem
anymore now, we can use BLACKLIST instead.
Change-Id: I6d45d3b4e9645558ecc783a81fd740b00235cdc1
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp')
-rw-r--r-- | tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp | 113 |
1 files changed, 18 insertions, 95 deletions
diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp index a3873bd99e..45e4ad1207 100644 --- a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp +++ b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp @@ -33,12 +33,8 @@ #include <private/qqmldebugconnection_p.h> #include <QtTest/qtest.h> -#include <private/qtestresult_p.h> #include <QtCore/qlibraryinfo.h> -#define STR_PORT_FROM "13773" -#define STR_PORT_TO "13783" - struct QQmlProfilerData { QQmlProfilerData(qint64 time = -2, int messageType = -1, int detailType = -1, @@ -258,24 +254,11 @@ void QQmlProfilerTestClient::complete() emit recordingFinished(); } -class tst_QQmlProfilerService : public QQmlDataTest +class tst_QQmlProfilerService : public QQmlDebugTest { Q_OBJECT -public: - tst_QQmlProfilerService() - : m_process(0) - , m_connection(0) - , m_client(0) - { - } - - private: - QQmlDebugProcess *m_process; - QQmlDebugConnection *m_connection; - QQmlProfilerTestClient *m_client; - enum MessageListType { MessageListQML, MessageListJavaScript, @@ -294,23 +277,17 @@ private: CheckAll = CheckMessageType | CheckDetailType | CheckLine | CheckColumn | CheckDataEndsWith }; - enum ConnectResult - { - ConnectSuccess, - ProcessFailed, - ClientFailed, - EnableFailed, - RestrictFailed - }; - ConnectResult connect(bool block, const QString &testFile, bool restrictServices = true); void checkTraceReceived(); void checkJsHeap(); bool verify(MessageListType type, int expectedPosition, const QQmlProfilerData &expected, quint32 checks); + QList<QQmlDebugClient *> createClients() override; + QPointer<QQmlProfilerTestClient> m_client; + private slots: - void cleanup(); + void cleanup() override; void connect_data(); void connect(); @@ -325,65 +302,13 @@ private slots: #define VERIFY(type, position, expected, checks) QVERIFY(verify(type, position, expected, checks)) -template<typename F> -struct Finalizer { - F m_lambda; - Finalizer(F &&lambda) : m_lambda(std::forward<F>(lambda)) {} - ~Finalizer() { m_lambda(); } -}; - -template<typename F> -static Finalizer<F> defer(F &&lambda) -{ - return Finalizer<F>(std::forward<F>(lambda)); -} - -tst_QQmlProfilerService::ConnectResult tst_QQmlProfilerService::connect( - bool block, const QString &testFile, bool restrictServices) +QQmlDebugTest::ConnectResult tst_QQmlProfilerService::connect(bool block, const QString &file, + bool restrictServices) { // ### Still using qmlscene due to QTBUG-33377 - const QString executable = QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene"; - QStringList arguments; - arguments << QString::fromLatin1("-qmljsdebugger=port:%1,%2%3%4") - .arg(STR_PORT_FROM).arg(STR_PORT_TO) - .arg(block ? QStringLiteral(",block") : QString()) - .arg(restrictServices ? QStringLiteral(",services:CanvasFrameRate") : QString()) - << QQmlDataTest::instance()->testFile(testFile); - - QScopedPointer<QQmlDebugProcess> process; - process.reset(new QQmlDebugProcess(executable, this)); - process->start(QStringList() << arguments); - if (!process->waitForSessionStart()) { - qDebug("Could not launch application, or did not get 'Waiting for connection'."); - return ProcessFailed; - } - - m_process = process.take(); - - m_connection = new QQmlDebugConnection(); - m_client = new QQmlProfilerTestClient(m_connection); - if (!m_client) - return ClientFailed; - - QList<QQmlDebugClient *> others = QQmlDebugTest::createOtherClients(m_connection); - auto deleter = defer([&others]() { qDeleteAll(others); }); - Q_UNUSED(deleter); - - const int port = m_process->debugPort(); - m_connection->connectToHost(QLatin1String("127.0.0.1"), port); - for (int tries = 0; tries < 100 && m_client->state() != QQmlDebugClient::Enabled; ++tries) - QTest::qWait(50); - if (m_client->state() != QQmlDebugClient::Enabled) - return EnableFailed; - - const QQmlDebugClient::State expectedState = restrictServices ? QQmlDebugClient::Unavailable - : QQmlDebugClient::Enabled; - for (QQmlDebugClient *other : others) { - if (other->state() != expectedState) - return RestrictFailed; - } - - return ConnectSuccess; + return QQmlDebugTest::connect(QLibraryInfo::location(QLibraryInfo::BinariesPath) + "/qmlscene", + restrictServices ? QStringLiteral("CanvasFrameRate") : QString(), + testFile(file), block); } void tst_QQmlProfilerService::checkTraceReceived() @@ -518,6 +443,12 @@ bool tst_QQmlProfilerService::verify(tst_QQmlProfilerService::MessageListType ty return false; } +QList<QQmlDebugClient *> tst_QQmlProfilerService::createClients() +{ + m_client = new QQmlProfilerTestClient(m_connection); + return QList<QQmlDebugClient *>({m_client}); +} + void tst_QQmlProfilerService::cleanup() { if (m_client && QTest::currentTestFailed()) { @@ -555,17 +486,9 @@ void tst_QQmlProfilerService::cleanup() qDebug() << i++ << data.time << data.messageType << data.detailType; } qDebug() << " "; - qDebug() << "Process State:" << (m_process ? m_process->state() : QLatin1String("null")); - qDebug() << "Application Output:" << (m_process ? m_process->output() : QLatin1String("null")); - qDebug() << "Connection State:" << QQmlDebugTest::connectionStateString(m_connection); - qDebug() << "Client State:" << QQmlDebugTest::clientStateString(m_client); } - delete m_process; - m_process = 0; - delete m_client; - m_client = 0; - delete m_connection; - m_connection = 0; + + QQmlDebugTest::cleanup(); } void tst_QQmlProfilerService::connect_data() |