From ccd06993cbb00058c937f28e8aa17dab87b448de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Mon, 29 Jun 2009 13:42:43 +0200 Subject: QTemporaryFile: Report the user-provided openMode Reviewed-by: Thiago --- src/corelib/io/qtemporaryfile.cpp | 3 ++- tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp | 33 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) 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" -- cgit v0.12