summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp')
-rw-r--r--tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp44
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"