summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qfile/tst_qfile.cpp
diff options
context:
space:
mode:
authorSimon Sasburg <simon.sasburg@gmail.com>2014-07-21 19:28:43 +0100
committerSimon Sasburg <simon.sasburg@gmail.com>2014-07-23 07:20:40 +0200
commit3905c6f00d9d11e01d6e211565d5ed58a59fc2d8 (patch)
treeb78f3e518bd879cd7c163da26162e595ad2ade9c /tests/auto/corelib/io/qfile/tst_qfile.cpp
parentf713bd3e19406e02502fe1dc877f09ae57eca8df (diff)
Add QFileDevice::MemoryMapFlags::MapPrivateOption flag.
Passing this flag to QFileDevice::map() will allow writes to the mapped memory without modifying the file that was mapped. These writes will be lost when the memory is unmapped. Change-Id: I7d46b044fc370585de8c06fdb4059f1f1be12d7d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Diffstat (limited to 'tests/auto/corelib/io/qfile/tst_qfile.cpp')
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp
index 60d1517ed3..9ce931d78a 100644
--- a/tests/auto/corelib/io/qfile/tst_qfile.cpp
+++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp
@@ -3028,17 +3028,21 @@ void tst_QFile::mapResource()
void tst_QFile::mapOpenMode_data()
{
QTest::addColumn<int>("openMode");
+ QTest::addColumn<int>("flags");
- QTest::newRow("ReadOnly") << int(QIODevice::ReadOnly);
+ QTest::newRow("ReadOnly") << int(QIODevice::ReadOnly) << int(QFileDevice::NoOptions);
//QTest::newRow("WriteOnly") << int(QIODevice::WriteOnly); // this doesn't make sense
- QTest::newRow("ReadWrite") << int(QIODevice::ReadWrite);
- QTest::newRow("ReadOnly,Unbuffered") << int(QIODevice::ReadOnly | QIODevice::Unbuffered);
- QTest::newRow("ReadWrite,Unbuffered") << int(QIODevice::ReadWrite | QIODevice::Unbuffered);
+ QTest::newRow("ReadWrite") << int(QIODevice::ReadWrite) << int(QFileDevice::NoOptions);
+ QTest::newRow("ReadOnly,Unbuffered") << int(QIODevice::ReadOnly | QIODevice::Unbuffered) << int(QFileDevice::NoOptions);
+ QTest::newRow("ReadWrite,Unbuffered") << int(QIODevice::ReadWrite | QIODevice::Unbuffered) << int(QFileDevice::NoOptions);
+ QTest::newRow("ReadOnly + MapPrivate") << int(QIODevice::ReadOnly) << int(QFileDevice::MapPrivateOption);
+ QTest::newRow("ReadWrite + MapPrivate") << int(QIODevice::ReadWrite) << int(QFileDevice::MapPrivateOption);
}
void tst_QFile::mapOpenMode()
{
QFETCH(int, openMode);
+ QFETCH(int, flags);
static const qint64 fileSize = 4096;
QByteArray pattern(fileSize, 'A');
@@ -3060,11 +3064,15 @@ void tst_QFile::mapOpenMode()
// open according to our mode
QVERIFY(file.open(QIODevice::OpenMode(openMode)));
- uchar *memory = file.map(0, fileSize);
+ uchar *memory = file.map(0, fileSize, QFileDevice::MemoryMapFlags(flags));
+#if defined(Q_OS_WINCE)
+ QEXPECT_FAIL("ReadOnly + MapPrivate" , "Windows CE does not support MapPrivateOption.", Abort);
+ QEXPECT_FAIL("ReadWrite + MapPrivate", "Windows CE does not support MapPrivateOption.", Abort);
+#endif
QVERIFY(memory);
QVERIFY(memcmp(memory, pattern, fileSize) == 0);
- if (openMode & QIODevice::WriteOnly) {
+ if ((openMode & QIODevice::WriteOnly) || (flags & QFileDevice::MapPrivateOption)) {
// try to write to the file
*memory = 'a';
file.unmap(memory);
@@ -3073,7 +3081,7 @@ void tst_QFile::mapOpenMode()
file.seek(0);
char c;
QVERIFY(file.getChar(&c));
- QCOMPARE(c, 'a');
+ QCOMPARE(c, (flags & QFileDevice::MapPrivateOption) ? 'A' : 'a');
}
file.close();