]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tests/testdir.cpp
8938e6082acf2b70353a7803c21135f55e3fb86f
1 /*****************************************************************************
2 * Copyright (C) 2010-2011 by Frank Reininghaus (frank78ac@googlemail.com) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 *****************************************************************************/
27 #include <sys/utime.h>
30 TestDir::TestDir(const QString
& directoryPrefix
) :
31 KTempDir(directoryPrefix
)
39 KUrl
TestDir::url() const
44 /** The following function is taken from kdelibs/kio/tests/kiotesthelper.h, copyright (C) 2006 by David Faure */
45 static void setTimeStamp(const QString
& path
, const QDateTime
& mtime
)
49 utbuf
.actime
= mtime
.toTime_t();
50 utbuf
.modtime
= utbuf
.actime
;
51 utime(QFile::encodeName(path
), &utbuf
);
52 #elif defined(Q_OS_WIN)
53 struct _utimbuf utbuf
;
54 utbuf
.actime
= mtime
.toTime_t();
55 utbuf
.modtime
= utbuf
.actime
;
56 _wutime(reinterpret_cast<const wchar_t *>(path
.utf16()), &utbuf
);
60 void TestDir::createFile(const QString
& path
, const QByteArray
& data
, const QDateTime
& time
)
62 QString absolutePath
= path
;
63 makePathAbsoluteAndCreateParents(absolutePath
);
65 QFile
f(absolutePath
);
66 f
.open(QIODevice::WriteOnly
);
71 setTimeStamp(absolutePath
, time
);
74 Q_ASSERT(QFile::exists(absolutePath
));
77 void TestDir::createFiles(const QStringList
& files
)
79 foreach (const QString
& path
, files
) {
84 void TestDir::createDir(const QString
& path
, const QDateTime
& time
)
86 QString absolutePath
= path
;
87 makePathAbsoluteAndCreateParents(absolutePath
);
88 QDir(name()).mkdir(absolutePath
);
91 setTimeStamp(absolutePath
, time
);
94 Q_ASSERT(QFile::exists(absolutePath
));
97 void TestDir::removeFile(const QString
& path
)
99 QString absolutePath
= path
;
100 QFileInfo
fileInfo(absolutePath
);
101 if (!fileInfo
.isAbsolute()) {
102 absolutePath
= name() + path
;
104 QFile::remove(absolutePath
);
107 void TestDir::makePathAbsoluteAndCreateParents(QString
& path
)
109 QFileInfo
fileInfo(path
);
110 if (!fileInfo
.isAbsolute()) {
111 path
= name() + path
;
112 fileInfo
.setFile(path
);
115 const QDir dir
= fileInfo
.dir();
117 createDir(dir
.absolutePath());
120 Q_ASSERT(dir
.exists());