summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-06-20 10:37:51 -0700
committerThiago Macieira <thiago.macieira@intel.com>2014-08-13 16:36:11 +0200
commit4848796f3e2f4aeebb8cbc0782853f27f93afeec (patch)
treec48a7d97075a663234af4a972561508468312762 /tests
parentc6718f01c20779da00689b3ef66ede7af5fe8ce5 (diff)
Make sure we don't cache old file sizes prior to new writes
If we write to a file, its size changes. We should drop previous size caches. Change-Id: Ib687c91e5fc88cab588c89023f23da9622160da9 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp
index 60d1517ed3..1afe629dac 100644
--- a/tests/auto/corelib/io/qfile/tst_qfile.cpp
+++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp
@@ -234,6 +234,8 @@ private slots:
void mapResource();
void mapOpenMode_data();
void mapOpenMode();
+ void mapWrittenFile_data();
+ void mapWrittenFile();
#ifndef Q_OS_WINCE
void openStandardStreamsFileDescriptors();
@@ -3079,6 +3081,44 @@ void tst_QFile::mapOpenMode()
file.close();
}
+void tst_QFile::mapWrittenFile_data()
+{
+ QTest::addColumn<int>("mode");
+ QTest::newRow("buffered") << 0;
+ QTest::newRow("unbuffered") << int(QIODevice::Unbuffered);
+}
+
+void tst_QFile::mapWrittenFile()
+{
+ static const char data[128] = "Some data padded with nulls\n";
+ QFETCH(int, mode);
+
+ QString fileName = QDir::currentPath() + '/' + "qfile_map_testfile";
+
+#ifdef Q_OS_WINCE
+ fileName = QFileInfo(fileName).absoluteFilePath();
+#endif
+
+ if (QFile::exists(fileName)) {
+ QVERIFY(QFile::setPermissions(fileName,
+ QFile::WriteOwner | QFile::ReadOwner | QFile::WriteUser | QFile::ReadUser));
+ QFile::remove(fileName);
+ }
+ QFile file(fileName);
+ QVERIFY(file.open(QIODevice::ReadWrite | QFile::OpenMode(mode)));
+ QCOMPARE(file.write(data, sizeof data), qint64(sizeof data));
+ if ((mode & QIODevice::Unbuffered) == 0)
+ file.flush();
+
+ // test that we can read the data we've just written, without closing the file
+ uchar *memory = file.map(0, sizeof data);
+ QVERIFY(memory);
+ QVERIFY(memcmp(memory, data, sizeof data) == 0);
+
+ file.close();
+ file.remove();
+}
+
void tst_QFile::openDirectory()
{
QFile f1(m_resourcesDir);