diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-06-08 14:45:03 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-06-10 10:06:17 +0000 |
commit | 4fe332f543ab169be0052d6533b8ed48b09d8f28 (patch) | |
tree | 195daf4e169a737a19fa94ca382c0aaa1fee1690 | |
parent | 83d952c2d08c17454192cd00ebf1be48fed1a9dc (diff) |
Fix leaking of link in tst_QFileInfo::canonicalFilePath().
Give the link a name containing time stamp and ensure
it is deleted.
Change-Id: I846c58095acbcd92e7daccfd43a69dd97e95e7b0
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
-rw-r--r-- | tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 62e183f619..ef51422579 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -609,6 +609,16 @@ void tst_QFileInfo::canonicalPath() QCOMPARE(fi.canonicalPath(), QFileInfo(QDir::tempPath()).canonicalFilePath()); } +class FileDeleter { + Q_DISABLE_COPY(FileDeleter) +public: + explicit FileDeleter(const QString fileName) : m_fileName(fileName) {} + ~FileDeleter() { QFile::remove(m_fileName); } + +private: + const QString m_fileName; +}; + void tst_QFileInfo::canonicalFilePath() { const QString fileName("tmp.canon"); @@ -639,9 +649,13 @@ void tst_QFileInfo::canonicalFilePath() QCOMPARE(info1.canonicalFilePath(), info2.canonicalFilePath()); } } + + const QString dirSymLinkName = QLatin1String("tst_qfileinfo") + + QDateTime::currentDateTime().toString(QLatin1String("yyMMddhhmmss")); + const QString link(QDir::tempPath() + QLatin1Char('/') + dirSymLinkName); + FileDeleter dirSymLinkDeleter(link); + { - const QString link(QDir::tempPath() + QDir::separator() + "tst_qfileinfo"); - QFile::remove(link); QFile file(QDir::currentPath()); if (file.link(link)) { QFile tempfile("tempfile.txt"); @@ -666,12 +680,12 @@ void tst_QFileInfo::canonicalFilePath() } } { - QString link(QDir::tempPath() + QDir::separator() + "tst_qfileinfo" - + QDir::separator() + "link_to_tst_qfileinfo"); + QString link(QDir::tempPath() + QLatin1Char('/') + dirSymLinkName + + "/link_to_tst_qfileinfo"); QFile::remove(link); - QFile file(QDir::tempPath() + QDir::separator() + "tst_qfileinfo" - + QDir::separator() + "tst_qfileinfo.cpp"); + QFile file(QDir::tempPath() + QLatin1Char('/') + dirSymLinkName + + "tst_qfileinfo.cpp"); if (file.link(link)) { QFileInfo info1("tst_qfileinfo.cpp"); |