summaryrefslogtreecommitdiffstats
path: root/tests/auto/qtemporaryfile
diff options
context:
space:
mode:
authorJoão Abecasis <joao@trolltech.com>2010-01-12 19:14:56 +0100
committerJoão Abecasis <joao@trolltech.com>2010-01-14 18:48:55 +0100
commit2d0bd1a13328d5a5ed6c4d1e768937a6627f1086 (patch)
tree7b9be549e8e6fec944d0519779eb7b4b529b6a5f /tests/auto/qtemporaryfile
parent88a07b4c0a3a87eeb47750640cb71a5a64e0573c (diff)
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')
-rw-r--r--tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp
index c7811084eb..1304f4e0ca 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"