~ubuntu-branches/ubuntu/maverick/kdegraphics/maverick-proposed

« back to all changes in this revision

Viewing changes to gwenview/tests/historymodeltest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2009-12-02 14:03:43 UTC
  • mfrom: (1.1.35 upstream)
  • Revision ID: james.westby@ubuntu.com-20091202140343-2732gbkj69g89arq
Tags: 4:4.3.80-0ubuntu1
* New upstream beta release:
  - Add build-depend on shared-desktop-ontologies for nepomuk integration
  - Bump .so versions for libkexiv, libkdcraw and libkipi
  - Update various .install files

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 "historymodeltest.moc"
 
21
 
 
22
// Qt
 
23
#include <QDir>
 
24
 
 
25
// KDE
 
26
#include <kdebug.h>
 
27
#include <kfileplacesmodel.h>
 
28
#include <ktempdir.h>
 
29
#include <qtest_kde.h>
 
30
 
 
31
// Local
 
32
#include "../lib/historymodel.h"
 
33
 
 
34
QTEST_KDEMAIN(HistoryModelTest, GUI)
 
35
 
 
36
using namespace Gwenview;
 
37
 
 
38
void testModel(const HistoryModel& model, const KUrl& u1, const KUrl& u2) {
 
39
        QModelIndex index;
 
40
        KUrl url;
 
41
        QCOMPARE(model.rowCount(), 2);
 
42
 
 
43
        index = model.index(0, 0);
 
44
        QVERIFY(index.isValid());
 
45
        url = model.data(index, KFilePlacesModel::UrlRole).value<QUrl>();
 
46
        QCOMPARE(url, u1);
 
47
 
 
48
        index = model.index(1, 0);
 
49
        QVERIFY(index.isValid());
 
50
        url = model.data(index, KFilePlacesModel::UrlRole).value<QUrl>();
 
51
        QCOMPARE(url, u2);
 
52
 
 
53
}
 
54
 
 
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);
 
60
        KTempDir dir;
 
61
        {
 
62
                HistoryModel model(0, dir.name());
 
63
                model.addUrl(u1, d1);
 
64
                model.addUrl(u2, d2);
 
65
                testModel(model, u2, u1);
 
66
        }
 
67
 
 
68
        HistoryModel model(0, dir.name());
 
69
        testModel(model, u2, u1);
 
70
 
 
71
        // Make u1 the most recent
 
72
        QDateTime d3 = QDateTime::fromString("2009-03-24T22:42:15", Qt::ISODate);
 
73
        model.addUrl(u1, d3);
 
74
        testModel(model, u1, u2);
 
75
}
 
76
 
 
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);
 
84
 
 
85
        KTempDir dir;
 
86
        {
 
87
                HistoryModel model(0, dir.name(), 2);
 
88
                model.addUrl(u1, d1);
 
89
                model.addUrl(u2, d2);
 
90
                testModel(model, u2, u1);
 
91
                model.addUrl(u3, d3);
 
92
        }
 
93
 
 
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
 
96
        // testModel()
 
97
        HistoryModel model(0, dir.name(), 10);
 
98
        testModel(model, u3, u2);
 
99
}
 
100
 
 
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);
 
106
 
 
107
        KTempDir dir;
 
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);
 
115
}