2
Gwenview: an image viewer
3
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License
7
as published by the Free Software Foundation; either version 2
8
of the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "placetreemodeltest.moc"
28
#include <kstandarddirs.h>
29
#include <qtest_kde.h>
32
#include "../lib/placetreemodel.h"
36
QTEST_KDEMAIN(PlaceTreeModelTest, GUI)
38
using namespace Gwenview;
40
const char* BOOKMARKS_XML =
41
"<?xml version='1.0' encoding='UTF-8'?>"
43
"<xbel xmlns:bookmark='http://www.freedesktop.org/standards/desktop-bookmarks' xmlns:mime='http://www.freedesktop.org/standards/shared-mime-info' xmlns:kdepriv='http://www.kde.org/kdepriv' dbusName='kfilePlaces' >"
44
" <bookmark href='%1' >"
45
" <title>url1</title>"
47
" <metadata owner='http://freedesktop.org' >"
48
" <bookmark:icon name='user-home' />"
50
" <metadata owner='http://www.kde.org' >"
51
" <ID>1214343736/0</ID>"
52
" <isSystemItem>true</isSystemItem>"
56
" <bookmark href='%2' >"
57
" <title>url2</title>"
59
" <metadata owner='http://freedesktop.org' >"
60
" <bookmark:icon name='user-home' />"
62
" <metadata owner='http://www.kde.org' >"
63
" <ID>1214343736/1</ID>"
64
" <isSystemItem>true</isSystemItem>"
71
void PlaceTreeModelTest::initTestCase() {
72
Q_ASSERT(mTempDir.exists());
73
QDir dir(mTempDir.name());
75
Q_ASSERT(dir.mkdir("url1"));
76
mUrl1 = KUrl::fromPath(dir.filePath("url1"));
78
Q_ASSERT(dir.mkdir("url2"));
79
mUrl2 = KUrl::fromPath(dir.filePath("url2"));
81
mUrl1Dirs << "aaa" << "zzz" << "bbb";
82
Q_FOREACH(const QString& dirName, mUrl1Dirs) {
83
dir.mkdir("url1/" + dirName);
86
QFile bookmark(KStandardDirs::locateLocal("data", "kfileplaces/bookmarks.xml"));
87
Q_ASSERT(bookmark.open(QIODevice::WriteOnly));
89
QString xml = QString(BOOKMARKS_XML)
90
.arg(mUrl1.toLocalFile())
91
.arg(mUrl2.toLocalFile())
93
bookmark.write(xml.toUtf8());
96
mTempDir.setAutoRemove(false);
97
kDebug() << "mTempDir:" << mTempDir.name();
102
void PlaceTreeModelTest::testListPlaces() {
103
PlaceTreeModel model(0);
104
QCOMPARE(model.rowCount(), 2);
107
index = model.index(0, 0);
108
QCOMPARE(model.urlForIndex(index), mUrl1);
109
index = model.index(1, 0);
110
QCOMPARE(model.urlForIndex(index), mUrl2);
114
void PlaceTreeModelTest::testListUrl1() {
115
PlaceTreeModel model(0);
117
QModelIndex index = model.index(0, 0);
118
QCOMPARE(model.urlForIndex(index), mUrl1);
120
// We should not have fetched content yet
121
QCOMPARE(model.rowCount(index), 0);
122
QVERIFY(model.canFetchMore(index));
124
while (model.canFetchMore(index)) {
125
model.fetchMore(index);
128
QCOMPARE(model.rowCount(index), mUrl1Dirs.length());
130
QStringList dirs = mUrl1Dirs;
133
for (int row = 0; row < dirs.count(); ++row) {
134
QModelIndex subIndex = model.index(row, 0, index);
135
QVERIFY(subIndex.isValid());
137
QString dirName = model.data(subIndex).toString();
138
QCOMPARE(dirName, dirs.value(row));