2
Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
4
This library is free software; you can redistribute it and/or modify it
5
under the terms of the GNU Library General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or (at your
7
option) any later version.
9
This library is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12
License for more details.
14
You should have received a copy of the GNU Library General Public License
15
along with this library; see the file COPYING.LIB. If not, write to the
16
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22
#include <qtest_kde.h>
23
#include <qtestevent.h>
25
#include "dynamictreemodel.h"
26
#include "../modeltest.h"
27
#include "../descendantentitiesproxymodel.h"
28
#include "proxymodeltest.h"
31
// #include "fakemonitor.h"
37
using namespace Akonadi;
40
class DescendantEntitiesProxyModelTest : public ProxyModelTest
44
DescendantEntitiesProxyModelTest( QObject *parent = 0 )
45
: ProxyModelTest( parent )
50
QVariantList getSignal(SignalType type, int start, int end)
52
return ProxyModelTest::getSignal(type, IndexFinder(), start, end);
55
void signalInsertion(const QString &name, int startRow, int rowsAffected)
57
ProxyModelTest::signalInsertion(name, IndexFinder(), startRow, rowsAffected, m_rowCount);
58
m_rowCount += rowsAffected;
61
void signalRemoval(const QString &name, int startRow, int rowsAffected)
63
ProxyModelTest::signalRemoval(name, IndexFinder(), startRow, rowsAffected, m_rowCount);
64
m_rowCount -= rowsAffected;
67
PersistentIndexChange getChange(int start, int end, int difference, bool toInvalid = false)
69
return ProxyModelTest::getChange(IndexFinder(), start, end, difference, toInvalid);
75
// TODO: Split these into tests in ProxyModelTest and initTestCase
76
void testInsertionChangeAndRemoval();
77
void testSameParentUp();
78
void testSameParentDown();
79
void testDifferentParentUp();
80
void testDifferentParentDown();
81
void testDifferentParentSameLevel();
82
void testInsertionWithDescendants();
85
DescendantEntitiesProxyModel *m_proxyModel;
86
IndexFinder m_rootIdxFinder;
91
void DescendantEntitiesProxyModelTest::initTestCase()
93
m_proxyModel = new DescendantEntitiesProxyModel(this);
94
setProxyModel(m_proxyModel);
96
QList<QVariantList> signalList;
97
QVariantList expected;
98
QList<PersistentIndexChange> persistentList;
101
int rowsInserted = 1;
103
signalInsertion("insert01", startRow, rowsInserted);
107
signalInsertion("insert02", startRow, rowsInserted);
110
signalInsertion("insert03", startRow, rowsInserted);
113
signalInsertion("insert04", startRow, rowsInserted);
116
signalInsertion("insert05", startRow, rowsInserted);
119
signalInsertion("insert06", startRow, rowsInserted);
122
signalInsertion("insert07", startRow, rowsInserted);
124
int accumulatedChange = 0;
126
signalList << getSignal(RowsAboutToBeInserted, startRow, startRow + rowsInserted - 1);
127
signalList << getSignal(RowsInserted, startRow, startRow + rowsInserted - 1);
128
accumulatedChange += 10;
131
signalList << getSignal(RowsAboutToBeInserted, startRow, startRow + rowsInserted - 1);
132
signalList << getSignal(RowsInserted, startRow, startRow + rowsInserted - 1);
133
accumulatedChange += 10;
136
signalList << getSignal(RowsAboutToBeInserted, startRow, startRow + rowsInserted - 1);
137
signalList << getSignal(RowsInserted, startRow, startRow + rowsInserted - 1);
138
accumulatedChange += 10;
139
persistentList << getChange(17, 17, accumulatedChange);
142
signalList << getSignal(RowsAboutToBeInserted, startRow, startRow + rowsInserted - 1);
143
signalList << getSignal(RowsInserted, startRow, startRow + rowsInserted - 1);
144
accumulatedChange += 10;
145
persistentList << getChange(18, 18, accumulatedChange);
148
signalList << getSignal(RowsAboutToBeInserted, startRow, startRow + rowsInserted - 1);
149
signalList << getSignal(RowsInserted, startRow, startRow + rowsInserted - 1);
150
accumulatedChange += 10;
152
persistentList << getChange(19, m_rowCount - 1, accumulatedChange);
154
setExpected("insert08", signalList, persistentList);
156
persistentList.clear();
157
m_rowCount += accumulatedChange;
161
signalRemoval("remove01", startRow, rowsRemoved);
165
signalRemoval("remove02", startRow, rowsRemoved);
169
signalRemoval("remove03", startRow, rowsRemoved);
172
signalRemoval("remove04", startRow, rowsRemoved);
175
signalRemoval("remove05", startRow, rowsRemoved);
179
signalRemoval("remove06", startRow, rowsRemoved);
183
signalRemoval("remove07", startRow, rowsRemoved);
188
void DescendantEntitiesProxyModelTest::testInsertionChangeAndRemoval()
190
DynamicTreeModel *model = new DynamicTreeModel(this);
192
DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
193
proxy->setSourceModel(model);
196
QList<int> ancestorRows;
198
ModelInsertCommand *ins;
200
for (int i = 0; i < max_runs; i++)
202
ins = new ModelInsertCommand(model, this);
203
ins->setAncestorRowNumbers(ancestorRows);
210
ModelDataChangeCommand *mch;
211
mch = new ModelDataChangeCommand(model, this);
240
ModelRemoveCommand *rem;
241
rem = new ModelRemoveCommand(model, this);
246
// If we get this far, modeltest didn't assert.
250
void DescendantEntitiesProxyModelTest::testSameParentDown()
252
DynamicTreeModel *model = new DynamicTreeModel(this);
254
DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
255
proxy->setSourceModel(model);
257
QList<int> ancestorRows;
259
ModelInsertCommand *ins;
261
for (int i = 0; i < max_runs; i++)
263
ins = new ModelInsertCommand(model, this);
264
ins->setAncestorRowNumbers(ancestorRows);
271
ModelMoveCommand *mmc;
272
mmc = new ModelMoveCommand(model, this);
281
void DescendantEntitiesProxyModelTest::testSameParentUp()
283
DynamicTreeModel *model = new DynamicTreeModel(this);
285
DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
286
proxy->setSourceModel(model);
288
QList<int> ancestorRows;
290
ModelInsertCommand *ins;
291
ins = new ModelInsertCommand(model, this);
292
ins->setAncestorRowNumbers(ancestorRows);
297
ModelMoveCommand *mmc;
299
mmc = new ModelMoveCommand(model, this);
305
mmc = new ModelMoveCommand(model, this);
311
mmc = new ModelMoveCommand(model, this);
317
mmc = new ModelMoveCommand(model, this);
323
mmc = new ModelMoveCommand(model, this);
332
void DescendantEntitiesProxyModelTest::testDifferentParentUp()
334
DynamicTreeModel *model = new DynamicTreeModel(this);
336
DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
337
proxy->setSourceModel(model);
339
QList<int> ancestorRows;
341
ModelInsertCommand *ins;
343
for (int i = 0; i < max_runs; i++)
345
ins = new ModelInsertCommand(model, this);
346
ins->setAncestorRowNumbers(ancestorRows);
353
ancestorRows.clear();
356
ModelMoveCommand *mmc;
357
mmc = new ModelMoveCommand(model, this);
358
mmc->setDestAncestors(ancestorRows);
367
void DescendantEntitiesProxyModelTest::testDifferentParentDown()
369
DynamicTreeModel *model = new DynamicTreeModel(this);
371
DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
372
proxy->setSourceModel(model);
374
QList<int> ancestorRows;
376
ModelInsertCommand *ins;
378
for (int i = 0; i < max_runs; i++)
380
ins = new ModelInsertCommand(model, this);
381
ins->setAncestorRowNumbers(ancestorRows);
388
ancestorRows.clear();
391
ModelMoveCommand *mmc;
392
mmc = new ModelMoveCommand(model, this);
393
mmc->setDestAncestors(ancestorRows);
402
void DescendantEntitiesProxyModelTest::testDifferentParentSameLevel()
404
DynamicTreeModel *model = new DynamicTreeModel(this);
406
DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
407
proxy->setSourceModel(model);
409
QList<int> ancestorRows;
411
ModelInsertCommand *ins;
413
for (int i = 0; i < max_runs; i++)
415
ins = new ModelInsertCommand(model, this);
416
ins->setAncestorRowNumbers(ancestorRows);
423
ancestorRows.clear();
426
ModelMoveCommand *mmc;
428
mmc = new ModelMoveCommand(model, this);
429
mmc->setDestAncestors(ancestorRows);
439
void DescendantEntitiesProxyModelTest::testInsertionWithDescendants()
441
DynamicTreeModel *model = new DynamicTreeModel(this);
443
DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
444
proxy->setSourceModel(model);
446
// First insert 4 items to the root.
447
ModelInsertCommand *ins = new ModelInsertCommand(model, this);
452
ModelInsertWithDescendantsCommand *insDesc = new ModelInsertWithDescendantsCommand(model, this);
453
QList<QPair<int, int> > descs;
454
QPair<int, int> pair;
455
pair.first = 1; // On the first row,
456
pair.second = 4; // insert 4 items.
458
pair.first = 2; // Make the 6th new item
459
pair.second = 5; // have 5 descendants itself.
461
insDesc->setNumDescendants(descs);
462
insDesc->doCommand();
468
QTEST_KDEMAIN(DescendantEntitiesProxyModelTest, GUI)
469
#include "descendantentitiesproxymodeltest.moc"