diff options
Diffstat (limited to 'tests/auto/qiodevice')
-rw-r--r-- | tests/auto/qiodevice/qiodevice.pro | 4 | ||||
-rw-r--r-- | tests/auto/qiodevice/tst_qiodevice.cpp | 59 |
2 files changed, 61 insertions, 2 deletions
diff --git a/tests/auto/qiodevice/qiodevice.pro b/tests/auto/qiodevice/qiodevice.pro index 716cdce..29b0a05 100644 --- a/tests/auto/qiodevice/qiodevice.pro +++ b/tests/auto/qiodevice/qiodevice.pro @@ -4,14 +4,14 @@ SOURCES += tst_qiodevice.cpp QT = core network wince*: { - addFiles.sources = tst_qiodevice.cpp + addFiles.files = tst_qiodevice.cpp addFiles.path = . DEPLOYMENT += addFiles DEFINES += SRCDIR=\\\"\\\" !wince50standard-x86-msvc2005: DEFINES += WINCE_EMULATOR_TEST=1 } else:symbian { # SRCDIR defined in code in symbian - addFiles.sources = tst_qiodevice.cpp + addFiles.files = tst_qiodevice.cpp addFiles.path = . DEPLOYMENT += addFiles TARGET.CAPABILITY = NetworkServices 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" |