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/.prev_CMakeLists.txt15
-rw-r--r--tests/auto/network/socket/CMakeLists.txt11
-rw-r--r--tests/auto/network/socket/platformsocketengine/BLACKLIST9
-rw-r--r--tests/auto/network/socket/platformsocketengine/CMakeLists.txt20
-rw-r--r--tests/auto/network/socket/platformsocketengine/platformsocketengine.pri8
-rw-r--r--tests/auto/network/socket/platformsocketengine/platformsocketengine.pro11
-rw-r--r--tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp51
-rw-r--r--tests/auto/network/socket/qabstractsocket/CMakeLists.txt11
-rw-r--r--tests/auto/network/socket/qabstractsocket/qabstractsocket.pro10
-rw-r--r--tests/auto/network/socket/qabstractsocket/tst_qabstractsocket.cpp31
-rw-r--r--tests/auto/network/socket/qhttpsocketengine/.prev_CMakeLists.txt34
-rw-r--r--tests/auto/network/socket/qhttpsocketengine/BLACKLIST3
-rw-r--r--tests/auto/network/socket/qhttpsocketengine/CMakeLists.txt22
-rw-r--r--tests/auto/network/socket/qhttpsocketengine/qhttpsocketengine.pro17
-rw-r--r--tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp37
-rw-r--r--tests/auto/network/socket/qlocalsocket/BLACKLIST10
-rw-r--r--tests/auto/network/socket/qlocalsocket/CMakeLists.txt15
-rw-r--r--tests/auto/network/socket/qlocalsocket/qlocalsocket.pro2
-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/socketprocess/socketprocess.pro8
-rw-r--r--tests/auto/network/socket/qlocalsocket/test/test.pro21
-rw-r--r--tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp702
-rw-r--r--tests/auto/network/socket/qsctpsocket/CMakeLists.txt11
-rw-r--r--tests/auto/network/socket/qsctpsocket/qsctpsocket.pro6
-rw-r--r--tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp46
-rw-r--r--tests/auto/network/socket/qsocks5socketengine/.prev_CMakeLists.txt34
-rw-r--r--tests/auto/network/socket/qsocks5socketengine/BLACKLIST8
-rw-r--r--tests/auto/network/socket/qsocks5socketengine/CMakeLists.txt22
-rw-r--r--tests/auto/network/socket/qsocks5socketengine/qsocks5socketengine.pro19
-rw-r--r--tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp54
-rw-r--r--tests/auto/network/socket/qtcpserver/BLACKLIST11
-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/crashingServer.pro8
-rw-r--r--tests/auto/network/socket/qtcpserver/crashingServer/main.cpp62
-rw-r--r--tests/auto/network/socket/qtcpserver/qtcpserver.pro4
-rw-r--r--tests/auto/network/socket/qtcpserver/test/.prev_CMakeLists.txt26
-rw-r--r--tests/auto/network/socket/qtcpserver/test/CMakeLists.txt19
-rw-r--r--tests/auto/network/socket/qtcpserver/test/test.pro24
-rw-r--r--tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp207
-rw-r--r--tests/auto/network/socket/qtcpsocket/BLACKLIST28
-rw-r--r--tests/auto/network/socket/qtcpsocket/CMakeLists.txt9
-rw-r--r--tests/auto/network/socket/qtcpsocket/qtcpsocket.pro8
-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/stressTest/stressTest.pro8
-rw-r--r--tests/auto/network/socket/qtcpsocket/test/.prev_CMakeLists.txt33
-rw-r--r--tests/auto/network/socket/qtcpsocket/test/CMakeLists.txt23
-rw-r--r--tests/auto/network/socket/qtcpsocket/test/test.pro23
-rw-r--r--tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp138
-rw-r--r--tests/auto/network/socket/qudpsocket/BLACKLIST11
-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/clientserver.pro5
-rw-r--r--tests/auto/network/socket/qudpsocket/clientserver/main.cpp29
-rw-r--r--tests/auto/network/socket/qudpsocket/qudpsocket.pro3
-rw-r--r--tests/auto/network/socket/qudpsocket/test/.prev_CMakeLists.txt33
-rw-r--r--tests/auto/network/socket/qudpsocket/test/CMakeLists.txt33
-rw-r--r--tests/auto/network/socket/qudpsocket/test/test.pro25
-rw-r--r--tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp359
-rw-r--r--tests/auto/network/socket/qudpsocket/udpServer/.prev_CMakeLists.txt12
-rw-r--r--tests/auto/network/socket/qudpsocket/udpServer/CMakeLists.txt7
-rw-r--r--tests/auto/network/socket/qudpsocket/udpServer/main.cpp29
-rw-r--r--tests/auto/network/socket/qudpsocket/udpServer/udpServer.pro3
-rw-r--r--tests/auto/network/socket/socket.pro22
68 files changed, 1265 insertions, 1347 deletions
diff --git a/tests/auto/network/socket/.prev_CMakeLists.txt b/tests/auto/network/socket/.prev_CMakeLists.txt
deleted file mode 100644
index 7e72b4be29..0000000000
--- a/tests/auto/network/socket/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-# Generated from socket.pro.
-
-if(QT_FEATURE_private_tests)
- add_subdirectory(qhttpsocketengine)
- add_subdirectory(qtcpsocket)
- add_subdirectory(qsocks5socketengine)
- add_subdirectory(platformsocketengine)
-endif()
-add_subdirectory(qudpsocket)
-add_subdirectory(qlocalsocket)
-add_subdirectory(qtcpserver)
-add_subdirectory(qabstractsocket)
-if(QT_FEATURE_sctp)
- add_subdirectory(qsctpsocket)
-endif()
diff --git a/tests/auto/network/socket/CMakeLists.txt b/tests/auto/network/socket/CMakeLists.txt
index 7e72b4be29..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)
@@ -7,9 +8,13 @@ if(QT_FEATURE_private_tests)
add_subdirectory(platformsocketengine)
endif()
add_subdirectory(qudpsocket)
-add_subdirectory(qlocalsocket)
-add_subdirectory(qtcpserver)
add_subdirectory(qabstractsocket)
+if(NOT ANDROID)
+ # QTBUG-87387
+ add_subdirectory(qlocalsocket)
+ # QTBUG-87388
+ add_subdirectory(qtcpserver)
+endif()
if(QT_FEATURE_sctp)
add_subdirectory(qsctpsocket)
endif()
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 21bc3e2c80..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,21 +18,16 @@ endif()
qt_internal_add_test(tst_platformsocketengine
SOURCES
tst_platformsocketengine.cpp
- INCLUDE_DIRECTORIES
- ${QT_SOURCE_TREE}/src/network
- 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/platformsocketengine.pri b/tests/auto/network/socket/platformsocketengine/platformsocketengine.pri
deleted file mode 100644
index 1b304bfc69..0000000000
--- a/tests/auto/network/socket/platformsocketengine/platformsocketengine.pri
+++ /dev/null
@@ -1,8 +0,0 @@
-QT += network
-
-QNETWORK_SRC = $$QT_SOURCE_TREE/src/network
-
-INCLUDEPATH += $$QNETWORK_SRC
-
-win32: QMAKE_USE += ws2_32
-
diff --git a/tests/auto/network/socket/platformsocketengine/platformsocketengine.pro b/tests/auto/network/socket/platformsocketengine/platformsocketengine.pro
deleted file mode 100644
index ab96bb444e..0000000000
--- a/tests/auto/network/socket/platformsocketengine/platformsocketengine.pro
+++ /dev/null
@@ -1,11 +0,0 @@
-CONFIG += testcase
-TARGET = tst_platformsocketengine
-SOURCES += tst_platformsocketengine.cpp
-
-include(../platformsocketengine/platformsocketengine.pri)
-
-requires(qtConfig(private_tests))
-
-MOC_DIR=tmp
-
-QT = core-private network-private testlib
diff --git a/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp b/tests/auto/network/socket/platformsocketengine/tst_platformsocketengine.cpp
index 88a39eea93..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));
@@ -324,7 +303,7 @@ void tst_PlatformSocketEngine::serverTest()
quint16 port = server.localPort();
// Listen for incoming connections
- QVERIFY(server.listen());
+ QVERIFY(server.listen(50));
QCOMPARE(server.state(), QAbstractSocket::ListeningState);
// Initialize a Tcp socket
@@ -429,7 +408,7 @@ void tst_PlatformSocketEngine::tcpLoopbackPerformance()
quint16 port = server.localPort();
// Listen for incoming connections
- QVERIFY(server.listen());
+ QVERIFY(server.listen(50));
QCOMPARE(server.state(), QAbstractSocket::ListeningState);
// Initialize a Tcp socket
@@ -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());
@@ -620,7 +599,7 @@ void tst_PlatformSocketEngine::receiveUrgentData()
QCOMPARE(server.state(), QAbstractSocket::BoundState);
quint16 port = server.localPort();
- QVERIFY(server.listen());
+ QVERIFY(server.listen(50));
QCOMPARE(server.state(), QAbstractSocket::ListeningState);
PLATFORMSOCKETENGINE client;
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/qabstractsocket.pro b/tests/auto/network/socket/qabstractsocket/qabstractsocket.pro
deleted file mode 100644
index 00e604972f..0000000000
--- a/tests/auto/network/socket/qabstractsocket/qabstractsocket.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-############################################################
-# Project file for autotest for file qabstractsocket.h
-############################################################
-
-CONFIG += testcase
-TARGET = tst_qabstractsocket
-QT = core network testlib
-
-SOURCES += tst_qabstractsocket.cpp
-
diff --git a/tests/auto/network/socket/qabstractsocket/tst_qabstractsocket.cpp b/tests/auto/network/socket/qabstractsocket/tst_qabstractsocket.cpp
index c306308b76..6b038acdfa 100644
--- a/tests/auto/network/socket/qabstractsocket/tst_qabstractsocket.cpp
+++ b/tests/auto/network/socket/qabstractsocket/tst_qabstractsocket.cpp
@@ -1,33 +1,8 @@
-/****************************************************************************
-**
-** 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/QtTest>
+#include <QTest>
#include <qcoreapplication.h>
#include <qdebug.h>
diff --git a/tests/auto/network/socket/qhttpsocketengine/.prev_CMakeLists.txt b/tests/auto/network/socket/qhttpsocketengine/.prev_CMakeLists.txt
deleted file mode 100644
index cb36b4c6e0..0000000000
--- a/tests/auto/network/socket/qhttpsocketengine/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,34 +0,0 @@
-# Generated from qhttpsocketengine.pro.
-
-if(NOT QT_FEATURE_private_tests)
- return()
-endif()
-
-#####################################################################
-## tst_qhttpsocketengine Test:
-#####################################################################
-
-qt_internal_add_test(tst_qhttpsocketengine
- SOURCES
- tst_qhttpsocketengine.cpp
- INCLUDE_DIRECTORIES
- ${QT_SOURCE_TREE}/src/network
- PUBLIC_LIBRARIES
- Qt::CorePrivate
- Qt::NetworkPrivate
-)
-
-#### 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
- ws2_32
-)
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 1d8e759f26..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,25 +18,18 @@ endif()
qt_internal_add_test(tst_qhttpsocketengine
SOURCES
tst_qhttpsocketengine.cpp
- INCLUDE_DIRECTORIES
- ${QT_SOURCE_TREE}/src/network
- 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/qhttpsocketengine.pro b/tests/auto/network/socket/qhttpsocketengine/qhttpsocketengine.pro
deleted file mode 100644
index 63f41f4eb7..0000000000
--- a/tests/auto/network/socket/qhttpsocketengine/qhttpsocketengine.pro
+++ /dev/null
@@ -1,17 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qhttpsocketengine
-SOURCES += tst_qhttpsocketengine.cpp
-
-
-include(../platformsocketengine/platformsocketengine.pri)
-
-MOC_DIR=tmp
-
-requires(qtConfig(private_tests))
-QT = core-private network-private testlib
-
-# TODO: For now linux-only, because cyrus is linux-only atm ...
-linux {
- CONFIG += unsupported/testserver
- QT_TEST_SERVER_LIST = squid danted cyrus apache2
-}
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
new file mode 100644
index 0000000000..730b7e6d2f
--- /dev/null
+++ b/tests/auto/network/socket/qlocalsocket/BLACKLIST
@@ -0,0 +1,10 @@
+# QTBUG-87387
+[fullPath]
+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 23f2b833e2..4b886a02ee 100644
--- a/tests/auto/network/socket/qlocalsocket/CMakeLists.txt
+++ b/tests/auto/network/socket/qlocalsocket/CMakeLists.txt
@@ -1,4 +1,12 @@
-# special case begin
+# 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(socketprocess)
qt_internal_add_test(tst_qlocalsocket
@@ -7,7 +15,8 @@ qt_internal_add_test(tst_qlocalsocket
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/qlocalsocket.pro b/tests/auto/network/socket/qlocalsocket/qlocalsocket.pro
deleted file mode 100644
index cbf5d160d9..0000000000
--- a/tests/auto/network/socket/qlocalsocket/qlocalsocket.pro
+++ /dev/null
@@ -1,2 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS = test 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/socketprocess/socketprocess.pro b/tests/auto/network/socket/qlocalsocket/socketprocess/socketprocess.pro
deleted file mode 100644
index e11ed5644b..0000000000
--- a/tests/auto/network/socket/qlocalsocket/socketprocess/socketprocess.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-QT = core network testlib
-
-DESTDIR = ./
-TARGET = socketprocess
-
-CONFIG += cmdline
-
-SOURCES += main.cpp
diff --git a/tests/auto/network/socket/qlocalsocket/test/test.pro b/tests/auto/network/socket/qlocalsocket/test/test.pro
deleted file mode 100644
index ab9ed90b1d..0000000000
--- a/tests/auto/network/socket/qlocalsocket/test/test.pro
+++ /dev/null
@@ -1,21 +0,0 @@
-CONFIG += testcase
-
-DEFINES += QLOCALSERVER_DEBUG
-DEFINES += QLOCALSOCKET_DEBUG
-DEFINES += SRCDIR=\\\"$$PWD/../\\\"
-
-QT = core network testlib
-
-SOURCES += ../tst_qlocalsocket.cpp
-
-TARGET = tst_qlocalsocket
-CONFIG(debug_and_release) {
- CONFIG(debug, debug|release) {
- DESTDIR = ../debug
- } else {
- DESTDIR = ../release
- }
-} else {
- DESTDIR = ..
-}
-
diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
index e481db6644..1ecd871ceb 100644
--- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
+++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp
@@ -1,38 +1,23 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// 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
+#include <QWaitCondition>
+#include <QLoggingCategory>
+#include <QMutex>
+#include <QList>
#include <qtextstream.h>
#include <qdatastream.h>
#include <qelapsedtimer.h>
+#include <qproperty.h>
#include <QtNetwork/qlocalsocket.h>
#include <QtNetwork/qlocalserver.h>
@@ -50,6 +35,7 @@
Q_DECLARE_METATYPE(QLocalSocket::LocalSocketError)
Q_DECLARE_METATYPE(QLocalSocket::LocalSocketState)
Q_DECLARE_METATYPE(QLocalServer::SocketOption)
+Q_DECLARE_METATYPE(QLocalSocket::SocketOption)
Q_DECLARE_METATYPE(QFile::Permissions)
class tst_QLocalSocket : public QObject
@@ -57,6 +43,7 @@ class tst_QLocalSocket : public QObject
Q_OBJECT
public:
+ using ByteArrayList = QList<QByteArray>;
tst_QLocalSocket();
private slots:
@@ -71,12 +58,24 @@ private slots:
void listenAndConnect_data();
void listenAndConnect();
+ void listenAndConnectAbstractNamespace_data();
+ void listenAndConnectAbstractNamespace();
+
+ void listenAndConnectAbstractNamespaceTrailingZeros_data();
+ void listenAndConnectAbstractNamespaceTrailingZeros();
+
void connectWithOpen();
void connectWithOldOpen();
void sendData_data();
void sendData();
+ void readLine_data();
+ void readLine();
+
+ void skip_data();
+ void skip();
+
void readBufferOverflow();
void simpleCommandProtocol1();
@@ -98,6 +97,8 @@ private slots:
void longPath();
void waitForDisconnect();
void waitForDisconnectByServer();
+ void waitForReadyReadOnDisconnected();
+ void delayedDisconnect();
void removeServer();
@@ -109,6 +110,7 @@ private slots:
void writeToClientAndDisconnect_data();
void writeToClientAndDisconnect();
+ void writeToDisconnected();
void debug();
void bytesWrittenSignal();
@@ -121,6 +123,11 @@ private slots:
void verifyListenWithDescriptor();
void verifyListenWithDescriptor_data();
+ void serverBindingsAndProperties();
+ void socketBindings();
+
+protected slots:
+ void socketClosedSlot();
};
tst_QLocalSocket::tst_QLocalSocket()
@@ -128,17 +135,17 @@ tst_QLocalSocket::tst_QLocalSocket()
qRegisterMetaType<QLocalSocket::LocalSocketState>("QLocalSocket::LocalSocketState");
qRegisterMetaType<QLocalSocket::LocalSocketError>("QLocalSocket::LocalSocketError");
qRegisterMetaType<QLocalServer::SocketOption>("QLocalServer::SocketOption");
+ qRegisterMetaType<QLocalServer::SocketOption>("QLocalSocket::SocketOption");
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)
@@ -147,10 +154,23 @@ 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:
- void incomingConnection(quintptr socketDescriptor)
+ void incomingConnection(quintptr socketDescriptor) override
{
hits.append(socketDescriptor);
QLocalServer::incomingConnection(socketDescriptor);
@@ -227,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()
@@ -269,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()
@@ -282,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
@@ -295,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);
@@ -303,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);
@@ -378,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);
@@ -397,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 {
@@ -418,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);
@@ -433,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);
}
@@ -451,16 +471,17 @@ 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()));
socket.setServerName("tst_qlocalsocket");
QVERIFY(socket.open());
@@ -474,6 +495,107 @@ void tst_QLocalSocket::connectWithOpen()
socket.close();
server.close();
+
+ QCOMPARE(spyAboutToClose.size(), 1);
+}
+
+void tst_QLocalSocket::listenAndConnectAbstractNamespaceTrailingZeros_data()
+{
+#ifdef Q_OS_LINUX
+ QTest::addColumn<bool>("server_0");
+ QTest::addColumn<bool>("client_0");
+ QTest::addColumn<bool>("success");
+ QTest::newRow("srv0_cli0") << true << true << true;
+ QTest::newRow("srv_cli0") << false << true << false;
+ QTest::newRow("srv0_cli") << true << false << false;
+ QTest::newRow("srv_cli") << false << false << true;
+#else
+ return;
+#endif
+}
+
+void tst_QLocalSocket::listenAndConnectAbstractNamespaceTrailingZeros()
+{
+#ifdef Q_OS_LINUX
+ QFETCH(bool, server_0);
+ QFETCH(bool, client_0);
+ QFETCH(bool, success);
+ bool expectedTimeOut = !success;
+ QString server_path("tst_qlocalsocket");
+ QString client_path("tst_qlocalsocket");
+
+ if (server_0)
+ server_path.append(QChar('\0'));
+ if (client_0)
+ client_path.append(QChar('\0'));
+ LocalServer server;
+ server.setSocketOptions(QLocalServer::AbstractNamespaceOption);
+ QVERIFY2(server.listen(server_path), qUtf8Printable(server.errorString()));
+ QCOMPARE(server.fullServerName(), server_path);
+
+ LocalSocket socket;
+ socket.setSocketOptions(QLocalSocket::AbstractNamespaceOption);
+ socket.setServerName(client_path);
+ QCOMPARE(socket.open(), success);
+ if (success)
+ QCOMPARE(socket.fullServerName(), client_path);
+ else
+ QVERIFY(socket.fullServerName().isEmpty());
+
+ bool timedOut = true;
+ QCOMPARE(server.waitForNewConnection(3000, &timedOut), success);
+
+#if defined(QT_LOCALSOCKET_TCP)
+ QTest::qWait(250);
+#endif
+ QCOMPARE(timedOut, expectedTimeOut);
+
+ socket.close();
+ server.close();
+#else
+ return;
+#endif
+}
+
+void tst_QLocalSocket::listenAndConnectAbstractNamespace_data()
+{
+ QTest::addColumn<QLocalServer::SocketOption>("serverOption");
+ QTest::addColumn<QLocalSocket::SocketOption>("socketOption");
+ QTest::addColumn<bool>("success");
+ QTest::newRow("abs_abs") << QLocalServer::AbstractNamespaceOption << QLocalSocket::AbstractNamespaceOption << true;
+ QTest::newRow("reg_reg") << QLocalServer::NoOptions << QLocalSocket::NoOptions << true;
+#ifdef Q_OS_LINUX
+ QTest::newRow("reg_abs") << QLocalServer::UserAccessOption << QLocalSocket::AbstractNamespaceOption << false;
+ QTest::newRow("abs_reg") << QLocalServer::AbstractNamespaceOption << QLocalSocket::NoOptions << false;
+#endif
+}
+
+void tst_QLocalSocket::listenAndConnectAbstractNamespace()
+{
+ QFETCH(QLocalServer::SocketOption, serverOption);
+ QFETCH(QLocalSocket::SocketOption, socketOption);
+ QFETCH(bool, success);
+ bool expectedTimeOut = !success;
+
+ LocalServer server;
+ server.setSocketOptions(serverOption);
+ QVERIFY2(server.listen("tst_qlocalsocket"), qUtf8Printable(server.errorString()));
+
+ LocalSocket socket;
+ socket.setSocketOptions(socketOption);
+ socket.setServerName("tst_qlocalsocket");
+ QCOMPARE(socket.open(), success);
+
+ bool timedOut = true;
+ QCOMPARE(server.waitForNewConnection(3000, &timedOut), success);
+
+#if defined(QT_LOCALSOCKET_TCP)
+ QTest::qWait(250);
+#endif
+ QCOMPARE(timedOut, expectedTimeOut);
+
+ socket.close();
+ server.close();
}
void tst_QLocalSocket::connectWithOldOpen()
@@ -540,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
@@ -566,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()));
@@ -577,16 +699,165 @@ 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()
+{
+ QTest::addColumn<ByteArrayList>("input");
+ QTest::addColumn<ByteArrayList>("output");
+ QTest::addColumn<int>("maxSize");
+ QTest::addColumn<bool>("wholeLinesOnly");
+
+ QTest::newRow("0") << ByteArrayList{ "\n", "A", "\n", "B", "B", "A", "\n" }
+ << ByteArrayList{ "\n", "", "", "A\n", "", "", "", "",
+ "BBA\n", "", "" }
+ << 80 << true;
+ QTest::newRow("1") << ByteArrayList{ "A", "\n", "\n", "B", "B", "\n", "A", "A" }
+ << ByteArrayList{ "", "A\n", "", "\n", "", "", "", "BB\n",
+ "", "", "", "AA", "" }
+ << 80 << true;
+
+ QTest::newRow("2") << ByteArrayList{ "\nA\nA\n" }
+ << ByteArrayList{ "\n", "A", "\n", "A", "\n", "", "" }
+ << 1 << false;
+ QTest::newRow("3") << ByteArrayList{ "A\n\n\nA", "A" }
+ << ByteArrayList{ "A\n", "\n", "\n", "A", "", "A", "", "" }
+ << 2 << false;
+
+ QTest::newRow("4") << ByteArrayList{ "He", "ll", "o\n", " \n", "wo", "rl", "d", "!\n" }
+ << ByteArrayList{ "", "Hel", "", "lo\n", "", " \n", "", "", "wor",
+ "", "", "ld!", "\n", "", "" }
+ << 3 << true;
+ QTest::newRow("5") << ByteArrayList{ "Hello\n world!" }
+ << ByteArrayList{ "Hello\n", "", " world!", "" }
+ << 80 << true;
+
+ QTest::newRow("6") << ByteArrayList{ "\nHello", " \n", " wor", "ld!\n" }
+ << ByteArrayList{ "\n", "Hell", "o", "", " \n", "", " wor", "",
+ "ld!\n", "", "" }
+ << 4 << false;
+ QTest::newRow("7") << ByteArrayList{ "Hello\n world", "!" }
+ << ByteArrayList{ "Hello\n", " world", "", "!", "", "" }
+ << 80 << false;
+}
+
+void tst_QLocalSocket::readLine()
+{
+ QFETCH(ByteArrayList, input);
+ QFETCH(ByteArrayList, output);
+ QFETCH(int, maxSize);
+ QFETCH(bool, wholeLinesOnly);
+
+ const QString serverName = QLatin1String("tst_localsocket");
+ LocalServer server;
+ QVERIFY2(server.listen(serverName), qUtf8Printable(server.errorString()));
+
+ LocalSocket client;
+ client.connectToServer(serverName);
+ QVERIFY(server.waitForNewConnection());
+ QLocalSocket *serverSocket = server.nextPendingConnection();
+ QVERIFY(serverSocket);
+ QCOMPARE(client.state(), QLocalSocket::ConnectedState);
+
+ ByteArrayList result;
+ qsizetype pos = 0;
+ do {
+ // This test assumes that such small chunks of data are synchronously
+ // delivered to the receiver on all supported platforms.
+ if (pos < input.size()) {
+ const QByteArray &chunk = input.at(pos);
+ QCOMPARE(serverSocket->write(chunk), qint64(chunk.size()));
+ QVERIFY(serverSocket->waitForBytesWritten());
+ QCOMPARE(serverSocket->bytesToWrite(), qint64(0));
+ QVERIFY(client.waitForReadyRead());
+ } else {
+ serverSocket->close();
+ QVERIFY(!client.waitForReadyRead());
+ }
+
+ while (!wholeLinesOnly || (client.bytesAvailable() >= qint64(maxSize))
+ || client.canReadLine() || (pos == input.size())) {
+ const bool chunkEmptied = (client.bytesAvailable() == 0);
+ QByteArray line(maxSize, Qt::Uninitialized);
+
+ const qint64 readResult = client.readLine(line.data(), maxSize + 1);
+ if (chunkEmptied) {
+ if (pos == input.size())
+ QCOMPARE(readResult, qint64(-1));
+ else
+ QCOMPARE(readResult, qint64(0));
+ break;
+ }
+ QVERIFY((readResult > 0) && (readResult <= maxSize));
+ line.resize(readResult);
+ result.append(line);
+ }
+ result.append(QByteArray());
+ } while (++pos <= input.size());
+ QCOMPARE(client.state(), QLocalSocket::UnconnectedState);
+ QCOMPARE(result, output);
+}
+
+void tst_QLocalSocket::skip_data()
+{
+ QTest::addColumn<QByteArray>("data");
+ QTest::addColumn<int>("read");
+ QTest::addColumn<int>("skip");
+ QTest::addColumn<int>("skipped");
+ QTest::addColumn<char>("expect");
+
+ QByteArray bigData;
+ bigData.fill('a', 20000);
+ bigData[10001] = 'x';
+
+ QTest::newRow("small_data") << QByteArray("abcdefghij") << 3 << 6 << 6 << 'j';
+ QTest::newRow("big_data") << bigData << 1 << 10000 << 10000 << 'x';
+ QTest::newRow("beyond_the_end") << bigData << 1 << 20000 << 19999 << '\0';
+}
+
+void tst_QLocalSocket::skip()
+{
+ QFETCH(QByteArray, data);
+ QFETCH(int, read);
+ QFETCH(int, skip);
+ QFETCH(int, skipped);
+ QFETCH(char, expect);
+ char lastChar = '\0';
+
+ const QString serverName = QLatin1String("tst_localsocket");
+ LocalServer server;
+ QVERIFY2(server.listen(serverName), qUtf8Printable(server.errorString()));
+
+ LocalSocket client;
+ client.connectToServer(serverName);
+ QVERIFY(server.waitForNewConnection());
+ QLocalSocket *serverSocket = server.nextPendingConnection();
+ QVERIFY(serverSocket);
+ QCOMPARE(client.state(), QLocalSocket::ConnectedState);
+
+ QCOMPARE(serverSocket->write(data), data.size());
+ while (serverSocket->waitForBytesWritten())
+ QVERIFY(client.waitForReadyRead());
+ QCOMPARE(serverSocket->bytesToWrite(), qint64(0));
+ serverSocket->close();
+ QVERIFY(client.waitForDisconnected());
+
+ for (int i = 0; i < read; ++i)
+ client.getChar(nullptr);
+
+ QCOMPARE(client.skip(skip), skipped);
+ client.getChar(&lastChar);
+ QCOMPARE(lastChar, expect);
}
void tst_QLocalSocket::readBufferOverflow()
@@ -632,26 +903,6 @@ void tst_QLocalSocket::readBufferOverflow()
QCOMPARE(client.read(buffer, readBufferSize), qint64(readBufferSize));
// no more bytes available
QCOMPARE(client.bytesAvailable(), 0);
-
-#ifdef Q_OS_WIN
- serverSocket->write(buffer, readBufferSize);
- QVERIFY(serverSocket->waitForBytesWritten());
-
- // ensure the read completion routine is called
- SleepEx(100, true);
- QVERIFY(client.waitForReadyRead());
- QCOMPARE(client.read(buffer, readBufferSize), qint64(readBufferSize));
-
- // Test overflow caused by an asynchronous pipe operation.
- client.setReadBufferSize(1);
- serverSocket->write(buffer, 2);
-
- QVERIFY(client.waitForReadyRead());
- // socket disconnects, if there any error on pipe
- QCOMPARE(client.state(), QLocalSocket::ConnectedState);
- QCOMPARE(client.bytesAvailable(), qint64(2));
- QCOMPARE(client.read(buffer, 2), qint64(2));
-#endif
}
static qint64 writeCommand(const QVariant &command, QIODevice *device, int commandCounter)
@@ -684,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;
@@ -710,10 +961,11 @@ void tst_QLocalSocket::simpleCommandProtocol1()
void tst_QLocalSocket::simpleCommandProtocol2()
{
- QLocalServer server;
+ CrashSafeLocalServer server;
server.listen(QStringLiteral("simpleProtocol"));
QLocalSocket localSocketWrite;
+ QSignalSpy spyDisconnected(&localSocketWrite, SIGNAL(disconnected()));
localSocketWrite.connectToServer(server.serverName());
QVERIFY(server.waitForNewConnection());
QLocalSocket* localSocketRead = server.nextPendingConnection();
@@ -755,13 +1007,18 @@ void tst_QLocalSocket::simpleCommandProtocol2()
}
localSocketWrite.abort();
+ QCOMPARE(localSocketWrite.state(), QLocalSocket::UnconnectedState);
+ QCOMPARE(spyDisconnected.size(), 1);
+ QCOMPARE(localSocketWrite.bytesToWrite(), 0);
+ QVERIFY(!localSocketWrite.isOpen());
+
QVERIFY(localSocketRead->waitForDisconnected(1000));
}
// 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";
@@ -771,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);
@@ -802,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) {
@@ -813,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());
}
@@ -832,7 +1089,7 @@ class Client : public QThread
{
public:
- void run()
+ void run() override
{
QString testLine = "test";
LocalSocket socket;
@@ -841,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();
@@ -857,13 +1114,13 @@ public:
int clients;
QMutex mutex;
QWaitCondition wc;
- void run()
+ void run() override
{
QString testLine = "test";
LocalServer server;
server.setMaxPendingConnections(10);
QVERIFY2(server.listen("qlocalsocket_threadtest"),
- server.errorString().toLatin1().constData());
+ qUtf8Printable(server.errorString()));
mutex.lock();
wc.wakeAll();
mutex.unlock();
@@ -885,7 +1142,7 @@ public:
--done;
delete serverSocket;
}
- QCOMPARE(server.hits.count(), clients);
+ QCOMPARE(server.hits.size(), clients);
}
};
@@ -1024,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));
@@ -1042,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());
@@ -1054,15 +1311,81 @@ 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;
+ QVERIFY2(server.listen(name), qUtf8Printable(server.errorString()));
+ LocalSocket socket;
+ connect(&socket, &QLocalSocket::readyRead, [&socket]() {
+ QVERIFY(socket.getChar(nullptr));
+ // The next call should not block because the socket was closed
+ // by the peer.
+ QVERIFY(!socket.waitForReadyRead(3000));
+ });
+
+ socket.connectToServer(name);
+ QVERIFY(socket.waitForConnected(3000));
+ QVERIFY(server.waitForNewConnection(3000));
+ QLocalSocket *serverSocket = server.nextPendingConnection();
+ QVERIFY(serverSocket);
+ QVERIFY(serverSocket->putChar(0));
+ QVERIFY(serverSocket->waitForBytesWritten(3000));
+ serverSocket->close();
+
+#ifdef Q_OS_WIN
+ // Ensure that the asynchronously delivered close notification is
+ // already queued up before we consume the data.
+ QTest::qSleep(250);
+#endif
+
+ QElapsedTimer timer;
+ timer.start();
+ QVERIFY(socket.waitForReadyRead(5000));
+ QVERIFY(timer.elapsed() < 2000);
+}
+
+void tst_QLocalSocket::delayedDisconnect()
+{
+ QString name = "tst_localsocket";
+ LocalServer server;
+ QVERIFY2(server.listen(name), qUtf8Printable(server.errorString()));
+ LocalSocket socket;
+ socket.connectToServer(name);
+ QVERIFY(socket.waitForConnected(3000));
+ QVERIFY(server.waitForNewConnection(3000));
+ QLocalSocket *serverSocket = server.nextPendingConnection();
+ QVERIFY(serverSocket);
+ connect(serverSocket, &QLocalSocket::aboutToClose, [serverSocket]() {
+ QVERIFY(serverSocket->isOpen());
+ QCOMPARE(serverSocket->bytesAvailable(), qint64(1));
+ });
+
+ QVERIFY(socket.putChar(0));
+ socket.disconnectFromServer();
+ QCOMPARE(socket.state(), QLocalSocket::ClosingState);
+ QVERIFY(socket.waitForDisconnected(3000));
+ QCOMPARE(socket.state(), QLocalSocket::UnconnectedState);
+ QVERIFY(socket.isOpen());
+
+ QVERIFY(serverSocket->waitForReadyRead(3000));
+ serverSocket->close();
+ QCOMPARE(serverSocket->state(), QLocalSocket::UnconnectedState);
+ QVERIFY(!serverSocket->isOpen());
+ QCOMPARE(serverSocket->bytesAvailable(), qint64(0));
}
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
@@ -1074,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));
@@ -1087,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));
@@ -1099,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);
@@ -1124,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");
@@ -1149,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);
@@ -1161,6 +1484,13 @@ void tst_QLocalSocket::writeOnlySocket()
QCOMPARE(client.bytesAvailable(), qint64(0));
QCOMPARE(client.state(), QLocalSocket::ConnectedState);
+
+ serverSocket->abort();
+ // On Windows, we need to test that the socket state is periodically
+ // checked in a loop, even if no timeout value is specified (i.e.
+ // waitForDisconnected(-1) does not fail immediately).
+ QVERIFY(client.waitForDisconnected(-1));
+ QCOMPARE(client.state(), QLocalSocket::UnconnectedState);
}
void tst_QLocalSocket::writeToClientAndDisconnect_data()
@@ -1173,33 +1503,60 @@ 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));
QLocalSocket* clientSocket = server.nextPendingConnection();
QVERIFY(clientSocket);
+ server.close();
char buffer[100];
memset(buffer, 0, sizeof(buffer));
for (int i = 0; i < chunks; ++i)
QCOMPARE(clientSocket->write(buffer, sizeof(buffer)), qint64(sizeof(buffer)));
- while (clientSocket->bytesToWrite())
- QVERIFY(clientSocket->waitForBytesWritten());
clientSocket->close();
- server.close();
+ QVERIFY(clientSocket->waitForDisconnected());
- client.waitForDisconnected();
- QCOMPARE(readChannelFinishedSpy.count(), 1);
+ QVERIFY(client.waitForDisconnected());
+ QCOMPARE(readChannelFinishedSpy.size(), 1);
const QByteArray received = client.readAll();
QCOMPARE(received.size(), qint64(sizeof(buffer) * chunks));
QCOMPARE(client.state(), QLocalSocket::UnconnectedState);
}
+void tst_QLocalSocket::writeToDisconnected()
+{
+ CrashSafeLocalServer server;
+ QVERIFY2(server.listen("writeToDisconnected"), qUtf8Printable(server.errorString()));
+
+ QLocalSocket client;
+ QSignalSpy spyError(&client, SIGNAL(errorOccurred(QLocalSocket::LocalSocketError)));
+ client.connectToServer("writeToDisconnected");
+ QVERIFY(client.waitForConnected(3000));
+ QVERIFY(server.waitForNewConnection(3000));
+ QLocalSocket *serverSocket = server.nextPendingConnection();
+ QVERIFY(serverSocket);
+ serverSocket->abort();
+
+ QCOMPARE(client.state(), QLocalSocket::ConnectedState);
+ QVERIFY(client.putChar(0));
+
+#ifdef Q_OS_WIN
+ // Ensure the asynchronous write operation is finished.
+ QTest::qSleep(250);
+#endif
+
+ QCOMPARE(client.bytesToWrite(), qint64(1));
+ QVERIFY(!client.waitForBytesWritten());
+ QCOMPARE(spyError.size(), 1);
+ QCOMPARE(client.state(), QLocalSocket::UnconnectedState);
+}
+
void tst_QLocalSocket::debug()
{
// Make sure this compiles
@@ -1212,7 +1569,8 @@ class WriteThread : public QThread
{
Q_OBJECT
public:
- void run() {
+ void run() override
+ {
QLocalSocket socket;
socket.connectToServer("qlocalsocket_readyread");
@@ -1244,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();
@@ -1256,11 +1614,23 @@ void tst_QLocalSocket::bytesWrittenSignal()
QVERIFY(writeThread.wait(2000));
}
+void tst_QLocalSocket::socketClosedSlot()
+{
+ QLocalSocket *socket = qobject_cast<QLocalSocket *>(sender());
+
+ QCOMPARE(socket->state(), QLocalSocket::UnconnectedState);
+}
+
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);
+ connect(&client, &QIODevice::readChannelFinished,
+ this, &tst_QLocalSocket::socketClosedSlot);
+
client.connectToServer("syncDisconnectNotify");
QVERIFY(server.waitForNewConnection());
QLocalSocket* serverSocket = server.nextPendingConnection();
@@ -1272,16 +1642,23 @@ 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()));
+ connect(&client, &QLocalSocket::disconnected,
+ this, &tst_QLocalSocket::socketClosedSlot);
+ connect(&client, &QIODevice::readChannelFinished,
+ this, &tst_QLocalSocket::socketClosedSlot);
+
client.connectToServer("asyncDisconnectNotify");
QVERIFY(server.waitForNewConnection());
QLocalSocket* serverSocket = server.nextPendingConnection();
QVERIFY(serverSocket);
delete serverSocket;
QTRY_VERIFY(!disconnectedSpy.isEmpty());
+ QCOMPARE(readChannelFinishedSpy.size(), 1);
}
void tst_QLocalSocket::verifySocketOptions_data()
@@ -1312,16 +1689,14 @@ void tst_QLocalSocket::verifySocketOptions_data()
void tst_QLocalSocket::verifySocketOptions()
{
// These are only guaranteed to be useful on linux at this time
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) && !defined(Q_OS_WEBOS)
QFETCH(QString, service);
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());
@@ -1334,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);
@@ -1343,15 +1718,15 @@ void tst_QLocalSocket::verifyListenWithDescriptor()
int listenSocket;
+ // Construct the unix address
+ struct ::sockaddr_un addr;
+ addr.sun_family = PF_UNIX;
+
if (bound) {
// create the unix socket
listenSocket = ::socket(PF_UNIX, SOCK_STREAM, 0);
QVERIFY2(listenSocket != -1, "failed to create test socket");
- // Construct the unix address
- struct ::sockaddr_un addr;
- addr.sun_family = PF_UNIX;
-
QVERIFY2(sizeof(addr.sun_path) > ((uint)path.size() + 1), "path to large to create socket");
::memset(addr.sun_path, 0, sizeof(addr.sun_path));
@@ -1376,16 +1751,16 @@ 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
- const QChar at(QLatin1Char('@'));
+#if defined(Q_OS_LINUX) || defined(Q_OS_QNX)
if (!bound) {
- QCOMPARE(server.serverName().at(0), at);
- QCOMPARE(server.fullServerName().at(0), at);
+ QCOMPARE(server.serverName().isEmpty(), true);
+ QCOMPARE(server.fullServerName().isEmpty(), true);
} else if (abstract) {
- QVERIFY2(server.fullServerName().at(0) == at, "abstract sockets should start with a '@'");
+ QVERIFY2(server.fullServerName().at(0) == addr.sun_path[1],
+ "abstract sockets should match server path without leading null");
} else {
QCOMPARE(server.fullServerName(), path);
if (path.contains(QLatin1Char('/'))) {
@@ -1395,8 +1770,17 @@ void tst_QLocalSocket::verifyListenWithDescriptor()
}
}
#else
- QVERIFY(server.serverName().isEmpty());
- QVERIFY(server.fullServerName().isEmpty());
+ if (bound) {
+ QCOMPARE(server.fullServerName(), path);
+ if (path.contains(QLatin1Char('/'))) {
+ QVERIFY2(server.serverName() == path.mid(path.lastIndexOf(QLatin1Char('/'))+1), "server name invalid short name");
+ } else {
+ QVERIFY2(server.serverName() == path, "server name doesn't match the path provided");
+ }
+ } else {
+ QVERIFY(server.serverName().isEmpty());
+ QVERIFY(server.fullServerName().isEmpty());
+ }
#endif
@@ -1411,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
@@ -1421,6 +1805,24 @@ void tst_QLocalSocket::verifyListenWithDescriptor_data()
}
+void tst_QLocalSocket::serverBindingsAndProperties()
+{
+ CrashSafeLocalServer server;
+
+ QTestPrivate::testReadWritePropertyBasics(
+ server, QLocalServer::SocketOptions{QLocalServer::GroupAccessOption},
+ QLocalServer::SocketOptions{QLocalServer::OtherAccessOption}, "socketOptions");
+}
+
+void tst_QLocalSocket::socketBindings()
+{
+ QLocalSocket socket;
+
+ QTestPrivate::testReadWritePropertyBasics(
+ socket, QLocalSocket::SocketOptions{QLocalSocket::AbstractNamespaceOption},
+ QLocalSocket::SocketOptions{QLocalSocket::NoOptions}, "socketOptions");
+}
+
QTEST_MAIN(tst_QLocalSocket)
#include "tst_qlocalsocket.moc"
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/qsctpsocket.pro b/tests/auto/network/socket/qsctpsocket/qsctpsocket.pro
deleted file mode 100644
index 49a40ce9b5..0000000000
--- a/tests/auto/network/socket/qsctpsocket/qsctpsocket.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qsctpsocket
-QT = core network testlib
-
-SOURCES += tst_qsctpsocket.cpp
-
diff --git a/tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp b/tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp
index 89a1430948..2893053158 100644
--- a/tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp
+++ b/tests/auto/network/socket/qsctpsocket/tst_qsctpsocket.cpp
@@ -1,34 +1,9 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include <QtTest/QtTest>
+// Copyright (C) 2016 Alex Trotsenko <alex1973tr@gmail.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QTest>
#include <QDebug>
-#include <QEventLoop>
+#include <QTestEventLoop>
#include <QByteArray>
#include <QString>
#include <QHostAddress>
@@ -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/.prev_CMakeLists.txt b/tests/auto/network/socket/qsocks5socketengine/.prev_CMakeLists.txt
deleted file mode 100644
index 851e81a40d..0000000000
--- a/tests/auto/network/socket/qsocks5socketengine/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,34 +0,0 @@
-# Generated from qsocks5socketengine.pro.
-
-if(NOT QT_FEATURE_private_tests)
- return()
-endif()
-
-#####################################################################
-## tst_qsocks5socketengine Test:
-#####################################################################
-
-qt_internal_add_test(tst_qsocks5socketengine
- SOURCES
- tst_qsocks5socketengine.cpp
- INCLUDE_DIRECTORIES
- ${QT_SOURCE_TREE}/src/network
- PUBLIC_LIBRARIES
- Qt::CorePrivate
- Qt::NetworkPrivate
-)
-
-#### 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
- ws2_32
-)
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 47c7698f94..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,25 +18,18 @@ endif()
qt_internal_add_test(tst_qsocks5socketengine
SOURCES
tst_qsocks5socketengine.cpp
- INCLUDE_DIRECTORIES
- ${QT_SOURCE_TREE}/src/network
- 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/qsocks5socketengine.pro b/tests/auto/network/socket/qsocks5socketengine/qsocks5socketengine.pro
deleted file mode 100644
index 243eab9480..0000000000
--- a/tests/auto/network/socket/qsocks5socketengine/qsocks5socketengine.pro
+++ /dev/null
@@ -1,19 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qsocks5socketengine
-SOURCES += tst_qsocks5socketengine.cpp
-
-
-include(../platformsocketengine/platformsocketengine.pri)
-
-
-MOC_DIR=tmp
-
-QT = core-private network-private testlib
-
-requires(qtConfig(private_tests))
-
-# Only on Linux until cyrus has been added to docker-compose-for-{windows,macOS}.yml and tested
-linux {
- CONFIG += unsupported/testserver
- QT_TEST_SERVER_LIST = danted apache2 cyrus
-}
diff --git a/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp b/tests/auto/network/socket/qsocks5socketengine/tst_qsocks5socketengine.cpp
index f0cff5da3e..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
@@ -312,12 +289,15 @@ void tst_QSocks5SocketEngine::simpleConnectToIMAP()
QCOMPARE(socketDevice.state(), QAbstractSocket::ConnectedState);
QCOMPARE(socketDevice.peerAddress(), QtNetworkSettings::imapServerIp());
- // Wait for the greeting
- QVERIFY2(socketDevice.waitForRead(), qPrintable("Socket error:" + socketDevice.errorString()));
-
- // Read the greeting
+ // Wait for the greeting, if it hasn't arrived yet
qint64 available = socketDevice.bytesAvailable();
+ if (available == 0) {
+ QVERIFY2(socketDevice.waitForRead(), qPrintable("Socket error:" + socketDevice.errorString()));
+ available = socketDevice.bytesAvailable();
+ }
QVERIFY(available > 0);
+
+ // Read the greeting
QByteArray array;
array.resize(available);
QVERIFY(socketDevice.read(array.data(), array.size()) == available);
@@ -363,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 {
@@ -453,7 +433,7 @@ void tst_QSocks5SocketEngine::serverTest()
QCOMPARE(server.state(), QAbstractSocket::BoundState);
// Listen for incoming connections
- QVERIFY(server.listen());
+ QVERIFY(server.listen(50));
QCOMPARE(server.state(), QAbstractSocket::ListeningState);
// Initialize a Tcp socket
@@ -937,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;
@@ -986,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 e268468bdb..a8b5f5d137 100644
--- a/tests/auto/network/socket/qtcpserver/BLACKLIST
+++ b/tests/auto/network/socket/qtcpserver/BLACKLIST
@@ -1,16 +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/crashingServer.pro b/tests/auto/network/socket/qtcpserver/crashingServer/crashingServer.pro
deleted file mode 100644
index 487b9014d0..0000000000
--- a/tests/auto/network/socket/qtcpserver/crashingServer/crashingServer.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-SOURCES += main.cpp
-QT = core network
-CONFIG -= app_bundle
-DESTDIR = ./
-
-# This means the auto test works on some machines for MinGW. No dialog stalls
-# the application.
-mingw:CONFIG += console
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/qtcpserver.pro b/tests/auto/network/socket/qtcpserver/qtcpserver.pro
deleted file mode 100644
index e123cfe73b..0000000000
--- a/tests/auto/network/socket/qtcpserver/qtcpserver.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS = test crashingServer
-
-
diff --git a/tests/auto/network/socket/qtcpserver/test/.prev_CMakeLists.txt b/tests/auto/network/socket/qtcpserver/test/.prev_CMakeLists.txt
deleted file mode 100644
index f842fda311..0000000000
--- a/tests/auto/network/socket/qtcpserver/test/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-# Generated from test.pro.
-
-#####################################################################
-## tst_qtcpserver Test:
-#####################################################################
-
-qt_internal_add_test(tst_qtcpserver
- SOURCES
- ../tst_qtcpserver.cpp
- PUBLIC_LIBRARIES
- Qt::Network
-)
-
-#### Keys ignored in scope 1:.:.:test.pro:<TRUE>:
-# MOC_DIR = "tmp"
-
-## Scopes:
-#####################################################################
-
-qt_internal_extend_target(tst_qtcpserver CONDITION WIN32
- PUBLIC_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/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/test/test.pro b/tests/auto/network/socket/qtcpserver/test/test.pro
deleted file mode 100644
index 491ff28cdc..0000000000
--- a/tests/auto/network/socket/qtcpserver/test/test.pro
+++ /dev/null
@@ -1,24 +0,0 @@
-CONFIG += testcase
-SOURCES += ../tst_qtcpserver.cpp
-
-win32: QMAKE_USE += ws2_32
-
-TARGET = tst_qtcpserver
-
-win32 {
- CONFIG(debug, debug|release) {
- TARGET = ../debug/tst_qtcpserver
-} else {
- TARGET = ../release/tst_qtcpserver
- }
-}
-
-QT = core network testlib
-
-MOC_DIR=tmp
-
-# Only on Linux until cyrus has been added to docker-compose-for-{windows,macOS}.yml and tested
-linux {
- CONFIG += unsupported/testserver
- 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 1bf6777040..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
@@ -38,7 +11,9 @@
#define INVALID_SOCKET -1
#endif
-#include <QtTest/QtTest>
+#include <QTest>
+#include <QSignalSpy>
+#include <QTimer>
#ifndef Q_OS_WIN
#include <unistd.h>
@@ -58,6 +33,8 @@
#include <qnetworkinterface.h>
#include <QNetworkProxy>
+#include <QSet>
+#include <QList>
#include "../../../network-settings.h"
@@ -113,6 +90,11 @@ private slots:
void canAccessPendingConnectionsWhileNotListening();
+ void pauseAccepting();
+
+ void pendingConnectionAvailable_data();
+ void pendingConnectionAvailable();
+
private:
bool shouldSkipIpv6TestsForBrokenGetsockopt();
#ifdef SHOULD_CHECK_SYSCALL_SUPPORT
@@ -156,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())
@@ -264,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);
@@ -425,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());
@@ -476,7 +459,7 @@ public:
protected:
void run() override
{
- sleep(2);
+ sleep(std::chrono::seconds{2});
QTcpSocket socket;
socket.connectToHost(host, port);
@@ -594,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
@@ -607,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));
@@ -624,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
}
@@ -744,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)
@@ -751,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();
@@ -765,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")
@@ -777,6 +770,7 @@ void tst_QTcpServer::proxyFactory_data()
QTest::newRow("ftp+cachinghttp")
<< proxyList << QNetworkProxy()
<< true << int(QAbstractSocket::UnsupportedSocketOperationError);
+#endif
}
void tst_QTcpServer::proxyFactory()
@@ -871,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();
}
}
@@ -928,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) {
@@ -941,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;
@@ -961,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
@@ -969,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);
@@ -984,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();
@@ -1019,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();
}
@@ -1046,5 +1050,104 @@ void tst_QTcpServer::canAccessPendingConnectionsWhileNotListening()
QCOMPARE(&socket, server.nextPendingConnection());
}
+void tst_QTcpServer::pauseAccepting()
+{
+ QTcpServer server;
+ QSignalSpy spy(&server, &QTcpServer::newConnection);
+ QVERIFY(server.listen());
+
+ QFETCH_GLOBAL(bool, setProxy);
+ const auto address = QHostAddress(setProxy ? QtNetworkSettings::socksProxyServerIp()
+ : QHostAddress::LocalHost);
+
+ const int NumSockets = 6;
+ QTcpSocket sockets[NumSockets];
+ sockets[0].connectToHost(address, server.serverPort());
+ QVERIFY(spy.wait());
+ 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.size(), 1);
+
+ server.resumeAccepting();
+ if (setProxy) {
+ QEXPECT_FAIL("", "The socks proxy does weird things after accepting the first connection",
+ Abort);
+ }
+ QVERIFY(spy.wait());
+ 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)
#include "tst_qtcpserver.moc"
diff --git a/tests/auto/network/socket/qtcpsocket/BLACKLIST b/tests/auto/network/socket/qtcpsocket/BLACKLIST
index d90171934f..6261c85a09 100644
--- a/tests/auto/network/socket/qtcpsocket/BLACKLIST
+++ b/tests/auto/network/socket/qtcpsocket/BLACKLIST
@@ -1,8 +1,25 @@
[timeoutConnect:ip]
windows
+# 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
-[connectToHostError]
-windows-10 gcc developer-build
[delayedClose:WithSocks5Proxy]
windows-10 gcc developer-build
[delayedClose:WithSocks5Proxy SSL]
@@ -51,3 +68,10 @@ windows-10 gcc developer-build
windows-10 gcc developer-build
[connectToHostError:WithHttpProxyBasicAuth SSL:localhost no service]
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/qtcpsocket.pro b/tests/auto/network/socket/qtcpsocket/qtcpsocket.pro
deleted file mode 100644
index 1f13a396dd..0000000000
--- a/tests/auto/network/socket/qtcpsocket/qtcpsocket.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-TEMPLATE = subdirs
-
-SUBDIRS = test
-!vxworks{
-SUBDIRS += stressTest
-test.depends = stressTest
-}
-requires(qtConfig(private_tests))
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/stressTest/stressTest.pro b/tests/auto/network/socket/qtcpsocket/stressTest/stressTest.pro
deleted file mode 100644
index 6afc008e7d..0000000000
--- a/tests/auto/network/socket/qtcpsocket/stressTest/stressTest.pro
+++ /dev/null
@@ -1,8 +0,0 @@
-HEADERS += Test.h
-SOURCES += main.cpp Test.cpp
-QT = core network testlib
-
-CONFIG += cmdline
-DESTDIR = ./
-MOC_DIR = .moc/
-TMP_DIR = .tmp/
diff --git a/tests/auto/network/socket/qtcpsocket/test/.prev_CMakeLists.txt b/tests/auto/network/socket/qtcpsocket/test/.prev_CMakeLists.txt
deleted file mode 100644
index e27383cf94..0000000000
--- a/tests/auto/network/socket/qtcpsocket/test/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-# Generated from test.pro.
-
-#####################################################################
-## tst_qtcpsocket Test:
-#####################################################################
-
-qt_internal_add_test(tst_qtcpsocket
- SOURCES
- ../tst_qtcpsocket.cpp
- PUBLIC_LIBRARIES
- Qt::CorePrivate
- Qt::NetworkPrivate
-)
-
-## Scopes:
-#####################################################################
-
-qt_internal_extend_target(tst_qtcpsocket CONDITION WIN32
- PUBLIC_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/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/test/test.pro b/tests/auto/network/socket/qtcpsocket/test/test.pro
deleted file mode 100644
index 4c07b1ec66..0000000000
--- a/tests/auto/network/socket/qtcpsocket/test/test.pro
+++ /dev/null
@@ -1,23 +0,0 @@
-CONFIG += testcase
-
-QT = core-private network-private testlib
-SOURCES += ../tst_qtcpsocket.cpp
-
-win32: QMAKE_USE += ws2_32
-TARGET = tst_qtcpsocket
-
-win32 {
- CONFIG(debug, debug|release) {
- DESTDIR = ../debug
-} else {
- DESTDIR = ../release
- }
-} else {
- DESTDIR = ../
-}
-
-# Only on Linux until cyrus has been added to docker-compose-for-{windows,macOS}.yml and tested
-linux {
- CONFIG += unsupported/testserver
- 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 0608fa8e63..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
@@ -44,8 +17,8 @@
#include <qplatformdefs.h>
-#include <QtTest/QtTest>
-
+#include <QTest>
+#include <QSignalSpy>
#include <QAuthenticator>
#include <QCoreApplication>
#include <QEventLoop>
@@ -87,6 +60,8 @@
#include "../../../network-settings.h"
+using namespace Qt::StringLiterals;
+
QT_FORWARD_DECLARE_CLASS(QTcpSocket)
class SocketPair;
@@ -308,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;
@@ -357,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");
@@ -372,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;
@@ -513,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.
@@ -548,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!)
@@ -588,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;
@@ -1806,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;
}
@@ -1848,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));
@@ -2031,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;
@@ -2090,31 +2067,50 @@ void tst_QTcpSocket::nestedEventLoopInErrorSlot()
void tst_QTcpSocket::connectToHostError_data()
{
QTest::addColumn<QString>("host");
- QTest::addColumn<int>("port");
+ QTest::addColumn<quint16>("port");
QTest::addColumn<QAbstractSocket::SocketError>("expectedError");
- QTest::newRow("localhost no service") << QStringLiteral("localhost") << 31415 << QAbstractSocket::ConnectionRefusedError;
- QTest::newRow("unreachable") << QStringLiteral("0.0.0.1") << 65000 << QAbstractSocket::NetworkError;
+ QTest::newRow("localhost no service") << QStringLiteral("localhost") << quint16(31415) << QAbstractSocket::ConnectionRefusedError;
+ QTest::newRow("unreachable") << QStringLiteral("0.0.0.1") << quint16(65000) << QAbstractSocket::NetworkError;
}
void tst_QTcpSocket::connectToHostError()
{
+ // We are aware of at least one OS in our CI, that would fail
+ // the test due to timeout - it's Ubuntu 20.04 and 'connect'
+ // to 0.0.0.1 there return EINPROGRESS, with no other error
+ // ever received, so only our own internal 30 s. timer can
+ // detect a connection timeout.
+
std::unique_ptr<QTcpSocket> socket(newSocket());
QAbstractSocket::SocketError error = QAbstractSocket::UnknownSocketError;
- QFETCH(QString, host);
- QFETCH(int, port);
+ QFETCH(const QString, host);
+ QFETCH(const quint16, port);
QFETCH(QAbstractSocket::SocketError, expectedError);
- connect(socket.get(), &QAbstractSocket::errorOccurred, [&](QAbstractSocket::SocketError socketError){
+ QTestEventLoop eventLoop;
+ connect(socket.get(), &QAbstractSocket::errorOccurred, socket.get(),
+ [&](QAbstractSocket::SocketError socketError) {
error = socketError;
+ QTimer::singleShot(0, &eventLoop, [&]{eventLoop.exitLoop();});
});
- socket->connectToHost(host, port); // no service running here, one suspects
- QTRY_COMPARE_WITH_TIMEOUT(socket->state(), QTcpSocket::UnconnectedState, 7000);
+
+ socket->connectToHost(host, port);
+ eventLoop.enterLoopMSecs(10'000);
+ if (eventLoop.timeout()) {
+ // Let's at least verify it's not in connected state:
+ QVERIFY(socket->state() != QAbstractSocket::ConnectedState);
+ QSKIP("Connection to unreachable host timed out, skipping the rest of the test");
+ }
+
+ QCOMPARE(socket->state(), QTcpSocket::UnconnectedState);
+
if (error != expectedError && error == QAbstractSocket::ConnectionRefusedError)
QEXPECT_FAIL("unreachable", "CI firewall interfers with this test", Continue);
+
QCOMPARE(error, expectedError);
}
@@ -2144,7 +2140,7 @@ void tst_QTcpSocket::waitForConnectedInHostLookupSlot()
if (tmpSocket->state() != QAbstractSocket::ConnectedState)
loop.exec();
- QCOMPARE(timerSpy.count(), 0);
+ QCOMPARE(timerSpy.size(), 0);
delete tmpSocket;
}
@@ -2198,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;
@@ -2249,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());
@@ -2257,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;
}
@@ -2331,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));
@@ -2451,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;
}
@@ -2587,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));
@@ -2918,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)
@@ -2925,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();
@@ -2933,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")
@@ -2945,6 +2944,7 @@ void tst_QTcpSocket::proxyFactory_data()
QTest::newRow("ftp+cachinghttp")
<< proxyList << QNetworkProxy()
<< true << int(QAbstractSocket::UnsupportedSocketOperationError);
+#endif
}
void tst_QTcpSocket::proxyFactory()
@@ -3124,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);
@@ -3214,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 0058bb91a6..f5f6a8e156 100644
--- a/tests/auto/network/socket/qudpsocket/BLACKLIST
+++ b/tests/auto/network/socket/qudpsocket/BLACKLIST
@@ -1,10 +1,9 @@
[writeDatagramToNonExistingPeer]
windows
-# QTBUG-85364
-windows-10 gcc cmake
[readyReadForEmptyDatagram]
opensuse-leap
-[echo]
-opensuse-42.3
-[readyReadForEmptyDatagram]
-linux
+[multicast]
+centos
+macos arm
+[linkLocalIPv6]
+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/clientserver.pro b/tests/auto/network/socket/qudpsocket/clientserver/clientserver.pro
deleted file mode 100644
index 83a31b11e9..0000000000
--- a/tests/auto/network/socket/qudpsocket/clientserver/clientserver.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-QT = core network
-SOURCES += main.cpp
-CONFIG += cmdline
-TARGET = clientserver
-DESTDIR = ./
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/qudpsocket.pro b/tests/auto/network/socket/qudpsocket/qudpsocket.pro
deleted file mode 100644
index b267d5f249..0000000000
--- a/tests/auto/network/socket/qudpsocket/qudpsocket.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS = test clientserver
-test.depends = clientserver
diff --git a/tests/auto/network/socket/qudpsocket/test/.prev_CMakeLists.txt b/tests/auto/network/socket/qudpsocket/test/.prev_CMakeLists.txt
deleted file mode 100644
index 2ef2d8a796..0000000000
--- a/tests/auto/network/socket/qudpsocket/test/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-# Generated from test.pro.
-
-#####################################################################
-## tst_qudpsocket Test:
-#####################################################################
-
-qt_internal_add_test(tst_qudpsocket
- SOURCES
- ../tst_qudpsocket.cpp
- INCLUDE_DIRECTORIES
- ../../../../../shared
- PUBLIC_LIBRARIES
- Qt::Network
-)
-
-#### 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"
diff --git a/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt b/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt
index 7bd9bd80fb..69b62c2f9f 100644
--- a/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt
+++ b/tests/auto/network/socket/qudpsocket/test/CMakeLists.txt
@@ -1,35 +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
- INCLUDE_DIRECTORIES
- ../../../../../shared
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Network
- QT_TEST_SERVER_LIST "danted" "echo" # special case
+ Qt::TestPrivate
+ 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/test/test.pro b/tests/auto/network/socket/qudpsocket/test/test.pro
deleted file mode 100644
index 994b360370..0000000000
--- a/tests/auto/network/socket/qudpsocket/test/test.pro
+++ /dev/null
@@ -1,25 +0,0 @@
-CONFIG += testcase
-testcase.timeout = 800 # this test is slow
-SOURCES += ../tst_qudpsocket.cpp
-INCLUDEPATH += ../../../../../shared/
-QT = core network testlib
-
-MOC_DIR=tmp
-
-win32:debug_and_release {
- CONFIG(debug, debug|release) {
- DESTDIR = ../debug
-} else {
- DESTDIR = ../release
- }
-} else {
- DESTDIR = ../
-}
-
-TARGET = tst_qudpsocket
-
-# Only on Linux until 'echo' has been added to docker-compose-for-{windows,macOS}.yml and tested
-linux {
- CONFIG += unsupported/testserver
- QT_TEST_SERVER_LIST = danted echo
-}
diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
index fe7822718f..689ff452f9 100644
--- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
+++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
@@ -1,34 +1,16 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <QtTest/QtTest>
+// 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>
+#include <QtEndian>
+#if QT_CONFIG(process)
+#include <QProcess>
+#endif
+#include <QScopeGuard>
+#include <QVersionNumber>
+#include <QSemaphore>
#include <qcoreapplication.h>
#include <qfileinfo.h>
@@ -46,8 +28,9 @@
#include <QNetworkInterface>
#include <qstringlist.h>
+#include <QSet>
#include "../../../network-settings.h"
-#include "emulationdetector.h"
+#include <QtTest/private/qemulationdetector_p.h>
#if defined(Q_OS_LINUX)
#define SHOULD_CHECK_SYSCALL_SUPPORT
@@ -63,6 +46,8 @@
# define RELIABLE_BYTES_AVAILABLE
#endif
+using namespace Qt::StringLiterals;
+
Q_DECLARE_METATYPE(QHostAddress)
QT_FORWARD_DECLARE_CLASS(QUdpSocket)
@@ -120,6 +105,8 @@ private slots:
void asyncReadDatagram();
void writeInHostLookupState();
+ void readyReadConnectionThrottling();
+
protected slots:
void empty_readyReadSlot();
void empty_connectedSlot();
@@ -138,6 +125,7 @@ private:
QList<QHostAddress> allAddresses;
QHostAddress multicastGroup4, multicastGroup6;
QList<QHostAddress> linklocalMulticastGroups;
+ QNetworkInterface ifaceWithIPv6;
QUdpSocket *m_asyncSender;
QUdpSocket *m_asyncReceiver;
};
@@ -188,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()
@@ -286,18 +255,25 @@ 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 (EmulationDetector::isRunningArmOnX86())
+ if (QTestPrivate::isRunningArmOnX86())
QSKIP("This test is unreliable due to QEMU emulation shortcomings.");
}
@@ -351,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"};
@@ -400,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);
@@ -428,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);
@@ -437,7 +414,6 @@ void tst_QUdpSocket::broadcasting()
QEXPECT_FAIL("",
"Broadcasting to 255.255.255.255 does not work on FreeBSD",
Abort);
- QVERIFY(false); // seems that QFAIL() doesn't respect the QEXPECT_FAIL() :/
#endif
QFAIL("Network operation timed out");
}
@@ -449,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]));
@@ -509,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);
@@ -586,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);
@@ -634,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());
@@ -646,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.");
}
@@ -657,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());
@@ -668,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());
@@ -680,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());
@@ -719,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);
}
@@ -740,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);
}
@@ -773,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));
}
@@ -893,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));
@@ -1016,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()
@@ -1059,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
@@ -1259,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;
@@ -1305,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;
@@ -1352,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);
}
@@ -1372,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;
}
@@ -1409,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();
}
@@ -1466,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;
}
@@ -1517,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)),
@@ -1568,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;
@@ -1595,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++;
@@ -1618,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) {
@@ -1633,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();
@@ -1648,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()));
@@ -1657,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()));
@@ -1665,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,
@@ -1704,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) {
@@ -1718,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();
@@ -1731,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
@@ -1742,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
@@ -1769,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);
}
@@ -1804,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));
@@ -1816,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));
@@ -1828,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));
@@ -1908,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;
@@ -1926,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/.prev_CMakeLists.txt b/tests/auto/network/socket/qudpsocket/udpServer/.prev_CMakeLists.txt
deleted file mode 100644
index 00b7ce272e..0000000000
--- a/tests/auto/network/socket/qudpsocket/udpServer/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-# Generated from udpServer.pro.
-
-#####################################################################
-## udpServer Binary:
-#####################################################################
-
-qt_internal_add_executable(udpServer
- SOURCES
- main.cpp
- PUBLIC_LIBRARIES
- Qt::Network
-)
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
diff --git a/tests/auto/network/socket/qudpsocket/udpServer/udpServer.pro b/tests/auto/network/socket/qudpsocket/udpServer/udpServer.pro
deleted file mode 100644
index c8f9ebf648..0000000000
--- a/tests/auto/network/socket/qudpsocket/udpServer/udpServer.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-SOURCES += main.cpp
-QT = core network
-CONFIG += cmdline
diff --git a/tests/auto/network/socket/socket.pro b/tests/auto/network/socket/socket.pro
deleted file mode 100644
index 1248d71172..0000000000
--- a/tests/auto/network/socket/socket.pro
+++ /dev/null
@@ -1,22 +0,0 @@
-TEMPLATE=subdirs
-QT_FOR_CONFIG += network
-
-SUBDIRS=\
- qhttpsocketengine \
- qudpsocket \
- qtcpsocket \
- qlocalsocket \
- qtcpserver \
- qsocks5socketengine \
- qabstractsocket \
- platformsocketengine \
- qsctpsocket \
-
-!qtConfig(private_tests): SUBDIRS -= \
- platformsocketengine \
- qtcpsocket \
- qhttpsocketengine \
- qsocks5socketengine \
-
-!qtConfig(sctp): SUBDIRS -= \
- qsctpsocket \