diff options
author | João Abecasis <joao@trolltech.com> | 2010-01-12 18:14:56 (GMT) |
---|---|---|
committer | João Abecasis <joao@trolltech.com> | 2010-01-14 17:48:55 (GMT) |
commit | 2d0bd1a13328d5a5ed6c4d1e768937a6627f1086 (patch) | |
tree | 7b9be549e8e6fec944d0519779eb7b4b529b6a5f /tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp | |
parent | 88a07b4c0a3a87eeb47750640cb71a5a64e0573c (diff) | |
download | Qt-2d0bd1a13328d5a5ed6c4d1e768937a6627f1086.zip Qt-2d0bd1a13328d5a5ed6c4d1e768937a6627f1086.tar.gz Qt-2d0bd1a13328d5a5ed6c4d1e768937a6627f1086.tar.bz2 |
QFile::remove: don't fail for unrelated errors
remove was checking for errors from close, but without clearing the
error state beforehand it ended picking unrelated errors.
Task-number: QTBUG-7285
Reviewed-by: qCaro
Diffstat (limited to 'tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp')
-rw-r--r-- | tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp index c781108..1304f4e 100644 --- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp @@ -95,6 +95,7 @@ private slots: void keepOpenMode(); void resetTemplateAfterError(); void setTemplateAfterOpen(); + void autoRemoveAfterFailedRename(); public: }; @@ -558,5 +559,40 @@ void tst_QTemporaryFile::setTemplateAfterOpen() QCOMPARE( temp.fileTemplate(), newTemplate ); } +void tst_QTemporaryFile::autoRemoveAfterFailedRename() +{ + struct CleanOnReturn + { + ~CleanOnReturn() + { + if (!tempName.isEmpty()) + QFile::remove(tempName); + } + + void reset() + { + tempName.clear(); + } + + QString tempName; + }; + + CleanOnReturn cleaner; + + { + QTemporaryFile file; + QVERIFY( file.open() ); + cleaner.tempName = file.fileName(); + + QVERIFY( QFile::exists(cleaner.tempName) ); + QVERIFY( !QFileInfo("i-do-not-exist").isDir() ); + QVERIFY( !file.rename("i-do-not-exist/file.txt") ); + QVERIFY( QFile::exists(cleaner.tempName) ); + } + + QVERIFY( !QFile::exists(cleaner.tempName) ); + cleaner.reset(); +} + QTEST_MAIN(tst_QTemporaryFile) #include "tst_qtemporaryfile.moc" |