summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qiodevice
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io/qiodevice')
-rw-r--r--tests/auto/corelib/io/qiodevice/BLACKLIST2
-rw-r--r--tests/auto/corelib/io/qiodevice/CMakeLists.txt34
-rw-r--r--tests/auto/corelib/io/qiodevice/qiodevice.pro12
-rw-r--r--tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp83
4 files changed, 50 insertions, 81 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 fdc896e45d..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_add_test(tst_qiodevice
+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 AND NOT ANDROID_EMBEDDED)
- # Resources:
- set(android_testdata_resource_files
- "tst_qiodevice.cpp"
- )
-
- qt_add_resource(tst_qiodevice "android_testdata"
- PREFIX
- "/"
- FILES
- ${android_testdata_resource_files}
- )
-endif()
diff --git a/tests/auto/corelib/io/qiodevice/qiodevice.pro b/tests/auto/corelib/io/qiodevice/qiodevice.pro
deleted file mode 100644
index 1c978953d6..0000000000
--- a/tests/auto/corelib/io/qiodevice/qiodevice.pro
+++ /dev/null
@@ -1,12 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qiodevice
-QT = core network testlib
-SOURCES = tst_qiodevice.cpp
-
-TESTDATA += tst_qiodevice.cpp
-MOC_DIR=tmp
-
-android:!android-embedded {
- RESOURCES += \
- android_testdata.qrc
-}
diff --git a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp
index 10214f2996..ad88d14bc9 100644
--- a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp
+++ b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp
@@ -1,34 +1,9 @@
-/****************************************************************************
-**
-** 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) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtCore/QCoreApplication>
#include <QtNetwork/QtNetwork>
-#include <QtTest/QtTest>
+#include <QTest>
#include "../../../network-settings.h"
@@ -70,7 +45,7 @@ private:
void tst_QIODevice::initTestCase()
{
-#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
+#ifdef Q_OS_ANDROID
QVERIFY(QFileInfo(QStringLiteral("./tst_qiodevice.cpp")).exists()
|| QFile::copy(QStringLiteral(":/tst_qiodevice.cpp"), QStringLiteral("./tst_qiodevice.cpp")));
#endif
@@ -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;
@@ -407,6 +395,9 @@ void tst_QIODevice::readLine()
QVERIFY(buffer.open(QIODevice::ReadWrite));
QVERIFY(buffer.canReadLine());
+ QTest::ignoreMessage(QtWarningMsg, "QIODevice::readLine (QBuffer): Called with maxSize < 2");
+ QCOMPARE(buffer.readLine(nullptr, 0), qint64(-1));
+
int linelen = data.indexOf('\n') + 1;
QByteArray line;
line.reserve(linelen + 100);
@@ -555,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;
}
@@ -598,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;
}
@@ -646,11 +640,12 @@ void tst_QIODevice::skip_data()
do {
QByteArray devName(sequential ? "sequential" : "random-access");
- QTest::newRow(qPrintable(devName + "-small_data")) << true << QByteArray("abcdefghij")
+ QTest::newRow(qPrintable(devName + "-small_data")) << sequential
+ << QByteArray("abcdefghij")
<< 3 << 6 << 6 << 'j';
- QTest::newRow(qPrintable(devName + "-big_data")) << true << bigData
+ QTest::newRow(qPrintable(devName + "-big_data")) << sequential << bigData
<< 1 << 10000 << 10000 << 'x';
- QTest::newRow(qPrintable(devName + "-beyond_the_end")) << true << bigData
+ QTest::newRow(qPrintable(devName + "-beyond_the_end")) << sequential << bigData
<< 1 << 20000 << 19999 << '\0';
sequential = !sequential;