]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/tests/testdir.cpp
Merge remote-tracking branch 'origin/master' into kf6
[dolphin.git] / src / tests / testdir.cpp
index c05752171e7dd3b836d1ab3f771b22f327c15278..30ca6632ec12e63bb6a4368c1fba82004f846c07 100644 (file)
@@ -12,8 +12,8 @@
 #include <sys/utime.h>
 #endif
 
-TestDir::TestDir(const QString& directoryPrefix) :
-    QTemporaryDir(directoryPrefix)
+TestDir::TestDir(const QString &directoryPrefix)
+    QTemporaryDir(directoryPrefix)
 {
 }
 
@@ -27,7 +27,7 @@ QUrl TestDir::url() const
 }
 
 /** The following function is taken from kdelibs/kio/tests/kiotesthelper.h, copyright (C) 2006 by David Faure */
-static void setTimeStamp(const QString& path, const QDateTime& mtime)
+static void setTimeStamp(const QString &path, const QDateTime &mtime)
 {
 #ifdef Q_OS_UNIX
     struct utimbuf utbuf;
@@ -36,13 +36,13 @@ static void setTimeStamp(const QString& path, const QDateTime& mtime)
     utime(QFile::encodeName(path), &utbuf);
 #elif defined(Q_OS_WIN)
     struct _utimbuf utbuf;
-    utbuf.actime = mtime.toTime_t();
+    utbuf.actime = mtime.toSecsSinceEpoch();
     utbuf.modtime = utbuf.actime;
     _wutime(reinterpret_cast<const wchar_t *>(path.utf16()), &utbuf);
 #endif
 }
 
-void TestDir::createFile(const QString& path, const QByteArray& data, const QDateTime& time)
+void TestDir::createFile(const QString &path, const QByteArray &data, const QDateTime &time)
 {
     QString absolutePath = path;
     makePathAbsoluteAndCreateParents(absolutePath);
@@ -59,14 +59,14 @@ void TestDir::createFile(const QString& path, const QByteArray& data, const QDat
     Q_ASSERT(QFile::exists(absolutePath));
 }
 
-void TestDir::createFiles(const QStringListfiles)
+void TestDir::createFiles(const QStringList &files)
 {
-    for (const QStringpath : files) {
+    for (const QString &path : files) {
         createFile(path);
     }
 }
 
-void TestDir::createDir(const QString& path, const QDateTime& time)
+void TestDir::createDir(const QString &path, const QDateTime &time)
 {
     QString absolutePath = path;
     makePathAbsoluteAndCreateParents(absolutePath);
@@ -79,14 +79,14 @@ void TestDir::createDir(const QString& path, const QDateTime& time)
     Q_ASSERT(QFile::exists(absolutePath));
 }
 
-void TestDir::removeFiles(const QStringListfiles)
+void TestDir::removeFiles(const QStringList &files)
 {
-    for (const QStringpath : files) {
+    for (const QString &path : files) {
         removeFile(path);
     }
 }
 
-void TestDir::removeFile(const QStringpath)
+void TestDir::removeFile(const QString &path)
 {
     QString absolutePath = path;
     QFileInfo fileInfo(absolutePath);
@@ -96,7 +96,18 @@ void TestDir::removeFile(const QString& path)
     QFile::remove(absolutePath);
 }
 
-void TestDir::makePathAbsoluteAndCreateParents(QString& path)
+void TestDir::removeDir(const QString &path)
+{
+    QString absolutePath = path;
+    QFileInfo fileInfo(absolutePath);
+    if (!fileInfo.isAbsolute()) {
+        absolutePath = TestDir::path() + QLatin1Char('/') + path;
+    }
+    QDir dirToRemove = QDir(absolutePath);
+    dirToRemove.removeRecursively();
+}
+
+void TestDir::makePathAbsoluteAndCreateParents(QString &path)
 {
     QFileInfo fileInfo(path);
     if (!fileInfo.isAbsolute()) {