2
* Copyright 2013 Canonical Ltd.
4
* This file is part of webbrowser-app.
6
* webbrowser-app is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 3.
10
* webbrowser-app 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, see <http://www.gnu.org/licenses/>.
20
#include <QtTest/QSignalSpy>
21
#include <QtTest/QtTest>
24
#include "history-model.h"
25
#include "history-timeframe-model.h"
28
class HistoryTimeframeModelTests : public QObject
34
HistoryTimeframeModel* timeframe;
39
model = new HistoryModel;
40
model->setDatabasePath(":memory:");
41
timeframe = new HistoryTimeframeModel;
42
timeframe->setSourceModel(model);
51
void shouldBeInitiallyEmpty()
53
QCOMPARE(timeframe->rowCount(), 0);
56
void shouldNotifyWhenChangingSourceModel()
58
QSignalSpy spy(timeframe, SIGNAL(sourceModelChanged()));
59
timeframe->setSourceModel(model);
60
QVERIFY(spy.isEmpty());
61
HistoryModel* model2 = new HistoryModel;
62
timeframe->setSourceModel(model2);
63
QCOMPARE(spy.count(), 1);
64
QCOMPARE(timeframe->sourceModel(), model2);
65
timeframe->setSourceModel(0);
66
QCOMPARE(spy.count(), 2);
67
QCOMPARE(timeframe->sourceModel(), (HistoryModel*) 0);
71
void shouldNotifyWhenChangingStart()
73
QSignalSpy spy(timeframe, SIGNAL(startChanged()));
74
QDateTime start = QDateTime::currentDateTimeUtc();
75
timeframe->setStart(start);
76
QCOMPARE(timeframe->start(), start);
77
QCOMPARE(spy.count(), 1);
78
timeframe->setStart(start);
79
QCOMPARE(spy.count(), 1);
81
timeframe->setStart(QDateTime::currentDateTimeUtc());
82
QCOMPARE(spy.count(), 2);
83
timeframe->setStart(QDateTime());
84
QCOMPARE(spy.count(), 3);
87
void shouldNotifyWhenChangingEnd()
89
QSignalSpy spy(timeframe, SIGNAL(endChanged()));
90
QDateTime end = QDateTime::currentDateTimeUtc();
91
timeframe->setEnd(end);
92
QCOMPARE(timeframe->end(), end);
93
QCOMPARE(spy.count(), 1);
94
timeframe->setEnd(end);
95
QCOMPARE(spy.count(), 1);
97
timeframe->setEnd(QDateTime::currentDateTimeUtc());
98
QCOMPARE(spy.count(), 2);
99
timeframe->setEnd(QDateTime());
100
QCOMPARE(spy.count(), 3);
103
void shouldMatchAllWhenNoBoundsSet()
105
model->add(QUrl("http://example.org"), "Example Domain", QUrl());
107
model->add(QUrl("http://example.com"), "Example Domain", QUrl());
108
QCOMPARE(timeframe->rowCount(), 2);
111
void shouldFilterOutOlderEntries()
113
model->add(QUrl("http://example.org"), "Example Domain", QUrl());
115
QDateTime start = QDateTime::currentDateTimeUtc();
117
model->add(QUrl("http://example.com"), "Example Domain", QUrl());
118
QCOMPARE(timeframe->rowCount(), 2);
119
timeframe->setStart(start);
120
QCOMPARE(timeframe->rowCount(), 1);
121
QCOMPARE(timeframe->data(timeframe->index(0, 0), HistoryModel::Url).toUrl(),
122
QUrl("http://example.com"));
125
void shouldFilterOutMoreRecentEntries()
127
model->add(QUrl("http://example.org"), "Example Domain", QUrl());
129
QDateTime end = QDateTime::currentDateTimeUtc();
131
model->add(QUrl("http://example.com"), "Example Domain", QUrl());
132
QCOMPARE(timeframe->rowCount(), 2);
133
timeframe->setEnd(end);
134
QCOMPARE(timeframe->rowCount(), 1);
135
QCOMPARE(timeframe->data(timeframe->index(0, 0), HistoryModel::Url).toUrl(),
136
QUrl("http://example.org"));
139
void shouldFilterOutOlderAndMoreRecentEntries()
141
model->add(QUrl("http://example.org"), "Example Domain", QUrl());
143
QDateTime start = QDateTime::currentDateTimeUtc();
145
model->add(QUrl("http://ubuntu.com"), "Ubuntu", QUrl());
147
QDateTime end = QDateTime::currentDateTimeUtc();
149
model->add(QUrl("http://example.com"), "Example Domain", QUrl());
150
QCOMPARE(timeframe->rowCount(), 3);
151
timeframe->setStart(start);
152
timeframe->setEnd(end);
153
QCOMPARE(timeframe->rowCount(), 1);
154
QCOMPARE(timeframe->data(timeframe->index(0, 0), HistoryModel::Url).toUrl(),
155
QUrl("http://ubuntu.com"));
159
QTEST_MAIN(HistoryTimeframeModelTests)
160
#include "tst_HistoryTimeframeModelTests.moc"