~ubuntu-branches/ubuntu/precise/gwenview/precise-proposed

« back to all changes in this revision

Viewing changes to tests/placetreemodeltest.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20111215141754-z043hyx69dulbggf
Tags: upstream-4.7.90
Import upstream version 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
Gwenview: an image viewer
3
 
Copyright 2009 Aurélien Gâteau <agateau@kde.org>
4
 
 
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.
9
 
 
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.
14
 
 
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.
18
 
 
19
 
*/
20
 
#include "placetreemodeltest.moc"
21
 
 
22
 
// Qt
23
 
#include <QDir>
24
 
#include <QFile>
25
 
 
26
 
// KDE
27
 
#include <kdebug.h>
28
 
#include <kstandarddirs.h>
29
 
#include <qtest_kde.h>
30
 
 
31
 
// Local
32
 
#include "../lib/placetreemodel.h"
33
 
 
34
 
#define KEEP_TEMP_DIR
35
 
 
36
 
QTEST_KDEMAIN(PlaceTreeModelTest, GUI)
37
 
 
38
 
using namespace Gwenview;
39
 
 
40
 
const char* BOOKMARKS_XML =
41
 
"<?xml version='1.0' encoding='UTF-8'?>"
42
 
"<!DOCTYPE xbel>"
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>"
46
 
"  <info>"
47
 
"   <metadata owner='http://freedesktop.org' >"
48
 
"    <bookmark:icon name='user-home' />"
49
 
"   </metadata>"
50
 
"   <metadata owner='http://www.kde.org' >"
51
 
"    <ID>1214343736/0</ID>"
52
 
"    <isSystemItem>true</isSystemItem>"
53
 
"   </metadata>"
54
 
"  </info>"
55
 
" </bookmark>"
56
 
" <bookmark href='%2' >"
57
 
"  <title>url2</title>"
58
 
"  <info>"
59
 
"   <metadata owner='http://freedesktop.org' >"
60
 
"    <bookmark:icon name='user-home' />"
61
 
"   </metadata>"
62
 
"   <metadata owner='http://www.kde.org' >"
63
 
"    <ID>1214343736/1</ID>"
64
 
"    <isSystemItem>true</isSystemItem>"
65
 
"   </metadata>"
66
 
"  </info>"
67
 
" </bookmark>"
68
 
"</xbel>";
69
 
 
70
 
 
71
 
void PlaceTreeModelTest::initTestCase() {
72
 
        Q_ASSERT(mTempDir.exists());
73
 
        QDir dir(mTempDir.name());
74
 
 
75
 
        Q_ASSERT(dir.mkdir("url1"));
76
 
        mUrl1 = KUrl::fromPath(dir.filePath("url1"));
77
 
 
78
 
        Q_ASSERT(dir.mkdir("url2"));
79
 
        mUrl2 = KUrl::fromPath(dir.filePath("url2"));
80
 
 
81
 
        mUrl1Dirs << "aaa" << "zzz" << "bbb";
82
 
        Q_FOREACH(const QString& dirName, mUrl1Dirs) {
83
 
                dir.mkdir("url1/" + dirName);
84
 
        }
85
 
 
86
 
        QFile bookmark(KStandardDirs::locateLocal("data", "kfileplaces/bookmarks.xml"));
87
 
        Q_ASSERT(bookmark.open(QIODevice::WriteOnly));
88
 
 
89
 
        QString xml = QString(BOOKMARKS_XML)
90
 
                .arg(mUrl1.toLocalFile())
91
 
                .arg(mUrl2.toLocalFile())
92
 
                ;
93
 
        bookmark.write(xml.toUtf8());
94
 
 
95
 
#ifdef KEEP_TEMP_DIR
96
 
        mTempDir.setAutoRemove(false);
97
 
        kDebug() << "mTempDir:" << mTempDir.name();
98
 
#endif
99
 
}
100
 
 
101
 
 
102
 
void PlaceTreeModelTest::testListPlaces() {
103
 
        PlaceTreeModel model(0);
104
 
        QCOMPARE(model.rowCount(), 2);
105
 
 
106
 
        QModelIndex index;
107
 
        index = model.index(0, 0);
108
 
        QCOMPARE(model.urlForIndex(index), mUrl1);
109
 
        index = model.index(1, 0);
110
 
        QCOMPARE(model.urlForIndex(index), mUrl2);
111
 
}
112
 
 
113
 
 
114
 
void PlaceTreeModelTest::testListUrl1() {
115
 
        PlaceTreeModel model(0);
116
 
 
117
 
        QModelIndex index = model.index(0, 0);
118
 
        QCOMPARE(model.urlForIndex(index), mUrl1);
119
 
 
120
 
        // We should not have fetched content yet
121
 
        QCOMPARE(model.rowCount(index), 0);
122
 
        QVERIFY(model.canFetchMore(index));
123
 
 
124
 
        while (model.canFetchMore(index)) {
125
 
                model.fetchMore(index);
126
 
        }
127
 
        QTest::qWait(1000);
128
 
        QCOMPARE(model.rowCount(index), mUrl1Dirs.length());
129
 
 
130
 
        QStringList dirs = mUrl1Dirs;
131
 
        dirs.sort();
132
 
 
133
 
        for (int row = 0; row < dirs.count(); ++row) {
134
 
                QModelIndex subIndex = model.index(row, 0, index);
135
 
                QVERIFY(subIndex.isValid());
136
 
 
137
 
                QString dirName = model.data(subIndex).toString();
138
 
                QCOMPARE(dirName, dirs.value(row));
139
 
        }
140
 
}