diff -r 41300fa6a67c -r 3b1da2848fc7 tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp --- a/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp Tue Feb 02 00:43:10 2010 +0200 +++ b/tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp Fri Feb 19 23:40:16 2010 +0200 @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -95,6 +95,7 @@ void keepOpenMode(); void resetTemplateAfterError(); void setTemplateAfterOpen(); + void autoRemoveAfterFailedRename(); public: }; @@ -558,5 +559,40 @@ 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"