]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/testbase.cpp
Fix implementation of DolphinView::invertSelection() which assures that DolphinView...
[dolphin.git] / src / tests / testbase.cpp
1 /***************************************************************************
2 * Copyright (C) 2010 by Frank Reininghaus (frank78ac@googlemail.com) *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "testbase.h"
21
22 #include <qtest_kde.h>
23
24 #include "views/dolphinview.h"
25 #include "views/dolphinmodel.h"
26 #include "views/dolphindirlister.h"
27 #include "views/dolphinsortfilterproxymodel.h"
28
29 #include <KTempDir>
30
31 #include <QtCore/QDir>
32 #include <QtGui/QAbstractItemView>
33
34 #include <kdebug.h>
35
36 TestBase::TestBase()
37 {
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);
43 }
44
45 TestBase::~TestBase()
46 {
47 delete m_view;
48 delete m_dir;
49 delete m_tempDir;
50 }
51
52 QAbstractItemView* TestBase::itemView () const
53 {
54 return m_view->m_viewAccessor.itemView();
55 }
56
57 void TestBase::reloadViewAndWait()
58 {
59 m_view->reload();
60 QVERIFY(QTest::kWaitForSignal(m_view, SIGNAL(finishedPathLoading(const KUrl&)), 2000));
61 }
62
63 KUrl TestBase::testDirUrl() const
64 {
65 return KUrl(m_path);
66 }
67
68 void TestBase::createFile(const QString& path, const QByteArray& data)
69 {
70 QString absolutePath = path;
71 makePathAbsoluteAndCreateParents(absolutePath);
72
73 QFile f(absolutePath);
74 f.open(QIODevice::WriteOnly);
75 f.write(data);
76 f.close();
77
78 Q_ASSERT(QFile::exists(absolutePath));
79 }
80
81 void TestBase::createFiles(const QStringList& files)
82 {
83 foreach(const QString& path, files) {
84 createFile(path);
85 }
86 }
87
88 void TestBase::createDir(const QString& path)
89 {
90 QString absolutePath = path;
91 makePathAbsoluteAndCreateParents(absolutePath);
92 m_dir->mkdir(absolutePath);
93
94 Q_ASSERT(QFile::exists(absolutePath));
95 }
96
97 void TestBase::makePathAbsoluteAndCreateParents(QString& path)
98 {
99 QFileInfo fileInfo(path);
100 if (!fileInfo.isAbsolute()) {
101 path = m_path + path;
102 fileInfo.setFile(path);
103 }
104
105 const QDir dir = fileInfo.dir();
106 if (!dir.exists()) {
107 createDir(dir.absolutePath());
108 }
109
110 Q_ASSERT(dir.exists());
111 }
112
113 void TestBase::cleanupTestDir()
114 {
115 delete m_tempDir;
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);
121 }