summaryrefslogtreecommitdiffstats
path: root/tests/auto/qfile
diff options
context:
space:
mode:
authorShane Kearns <ext-shane.2.kearns@nokia.com>2012-03-08 11:45:05 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-03-13 14:40:50 (GMT)
commita3a2ff59284840f1980197e3f6d06d99fcc0f512 (patch)
tree95226afc1dfb521840e1c7f093ab149aaac85ff4 /tests/auto/qfile
parent5bce44ef030a18d7ed3f6e3abf824d42ab84bf70 (diff)
downloadQt-a3a2ff59284840f1980197e3f6d06d99fcc0f512.zip
Qt-a3a2ff59284840f1980197e3f6d06d99fcc0f512.tar.gz
Qt-a3a2ff59284840f1980197e3f6d06d99fcc0f512.tar.bz2
Optimise QFile::seek that doesn't move the file pointer
If the seek position matches the current file position, then avoid doing an implicit flush that could be expensive. Change-Id: I019858ffb36fe832b9aee8da0a7803cafc8f7f75 Reviewed-by: Jaakko Helanti <ext-jaakko.helanti@nokia.com> Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'tests/auto/qfile')
-rw-r--r--tests/auto/qfile/tst_qfile.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/qfile/tst_qfile.cpp b/tests/auto/qfile/tst_qfile.cpp
index 7c5ae6f..832a7ef 100644
--- a/tests/auto/qfile/tst_qfile.cpp
+++ b/tests/auto/qfile/tst_qfile.cpp
@@ -128,6 +128,7 @@ private slots:
void seek();
void setSize();
void setSizeSeek();
+ void seekToSamePosition();
void atEnd();
void readLine();
void readLine2();
@@ -458,6 +459,7 @@ void tst_QFile::cleanupTestCase()
QFile::remove("readAllBuffer.txt");
QFile::remove("qt_file.tmp");
QFile::remove("File.txt");
+ QFile::remove("seekToSamePosition.txt");
}
//------------------------------------------
@@ -756,6 +758,59 @@ void tst_QFile::setSizeSeek()
QCOMPARE(f.pos(), qint64(2));
}
+void tst_QFile::seekToSamePosition()
+{
+ QFile in("testfile.txt");
+ QFile out("seekToSamePosition.txt");
+ QVERIFY(in.open(QFile::ReadOnly));
+ QVERIFY(out.open(QFile::WriteOnly));
+ QByteArray plusses;
+ plusses.fill('+', 58);
+
+ qint64 cursor = 0;
+ QVERIFY(in.seek(cursor));
+ QVERIFY(out.seek(cursor));
+
+ QVERIFY(out.write(plusses));
+
+ cursor += 58;
+ QVERIFY(in.seek(cursor));
+ QVERIFY(out.seek(cursor));
+
+ QByteArray copy = in.read(60);
+ QVERIFY(out.write(copy));
+
+ cursor += 60;
+ QVERIFY(in.seek(cursor));
+ QVERIFY(out.seek(cursor));
+
+ QVERIFY(out.write(plusses));
+
+ cursor += 58;
+ QVERIFY(in.seek(cursor));
+ QVERIFY(out.seek(cursor));
+
+ copy = in.readAll();
+ QVERIFY(out.write(copy));
+
+ //compare
+ out.close();
+ QVERIFY(out.open(QFile::ReadOnly));
+ QVERIFY(in.seek(0));
+
+ QByteArray clean = in.readAll();
+ QByteArray dirty = out.readAll();
+ out.close();
+
+ QVERIFY(clean.size() == dirty.size());
+ for (int i=0;i<clean.size();i++) {
+ if (clean[i] == '-')
+ QVERIFY2(dirty[i] == '+', qPrintable(QString("no + at pos %1").arg(i)));
+ else
+ QVERIFY2(dirty[i] == clean[i], qPrintable(QString("char at pos %1 mismatched, %2 vs %3").arg(i).arg(clean[i]).arg(dirty[i])));
+ }
+}
+
void tst_QFile::atEnd()
{
QFile f( SRCDIR "testfile.txt" );