]>
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>
30 /** The following function is taken from kdelibs/kio/tests/kiotesthelper.h, copyright (C) 2006 by David Faure */
32 static void setTimeStamp(const QString
& path
, const QDateTime
& mtime
)
36 utbuf
.actime
= mtime
.toTime_t();
37 utbuf
.modtime
= utbuf
.actime
;
38 utime(QFile::encodeName(path
), &utbuf
);
39 #elif defined(Q_OS_WIN)
40 struct _utimbuf utbuf
;
41 utbuf
.actime
= mtime
.toTime_t();
42 utbuf
.modtime
= utbuf
.actime
;
43 _wutime(reinterpret_cast<const wchar_t *>(path
.utf16()), &utbuf
);
47 void TestDir::createFile(const QString
& path
, const QByteArray
& data
, const QDateTime
& time
)
49 QString absolutePath
= path
;
50 makePathAbsoluteAndCreateParents(absolutePath
);
52 QFile
f(absolutePath
);
53 f
.open(QIODevice::WriteOnly
);
58 setTimeStamp(absolutePath
, time
);
61 Q_ASSERT(QFile::exists(absolutePath
));
64 void TestDir::createFiles(const QStringList
& files
)
66 foreach(const QString
& path
, files
) {
71 void TestDir::createDir(const QString
& path
, const QDateTime
& time
)
73 QString absolutePath
= path
;
74 makePathAbsoluteAndCreateParents(absolutePath
);
75 QDir(name()).mkdir(absolutePath
);
78 setTimeStamp(absolutePath
, time
);
81 Q_ASSERT(QFile::exists(absolutePath
));
84 void TestDir::makePathAbsoluteAndCreateParents(QString
& path
)
86 QFileInfo
fileInfo(path
);
87 if (!fileInfo
.isAbsolute()) {
89 fileInfo
.setFile(path
);
92 const QDir dir
= fileInfo
.dir();
94 createDir(dir
.absolutePath());
97 Q_ASSERT(dir
.exists());