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 "historymodeltest.moc"
27
#include <kfileplacesmodel.h>
29
#include <qtest_kde.h>
32
#include "../lib/historymodel.h"
34
QTEST_KDEMAIN(HistoryModelTest, GUI)
36
using namespace Gwenview;
38
void testModel(const HistoryModel& model, const KUrl& u1, const KUrl& u2) {
41
QCOMPARE(model.rowCount(), 2);
43
index = model.index(0, 0);
44
QVERIFY(index.isValid());
45
url = model.data(index, KFilePlacesModel::UrlRole).value<QUrl>();
48
index = model.index(1, 0);
49
QVERIFY(index.isValid());
50
url = model.data(index, KFilePlacesModel::UrlRole).value<QUrl>();
55
void HistoryModelTest::testAddUrl() {
56
KUrl u1 = KUrl::fromPath("/home");
57
QDateTime d1 = QDateTime::fromString("2008-02-03T12:34:56", Qt::ISODate);
58
KUrl u2 = KUrl::fromPath("/root");
59
QDateTime d2 = QDateTime::fromString("2009-01-29T23:01:47", Qt::ISODate);
62
HistoryModel model(0, dir.name());
65
testModel(model, u2, u1);
68
HistoryModel model(0, dir.name());
69
testModel(model, u2, u1);
71
// Make u1 the most recent
72
QDateTime d3 = QDateTime::fromString("2009-03-24T22:42:15", Qt::ISODate);
74
testModel(model, u1, u2);
77
void HistoryModelTest::testGarbageCollect() {
78
KUrl u1 = KUrl::fromPath("/home");
79
QDateTime d1 = QDateTime::fromString("2008-02-03T12:34:56", Qt::ISODate);
80
KUrl u2 = KUrl::fromPath("/root");
81
QDateTime d2 = QDateTime::fromString("2009-01-29T23:01:47", Qt::ISODate);
82
KUrl u3 = KUrl::fromPath("/usr");
83
QDateTime d3 = QDateTime::fromString("2009-03-24T22:42:15", Qt::ISODate);
87
HistoryModel model(0, dir.name(), 2);
90
testModel(model, u2, u1);
94
// Create a model with a larger history so that if garbage collecting fails
95
// to remove the collected url, the size of the model won't pass
97
HistoryModel model(0, dir.name(), 10);
98
testModel(model, u3, u2);
101
void HistoryModelTest::testRemoveRows() {
102
KUrl u1 = KUrl::fromPath("/home");
103
QDateTime d1 = QDateTime::fromString("2008-02-03T12:34:56", Qt::ISODate);
104
KUrl u2 = KUrl::fromPath("/root");
105
QDateTime d2 = QDateTime::fromString("2009-01-29T23:01:47", Qt::ISODate);
108
HistoryModel model(0, dir.name(), 2);
109
model.addUrl(u1, d1);
110
model.addUrl(u2, d2);
111
model.removeRows(0, 1);
112
QCOMPARE(model.rowCount(), 1);
113
QDir qDir(dir.name());
114
QCOMPARE(qDir.entryList(QDir::Files | QDir::NoDotAndDotDot).count(), 1);