summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/kernel/qnetworkinterface
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/network/kernel/qnetworkinterface')
-rw-r--r--tests/auto/network/kernel/qnetworkinterface/CMakeLists.txt13
-rw-r--r--tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp48
2 files changed, 39 insertions, 22 deletions
diff --git a/tests/auto/network/kernel/qnetworkinterface/CMakeLists.txt b/tests/auto/network/kernel/qnetworkinterface/CMakeLists.txt
index b8d8f7f5aa..3e5dab63e0 100644
--- a/tests/auto/network/kernel/qnetworkinterface/CMakeLists.txt
+++ b/tests/auto/network/kernel/qnetworkinterface/CMakeLists.txt
@@ -1,13 +1,20 @@
-# Generated from qnetworkinterface.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qnetworkinterface Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qnetworkinterface LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qnetworkinterface
SOURCES
tst_qnetworkinterface.cpp
- PUBLIC_LIBRARIES
- Qt::Network
+ LIBRARIES
+ Qt::NetworkPrivate
QT_TEST_SERVER_LIST "apache2"
)
diff --git a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
index d609bf5877..e5bbf3467c 100644
--- a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
+++ b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
@@ -1,7 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd.
// Copyright (C) 2016 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtEndian>
@@ -12,6 +11,8 @@
#include <qudpsocket.h>
#include "../../../network-settings.h"
+#include <private/qtnetwork-config_p.h>
+
Q_DECLARE_METATYPE(QHostAddress)
class tst_QNetworkInterface : public QObject
@@ -49,14 +50,13 @@ tst_QNetworkInterface::~tst_QNetworkInterface()
bool tst_QNetworkInterface::isIPv6Working()
{
- // Version without following cannot get IPV6 information
- #if !defined(QT_NO_GETIFADDRS) && !defined(QT_NO_IPV6IFNAME)
- QUdpSocket socket;
- socket.connectToHost(QHostAddress::LocalHostIPv6, 1234);
- return socket.state() == QAbstractSocket::ConnectedState || socket.waitForConnected(100);
- #else
- return false;
- #endif
+ // 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()
@@ -71,8 +71,8 @@ void tst_QNetworkInterface::initTestCase()
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,";
@@ -99,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);
@@ -125,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());
@@ -196,6 +197,14 @@ void tst_QNetworkInterface::localAddress_data()
} else if (!ipv6 || entry.prefixLength() != 64) {
continue;
} else {
+#ifdef Q_OS_ANDROID
+ // Android seem to not allow IPv6 connection from interfaces other than wlan,
+ // if it's connected, and wlan is connected by default on Android emulators,
+ // so prefer selecting wlan in this test.
+ const QString scopeId = addr.scopeId();
+ if (!scopeId.isEmpty() && !scopeId.startsWith("wlan"))
+ continue;
+#endif
// add a random node in this IPv6 network
quint64 randomid = qFromBigEndian(Q_UINT64_C(0x8f41f072e5733caa));
QIPv6Address ip6 = addr.toIPv6Address();
@@ -250,10 +259,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;
}
@@ -267,7 +276,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()) {