Fix cleanup of temporary files in test of QFileInfo.
Change-Id: I0d21fc05a7d816acab5f7284f905bf971a5c04da Reviewed-by: David Faure (KDE) <faure@kde.org>
This commit is contained in:
parent
267e2bbee4
commit
c73dc44606
@ -46,6 +46,7 @@
|
|||||||
#include <qcoreapplication.h>
|
#include <qcoreapplication.h>
|
||||||
#include <qlibrary.h>
|
#include <qlibrary.h>
|
||||||
#include <qtemporaryfile.h>
|
#include <qtemporaryfile.h>
|
||||||
|
#include <qtemporarydir.h>
|
||||||
#include <qdir.h>
|
#include <qdir.h>
|
||||||
#include <qfileinfo.h>
|
#include <qfileinfo.h>
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
@ -80,6 +81,9 @@ class tst_QFileInfo : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
tst_QFileInfo() : m_currentDir(QDir::currentPath()) {}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
@ -193,8 +197,10 @@ private slots:
|
|||||||
void nonExistingFileDates();
|
void nonExistingFileDates();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const QString m_currentDir;
|
||||||
QString m_sourceFile;
|
QString m_sourceFile;
|
||||||
QString m_resourcesDir;
|
QString m_resourcesDir;
|
||||||
|
QTemporaryDir m_dir;
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QFileInfo::initTestCase()
|
void tst_QFileInfo::initTestCase()
|
||||||
@ -203,32 +209,13 @@ void tst_QFileInfo::initTestCase()
|
|||||||
QVERIFY(!m_sourceFile.isEmpty());
|
QVERIFY(!m_sourceFile.isEmpty());
|
||||||
m_resourcesDir = QFINDTESTDATA("resources");
|
m_resourcesDir = QFINDTESTDATA("resources");
|
||||||
QVERIFY(!m_resourcesDir.isEmpty());
|
QVERIFY(!m_resourcesDir.isEmpty());
|
||||||
|
QVERIFY(m_dir.isValid());
|
||||||
|
QVERIFY(QDir::setCurrent(m_dir.path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QFileInfo::cleanupTestCase()
|
void tst_QFileInfo::cleanupTestCase()
|
||||||
{
|
{
|
||||||
QFile::remove("brokenlink.lnk");
|
QDir::setCurrent(m_currentDir); // Release temporary directory so that it can be deleted on Windows
|
||||||
QFile::remove("link.lnk");
|
|
||||||
QFile::remove("file1");
|
|
||||||
QFile::remove("dummyfile");
|
|
||||||
QFile::remove("simplefile.txt");
|
|
||||||
QFile::remove("longFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileName.txt");
|
|
||||||
QFile::remove("tempfile.txt");
|
|
||||||
|
|
||||||
#if defined(Q_OS_UNIX)
|
|
||||||
QDir().rmdir("./.hidden-directory");
|
|
||||||
QFile::remove("link_to_tst_qfileinfo");
|
|
||||||
#endif
|
|
||||||
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
|
|
||||||
QDir().rmdir("./hidden-directory");
|
|
||||||
QDir().rmdir("abs_symlink");
|
|
||||||
QDir().rmdir("rel_symlink");
|
|
||||||
QDir().rmdir("junction_pwd");
|
|
||||||
QDir().rmdir("junction_root");
|
|
||||||
QDir().rmdir("mountpoint");
|
|
||||||
QFile::remove("abs_symlink.cpp");
|
|
||||||
QFile::remove("rel_symlink.cpp");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Testing get/set functions
|
// Testing get/set functions
|
||||||
@ -1462,10 +1449,22 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks()
|
|||||||
QFETCH(QString, canonicalFilePath);
|
QFETCH(QString, canonicalFilePath);
|
||||||
|
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(path);
|
||||||
QCOMPARE(fi.isSymLink(), isSymLink);
|
const bool actualIsSymLink = fi.isSymLink();
|
||||||
|
const QString actualSymLinkTarget = isSymLink ? fi.symLinkTarget() : QString();
|
||||||
|
const QString actualCanonicalFilePath = isSymLink ? fi.canonicalFilePath() : QString();
|
||||||
|
// Ensure that junctions, mountpoints are removed. If this fails, do not remove
|
||||||
|
// temporary directory to prevent it from trashing the system.
|
||||||
|
if (fi.isDir()) {
|
||||||
|
if (!QDir().rmdir(fi.fileName())) {
|
||||||
|
qWarning("Unable to remove NTFS junction '%s'', keeping '%s'.",
|
||||||
|
qPrintable(fi.fileName()), qPrintable(QDir::toNativeSeparators(m_dir.path())));
|
||||||
|
m_dir.setAutoRemove(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QCOMPARE(actualIsSymLink, isSymLink);
|
||||||
if (isSymLink) {
|
if (isSymLink) {
|
||||||
QCOMPARE(fi.symLinkTarget(), linkTarget);
|
QCOMPARE(actualSymLinkTarget, linkTarget);
|
||||||
QCOMPARE(fi.canonicalFilePath(), canonicalFilePath);
|
QCOMPARE(actualCanonicalFilePath, canonicalFilePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user