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) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
6a2b565b5b
commit
ff344e647f
@ -1,6 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
** Copyright (C) 2020 The Qt Company Ltd.
|
** Copyright (C) 2021 The Qt Company Ltd.
|
||||||
** Copyright (C) 2020 Intel Corporation.
|
** Copyright (C) 2020 Intel Corporation.
|
||||||
** Contact: https://www.qt.io/licensing/
|
** Contact: https://www.qt.io/licensing/
|
||||||
**
|
**
|
||||||
@ -40,6 +40,7 @@
|
|||||||
#include <QtCore/QRegularExpression>
|
#include <QtCore/QRegularExpression>
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
#include <QtCore/QMetaType>
|
#include <QtCore/QMetaType>
|
||||||
|
#include <QtCore/QScopeGuard>
|
||||||
#include <QtNetwork/QHostInfo>
|
#include <QtNetwork/QHostInfo>
|
||||||
|
|
||||||
#include <qplatformdefs.h>
|
#include <qplatformdefs.h>
|
||||||
@ -1244,17 +1245,15 @@ void tst_QProcess::processesInMultipleThreads()
|
|||||||
threadCount = qMax(threadCount, QThread::idealThreadCount() + 2);
|
threadCount = qMax(threadCount, QThread::idealThreadCount() + 2);
|
||||||
|
|
||||||
QList<TestThread *> threads(threadCount);
|
QList<TestThread *> threads(threadCount);
|
||||||
|
QScopeGuard cleanup([&threads]() { qDeleteAll(threads); });
|
||||||
for (int j = 0; j < threadCount; ++j)
|
for (int j = 0; j < threadCount; ++j)
|
||||||
threads[j] = new TestThread;
|
threads[j] = new TestThread;
|
||||||
for (int j = 0; j < threadCount; ++j)
|
for (int j = 0; j < threadCount; ++j)
|
||||||
threads[j]->start();
|
threads[j]->start();
|
||||||
for (int j = 0; j < threadCount; ++j) {
|
for (int j = 0; j < threadCount; ++j)
|
||||||
QVERIFY(threads[j]->wait(10000));
|
QVERIFY(threads[j]->wait(10000));
|
||||||
}
|
for (int j = 0; j < threadCount; ++j)
|
||||||
for (int j = 0; j < threadCount; ++j) {
|
|
||||||
QCOMPARE(threads[j]->code(), 0);
|
QCOMPARE(threads[j]->code(), 0);
|
||||||
}
|
|
||||||
qDeleteAll(threads);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user