]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tests/testbase.cpp
2161c9314c4ca6b7a18d3850e31e538da121371a
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_dirLister
= new DolphinDirLister();
43 m_dirLister
->setAutoUpdate(true);
44 m_dolphinModel
= new DolphinModel();
45 m_dolphinModel
->setDirLister(m_dirLister
);
46 m_proxyModel
= new DolphinSortFilterProxyModel(0);
47 m_proxyModel
->setSourceModel(m_dolphinModel
);
48 m_proxyModel
->setFilterCaseSensitivity(Qt::CaseInsensitive
);
49 m_view
= new DolphinView(0, KUrl(m_path
), m_proxyModel
);
56 // m_dolphinModel owns m_dirLister -> do not delete it here!
57 delete m_dolphinModel
;
62 QAbstractItemView
* TestBase::itemView () const
64 return m_view
->m_viewAccessor
.itemView();
67 void TestBase::reloadViewAndWait()
70 QVERIFY(QTest::kWaitForSignal(m_view
, SIGNAL(finishedPathLoading(const KUrl
&)), 5000));
73 KUrl
TestBase::testDirUrl() const
78 void TestBase::createFile(const QString
& path
, const QByteArray
& data
)
80 QString absolutePath
= path
;
81 makePathAbsoluteAndCreateParents(absolutePath
);
83 QFile
f(absolutePath
);
84 f
.open(QIODevice::WriteOnly
);
88 Q_ASSERT(QFile::exists(absolutePath
));
91 void TestBase::createFiles(const QStringList
& files
)
93 foreach(const QString
& path
, files
) {
98 void TestBase::createDir(const QString
& path
)
100 QString absolutePath
= path
;
101 makePathAbsoluteAndCreateParents(absolutePath
);
102 m_dir
->mkdir(absolutePath
);
104 Q_ASSERT(QFile::exists(absolutePath
));
107 void TestBase::makePathAbsoluteAndCreateParents(QString
& path
)
109 QFileInfo
fileInfo(path
);
110 if (!fileInfo
.isAbsolute()) {
111 path
= m_path
+ path
;
112 fileInfo
.setFile(path
);
115 const QDir dir
= fileInfo
.dir();
117 createDir(dir
.absolutePath());
120 Q_ASSERT(dir
.exists());
123 void TestBase::cleanupTestDir()
126 m_tempDir
= new KTempDir
;
127 Q_ASSERT(m_tempDir
->exists());
128 m_path
= m_tempDir
->name();
129 m_dir
->setPath(m_path
);
130 m_view
->setUrl(m_path
);