diff options
Diffstat (limited to 'tests/auto/corelib/io/qbuffer')
-rw-r--r-- | tests/auto/corelib/io/qbuffer/CMakeLists.txt | 10 | ||||
-rw-r--r-- | tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp | 26 |
2 files changed, 32 insertions, 4 deletions
diff --git a/tests/auto/corelib/io/qbuffer/CMakeLists.txt b/tests/auto/corelib/io/qbuffer/CMakeLists.txt index 661bad7866..87022451a0 100644 --- a/tests/auto/corelib/io/qbuffer/CMakeLists.txt +++ b/tests/auto/corelib/io/qbuffer/CMakeLists.txt @@ -1,12 +1,16 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -# Generated from qbuffer.pro. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qbuffer Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qbuffer LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qbuffer SOURCES tst_qbuffer.cpp diff --git a/tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp b/tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp index 93e0d6fce8..acfd60e224 100644 --- a/tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp +++ b/tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QTestEventLoop> @@ -15,6 +15,7 @@ class tst_QBuffer : public QObject Q_OBJECT private slots: void open(); + void openWriteOnlyDoesNotTruncate(); void getSetCheck(); void readBlock(); void readBlockPastEnd(); @@ -111,6 +112,29 @@ void tst_QBuffer::open() b.close(); } +void tst_QBuffer::openWriteOnlyDoesNotTruncate() +{ + QBuffer b; + const auto data = QByteArrayLiteral("Hey, presto!"); + + { + QVERIFY(b.open(QIODevice::WriteOnly)); + b.write(data); + b.close(); + } + { + QVERIFY(b.open(QIODevice::ReadOnly)); + QCOMPARE(b.readAll(), data); + b.close(); + } + { + QVERIFY(b.open(QIODevice::WriteOnly)); + QCOMPARE(b.size(), data.size()); + QCOMPARE(b.pos(), 0); + b.close(); + } +} + // some status() tests, too void tst_QBuffer::readBlock() { |