diff options
Diffstat (limited to 'tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp')
-rw-r--r-- | tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp index 5695f90c53..36dcec0a82 100644 --- a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp +++ b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp @@ -32,7 +32,7 @@ #include <qcoreapplication.h> #include <qnetworkinterface.h> -#include <qtcpsocket.h> +#include <qudpsocket.h> #ifndef QT_NO_BEARERMANAGEMENT #include <QNetworkConfigurationManager> #include <QNetworkSession> @@ -48,6 +48,8 @@ public: tst_QNetworkInterface(); virtual ~tst_QNetworkInterface(); + bool isIPv6Working(); + private slots: void initTestCase(); void cleanupTestCase(); @@ -76,6 +78,13 @@ tst_QNetworkInterface::~tst_QNetworkInterface() { } +bool tst_QNetworkInterface::isIPv6Working() +{ + QUdpSocket socket; + socket.connectToHost(QHostAddress::LocalHostIPv6, 1234); + return socket.state() == QAbstractSocket::ConnectedState || socket.waitForConnected(100); +} + void tst_QNetworkInterface::initTestCase() { if (!QtNetworkSettings::verifyTestNetworkSettings()) @@ -172,35 +181,21 @@ void tst_QNetworkInterface::loopbackIPv4() void tst_QNetworkInterface::loopbackIPv6() { + if (!isIPv6Working()) + QSKIP("IPv6 not active on this machine"); QList<QHostAddress> all = QNetworkInterface::allAddresses(); - - bool loopbackfound = false; - bool anyIPv6 = false; - foreach (QHostAddress addr, all) - if (addr == QHostAddress::LocalHostIPv6) { - loopbackfound = true; - anyIPv6 = true; - break; - } else if (addr.protocol() == QAbstractSocket::IPv6Protocol) - anyIPv6 = true; - - QVERIFY(!anyIPv6 || loopbackfound); + QVERIFY(all.contains(QHostAddress(QHostAddress::LocalHostIPv6))); } void tst_QNetworkInterface::localAddress() { - QTcpSocket socket; + QUdpSocket socket; socket.connectToHost(QtNetworkSettings::serverName(), 80); QVERIFY(socket.waitForConnected(5000)); QHostAddress local = socket.localAddress(); - // make Apache happy on fluke - socket.write("GET / HTTP/1.0\r\n\r\n"); - socket.waitForBytesWritten(1000); - socket.close(); - - // test that we can find the address that QTcpSocket reported + // test that we can find the address that QUdpSocket reported QList<QHostAddress> all = QNetworkInterface::allAddresses(); QVERIFY(all.contains(local)); } |