diff options
author | Martin Smith <msmith@trolltech.com> | 2010-01-05 12:27:33 (GMT) |
---|---|---|
committer | Martin Smith <msmith@trolltech.com> | 2010-01-05 12:27:33 (GMT) |
commit | 2f42f8eee39d03a84a24da8b1d047f8e58079a26 (patch) | |
tree | 1bce31e1052080511f53bd5c44a4e983135e22f1 | |
parent | 94c2fce09c34b629a6fcb5a9576c4646a1ac24a8 (diff) | |
parent | d03475b69aa552a490e32fb2b7ad4dfaeacecf93 (diff) | |
download | Qt-2f42f8eee39d03a84a24da8b1d047f8e58079a26.zip Qt-2f42f8eee39d03a84a24da8b1d047f8e58079a26.tar.gz Qt-2f42f8eee39d03a84a24da8b1d047f8e58079a26.tar.bz2 |
Merge branch '4.6' of git@scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.6
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 12 | ||||
-rw-r--r-- | tests/auto/qfile/tst_qfile.cpp | 41 |
2 files changed, 51 insertions, 2 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 0e5a2de..8dcccb4 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -965,7 +965,15 @@ QByteArray QIODevice::readAll() QByteArray result; qint64 readBytes = 0; - if (d->isSequential() || (readBytes = size()) == 0) { + + // flush internal read buffer + if (!(d->openMode & Text) && !d->buffer.isEmpty()) { + result = d->buffer.readAll(); + readBytes = result.size(); + } + + qint64 theSize; + if (d->isSequential() || (theSize = size()) == 0) { // Size is unknown, read incrementally. qint64 readResult; do { @@ -977,7 +985,7 @@ QByteArray QIODevice::readAll() } else { // Read it all in one go. // If resize fails, don't read anything. - result.resize(int(readBytes - d->pos)); + result.resize(int(theSize - d->pos)); readBytes = read(result.data(), result.size()); } diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp index 2b2f431..e88c222 100644 --- a/tests/auto/qfile/tst_qfile.cpp +++ b/tests/auto/qfile/tst_qfile.cpp @@ -129,6 +129,8 @@ private slots: void readLine(); void readLine2(); void readLineNullInLine(); + void readAll_data(); + void readAll(); void readAllStdin(); void readLineStdin(); void readLineStdin_lineByLine(); @@ -752,6 +754,45 @@ void tst_QFile::readLineNullInLine() QCOMPARE(file.readLine(), QByteArray()); } +void tst_QFile::readAll_data() +{ + QTest::addColumn<bool>("textMode"); + QTest::addColumn<QString>("fileName"); + QTest::newRow( "TextMode unixfile" ) << true << SRCDIR "testfile.txt"; + QTest::newRow( "BinaryMode unixfile" ) << false << SRCDIR "testfile.txt"; + QTest::newRow( "TextMode dosfile" ) << true << SRCDIR "dosfile.txt"; + QTest::newRow( "BinaryMode dosfile" ) << false << SRCDIR "dosfile.txt"; + QTest::newRow( "TextMode bigfile" ) << true << SRCDIR "tst_qfile.cpp"; + QTest::newRow( "BinaryMode bigfile" ) << false << SRCDIR "tst_qfile.cpp"; + QVERIFY(QFile(SRCDIR "tst_qfile.cpp").size() > 64*1024); +} + +void tst_QFile::readAll() +{ + QFETCH( bool, textMode ); + QFETCH( QString, fileName ); + + QFile file(fileName); + if (textMode) + QVERIFY(file.open(QFile::Text | QFile::ReadOnly)); + else + QVERIFY(file.open(QFile::ReadOnly)); + + QByteArray a = file.readAll(); + file.reset(); + QVERIFY(file.pos() == 0); + + QVERIFY(file.bytesAvailable() > 7); + QByteArray b = file.read(1); + char x; + file.getChar(&x); + b.append(x); + b.append(file.read(5)); + b.append(file.readAll()); + + QCOMPARE(a, b); +} + void tst_QFile::readAllStdin() { #if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) |