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. Change-Id: Id02c4847c2357c3033dce94b68787ed37d6ca276 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 9a08f2fbc8476111b1d7a42f0b9b9eb4e71deeaa) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
1b559b25a6
commit
12fdb3bc1f
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user