summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp')
-rw-r--r--tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp77
1 files changed, 33 insertions, 44 deletions
diff --git a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
index e18c50afbd..141ca25021 100644
--- a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
+++ b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
@@ -1,41 +1,18 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtEndian>
+#include <QSet>
#include <qcoreapplication.h>
#include <qnetworkinterface.h>
#include <qudpsocket.h>
#include "../../../network-settings.h"
+#include <private/qtnetwork-config_p.h>
+
Q_DECLARE_METATYPE(QHostAddress)
class tst_QNetworkInterface : public QObject
@@ -59,6 +36,8 @@ private slots:
void interfaceFromXXX_data();
void interfaceFromXXX();
void copyInvalidInterface();
+private:
+ bool hasNetworkServer = false;
};
tst_QNetworkInterface::tst_QNetworkInterface()
@@ -71,22 +50,29 @@ tst_QNetworkInterface::~tst_QNetworkInterface()
bool tst_QNetworkInterface::isIPv6Working()
{
- QUdpSocket socket;
- socket.connectToHost(QHostAddress::LocalHostIPv6, 1234);
- return socket.state() == QAbstractSocket::ConnectedState || socket.waitForConnected(100);
+ // QNetworkInterface may be unable to detect IPv6 addresses even if they
+ // are there, due to limitations of the implementation.
+ if (QOperatingSystemVersion::currentType() == QOperatingSystemVersion::Windows ||
+ QT_CONFIG(linux_netlink) || (QT_CONFIG(getifaddrs) && QT_CONFIG(ipv6ifname))) {
+ return QtNetworkSettings::hasIPv6();
+ }
+ return false;
}
void tst_QNetworkInterface::initTestCase()
{
- if (!QtNetworkSettings::verifyTestNetworkSettings())
- QSKIP("No network test server available");
+#ifdef QT_TEST_SERVER
+ hasNetworkServer = QtNetworkSettings::verifyConnection(QtNetworkSettings::httpServerName(), 80);
+#else
+ hasNetworkServer = QtNetworkSettings::verifyTestNetworkSettings();
+#endif
}
void tst_QNetworkInterface::dump()
{
// This is for manual testing:
- QList<QNetworkInterface> allInterfaces = QNetworkInterface::allInterfaces();
- foreach (const QNetworkInterface &i, allInterfaces) {
+ const QList<QNetworkInterface> allInterfaces = QNetworkInterface::allInterfaces();
+ for (const QNetworkInterface &i : allInterfaces) {
QString flags;
if (i.flags() & QNetworkInterface::IsUp) flags += "Up,";
if (i.flags() & QNetworkInterface::IsRunning) flags += "Running,";
@@ -113,7 +99,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);
@@ -139,11 +126,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());
@@ -189,7 +176,8 @@ void tst_QNetworkInterface::localAddress_data()
if (ipv6)
QTest::newRow("localhost-ipv6") << QHostAddress(QHostAddress::LocalHostIPv6);
- QTest::newRow("test-server") << QtNetworkSettings::serverIP();
+ if (hasNetworkServer)
+ QTest::newRow("test-server") << QtNetworkSettings::httpServerIp();
QSet<QHostAddress> added;
const QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
@@ -263,10 +251,10 @@ void tst_QNetworkInterface::interfaceFromXXX_data()
{
QTest::addColumn<QNetworkInterface>("iface");
- QList<QNetworkInterface> allInterfaces = QNetworkInterface::allInterfaces();
- if (allInterfaces.count() == 0)
+ 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;
}
@@ -280,7 +268,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()) {