From 12fdb3bc1fdc79cc79e76f283e548d664b4c30a5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 26 Jan 2024 10:50:43 +0100 Subject: [PATCH] QTest: hold WatchDog in optional<> instead of QScopedPointer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Means we don't need to allocate it on the heap and optional<> fits the semantics of an optional object better. Change-Id: Id02c4847c2357c3033dce94b68787ed37d6ca276 Reviewed-by: Tor Arne Vestbø Reviewed-by: Thiago Macieira (cherry picked from commit 9a08f2fbc8476111b1d7a42f0b9b9eb4e71deeaa) Reviewed-by: Qt Cherry-pick Bot --- src/testlib/qtestcase.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 1f69b725571..4428b8363f6 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #include #include @@ -493,7 +494,7 @@ public: static QMetaMethod findMethod(const QObject *obj, const char *signature); private: - bool invokeTest(int index, QLatin1StringView tag, WatchDog *watchDog) const; + bool invokeTest(int index, QLatin1StringView tag, std::optional &watchDog) const; void invokeTestOnData(int index) const; QMetaMethod m_initTestCaseMethod; // might not exist, check isValid(). @@ -1387,7 +1388,7 @@ static void printUnknownDataTagError(QLatin1StringView name, QLatin1StringView t If the function was successfully called, true is returned, otherwise false. */ -bool TestMethods::invokeTest(int index, QLatin1StringView tag, WatchDog *watchDog) const +bool TestMethods::invokeTest(int index, QLatin1StringView tag, std::optional &watchDog) const { QBenchmarkTestMethodData benchmarkData; QBenchmarkTestMethodData::current = &benchmarkData; @@ -1776,13 +1777,13 @@ void TestMethods::invokeTests(QObject *testObject) const QTestResult::setCurrentTestFunction("initTestCase"); invokeTestMethodIfValid(m_initTestCaseDataMethod, testObject); - QScopedPointer watchDog; + std::optional watchDog = std::nullopt; if (!alreadyDebugging() #if QT_CONFIG(valgrind) && QBenchmarkGlobalData::current->mode() != QBenchmarkGlobalData::CallgrindChildProcess #endif ) { - watchDog.reset(new WatchDog); + watchDog.emplace(); } QSignalDumper::startDump(); @@ -1801,7 +1802,7 @@ void TestMethods::invokeTests(QObject *testObject) const const char *data = nullptr; if (i < QTest::testTags.size() && !QTest::testTags.at(i).isEmpty()) data = qstrdup(QTest::testTags.at(i).toLatin1().constData()); - const bool ok = invokeTest(i, QLatin1StringView(data), watchDog.data()); + const bool ok = invokeTest(i, QLatin1StringView(data), watchDog); delete [] data; if (!ok) break;