From 39721ae5cce44c3ea77d96a47d60aff54a91ad5c Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Tue, 20 Jul 2010 08:54:36 +0200 Subject: Add a testcase for when peeking and then reading from a QIODevice This case was broken and then fixed again recently, this testcase should ensure that it does not break again in the future. Reviewed-by: Andreas Kling --- tests/auto/qiodevice/tst_qiodevice.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/auto/qiodevice/tst_qiodevice.cpp b/tests/auto/qiodevice/tst_qiodevice.cpp index 356e2f8..7048754 100644 --- a/tests/auto/qiodevice/tst_qiodevice.cpp +++ b/tests/auto/qiodevice/tst_qiodevice.cpp @@ -72,6 +72,7 @@ private slots: void read_QByteArray(); void unget(); void peek(); + void peekAndRead(); void getch(); void putch(); @@ -354,6 +355,31 @@ void tst_QIODevice::peek() QFile::remove("peektestfile"); } +void tst_QIODevice::peekAndRead() +{ + QByteArray originalData; + for (int i=0;i<1000;i++) + originalData += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QBuffer buffer; + QFile::remove("peektestfile"); + QFile file("peektestfile"); + + for (int i = 0; i < 2; ++i) { + QByteArray readData; + QIODevice *device = i ? (QIODevice *)&file : (QIODevice *)&buffer; + device->open(QBuffer::ReadWrite); + device->write(originalData); + device->seek(0); + while (!device->atEnd()) { + char peekIn[26]; + device->peek(peekIn, 26); + readData += device->read(26); + } + QCOMPARE(readData, originalData); + } + QFile::remove("peektestfile"); +} + void tst_QIODevice::getch() { #ifdef QT3_SUPPORT -- cgit v0.12