summaryrefslogtreecommitdiffstats
path: root/tests/auto/qiodevice/tst_qiodevice.cpp
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-11-20 12:50:41 (GMT)
committerJoão Abecasis <joao@abecasis.name>2009-11-20 15:33:00 (GMT)
commitb7692016f282251002b3e85dfcb5567bd91a12c0 (patch)
treeac3ba927000938e56508c06ddcce6e5f06430357 /tests/auto/qiodevice/tst_qiodevice.cpp
parentbda75bfc7cf0137474005a0a733ff83e2aae16e9 (diff)
downloadQt-b7692016f282251002b3e85dfcb5567bd91a12c0.zip
Qt-b7692016f282251002b3e85dfcb5567bd91a12c0.tar.gz
Qt-b7692016f282251002b3e85dfcb5567bd91a12c0.tar.bz2
Fix regression introduced in 1e6b424b692b20dcfec920f8d3563e520ec1ff05
When processing the result of QIODevice::readLine, forgot to take into account that a '\0' is appended to the array. The terminating character is not accounted for in the number of bytes returned. By pre-allocating a byte for the terminating null character, we make sure we'll actually read 16k bytes on each and every iteration. Task-number: QTBUG-6019 Reviewed-by: Thiago Macieira
Diffstat (limited to 'tests/auto/qiodevice/tst_qiodevice.cpp')
-rw-r--r--tests/auto/qiodevice/tst_qiodevice.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/auto/qiodevice/tst_qiodevice.cpp b/tests/auto/qiodevice/tst_qiodevice.cpp
index 056ad6a..84fd8ad 100644
--- a/tests/auto/qiodevice/tst_qiodevice.cpp
+++ b/tests/auto/qiodevice/tst_qiodevice.cpp
@@ -77,6 +77,9 @@ private slots:
void readLine_data();
void readLine();
+
+ void readLine2_data();
+ void readLine2();
};
// Testing get/set functions
@@ -453,5 +456,114 @@ void tst_QIODevice::readLine()
QCOMPARE(line.size(), linelen);
}
+void tst_QIODevice::readLine2_data()
+{
+ QTest::addColumn<QByteArray>("line");
+
+ QTest::newRow("1024 - 4") << QByteArray(1024 - 4, 'x');
+ QTest::newRow("1024 - 3") << QByteArray(1024 - 3, 'x');
+ QTest::newRow("1024 - 2") << QByteArray(1024 - 2, 'x');
+ QTest::newRow("1024 - 1") << QByteArray(1024 - 1, 'x');
+ QTest::newRow("1024" ) << QByteArray(1024 , 'x');
+ QTest::newRow("1024 + 1") << QByteArray(1024 + 1, 'x');
+ QTest::newRow("1024 + 2") << QByteArray(1024 + 2, 'x');
+
+ QTest::newRow("4096 - 4") << QByteArray(4096 - 4, 'x');
+ QTest::newRow("4096 - 3") << QByteArray(4096 - 3, 'x');
+ QTest::newRow("4096 - 2") << QByteArray(4096 - 2, 'x');
+ QTest::newRow("4096 - 1") << QByteArray(4096 - 1, 'x');
+ QTest::newRow("4096" ) << QByteArray(4096 , 'x');
+ QTest::newRow("4096 + 1") << QByteArray(4096 + 1, 'x');
+ QTest::newRow("4096 + 2") << QByteArray(4096 + 2, 'x');
+
+ QTest::newRow("8192 - 4") << QByteArray(8192 - 4, 'x');
+ QTest::newRow("8192 - 3") << QByteArray(8192 - 3, 'x');
+ QTest::newRow("8192 - 2") << QByteArray(8192 - 2, 'x');
+ QTest::newRow("8192 - 1") << QByteArray(8192 - 1, 'x');
+ QTest::newRow("8192" ) << QByteArray(8192 , 'x');
+ QTest::newRow("8192 + 1") << QByteArray(8192 + 1, 'x');
+ QTest::newRow("8192 + 2") << QByteArray(8192 + 2, 'x');
+
+ QTest::newRow("16384 - 4") << QByteArray(16384 - 4, 'x');
+ QTest::newRow("16384 - 3") << QByteArray(16384 - 3, 'x');
+ QTest::newRow("16384 - 2") << QByteArray(16384 - 2, 'x');
+ QTest::newRow("16384 - 1") << QByteArray(16384 - 1, 'x');
+ QTest::newRow("16384" ) << QByteArray(16384 , 'x');
+ QTest::newRow("16384 + 1") << QByteArray(16384 + 1, 'x');
+ QTest::newRow("16384 + 2") << QByteArray(16384 + 2, 'x');
+
+ QTest::newRow("20000") << QByteArray(20000, 'x');
+
+ QTest::newRow("32768 - 4") << QByteArray(32768 - 4, 'x');
+ QTest::newRow("32768 - 3") << QByteArray(32768 - 3, 'x');
+ QTest::newRow("32768 - 2") << QByteArray(32768 - 2, 'x');
+ QTest::newRow("32768 - 1") << QByteArray(32768 - 1, 'x');
+ QTest::newRow("32768" ) << QByteArray(32768 , 'x');
+ QTest::newRow("32768 + 1") << QByteArray(32768 + 1, 'x');
+ QTest::newRow("32768 + 2") << QByteArray(32768 + 2, 'x');
+
+ QTest::newRow("40000") << QByteArray(40000, 'x');
+}
+
+void tst_QIODevice::readLine2()
+{
+ QFETCH(QByteArray, line);
+
+ int length = line.size();
+
+ QByteArray data("First line.\r\n");
+ data.append(line);
+ data.append("\r\n");
+ data.append(line);
+ data.append("\r\n");
+ data.append("\r\n0123456789");
+
+ {
+ QBuffer buffer(&data);
+ buffer.open(QIODevice::ReadOnly);
+
+ buffer.seek(0);
+ QByteArray temp;
+ temp.resize(64536);
+ QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(13));
+ QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(length + 2));
+ QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(length + 2));
+ QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(2));
+ QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(10));
+ QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(-1));
+
+ buffer.seek(0);
+ QCOMPARE(buffer.readLine().size(), 13);
+ QCOMPARE(buffer.readLine().size(), length + 2);
+ QCOMPARE(buffer.readLine().size(), length + 2);
+ QCOMPARE(buffer.readLine().size(), 2);
+ QCOMPARE(buffer.readLine().size(), 10);
+ QVERIFY(buffer.readLine().isNull());
+ }
+
+ {
+ QBuffer buffer(&data);
+ buffer.open(QIODevice::ReadOnly | QIODevice::Text);
+
+ buffer.seek(0);
+ QByteArray temp;
+ temp.resize(64536);
+ QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(12));
+ QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(length + 1));
+ QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(length + 1));
+ QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(1));
+ QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(10));
+ QCOMPARE(buffer.readLine(temp.data(), temp.size()), qint64(-1));
+
+ buffer.seek(0);
+ QCOMPARE(buffer.readLine().size(), 12);
+ QCOMPARE(buffer.readLine().size(), length + 1);
+ QCOMPARE(buffer.readLine().size(), length + 1);
+ QCOMPARE(buffer.readLine().size(), 1);
+ QCOMPARE(buffer.readLine().size(), 10);
+ QVERIFY(buffer.readLine().isNull());
+ }
+}
+
QTEST_MAIN(tst_QIODevice)
#include "tst_qiodevice.moc"