summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2010-01-06 12:15:12 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-01-06 15:40:14 (GMT)
commit859bc191b1096c02cebad011c75a4573289904e7 (patch)
tree272798d460cb4e69a8de1c2c90bac0d626af9c33 /tests
parent5529a356368b31998e859e3fb5f94e85c16447aa (diff)
downloadQt-859bc191b1096c02cebad011c75a4573289904e7.zip
Qt-859bc191b1096c02cebad011c75a4573289904e7.tar.gz
Qt-859bc191b1096c02cebad011c75a4573289904e7.tar.bz2
QIODevice: Fix readAll()
My patch from yesterday did not have any effect: Instead of really using what was in the buffer, it used it but then read it from the underlying device anyway. Thanks Ritt Konstantin and Joao. Reviewed-by: joao
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qfile/tst_qfile.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp
index d3a607d..453434d 100644
--- a/tests/auto/qfile/tst_qfile.cpp
+++ b/tests/auto/qfile/tst_qfile.cpp
@@ -131,6 +131,7 @@ private slots:
void readLineNullInLine();
void readAll_data();
void readAll();
+ void readAllBuffer();
void readAllStdin();
void readLineStdin();
void readLineStdin_lineByLine();
@@ -390,6 +391,7 @@ void tst_QFile::cleanupTestCase()
QFile::remove("myLink2.lnk");
QFile::remove("resources");
QFile::remove("qfile_map_testfile");
+ QFile::remove("readAllBuffer.txt");
}
//------------------------------------------
@@ -793,6 +795,38 @@ void tst_QFile::readAll()
QCOMPARE(a, b);
}
+void tst_QFile::readAllBuffer()
+{
+ QString fileName = QLatin1String("readAllBuffer.txt");
+
+ QFile::remove(fileName);
+
+ QFile writer(fileName);
+ QFile reader(fileName);
+
+ QByteArray data1("This is arguably a very simple text.");
+ QByteArray data2("This is surely not as simple a test.");
+
+ QVERIFY( writer.open(QIODevice::ReadWrite | QIODevice::Unbuffered) );
+ QVERIFY( reader.open(QIODevice::ReadOnly) );
+
+ QCOMPARE( writer.write(data1), qint64(data1.size()) );
+ QVERIFY( writer.seek(0) );
+
+ QByteArray result;
+ result = reader.read(18);
+ QCOMPARE( result.size(), 18 );
+
+ QCOMPARE( writer.write(data2), qint64(data2.size()) ); // new data, old version buffered in reader
+ QCOMPARE( writer.write(data2), qint64(data2.size()) ); // new data, unbuffered in reader
+
+ result += reader.readAll();
+
+ QCOMPARE( result, data1 + data2 );
+
+ QFile::remove(fileName);
+}
+
void tst_QFile::readAllStdin()
{
#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)