summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-08-08 10:54:07 +0200
committerAhmad Samir <a.samirh78@gmail.com>2023-08-14 23:11:54 +0300
commitf2f8820073488c89fb71e3eb2d2e87bb582c3995 (patch)
tree13e8a7bc5bb755fac84f8e8dc9801a670edea5d0 /tests/auto
parent47375a213f0751b5649ee7c4ae47fae020f9c77f (diff)
tests: port assorted trivial uses of Q_FOREACH to ranged for loops
All of these fall into the trivial category: loops over (readily made) const local containers. As such, they cannot possibly depend on the safety copy that Q_FOREACH performs, so are safe to port as-is to ranged for loops. There may be more where these came from, but these were the ones that stood out as immediately obvious when scanning the 100s of uses in qtbase, so I preferred to directly fix them over white-listing their files with QT_NO_FOREACH (which still may be necessary for some files, as this patch may not port all uses in that file). Pick-to: 6.6 6.5 Task-nubmber: QTBUG-115839 Change-Id: I7b7893bec8254f902660dac24167113aca855029 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp4
-rw-r--r--tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp5
-rw-r--r--tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp4
-rw-r--r--tests/auto/gui/text/qrawfont/tst_qrawfont.cpp4
-rw-r--r--tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp4
-rw-r--r--tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp4
-rw-r--r--tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp4
-rw-r--r--tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp4
-rw-r--r--tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp4
-rw-r--r--tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp4
-rw-r--r--tests/auto/tools/macdeployqt/tst_macdeployqt.cpp2
11 files changed, 22 insertions, 21 deletions
diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
index f4714af91f..bb6ecb45f4 100644
--- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
+++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
@@ -876,8 +876,8 @@ void tst_QPluginLoader::loadMachO_data()
QTest::newRow("machtest/good.fat.stub-i386.dylib") << false;
QDir d(QFINDTESTDATA("machtest"));
- QStringList badlist = d.entryList(QStringList() << "bad*.dylib");
- foreach (const QString &bad, badlist)
+ const QStringList badlist = d.entryList(QStringList() << "bad*.dylib");
+ for (const QString &bad : badlist)
QTest::newRow(qPrintable("machtest/" + bad)) << false;
#endif
}
diff --git a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp
index 3802f8afc6..6f7aa0e180 100644
--- a/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/gui/itemmodels/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -1028,11 +1028,12 @@ void tst_QFileSystemModel::drives()
QFileSystemModel model;
model.setRootPath(path);
model.fetchMore(QModelIndex());
- QFileInfoList drives = QDir::drives();
+ const QFileInfoList drives = QDir::drives();
int driveCount = 0;
- foreach(const QFileInfo& driveRoot, drives)
+ for (const QFileInfo& driveRoot : drives) {
if (driveRoot.exists())
driveCount++;
+ }
QTRY_COMPARE(model.rowCount(), driveCount);
}
diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
index 665ee75a35..172cb2480b 100644
--- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
+++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
@@ -319,8 +319,8 @@ void tst_QFontDatabase::fallbackFonts()
layout.createLine();
layout.endLayout();
- QList<QGlyphRun> runs = layout.glyphRuns(0, 1);
- foreach (QGlyphRun run, runs) {
+ const QList<QGlyphRun> runs = layout.glyphRuns(0, 1);
+ for (QGlyphRun run : runs) {
QRawFont rawFont = run.rawFont();
QVERIFY(rawFont.isValid());
diff --git a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
index 8b203f439e..3c45a18ab2 100644
--- a/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
+++ b/tests/auto/gui/text/qrawfont/tst_qrawfont.cpp
@@ -490,7 +490,7 @@ void tst_QRawFont::supportedWritingSystems_data()
void tst_QRawFont::supportedWritingSystems()
{
QFETCH(QString, fileName);
- QFETCH(WritingSystemList, writingSystems);
+ QFETCH(const WritingSystemList, writingSystems);
QFETCH(QFont::HintingPreference, hintingPreference);
QRawFont font(fileName, 10, hintingPreference);
@@ -499,7 +499,7 @@ void tst_QRawFont::supportedWritingSystems()
WritingSystemList actualWritingSystems = font.supportedWritingSystems();
QCOMPARE(actualWritingSystems.size(), writingSystems.size());
- foreach (QFontDatabase::WritingSystem writingSystem, writingSystems)
+ for (QFontDatabase::WritingSystem writingSystem : writingSystems)
QVERIFY(actualWritingSystems.contains(writingSystem));
}
diff --git a/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp b/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp
index c04530d085..356400f6a8 100644
--- a/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp
+++ b/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp
@@ -166,11 +166,11 @@ void tst_QNetworkRequest::rawHeaderList_data()
void tst_QNetworkRequest::rawHeaderList()
{
- QFETCH(QList<QByteArray>, set);
+ QFETCH(const QList<QByteArray>, set);
QFETCH(QList<QByteArray>, expected);
QNetworkRequest request;
- foreach (QByteArray header, set)
+ for (const QByteArray &header : set)
request.setRawHeader(header, "a value");
QList<QByteArray> got = request.rawHeaderList();
diff --git a/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp b/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp
index 1b7e8db7b1..89d9063f8e 100644
--- a/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp
+++ b/tests/auto/network/kernel/qdnslookup/tst_qdnslookup.cpp
@@ -190,9 +190,9 @@ QString tst_QDnsLookup::domainName(const QString &input)
QString tst_QDnsLookup::domainNameList(const QString &input)
{
- QStringList list = input.split(QLatin1Char(';'));
+ const QStringList list = input.split(QLatin1Char(';'));
QString result;
- foreach (const QString &s, list) {
+ for (const QString &s : list) {
if (!result.isEmpty())
result += ';';
result += domainName(s);
diff --git a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
index 36027d89da..db06b83940 100644
--- a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
+++ b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
@@ -71,8 +71,8 @@ void tst_QNetworkInterface::initTestCase()
void tst_QNetworkInterface::dump()
{
// This is for manual testing:
- QList<QNetworkInterface> allInterfaces = QNetworkInterface::allInterfaces();
- foreach (const QNetworkInterface &i, allInterfaces) {
+ const QList<QNetworkInterface> allInterfaces = QNetworkInterface::allInterfaces();
+ for (const QNetworkInterface &i : allInterfaces) {
QString flags;
if (i.flags() & QNetworkInterface::IsUp) flags += "Up,";
if (i.flags() & QNetworkInterface::IsRunning) flags += "Running,";
diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
index 4e08b5a30f..c1b89f9e56 100644
--- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
@@ -487,8 +487,8 @@ void tst_QTcpSocket::bind_data()
bool testIpv6 = false;
// iterate all interfaces, add all addresses on them as test data
- QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
- foreach (const QNetworkInterface &netinterface, interfaces) {
+ const QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
+ for (const QNetworkInterface &netinterface : interfaces) {
if (!netinterface.isValid())
continue;
diff --git a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp
index 282bec95ef..852825b5d9 100644
--- a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp
+++ b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp
@@ -138,13 +138,13 @@ void tst_QSslCertificate::initTestCase()
testDataDir += QLatin1String("/");
QDir dir(testDataDir + "certificates");
- QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable);
+ const QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files | QDir::Readable);
QRegularExpression rxCert(QLatin1String("^.+\\.(pem|der)$"));
QRegularExpression rxSan(QLatin1String("^(.+\\.(?:pem|der))\\.san$"));
QRegularExpression rxPubKey(QLatin1String("^(.+\\.(?:pem|der))\\.pubkey$"));
QRegularExpression rxDigest(QLatin1String("^(.+\\.(?:pem|der))\\.digest-(md5|sha1)$"));
QRegularExpressionMatch match;
- foreach (QFileInfo fileInfo, fileInfoList) {
+ for (const QFileInfo &fileInfo : fileInfoList) {
if ((match = rxCert.match(fileInfo.fileName())).hasMatch())
certInfoList <<
CertInfo(fileInfo,
diff --git a/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp b/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp
index bdddb93ed5..44ef264c67 100644
--- a/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp
+++ b/tests/auto/printsupport/kernel/qprinterinfo/tst_qprinterinfo.cpp
@@ -340,11 +340,11 @@ void tst_QPrinterInfo::testAssignment()
void tst_QPrinterInfo::namedPrinter()
{
- QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
+ const QList<QPrinterInfo> printers = QPrinterInfo::availablePrinters();
QStringList printerNames;
- foreach (const QPrinterInfo &pi, printers) {
+ for (const QPrinterInfo &pi : printers) {
QPrinterInfo pi2 = QPrinterInfo::printerInfo(pi.printerName());
QCOMPARE(pi2.printerName(), pi.printerName());
QCOMPARE(pi2.description(), pi.description());
diff --git a/tests/auto/tools/macdeployqt/tst_macdeployqt.cpp b/tests/auto/tools/macdeployqt/tst_macdeployqt.cpp
index 9560854197..3953452bf8 100644
--- a/tests/auto/tools/macdeployqt/tst_macdeployqt.cpp
+++ b/tests/auto/tools/macdeployqt/tst_macdeployqt.cpp
@@ -199,7 +199,7 @@ void runVerifyDeployment(const QString &name)
const QList<QString> parts = QString::fromLocal8Bit(libraries).split("dyld: loaded:");
const QString qtPath = QLibraryInfo::path(QLibraryInfo::PrefixPath);
// Let assume Qt is not installed in system
- foreach (QString part, parts) {
+ for (const QString &part : parts) {
part = part.trimmed();
if (part.isEmpty())
continue;