diff options
Diffstat (limited to 'tests/auto/network/socket/qtcpsocket')
8 files changed, 87 insertions, 170 deletions
diff --git a/tests/auto/network/socket/qtcpsocket/BLACKLIST b/tests/auto/network/socket/qtcpsocket/BLACKLIST index d42457d743..6261c85a09 100644 --- a/tests/auto/network/socket/qtcpsocket/BLACKLIST +++ b/tests/auto/network/socket/qtcpsocket/BLACKLIST @@ -1,7 +1,24 @@ [timeoutConnect:ip] windows -[connectToHostError] -windows-10 gcc developer-build +# QTBUG-101274 +[timeoutConnect:WithSocks5Proxy:ip] +qnx ci +[timeoutConnect:WithSocks5ProxyAuth:ip] +qnx ci +[timeoutConnect:WithHttpProxy:ip] +qnx ci +[timeoutConnect:WithHttpProxyBasicAuth:ip] +qnx ci +[timeoutConnect:WithSocks5Proxy SSL:ip] +qnx ci +[timeoutConnect:WithSocks5AuthProxy SSL:ip] +qnx ci +[timeoutConnect:WithHttpProxy SSL:ip] +qnx ci +[timeoutConnect:WithHttpProxyBasicAuth SSL:ip] +qnx ci +[suddenRemoteDisconnect:WithoutProxy:Qt4 Client <-> Qt4 Server] +qnx ci # QTBUG-66247 [delayedClose:WithSocks5Proxy] windows-10 gcc developer-build @@ -53,3 +70,8 @@ windows-10 gcc developer-build windows-10 gcc developer-build [bind] macos arm +# QTBUG-101274 +[bindThenResolveHost:WithoutProxy:first-fail] +qnx ci +[bindThenResolveHost:WithoutProxy SSL:first-fail] +qnx ci diff --git a/tests/auto/network/socket/qtcpsocket/CMakeLists.txt b/tests/auto/network/socket/qtcpsocket/CMakeLists.txt index 645c65671a..7b6bb4d881 100644 --- a/tests/auto/network/socket/qtcpsocket/CMakeLists.txt +++ b/tests/auto/network/socket/qtcpsocket/CMakeLists.txt @@ -1,4 +1,11 @@ -# Generated from qtcpsocket.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qtcpsocket LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() if(NOT QT_FEATURE_private_tests) return() diff --git a/tests/auto/network/socket/qtcpsocket/stressTest/CMakeLists.txt b/tests/auto/network/socket/qtcpsocket/stressTest/CMakeLists.txt index 950c4356e2..3ea6c55895 100644 --- a/tests/auto/network/socket/qtcpsocket/stressTest/CMakeLists.txt +++ b/tests/auto/network/socket/qtcpsocket/stressTest/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from stressTest.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## stressTest Binary: @@ -9,11 +10,7 @@ qt_internal_add_executable(stressTest SOURCES Test.cpp Test.h main.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Network Qt::Test ) - -#### Keys ignored in scope 1:.:.:stressTest.pro:<TRUE>: -# MOC_DIR = ".moc/" -# TMP_DIR = ".tmp/" diff --git a/tests/auto/network/socket/qtcpsocket/stressTest/Test.cpp b/tests/auto/network/socket/qtcpsocket/stressTest/Test.cpp index ed61db1a13..8d6e470220 100644 --- a/tests/auto/network/socket/qtcpsocket/stressTest/Test.cpp +++ b/tests/auto/network/socket/qtcpsocket/stressTest/Test.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only // Qt #include <QByteArray> #include <QCoreApplication> diff --git a/tests/auto/network/socket/qtcpsocket/stressTest/Test.h b/tests/auto/network/socket/qtcpsocket/stressTest/Test.h index 5e6b2b9467..495b90d733 100644 --- a/tests/auto/network/socket/qtcpsocket/stressTest/Test.h +++ b/tests/auto/network/socket/qtcpsocket/stressTest/Test.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef TEST_H #define TEST_H diff --git a/tests/auto/network/socket/qtcpsocket/stressTest/main.cpp b/tests/auto/network/socket/qtcpsocket/stressTest/main.cpp index 1948389e37..f989a4de34 100644 --- a/tests/auto/network/socket/qtcpsocket/stressTest/main.cpp +++ b/tests/auto/network/socket/qtcpsocket/stressTest/main.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "Test.h" #include <QCoreApplication> diff --git a/tests/auto/network/socket/qtcpsocket/test/CMakeLists.txt b/tests/auto/network/socket/qtcpsocket/test/CMakeLists.txt index 759f655417..c3258f8a95 100644 --- a/tests/auto/network/socket/qtcpsocket/test/CMakeLists.txt +++ b/tests/auto/network/socket/qtcpsocket/test/CMakeLists.txt @@ -1,35 +1,24 @@ -# Generated from test.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qtcpsocket Test: ##################################################################### qt_internal_add_test(tst_qtcpsocket - OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" # special case + OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../" SOURCES ../tst_qtcpsocket.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::CorePrivate Qt::NetworkPrivate - QT_TEST_SERVER_LIST "danted" "squid" "apache2" "ftp-proxy" "vsftpd" "iptables" "cyrus" # special case + QT_TEST_SERVER_LIST "danted" "squid" "apache2" "ftp-proxy" "vsftpd" "iptables" "cyrus" ) ## Scopes: ##################################################################### qt_internal_extend_target(tst_qtcpsocket CONDITION WIN32 - PUBLIC_LIBRARIES + LIBRARIES ws2_32 ) - -#### Keys ignored in scope 4:.:.:test.pro:(CMAKE_BUILD_TYPE STREQUAL Debug): -# DESTDIR = "../debug" - -#### Keys ignored in scope 5:.:.:test.pro:else: -# DESTDIR = "../release" - -#### Keys ignored in scope 6:.:.:test.pro:else: -# DESTDIR = "../" - -#### Keys ignored in scope 7:.:.:test.pro:LINUX: -# QT_TEST_SERVER_LIST = "danted" "squid" "apache2" "ftp-proxy" "vsftpd" "iptables" "cyrus" diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index 4d903a710a..4ec01a9d94 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -1,36 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2017 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2017 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <qglobal.h> -// To prevent windows system header files from re-defining min/max -#define NOMINMAX 1 #if defined(_WIN32) #include <winsock2.h> #else @@ -83,14 +56,12 @@ #include <memory> -#ifdef Q_OS_LINUX -#include "private/qnativesocketengine_p.h" -#endif // Q_OS_LINUX - #include "private/qhostinfo_p.h" #include "../../../network-settings.h" +using namespace Qt::StringLiterals; + QT_FORWARD_DECLARE_CLASS(QTcpSocket) class SocketPair; @@ -312,7 +283,7 @@ tst_QTcpSocket::tst_QTcpSocket() tmpSocket = 0; //This code relates to the socketsConstructedBeforeEventLoop test case - earlyConstructedSockets = new SocketPair; + earlyConstructedSockets = new SocketPair(this); QVERIFY(earlyConstructedSockets->create()); earlyBytesWrittenCount = 0; earlyReadyReadCount = 0; @@ -361,7 +332,8 @@ void tst_QTcpSocket::initTestCase() //QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::firewallServerName(), 1357)); QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::socksProxyServerName(), 1080)); QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpServerName(), 21)); - QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpProxyServerName(), 2121)); + // FTP currently not supported: + // QVERIFY(QtNetworkSettings::verifyConnection(QtNetworkSettings::ftpProxyServerName(), 2121)); #else if (!QtNetworkSettings::verifyTestNetworkSettings()) QSKIP("No network test server available"); @@ -376,8 +348,8 @@ void tst_QTcpSocket::init() QFETCH_GLOBAL(int, proxyType); QList<QHostAddress> socks5Addresses = QHostInfo::fromName(QtNetworkSettings::socksProxyServerName()).addresses(); QList<QHostAddress> httpProxyAddresses = QHostInfo::fromName(QtNetworkSettings::httpProxyServerName()).addresses(); - QVERIFY2(socks5Addresses.count() > 0, "failed to get ip address for SOCKS5 proxy server"); - QVERIFY2(httpProxyAddresses.count() > 0, "failed to get ip address for HTTP proxy server"); + QVERIFY2(socks5Addresses.size() > 0, "failed to get ip address for SOCKS5 proxy server"); + QVERIFY2(httpProxyAddresses.size() > 0, "failed to get ip address for HTTP proxy server"); QString socks5Address = socks5Addresses.first().toString(); QString httpProxyAddress = httpProxyAddresses.first().toString(); QNetworkProxy proxy; @@ -517,12 +489,13 @@ void tst_QTcpSocket::bind_data() bool testIpv6 = false; // iterate all interfaces, add all addresses on them as test data - QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces(); - foreach (const QNetworkInterface &netinterface, interfaces) { + const QList<QNetworkInterface> interfaces = QNetworkInterface::allInterfaces(); + for (const QNetworkInterface &netinterface : interfaces) { if (!netinterface.isValid()) continue; - foreach (const QNetworkAddressEntry &entry, netinterface.addressEntries()) { + const auto entries = netinterface.addressEntries(); + for (const QNetworkAddressEntry &entry : entries) { if (entry.ip().isInSubnet(QHostAddress::parseSubnet("fe80::/10")) || entry.ip().isInSubnet(QHostAddress::parseSubnet("169.254/16"))) continue; // link-local bind will fail, at least on Linux, so skip it. @@ -552,12 +525,12 @@ void tst_QTcpSocket::bind_data() // these ranges are guaranteed to be reserved for 'documentation purposes', // and thus, should be unused in the real world. Not that I'm assuming the // world is full of competent administrators, or anything. - QStringList knownBad; - knownBad << "198.51.100.1"; - knownBad << "2001:0DB8::1"; - foreach (const QString &badAddress, knownBad) { + const QString knownBad[] = { + u"198.51.100.1"_s, + u"2001:0DB8::1"_s + }; + for (const QString &badAddress : knownBad) QTest::addRow("%s:0", badAddress.toLatin1().constData()) << badAddress << 0 << false << QString(); - } // try to bind to a privileged ports // we should fail if we're not root (unless the ports are in use!) @@ -592,7 +565,7 @@ void tst_QTcpSocket::bind() std::unique_ptr<QTcpSocket> socket(newSocket()); quint16 boundPort; - qintptr fd; + qintptr fd = 0; if (successExpected) { bool randomPort = port == -1; @@ -1810,7 +1783,7 @@ void tst_QTcpSocket::recursiveReadyRead() QVERIFY2(!timeout(), "Timed out when waiting for the readyRead() signal."); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); delete testSocket; } @@ -1852,7 +1825,7 @@ void tst_QTcpSocket::atEnd() QVERIFY2(greeting.startsWith("220 (vsFTPd 3."), qPrintable(greeting)); #else // Test server must use some vsFTPd 2.x.x version - QVERIFY2(greeting.length() == sizeof("220 (vsFTPd 2.x.x)")-1, qPrintable(greeting)); + QVERIFY2(greeting.size() == sizeof("220 (vsFTPd 2.x.x)")-1, qPrintable(greeting)); QVERIFY2(greeting.startsWith("220 (vsFTPd 2."), qPrintable(greeting)); #endif QVERIFY2(greeting.endsWith(QLatin1Char(')')), qPrintable(greeting)); @@ -2035,8 +2008,8 @@ void tst_QTcpSocket::remoteCloseError() enterLoop(30); QVERIFY(!timeout()); - QCOMPARE(disconnectedSpy.count(), 1); - QCOMPARE(errorSpy.count(), 1); + QCOMPARE(disconnectedSpy.size(), 1); + QCOMPARE(errorSpy.size(), 1); QCOMPARE(clientSocket->error(), QAbstractSocket::RemoteHostClosedError); delete serverSocket; @@ -2167,7 +2140,7 @@ void tst_QTcpSocket::waitForConnectedInHostLookupSlot() if (tmpSocket->state() != QAbstractSocket::ConnectedState) loop.exec(); - QCOMPARE(timerSpy.count(), 0); + QCOMPARE(timerSpy.size(), 0); delete tmpSocket; } @@ -2221,7 +2194,7 @@ public slots: #if defined(Q_OS_MAC) pthread_yield_np(); #elif defined Q_OS_LINUX && !defined Q_OS_ANDROID - pthread_yield(); + sched_yield(); #endif if (!sock->waitForConnected()) { networkTimeout = true; @@ -2272,7 +2245,7 @@ void tst_QTcpSocket::readyReadSignalsAfterWaitForReadyRead() // Wait for the read QVERIFY(socket->waitForReadyRead(10000)); - QCOMPARE(readyReadSpy.count(), 1); + QCOMPARE(readyReadSpy.size(), 1); QString s = socket->readLine(); QVERIFY2(QtNetworkSettings::compareReplyIMAP(s.toLatin1()), s.toLatin1().constData()); @@ -2280,7 +2253,7 @@ void tst_QTcpSocket::readyReadSignalsAfterWaitForReadyRead() QCoreApplication::instance()->processEvents(); QCOMPARE(socket->bytesAvailable(), qint64(0)); - QCOMPARE(readyReadSpy.count(), 1); + QCOMPARE(readyReadSpy.size(), 1); delete socket; } @@ -2354,8 +2327,8 @@ void tst_QTcpSocket::abortiveClose() enterLoop(5); - QCOMPARE(readyReadSpy.count(), 0); - QCOMPARE(errorSpy.count(), 1); + QCOMPARE(readyReadSpy.size(), 0); + QCOMPARE(errorSpy.size(), 1); QCOMPARE(*static_cast<const int *>(errorSpy.at(0).at(0).constData()), int(QAbstractSocket::RemoteHostClosedError)); @@ -2474,11 +2447,11 @@ void tst_QTcpSocket::connectionRefused() QCOMPARE(socket->state(), QAbstractSocket::UnconnectedState); QCOMPARE(socket->error(), QAbstractSocket::ConnectionRefusedError); - QCOMPARE(stateSpy.count(), 3); + QCOMPARE(stateSpy.size(), 3); QCOMPARE(qvariant_cast<QAbstractSocket::SocketState>(stateSpy.at(0).at(0)), QAbstractSocket::HostLookupState); QCOMPARE(qvariant_cast<QAbstractSocket::SocketState>(stateSpy.at(1).at(0)), QAbstractSocket::ConnectingState); QCOMPARE(qvariant_cast<QAbstractSocket::SocketState>(stateSpy.at(2).at(0)), QAbstractSocket::UnconnectedState); - QCOMPARE(errorSpy.count(), 1); + QCOMPARE(errorSpy.size(), 1); delete socket; } @@ -2610,7 +2583,7 @@ void tst_QTcpSocket::moveToThread0() { // Case 1: Moved after connecting, before waiting for connection. - QTcpSocket *socket = newSocket();; + QTcpSocket *socket = newSocket(); socket->connectToHost(QtNetworkSettings::imapServerName(), 143); socket->moveToThread(0); QVERIFY(socket->waitForConnected(5000)); @@ -2941,6 +2914,7 @@ void tst_QTcpSocket::proxyFactory_data() << proxyList << proxyList.at(1) << false << int(QAbstractSocket::UnknownSocketError); +#if 0 // FTP not currently supported proxyList.clear(); proxyList << QNetworkProxy(QNetworkProxy::FtpCachingProxy, QtNetworkSettings::ftpProxyServerName(), 2121) << QNetworkProxy(QNetworkProxy::HttpCachingProxy, QtNetworkSettings::httpProxyServerName(), 3129) @@ -2948,6 +2922,7 @@ void tst_QTcpSocket::proxyFactory_data() QTest::newRow("ftp+cachinghttp+socks5") << proxyList << proxyList.at(2) << false << int(QAbstractSocket::UnknownSocketError); +#endif // tests that fail to connect proxyList.clear(); @@ -2956,6 +2931,7 @@ void tst_QTcpSocket::proxyFactory_data() << proxyList << QNetworkProxy() << true << int(QAbstractSocket::UnsupportedSocketOperationError); +#if 0 // FTP not currently supported proxyList.clear(); proxyList << QNetworkProxy(QNetworkProxy::FtpCachingProxy, QtNetworkSettings::ftpProxyServerName(), 2121); QTest::newRow("ftp") @@ -2968,6 +2944,7 @@ void tst_QTcpSocket::proxyFactory_data() QTest::newRow("ftp+cachinghttp") << proxyList << QNetworkProxy() << true << int(QAbstractSocket::UnsupportedSocketOperationError); +#endif } void tst_QTcpSocket::proxyFactory() @@ -3147,8 +3124,8 @@ void tst_QTcpSocket::serverDisconnectWithBuffered() QCOMPARE(socket->state(), QAbstractSocket::UnconnectedState); } // Test signal emitting - QCOMPARE(spyDisconnected.count(), 1); - QVERIFY(spyStateChanged.count() > 0); + QCOMPARE(spyDisconnected.size(), 1); + QVERIFY(spyStateChanged.size() > 0); QVERIFY(qvariant_cast<QAbstractSocket::SocketState>(spyStateChanged.last().first()) == QAbstractSocket::UnconnectedState); @@ -3237,7 +3214,7 @@ void tst_QTcpSocket::readNotificationsAfterBind() QTestEventLoop::instance().enterLoop(10); QVERIFY2(!QTestEventLoop::instance().timeout(), "Connection to closed port timed out instead of refusing, something is wrong"); QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState, "Socket connected unexpectedly!"); - QCOMPARE(spyReadyRead.count(), 0); + QCOMPARE(spyReadyRead.size(), 0); } QTEST_MAIN(tst_QTcpSocket) |