summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Abecasis <joao@abecasis.name>2009-06-29 11:42:43 (GMT)
committerJoão Abecasis <joao@abecasis.name>2009-06-29 16:14:03 (GMT)
commitccd06993cbb00058c937f28e8aa17dab87b448de (patch)
treee5db7d230c8c2df57c89a19e5c4cdd06fa9d13a6
parent02ed2cd9ddf57ee9daadbfc76e6b73dbd4165583 (diff)
downloadQt-ccd06993cbb00058c937f28e8aa17dab87b448de.zip
Qt-ccd06993cbb00058c937f28e8aa17dab87b448de.tar.gz
Qt-ccd06993cbb00058c937f28e8aa17dab87b448de.tar.bz2
QTemporaryFile: Report the user-provided openMode
Reviewed-by: Thiago
-rw-r--r--src/corelib/io/qtemporaryfile.cpp3
-rw-r--r--tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp33
2 files changed, 35 insertions, 1 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index a735dda..2d2db7d 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -341,6 +341,8 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
Q_D(QFSFileEngine);
Q_ASSERT(!isReallyOpen());
+ openMode |= QIODevice::ReadWrite;
+
if (!filePathIsTemplate)
return QFSFileEngine::open(openMode);
@@ -758,7 +760,6 @@ bool QTemporaryFile::open(OpenMode flags)
}
}
- flags |= QIODevice::ReadWrite;
if (QFile::open(flags)) {
d->fileName = d->fileEngine->fileName(QAbstractFileEngine::DefaultName);
return true;
diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
index d7c0574..66896a8 100644
--- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -88,6 +88,7 @@ private slots:
void rename();
void renameFdLeak();
void reOpenThroughQFile();
+ void keepOpenMode();
public:
};
@@ -439,5 +440,37 @@ void tst_QTemporaryFile::reOpenThroughQFile()
QCOMPARE(file.readAll(), data);
}
+void tst_QTemporaryFile::keepOpenMode()
+{
+ QByteArray data("abcdefghij");
+
+ {
+ QTemporaryFile file;
+ QVERIFY(((QFile &)file).open(QIODevice::WriteOnly));
+ QVERIFY(QIODevice::WriteOnly == file.openMode());
+
+ QCOMPARE(file.write(data), (qint64)data.size());
+ file.close();
+
+ QVERIFY(((QFile &)file).open(QIODevice::ReadOnly));
+ QVERIFY(QIODevice::ReadOnly == file.openMode());
+ QCOMPARE(file.readAll(), data);
+ }
+
+ {
+ QTemporaryFile file;
+ QVERIFY(file.open());
+ QCOMPARE(file.write(data), (qint64)data.size());
+ QVERIFY(file.rename("temporary-file.txt"));
+
+ QVERIFY(((QFile &)file).open(QIODevice::ReadOnly));
+ QVERIFY(QIODevice::ReadOnly == file.openMode());
+ QCOMPARE(file.readAll(), data);
+
+ QVERIFY(((QFile &)file).open(QIODevice::WriteOnly));
+ QVERIFY(QIODevice::WriteOnly == file.openMode());
+ }
+}
+
QTEST_MAIN(tst_QTemporaryFile)
#include "tst_qtemporaryfile.moc"