]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tests/testdir.cpp
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>
38 KUrl
TestDir::url() const
43 /** The following function is taken from kdelibs/kio/tests/kiotesthelper.h, copyright (C) 2006 by David Faure */
44 static void setTimeStamp(const QString
& path
, const QDateTime
& mtime
)
48 utbuf
.actime
= mtime
.toTime_t();
49 utbuf
.modtime
= utbuf
.actime
;
50 utime(QFile::encodeName(path
), &utbuf
);
51 #elif defined(Q_OS_WIN)
52 struct _utimbuf utbuf
;
53 utbuf
.actime
= mtime
.toTime_t();
54 utbuf
.modtime
= utbuf
.actime
;
55 _wutime(reinterpret_cast<const wchar_t *>(path
.utf16()), &utbuf
);
59 void TestDir::createFile(const QString
& path
, const QByteArray
& data
, const QDateTime
& time
)
61 QString absolutePath
= path
;
62 makePathAbsoluteAndCreateParents(absolutePath
);
64 QFile
f(absolutePath
);
65 f
.open(QIODevice::WriteOnly
);
70 setTimeStamp(absolutePath
, time
);
73 Q_ASSERT(QFile::exists(absolutePath
));
76 void TestDir::createFiles(const QStringList
& files
)
78 foreach (const QString
& path
, files
) {
83 void TestDir::createDir(const QString
& path
, const QDateTime
& time
)
85 QString absolutePath
= path
;
86 makePathAbsoluteAndCreateParents(absolutePath
);
87 QDir(name()).mkdir(absolutePath
);
90 setTimeStamp(absolutePath
, time
);
93 Q_ASSERT(QFile::exists(absolutePath
));
96 void TestDir::removeFile(const QString
& path
)
98 QString absolutePath
= path
;
99 QFileInfo
fileInfo(absolutePath
);
100 if (!fileInfo
.isAbsolute()) {
101 absolutePath
= name() + path
;
103 QFile::remove(absolutePath
);
106 void TestDir::makePathAbsoluteAndCreateParents(QString
& path
)
108 QFileInfo
fileInfo(path
);
109 if (!fileInfo
.isAbsolute()) {
110 path
= name() + path
;
111 fileInfo
.setFile(path
);
114 const QDir dir
= fileInfo
.dir();
116 createDir(dir
.absolutePath());
119 Q_ASSERT(dir
.exists());