diff options
Diffstat (limited to 'tests/auto/corelib/io/qiodevice')
-rw-r--r-- | tests/auto/corelib/io/qiodevice/BLACKLIST | 2 | ||||
-rw-r--r-- | tests/auto/corelib/io/qiodevice/CMakeLists.txt | 32 | ||||
-rw-r--r-- | tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp | 69 |
3 files changed, 40 insertions, 63 deletions
diff --git a/tests/auto/corelib/io/qiodevice/BLACKLIST b/tests/auto/corelib/io/qiodevice/BLACKLIST deleted file mode 100644 index b8a61d3ca9..0000000000 --- a/tests/auto/corelib/io/qiodevice/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[unget] -redhatenterpriselinuxworkstation-6.6 diff --git a/tests/auto/corelib/io/qiodevice/CMakeLists.txt b/tests/auto/corelib/io/qiodevice/CMakeLists.txt index 2bd6033440..18cae40663 100644 --- a/tests/auto/corelib/io/qiodevice/CMakeLists.txt +++ b/tests/auto/corelib/io/qiodevice/CMakeLists.txt @@ -1,36 +1,24 @@ -# Generated from qiodevice.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qiodevice Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qiodevice LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data list(APPEND test_data "tst_qiodevice.cpp") qt_internal_add_test(tst_qiodevice SOURCES tst_qiodevice.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Network TESTDATA ${test_data} + QT_TEST_SERVER_LIST "apache2" "cyrus" ) - -#### Keys ignored in scope 1:.:.:qiodevice.pro:<TRUE>: -# MOC_DIR = "tmp" - -## Scopes: -##################################################################### - -if(ANDROID) - # Resources: - set(android_testdata_resource_files - "tst_qiodevice.cpp" - ) - - qt_internal_add_resource(tst_qiodevice "android_testdata" - PREFIX - "/" - FILES - ${android_testdata_resource_files} - ) -endif() diff --git a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp index 88e41092a6..ad88d14bc9 100644 --- a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp +++ b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 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) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QtCore/QCoreApplication> #include <QtNetwork/QtNetwork> @@ -104,15 +79,20 @@ void tst_QIODevice::getSetCheck() //---------------------------------------------------------------------------------- void tst_QIODevice::constructing_QTcpSocket() { +#ifdef QT_TEST_SERVER + if (!QtNetworkSettings::verifyConnection(QtNetworkSettings::imapServerName(), 143)) + QSKIP("No network test server available"); +#else if (!QtNetworkSettings::verifyTestNetworkSettings()) QSKIP("No network test server available"); +#endif QTcpSocket socket; QIODevice *device = &socket; QVERIFY(!device->isOpen()); - socket.connectToHost(QtNetworkSettings::serverName(), 143); + socket.connectToHost(QtNetworkSettings::imapServerName(), 143); QVERIFY(socket.waitForConnected(30000)); QVERIFY(device->isOpen()); QCOMPARE(device->readChannelCount(), 1); @@ -130,7 +110,7 @@ void tst_QIODevice::constructing_QTcpSocket() socket.close(); QCOMPARE(socket.readChannelCount(), 0); QCOMPARE(socket.writeChannelCount(), 0); - socket.connectToHost(QtNetworkSettings::serverName(), 143); + socket.connectToHost(QtNetworkSettings::imapServerName(), 143); QVERIFY(socket.waitForConnected(30000)); QVERIFY(device->isOpen()); @@ -191,16 +171,16 @@ void tst_QIODevice::constructing_QFile() void tst_QIODevice::read_QByteArray() { QFile f(QFINDTESTDATA("tst_qiodevice.cpp")); - f.open(QIODevice::ReadOnly); + QVERIFY(f.open(QIODevice::ReadOnly)); QByteArray b = f.read(10); - QCOMPARE(b.length(), 10); + QCOMPARE(b.size(), 10); b = f.read(256); - QCOMPARE(b.length(), 256); + QCOMPARE(b.size(), 256); b = f.read(0); - QCOMPARE(b.length(), 0); + QCOMPARE(b.size(), 0); } //-------------------------------------------------------------------- @@ -270,9 +250,17 @@ void tst_QIODevice::unget() result = QByteArray("ZXCV"); lineResult = "ZXCV"; } else { - if (!QtNetworkSettings::verifyTestNetworkSettings()) - QSKIP("No network test server available"); - socket.connectToHost(QtNetworkSettings::serverName(), 80); +#ifdef QT_TEST_SERVER + const bool hasNetworkServer = + QtNetworkSettings::verifyConnection(QtNetworkSettings::httpServerName(), 80); +#else + const bool hasNetworkServer = QtNetworkSettings::verifyTestNetworkSettings(); +#endif + if (!hasNetworkServer) { + qInfo("No network test server: skipping QTcpSocket part of test."); + continue; + } + socket.connectToHost(QtNetworkSettings::httpServerName(), 80); socket.write("GET / HTTP/1.0\r\n\r\n"); QVERIFY(socket.waitForReadyRead()); dev = &socket; @@ -558,7 +546,8 @@ protected: qint64 readData(char *data, qint64 maxSize) override { maxSize = qMin(maxSize, qint64(buf->size() - offset)); - memcpy(data, buf->constData() + offset, maxSize); + if (maxSize > 0) + memcpy(data, buf->constData() + offset, maxSize); offset += maxSize; return maxSize; } @@ -601,13 +590,15 @@ protected: qint64 readData(char *data, qint64 maxSize) override { maxSize = qMin(maxSize, qint64(buf.size() - pos())); - memcpy(data, buf.constData() + pos(), maxSize); + if (maxSize > 0) + memcpy(data, buf.constData() + pos(), maxSize); return maxSize; } qint64 writeData(const char *data, qint64 maxSize) override { maxSize = qMin(maxSize, qint64(buf.size() - pos())); - memcpy(buf.data() + pos(), data, maxSize); + if (maxSize > 0) + memcpy(buf.data() + pos(), data, maxSize); return maxSize; } |