]>
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 "views/dolphinview.h"
23 #include "views/dolphinmodel.h"
24 #include "views/dolphindirlister.h"
25 #include "views/dolphinsortfilterproxymodel.h"
29 #include <QtCore/QDir>
30 #include <QtGui/QAbstractItemView>
34 m_tempDir
= new KTempDir
;
35 Q_ASSERT(m_tempDir
->exists());
36 m_path
= m_tempDir
->name();
37 m_dir
= new QDir(m_path
);
38 m_dirLister
= new DolphinDirLister();
39 m_dirLister
->setAutoUpdate(true);
40 m_dolphinModel
= new DolphinModel();
41 m_dolphinModel
->setDirLister(m_dirLister
);
42 m_proxyModel
= new DolphinSortFilterProxyModel(0);
43 m_proxyModel
->setSourceModel(m_dolphinModel
);
44 m_proxyModel
->setFilterCaseSensitivity(Qt::CaseInsensitive
);
45 m_view
= new DolphinView(0, KUrl(m_path
), m_proxyModel
);
52 // m_dolphinModel owns m_dirLister -> do not delete it here!
53 delete m_dolphinModel
;
58 QAbstractItemView
* TestBase::itemView () const
60 return m_view
->m_viewAccessor
.itemView();
64 KUrl
TestBase::testDirUrl() const
69 void TestBase::createFile(const QString
& path
, const QByteArray
& data
)
71 QString absolutePath
= path
;
72 makePathAbsoluteAndCreateParents(absolutePath
);
74 QFile
f(absolutePath
);
75 f
.open(QIODevice::WriteOnly
);
79 Q_ASSERT(QFile::exists(absolutePath
));
82 void TestBase::createFiles(const QStringList
& files
)
84 foreach(const QString
& path
, files
) {
89 void TestBase::createDir(const QString
& path
)
91 QString absolutePath
= path
;
92 makePathAbsoluteAndCreateParents(absolutePath
);
93 m_dir
->mkdir(absolutePath
);
95 Q_ASSERT(QFile::exists(absolutePath
));
98 void TestBase::makePathAbsoluteAndCreateParents(QString
& path
)
100 QFileInfo
fileInfo(path
);
101 if (!fileInfo
.isAbsolute()) {
102 path
= m_path
+ path
;
103 fileInfo
.setFile(path
);
106 const QDir dir
= fileInfo
.dir();
108 createDir(dir
.absolutePath());
111 Q_ASSERT(dir
.exists());
114 void TestBase::cleanupTestDir()
117 m_tempDir
= new KTempDir
;
118 Q_ASSERT(m_tempDir
->exists());
119 m_path
= m_tempDir
->name();
120 m_dir
->setPath(m_path
);
121 m_view
->setUrl(m_path
);