equal
deleted
inserted
replaced
1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the test suite of the Qt Toolkit. |
7 ** This file is part of the test suite of the Qt Toolkit. |
8 ** |
8 ** |
93 void renameFdLeak(); |
93 void renameFdLeak(); |
94 void reOpenThroughQFile(); |
94 void reOpenThroughQFile(); |
95 void keepOpenMode(); |
95 void keepOpenMode(); |
96 void resetTemplateAfterError(); |
96 void resetTemplateAfterError(); |
97 void setTemplateAfterOpen(); |
97 void setTemplateAfterOpen(); |
|
98 void autoRemoveAfterFailedRename(); |
98 |
99 |
99 public: |
100 public: |
100 }; |
101 }; |
101 |
102 |
102 void tst_QTemporaryFile::construction() |
103 void tst_QTemporaryFile::construction() |
556 QVERIFY( temp.open() ); |
557 QVERIFY( temp.open() ); |
557 QCOMPARE( temp.fileName(), fileName ); |
558 QCOMPARE( temp.fileName(), fileName ); |
558 QCOMPARE( temp.fileTemplate(), newTemplate ); |
559 QCOMPARE( temp.fileTemplate(), newTemplate ); |
559 } |
560 } |
560 |
561 |
|
562 void tst_QTemporaryFile::autoRemoveAfterFailedRename() |
|
563 { |
|
564 struct CleanOnReturn |
|
565 { |
|
566 ~CleanOnReturn() |
|
567 { |
|
568 if (!tempName.isEmpty()) |
|
569 QFile::remove(tempName); |
|
570 } |
|
571 |
|
572 void reset() |
|
573 { |
|
574 tempName.clear(); |
|
575 } |
|
576 |
|
577 QString tempName; |
|
578 }; |
|
579 |
|
580 CleanOnReturn cleaner; |
|
581 |
|
582 { |
|
583 QTemporaryFile file; |
|
584 QVERIFY( file.open() ); |
|
585 cleaner.tempName = file.fileName(); |
|
586 |
|
587 QVERIFY( QFile::exists(cleaner.tempName) ); |
|
588 QVERIFY( !QFileInfo("i-do-not-exist").isDir() ); |
|
589 QVERIFY( !file.rename("i-do-not-exist/file.txt") ); |
|
590 QVERIFY( QFile::exists(cleaner.tempName) ); |
|
591 } |
|
592 |
|
593 QVERIFY( !QFile::exists(cleaner.tempName) ); |
|
594 cleaner.reset(); |
|
595 } |
|
596 |
561 QTEST_MAIN(tst_QTemporaryFile) |
597 QTEST_MAIN(tst_QTemporaryFile) |
562 #include "tst_qtemporaryfile.moc" |
598 #include "tst_qtemporaryfile.moc" |