From 4ccbd751f1eee5c27ce5d4c9868d65092630d991 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 13 Aug 2021 12:57:18 +0200 Subject: Use a scope-guard to take care of process deletion in a test Doing the deletion at the end of the block only works if the test passes. Drive-by: remove spurious braces from single-line bodies of single-line controls. The QTest macros are done properly. Pick-to: 6.2 6.1 5.15 Change-Id: I83002547dba49ab9792f4db44d73151b1c036900 Reviewed-by: Sona Kurazyan --- tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index fad0277821..41f90de1e7 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Copyright (C) 2020 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -1243,17 +1244,15 @@ void tst_QProcess::processesInMultipleThreads() threadCount = qMax(threadCount, QThread::idealThreadCount() + 2); QList threads(threadCount); + QScopeGuard cleanup([&threads]() { qDeleteAll(threads); }); for (int j = 0; j < threadCount; ++j) threads[j] = new TestThread; for (int j = 0; j < threadCount; ++j) threads[j]->start(); - for (int j = 0; j < threadCount; ++j) { + for (int j = 0; j < threadCount; ++j) QVERIFY(threads[j]->wait(10000)); - } - for (int j = 0; j < threadCount; ++j) { + for (int j = 0; j < threadCount; ++j) QCOMPARE(threads[j]->code(), 0); - } - qDeleteAll(threads); } } -- cgit v1.2.3