]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tests/testbase.cpp
1cb326766c71984a50ff19b92fef17f2fb76b2f2
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 *****************************************************************************/
22 #include <qtest_kde.h>
24 #include "views/dolphinview.h"
25 #include "views/dolphinmodel.h"
26 #include "views/dolphindirlister.h"
27 #include "views/dolphinsortfilterproxymodel.h"
31 #include <QtCore/QDir>
32 #include <QtGui/QAbstractItemView>
39 #include <sys/utime.h>
44 m_tempDir
= new KTempDir
;
45 Q_ASSERT(m_tempDir
->exists());
46 m_path
= m_tempDir
->name();
47 m_dir
= new QDir(m_path
);
48 m_view
= new DolphinView(KUrl(m_path
), 0);
58 QAbstractItemView
* TestBase::itemView() const
60 return m_view
->m_viewAccessor
.itemView();
63 void TestBase::reloadViewAndWait()
66 QVERIFY(QTest::kWaitForSignal(m_view
, SIGNAL(finishedPathLoading(const KUrl
&)), 2000));
69 KUrl
TestBase::testDirUrl() const
74 /** The following function is taken from kdelibs/kio/tests/kiotesthelper.h, copyright (C) 2006 by David Faure */
76 static void setTimeStamp(const QString
& path
, const QDateTime
& mtime
)
80 utbuf
.actime
= mtime
.toTime_t();
81 utbuf
.modtime
= utbuf
.actime
;
82 utime(QFile::encodeName(path
), &utbuf
);
83 #elif defined(Q_OS_WIN)
84 struct _utimbuf utbuf
;
85 utbuf
.actime
= mtime
.toTime_t();
86 utbuf
.modtime
= utbuf
.actime
;
87 _wutime(reinterpret_cast<const wchar_t *>(path
.utf16()), &utbuf
);
91 void TestBase::createFile(const QString
& path
, const QByteArray
& data
, const QDateTime
& time
)
93 QString absolutePath
= path
;
94 makePathAbsoluteAndCreateParents(absolutePath
);
96 QFile
f(absolutePath
);
97 f
.open(QIODevice::WriteOnly
);
101 if (time
.isValid()) {
102 setTimeStamp(absolutePath
, time
);
105 Q_ASSERT(QFile::exists(absolutePath
));
108 void TestBase::createFiles(const QStringList
& files
)
110 foreach(const QString
& path
, files
) {
115 void TestBase::createDir(const QString
& path
, const QDateTime
& time
)
117 QString absolutePath
= path
;
118 makePathAbsoluteAndCreateParents(absolutePath
);
119 m_dir
->mkdir(absolutePath
);
121 if (time
.isValid()) {
122 setTimeStamp(absolutePath
, time
);
125 Q_ASSERT(QFile::exists(absolutePath
));
128 QStringList
TestBase::viewItems() const
130 QStringList itemList
;
131 const QAbstractItemModel
* model
= itemView()->model();
133 for (int row
= 0; row
< model
->rowCount(); row
++) {
134 itemList
<< model
->data(model
->index(row
, 0), Qt::DisplayRole
).toString();
140 void TestBase::makePathAbsoluteAndCreateParents(QString
& path
)
142 QFileInfo
fileInfo(path
);
143 if (!fileInfo
.isAbsolute()) {
144 path
= m_path
+ path
;
145 fileInfo
.setFile(path
);
148 const QDir dir
= fileInfo
.dir();
150 createDir(dir
.absolutePath());
153 Q_ASSERT(dir
.exists());
156 void TestBase::cleanupTestDir()
159 m_tempDir
= new KTempDir
;
160 Q_ASSERT(m_tempDir
->exists());
161 m_path
= m_tempDir
->name();
162 m_dir
->setPath(m_path
);
163 m_view
->setUrl(m_path
);