diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-04-06 19:10:10 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-04-06 19:10:25 +0200 |
commit | 20cac3d9c9c22153e9e316daff32b6050ff6be6b (patch) | |
tree | b563a89475df9afb4f40841ec371be9488d5b1ed /tests/auto/corelib/io | |
parent | 8ce85d74b692392a4ea0785360156f37418cff13 (diff) | |
parent | 9eb0b09abce28b11e4915fc9c3b3e996eb19cef2 (diff) |
Merge remote-tracking branch 'origin/5.5' into dev
Change-Id: If9fd98525b6b4ca07e5e006fc98bf372a73b8a21
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r-- | tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp index 30c1f2be59..f756588e80 100644 --- a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp +++ b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp @@ -58,6 +58,7 @@ private slots: void readLine2(); void peekBug(); + void readAllKeepPosition(); }; void tst_QIODevice::initTestCase() @@ -584,5 +585,48 @@ void tst_QIODevice::peekBug() } +class SequentialReadBuffer : public QIODevice +{ +public: + SequentialReadBuffer(const char *data) : QIODevice(), buf(data), offset(0) { } + + bool isSequential() const Q_DECL_OVERRIDE { return true; } + const QByteArray &buffer() const { return buf; } + +protected: + qint64 readData(char *data, qint64 maxSize) Q_DECL_OVERRIDE + { + maxSize = qMin(maxSize, qint64(buf.size() - offset)); + memcpy(data, buf.constData() + offset, maxSize); + offset += maxSize; + return maxSize; + } + qint64 writeData(const char * /* data */, qint64 /* maxSize */) Q_DECL_OVERRIDE + { + return -1; + } + +private: + QByteArray buf; + int offset; +}; + +// Test readAll() on position change for sequential device +void tst_QIODevice::readAllKeepPosition() +{ + SequentialReadBuffer buffer("Hello world!"); + buffer.open(QIODevice::ReadOnly); + char c; + + QVERIFY(buffer.getChar(&c)); + QCOMPARE(buffer.pos(), qint64(0)); + buffer.ungetChar(c); + QCOMPARE(buffer.pos(), qint64(0)); + + QByteArray resultArray = buffer.readAll(); + QCOMPARE(buffer.pos(), qint64(0)); + QCOMPARE(resultArray, buffer.buffer()); +} + QTEST_MAIN(tst_QIODevice) #include "tst_qiodevice.moc" |