]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tests/testbase.cpp
1 /***************************************************************************
2 * Copyright (C) 2010 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>
38 m_tempDir
= new KTempDir
;
39 Q_ASSERT(m_tempDir
->exists());
40 m_path
= m_tempDir
->name();
41 m_dir
= new QDir(m_path
);
42 m_view
= new DolphinView(KUrl(m_path
), 0);
52 QAbstractItemView
* TestBase::itemView () const
54 return m_view
->m_viewAccessor
.itemView();
57 void TestBase::reloadViewAndWait()
60 QVERIFY(QTest::kWaitForSignal(m_view
, SIGNAL(finishedPathLoading(const KUrl
&)), 2000));
63 KUrl
TestBase::testDirUrl() const
68 void TestBase::createFile(const QString
& path
, const QByteArray
& data
)
70 QString absolutePath
= path
;
71 makePathAbsoluteAndCreateParents(absolutePath
);
73 QFile
f(absolutePath
);
74 f
.open(QIODevice::WriteOnly
);
78 Q_ASSERT(QFile::exists(absolutePath
));
81 void TestBase::createFiles(const QStringList
& files
)
83 foreach(const QString
& path
, files
) {
88 void TestBase::createDir(const QString
& path
)
90 QString absolutePath
= path
;
91 makePathAbsoluteAndCreateParents(absolutePath
);
92 m_dir
->mkdir(absolutePath
);
94 Q_ASSERT(QFile::exists(absolutePath
));
97 void TestBase::makePathAbsoluteAndCreateParents(QString
& path
)
99 QFileInfo
fileInfo(path
);
100 if (!fileInfo
.isAbsolute()) {
101 path
= m_path
+ path
;
102 fileInfo
.setFile(path
);
105 const QDir dir
= fileInfo
.dir();
107 createDir(dir
.absolutePath());
110 Q_ASSERT(dir
.exists());
113 void TestBase::cleanupTestDir()
116 m_tempDir
= new KTempDir
;
117 Q_ASSERT(m_tempDir
->exists());
118 m_path
= m_tempDir
->name();
119 m_dir
->setPath(m_path
);
120 m_view
->setUrl(m_path
);