tst_QDirIterator: build with QT_NO_FOREACH

cleanupTestCase: the loops don't change the member containers, so use
std::as_const and ranged for.

iterateRelativeDirectory(): the for loop doesn't change the container,
so make it const to begin with, and use a ranged-for loop.

Drive-by change: make the for-loop variables const&, no need to create
unnecessary copies.

Task-number: QTBUG-115839
Change-Id: Ic2776459f695c9f334f83916b1c9bbe5646a3b9d
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Ahmad Samir 2023-08-11 02:57:57 +03:00
parent 019554a399
commit c7a8e1e992

View File

@ -1,8 +1,6 @@
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include <QTest>
#include <qcoreapplication.h>
@ -194,10 +192,10 @@ void tst_QDirIterator::initTestCase()
void tst_QDirIterator::cleanupTestCase()
{
Q_FOREACH(QString fileName, createdFiles)
for (const QString &fileName : std::as_const(createdFiles))
QFile::remove(fileName);
Q_FOREACH(QString dirName, createdDirectories)
for (const QString &dirName : std::as_const(createdDirectories))
currentDir.rmdir(dirName);
}
@ -325,7 +323,7 @@ void tst_QDirIterator::iterateRelativeDirectory()
QFETCH(QDirIterator::IteratorFlags, flags);
QFETCH(QDir::Filters, filters);
QFETCH(QStringList, nameFilters);
QFETCH(QStringList, entries);
QFETCH(const QStringList, entries);
QDirIterator it(dirName, nameFilters, filters, flags);
QStringList list;
@ -353,7 +351,7 @@ void tst_QDirIterator::iterateRelativeDirectory()
list.sort();
QStringList sortedEntries;
foreach(QString item, entries)
for (const QString &item : entries)
sortedEntries.append(QFileInfo(item).canonicalFilePath());
sortedEntries.sort();