summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2023-08-11 19:49:42 +0300
committerAhmad Samir <a.samirh78@gmail.com>2023-08-22 21:47:16 +0300
commit1a9829320005d4ca876d35f70eac309fcab293d5 (patch)
treeae041afb88960d0820d4745132ca37da650d9b78 /tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
parent87aac3caca30f9f9ac9efbe895ec0f9fafab8155 (diff)
QtNetwork auto tests: port Q_FOREACH to ranged-for [1]
The loops were iterating over a temporary, so use a local const auto variable to hold it, and use ranged-for. Drive-by, make the for-loop variable const& instead of copying it, for any object that has a d-pointer (QNetworkAddressEntry, QHostAddress, QNetworkInterface). Task-number: QTBUG-115839 Change-Id: If96c0b2a6142fe2fa2ed45ed7e2435cc1f80e005 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp')
-rw-r--r--tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
index e0436d2d99..5fa684ca14 100644
--- a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
+++ b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
@@ -100,7 +100,8 @@ void tst_QNetworkInterface::dump()
qDebug() << " MTU: " << i.maximumTransmissionUnit();
int count = 0;
- foreach (const QNetworkAddressEntry &e, i.addressEntries()) {
+ const auto entries = i.addressEntries();
+ for (const QNetworkAddressEntry &e : entries) {
QDebug s = qDebug();
s.nospace() << " address "
<< qSetFieldWidth(2) << count++ << qSetFieldWidth(0);
@@ -126,11 +127,11 @@ void tst_QNetworkInterface::dump()
void tst_QNetworkInterface::consistencyCheck()
{
- QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
+ const QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
QSet<QString> interfaceNames;
QList<int> interfaceIndexes;
- foreach (const QNetworkInterface &iface, ifaces) {
+ for (const QNetworkInterface &iface : ifaces) {
QVERIFY(iface.isValid());
QVERIFY2(!interfaceNames.contains(iface.name()),
"duplicate name = " + iface.name().toLocal8Bit());
@@ -251,10 +252,10 @@ void tst_QNetworkInterface::interfaceFromXXX_data()
{
QTest::addColumn<QNetworkInterface>("iface");
- QList<QNetworkInterface> allInterfaces = QNetworkInterface::allInterfaces();
+ const QList<QNetworkInterface> allInterfaces = QNetworkInterface::allInterfaces();
if (allInterfaces.size() == 0)
QSKIP("No interfaces to test!");
- foreach (QNetworkInterface iface, allInterfaces)
+ for (const QNetworkInterface &iface : allInterfaces)
QTest::newRow(iface.name().toLocal8Bit()) << iface;
}
@@ -268,7 +269,8 @@ void tst_QNetworkInterface::interfaceFromXXX()
QCOMPARE(QNetworkInterface::interfaceNameFromIndex(idx), iface.name());
QCOMPARE(QNetworkInterface::interfaceIndexFromName(iface.name()), idx);
}
- foreach (QNetworkAddressEntry entry, iface.addressEntries()) {
+ const auto entries = iface.addressEntries();
+ for (const QNetworkAddressEntry &entry : entries) {
QVERIFY(!entry.ip().isNull());
if (!entry.netmask().isNull()) {