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>bb10
parent
87aac3caca
commit
1a98293200
|
|
@ -379,7 +379,8 @@ void tst_QDnsLookup::lookup()
|
|||
// host addresses
|
||||
const QString hostName = cname.isEmpty() ? domain : cname;
|
||||
QStringList addresses;
|
||||
foreach (const QDnsHostAddressRecord &record, lookup.hostAddressRecords()) {
|
||||
const auto records = lookup.hostAddressRecords();
|
||||
for (const QDnsHostAddressRecord &record : records) {
|
||||
//reply may include A & AAAA records for nameservers, ignore them and only look at records matching the query
|
||||
if (record.name() == hostName)
|
||||
addresses << record.value().toString().toLower();
|
||||
|
|
@ -389,7 +390,8 @@ void tst_QDnsLookup::lookup()
|
|||
|
||||
// mail exchanges
|
||||
QStringList mailExchanges;
|
||||
foreach (const QDnsMailExchangeRecord &record, lookup.mailExchangeRecords()) {
|
||||
const auto mailRecords = lookup.mailExchangeRecords();
|
||||
for (const QDnsMailExchangeRecord &record : mailRecords) {
|
||||
QCOMPARE(record.name(), domain);
|
||||
mailExchanges << QString::number(record.preference()) + QLatin1Char(' ') + record.exchange();
|
||||
}
|
||||
|
|
@ -398,7 +400,8 @@ void tst_QDnsLookup::lookup()
|
|||
|
||||
// name servers
|
||||
QStringList nameServers;
|
||||
foreach (const QDnsDomainNameRecord &record, lookup.nameServerRecords()) {
|
||||
const auto nameServerRecords = lookup.nameServerRecords();
|
||||
for (const QDnsDomainNameRecord &record : nameServerRecords) {
|
||||
//reply may include NS records for authoritative nameservers, ignore them and only look at records matching the query
|
||||
if (record.name() == domain)
|
||||
nameServers << record.value();
|
||||
|
|
@ -418,7 +421,8 @@ void tst_QDnsLookup::lookup()
|
|||
|
||||
// services
|
||||
QStringList services;
|
||||
foreach (const QDnsServiceRecord &record, lookup.serviceRecords()) {
|
||||
const auto serviceRecords = lookup.serviceRecords();
|
||||
for (const QDnsServiceRecord &record : serviceRecords) {
|
||||
QCOMPARE(record.name(), domain);
|
||||
services << (QString::number(record.priority()) + QLatin1Char(' ')
|
||||
+ QString::number(record.weight()) + QLatin1Char(' ')
|
||||
|
|
@ -429,10 +433,12 @@ void tst_QDnsLookup::lookup()
|
|||
|
||||
// text
|
||||
QStringList texts;
|
||||
foreach (const QDnsTextRecord &record, lookup.textRecords()) {
|
||||
const auto textRecords = lookup.textRecords();
|
||||
for (const QDnsTextRecord &record : textRecords) {
|
||||
QCOMPARE(record.name(), domain);
|
||||
QString text;
|
||||
foreach (const QByteArray &ba, record.values()) {
|
||||
const auto values = record.values();
|
||||
for (const QByteArray &ba : values) {
|
||||
if (!text.isEmpty())
|
||||
text += '\0';
|
||||
text += QString::fromLatin1(ba);
|
||||
|
|
|
|||
|
|
@ -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()) {
|
||||
|
|
|
|||
|
|
@ -95,7 +95,8 @@ void tst_QNetworkProxyFactory::systemProxyForQuery_data()
|
|||
QTest::newRow("autobind-server") << (int)QNetworkProxyQuery::TcpServer << QUrl() << QString() << QString() << 0 << (int)QNetworkProxy::ListeningCapability;
|
||||
QTest::newRow("web-server") << (int)QNetworkProxyQuery::TcpServer << QUrl() << QString() << QString() << 80 << (int)QNetworkProxy::ListeningCapability;
|
||||
//windows: these should be bypassed if "bypass proxy server for local addresses" is ticked
|
||||
foreach (QHostAddress address, QNetworkInterface::allAddresses()) {
|
||||
const auto addresses = QNetworkInterface::allAddresses();
|
||||
for (const QHostAddress &address : addresses) {
|
||||
QTest::newRow(qPrintable(address.toString())) << (int)QNetworkProxyQuery::TcpSocket << QUrl() << QString() << address.toString() << 0 << 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -867,10 +867,12 @@ void tst_QTcpServer::serverAddress_data()
|
|||
QTest::newRow("AnyIPv4") << QHostAddress(QHostAddress::AnyIPv4) << QHostAddress(QHostAddress::AnyIPv4);
|
||||
if (QtNetworkSettings::hasIPv6())
|
||||
QTest::newRow("AnyIPv6") << QHostAddress(QHostAddress::AnyIPv6) << QHostAddress(QHostAddress::AnyIPv6);
|
||||
foreach (const QNetworkInterface &iface, QNetworkInterface::allInterfaces()) {
|
||||
const auto ifaces = QNetworkInterface::allInterfaces();
|
||||
for (const QNetworkInterface &iface : ifaces) {
|
||||
if ((iface.flags() & QNetworkInterface::IsUp) == 0)
|
||||
continue;
|
||||
foreach (const QNetworkAddressEntry &entry, iface.addressEntries()) {
|
||||
const auto entries = iface.addressEntries();
|
||||
for (const QNetworkAddressEntry &entry : entries) {
|
||||
QTest::newRow(qPrintable(entry.ip().toString())) << entry.ip() << entry.ip();
|
||||
}
|
||||
}
|
||||
|
|
@ -924,7 +926,8 @@ void tst_QTcpServer::linkLocal()
|
|||
QSet <QString> scopes;
|
||||
QHostAddress localMaskv4("169.254.0.0");
|
||||
QHostAddress localMaskv6("fe80::");
|
||||
foreach (const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) {
|
||||
const auto ifaces = QNetworkInterface::allInterfaces();
|
||||
for (const QNetworkInterface &iface : ifaces) {
|
||||
//Windows preallocates link local addresses to interfaces that are down.
|
||||
//These may or may not work depending on network driver (they do not work for the Bluetooth PAN driver)
|
||||
if (iface.flags() & QNetworkInterface::IsUp) {
|
||||
|
|
@ -944,7 +947,8 @@ void tst_QTcpServer::linkLocal()
|
|||
if (iface.name().startsWith("awdl"))
|
||||
continue;
|
||||
#endif
|
||||
foreach (QNetworkAddressEntry addressEntry, iface.addressEntries()) {
|
||||
const auto entries = iface.addressEntries();
|
||||
for (const QNetworkAddressEntry &addressEntry : entries) {
|
||||
QHostAddress addr = addressEntry.ip();
|
||||
if (addr.isInSubnet(localMaskv4, 16)) {
|
||||
addresses << addr;
|
||||
|
|
|
|||
|
|
@ -494,7 +494,8 @@ void tst_QTcpSocket::bind_data()
|
|||
if (!netinterface.isValid())
|
||||
continue;
|
||||
|
||||
foreach (const QNetworkAddressEntry &entry, netinterface.addressEntries()) {
|
||||
const auto entries = netinterface.addressEntries();
|
||||
for (const QNetworkAddressEntry &entry : entries) {
|
||||
if (entry.ip().isInSubnet(QHostAddress::parseSubnet("fe80::/10"))
|
||||
|| entry.ip().isInSubnet(QHostAddress::parseSubnet("169.254/16")))
|
||||
continue; // link-local bind will fail, at least on Linux, so skip it.
|
||||
|
|
|
|||
|
|
@ -384,7 +384,8 @@ void tst_QUdpSocket::broadcasting()
|
|||
const char *message[] = {"Yo mista", "", "Yo", "Wassap"};
|
||||
|
||||
QList<QHostAddress> broadcastAddresses;
|
||||
foreach (QNetworkInterface iface, QNetworkInterface::allInterfaces()) {
|
||||
const auto ifaces = QNetworkInterface::allInterfaces();
|
||||
for (const QNetworkInterface &iface : ifaces) {
|
||||
if ((iface.flags() & QNetworkInterface::CanBroadcast)
|
||||
&& iface.flags() & QNetworkInterface::IsUp) {
|
||||
for (int i=0;i<iface.addressEntries().size();i++) {
|
||||
|
|
@ -1392,11 +1393,12 @@ void tst_QUdpSocket::setMulticastInterface_data()
|
|||
{
|
||||
QTest::addColumn<QNetworkInterface>("iface");
|
||||
QTest::addColumn<QHostAddress>("address");
|
||||
QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
|
||||
foreach (const QNetworkInterface &iface, interfaces) {
|
||||
const QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
|
||||
for (const QNetworkInterface &iface : interfaces) {
|
||||
if ((iface.flags() & QNetworkInterface::IsUp) == 0)
|
||||
continue;
|
||||
foreach (const QNetworkAddressEntry &entry, iface.addressEntries()) {
|
||||
const auto entries = iface.addressEntries();
|
||||
for (const QNetworkAddressEntry &entry : entries) {
|
||||
const QByteArray testName = iface.name().toLatin1() + ':' + entry.ip().toString().toLatin1();
|
||||
QTest::newRow(testName.constData()) << iface << entry.ip();
|
||||
}
|
||||
|
|
@ -1601,7 +1603,8 @@ void tst_QUdpSocket::linkLocalIPv6()
|
|||
QList <QHostAddress> addresses;
|
||||
QSet <QString> scopes;
|
||||
QHostAddress localMask("fe80::");
|
||||
foreach (const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) {
|
||||
const auto ifaces = QNetworkInterface::allInterfaces();
|
||||
for (const QNetworkInterface &iface : ifaces) {
|
||||
//Windows preallocates link local addresses to interfaces that are down.
|
||||
//These may or may not work depending on network driver
|
||||
if (iface.flags() & QNetworkInterface::IsUp) {
|
||||
|
|
@ -1616,7 +1619,8 @@ void tst_QUdpSocket::linkLocalIPv6()
|
|||
continue;
|
||||
#endif
|
||||
|
||||
foreach (QNetworkAddressEntry addressEntry, iface.addressEntries()) {
|
||||
const auto entries = iface.addressEntries();
|
||||
for (const QNetworkAddressEntry &addressEntry : entries) {
|
||||
QHostAddress addr(addressEntry.ip());
|
||||
if (!addr.scopeId().isEmpty() && addr.isInSubnet(localMask, 64)) {
|
||||
scopes << addr.scopeId();
|
||||
|
|
@ -1687,7 +1691,8 @@ void tst_QUdpSocket::linkLocalIPv4()
|
|||
|
||||
QList <QHostAddress> addresses;
|
||||
QHostAddress localMask("169.254.0.0");
|
||||
foreach (const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) {
|
||||
const auto ifaces = QNetworkInterface::allInterfaces();
|
||||
for (const QNetworkInterface &iface : ifaces) {
|
||||
//Windows preallocates link local addresses to interfaces that are down.
|
||||
//These may or may not work depending on network driver (they do not work for the Bluetooth PAN driver)
|
||||
if (iface.flags() & QNetworkInterface::IsUp) {
|
||||
|
|
@ -1701,7 +1706,8 @@ void tst_QUdpSocket::linkLocalIPv4()
|
|||
if (iface.name().startsWith("utun"))
|
||||
continue;
|
||||
#endif
|
||||
foreach (QNetworkAddressEntry addr, iface.addressEntries()) {
|
||||
const auto entries = iface.addressEntries();
|
||||
for (const QNetworkAddressEntry &addr : entries) {
|
||||
if (addr.ip().isInSubnet(localMask, 16)) {
|
||||
addresses << addr.ip();
|
||||
qDebug() << "Found IPv4 link local address" << addr.ip();
|
||||
|
|
|
|||
|
|
@ -67,7 +67,8 @@ void tst_QSslEllipticCurve::fromShortName_data()
|
|||
QTest::newRow("QString()") << QString() << QSslEllipticCurve() << false;
|
||||
QTest::newRow("\"\"") << QString("") << QSslEllipticCurve() << false;
|
||||
QTest::newRow("does-not-exist") << QStringLiteral("does-not-exist") << QSslEllipticCurve() << false;
|
||||
Q_FOREACH (QSslEllipticCurve ec, QSslConfiguration::supportedEllipticCurves()) {
|
||||
const auto supported = QSslConfiguration::supportedEllipticCurves();
|
||||
for (QSslEllipticCurve ec : supported) {
|
||||
const QString sN = ec.shortName();
|
||||
QTest::newRow(qPrintable("supported EC \"" + sN + '"')) << sN << ec << true;
|
||||
// At least in the OpenSSL impl, the short name is case-sensitive. That feels odd.
|
||||
|
|
@ -100,7 +101,8 @@ void tst_QSslEllipticCurve::fromLongName_data()
|
|||
QTest::newRow("QString()") << QString() << QSslEllipticCurve() << false;
|
||||
QTest::newRow("\"\"") << QString("") << QSslEllipticCurve() << false;
|
||||
QTest::newRow("does-not-exist") << QStringLiteral("does-not-exist") << QSslEllipticCurve() << false;
|
||||
Q_FOREACH (QSslEllipticCurve ec, QSslConfiguration::supportedEllipticCurves()) {
|
||||
const auto supported = QSslConfiguration::supportedEllipticCurves();
|
||||
for (QSslEllipticCurve ec : supported) {
|
||||
const QString lN = ec.longName();
|
||||
QTest::newRow(qPrintable("supported EC \"" + lN + '"')) << lN << ec << true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue