QtNetwork auto tests: port Q_FOREACH to ranged-for [2]
The containers are created locally in the top level test functions, they can't be made const due to the way they are filled, however the loop body don't change them; even if the code in a loop would cause re-entrance du due to signal emittance or events processing, those containers aren't affected and aren't changed during iteration because the top-level test functions themselves aren't re-entered, hence use std::as_const. Drive-by change: take QHostAddress by const& when it's used as a for-loop variable (it has a QExplicitlySharedDataPointer d-pointer). Task-number: QTBUG-115839 Change-Id: I443169e10d973aba2f62854aba200fc2dc2c80aa Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>bb10
parent
1a98293200
commit
bca2805b34
|
|
@ -967,7 +967,7 @@ void tst_QTcpServer::linkLocal()
|
|||
|
||||
QList<QTcpServer*> servers;
|
||||
quint16 port = 0;
|
||||
foreach (const QHostAddress& addr, addresses) {
|
||||
for (const QHostAddress &addr : std::as_const(addresses)) {
|
||||
QTcpServer *server = new QTcpServer;
|
||||
QVERIFY(server->listen(addr, port));
|
||||
port = server->serverPort(); //listen to same port on different interfaces
|
||||
|
|
@ -975,7 +975,7 @@ void tst_QTcpServer::linkLocal()
|
|||
}
|
||||
|
||||
QList<QTcpSocket*> clients;
|
||||
foreach (const QHostAddress& addr, addresses) {
|
||||
for (const QHostAddress &addr : std::as_const(addresses)) {
|
||||
//unbound socket
|
||||
QTcpSocket *socket = new QTcpSocket;
|
||||
socket->connectToHost(addr, port);
|
||||
|
|
@ -990,7 +990,7 @@ void tst_QTcpServer::linkLocal()
|
|||
}
|
||||
|
||||
//each server should have two connections
|
||||
foreach (QTcpServer* server, servers) {
|
||||
for (QTcpServer *server : std::as_const(servers)) {
|
||||
//qDebug() << "checking for connections" << server->serverAddress() << ":" << server->serverPort();
|
||||
QVERIFY(server->waitForNewConnection(5000));
|
||||
QTcpSocket* remote = server->nextPendingConnection();
|
||||
|
|
|
|||
|
|
@ -413,7 +413,7 @@ void tst_QUdpSocket::broadcasting()
|
|||
for (int k = 0; k < 4; k++) {
|
||||
broadcastSocket.writeDatagram(message[i], strlen(message[i]),
|
||||
QHostAddress::Broadcast, serverPort);
|
||||
foreach (QHostAddress addr, broadcastAddresses)
|
||||
for (const QHostAddress &addr : std::as_const(broadcastAddresses))
|
||||
broadcastSocket.writeDatagram(message[i], strlen(message[i]), addr, serverPort);
|
||||
}
|
||||
QTestEventLoop::instance().enterLoop(15);
|
||||
|
|
@ -1635,7 +1635,7 @@ void tst_QUdpSocket::linkLocalIPv6()
|
|||
|
||||
QList <QUdpSocket*> sockets;
|
||||
quint16 port = 0;
|
||||
foreach (const QHostAddress& addr, addresses) {
|
||||
for (const QHostAddress &addr : std::as_const(addresses)) {
|
||||
QUdpSocket *s = new QUdpSocket;
|
||||
QVERIFY2(s->bind(addr, port), addr.toString().toLatin1()
|
||||
+ '/' + QByteArray::number(port) + ": " + qPrintable(s->errorString()));
|
||||
|
|
@ -1644,7 +1644,7 @@ void tst_QUdpSocket::linkLocalIPv6()
|
|||
}
|
||||
|
||||
QByteArray testData("hello");
|
||||
foreach (QUdpSocket *s, sockets) {
|
||||
for (QUdpSocket *s : std::as_const(sockets)) {
|
||||
QUdpSocket neutral;
|
||||
QVERIFY(neutral.bind(QHostAddress(QHostAddress::AnyIPv6)));
|
||||
QSignalSpy neutralReadSpy(&neutral, SIGNAL(readyRead()));
|
||||
|
|
@ -1670,9 +1670,8 @@ void tst_QUdpSocket::linkLocalIPv6()
|
|||
QCOMPARE(dgram.data(), testData);
|
||||
|
||||
//sockets bound to other interfaces shouldn't have received anything
|
||||
foreach (QUdpSocket *s2, sockets) {
|
||||
for (QUdpSocket *s2 : std::as_const(sockets))
|
||||
QCOMPARE((int)s2->bytesAvailable(), 0);
|
||||
}
|
||||
|
||||
//Sending to the same address with different scope should normally fail
|
||||
//However it will pass if there is a route between two interfaces,
|
||||
|
|
@ -1720,7 +1719,7 @@ void tst_QUdpSocket::linkLocalIPv4()
|
|||
|
||||
QList <QUdpSocket*> sockets;
|
||||
quint16 port = 0;
|
||||
foreach (const QHostAddress& addr, addresses) {
|
||||
for (const QHostAddress &addr : std::as_const(addresses)) {
|
||||
QUdpSocket *s = new QUdpSocket;
|
||||
QVERIFY2(s->bind(addr, port), qPrintable(s->errorString()));
|
||||
port = s->localPort(); //bind same port, different networks
|
||||
|
|
@ -1731,7 +1730,7 @@ void tst_QUdpSocket::linkLocalIPv4()
|
|||
QVERIFY(neutral.bind(QHostAddress(QHostAddress::AnyIPv4)));
|
||||
|
||||
QByteArray testData("hello");
|
||||
foreach (QUdpSocket *s, sockets) {
|
||||
for (QUdpSocket *s : std::as_const(sockets)) {
|
||||
QVERIFY(s->writeDatagram(testData, s->localAddress(), neutral.localPort()));
|
||||
QVERIFY2(neutral.waitForReadyRead(10000), QtNetworkSettings::msgSocketError(neutral).constData());
|
||||
|
||||
|
|
@ -1763,9 +1762,8 @@ void tst_QUdpSocket::linkLocalIPv4()
|
|||
QCOMPARE(dgram.data(), testData);
|
||||
|
||||
//sockets bound to other interfaces shouldn't have received anything
|
||||
foreach (QUdpSocket *s2, sockets) {
|
||||
for (QUdpSocket *s2 : std::as_const(sockets))
|
||||
QCOMPARE((int)s2->bytesAvailable(), 0);
|
||||
}
|
||||
}
|
||||
qDeleteAll(sockets);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1084,7 +1084,7 @@ void tst_QSslCertificate::verify()
|
|||
toVerify = QSslCertificate::fromPath(testDataDir + "verify-certs/test-addons-mozilla-org-cert.pem", QSsl::Pem, QSslCertificate::PatternSyntax::FixedString);
|
||||
errors = QSslCertificate::verify(toVerify);
|
||||
bool foundBlack = false;
|
||||
foreach (const QSslError &error, errors) {
|
||||
for (const QSslError &error : std::as_const(errors)) {
|
||||
if (error.error() == QSslError::CertificateBlacklisted) {
|
||||
foundBlack = true;
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue