From a8426626d1f9cb3c7ed304d951fe81fcea230895 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 10 Aug 2017 11:46:31 +0200 Subject: [PATCH] QmlProfiler: Fix and extend the local qml profiler runner test We need to indirectly verify that the profiler support is doing the right thing by watching the RunControl's state transitions. Change-Id: I8f92f21022668ed3bb28477152132ccdcffaaea6 Reviewed-by: hjk --- .../tests/localqmlprofilerrunner_test.cpp | 146 +++++++++++------- .../tests/localqmlprofilerrunner_test.h | 13 -- 2 files changed, 86 insertions(+), 73 deletions(-) diff --git a/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp b/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp index 0b94133b001..6275067d892 100644 --- a/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp +++ b/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp @@ -25,17 +25,13 @@ #include "localqmlprofilerrunner_test.h" -#include "../qmlprofilerruncontrol.h" - #include - #include +#include #include #include -using namespace ProjectExplorer; - namespace QmlProfiler { namespace Internal { @@ -43,85 +39,115 @@ LocalQmlProfilerRunnerTest::LocalQmlProfilerRunnerTest(QObject *parent) : QObjec { } -void LocalQmlProfilerRunnerTest::start() -{ - delete runControl; - runControl = new ProjectExplorer::RunControl(nullptr, ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); - runControl->setRunnable(debuggee); - auto runner = new LocalQmlProfilerSupport(runControl, serverUrl); - - connect(runner, &LocalQmlProfilerSupport::localRunnerStarted, this, [this] { - QVERIFY(!running); - ++runCount; - running = true; - }); - connect(runner, &LocalQmlProfilerSupport::localRunnerStopped, this, [this] { - QVERIFY(running); - running = false; - }); - runControl->initiateStart(); -} - void LocalQmlProfilerRunnerTest::testRunner() { + QPointer runControl; + QPointer profiler; + ProjectExplorer::StandardRunnable debuggee; + QUrl serverUrl; + + bool running = false; + bool started = false; + int startCount = 0; + int runCount = 0; + int stopCount = 0; + debuggee.executable = "\\-/|\\-/"; debuggee.environment = Utils::Environment::systemEnvironment(); // should not be used anywhere but cannot be empty serverUrl.setPath("invalid"); - start(); + runControl = new ProjectExplorer::RunControl(nullptr, + ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); + runControl->setRunnable(debuggee); + profiler = new LocalQmlProfilerSupport(runControl, serverUrl); - QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner1); - QTRY_COMPARE_WITH_TIMEOUT(runControl, static_cast(nullptr), 70000); -} + auto connectRunner = [&]() { + connect(runControl, &ProjectExplorer::RunControl::aboutToStart, this, [&]() { + QVERIFY(!started); + QVERIFY(!running); + ++startCount; + started = true; + }); + connect(runControl, &ProjectExplorer::RunControl::started, this, [&]() { + QVERIFY(started); + QVERIFY(!running); + ++runCount; + running = true; + }); + connect(runControl, &ProjectExplorer::RunControl::stopped, this, [&]() { + QVERIFY(started); + ++stopCount; + running = false; + started = false; + }); + connect(runControl, &ProjectExplorer::RunControl::finished, this, [&]() { + running = false; + started = false; + }); + }; -void LocalQmlProfilerRunnerTest::testRunner1() -{ - QTRY_COMPARE_WITH_TIMEOUT(runCount, 1, 10000); - QTRY_VERIFY_WITH_TIMEOUT(!running, 10000); + connectRunner(); - serverUrl = urlFromLocalSocket(); + runControl->initiateStart(); + + QTRY_COMPARE_WITH_TIMEOUT(startCount, 1, 10000); + QTRY_VERIFY_WITH_TIMEOUT(!started, 10000); + QCOMPARE(stopCount, 1); + QCOMPARE(runCount, 0); + + runControl->initiateFinish(); + QTRY_VERIFY(runControl.isNull()); + QVERIFY(profiler.isNull()); + + serverUrl = ProjectExplorer::urlFromLocalSocket(); + debuggee.executable = qApp->applicationFilePath(); - debuggee.executable = QCoreApplication::applicationFilePath(); // comma is used to specify a test function. In this case, an invalid one. debuggee.commandLineArguments = QString("-test QmlProfiler,"); + runControl = new ProjectExplorer::RunControl(nullptr, + ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); + runControl->setRunnable(debuggee); + profiler = new LocalQmlProfilerSupport(runControl, serverUrl); + connectRunner(); + runControl->initiateStart(); - start(); - - QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner2); -} - -void LocalQmlProfilerRunnerTest::testRunner2() -{ - QTRY_COMPARE_WITH_TIMEOUT(runCount, 2, 10000); + QTRY_VERIFY_WITH_TIMEOUT(running, 10000); QTRY_VERIFY_WITH_TIMEOUT(!running, 10000); + QCOMPARE(startCount, 2); + QCOMPARE(stopCount, 2); + QCOMPARE(runCount, 1); + + runControl->initiateFinish(); + QTRY_VERIFY(runControl.isNull()); + QVERIFY(profiler.isNull()); debuggee.commandLineArguments.clear(); - serverUrl = urlFromLocalHostAndFreePort(); + serverUrl.clear(); + serverUrl = ProjectExplorer::urlFromLocalHostAndFreePort(); + runControl = new ProjectExplorer::RunControl(nullptr, + ProjectExplorer::Constants::QML_PROFILER_RUN_MODE); + runControl->setRunnable(debuggee); + profiler = new LocalQmlProfilerSupport(runControl, serverUrl); + connectRunner(); + runControl->initiateStart(); - start(); - - QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner3); -} - -void LocalQmlProfilerRunnerTest::testRunner3() -{ - QTRY_COMPARE_WITH_TIMEOUT(runCount, 3, 10000); + QTRY_VERIFY_WITH_TIMEOUT(running, 10000); runControl->initiateStop(); - QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner4); -} - -void LocalQmlProfilerRunnerTest::testRunner4() -{ QTRY_VERIFY_WITH_TIMEOUT(!running, 10000); - delete runControl; - runControl = nullptr; + QCOMPARE(startCount, 3); + QCOMPARE(stopCount, 3); + QCOMPARE(runCount, 2); + + runControl->initiateFinish(); + QTRY_VERIFY(runControl.isNull()); + QVERIFY(profiler.isNull()); } void LocalQmlProfilerRunnerTest::testFindFreePort() { - QUrl serverUrl = urlFromLocalHostAndFreePort(); + QUrl serverUrl = ProjectExplorer::urlFromLocalHostAndFreePort(); QVERIFY(serverUrl.port() != -1); QVERIFY(!serverUrl.host().isEmpty()); QTcpServer server; @@ -130,7 +156,7 @@ void LocalQmlProfilerRunnerTest::testFindFreePort() void LocalQmlProfilerRunnerTest::testFindFreeSocket() { - QUrl serverUrl = urlFromLocalSocket(); + QUrl serverUrl = ProjectExplorer::urlFromLocalSocket(); QString socket = serverUrl.path(); QVERIFY(!socket.isEmpty()); QVERIFY(!QFile::exists(socket)); diff --git a/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.h b/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.h index 7b6bc60980e..796f2ce3c4b 100644 --- a/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.h +++ b/src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.h @@ -43,19 +43,6 @@ private slots: void testRunner(); void testFindFreePort(); void testFindFreeSocket(); - -private: - void start(); - void testRunner1(); - void testRunner2(); - void testRunner3(); - void testRunner4(); - - bool running = false; - int runCount = 0; - ProjectExplorer::RunControl *runControl = nullptr; - ProjectExplorer::StandardRunnable debuggee; - QUrl serverUrl; }; } // namespace Internal