diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2017-08-10 11:46:31 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2017-08-10 10:23:39 +0000 |
commit | a8426626d1f9cb3c7ed304d951fe81fcea230895 (patch) | |
tree | f11e8a9070b8772c07ff606247dfdfece818731a | |
parent | f4f240ad431b234c97c3f0c50e81484ec305a652 (diff) | |
download | qt-creator-a8426626d1f9cb3c7ed304d951fe81fcea230895.tar.gz |
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 <hjk@qt.io>
-rw-r--r-- | src/plugins/qmlprofiler/tests/localqmlprofilerrunner_test.cpp | 146 | ||||
-rw-r--r-- | src/plugins/qmlprofiler/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 0b94133b00..6275067d89 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 <debugger/analyzer/analyzermanager.h> - #include <projectexplorer/runnables.h> +#include <qmlprofiler/qmlprofilerruncontrol.h> #include <QtTest> #include <QTcpServer> -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<ProjectExplorer::RunControl> runControl; + QPointer<LocalQmlProfilerSupport> 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); + + 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; + }); + }; + + connectRunner(); - QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner1); - QTRY_COMPARE_WITH_TIMEOUT(runControl, static_cast<ProjectExplorer::RunControl *>(nullptr), 70000); -} + runControl->initiateStart(); -void LocalQmlProfilerRunnerTest::testRunner1() -{ - QTRY_COMPARE_WITH_TIMEOUT(runCount, 1, 10000); - QTRY_VERIFY_WITH_TIMEOUT(!running, 10000); + QTRY_COMPARE_WITH_TIMEOUT(startCount, 1, 10000); + QTRY_VERIFY_WITH_TIMEOUT(!started, 10000); + QCOMPARE(stopCount, 1); + QCOMPARE(runCount, 0); - serverUrl = urlFromLocalSocket(); + 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); - debuggee.commandLineArguments.clear(); - serverUrl = urlFromLocalHostAndFreePort(); - - start(); + runControl->initiateFinish(); + QTRY_VERIFY(runControl.isNull()); + QVERIFY(profiler.isNull()); - QTimer::singleShot(0, this, &LocalQmlProfilerRunnerTest::testRunner3); -} + debuggee.commandLineArguments.clear(); + 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(); -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 7b6bc60980..796f2ce3c4 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 |