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>
This commit is contained in:
parent
9af5ed3a81
commit
3da9143b36
@ -277,6 +277,10 @@ void QBuffer::setData(const QByteArray &data)
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
\reimp
|
\reimp
|
||||||
|
|
||||||
|
Unlike QFile, opening a QBuffer QIODevice::WriteOnly does not truncate it.
|
||||||
|
However, pos() is set to 0. Use QIODevice::Append or QIODevice::Truncate to
|
||||||
|
change either behavior.
|
||||||
*/
|
*/
|
||||||
bool QBuffer::open(OpenMode flags)
|
bool QBuffer::open(OpenMode flags)
|
||||||
{
|
{
|
||||||
|
@ -15,6 +15,7 @@ class tst_QBuffer : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void open();
|
void open();
|
||||||
|
void openWriteOnlyDoesNotTruncate();
|
||||||
void getSetCheck();
|
void getSetCheck();
|
||||||
void readBlock();
|
void readBlock();
|
||||||
void readBlockPastEnd();
|
void readBlockPastEnd();
|
||||||
@ -111,6 +112,29 @@ void tst_QBuffer::open()
|
|||||||
b.close();
|
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
|
// some status() tests, too
|
||||||
void tst_QBuffer::readBlock()
|
void tst_QBuffer::readBlock()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user