diff options
author | Shane Kearns <ext-shane.2.kearns@nokia.com> | 2012-05-10 15:37:57 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-24 03:39:40 (GMT) |
commit | 7be85320379f49f04da3860fa14c9929e329acdd (patch) | |
tree | 64d92d53637431081acccb55994e67f851d1f82c /tests | |
parent | 56cd31405241e81633ed6ae64b8f58c840b9a058 (diff) | |
download | Qt-7be85320379f49f04da3860fa14c9929e329acdd.zip Qt-7be85320379f49f04da3860fa14c9929e329acdd.tar.gz Qt-7be85320379f49f04da3860fa14c9929e329acdd.tar.bz2 |
Add test case for link local TCP connections
The socket engines already implemented this, but it is a good idea
to test it explicitly.
Task-number: QTBUG-25634
Change-Id: Ife3fe09b0119ed435e4055523c553847739a09fe
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(back ported from commit e5f77fe31be0ea2c891eacd3e866bb9db4e0a238)
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qtcpserver/tst_qtcpserver.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/auto/qtcpserver/tst_qtcpserver.cpp b/tests/auto/qtcpserver/tst_qtcpserver.cpp index 0052518..dd3d43d 100644 --- a/tests/auto/qtcpserver/tst_qtcpserver.cpp +++ b/tests/auto/qtcpserver/tst_qtcpserver.cpp @@ -115,6 +115,8 @@ private slots: void qtbug6305(); + void linkLocal(); + private: #ifndef QT_NO_BEARERMANAGEMENT QNetworkSession *networkSession; @@ -805,5 +807,75 @@ void tst_QTcpServer::qtbug6305() QVERIFY(!server2.listen(QHostAddress::Any, server.serverPort())); // second listen should fail } +void tst_QTcpServer::linkLocal() +{ + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) + return; + + QList <QHostAddress> addresses; + QSet <QString> scopes; + QHostAddress localMaskv4("169.254.0.0"); + QHostAddress localMaskv6("fe80::"); + foreach (const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) { + //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) { + foreach (QNetworkAddressEntry addressEntry, iface.addressEntries()) { + QHostAddress addr = addressEntry.ip(); + if (addr.isInSubnet(localMaskv4, 16)) { + addresses << addr; + qDebug() << addr; + } + else if (!addr.scopeId().isEmpty() && addr.isInSubnet(localMaskv6, 64)) { + scopes << addr.scopeId(); + addresses << addr; + qDebug() << addr; + } + } + } + } + if (addresses.isEmpty()) + QSKIP("no link local addresses", SkipSingle); + + QList<QTcpServer*> servers; + quint16 port = 0; + foreach (const QHostAddress& addr, addresses) { + QTcpServer *server = new QTcpServer; + QVERIFY(server->listen(addr, port)); + port = server->serverPort(); //listen to same port on different interfaces + servers << server; + } + + QList<QTcpSocket*> clients; + foreach (const QHostAddress& addr, addresses) { + //unbound socket (note, bound TCP client socket not supported by Qt 4.8) + QTcpSocket *socket = new QTcpSocket; + socket->connectToHost(addr, port); + QVERIFY(socket->waitForConnected(5000)); + clients << socket; + } + + //each server should have one connection + foreach (QTcpServer* server, servers) { + QTcpSocket* remote; + //qDebug() << "checking for connections" << server->serverAddress() << ":" << server->serverPort(); + QVERIFY(server->waitForNewConnection(5000)); + QVERIFY(remote = server->nextPendingConnection()); + remote->close(); + delete remote; + QVERIFY(!server->hasPendingConnections()); + } + + //Connecting to the same address with different scope should normally fail + //However it will pass if there are two interfaces connected to the same physical network, + //e.g. connected via wired and wireless interfaces, or two wired NICs. + //which is a reasonably common case. + //So this is not auto tested. + + qDeleteAll(clients); + qDeleteAll(servers); +} + QTEST_MAIN(tst_QTcpServer) #include "tst_qtcpserver.moc" |