summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/socket
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/network/socket')
-rw-r--r--tests/auto/network/socket/CMakeLists.txt7
-rw-r--r--tests/auto/network/socket/platformsocketengine/BLACKLIST9
-rw-r--r--tests/auto/network/socket/platformsocketengine/CMakeLists.txt18
-rw-r--r--tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp45
-rw-r--r--tests/auto/network/socket/qabstractsocket/CMakeLists.txt11
-rw-r--r--tests/auto/network/socket/qabstractsocket/tst_qabstractsocket.cpp29
-rw-r--r--tests/auto/network/socket/qhttpsocketengine/BLACKLIST3
-rw-r--r--tests/auto/network/socket/qhttpsocketengine/CMakeLists.txt20
-rw-r--r--tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp37
-rw-r--r--tests/auto/network/socket/qlocalsocket/BLACKLIST3
-rw-r--r--tests/auto/network/socket/qlocalsocket/CMakeLists.txt16
-rw-r--r--tests/auto/network/socket/qlocalsocket/socketprocess/CMakeLists.txt5
-rw-r--r--tests/auto/network/socket/qlocalsocket/socketprocess/main.cpp29
-rw-r--r--tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp249
-rw-r--r--tests/auto/network/socket/qsctpsocket/CMakeLists.txt11
-rw-r--r--tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp40
-rw-r--r--tests/auto/network/socket/qsocks5socketengine/BLACKLIST8
-rw-r--r--tests/auto/network/socket/qsocks5socketengine/CMakeLists.txt20
-rw-r--r--tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp41
-rw-r--r--tests/auto/network/socket/qtcpserver/BLACKLIST10
-rw-r--r--tests/auto/network/socket/qtcpserver/CMakeLists.txt11
-rw-r--r--tests/auto/network/socket/qtcpserver/crashingServer/CMakeLists.txt5
-rw-r--r--tests/auto/network/socket/qtcpserver/crashingServer/main.cpp62
-rw-r--r--tests/auto/network/socket/qtcpserver/test/CMakeLists.txt19
-rw-r--r--tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp176
-rw-r--r--tests/auto/network/socket/qtcpsocket/BLACKLIST26
-rw-r--r--tests/auto/network/socket/qtcpsocket/CMakeLists.txt9
-rw-r--r--tests/auto/network/socket/qtcpsocket/stressTest/CMakeLists.txt9
-rw-r--r--tests/auto/network/socket/qtcpsocket/stressTest/Test.cpp29
-rw-r--r--tests/auto/network/socket/qtcpsocket/stressTest/Test.h29
-rw-r--r--tests/auto/network/socket/qtcpsocket/stressTest/main.cpp29
-rw-r--r--tests/auto/network/socket/qtcpsocket/test/CMakeLists.txt23
-rw-r--r--tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp103
-rw-r--r--tests/auto/network/socket/qudpsocket/BLACKLIST6
-rw-r--r--tests/auto/network/socket/qudpsocket/CMakeLists.txt11
-rw-r--r--tests/auto/network/socket/qudpsocket/clientserver/CMakeLists.txt5
-rw-r--r--tests/auto/network/socket/qudpsocket/clientserver/main.cpp29
-rw-r--r--tests/auto/network/socket/qudpsocket/test/CMakeLists.txt30
-rw-r--r--tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp343
-rw-r--r--tests/auto/network/socket/qudpsocket/udpServer/CMakeLists.txt7
-rw-r--r--tests/auto/network/socket/qudpsocket/udpServer/main.cpp29
41 files changed, 725 insertions, 876 deletions
diff --git a/tests/auto/network/socket/CMakeLists.txt b/tests/auto/network/socket/CMakeLists.txt
index 6e4421aad8..c3f8e8f87f 100644
--- a/tests/auto/network/socket/CMakeLists.txt
+++ b/tests/auto/network/socket/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from socket.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
if(QT_FEATURE_private_tests)
add_subdirectory(qhttpsocketengine)
@@ -9,9 +10,9 @@ endif()
add_subdirectory(qudpsocket)
add_subdirectory(qabstractsocket)
if(NOT ANDROID)
- # QTBUG-87387 # special case
+ # QTBUG-87387
add_subdirectory(qlocalsocket)
- # QTBUG-87388 # special case
+ # QTBUG-87388
add_subdirectory(qtcpserver)
endif()
if(QT_FEATURE_sctp)
diff --git a/tests/auto/network/socket/platformsocketengine/BLACKLIST b/tests/auto/network/socket/platformsocketengine/BLACKLIST
index f1f88d26d1..796f81a02a 100644
--- a/tests/auto/network/socket/platformsocketengine/BLACKLIST
+++ b/tests/auto/network/socket/platformsocketengine/BLACKLIST
@@ -1,11 +1,2 @@
[tcpLoopbackPerformance]
-windows-10 msvc-2015
-windows-7sp1
-[receiveUrgentData]
-windows-10 msvc-2015
-windows-7sp1
-[serverTest]
-windows-10 msvc-2015
-windows-7sp1
-[tcpLoopbackPerformance]
windows
diff --git a/tests/auto/network/socket/platformsocketengine/CMakeLists.txt b/tests/auto/network/socket/platformsocketengine/CMakeLists.txt
index cfd8a118ca..891041df04 100644
--- a/tests/auto/network/socket/platformsocketengine/CMakeLists.txt
+++ b/tests/auto/network/socket/platformsocketengine/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from platformsocketengine.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_platformsocketengine LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
if(NOT QT_FEATURE_private_tests)
return()
@@ -11,19 +18,16 @@ endif()
qt_internal_add_test(tst_platformsocketengine
SOURCES
tst_platformsocketengine.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::NetworkPrivate
+ QT_TEST_SERVER_LIST "cyrus"
)
-#### Keys ignored in scope 1:.:.:platformsocketengine.pro:<TRUE>:
-# MOC_DIR = "tmp"
-# _REQUIREMENTS = "qtConfig(private_tests)"
-
## Scopes:
#####################################################################
qt_internal_extend_target(tst_platformsocketengine CONDITION WIN32
- PUBLIC_LIBRARIES
+ LIBRARIES
ws2_32
)
diff --git a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp
index 23566a3d70..1f6ecf9200 100644
--- a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp
+++ b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp
@@ -1,31 +1,6 @@
-/****************************************************************************
-**
-** 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 <QtTest/QTest>
@@ -48,7 +23,7 @@
#define PLATFORMSOCKETENGINE QNativeSocketEngine
#define PLATFORMSOCKETENGINESTRING "QNativeSocketEngine"
-#include <private/qnativesocketengine_p.h>
+#include <private/qnativesocketengine_p_p.h>
#include <qstringlist.h>
@@ -81,8 +56,12 @@ private slots:
void tst_PlatformSocketEngine::initTestCase()
{
+#ifdef QT_TEST_SERVER
+ QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::imapServerName(), 143));
+#else
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
+#endif
}
//---------------------------------------------------------------------------
@@ -122,14 +101,14 @@ void tst_PlatformSocketEngine::simpleConnectToIMAP()
QVERIFY(socketDevice.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol));
QCOMPARE(socketDevice.state(), QAbstractSocket::UnconnectedState);
- const bool isConnected = socketDevice.connectToHost(QtNetworkSettings::serverIP(), 143);
+ const bool isConnected = socketDevice.connectToHost(QtNetworkSettings::imapServerIp(), 143);
if (!isConnected) {
QCOMPARE(socketDevice.state(), QAbstractSocket::ConnectingState);
QVERIFY(socketDevice.waitForWrite());
QCOMPARE(socketDevice.state(), QAbstractSocket::ConnectedState);
}
QCOMPARE(socketDevice.state(), QAbstractSocket::ConnectedState);
- QCOMPARE(socketDevice.peerAddress(), QtNetworkSettings::serverIP());
+ QCOMPARE(socketDevice.peerAddress(), QtNetworkSettings::imapServerIp());
// Wait for the greeting
QVERIFY(socketDevice.waitForRead());
@@ -276,7 +255,7 @@ void tst_PlatformSocketEngine::broadcastTest()
PLATFORMSOCKETENGINE broadcastSocket;
// Initialize a regular Udp socket
- QVERIFY(broadcastSocket.initialize(QAbstractSocket::UdpSocket, QAbstractSocket::AnyIPProtocol));
+ QVERIFY(broadcastSocket.initialize(QAbstractSocket::UdpSocket, QAbstractSocket::IPv4Protocol));
// Bind to any port on all interfaces
QVERIFY(broadcastSocket.bind(QHostAddress::Any, 0));
@@ -567,7 +546,7 @@ void tst_PlatformSocketEngine::networkError()
QVERIFY(client.initialize(QAbstractSocket::TcpSocket, QAbstractSocket::IPv4Protocol));
- const bool isConnected = client.connectToHost(QtNetworkSettings::serverIP(), 143);
+ const bool isConnected = client.connectToHost(QtNetworkSettings::imapServerIp(), 143);
if (!isConnected) {
QCOMPARE(client.state(), QAbstractSocket::ConnectingState);
QVERIFY(client.waitForWrite());
diff --git a/tests/auto/network/socket/qabstractsocket/CMakeLists.txt b/tests/auto/network/socket/qabstractsocket/CMakeLists.txt
index ee83261ab0..3ca18aceef 100644
--- a/tests/auto/network/socket/qabstractsocket/CMakeLists.txt
+++ b/tests/auto/network/socket/qabstractsocket/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qabstractsocket.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qabstractsocket Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qabstractsocket LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qabstractsocket
SOURCES
tst_qabstractsocket.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
)
diff --git a/tests/auto/network/socket/qabstractsocket/tst_qabstractsocket.cpp b/tests/auto/network/socket/qabstractsocket/tst_qabstractsocket.cpp
index bb5e8090f8..6b038acdfa 100644
--- a/tests/auto/network/socket/qabstractsocket/tst_qabstractsocket.cpp
+++ b/tests/auto/network/socket/qabstractsocket/tst_qabstractsocket.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** 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.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
diff --git a/tests/auto/network/socket/qhttpsocketengine/BLACKLIST b/tests/auto/network/socket/qhttpsocketengine/BLACKLIST
index ceb3b7862e..e0cd701636 100644
--- a/tests/auto/network/socket/qhttpsocketengine/BLACKLIST
+++ b/tests/auto/network/socket/qhttpsocketengine/BLACKLIST
@@ -1,5 +1,2 @@
-[downloadBigFile]
-windows-10 msvc-2015
-windows-7sp1
[ensureEofTriggersNotification]
windows
diff --git a/tests/auto/network/socket/qhttpsocketengine/CMakeLists.txt b/tests/auto/network/socket/qhttpsocketengine/CMakeLists.txt
index fcad653783..6b4f904725 100644
--- a/tests/auto/network/socket/qhttpsocketengine/CMakeLists.txt
+++ b/tests/auto/network/socket/qhttpsocketengine/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qhttpsocketengine.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qhttpsocketengine LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
if(NOT QT_FEATURE_private_tests)
return()
@@ -11,23 +18,18 @@ endif()
qt_internal_add_test(tst_qhttpsocketengine
SOURCES
tst_qhttpsocketengine.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::NetworkPrivate
- QT_TEST_SERVER_LIST "squid" "danted" "cyrus" "apache2" # special case
+ QT_TEST_SERVER_LIST "squid" "danted" "cyrus" "apache2"
)
-#### Keys ignored in scope 1:.:.:qhttpsocketengine.pro:<TRUE>:
-# MOC_DIR = "tmp"
-# _REQUIREMENTS = "qtConfig(private_tests)"
-
## Scopes:
#####################################################################
-#### Keys ignored in scope 2:.:.:qhttpsocketengine.pro:LINUX:
# QT_TEST_SERVER_LIST = "squid" "danted" "cyrus" "apache2"
qt_internal_extend_target(tst_qhttpsocketengine CONDITION WIN32
- PUBLIC_LIBRARIES
+ LIBRARIES
ws2_32
)
diff --git a/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp b/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp
index 2d0d9f5ffc..a52099b5b4 100644
--- a/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp
+++ b/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** 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.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QTest>
@@ -43,6 +18,8 @@
#include "../../../network-settings.h"
+using namespace std::chrono_literals;
+
class tst_QHttpSocketEngine : public QObject
{
Q_OBJECT
@@ -108,9 +85,9 @@ public slots:
int idx = client->property("dataTransmitionIdx").toInt();
if (receivedData.contains("\r\n\r\n") ||
receivedData.contains("\n\n")) {
- if (idx < dataToTransmit.length())
+ if (idx < dataToTransmit.size())
client->write(dataToTransmit.at(idx++));
- if (idx == dataToTransmit.length()) {
+ if (idx == dataToTransmit.size()) {
client->disconnectFromHost();
disconnect(client, 0, this, 0);
client = 0;
@@ -348,7 +325,7 @@ void tst_QHttpSocketEngine::simpleErrorsAndStates()
QCOMPARE(socketDevice.state(), QAbstractSocket::UnconnectedState);
QVERIFY(!socketDevice.connectToHost(QHostAddress(QtNetworkSettings::socksProxyServerName()), 8088));
QCOMPARE(socketDevice.state(), QAbstractSocket::ConnectingState);
- if (socketDevice.waitForWrite(30000)) {
+ if (socketDevice.waitForWrite(30s)) {
QVERIFY(socketDevice.state() == QAbstractSocket::ConnectedState ||
socketDevice.state() == QAbstractSocket::UnconnectedState);
} else {
diff --git a/tests/auto/network/socket/qlocalsocket/BLACKLIST b/tests/auto/network/socket/qlocalsocket/BLACKLIST
index cec50425c5..730b7e6d2f 100644
--- a/tests/auto/network/socket/qlocalsocket/BLACKLIST
+++ b/tests/auto/network/socket/qlocalsocket/BLACKLIST
@@ -3,5 +3,8 @@
android
[processConnection]
android
+windows
[verifySocketOptions]
android
+[threadedConnection]
+windows
diff --git a/tests/auto/network/socket/qlocalsocket/CMakeLists.txt b/tests/auto/network/socket/qlocalsocket/CMakeLists.txt
index b0eca25191..4b886a02ee 100644
--- a/tests/auto/network/socket/qlocalsocket/CMakeLists.txt
+++ b/tests/auto/network/socket/qlocalsocket/CMakeLists.txt
@@ -1,14 +1,22 @@
-# Generated from qlocalsocket.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qlocalsocket LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
-# add_subdirectory(test) # special case remove
add_subdirectory(socketprocess)
+
qt_internal_add_test(tst_qlocalsocket
SOURCES
tst_qlocalsocket.cpp
DEFINES
QLOCALSERVER_DEBUG
QLOCALSOCKET_DEBUG
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
+ Qt::TestPrivate
)
-# special case end
+add_dependencies(tst_qlocalsocket socketprocess)
diff --git a/tests/auto/network/socket/qlocalsocket/socketprocess/CMakeLists.txt b/tests/auto/network/socket/qlocalsocket/socketprocess/CMakeLists.txt
index adf1752ac0..3e0476d2b6 100644
--- a/tests/auto/network/socket/qlocalsocket/socketprocess/CMakeLists.txt
+++ b/tests/auto/network/socket/qlocalsocket/socketprocess/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from socketprocess.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## socketprocess Binary:
@@ -8,7 +9,7 @@ qt_internal_add_executable(socketprocess
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/"
SOURCES
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
Qt::Test
)
diff --git a/tests/auto/network/socket/qlocalsocket/socketprocess/main.cpp b/tests/auto/network/socket/qlocalsocket/socketprocess/main.cpp
index 272e837ac5..d254253aca 100644
--- a/tests/auto/network/socket/qlocalsocket/socketprocess/main.cpp
+++ b/tests/auto/network/socket/qlocalsocket/socketprocess/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** 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.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qcoreapplication.h>
diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
index ba699242fd..1ecd871ceb 100644
--- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
+++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
@@ -1,35 +1,11 @@
-/****************************************************************************
-**
-** 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 <QSignalSpy>
+#include <QtTest/private/qpropertytesthelper_p.h>
#if QT_CONFIG(process)
#include <QProcess>
#endif
@@ -148,6 +124,7 @@ private slots:
void verifyListenWithDescriptor_data();
void serverBindingsAndProperties();
+ void socketBindings();
protected slots:
void socketClosedSlot();
@@ -162,14 +139,13 @@ tst_QLocalSocket::tst_QLocalSocket()
qRegisterMetaType<QFile::Permissions>("QFile::Permissions");
}
-class LocalServer : public QLocalServer
+class CrashSafeLocalServer : public QLocalServer
{
Q_OBJECT
public:
- LocalServer() : QLocalServer()
+ CrashSafeLocalServer() : QLocalServer()
{
- connect(this, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
}
bool listen(const QString &name)
@@ -178,6 +154,19 @@ public:
return QLocalServer::listen(name);
}
+ bool listen(qintptr socketDescriptor) { return QLocalServer::listen(socketDescriptor); }
+};
+
+class LocalServer : public CrashSafeLocalServer
+{
+ Q_OBJECT
+
+public:
+ LocalServer() : CrashSafeLocalServer()
+ {
+ connect(this, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
+ }
+
QList<int> hits;
protected:
@@ -258,8 +247,8 @@ void tst_QLocalSocket::server_basic()
QVERIFY(!timedOut);
QCOMPARE(server.listen(QString()), false);
- QCOMPARE(server.hits.count(), 0);
- QCOMPARE(spyNewConnection.count(), 0);
+ QCOMPARE(server.hits.size(), 0);
+ QCOMPARE(spyNewConnection.size(), 0);
}
void tst_QLocalSocket::server_connectionsCount()
@@ -300,11 +289,11 @@ void tst_QLocalSocket::socket_basic()
QCOMPARE(socket.waitForDisconnected(0), false);
QCOMPARE(socket.waitForReadyRead(0), false);
- QCOMPARE(spyConnected.count(), 0);
- QCOMPARE(spyDisconnected.count(), 0);
- QCOMPARE(spyError.count(), 0);
- QCOMPARE(spyStateChanged.count(), 0);
- QCOMPARE(spyReadyRead.count(), 0);
+ QCOMPARE(spyConnected.size(), 0);
+ QCOMPARE(spyDisconnected.size(), 0);
+ QCOMPARE(spyError.size(), 0);
+ QCOMPARE(spyStateChanged.size(), 0);
+ QCOMPARE(spyReadyRead.size(), 0);
}
void tst_QLocalSocket::listen_data()
@@ -313,8 +302,8 @@ void tst_QLocalSocket::listen_data()
QTest::addColumn<bool>("canListen");
QTest::addColumn<bool>("close");
QTest::newRow("null") << QString() << false << false;
- QTest::newRow("tst_localsocket") << "tst_localsocket" << true << true;
- QTest::newRow("tst_localsocket") << "tst_localsocket" << true << false;
+ QTest::newRow("tst_localsocket,close") << "tst_localsocket" << true << true;
+ QTest::newRow("tst_localsocket,no-close") << "tst_localsocket" << true << false;
}
// start a server that listens, but don't connect a socket, make sure everything is in order
@@ -326,7 +315,7 @@ void tst_QLocalSocket::listen()
QFETCH(QString, name);
QFETCH(bool, canListen);
QFETCH(bool, close);
- QVERIFY2((server.listen(name) == canListen), server.errorString().toLatin1().constData());
+ QVERIFY2((server.listen(name) == canListen), qUtf8Printable(server.errorString()));
// test listening
QCOMPARE(server.serverName(), name);
@@ -334,8 +323,8 @@ void tst_QLocalSocket::listen()
QCOMPARE(server.isListening(), canListen);
QCOMPARE(server.hasPendingConnections(), false);
QCOMPARE(server.nextPendingConnection(), (QLocalSocket*)0);
- QCOMPARE(server.hits.count(), 0);
- QCOMPARE(spyNewConnection.count(), 0);
+ QCOMPARE(server.hits.size(), 0);
+ QCOMPARE(spyNewConnection.size(), 0);
if (canListen) {
QVERIFY(server.errorString().isEmpty());
QCOMPARE(server.serverError(), QAbstractSocket::UnknownSocketError);
@@ -409,7 +398,7 @@ void tst_QLocalSocket::listenAndConnect()
QCOMPARE(socket->error(), QLocalSocket::UnknownSocketError);
QCOMPARE(socket->state(), QLocalSocket::ConnectedState);
//QVERIFY(socket->socketDescriptor() != -1);
- QCOMPARE(spyError.count(), 0);
+ QCOMPARE(spyError.size(), 0);
} else {
QVERIFY(!socket->errorString().isEmpty());
QVERIFY(socket->error() != QLocalSocket::UnknownSocketError);
@@ -428,13 +417,13 @@ void tst_QLocalSocket::listenAndConnect()
QCOMPARE(socket->waitForConnected(0), canListen);
QCOMPARE(socket->waitForReadyRead(0), false);
- QTRY_COMPARE(spyConnected.count(), canListen ? 1 : 0);
- QCOMPARE(spyDisconnected.count(), 0);
+ QTRY_COMPARE(spyConnected.size(), canListen ? 1 : 0);
+ QCOMPARE(spyDisconnected.size(), 0);
// error signals
- QVERIFY(spyError.count() >= 0);
+ QVERIFY(spyError.size() >= 0);
if (canListen) {
- if (spyError.count() > 0)
+ if (spyError.size() > 0)
QCOMPARE(qvariant_cast<QLocalSocket::LocalSocketError>(spyError.first()[0]),
QLocalSocket::SocketTimeoutError);
} else {
@@ -449,8 +438,8 @@ void tst_QLocalSocket::listenAndConnect()
if (canListen)
QCOMPARE(qvariant_cast<QLocalSocket::LocalSocketState>(spyStateChanged.last()[0]),
QLocalSocket::ConnectedState);
- QCOMPARE(spyStateChanged.count(), 2);
- QCOMPARE(spyReadyRead.count(), 0);
+ QCOMPARE(spyStateChanged.size(), 2);
+ QCOMPARE(spyReadyRead.size(), 0);
bool timedOut = true;
QCOMPARE(server.waitForNewConnection(3000, &timedOut), canListen);
@@ -464,16 +453,16 @@ void tst_QLocalSocket::listenAndConnect()
QCOMPARE(server.serverName(), name);
QVERIFY(server.fullServerName().contains(name));
QVERIFY(server.nextPendingConnection() != (QLocalSocket*)0);
- QTRY_COMPARE(server.hits.count(), i + 1);
- QCOMPARE(spyNewConnection.count(), i + 1);
+ QTRY_COMPARE(server.hits.size(), i + 1);
+ QCOMPARE(spyNewConnection.size(), i + 1);
QVERIFY(server.errorString().isEmpty());
QCOMPARE(server.serverError(), QAbstractSocket::UnknownSocketError);
} else {
QVERIFY(server.serverName().isEmpty());
QVERIFY(server.fullServerName().isEmpty());
QCOMPARE(server.nextPendingConnection(), (QLocalSocket*)0);
- QCOMPARE(spyNewConnection.count(), 0);
- QCOMPARE(server.hits.count(), 0);
+ QCOMPARE(spyNewConnection.size(), 0);
+ QCOMPARE(server.hits.size(), 0);
QVERIFY(!server.errorString().isEmpty());
QCOMPARE(server.serverError(), QAbstractSocket::HostNotFoundError);
}
@@ -482,14 +471,14 @@ void tst_QLocalSocket::listenAndConnect()
server.close();
- QCOMPARE(server.hits.count(), (canListen ? connections : 0));
- QCOMPARE(spyNewConnection.count(), (canListen ? connections : 0));
+ QCOMPARE(server.hits.size(), (canListen ? connections : 0));
+ QCOMPARE(spyNewConnection.size(), (canListen ? connections : 0));
}
void tst_QLocalSocket::connectWithOpen()
{
LocalServer server;
- QVERIFY(server.listen("tst_qlocalsocket"));
+ QVERIFY2(server.listen("tst_qlocalsocket"), qUtf8Printable(server.errorString()));
LocalSocket socket;
QSignalSpy spyAboutToClose(&socket, SIGNAL(aboutToClose()));
@@ -507,7 +496,7 @@ void tst_QLocalSocket::connectWithOpen()
socket.close();
server.close();
- QCOMPARE(spyAboutToClose.count(), 1);
+ QCOMPARE(spyAboutToClose.size(), 1);
}
void tst_QLocalSocket::listenAndConnectAbstractNamespaceTrailingZeros_data()
@@ -541,7 +530,7 @@ void tst_QLocalSocket::listenAndConnectAbstractNamespaceTrailingZeros()
client_path.append(QChar('\0'));
LocalServer server;
server.setSocketOptions(QLocalServer::AbstractNamespaceOption);
- QVERIFY(server.listen(server_path));
+ QVERIFY2(server.listen(server_path), qUtf8Printable(server.errorString()));
QCOMPARE(server.fullServerName(), server_path);
LocalSocket socket;
@@ -590,7 +579,7 @@ void tst_QLocalSocket::listenAndConnectAbstractNamespace()
LocalServer server;
server.setSocketOptions(serverOption);
- QVERIFY(server.listen("tst_qlocalsocket"));
+ QVERIFY2(server.listen("tst_qlocalsocket"), qUtf8Printable(server.errorString()));
LocalSocket socket;
socket.setSocketOptions(socketOption);
@@ -673,7 +662,7 @@ void tst_QLocalSocket::sendData()
QTest::qWait(250);
#endif
QVERIFY(!timedOut);
- QCOMPARE(spyConnected.count(), canListen ? 1 : 0);
+ QCOMPARE(spyConnected.size(), canListen ? 1 : 0);
QCOMPARE(socket.state(), canListen ? QLocalSocket::ConnectedState : QLocalSocket::UnconnectedState);
// test sending/receiving data
@@ -699,7 +688,7 @@ void tst_QLocalSocket::sendData()
QCOMPARE(socket.flush(), false);
QCOMPARE(socket.isValid(), canListen);
QCOMPARE(socket.readBufferSize(), (qint64)0);
- QCOMPARE(spyReadyRead.count(), expectedReadyReadSignals);
+ QCOMPARE(spyReadyRead.size(), expectedReadyReadSignals);
QVERIFY(testLine.startsWith(in.readLine()));
@@ -710,16 +699,16 @@ void tst_QLocalSocket::sendData()
}
socket.disconnectFromServer();
- QCOMPARE(spyConnected.count(), canListen ? 1 : 0);
- QCOMPARE(spyDisconnected.count(), canListen ? 1 : 0);
- QCOMPARE(spyError.count(), canListen ? 0 : 1);
- QCOMPARE(spyStateChanged.count(), canListen ? 4 : 2);
- QCOMPARE(spyReadyRead.count(), canListen ? expectedReadyReadSignals : 0);
+ QCOMPARE(spyConnected.size(), canListen ? 1 : 0);
+ QCOMPARE(spyDisconnected.size(), canListen ? 1 : 0);
+ QCOMPARE(spyError.size(), canListen ? 0 : 1);
+ QCOMPARE(spyStateChanged.size(), canListen ? 4 : 2);
+ QCOMPARE(spyReadyRead.size(), canListen ? expectedReadyReadSignals : 0);
server.close();
- QCOMPARE(server.hits.count(), (canListen ? 1 : 0));
- QCOMPARE(spy.count(), (canListen ? 1 : 0));
+ QCOMPARE(server.hits.size(), (canListen ? 1 : 0));
+ QCOMPARE(spy.size(), (canListen ? 1 : 0));
}
void tst_QLocalSocket::readLine_data()
@@ -771,7 +760,7 @@ void tst_QLocalSocket::readLine()
const QString serverName = QLatin1String("tst_localsocket");
LocalServer server;
- QVERIFY(server.listen(serverName));
+ QVERIFY2(server.listen(serverName), qUtf8Printable(server.errorString()));
LocalSocket client;
client.connectToServer(serverName);
@@ -847,7 +836,7 @@ void tst_QLocalSocket::skip()
const QString serverName = QLatin1String("tst_localsocket");
LocalServer server;
- QVERIFY(server.listen(serverName));
+ QVERIFY2(server.listen(serverName), qUtf8Printable(server.errorString()));
LocalSocket client;
client.connectToServer(serverName);
@@ -946,7 +935,7 @@ static QVariant readCommand(QIODevice *ioDevice, int *readCommandCounter, bool r
void tst_QLocalSocket::simpleCommandProtocol1()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
server.listen(QStringLiteral("simpleProtocol"));
QLocalSocket localSocketWrite;
@@ -972,7 +961,7 @@ void tst_QLocalSocket::simpleCommandProtocol1()
void tst_QLocalSocket::simpleCommandProtocol2()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
server.listen(QStringLiteral("simpleProtocol"));
QLocalSocket localSocketWrite;
@@ -1019,7 +1008,7 @@ void tst_QLocalSocket::simpleCommandProtocol2()
localSocketWrite.abort();
QCOMPARE(localSocketWrite.state(), QLocalSocket::UnconnectedState);
- QCOMPARE(spyDisconnected.count(), 1);
+ QCOMPARE(spyDisconnected.size(), 1);
QCOMPARE(localSocketWrite.bytesToWrite(), 0);
QVERIFY(!localSocketWrite.isOpen());
@@ -1029,7 +1018,7 @@ void tst_QLocalSocket::simpleCommandProtocol2()
// QLocalSocket/Server can take a name or path, check that it works as expected
void tst_QLocalSocket::fullPath()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
QString name = "qlocalsocket_pathtest";
#if defined(QT_LOCALSOCKET_TCP)
QString path = "QLocalServer";
@@ -1039,7 +1028,7 @@ void tst_QLocalSocket::fullPath()
QString path = "/tmp";
#endif
QString serverName = path + '/' + name;
- QVERIFY2(server.listen(serverName), server.errorString().toLatin1().constData());
+ QVERIFY2(server.listen(serverName), qUtf8Printable(server.errorString()));
QCOMPARE(server.serverName(), serverName);
QCOMPARE(server.fullServerName(), serverName);
@@ -1070,7 +1059,7 @@ void tst_QLocalSocket::hitMaximumConnections()
LocalServer server;
QString name = "tst_localsocket";
server.setMaxPendingConnections(max);
- QVERIFY2(server.listen(name), server.errorString().toLatin1().constData());
+ QVERIFY2(server.listen(name), qUtf8Printable(server.errorString()));
int connections = server.maxPendingConnections() + 1;
QList<QLocalSocket*> sockets;
for (int i = 0; i < connections; ++i) {
@@ -1081,7 +1070,7 @@ void tst_QLocalSocket::hitMaximumConnections()
bool timedOut = true;
QVERIFY(server.waitForNewConnection(3000, &timedOut));
QVERIFY(!timedOut);
- QVERIFY(server.hits.count() > 0);
+ QVERIFY(server.hits.size() > 0);
qDeleteAll(sockets.begin(), sockets.end());
}
@@ -1109,9 +1098,9 @@ public:
QVERIFY(socket.waitForConnected(1000));
// We should *not* have this signal yet!
- QCOMPARE(spyReadyRead.count(), 0);
+ QCOMPARE(spyReadyRead.size(), 0);
socket.waitForReadyRead();
- QCOMPARE(spyReadyRead.count(), 1);
+ QCOMPARE(spyReadyRead.size(), 1);
QTextStream in(&socket);
QCOMPARE(in.readLine(), testLine);
socket.close();
@@ -1131,7 +1120,7 @@ public:
LocalServer server;
server.setMaxPendingConnections(10);
QVERIFY2(server.listen("qlocalsocket_threadtest"),
- server.errorString().toLatin1().constData());
+ qUtf8Printable(server.errorString()));
mutex.lock();
wc.wakeAll();
mutex.unlock();
@@ -1153,7 +1142,7 @@ public:
--done;
delete serverSocket;
}
- QCOMPARE(server.hits.count(), clients);
+ QCOMPARE(server.hits.size(), clients);
}
};
@@ -1292,7 +1281,7 @@ void tst_QLocalSocket::waitForDisconnect()
{
QString name = "tst_localsocket";
LocalServer server;
- QVERIFY(server.listen(name));
+ QVERIFY2(server.listen(name), qUtf8Printable(server.errorString()));
LocalSocket socket;
socket.connectToServer(name);
QVERIFY(socket.waitForConnected(3000));
@@ -1310,7 +1299,7 @@ void tst_QLocalSocket::waitForDisconnectByServer()
{
QString name = "tst_localsocket";
LocalServer server;
- QVERIFY(server.listen(name));
+ QVERIFY2(server.listen(name), qUtf8Printable(server.errorString()));
LocalSocket socket;
QSignalSpy spy(&socket, SIGNAL(disconnected()));
QVERIFY(spy.isValid());
@@ -1322,14 +1311,14 @@ void tst_QLocalSocket::waitForDisconnectByServer()
serverSocket->close();
QCOMPARE(serverSocket->state(), QLocalSocket::UnconnectedState);
QVERIFY(socket.waitForDisconnected(3000));
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
void tst_QLocalSocket::waitForReadyReadOnDisconnected()
{
QString name = "tst_localsocket";
LocalServer server;
- QVERIFY(server.listen(name));
+ QVERIFY2(server.listen(name), qUtf8Printable(server.errorString()));
LocalSocket socket;
connect(&socket, &QLocalSocket::readyRead, [&socket]() {
QVERIFY(socket.getChar(nullptr));
@@ -1363,7 +1352,7 @@ void tst_QLocalSocket::delayedDisconnect()
{
QString name = "tst_localsocket";
LocalServer server;
- QVERIFY(server.listen(name));
+ QVERIFY2(server.listen(name), qUtf8Printable(server.errorString()));
LocalSocket socket;
socket.connectToServer(name);
QVERIFY(socket.waitForConnected(3000));
@@ -1392,9 +1381,11 @@ void tst_QLocalSocket::delayedDisconnect()
void tst_QLocalSocket::removeServer()
{
// this is a hostile takeover, but recovering from a crash results in the same
+ // Note: Explicitly not a CrashSafeLocalServer
QLocalServer server, server2;
+
QVERIFY(QLocalServer::removeServer("cleanuptest"));
- QVERIFY(server.listen("cleanuptest"));
+ QVERIFY2(server.listen("cleanuptest"), qUtf8Printable(server.errorString()));
#ifndef Q_OS_WIN
// on Windows, there can be several sockets listening on the same pipe
// on Unix, there can only be one socket instance
@@ -1406,10 +1397,10 @@ void tst_QLocalSocket::removeServer()
void tst_QLocalSocket::recycleServer()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
QLocalSocket client;
- QVERIFY(server.listen("recycletest1"));
+ QVERIFY2(server.listen("recycletest1"), qUtf8Printable(server.errorString()));
client.connectToServer("recycletest1");
QVERIFY(client.waitForConnected(201));
QVERIFY(server.waitForNewConnection(201));
@@ -1419,7 +1410,7 @@ void tst_QLocalSocket::recycleServer()
client.disconnectFromServer();
qApp->processEvents();
- QVERIFY(server.listen("recycletest2"));
+ QVERIFY2(server.listen("recycletest2"), qUtf8Printable(server.errorString()));
client.connectToServer("recycletest2");
QVERIFY(client.waitForConnected(202));
QVERIFY(server.waitForNewConnection(202));
@@ -1431,13 +1422,13 @@ void tst_QLocalSocket::recycleClientSocket()
const QByteArrayList lines = QByteArrayList() << "Have you heard of that new band"
<< "\"1023 Megabytes\"?"
<< "They haven't made it to a gig yet.";
- QLocalServer server;
+ CrashSafeLocalServer server;
const QString serverName = QStringLiteral("recycleClientSocket");
- QVERIFY(server.listen(serverName));
+ QVERIFY2(server.listen(serverName), qUtf8Printable(server.errorString()));
QLocalSocket client;
QSignalSpy clientReadyReadSpy(&client, SIGNAL(readyRead()));
QSignalSpy clientErrorSpy(&client, SIGNAL(errorOccurred(QLocalSocket::LocalSocketError)));
- for (int i = 0; i < lines.count(); ++i) {
+ for (int i = 0; i < lines.size(); ++i) {
client.abort();
clientReadyReadSpy.clear();
client.connectToServer(serverName);
@@ -1456,12 +1447,12 @@ void tst_QLocalSocket::recycleClientSocket()
void tst_QLocalSocket::multiConnect()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
QLocalSocket client1;
QLocalSocket client2;
QLocalSocket client3;
- QVERIFY(server.listen("multiconnect"));
+ QVERIFY2(server.listen("multiconnect"), qUtf8Printable(server.errorString()));
client1.connectToServer("multiconnect");
client2.connectToServer("multiconnect");
@@ -1481,8 +1472,8 @@ void tst_QLocalSocket::multiConnect()
void tst_QLocalSocket::writeOnlySocket()
{
- QLocalServer server;
- QVERIFY(server.listen("writeOnlySocket"));
+ CrashSafeLocalServer server;
+ QVERIFY2(server.listen("writeOnlySocket"), qUtf8Printable(server.errorString()));
QLocalSocket client;
client.connectToServer("writeOnlySocket", QIODevice::WriteOnly);
@@ -1512,11 +1503,11 @@ void tst_QLocalSocket::writeToClientAndDisconnect_data()
void tst_QLocalSocket::writeToClientAndDisconnect()
{
QFETCH(int, chunks);
- QLocalServer server;
+ CrashSafeLocalServer server;
QLocalSocket client;
QSignalSpy readChannelFinishedSpy(&client, SIGNAL(readChannelFinished()));
- QVERIFY(server.listen("writeAndDisconnectServer"));
+ QVERIFY2(server.listen("writeAndDisconnectServer"), qUtf8Printable(server.errorString()));
client.connectToServer("writeAndDisconnectServer");
QVERIFY(client.waitForConnected(200));
QVERIFY(server.waitForNewConnection(200));
@@ -1532,7 +1523,7 @@ void tst_QLocalSocket::writeToClientAndDisconnect()
QVERIFY(clientSocket->waitForDisconnected());
QVERIFY(client.waitForDisconnected());
- QCOMPARE(readChannelFinishedSpy.count(), 1);
+ QCOMPARE(readChannelFinishedSpy.size(), 1);
const QByteArray received = client.readAll();
QCOMPARE(received.size(), qint64(sizeof(buffer) * chunks));
QCOMPARE(client.state(), QLocalSocket::UnconnectedState);
@@ -1540,8 +1531,8 @@ void tst_QLocalSocket::writeToClientAndDisconnect()
void tst_QLocalSocket::writeToDisconnected()
{
- QLocalServer server;
- QVERIFY(server.listen("writeToDisconnected"));
+ CrashSafeLocalServer server;
+ QVERIFY2(server.listen("writeToDisconnected"), qUtf8Printable(server.errorString()));
QLocalSocket client;
QSignalSpy spyError(&client, SIGNAL(errorOccurred(QLocalSocket::LocalSocketError)));
@@ -1562,7 +1553,7 @@ void tst_QLocalSocket::writeToDisconnected()
QCOMPARE(client.bytesToWrite(), qint64(1));
QVERIFY(!client.waitForBytesWritten());
- QCOMPARE(spyError.count(), 1);
+ QCOMPARE(spyError.size(), 1);
QCOMPARE(client.state(), QLocalSocket::UnconnectedState);
}
@@ -1611,8 +1602,8 @@ public slots:
*/
void tst_QLocalSocket::bytesWrittenSignal()
{
- QLocalServer server;
- QVERIFY(server.listen("qlocalsocket_readyread"));
+ CrashSafeLocalServer server;
+ QVERIFY2(server.listen("qlocalsocket_readyread"), qUtf8Printable(server.errorString()));
WriteThread writeThread;
QSignalSpy receivedSpy(&writeThread, &WriteThread::bytesWrittenReceived);
writeThread.start();
@@ -1632,8 +1623,8 @@ void tst_QLocalSocket::socketClosedSlot()
void tst_QLocalSocket::syncDisconnectNotify()
{
- QLocalServer server;
- QVERIFY(server.listen("syncDisconnectNotify"));
+ CrashSafeLocalServer server;
+ QVERIFY2(server.listen("syncDisconnectNotify"), qUtf8Printable(server.errorString()));
QLocalSocket client;
connect(&client, &QLocalSocket::disconnected,
this, &tst_QLocalSocket::socketClosedSlot);
@@ -1651,8 +1642,8 @@ void tst_QLocalSocket::syncDisconnectNotify()
void tst_QLocalSocket::asyncDisconnectNotify()
{
- QLocalServer server;
- QVERIFY(server.listen("asyncDisconnectNotify"));
+ CrashSafeLocalServer server;
+ QVERIFY2(server.listen("asyncDisconnectNotify"), qUtf8Printable(server.errorString()));
QLocalSocket client;
QSignalSpy disconnectedSpy(&client, SIGNAL(disconnected()));
QSignalSpy readChannelFinishedSpy(&client, SIGNAL(readChannelFinished()));
@@ -1667,7 +1658,7 @@ void tst_QLocalSocket::asyncDisconnectNotify()
QVERIFY(serverSocket);
delete serverSocket;
QTRY_VERIFY(!disconnectedSpy.isEmpty());
- QCOMPARE(readChannelFinishedSpy.count(), 1);
+ QCOMPARE(readChannelFinishedSpy.size(), 1);
}
void tst_QLocalSocket::verifySocketOptions_data()
@@ -1703,11 +1694,9 @@ void tst_QLocalSocket::verifySocketOptions()
QFETCH(QLocalServer::SocketOption, opts);
QFETCH(QFile::Permissions, perms);
-
- QLocalServer::removeServer(service);
- QLocalServer server;
+ CrashSafeLocalServer server;
server.setSocketOptions(opts);
- QVERIFY2(server.listen(service), "service failed to start listening");
+ QVERIFY2(server.listen(service), qUtf8Printable(server.errorString()));
// find the socket
QString fullServerPath = QDir::cleanPath(QDir::tempPath());
@@ -1720,7 +1709,7 @@ void tst_QLocalSocket::verifySocketOptions()
void tst_QLocalSocket::verifyListenWithDescriptor()
{
-#ifdef Q_OS_UNIX
+#if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS)
QFETCH(QString, path);
QFETCH(bool, abstract);
QFETCH(bool, bound);
@@ -1762,10 +1751,10 @@ void tst_QLocalSocket::verifyListenWithDescriptor()
close(fds[1]);
}
- QLocalServer server;
- QVERIFY2(server.listen(listenSocket), "failed to start create QLocalServer with local socket");
+ CrashSafeLocalServer server;
+ QVERIFY2(server.listen(listenSocket), qUtf8Printable(server.errorString()));
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_QNX)
if (!bound) {
QCOMPARE(server.serverName().isEmpty(), true);
QCOMPARE(server.fullServerName().isEmpty(), true);
@@ -1806,7 +1795,7 @@ void tst_QLocalSocket::verifyListenWithDescriptor_data()
QTest::addColumn<bool>("bound");
QTest::newRow("normal") << QDir::tempPath() + QLatin1String("/testsocket") << false << true;
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) || defined(Q_OS_QNX)
QTest::newRow("abstract") << QString::fromLatin1("abstractsocketname") << true << true;
QTest::newRow("abstractwithslash") << QString::fromLatin1("abstractsocketwitha/inthename") << true << true;
#endif
@@ -1818,16 +1807,20 @@ void tst_QLocalSocket::verifyListenWithDescriptor_data()
void tst_QLocalSocket::serverBindingsAndProperties()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
+
+ QTestPrivate::testReadWritePropertyBasics(
+ server, QLocalServer::SocketOptions{QLocalServer::GroupAccessOption},
+ QLocalServer::SocketOptions{QLocalServer::OtherAccessOption}, "socketOptions");
+}
- QProperty<QLocalServer::SocketOptions> sockOpts;
- server.bindableSocketOptions().setBinding(Qt::makePropertyBinding(sockOpts));
- sockOpts = QLocalServer::GroupAccessOption | QLocalServer::UserAccessOption;
- QCOMPARE(server.socketOptions(), sockOpts.value());
+void tst_QLocalSocket::socketBindings()
+{
+ QLocalSocket socket;
- sockOpts.setBinding(server.bindableSocketOptions().makeBinding());
- server.setSocketOptions(QLocalServer::OtherAccessOption);
- QCOMPARE(sockOpts.value(), QLocalServer::OtherAccessOption);
+ QTestPrivate::testReadWritePropertyBasics(
+ socket, QLocalSocket::SocketOptions{QLocalSocket::AbstractNamespaceOption},
+ QLocalSocket::SocketOptions{QLocalSocket::NoOptions}, "socketOptions");
}
QTEST_MAIN(tst_QLocalSocket)
diff --git a/tests/auto/network/socket/qsctpsocket/CMakeLists.txt b/tests/auto/network/socket/qsctpsocket/CMakeLists.txt
index af3f809113..4bf5438841 100644
--- a/tests/auto/network/socket/qsctpsocket/CMakeLists.txt
+++ b/tests/auto/network/socket/qsctpsocket/CMakeLists.txt
@@ -1,12 +1,19 @@
-# Generated from qsctpsocket.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qsctpsocket Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qsctpsocket LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qsctpsocket
SOURCES
tst_qsctpsocket.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
)
diff --git a/tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp b/tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp
index c2e29c0ce2..2893053158 100644
--- a/tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp
+++ b/tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Alex Trotsenko <alex1973tr@gmail.com>
-** 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 Alex Trotsenko <alex1973tr@gmail.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QDebug>
@@ -152,12 +127,13 @@ void tst_QSctpSocket::bind_data()
// these ranges are guaranteed to be reserved for 'documentation purposes',
// and thus, should be unused in the real world. Not that I'm assuming the
// world is full of competent administrators, or anything.
- QStringList knownBad;
- knownBad << "198.51.100.1";
- knownBad << "2001:0DB8::1";
- foreach (const QString &badAddress, knownBad) {
+ const QString knownBad[] = {
+ "198.51.100.1",
+ "2001:0DB8::1",
+ };
+
+ for (const QString &badAddress : knownBad)
QTest::newRow(badAddress.toLatin1().constData()) << badAddress << false << QString();
- }
}
// Testing bind function
diff --git a/tests/auto/network/socket/qsocks5socketengine/BLACKLIST b/tests/auto/network/socket/qsocks5socketengine/BLACKLIST
index 405d03f990..6b3a39ab5e 100644
--- a/tests/auto/network/socket/qsocks5socketengine/BLACKLIST
+++ b/tests/auto/network/socket/qsocks5socketengine/BLACKLIST
@@ -1,12 +1,10 @@
[udpTest]
*
[passwordAuth]
-ubuntu-18.04
-ubuntu-20.04
+ubuntu
+# QTBUG-101274
+qnx ci
# QTBUG-74162
[passwordAuth2]
ubuntu
-[downloadBigFile]
-windows-10 msvc-2015
-windows-7sp1
diff --git a/tests/auto/network/socket/qsocks5socketengine/CMakeLists.txt b/tests/auto/network/socket/qsocks5socketengine/CMakeLists.txt
index 64f3aa7a9e..dc0b87cd94 100644
--- a/tests/auto/network/socket/qsocks5socketengine/CMakeLists.txt
+++ b/tests/auto/network/socket/qsocks5socketengine/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qsocks5socketengine.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qsocks5socketengine LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
if(NOT QT_FEATURE_private_tests)
return()
@@ -11,23 +18,18 @@ endif()
qt_internal_add_test(tst_qsocks5socketengine
SOURCES
tst_qsocks5socketengine.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::NetworkPrivate
- QT_TEST_SERVER_LIST "danted" "apache2" "cyrus" # special case
+ QT_TEST_SERVER_LIST "danted" "apache2" "cyrus"
)
-#### Keys ignored in scope 1:.:.:qsocks5socketengine.pro:<TRUE>:
-# MOC_DIR = "tmp"
-# _REQUIREMENTS = "qtConfig(private_tests)"
-
## Scopes:
#####################################################################
-#### Keys ignored in scope 2:.:.:qsocks5socketengine.pro:LINUX:
# QT_TEST_SERVER_LIST = "danted" "apache2" "cyrus"
qt_internal_extend_target(tst_qsocks5socketengine CONDITION WIN32
- PUBLIC_LIBRARIES
+ LIBRARIES
ws2_32
)
diff --git a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp
index 11e17cb319..cc77ba2da3 100644
--- a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp
+++ b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** 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.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QTest>
@@ -48,6 +23,8 @@
#include "../../../network-settings.h"
+using namespace std::chrono_literals;
+
class tst_QSocks5SocketEngine : public QObject, public QAbstractSocketEngineReceiver
{
Q_OBJECT
@@ -366,7 +343,7 @@ void tst_QSocks5SocketEngine::simpleErrorsAndStates()
QCOMPARE(socketDevice.state(), QAbstractSocket::UnconnectedState);
QVERIFY(!socketDevice.connectToHost(QHostInfo::fromName(QtNetworkSettings::socksProxyServerName()).addresses().first(), 8088));
QCOMPARE(socketDevice.state(), QAbstractSocket::ConnectingState);
- if (socketDevice.waitForWrite(15000)) {
+ if (socketDevice.waitForWrite(15s)) {
QVERIFY(socketDevice.state() == QAbstractSocket::UnconnectedState ||
socketDevice.state() == QAbstractSocket::ConnectedState);
} else {
@@ -940,13 +917,13 @@ void tst_QSocks5SocketEngine::fragmentation_data()
responses << authMethodBasic << authSuccess.left(1) << authSuccess.mid(1) << connectResponseIPv4;
QTest::newRow("auth-response") << responses;
- for (int i = 1; i < connectResponseIPv4.length() - 1; i++) {
+ for (int i = 1; i < connectResponseIPv4.size() - 1; i++) {
responses.clear();
responses << authMethodNone << connectResponseIPv4.left(i) << connectResponseIPv4.mid(i);
QTest::newRow(qPrintable(QString("connect-response-ipv4-") + QString::number(i))) << responses;
}
- for (int i = 1; i < connectResponseIPv6.length() - 1; i++) {
+ for (int i = 1; i < connectResponseIPv6.size() - 1; i++) {
responses.clear();
responses << authMethodNone << connectResponseIPv6.left(i) << connectResponseIPv6.mid(i);
QTest::newRow(qPrintable(QString("connect-response-ipv6-") + QString::number(i))) << responses;
@@ -989,13 +966,13 @@ void tst_QSocks5SocketEngine::incomplete_data()
responses << authMethodBasic << authSuccess.left(1);
QTest::newRow("auth-response") << responses;
- for (int i = 1; i < connectResponseIPv4.length() - 1; i++) {
+ for (int i = 1; i < connectResponseIPv4.size() - 1; i++) {
responses.clear();
responses << authMethodNone << connectResponseIPv4.left(i);
QTest::newRow(qPrintable(QString("connect-response-ipv4-") + QString::number(i))) << responses;
}
- for (int i = 1; i < connectResponseIPv6.length() - 1; i++) {
+ for (int i = 1; i < connectResponseIPv6.size() - 1; i++) {
responses.clear();
responses << authMethodNone << connectResponseIPv6.left(i);
QTest::newRow(qPrintable(QString("connect-response-ipv6-") + QString::number(i))) << responses;
diff --git a/tests/auto/network/socket/qtcpserver/BLACKLIST b/tests/auto/network/socket/qtcpserver/BLACKLIST
index c6d4d49908..a8b5f5d137 100644
--- a/tests/auto/network/socket/qtcpserver/BLACKLIST
+++ b/tests/auto/network/socket/qtcpserver/BLACKLIST
@@ -1,19 +1,13 @@
[listenWhileListening:WithSocks5Proxy]
linux
windows
-[ipv6Server]
-windows-7sp1
-windows-10 msvc-2017
[ipv6Server:WithoutProxy]
windows
osx
-[eagainBlockingAccept]
-windows-7sp1
-windows-10
[serverAddress]
-windows-7sp1
+# QTBUG-103056
+qnx
windows-10
[linkLocal]
macos arm
-
diff --git a/tests/auto/network/socket/qtcpserver/CMakeLists.txt b/tests/auto/network/socket/qtcpserver/CMakeLists.txt
index 01f6c8b672..b01a164302 100644
--- a/tests/auto/network/socket/qtcpserver/CMakeLists.txt
+++ b/tests/auto/network/socket/qtcpserver/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qtcpserver.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtcpserver LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
-add_subdirectory(test)
add_subdirectory(crashingServer)
+add_subdirectory(test)
diff --git a/tests/auto/network/socket/qtcpserver/crashingServer/CMakeLists.txt b/tests/auto/network/socket/qtcpserver/crashingServer/CMakeLists.txt
index dd309ba605..bb1feb0237 100644
--- a/tests/auto/network/socket/qtcpserver/crashingServer/CMakeLists.txt
+++ b/tests/auto/network/socket/qtcpserver/crashingServer/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from crashingServer.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## crashingServer Binary:
@@ -8,7 +9,7 @@ qt_internal_add_executable(crashingServer
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/"
SOURCES
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
)
diff --git a/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp b/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp
index 7cb65cd1a3..1c41552eb5 100644
--- a/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp
+++ b/tests/auto/network/socket/qtcpserver/crashingServer/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** 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.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore>
@@ -32,18 +7,45 @@
#if defined(Q_OS_WIN) && defined(Q_CC_MSVC)
# include <crtdbg.h>
#endif
+#ifdef Q_OS_UNIX
+# include <sys/resource.h>
+# include <unistd.h>
+#endif
int main(int argc, char *argv[])
{
- // Windows: Suppress crash notification dialog.
#if defined(Q_OS_WIN) && defined(Q_CC_MSVC)
+ // Windows: Suppress crash notification dialog.
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
+#elif defined(RLIMIT_CORE)
+ // Unix: set our core dump limit to zero to request no dialogs.
+ if (struct rlimit rlim; getrlimit(RLIMIT_CORE, &rlim) == 0) {
+ rlim.rlim_cur = 0;
+ setrlimit(RLIMIT_CORE, &rlim);
+ }
#endif
+
QCoreApplication app(argc, argv);
+ if (argc < 1) {
+ fprintf(stderr, "Need a port number\n");
+ return 1;
+ }
+ int port = QByteArrayView(argv[1]).toInt();
QTcpServer server;
- if (!server.listen(QHostAddress::LocalHost, 49199)) {
- qDebug("Failed to listen: %s", server.errorString().toLatin1().constData());
+ if (!server.listen(QHostAddress::LocalHost, port)) {
+ fprintf(stderr, "Failed to listen: %s\n", server.errorString().toLatin1().constData());
+ if (server.serverError() == QTcpSocket::AddressInUseError) {
+ // let's see if we can find the process that would be holding this
+ // still open
+#ifdef Q_OS_LINUX
+ static const char *ss_args[] = {
+ "ss", "-nap", "sport", "=", argv[1], nullptr
+ };
+ dup2(STDERR_FILENO, STDOUT_FILENO);
+ execvp(ss_args[0], const_cast<char **>(ss_args));
+#endif
+ }
return 1;
}
diff --git a/tests/auto/network/socket/qtcpserver/test/CMakeLists.txt b/tests/auto/network/socket/qtcpserver/test/CMakeLists.txt
index 74aed77c95..55615bbae1 100644
--- a/tests/auto/network/socket/qtcpserver/test/CMakeLists.txt
+++ b/tests/auto/network/socket/qtcpserver/test/CMakeLists.txt
@@ -1,28 +1,27 @@
-# Generated from test.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtcpserver Test:
#####################################################################
qt_internal_add_test(tst_qtcpserver
- OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" # special case
+ OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../"
SOURCES
../tst_qtcpserver.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
- QT_TEST_SERVER_LIST "danted" "cyrus" "squid" "ftp-proxy" # special case
+ QT_TEST_SERVER_LIST "danted" "cyrus" "squid" "ftp-proxy"
)
-#### Keys ignored in scope 1:.:.:test.pro:<TRUE>:
-# MOC_DIR = "tmp"
+add_dependencies(tst_qtcpserver
+ crashingServer
+)
## Scopes:
#####################################################################
qt_internal_extend_target(tst_qtcpserver CONDITION WIN32
- PUBLIC_LIBRARIES
+ LIBRARIES
ws2_32
)
-
-#### Keys ignored in scope 6:.:.:test.pro:LINUX:
-# QT_TEST_SERVER_LIST = "danted" "cyrus" "squid" "ftp-proxy"
diff --git a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp
index 4759ac292a..c03076d98e 100644
--- a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp
+++ b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp
@@ -1,34 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** 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.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qglobal.h>
-// To prevent windows system header files from re-defining min/max
-#define NOMINMAX 1
#if defined(_WIN32)
#include <winsock2.h>
#else
@@ -60,6 +33,8 @@
#include <qnetworkinterface.h>
#include <QNetworkProxy>
+#include <QSet>
+#include <QList>
#include "../../../network-settings.h"
@@ -117,6 +92,9 @@ private slots:
void pauseAccepting();
+ void pendingConnectionAvailable_data();
+ void pendingConnectionAvailable();
+
private:
bool shouldSkipIpv6TestsForBrokenGetsockopt();
#ifdef SHOULD_CHECK_SYSCALL_SUPPORT
@@ -160,7 +138,8 @@ void tst_QTcpServer::initTestCase()
#ifdef QT_TEST_SERVER
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::socksProxyServerName(), 1080));
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::httpProxyServerName(), 3128));
- QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpProxyServerName(), 2121));
+ // FTP currently not supported:
+ // QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpProxyServerName(), 2121));
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::imapServerName(), 143));
#else
if (!QtNetworkSettings::verifyTestNetworkSettings())
@@ -268,7 +247,7 @@ void tst_QTcpServer::clientServerLoop()
QVERIFY(server.waitForNewConnection(5000));
QVERIFY(server.hasPendingConnections());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QTcpSocket *serverSocket = server.nextPendingConnection();
QVERIFY(serverSocket != 0);
@@ -429,9 +408,9 @@ void tst_QTcpServer::maxPendingConnections()
// two connections have been made. The second compare makes sure no
// more are accepted. Creating connections happens multithreaded so
// qWait must be used for that.
- QTRY_COMPARE(spy.count(), 2);
+ QTRY_COMPARE(spy.size(), 2);
QTest::qWait(100);
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
QVERIFY(server.hasPendingConnections());
QVERIFY(server.nextPendingConnection());
@@ -480,7 +459,7 @@ public:
protected:
void run() override
{
- sleep(2);
+ sleep(std::chrono::seconds{2});
QTcpSocket socket;
socket.connectToHost(host, port);
@@ -598,9 +577,6 @@ void tst_QTcpServer::addressReusable()
#if !QT_CONFIG(process)
QSKIP("No qprocess support", SkipAll);
#else
-#ifdef Q_OS_LINUX
- QSKIP("The addressReusable test is unstable on Linux. See QTBUG-39985.");
-#endif
QFETCH_GLOBAL(bool, setProxy);
if (setProxy) {
#ifndef QT_NO_NETWORKPROXY
@@ -611,16 +587,25 @@ void tst_QTcpServer::addressReusable()
QSKIP("No proxy support");
#endif // QT_NO_NETWORKPROXY
}
+
+ QTcpServer server;
+ QVERIFY(server.listen(QHostAddress::LocalHost, 0));
+ quint16 serverPort = server.serverPort();
+ qDebug() << "Got port" << serverPort;
+ server.close(); // cleanly close
+
+ QTest::qSleep(10);
+
// The crashingServer process will crash once it gets a connection.
QProcess process;
QString processExe = crashingServerDir + "/crashingServer";
- process.start(processExe);
+ process.start(processExe, { QString::number(serverPort) });
QVERIFY2(process.waitForStarted(), qPrintable(
QString::fromLatin1("Could not start %1: %2").arg(processExe, process.errorString())));
- QVERIFY(process.waitForReadyRead(5000));
+ QVERIFY2(process.waitForReadyRead(5000), qPrintable(process.readAllStandardError()));
QTcpSocket socket;
- socket.connectToHost(QHostAddress::LocalHost, 49199);
+ socket.connectToHost(QHostAddress::LocalHost, serverPort);
QVERIFY(socket.waitForConnected(5000));
QVERIFY(process.waitForFinished(30000));
@@ -628,8 +613,9 @@ void tst_QTcpServer::addressReusable()
// Give the system some time.
QTest::qSleep(10);
- QTcpServer server;
- QVERIFY(server.listen(QHostAddress::LocalHost, 49199));
+ // listen again
+ QVERIFY2(server.listen(QHostAddress::LocalHost, serverPort),
+ qPrintable(server.errorString()));
#endif
}
@@ -748,6 +734,7 @@ void tst_QTcpServer::proxyFactory_data()
<< proxyList << proxyList.at(1)
<< false << int(QAbstractSocket::UnknownSocketError);
+#if 0 // ftp not currently supported
proxyList.clear();
proxyList << QNetworkProxy(QNetworkProxy::FtpCachingProxy, QtNetworkSettings::ftpProxyServerName(), 2121)
<< QNetworkProxy(QNetworkProxy::HttpCachingProxy, QtNetworkSettings::httpProxyServerName(), 3128)
@@ -755,6 +742,7 @@ void tst_QTcpServer::proxyFactory_data()
QTest::newRow("ftp+cachinghttp+socks5")
<< proxyList << proxyList.at(2)
<< false << int(QAbstractSocket::UnknownSocketError);
+#endif
// tests that fail to listen
proxyList.clear();
@@ -769,6 +757,7 @@ void tst_QTcpServer::proxyFactory_data()
<< proxyList << QNetworkProxy()
<< true << int(QAbstractSocket::UnsupportedSocketOperationError);
+#if 0 // ftp not currently supported
proxyList.clear();
proxyList << QNetworkProxy(QNetworkProxy::FtpCachingProxy, QtNetworkSettings::ftpProxyServerName(), 2121);
QTest::newRow("ftp")
@@ -781,6 +770,7 @@ void tst_QTcpServer::proxyFactory_data()
QTest::newRow("ftp+cachinghttp")
<< proxyList << QNetworkProxy()
<< true << int(QAbstractSocket::UnsupportedSocketOperationError);
+#endif
}
void tst_QTcpServer::proxyFactory()
@@ -875,10 +865,12 @@ void tst_QTcpServer::serverAddress_data()
QTest::newRow("AnyIPv4") << QHostAddress(QHostAddress::AnyIPv4) << QHostAddress(QHostAddress::AnyIPv4);
if (QtNetworkSettings::hasIPv6())
QTest::newRow("AnyIPv6") << QHostAddress(QHostAddress::AnyIPv6) << QHostAddress(QHostAddress::AnyIPv6);
- foreach (const QNetworkInterface &iface, QNetworkInterface::allInterfaces()) {
+ const auto ifaces = QNetworkInterface::allInterfaces();
+ for (const QNetworkInterface &iface : ifaces) {
if ((iface.flags() & QNetworkInterface::IsUp) == 0)
continue;
- foreach (const QNetworkAddressEntry &entry, iface.addressEntries()) {
+ const auto entries = iface.addressEntries();
+ for (const QNetworkAddressEntry &entry : entries) {
QTest::newRow(qPrintable(entry.ip().toString())) << entry.ip() << entry.ip();
}
}
@@ -932,7 +924,8 @@ void tst_QTcpServer::linkLocal()
QSet <QString> scopes;
QHostAddress localMaskv4("169.254.0.0");
QHostAddress localMaskv6("fe80::");
- foreach (const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) {
+ const auto ifaces = QNetworkInterface::allInterfaces();
+ for (const QNetworkInterface &iface : ifaces) {
//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) {
@@ -945,8 +938,15 @@ void tst_QTcpServer::linkLocal()
// (we don't know why)
if (iface.name().startsWith("utun"))
continue;
+ // Do not use the iBridge interfae
+ if (iface.hardwareAddress() == "AC:DE:48:00:11:22")
+ continue;
+ // Do no use the Apple Wireless Direct Link interfaces
+ if (iface.name().startsWith("awdl"))
+ continue;
#endif
- foreach (QNetworkAddressEntry addressEntry, iface.addressEntries()) {
+ const auto entries = iface.addressEntries();
+ for (const QNetworkAddressEntry &addressEntry : entries) {
QHostAddress addr = addressEntry.ip();
if (addr.isInSubnet(localMaskv4, 16)) {
addresses << addr;
@@ -965,7 +965,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
@@ -973,7 +973,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);
@@ -988,7 +988,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();
@@ -1023,12 +1023,12 @@ void tst_QTcpServer::eagainBlockingAccept()
QTcpSocket s;
s.connectToHost(QHostAddress::LocalHost, 7896);
QSignalSpy spy(&server, SIGNAL(newConnection()));
- QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 500);
+ QTRY_COMPARE_WITH_TIMEOUT(spy.size(), 1, 500);
s.close();
// To test try again, should connect just fine.
s.connectToHost(QHostAddress::LocalHost, 7896);
- QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 2, 500);
+ QTRY_COMPARE_WITH_TIMEOUT(spy.size(), 2, 500);
s.close();
server.close();
}
@@ -1064,13 +1064,13 @@ void tst_QTcpServer::pauseAccepting()
QTcpSocket sockets[NumSockets];
sockets[0].connectToHost(address, server.serverPort());
QVERIFY(spy.wait());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
server.pauseAccepting();
for (int i = 1; i < NumSockets; ++i)
sockets[i].connectToHost(address, server.serverPort());
QVERIFY(!spy.wait(400));
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
server.resumeAccepting();
if (setProxy) {
@@ -1078,7 +1078,75 @@ void tst_QTcpServer::pauseAccepting()
Abort);
}
QVERIFY(spy.wait());
- QCOMPARE(spy.count(), 6);
+ QCOMPARE(spy.size(), 6);
+}
+
+
+// Only adds the socket to the pending connections list after emitNextSocket is
+// called. It's very artificial, but it allows us to test the behavior of
+// the pendingConnectionAvailable signal when a server doesn't add the socket
+// during the incomingConnection virtual function.
+class DerivedServer : public QTcpServer
+{
+public:
+ explicit DerivedServer(QObject *parent = nullptr)
+ : QTcpServer(parent)
+ {
+ }
+
+ void emitNextSocket()
+ {
+ if (m_socketDescriptors.isEmpty())
+ return;
+ auto *socket = new QTcpSocket(this);
+ socket->setSocketDescriptor(m_socketDescriptors.back());
+ m_socketDescriptors.pop_back();
+ addPendingConnection(socket);
+ }
+protected:
+ void incomingConnection(qintptr socketDescriptor) override
+ {
+ m_socketDescriptors.push_back(socketDescriptor);
+ }
+private:
+ QList<qintptr> m_socketDescriptors;
+};
+
+void tst_QTcpServer::pendingConnectionAvailable_data()
+{
+ QTest::addColumn<bool>("useDerivedServer");
+ QTest::newRow("QTcpServer") << false;
+ QTest::newRow("DerivedServer") << true;
+}
+
+void tst_QTcpServer::pendingConnectionAvailable()
+{
+ QFETCH_GLOBAL(bool, setProxy);
+ if (setProxy)
+ QSKIP("This feature does not differentiate with or without proxy");
+ QFETCH(bool, useDerivedServer);
+
+ QTcpServer *server = useDerivedServer ? new DerivedServer : new QTcpServer;
+ if (!server->listen(QHostAddress::LocalHost, 0)) {
+ qWarning() << "Server failed to listen:" << server->errorString();
+ QSKIP("Server failed to listen");
+ }
+ QSignalSpy newConnectionSpy(server, &QTcpServer::newConnection);
+ QSignalSpy pendingConnectionSpy(server, &QTcpServer::pendingConnectionAvailable);
+
+ QTcpSocket socket;
+ socket.connectToHost(QHostAddress::LocalHost, server->serverPort());
+
+ QVERIFY(newConnectionSpy.wait());
+ QVERIFY(socket.waitForConnected());
+ QCOMPARE(socket.state(), QTcpSocket::ConnectedState);
+
+ int expectedPendingConnections = useDerivedServer ? 0 : 1;
+ QCOMPARE(pendingConnectionSpy.size(), expectedPendingConnections);
+
+ if (useDerivedServer)
+ static_cast<DerivedServer *>(server)->emitNextSocket();
+ QCOMPARE(pendingConnectionSpy.size(), 1);
}
QTEST_MAIN(tst_QTcpServer)
diff --git a/tests/auto/network/socket/qtcpsocket/BLACKLIST b/tests/auto/network/socket/qtcpsocket/BLACKLIST
index d42457d743..6261c85a09 100644
--- a/tests/auto/network/socket/qtcpsocket/BLACKLIST
+++ b/tests/auto/network/socket/qtcpsocket/BLACKLIST
@@ -1,7 +1,24 @@
[timeoutConnect:ip]
windows
-[connectToHostError]
-windows-10 gcc developer-build
+# QTBUG-101274
+[timeoutConnect:WithSocks5Proxy:ip]
+qnx ci
+[timeoutConnect:WithSocks5ProxyAuth:ip]
+qnx ci
+[timeoutConnect:WithHttpProxy:ip]
+qnx ci
+[timeoutConnect:WithHttpProxyBasicAuth:ip]
+qnx ci
+[timeoutConnect:WithSocks5Proxy SSL:ip]
+qnx ci
+[timeoutConnect:WithSocks5AuthProxy SSL:ip]
+qnx ci
+[timeoutConnect:WithHttpProxy SSL:ip]
+qnx ci
+[timeoutConnect:WithHttpProxyBasicAuth SSL:ip]
+qnx ci
+[suddenRemoteDisconnect:WithoutProxy:Qt4 Client <-> Qt4 Server]
+qnx ci
# QTBUG-66247
[delayedClose:WithSocks5Proxy]
windows-10 gcc developer-build
@@ -53,3 +70,8 @@ windows-10 gcc developer-build
windows-10 gcc developer-build
[bind]
macos arm
+# QTBUG-101274
+[bindThenResolveHost:WithoutProxy:first-fail]
+qnx ci
+[bindThenResolveHost:WithoutProxy SSL:first-fail]
+qnx ci
diff --git a/tests/auto/network/socket/qtcpsocket/CMakeLists.txt b/tests/auto/network/socket/qtcpsocket/CMakeLists.txt
index 645c65671a..7b6bb4d881 100644
--- a/tests/auto/network/socket/qtcpsocket/CMakeLists.txt
+++ b/tests/auto/network/socket/qtcpsocket/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qtcpsocket.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qtcpsocket LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
if(NOT QT_FEATURE_private_tests)
return()
diff --git a/tests/auto/network/socket/qtcpsocket/stressTest/CMakeLists.txt b/tests/auto/network/socket/qtcpsocket/stressTest/CMakeLists.txt
index 950c4356e2..3ea6c55895 100644
--- a/tests/auto/network/socket/qtcpsocket/stressTest/CMakeLists.txt
+++ b/tests/auto/network/socket/qtcpsocket/stressTest/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from stressTest.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## stressTest Binary:
@@ -9,11 +10,7 @@ qt_internal_add_executable(stressTest
SOURCES
Test.cpp Test.h
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:stressTest.pro:<TRUE>:
-# MOC_DIR = ".moc/"
-# TMP_DIR = ".tmp/"
diff --git a/tests/auto/network/socket/qtcpsocket/stressTest/Test.cpp b/tests/auto/network/socket/qtcpsocket/stressTest/Test.cpp
index ed61db1a13..8d6e470220 100644
--- a/tests/auto/network/socket/qtcpsocket/stressTest/Test.cpp
+++ b/tests/auto/network/socket/qtcpsocket/stressTest/Test.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** 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.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
// Qt
#include <QByteArray>
#include <QCoreApplication>
diff --git a/tests/auto/network/socket/qtcpsocket/stressTest/Test.h b/tests/auto/network/socket/qtcpsocket/stressTest/Test.h
index 5e6b2b9467..495b90d733 100644
--- a/tests/auto/network/socket/qtcpsocket/stressTest/Test.h
+++ b/tests/auto/network/socket/qtcpsocket/stressTest/Test.h
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** 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.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef TEST_H
#define TEST_H
diff --git a/tests/auto/network/socket/qtcpsocket/stressTest/main.cpp b/tests/auto/network/socket/qtcpsocket/stressTest/main.cpp
index 1948389e37..f989a4de34 100644
--- a/tests/auto/network/socket/qtcpsocket/stressTest/main.cpp
+++ b/tests/auto/network/socket/qtcpsocket/stressTest/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** 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.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "Test.h"
#include <QCoreApplication>
diff --git a/tests/auto/network/socket/qtcpsocket/test/CMakeLists.txt b/tests/auto/network/socket/qtcpsocket/test/CMakeLists.txt
index 759f655417..c3258f8a95 100644
--- a/tests/auto/network/socket/qtcpsocket/test/CMakeLists.txt
+++ b/tests/auto/network/socket/qtcpsocket/test/CMakeLists.txt
@@ -1,35 +1,24 @@
-# Generated from test.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qtcpsocket Test:
#####################################################################
qt_internal_add_test(tst_qtcpsocket
- OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" # special case
+ OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../"
SOURCES
../tst_qtcpsocket.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::NetworkPrivate
- QT_TEST_SERVER_LIST "danted" "squid" "apache2" "ftp-proxy" "vsftpd" "iptables" "cyrus" # special case
+ QT_TEST_SERVER_LIST "danted" "squid" "apache2" "ftp-proxy" "vsftpd" "iptables" "cyrus"
)
## Scopes:
#####################################################################
qt_internal_extend_target(tst_qtcpsocket CONDITION WIN32
- PUBLIC_LIBRARIES
+ LIBRARIES
ws2_32
)
-
-#### Keys ignored in scope 4:.:.:test.pro:(CMAKE_BUILD_TYPE STREQUAL Debug):
-# DESTDIR = "../debug"
-
-#### Keys ignored in scope 5:.:.:test.pro:else:
-# DESTDIR = "../release"
-
-#### Keys ignored in scope 6:.:.:test.pro:else:
-# DESTDIR = "../"
-
-#### Keys ignored in scope 7:.:.:test.pro:LINUX:
-# QT_TEST_SERVER_LIST = "danted" "squid" "apache2" "ftp-proxy" "vsftpd" "iptables" "cyrus"
diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
index 4d903a710a..4ec01a9d94 100644
--- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
@@ -1,36 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2017 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) 2017 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qglobal.h>
-// To prevent windows system header files from re-defining min/max
-#define NOMINMAX 1
#if defined(_WIN32)
#include <winsock2.h>
#else
@@ -83,14 +56,12 @@
#include <memory>
-#ifdef Q_OS_LINUX
-#include "private/qnativesocketengine_p.h"
-#endif // Q_OS_LINUX
-
#include "private/qhostinfo_p.h"
#include "../../../network-settings.h"
+using namespace Qt::StringLiterals;
+
QT_FORWARD_DECLARE_CLASS(QTcpSocket)
class SocketPair;
@@ -312,7 +283,7 @@ tst_QTcpSocket::tst_QTcpSocket()
tmpSocket = 0;
//This code relates to the socketsConstructedBeforeEventLoop test case
- earlyConstructedSockets = new SocketPair;
+ earlyConstructedSockets = new SocketPair(this);
QVERIFY(earlyConstructedSockets->create());
earlyBytesWrittenCount = 0;
earlyReadyReadCount = 0;
@@ -361,7 +332,8 @@ void tst_QTcpSocket::initTestCase()
//QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::firewallServerName(), 1357));
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::socksProxyServerName(), 1080));
QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpServerName(), 21));
- QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpProxyServerName(), 2121));
+ // FTP currently not supported:
+ // QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpProxyServerName(), 2121));
#else
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
@@ -376,8 +348,8 @@ void tst_QTcpSocket::init()
QFETCH_GLOBAL(int, proxyType);
QList<QHostAddress> socks5Addresses = QHostInfo::fromName(QtNetworkSettings::socksProxyServerName()).addresses();
QList<QHostAddress> httpProxyAddresses = QHostInfo::fromName(QtNetworkSettings::httpProxyServerName()).addresses();
- QVERIFY2(socks5Addresses.count() > 0, "failed to get ip address for SOCKS5 proxy server");
- QVERIFY2(httpProxyAddresses.count() > 0, "failed to get ip address for HTTP proxy server");
+ QVERIFY2(socks5Addresses.size() > 0, "failed to get ip address for SOCKS5 proxy server");
+ QVERIFY2(httpProxyAddresses.size() > 0, "failed to get ip address for HTTP proxy server");
QString socks5Address = socks5Addresses.first().toString();
QString httpProxyAddress = httpProxyAddresses.first().toString();
QNetworkProxy proxy;
@@ -517,12 +489,13 @@ void tst_QTcpSocket::bind_data()
bool testIpv6 = false;
// iterate all interfaces, add all addresses on them as test data
- QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
- foreach (const QNetworkInterface &netinterface, interfaces) {
+ const QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
+ for (const QNetworkInterface &netinterface : interfaces) {
if (!netinterface.isValid())
continue;
- foreach (const QNetworkAddressEntry &entry, netinterface.addressEntries()) {
+ const auto entries = netinterface.addressEntries();
+ for (const QNetworkAddressEntry &entry : entries) {
if (entry.ip().isInSubnet(QHostAddress::parseSubnet("fe80::/10"))
|| entry.ip().isInSubnet(QHostAddress::parseSubnet("169.254/16")))
continue; // link-local bind will fail, at least on Linux, so skip it.
@@ -552,12 +525,12 @@ void tst_QTcpSocket::bind_data()
// these ranges are guaranteed to be reserved for 'documentation purposes',
// and thus, should be unused in the real world. Not that I'm assuming the
// world is full of competent administrators, or anything.
- QStringList knownBad;
- knownBad << "198.51.100.1";
- knownBad << "2001:0DB8::1";
- foreach (const QString &badAddress, knownBad) {
+ const QString knownBad[] = {
+ u"198.51.100.1"_s,
+ u"2001:0DB8::1"_s
+ };
+ for (const QString &badAddress : knownBad)
QTest::addRow("%s:0", badAddress.toLatin1().constData()) << badAddress << 0 << false << QString();
- }
// try to bind to a privileged ports
// we should fail if we're not root (unless the ports are in use!)
@@ -592,7 +565,7 @@ void tst_QTcpSocket::bind()
std::unique_ptr<QTcpSocket> socket(newSocket());
quint16 boundPort;
- qintptr fd;
+ qintptr fd = 0;
if (successExpected) {
bool randomPort = port == -1;
@@ -1810,7 +1783,7 @@ void tst_QTcpSocket::recursiveReadyRead()
QVERIFY2(!timeout(),
"Timed out when waiting for the readyRead() signal.");
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
delete testSocket;
}
@@ -1852,7 +1825,7 @@ void tst_QTcpSocket::atEnd()
QVERIFY2(greeting.startsWith("220 (vsFTPd 3."), qPrintable(greeting));
#else
// Test server must use some vsFTPd 2.x.x version
- QVERIFY2(greeting.length() == sizeof("220 (vsFTPd 2.x.x)")-1, qPrintable(greeting));
+ QVERIFY2(greeting.size() == sizeof("220 (vsFTPd 2.x.x)")-1, qPrintable(greeting));
QVERIFY2(greeting.startsWith("220 (vsFTPd 2."), qPrintable(greeting));
#endif
QVERIFY2(greeting.endsWith(QLatin1Char(')')), qPrintable(greeting));
@@ -2035,8 +2008,8 @@ void tst_QTcpSocket::remoteCloseError()
enterLoop(30);
QVERIFY(!timeout());
- QCOMPARE(disconnectedSpy.count(), 1);
- QCOMPARE(errorSpy.count(), 1);
+ QCOMPARE(disconnectedSpy.size(), 1);
+ QCOMPARE(errorSpy.size(), 1);
QCOMPARE(clientSocket->error(), QAbstractSocket::RemoteHostClosedError);
delete serverSocket;
@@ -2167,7 +2140,7 @@ void tst_QTcpSocket::waitForConnectedInHostLookupSlot()
if (tmpSocket->state() != QAbstractSocket::ConnectedState)
loop.exec();
- QCOMPARE(timerSpy.count(), 0);
+ QCOMPARE(timerSpy.size(), 0);
delete tmpSocket;
}
@@ -2221,7 +2194,7 @@ public slots:
#if defined(Q_OS_MAC)
pthread_yield_np();
#elif defined Q_OS_LINUX && !defined Q_OS_ANDROID
- pthread_yield();
+ sched_yield();
#endif
if (!sock->waitForConnected()) {
networkTimeout = true;
@@ -2272,7 +2245,7 @@ void tst_QTcpSocket::readyReadSignalsAfterWaitForReadyRead()
// Wait for the read
QVERIFY(socket->waitForReadyRead(10000));
- QCOMPARE(readyReadSpy.count(), 1);
+ QCOMPARE(readyReadSpy.size(), 1);
QString s = socket->readLine();
QVERIFY2(QtNetworkSettings::compareReplyIMAP(s.toLatin1()), s.toLatin1().constData());
@@ -2280,7 +2253,7 @@ void tst_QTcpSocket::readyReadSignalsAfterWaitForReadyRead()
QCoreApplication::instance()->processEvents();
QCOMPARE(socket->bytesAvailable(), qint64(0));
- QCOMPARE(readyReadSpy.count(), 1);
+ QCOMPARE(readyReadSpy.size(), 1);
delete socket;
}
@@ -2354,8 +2327,8 @@ void tst_QTcpSocket::abortiveClose()
enterLoop(5);
- QCOMPARE(readyReadSpy.count(), 0);
- QCOMPARE(errorSpy.count(), 1);
+ QCOMPARE(readyReadSpy.size(), 0);
+ QCOMPARE(errorSpy.size(), 1);
QCOMPARE(*static_cast<const int *>(errorSpy.at(0).at(0).constData()),
int(QAbstractSocket::RemoteHostClosedError));
@@ -2474,11 +2447,11 @@ void tst_QTcpSocket::connectionRefused()
QCOMPARE(socket->state(), QAbstractSocket::UnconnectedState);
QCOMPARE(socket->error(), QAbstractSocket::ConnectionRefusedError);
- QCOMPARE(stateSpy.count(), 3);
+ QCOMPARE(stateSpy.size(), 3);
QCOMPARE(qvariant_cast<QAbstractSocket::SocketState>(stateSpy.at(0).at(0)), QAbstractSocket::HostLookupState);
QCOMPARE(qvariant_cast<QAbstractSocket::SocketState>(stateSpy.at(1).at(0)), QAbstractSocket::ConnectingState);
QCOMPARE(qvariant_cast<QAbstractSocket::SocketState>(stateSpy.at(2).at(0)), QAbstractSocket::UnconnectedState);
- QCOMPARE(errorSpy.count(), 1);
+ QCOMPARE(errorSpy.size(), 1);
delete socket;
}
@@ -2610,7 +2583,7 @@ void tst_QTcpSocket::moveToThread0()
{
// Case 1: Moved after connecting, before waiting for connection.
- QTcpSocket *socket = newSocket();;
+ QTcpSocket *socket = newSocket();
socket->connectToHost(QtNetworkSettings::imapServerName(), 143);
socket->moveToThread(0);
QVERIFY(socket->waitForConnected(5000));
@@ -2941,6 +2914,7 @@ void tst_QTcpSocket::proxyFactory_data()
<< proxyList << proxyList.at(1)
<< false << int(QAbstractSocket::UnknownSocketError);
+#if 0 // FTP not currently supported
proxyList.clear();
proxyList << QNetworkProxy(QNetworkProxy::FtpCachingProxy, QtNetworkSettings::ftpProxyServerName(), 2121)
<< QNetworkProxy(QNetworkProxy::HttpCachingProxy, QtNetworkSettings::httpProxyServerName(), 3129)
@@ -2948,6 +2922,7 @@ void tst_QTcpSocket::proxyFactory_data()
QTest::newRow("ftp+cachinghttp+socks5")
<< proxyList << proxyList.at(2)
<< false << int(QAbstractSocket::UnknownSocketError);
+#endif
// tests that fail to connect
proxyList.clear();
@@ -2956,6 +2931,7 @@ void tst_QTcpSocket::proxyFactory_data()
<< proxyList << QNetworkProxy()
<< true << int(QAbstractSocket::UnsupportedSocketOperationError);
+#if 0 // FTP not currently supported
proxyList.clear();
proxyList << QNetworkProxy(QNetworkProxy::FtpCachingProxy, QtNetworkSettings::ftpProxyServerName(), 2121);
QTest::newRow("ftp")
@@ -2968,6 +2944,7 @@ void tst_QTcpSocket::proxyFactory_data()
QTest::newRow("ftp+cachinghttp")
<< proxyList << QNetworkProxy()
<< true << int(QAbstractSocket::UnsupportedSocketOperationError);
+#endif
}
void tst_QTcpSocket::proxyFactory()
@@ -3147,8 +3124,8 @@ void tst_QTcpSocket::serverDisconnectWithBuffered()
QCOMPARE(socket->state(), QAbstractSocket::UnconnectedState);
}
// Test signal emitting
- QCOMPARE(spyDisconnected.count(), 1);
- QVERIFY(spyStateChanged.count() > 0);
+ QCOMPARE(spyDisconnected.size(), 1);
+ QVERIFY(spyStateChanged.size() > 0);
QVERIFY(qvariant_cast<QAbstractSocket::SocketState>(spyStateChanged.last().first())
== QAbstractSocket::UnconnectedState);
@@ -3237,7 +3214,7 @@ void tst_QTcpSocket::readNotificationsAfterBind()
QTestEventLoop::instance().enterLoop(10);
QVERIFY2(!QTestEventLoop::instance().timeout(), "Connection to closed port timed out instead of refusing, something is wrong");
QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState, "Socket connected unexpectedly!");
- QCOMPARE(spyReadyRead.count(), 0);
+ QCOMPARE(spyReadyRead.size(), 0);
}
QTEST_MAIN(tst_QTcpSocket)
diff --git a/tests/auto/network/socket/qudpsocket/BLACKLIST b/tests/auto/network/socket/qudpsocket/BLACKLIST
index 9d4396deb6..f5f6a8e156 100644
--- a/tests/auto/network/socket/qudpsocket/BLACKLIST
+++ b/tests/auto/network/socket/qudpsocket/BLACKLIST
@@ -1,13 +1,7 @@
[writeDatagramToNonExistingPeer]
windows
-# QTBUG-85364
-windows-10 gcc cmake
[readyReadForEmptyDatagram]
opensuse-leap
-[echo]
-opensuse-42.3
-[readyReadForEmptyDatagram]
-linux
[multicast]
centos
macos arm
diff --git a/tests/auto/network/socket/qudpsocket/CMakeLists.txt b/tests/auto/network/socket/qudpsocket/CMakeLists.txt
index b9d0646e58..a7a2659340 100644
--- a/tests/auto/network/socket/qudpsocket/CMakeLists.txt
+++ b/tests/auto/network/socket/qudpsocket/CMakeLists.txt
@@ -1,4 +1,11 @@
-# Generated from qudpsocket.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qudpsocket LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
-add_subdirectory(test)
add_subdirectory(clientserver)
+add_subdirectory(test)
diff --git a/tests/auto/network/socket/qudpsocket/clientserver/CMakeLists.txt b/tests/auto/network/socket/qudpsocket/clientserver/CMakeLists.txt
index 7c8b924ca9..4644d0d96f 100644
--- a/tests/auto/network/socket/qudpsocket/clientserver/CMakeLists.txt
+++ b/tests/auto/network/socket/qudpsocket/clientserver/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from clientserver.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## clientserver Binary:
@@ -8,6 +9,6 @@ qt_internal_add_executable(clientserver
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/"
SOURCES
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
)
diff --git a/tests/auto/network/socket/qudpsocket/clientserver/main.cpp b/tests/auto/network/socket/qudpsocket/clientserver/main.cpp
index 705abf87e3..76bdf3aada 100644
--- a/tests/auto/network/socket/qudpsocket/clientserver/main.cpp
+++ b/tests/auto/network/socket/qudpsocket/clientserver/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** 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.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtNetwork>
class ClientServer : public QUdpSocket
diff --git a/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt b/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt
index 6a781aadc4..69b62c2f9f 100644
--- a/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt
+++ b/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt
@@ -1,34 +1,20 @@
-# Generated from test.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qudpsocket Test:
#####################################################################
qt_internal_add_test(tst_qudpsocket
- OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" # special case
+ OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../"
SOURCES
../tst_qudpsocket.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
Qt::TestPrivate
- QT_TEST_SERVER_LIST "danted" "echo" # special case
+ QT_TEST_SERVER_LIST "danted" "echo"
)
-#### Keys ignored in scope 1:.:.:test.pro:<TRUE>:
-# MOC_DIR = "tmp"
-# testcase.timeout = "800"
-
-## Scopes:
-#####################################################################
-
-#### Keys ignored in scope 3:.:.:test.pro:(CMAKE_BUILD_TYPE STREQUAL Debug):
-# DESTDIR = "../debug"
-
-#### Keys ignored in scope 4:.:.:test.pro:else:
-# DESTDIR = "../release"
-
-#### Keys ignored in scope 5:.:.:test.pro:else:
-# DESTDIR = "../"
-
-#### Keys ignored in scope 6:.:.:test.pro:LINUX:
-# QT_TEST_SERVER_LIST = "danted" "echo"
+if(QT_FEATURE_process)
+ add_dependencies(tst_qudpsocket clientserver)
+endif()
diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
index 31fd1a3b30..689ff452f9 100644
--- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
+++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
@@ -1,32 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Copyright (C) 2017 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) 2021 The Qt Company Ltd.
+// Copyright (C) 2017 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QSignalSpy>
@@ -36,6 +10,7 @@
#endif
#include <QScopeGuard>
#include <QVersionNumber>
+#include <QSemaphore>
#include <qcoreapplication.h>
#include <qfileinfo.h>
@@ -53,6 +28,7 @@
#include <QNetworkInterface>
#include <qstringlist.h>
+#include <QSet>
#include "../../../network-settings.h"
#include <QtTest/private/qemulationdetector_p.h>
@@ -70,6 +46,8 @@
# define RELIABLE_BYTES_AVAILABLE
#endif
+using namespace Qt::StringLiterals;
+
Q_DECLARE_METATYPE(QHostAddress)
QT_FORWARD_DECLARE_CLASS(QUdpSocket)
@@ -127,6 +105,8 @@ private slots:
void asyncReadDatagram();
void writeInHostLookupState();
+ void readyReadConnectionThrottling();
+
protected slots:
void empty_readyReadSlot();
void empty_connectedSlot();
@@ -145,6 +125,7 @@ private:
QList<QHostAddress> allAddresses;
QHostAddress multicastGroup4, multicastGroup6;
QList<QHostAddress> linklocalMulticastGroups;
+ QNetworkInterface ifaceWithIPv6;
QUdpSocket *m_asyncSender;
QUdpSocket *m_asyncReceiver;
};
@@ -195,26 +176,7 @@ QNetworkInterface tst_QUdpSocket::interfaceForGroup(const QHostAddress &multicas
if (!scope.isEmpty())
return QNetworkInterface::interfaceFromName(scope);
- static QNetworkInterface ipv6if = [&]() {
- // find any link local address in the allAddress list
- for (const QHostAddress &addr: qAsConst(allAddresses)) {
- if (addr.isLoopback())
- continue;
-
- QString scope = addr.scopeId();
- if (!scope.isEmpty()) {
- QNetworkInterface iface = QNetworkInterface::interfaceFromName(scope);
- qDebug() << "Will bind IPv6 sockets to" << iface;
- return iface;
- }
- }
-
- qWarning("interfaceForGroup(%s) could not find any link-local IPv6 address! "
- "Make sure this test is behind a check of QtNetworkSettings::hasIPv6().",
- qUtf8Printable(multicastGroup.toString()));
- return QNetworkInterface();
- }();
- return ipv6if;
+ return ifaceWithIPv6;
}
bool tst_QUdpSocket::shouldWorkaroundLinuxKernelBug()
@@ -293,15 +255,22 @@ void tst_QUdpSocket::initTestCase()
// ff12:: is temporary, not prefix-based, link-local
r[0] = qToBigEndian(Q_UINT64_C(0xff12) << 48);
QHostAddress llbase(*reinterpret_cast<Q_IPV6ADDR *>(&r));
- for (const QHostAddress &a : qAsConst(allAddresses)) {
+ for (const QHostAddress &a : std::as_const(allAddresses)) {
QString scope = a.scopeId();
if (scope.isEmpty())
continue;
llbase.setScopeId(scope);
linklocalMulticastGroups << llbase;
+ if (!ifaceWithIPv6.isValid()) {
+ // Remember the first interface we've found that has IPv6 so we can
+ // bind non-link-local sockets to it (the first is least likely to
+ // be some weird virtual interface).
+ ifaceWithIPv6 = QNetworkInterface::interfaceFromName(scope);
+ }
}
qDebug() << "Will use multicast groups" << multicastGroup4 << multicastGroup6 << linklocalMulticastGroups;
+ qDebug() << "Will bind IPv6 sockets to" << ifaceWithIPv6;
m_workaroundLinuxKernelBug = shouldWorkaroundLinuxKernelBug();
if (QTestPrivate::isRunningArmOnX86())
@@ -358,7 +327,7 @@ void tst_QUdpSocket::unconnectedServerAndClientTest()
QSignalSpy stateChangedSpy(&serverSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)));
QVERIFY2(serverSocket.bind(), serverSocket.errorString().toLatin1().constData());
- QCOMPARE(stateChangedSpy.count(), 1);
+ QCOMPARE(stateChangedSpy.size(), 1);
const char *message[] = {"Yo mista", "Yo", "Wassap"};
@@ -407,10 +376,11 @@ void tst_QUdpSocket::broadcasting()
const char *message[] = {"Yo mista", "", "Yo", "Wassap"};
QList<QHostAddress> broadcastAddresses;
- foreach (QNetworkInterface iface, QNetworkInterface::allInterfaces()) {
+ const auto ifaces = QNetworkInterface::allInterfaces();
+ for (const QNetworkInterface &iface : ifaces) {
if ((iface.flags() & QNetworkInterface::CanBroadcast)
&& iface.flags() & QNetworkInterface::IsUp) {
- for (int i=0;i<iface.addressEntries().count();i++) {
+ for (int i=0;i<iface.addressEntries().size();i++) {
QHostAddress broadcast = iface.addressEntries().at(i).broadcast();
if (broadcast.protocol() == QAbstractSocket::IPv4Protocol)
broadcastAddresses.append(broadcast);
@@ -435,7 +405,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);
@@ -455,7 +425,7 @@ void tst_QUdpSocket::broadcasting()
QVERIFY(dgram.isValid());
QByteArray arr = dgram.data();
- QCOMPARE(arr.length(), messageLength);
+ QCOMPARE(arr.size(), messageLength);
arr.resize(messageLength);
QCOMPARE(arr, QByteArray(message[i]));
@@ -515,27 +485,27 @@ void tst_QUdpSocket::loop()
QHostAddress peterAddress = makeNonAny(peter.localAddress());
QHostAddress paulAddress = makeNonAny(paul.localAddress());
- QCOMPARE(peter.writeDatagram(peterMessage.data(), peterMessage.length(),
- paulAddress, paul.localPort()), qint64(peterMessage.length()));
- QCOMPARE(paul.writeDatagram(paulMessage.data(), paulMessage.length(),
- peterAddress, peter.localPort()), qint64(paulMessage.length()));
+ QCOMPARE(peter.writeDatagram(peterMessage.data(), peterMessage.size(),
+ paulAddress, paul.localPort()), qint64(peterMessage.size()));
+ QCOMPARE(paul.writeDatagram(paulMessage.data(), paulMessage.size(),
+ peterAddress, peter.localPort()), qint64(paulMessage.size()));
QVERIFY2(peter.waitForReadyRead(9000), QtNetworkSettings::msgSocketError(peter).constData());
QVERIFY2(paul.waitForReadyRead(9000), QtNetworkSettings::msgSocketError(paul).constData());
- QNetworkDatagram peterDatagram = peter.receiveDatagram(paulMessage.length() * 2);
- QNetworkDatagram paulDatagram = paul.receiveDatagram(peterMessage.length() * 2);
+ QNetworkDatagram peterDatagram = peter.receiveDatagram(paulMessage.size() * 2);
+ QNetworkDatagram paulDatagram = paul.receiveDatagram(peterMessage.size() * 2);
if (success) {
- QCOMPARE(peterDatagram.data().length(), qint64(paulMessage.length()));
- QCOMPARE(paulDatagram.data().length(), qint64(peterMessage.length()));
+ QCOMPARE(peterDatagram.data().size(), qint64(paulMessage.size()));
+ QCOMPARE(paulDatagram.data().size(), qint64(peterMessage.size()));
} else {
// this code path seems to never be executed
- QVERIFY(peterDatagram.data().length() != paulMessage.length());
- QVERIFY(paulDatagram.data().length() != peterMessage.length());
+ QVERIFY(peterDatagram.data().size() != paulMessage.size());
+ QVERIFY(paulDatagram.data().size() != peterMessage.size());
}
- QCOMPARE(peterDatagram.data().left(paulMessage.length()), paulMessage);
- QCOMPARE(paulDatagram.data().left(peterMessage.length()), peterMessage);
+ QCOMPARE(peterDatagram.data().left(paulMessage.size()), paulMessage);
+ QCOMPARE(paulDatagram.data().left(peterMessage.size()), peterMessage);
QCOMPARE(peterDatagram.senderAddress(), paulAddress);
QCOMPARE(paulDatagram.senderAddress(), peterAddress);
@@ -592,27 +562,27 @@ void tst_QUdpSocket::ipv6Loop()
peterPort = peter.localPort();
paulPort = paul.localPort();
- QCOMPARE(peter.writeDatagram(peterMessage.data(), peterMessage.length(), QHostAddress("::1"),
- paulPort), qint64(peterMessage.length()));
- QCOMPARE(paul.writeDatagram(paulMessage.data(), paulMessage.length(),
- QHostAddress("::1"), peterPort), qint64(paulMessage.length()));
+ QCOMPARE(peter.writeDatagram(peterMessage.data(), peterMessage.size(), QHostAddress("::1"),
+ paulPort), qint64(peterMessage.size()));
+ QCOMPARE(paul.writeDatagram(paulMessage.data(), paulMessage.size(),
+ QHostAddress("::1"), peterPort), qint64(paulMessage.size()));
QVERIFY(peter.waitForReadyRead(5000));
QVERIFY(paul.waitForReadyRead(5000));
- QNetworkDatagram peterDatagram = peter.receiveDatagram(paulMessage.length() * 2);
- QNetworkDatagram paulDatagram = paul.receiveDatagram(peterMessage.length() * 2);
+ QNetworkDatagram peterDatagram = peter.receiveDatagram(paulMessage.size() * 2);
+ QNetworkDatagram paulDatagram = paul.receiveDatagram(peterMessage.size() * 2);
if (success) {
- QCOMPARE(peterDatagram.data().length(), qint64(paulMessage.length()));
- QCOMPARE(paulDatagram.data().length(), qint64(peterMessage.length()));
+ QCOMPARE(peterDatagram.data().size(), qint64(paulMessage.size()));
+ QCOMPARE(paulDatagram.data().size(), qint64(peterMessage.size()));
} else {
// this code path seems to never be executed
- QVERIFY(peterDatagram.data().length() != paulMessage.length());
- QVERIFY(paulDatagram.data().length() != peterMessage.length());
+ QVERIFY(peterDatagram.data().size() != paulMessage.size());
+ QVERIFY(paulDatagram.data().size() != peterMessage.size());
}
- QCOMPARE(peterDatagram.data().left(paulMessage.length()), paulMessage);
- QCOMPARE(paulDatagram.data().left(peterMessage.length()), peterMessage);
+ QCOMPARE(peterDatagram.data().left(paulMessage.size()), paulMessage);
+ QCOMPARE(paulDatagram.data().left(peterMessage.size()), peterMessage);
QCOMPARE(peterDatagram.senderAddress(), paulAddress);
QCOMPARE(paulDatagram.senderAddress(), peterAddress);
@@ -640,7 +610,7 @@ void tst_QUdpSocket::dualStack()
QVERIFY(v4Sock.bind(QHostAddress(QHostAddress::AnyIPv4), 0));
//test v4 -> dual
- QCOMPARE((int)v4Sock.writeDatagram(v4Data.constData(), v4Data.length(), QHostAddress(QHostAddress::LocalHost), dualSock.localPort()), v4Data.length());
+ QCOMPARE((int)v4Sock.writeDatagram(v4Data.constData(), v4Data.size(), QHostAddress(QHostAddress::LocalHost), dualSock.localPort()), v4Data.size());
QVERIFY2(dualSock.waitForReadyRead(5000), QtNetworkSettings::msgSocketError(dualSock).constData());
QNetworkDatagram dgram = dualSock.receiveDatagram(100);
QVERIFY(dgram.isValid());
@@ -652,7 +622,7 @@ void tst_QUdpSocket::dualStack()
QCOMPARE(dgram.senderAddress(), makeNonAny(v4Sock.localAddress(), QHostAddress::Null));
if (dgram.destinationPort() != -1) {
QCOMPARE(dgram.destinationPort(), int(dualSock.localPort()));
- QVERIFY(dgram.destinationAddress().isEqual(dualSock.localAddress()));
+ QVERIFY(dgram.destinationAddress().isEqual(makeNonAny(dualSock.localAddress(), QHostAddress::LocalHost)));
} else {
qInfo("Getting IPv4 destination address failed.");
}
@@ -663,7 +633,7 @@ void tst_QUdpSocket::dualStack()
QVERIFY(v6Sock.bind(QHostAddress(QHostAddress::AnyIPv6), 0));
//test v6 -> dual
- QCOMPARE((int)v6Sock.writeDatagram(v6Data.constData(), v6Data.length(), QHostAddress(QHostAddress::LocalHostIPv6), dualSock.localPort()), v6Data.length());
+ QCOMPARE((int)v6Sock.writeDatagram(v6Data.constData(), v6Data.size(), QHostAddress(QHostAddress::LocalHostIPv6), dualSock.localPort()), v6Data.size());
QVERIFY2(dualSock.waitForReadyRead(5000), QtNetworkSettings::msgSocketError(dualSock).constData());
dgram = dualSock.receiveDatagram(100);
QVERIFY(dgram.isValid());
@@ -674,7 +644,7 @@ void tst_QUdpSocket::dualStack()
QCOMPARE(dgram.destinationAddress(), makeNonAny(dualSock.localAddress(), QHostAddress::LocalHostIPv6));
//test dual -> v6
- QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.length(), QHostAddress(QHostAddress::LocalHostIPv6), v6Sock.localPort()), dualData.length());
+ QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.size(), QHostAddress(QHostAddress::LocalHostIPv6), v6Sock.localPort()), dualData.size());
QVERIFY2(v6Sock.waitForReadyRead(5000), QtNetworkSettings::msgSocketError(v6Sock).constData());
dgram = v6Sock.receiveDatagram(100);
QVERIFY(dgram.isValid());
@@ -686,7 +656,7 @@ void tst_QUdpSocket::dualStack()
}
//test dual -> v4
- QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.length(), QHostAddress(QHostAddress::LocalHost), v4Sock.localPort()), dualData.length());
+ QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.size(), QHostAddress(QHostAddress::LocalHost), v4Sock.localPort()), dualData.size());
QVERIFY2(v4Sock.waitForReadyRead(5000), QtNetworkSettings::msgSocketError(v4Sock).constData());
dgram = v4Sock.receiveDatagram(100);
QVERIFY(dgram.isValid());
@@ -725,19 +695,19 @@ void tst_QUdpSocket::dualStackAutoBinding()
//test an autobound socket can send to both v4 and v6 addresses (v4 first)
QUdpSocket dualSock;
- QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.length(), QHostAddress(QHostAddress::LocalHost), v4Sock.localPort()), dualData.length());
+ QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.size(), QHostAddress(QHostAddress::LocalHost), v4Sock.localPort()), dualData.size());
QVERIFY2(v4Sock.waitForReadyRead(5000), QtNetworkSettings::msgSocketError(v4Sock).constData());
buffer.reserve(100);
size = v4Sock.readDatagram(buffer.data(), 100, &from, &port);
- QCOMPARE((int)size, dualData.length());
+ QCOMPARE((int)size, dualData.size());
buffer.resize(size);
QCOMPARE(buffer, dualData);
- QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.length(), QHostAddress(QHostAddress::LocalHostIPv6), v6Sock.localPort()), dualData.length());
+ QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.size(), QHostAddress(QHostAddress::LocalHostIPv6), v6Sock.localPort()), dualData.size());
QVERIFY2(v6Sock.waitForReadyRead(5000), QtNetworkSettings::msgSocketError(v6Sock).constData());
buffer.reserve(100);
size = v6Sock.readDatagram(buffer.data(), 100, &from, &port);
- QCOMPARE((int)size, dualData.length());
+ QCOMPARE((int)size, dualData.size());
buffer.resize(size);
QCOMPARE(buffer, dualData);
}
@@ -746,19 +716,19 @@ void tst_QUdpSocket::dualStackAutoBinding()
//test an autobound socket can send to both v4 and v6 addresses (v6 first)
QUdpSocket dualSock;
- QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.length(), QHostAddress(QHostAddress::LocalHostIPv6), v6Sock.localPort()), dualData.length());
+ QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.size(), QHostAddress(QHostAddress::LocalHostIPv6), v6Sock.localPort()), dualData.size());
QVERIFY2(v6Sock.waitForReadyRead(5000), QtNetworkSettings::msgSocketError(v6Sock).constData());
buffer.reserve(100);
size = v6Sock.readDatagram(buffer.data(), 100, &from, &port);
- QCOMPARE((int)size, dualData.length());
+ QCOMPARE((int)size, dualData.size());
buffer.resize(size);
QCOMPARE(buffer, dualData);
- QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.length(), QHostAddress(QHostAddress::LocalHost), v4Sock.localPort()), dualData.length());
+ QCOMPARE((int)dualSock.writeDatagram(dualData.constData(), dualData.size(), QHostAddress(QHostAddress::LocalHost), v4Sock.localPort()), dualData.size());
QVERIFY2(v4Sock.waitForReadyRead(5000), QtNetworkSettings::msgSocketError(v4Sock).constData());
buffer.reserve(100);
size = v4Sock.readDatagram(buffer.data(), 100, &from, &port);
- QCOMPARE((int)size, dualData.length());
+ QCOMPARE((int)size, dualData.size());
buffer.resize(size);
QCOMPARE(buffer, dualData);
}
@@ -779,7 +749,7 @@ void tst_QUdpSocket::dualStackNoIPv4onV6only()
QVERIFY(v6Sock.bind(QHostAddress(QHostAddress::AnyIPv6), 0));
//test v4 -> v6 (should not be received as this is a v6 only socket)
- QCOMPARE((int)v4Sock.writeDatagram(v4Data.constData(), v4Data.length(), QHostAddress(QHostAddress::LocalHost), v6Sock.localPort()), v4Data.length());
+ QCOMPARE((int)v4Sock.writeDatagram(v4Data.constData(), v4Data.size(), QHostAddress(QHostAddress::LocalHost), v6Sock.localPort()), v4Data.size());
QVERIFY(!v6Sock.waitForReadyRead(1000));
}
@@ -899,17 +869,17 @@ void tst_QUdpSocket::writeDatagram()
#if defined (Q_OS_HPUX)
QSKIP("HP-UX 11.11 on hai (PA-RISC 64) truncates too long datagrams.");
#endif
- QCOMPARE(bytesspy.count(), 0);
- QCOMPARE(errorspy.count(), 1);
+ QCOMPARE(bytesspy.size(), 0);
+ QCOMPARE(errorspy.size(), 1);
QCOMPARE(*static_cast<const int *>(errorspy.at(0).at(0).constData()),
int(QUdpSocket::DatagramTooLargeError));
QCOMPARE(client.error(), QUdpSocket::DatagramTooLargeError);
break;
}
- QCOMPARE(bytesspy.count(), 1);
+ QCOMPARE(bytesspy.size(), 1);
QCOMPARE(*static_cast<const qint64 *>(bytesspy.at(0).at(0).constData()),
qint64(i * 1024));
- QCOMPARE(errorspy.count(), 0);
+ QCOMPARE(errorspy.size(), 0);
if (!server.waitForReadyRead(5000))
QSKIP(QString("UDP packet lost at size %1, unable to complete the test.").arg(i * 1024).toLatin1().data());
QCOMPARE(server.pendingDatagramSize(), qint64(i * 1024));
@@ -1022,7 +992,7 @@ void tst_QUdpSocket::writeDatagramToNonExistingPeer()
QVERIFY(sUdp.bind());
QCOMPARE(sUdp.writeDatagram("", 1, peerAddress, peerPort), qint64(1));
QTestEventLoop::instance().enterLoop(1);
- QCOMPARE(sReadyReadSpy.count(), 0);
+ QCOMPARE(sReadyReadSpy.size(), 0);
}
void tst_QUdpSocket::writeToNonExistingPeer_data()
@@ -1065,8 +1035,8 @@ void tst_QUdpSocket::writeToNonExistingPeer()
// the third one will succeed...
QCOMPARE(sConnected.write("", 1), qint64(1));
QTestEventLoop::instance().enterLoop(1);
- QCOMPARE(sConnectedReadyReadSpy.count(), 0);
- QCOMPARE(sConnectedErrorSpy.count(), 1);
+ QCOMPARE(sConnectedReadyReadSpy.size(), 0);
+ QCOMPARE(sConnectedErrorSpy.size(), 1);
QCOMPARE(int(sConnected.error()), int(QUdpSocket::ConnectionRefusedError));
// we should now get a read error
@@ -1265,11 +1235,12 @@ void tst_QUdpSocket::multicastTtlOption_data()
QTest::addColumn<int>("ttl");
QTest::addColumn<int>("expected");
- QList<QHostAddress> addresses;
- addresses += QHostAddress(QHostAddress::AnyIPv4);
- addresses += QHostAddress(QHostAddress::AnyIPv6);
+ const QHostAddress addresses[] = {
+ QHostAddress(QHostAddress::AnyIPv4),
+ QHostAddress(QHostAddress::AnyIPv6),
+ };
- foreach (const QHostAddress &address, addresses) {
+ for (const QHostAddress &address : addresses) {
const QByteArray addressB = address.toString().toLatin1();
QTest::newRow((addressB + " 0").constData()) << address << 0 << 0;
QTest::newRow((addressB + " 1").constData()) << address << 1 << 1;
@@ -1311,11 +1282,12 @@ void tst_QUdpSocket::multicastLoopbackOption_data()
QTest::addColumn<int>("loopback");
QTest::addColumn<int>("expected");
- QList<QHostAddress> addresses;
- addresses += QHostAddress(QHostAddress::AnyIPv4);
- addresses += QHostAddress(QHostAddress::AnyIPv6);
+ const QHostAddress addresses[] = {
+ QHostAddress(QHostAddress::AnyIPv4),
+ QHostAddress(QHostAddress::AnyIPv6),
+ };
- foreach (const QHostAddress &address, addresses) {
+ for (const QHostAddress &address : addresses) {
const QByteArray addressB = address.toString().toLatin1();
QTest::newRow((addressB + " 0").constData()) << address << 0 << 0;
QTest::newRow((addressB + " 1").constData()) << address << 1 << 1;
@@ -1358,7 +1330,7 @@ void tst_QUdpSocket::multicastJoinBeforeBind_data()
QTest::newRow("valid ipv4 group address") << multicastGroup4;
QTest::newRow("invalid ipv4 group address") << QHostAddress(QHostAddress::Broadcast);
QTest::newRow("valid ipv6 group address") << multicastGroup6;
- for (const QHostAddress &a : qAsConst(linklocalMulticastGroups))
+ for (const QHostAddress &a : std::as_const(linklocalMulticastGroups))
QTest::addRow("valid ipv6 %s-link group address", a.scopeId().toLatin1().constData()) << a;
QTest::newRow("invalid ipv6 group address") << QHostAddress(QHostAddress::AnyIPv6);
}
@@ -1378,7 +1350,7 @@ void tst_QUdpSocket::multicastLeaveAfterClose_data()
QTest::addColumn<QHostAddress>("groupAddress");
QTest::newRow("ipv4") << multicastGroup4;
QTest::newRow("ipv6") << multicastGroup6;
- for (const QHostAddress &a : qAsConst(linklocalMulticastGroups))
+ for (const QHostAddress &a : std::as_const(linklocalMulticastGroups))
QTest::addRow("ipv6-link-%s", a.scopeId().toLatin1().constData()) << a;
}
@@ -1415,11 +1387,12 @@ void tst_QUdpSocket::setMulticastInterface_data()
{
QTest::addColumn<QNetworkInterface>("iface");
QTest::addColumn<QHostAddress>("address");
- QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
- foreach (const QNetworkInterface &iface, interfaces) {
+ const QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces();
+ for (const QNetworkInterface &iface : interfaces) {
if ((iface.flags() & QNetworkInterface::IsUp) == 0)
continue;
- foreach (const QNetworkAddressEntry &entry, iface.addressEntries()) {
+ const auto entries = iface.addressEntries();
+ for (const QNetworkAddressEntry &entry : entries) {
const QByteArray testName = iface.name().toLatin1() + ':' + entry.ip().toString().toLatin1();
QTest::newRow(testName.constData()) << iface << entry.ip();
}
@@ -1472,13 +1445,13 @@ void tst_QUdpSocket::multicast_data()
QTest::newRow("valid bind, group ipv4 address") << anyAddress << true << groupAddress << true;
QTest::newRow("valid bind, invalid group ipv4 address") << anyAddress << true << anyAddress << false;
QTest::newRow("valid bind, group ipv6 address") << any6Address << true << group6Address << true;
- for (const QHostAddress &a : qAsConst(linklocalMulticastGroups))
+ for (const QHostAddress &a : std::as_const(linklocalMulticastGroups))
QTest::addRow("valid bind, %s-link group ipv6 address", a.scopeId().toLatin1().constData())
<< any6Address << true << a << true;
QTest::newRow("valid bind, invalid group ipv6 address") << any6Address << true << any6Address << false;
QTest::newRow("dual bind, group ipv4 address") << dualAddress << true << groupAddress << false;
QTest::newRow("dual bind, group ipv6 address") << dualAddress << true << group6Address << true;
- for (const QHostAddress &a : qAsConst(linklocalMulticastGroups))
+ for (const QHostAddress &a : std::as_const(linklocalMulticastGroups))
QTest::addRow("dual bind, %s-link group ipv6 address", a.scopeId().toLatin1().constData())
<< dualAddress << true << a << true;
}
@@ -1523,15 +1496,16 @@ void tst_QUdpSocket::multicast()
if (!joinResult)
return;
- QList<QByteArray> datagrams = QList<QByteArray>()
- << QByteArray("0123")
- << QByteArray("4567")
- << QByteArray("89ab")
- << QByteArray("cdef");
+ const QByteArray datagrams[] = {
+ "0123"_ba,
+ "4567"_ba,
+ "89ab"_ba,
+ "cdef"_ba,
+ };
QUdpSocket sender;
sender.bind();
- foreach (const QByteArray &datagram, datagrams) {
+ for (const QByteArray &datagram : datagrams) {
QNetworkDatagram dgram(datagram, groupAddress, receiver.localPort());
dgram.setInterfaceIndex(interfaceForGroup(groupAddress).index());
QCOMPARE(int(sender.writeDatagram(dgram)),
@@ -1574,7 +1548,7 @@ void tst_QUdpSocket::echo()
{
QFETCH(bool, connect);
QHostInfo info = QHostInfo::fromName(QtNetworkSettings::echoServerName());
- QVERIFY(info.addresses().count());
+ QVERIFY(info.addresses().size());
QHostAddress remote = info.addresses().first();
QUdpSocket sock;
@@ -1601,7 +1575,7 @@ void tst_QUdpSocket::echo()
in = sock.read(sock.pendingDatagramSize());
} else {
in.resize(sock.pendingDatagramSize());
- sock.readDatagram(in.data(), in.length(), &from, &port);
+ sock.readDatagram(in.data(), in.size(), &from, &port);
}
if (in==out)
successes++;
@@ -1624,7 +1598,8 @@ void tst_QUdpSocket::linkLocalIPv6()
QList <QHostAddress> addresses;
QSet <QString> scopes;
QHostAddress localMask("fe80::");
- foreach (const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) {
+ const auto ifaces = QNetworkInterface::allInterfaces();
+ for (const QNetworkInterface &iface : ifaces) {
//Windows preallocates link local addresses to interfaces that are down.
//These may or may not work depending on network driver
if (iface.flags() & QNetworkInterface::IsUp) {
@@ -1639,7 +1614,8 @@ void tst_QUdpSocket::linkLocalIPv6()
continue;
#endif
- foreach (QNetworkAddressEntry addressEntry, iface.addressEntries()) {
+ const auto entries = iface.addressEntries();
+ for (const QNetworkAddressEntry &addressEntry : entries) {
QHostAddress addr(addressEntry.ip());
if (!addr.scopeId().isEmpty() && addr.isInSubnet(localMask, 64)) {
scopes << addr.scopeId();
@@ -1654,7 +1630,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()));
@@ -1663,7 +1639,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()));
@@ -1671,27 +1647,26 @@ void tst_QUdpSocket::linkLocalIPv6()
QSignalSpy spy(s, SIGNAL(readyRead()));
QVERIFY(s->writeDatagram(testData, s->localAddress(), neutral.localPort()));
- QTRY_VERIFY(neutralReadSpy.count() > 0); //note may need to accept a firewall prompt
+ QTRY_VERIFY(neutralReadSpy.size() > 0); //note may need to accept a firewall prompt
- QNetworkDatagram dgram = neutral.receiveDatagram(testData.length() * 2);
+ QNetworkDatagram dgram = neutral.receiveDatagram(testData.size() * 2);
QVERIFY(dgram.isValid());
QCOMPARE(dgram.senderAddress(), s->localAddress());
QCOMPARE(dgram.senderPort(), int(s->localPort()));
QCOMPARE(dgram.destinationAddress(), s->localAddress());
QCOMPARE(dgram.destinationPort(), int(neutral.localPort()));
- QCOMPARE(dgram.data().length(), testData.length());
+ QCOMPARE(dgram.data().size(), testData.size());
QCOMPARE(dgram.data(), testData);
QVERIFY(neutral.writeDatagram(dgram.makeReply(testData)));
- QTRY_VERIFY(spy.count() > 0); //note may need to accept a firewall prompt
+ QTRY_VERIFY(spy.size() > 0); //note may need to accept a firewall prompt
- dgram = s->receiveDatagram(testData.length() * 2);
+ dgram = s->receiveDatagram(testData.size() * 2);
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,
@@ -1710,7 +1685,8 @@ void tst_QUdpSocket::linkLocalIPv4()
QList <QHostAddress> addresses;
QHostAddress localMask("169.254.0.0");
- foreach (const QNetworkInterface& iface, QNetworkInterface::allInterfaces()) {
+ const auto ifaces = QNetworkInterface::allInterfaces();
+ for (const QNetworkInterface &iface : ifaces) {
//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) {
@@ -1724,7 +1700,8 @@ void tst_QUdpSocket::linkLocalIPv4()
if (iface.name().startsWith("utun"))
continue;
#endif
- foreach (QNetworkAddressEntry addr, iface.addressEntries()) {
+ const auto entries = iface.addressEntries();
+ for (const QNetworkAddressEntry &addr : entries) {
if (addr.ip().isInSubnet(localMask, 16)) {
addresses << addr.ip();
qDebug() << "Found IPv4 link local address" << addr.ip();
@@ -1737,7 +1714,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
@@ -1748,15 +1725,15 @@ 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());
- QNetworkDatagram dgram = neutral.receiveDatagram(testData.length() * 2);
+ QNetworkDatagram dgram = neutral.receiveDatagram(testData.size() * 2);
QVERIFY(dgram.isValid());
QCOMPARE(dgram.senderAddress(), s->localAddress());
QCOMPARE(dgram.senderPort(), int(s->localPort()));
- QCOMPARE(dgram.data().length(), testData.length());
+ QCOMPARE(dgram.data().size(), testData.size());
QCOMPARE(dgram.data(), testData);
// Unlike for IPv6 with IPV6_PKTINFO, IPv4 has no standardized way of
@@ -1775,14 +1752,13 @@ void tst_QUdpSocket::linkLocalIPv4()
QVERIFY(neutral.writeDatagram(dgram.makeReply(testData)));
QVERIFY2(s->waitForReadyRead(10000), QtNetworkSettings::msgSocketError(*s).constData());
- dgram = s->receiveDatagram(testData.length() * 2);
+ dgram = s->receiveDatagram(testData.size() * 2);
QVERIFY(dgram.isValid());
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);
}
@@ -1810,7 +1786,7 @@ void tst_QUdpSocket::readyRead()
QTest::qWait(100);
// make sure only one signal was emitted
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QVERIFY(receiver.hasPendingDatagrams());
#ifdef RELIABLE_BYTES_AVAILABLE
QCOMPARE(receiver.bytesAvailable(), qint64(2));
@@ -1822,7 +1798,7 @@ void tst_QUdpSocket::readyRead()
// no new signal should be emitted because we haven't read the first datagram yet
QTest::qWait(100);
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QVERIFY(receiver.hasPendingDatagrams());
QVERIFY(receiver.bytesAvailable() >= 1); // most likely is 1, but it could be 1 + 2 in the future
QCOMPARE(receiver.pendingDatagramSize(), qint64(2));
@@ -1834,7 +1810,7 @@ void tst_QUdpSocket::readyRead()
// write a new datagram and ensure the signal is emitted now
sender.writeDatagram("abc", makeNonAny(receiver.localAddress()), port);
QTest::qWait(100);
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
QVERIFY(receiver.hasPendingDatagrams());
#ifdef RELIABLE_BYTES_AVAILABLE
QCOMPARE(receiver.bytesAvailable(), qint64(3));
@@ -1914,7 +1890,7 @@ void tst_QUdpSocket::asyncReadDatagram()
QTestEventLoop::instance().enterLoop(1);
QVERIFY(!QTestEventLoop::instance().timeout());
- QCOMPARE(spy.count(), 2);
+ QCOMPARE(spy.size(), 2);
delete m_asyncSender;
delete m_asyncReceiver;
@@ -1932,5 +1908,78 @@ void tst_QUdpSocket::writeInHostLookupState()
QVERIFY(!socket.putChar('0'));
}
+void tst_QUdpSocket::readyReadConnectionThrottling()
+{
+ QFETCH_GLOBAL(bool, setProxy);
+ if (setProxy)
+ return;
+ using namespace std::chrono_literals;
+
+ // QTBUG-105871:
+ // We have some signal/slot connection throttling in QAbstractSocket, but it
+ // was caring about the bytes, not about the datagrams.
+ // Test that we don't disable read notifications until we have at least one
+ // datagram available. Otherwise our good users who use the datagram APIs
+ // can get into scenarios where they no longer get the readyRead signal
+ // unless they call a read function once in a while.
+
+ QUdpSocket receiver;
+ QVERIFY(receiver.bind(QHostAddress(QHostAddress::LocalHost), 0));
+
+ QSemaphore semaphore;
+
+ // Repro-ing deterministically eludes me, so we are bruteforcing it:
+ // The thread acts as a remote sender, flooding the receiver with datagrams,
+ // and at some point the receiver would get into the broken state mentioned
+ // earlier.
+ std::unique_ptr<QThread> thread(QThread::create([&semaphore, port = receiver.localPort()]() {
+ QUdpSocket sender;
+ sender.connectToHost(QHostAddress(QHostAddress::LocalHost), port);
+ QCOMPARE(sender.state(), QUdpSocket::ConnectedState);
+
+ constexpr qsizetype PayloadSize = 242;
+ const QByteArray payload(PayloadSize, 'a');
+
+ semaphore.acquire(); // Wait for main thread to be ready
+ while (true) {
+ // We send 100 datagrams at a time, then sleep.
+ // This is mostly to let the main thread catch up between bursts so
+ // it doesn't get stuck in the loop.
+ for (int i = 0; i < 100; ++i) {
+ [[maybe_unused]]
+ qsizetype sent = sender.write(payload);
+ Q_ASSERT(sent > 0);
+ }
+ if (QThread::currentThread()->isInterruptionRequested())
+ break;
+ QThread::sleep(20ms);
+ }
+ }));
+ thread->start();
+ auto threadStopAndWaitGuard = qScopeGuard([&thread] {
+ thread->requestInterruption();
+ thread->quit();
+ thread->wait();
+ });
+
+ qsizetype count = 0;
+ QObject::connect(&receiver, &QUdpSocket::readyRead, &receiver,
+ [&] {
+ while (receiver.hasPendingDatagrams()) {
+ receiver.readDatagram(nullptr, 0);
+ ++count;
+ }
+ // If this prints `false, xxxx` we were pretty much guaranteed
+ // that we would not get called again:
+ // qDebug() << receiver.hasPendingDatagrams() << receiver.bytesAvailable();
+ },
+ Qt::QueuedConnection);
+
+ semaphore.release();
+ constexpr qsizetype MaxCount = 500;
+ QVERIFY2(QTest::qWaitFor([&] { return count >= MaxCount; }, 10s),
+ QByteArray::number(count).constData());
+}
+
QTEST_MAIN(tst_QUdpSocket)
#include "tst_qudpsocket.moc"
diff --git a/tests/auto/network/socket/qudpsocket/udpServer/CMakeLists.txt b/tests/auto/network/socket/qudpsocket/udpServer/CMakeLists.txt
index 4afeb529a7..7dd7f2ba5d 100644
--- a/tests/auto/network/socket/qudpsocket/udpServer/CMakeLists.txt
+++ b/tests/auto/network/socket/qudpsocket/udpServer/CMakeLists.txt
@@ -1,13 +1,14 @@
-# Generated from udpServer.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## udpServer Binary:
#####################################################################
qt_internal_add_executable(udpServer
- OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/./" # special case
+ OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/./"
SOURCES
main.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
)
diff --git a/tests/auto/network/socket/qudpsocket/udpServer/main.cpp b/tests/auto/network/socket/qudpsocket/udpServer/main.cpp
index a5986c29c7..ba5bb3c0d0 100644
--- a/tests/auto/network/socket/qudpsocket/udpServer/main.cpp
+++ b/tests/auto/network/socket/qudpsocket/udpServer/main.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** 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.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtNetwork>
class Server : public QObject