diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-12-12 15:09:25 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-12-14 18:22:30 +0000 |
commit | ff523a0e3edafa927c9d13e605d0b007e4fc3a16 (patch) | |
tree | 1909a063c2dc6442448b96a01e8c8a0e9b068bf5 /tests/auto/corelib | |
parent | 24c2f91079fa67a68c480d3dea1de0bca13c6e03 (diff) |
QBuffer: test and document open() behavior
QBuffer::open() was only documented as \reimp, so its behavior
regarding WriteOnly was never actually described.
Add a test and document the outcome.
Change-Id: I75c49cd3f6a1961bcaece4a92a4e479bb3300d36
Reviewed-by: Mate Barany <mate.barany@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit c262a1805a062fd99abc890f58ea951da80ff0af)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r-- | tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp b/tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp index a4f26e2c6f..4e3dd70e12 100644 --- a/tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp +++ b/tests/auto/corelib/io/qbuffer/tst_qbuffer.cpp @@ -40,6 +40,7 @@ class tst_QBuffer : public QObject Q_OBJECT private slots: void open(); + void openWriteOnlyDoesNotTruncate(); void getSetCheck(); void readBlock(); void readBlockPastEnd(); @@ -136,6 +137,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() { |