diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-13 12:57:18 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-08-19 16:44:33 +0200 |
commit | 3b184c716eab96741880d2773efa4fa44026e168 (patch) | |
tree | 9b2070c079f29503cb7249d91ba95077c9ee0e0a /tests | |
parent | 91f1be0951fd6c75a8bb7216379e46cfb92b43ec (diff) |
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.
Change-Id: I83002547dba49ab9792f4db44d73151b1c036900
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
(cherry picked from commit 4ccbd751f1eee5c27ce5d4c9868d65092630d991)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 11 |
1 files 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 bc9df3f1f3..db60bead64 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/ ** @@ -39,6 +39,7 @@ #include <QtCore/QRegExp> #include <QtCore/QDebug> #include <QtCore/QMetaType> +#include <QtCore/QScopeGuard> #include <QtNetwork/QHostInfo> #include <qplatformdefs.h> @@ -1271,17 +1272,15 @@ void tst_QProcess::processesInMultipleThreads() threadCount = qMax(threadCount, QThread::idealThreadCount() + 2); QVector<TestThread *> threads(threadCount); + auto cleanup = qScopeGuard([&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); } } |