summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2024-01-26 10:50:43 +0100
committerMarc Mutz <marc.mutz@qt.io>2024-01-27 16:22:36 +0100
commit9a08f2fbc8476111b1d7a42f0b9b9eb4e71deeaa (patch)
treeca17a27c69cba05ae12e194e04273a991ea92a66 /src/testlib
parent1ea51e1f2dfedbea306a16b2a2996ed13c29f7fd (diff)
QTest: hold WatchDog in optional<> instead of QScopedPointer
Means we don't need to allocate it on the heap and optional<> fits the semantics of an optional object better. Pick-to: 6.7 Change-Id: Id02c4847c2357c3033dce94b68787ed37d6ca276 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qtestcase.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 5db6cbd47b..313e9c45c4 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -64,6 +64,7 @@
#include <memory>
#include <mutex>
#include <numeric>
+#include <optional>
#include <stdarg.h>
#include <stdio.h>
@@ -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> &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> &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> watchDog;
+ std::optional<WatchDog> 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;