diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2010-08-12 09:23:04 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2010-08-12 09:28:20 (GMT) |
commit | f28eb5e37c726ecd44bbbf1a5ad746570d2cac9b (patch) | |
tree | 0cfafa527c04efd82aff55214082491d6c370fba /tests/auto/qiodevice | |
parent | 690598adbcb76b07dc791ab7ee5e3513ddd4096e (diff) | |
download | Qt-f28eb5e37c726ecd44bbbf1a5ad746570d2cac9b.zip Qt-f28eb5e37c726ecd44bbbf1a5ad746570d2cac9b.tar.gz Qt-f28eb5e37c726ecd44bbbf1a5ad746570d2cac9b.tar.bz2 |
tst_qiodevice: Add peek()ing auto test
Diffstat (limited to 'tests/auto/qiodevice')
-rw-r--r-- | tests/auto/qiodevice/tst_qiodevice.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/auto/qiodevice/tst_qiodevice.cpp b/tests/auto/qiodevice/tst_qiodevice.cpp index 7048754..0226402 100644 --- a/tests/auto/qiodevice/tst_qiodevice.cpp +++ b/tests/auto/qiodevice/tst_qiodevice.cpp @@ -81,6 +81,8 @@ private slots: void readLine2_data(); void readLine2(); + + void peekBug(); }; // Testing get/set functions @@ -591,5 +593,62 @@ void tst_QIODevice::readLine2() } } + +class PeekBug : public QIODevice { + Q_OBJECT +public: + char alphabet[27]; + qint64 counter; + PeekBug() : QIODevice(), counter(0) { + memcpy(alphabet,"abcdefghijklmnopqrstuvqxyz",27); + }; + qint64 readData(char *data, qint64 maxlen) { + qint64 pos = 0; + while (pos < maxlen) { + *(data + pos) = alphabet[counter]; + pos++; + counter++; + if (counter == 26) + counter = 0; + } + return maxlen; + } + qint64 writeData(const char *data, qint64 maxlen) { + return -1; + } + +}; + +// This is a testcase for the bug fixed with bd287865 +void tst_QIODevice::peekBug() +{ + PeekBug peekBug; + peekBug.open(QIODevice::ReadOnly | QIODevice::Unbuffered); + + char onetwo[2]; + peekBug.peek(onetwo, 2); + QCOMPARE(onetwo[0], 'a'); + QCOMPARE(onetwo[1], 'b'); + + peekBug.read(onetwo, 1); + QCOMPARE(onetwo[0], 'a'); + + peekBug.peek(onetwo, 2); + QCOMPARE(onetwo[0], 'b'); + QCOMPARE(onetwo[1], 'c'); + + peekBug.read(onetwo, 1); + QCOMPARE(onetwo[0], 'b'); + peekBug.read(onetwo, 1); + QCOMPARE(onetwo[0], 'c'); + peekBug.read(onetwo, 1); + QCOMPARE(onetwo[0], 'd'); + + peekBug.peek(onetwo, 2); + QCOMPARE(onetwo[0], 'e'); + QCOMPARE(onetwo[1], 'f'); + +} + QTEST_MAIN(tst_QIODevice) #include "tst_qiodevice.moc" |