~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/akonadi_next/tests/descendantentitiesproxymodeltest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2009 Stephen Kelly <steveire@gmail.com>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
    02110-1301, USA.
 
18
*/
 
19
 
 
20
#include <QtTest>
 
21
#include <QtCore>
 
22
#include <qtest_kde.h>
 
23
#include <qtestevent.h>
 
24
 
 
25
#include "dynamictreemodel.h"
 
26
#include "../modeltest.h"
 
27
#include "../descendantentitiesproxymodel.h"
 
28
#include "proxymodeltest.h"
 
29
 
 
30
 
 
31
// #include "fakemonitor.h"
 
32
 
 
33
#include <QTreeView>
 
34
 
 
35
#include <kdebug.h>
 
36
 
 
37
using namespace Akonadi;
 
38
 
 
39
 
 
40
class DescendantEntitiesProxyModelTest : public ProxyModelTest
 
41
{
 
42
  Q_OBJECT
 
43
public:
 
44
  DescendantEntitiesProxyModelTest( QObject *parent = 0 )
 
45
      : ProxyModelTest( parent )
 
46
  {
 
47
  }
 
48
 
 
49
  protected:
 
50
    QVariantList getSignal(SignalType type, int start, int end)
 
51
    {
 
52
      return ProxyModelTest::getSignal(type, IndexFinder(), start, end);
 
53
    }
 
54
 
 
55
    void signalInsertion(const QString &name, int startRow, int rowsAffected)
 
56
    {
 
57
      ProxyModelTest::signalInsertion(name, IndexFinder(), startRow, rowsAffected, m_rowCount);
 
58
      m_rowCount += rowsAffected;
 
59
    }
 
60
 
 
61
    void signalRemoval(const QString &name, int startRow, int rowsAffected)
 
62
    {
 
63
      ProxyModelTest::signalRemoval(name, IndexFinder(), startRow, rowsAffected, m_rowCount);
 
64
      m_rowCount -= rowsAffected;
 
65
    }
 
66
 
 
67
    PersistentIndexChange getChange(int start, int end, int difference, bool toInvalid = false)
 
68
    {
 
69
      return ProxyModelTest::getChange(IndexFinder(), start, end, difference, toInvalid);
 
70
    }
 
71
 
 
72
private slots:
 
73
  void initTestCase();
 
74
 
 
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();
 
83
 
 
84
private:
 
85
  DescendantEntitiesProxyModel *m_proxyModel;
 
86
  IndexFinder m_rootIdxFinder;
 
87
  int m_rowCount;
 
88
};
 
89
 
 
90
 
 
91
void DescendantEntitiesProxyModelTest::initTestCase()
 
92
{
 
93
  m_proxyModel = new DescendantEntitiesProxyModel(this);
 
94
  setProxyModel(m_proxyModel);
 
95
 
 
96
  QList<QVariantList> signalList;
 
97
  QVariantList expected;
 
98
  QList<PersistentIndexChange> persistentList;
 
99
  m_rowCount = 0;
 
100
  int startRow = 0;
 
101
  int rowsInserted = 1;
 
102
 
 
103
  signalInsertion("insert01", startRow, rowsInserted);
 
104
 
 
105
  startRow = 1;
 
106
  rowsInserted = 10;
 
107
  signalInsertion("insert02", startRow, rowsInserted);
 
108
 
 
109
  startRow = 0;
 
110
  signalInsertion("insert03", startRow, rowsInserted);
 
111
 
 
112
  startRow = 21;
 
113
  signalInsertion("insert04", startRow, rowsInserted);
 
114
 
 
115
  startRow = 11;
 
116
  signalInsertion("insert05", startRow, rowsInserted);
 
117
 
 
118
  startRow = 31;
 
119
  signalInsertion("insert06", startRow, rowsInserted);
 
120
 
 
121
  startRow = 21;
 
122
  signalInsertion("insert07", startRow, rowsInserted);
 
123
 
 
124
  int accumulatedChange = 0;
 
125
  startRow = 17;
 
126
  signalList << getSignal(RowsAboutToBeInserted, startRow, startRow + rowsInserted - 1);
 
127
  signalList << getSignal(RowsInserted, startRow, startRow + rowsInserted - 1);
 
128
  accumulatedChange += 10;
 
129
 
 
130
  startRow = 23;
 
131
  signalList << getSignal(RowsAboutToBeInserted, startRow, startRow + rowsInserted - 1);
 
132
  signalList << getSignal(RowsInserted, startRow, startRow + rowsInserted - 1);
 
133
  accumulatedChange += 10;
 
134
 
 
135
  startRow = 29;
 
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);
 
140
 
 
141
  startRow = 48;
 
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);
 
146
 
 
147
  startRow = 59;
 
148
  signalList << getSignal(RowsAboutToBeInserted, startRow, startRow + rowsInserted - 1);
 
149
  signalList << getSignal(RowsInserted, startRow, startRow + rowsInserted - 1);
 
150
  accumulatedChange += 10;
 
151
 
 
152
  persistentList << getChange(19, m_rowCount - 1, accumulatedChange);
 
153
 
 
154
  setExpected("insert08", signalList, persistentList);
 
155
  signalList.clear();
 
156
  persistentList.clear();
 
157
  m_rowCount += accumulatedChange;
 
158
 
 
159
  startRow = 11;
 
160
  int rowsRemoved = 1;
 
161
  signalRemoval("remove01", startRow, rowsRemoved);
 
162
 
 
163
  startRow = 57;
 
164
  rowsRemoved = 11;
 
165
  signalRemoval("remove02", startRow, rowsRemoved);
 
166
 
 
167
  startRow = 47;
 
168
  rowsRemoved = 1;
 
169
  signalRemoval("remove03", startRow, rowsRemoved);
 
170
 
 
171
  startRow = 55;
 
172
  signalRemoval("remove04", startRow, rowsRemoved);
 
173
 
 
174
  startRow = 50;
 
175
  signalRemoval("remove05", startRow, rowsRemoved);
 
176
 
 
177
  startRow = 47;
 
178
  rowsRemoved = 7;
 
179
  signalRemoval("remove06", startRow, rowsRemoved);
 
180
 
 
181
  startRow = 15;
 
182
  rowsRemoved = 31;
 
183
  signalRemoval("remove07", startRow, rowsRemoved);
 
184
 
 
185
}
 
186
 
 
187
 
 
188
void DescendantEntitiesProxyModelTest::testInsertionChangeAndRemoval()
 
189
{
 
190
  DynamicTreeModel *model = new DynamicTreeModel(this);
 
191
 
 
192
  DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
 
193
  proxy->setSourceModel(model);
 
194
 
 
195
 
 
196
  QList<int> ancestorRows;
 
197
 
 
198
  ModelInsertCommand *ins;
 
199
  int max_runs = 2;
 
200
  for (int i = 0; i < max_runs; i++)
 
201
  {
 
202
    ins = new ModelInsertCommand(model, this);
 
203
    ins->setAncestorRowNumbers(ancestorRows);
 
204
    ins->setStartRow(0);
 
205
    ins->setEndRow(9);
 
206
    ins->doCommand();
 
207
    ancestorRows << 2;
 
208
  }
 
209
 
 
210
  ModelDataChangeCommand *mch;
 
211
  mch = new ModelDataChangeCommand(model, this);
 
212
  mch->setStartRow(0);
 
213
  mch->setEndRow(4);
 
214
  mch->doCommand();
 
215
 
 
216
  // Item 0-0
 
217
  // Item 1-0
 
218
  // Item 2-0
 
219
  // Item 3-0
 
220
  // Item 4-0
 
221
 
 
222
  // Item 0-0
 
223
  // Item 2-0
 
224
  // Item 3-0
 
225
  // Item 1-0
 
226
  // Item 4-0
 
227
//   2, 3 -1
 
228
//   1 2
 
229
 
 
230
  // Item 0-0
 
231
  // Item 3-0
 
232
  // Item 1-0
 
233
  // Item 2-0
 
234
  // Item 4-0
 
235
// 3 -2
 
236
// 1,2 +1
 
237
 
 
238
 
 
239
 
 
240
  ModelRemoveCommand *rem;
 
241
  rem = new ModelRemoveCommand(model, this);
 
242
  rem->setStartRow(2);
 
243
  rem->setEndRow(2);
 
244
  rem->doCommand();
 
245
 
 
246
  // If we get this far, modeltest didn't assert.
 
247
  QVERIFY(true);
 
248
}
 
249
 
 
250
void DescendantEntitiesProxyModelTest::testSameParentDown()
 
251
{
 
252
  DynamicTreeModel *model = new DynamicTreeModel(this);
 
253
 
 
254
  DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
 
255
  proxy->setSourceModel(model);
 
256
 
 
257
  QList<int> ancestorRows;
 
258
 
 
259
  ModelInsertCommand *ins;
 
260
  int max_runs = 1;
 
261
  for (int i = 0; i < max_runs; i++)
 
262
  {
 
263
    ins = new ModelInsertCommand(model, this);
 
264
    ins->setAncestorRowNumbers(ancestorRows);
 
265
    ins->setStartRow(0);
 
266
    ins->setEndRow(9);
 
267
    ins->doCommand();
 
268
    ancestorRows << 2;
 
269
  }
 
270
 
 
271
  ModelMoveCommand *mmc;
 
272
  mmc = new ModelMoveCommand(model, this);
 
273
  mmc->setStartRow(3);
 
274
  mmc->setEndRow(5);
 
275
  mmc->setDestRow(8);
 
276
  mmc->doCommand();
 
277
 
 
278
  QVERIFY(true);
 
279
}
 
280
 
 
281
void DescendantEntitiesProxyModelTest::testSameParentUp()
 
282
{
 
283
  DynamicTreeModel *model = new DynamicTreeModel(this);
 
284
 
 
285
  DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
 
286
  proxy->setSourceModel(model);
 
287
 
 
288
  QList<int> ancestorRows;
 
289
 
 
290
  ModelInsertCommand *ins;
 
291
  ins = new ModelInsertCommand(model, this);
 
292
  ins->setAncestorRowNumbers(ancestorRows);
 
293
  ins->setStartRow(0);
 
294
  ins->setEndRow(9);
 
295
  ins->doCommand();
 
296
 
 
297
  ModelMoveCommand *mmc;
 
298
 
 
299
  mmc = new ModelMoveCommand(model, this);
 
300
  mmc->setStartRow(8);
 
301
  mmc->setEndRow(8);
 
302
  mmc->setDestRow(1);
 
303
  mmc->doCommand();
 
304
 
 
305
  mmc = new ModelMoveCommand(model, this);
 
306
  mmc->setStartRow(7);
 
307
  mmc->setEndRow(8);
 
308
  mmc->setDestRow(1);
 
309
  mmc->doCommand();
 
310
 
 
311
  mmc = new ModelMoveCommand(model, this);
 
312
  mmc->setStartRow(6);
 
313
  mmc->setEndRow(8);
 
314
  mmc->setDestRow(1);
 
315
  mmc->doCommand();
 
316
 
 
317
  mmc = new ModelMoveCommand(model, this);
 
318
  mmc->setStartRow(5);
 
319
  mmc->setEndRow(8);
 
320
  mmc->setDestRow(1);
 
321
  mmc->doCommand();
 
322
 
 
323
  mmc = new ModelMoveCommand(model, this);
 
324
  mmc->setStartRow(4);
 
325
  mmc->setEndRow(8);
 
326
  mmc->setDestRow(1);
 
327
  mmc->doCommand();
 
328
 
 
329
  QVERIFY(true);
 
330
}
 
331
 
 
332
void DescendantEntitiesProxyModelTest::testDifferentParentUp()
 
333
{
 
334
  DynamicTreeModel *model = new DynamicTreeModel(this);
 
335
 
 
336
  DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
 
337
  proxy->setSourceModel(model);
 
338
 
 
339
  QList<int> ancestorRows;
 
340
 
 
341
  ModelInsertCommand *ins;
 
342
  int max_runs = 2;
 
343
  for (int i = 0; i < max_runs; i++)
 
344
  {
 
345
    ins = new ModelInsertCommand(model, this);
 
346
    ins->setAncestorRowNumbers(ancestorRows);
 
347
    ins->setStartRow(0);
 
348
    ins->setEndRow(9);
 
349
    ins->doCommand();
 
350
    ancestorRows << 2;
 
351
  }
 
352
 
 
353
  ancestorRows.clear();
 
354
  ancestorRows << 2;
 
355
 
 
356
  ModelMoveCommand *mmc;
 
357
  mmc = new ModelMoveCommand(model, this);
 
358
  mmc->setDestAncestors(ancestorRows);
 
359
  mmc->setStartRow(7);
 
360
  mmc->setEndRow(8);
 
361
  mmc->setDestRow(1);
 
362
  mmc->doCommand();
 
363
 
 
364
  QVERIFY(true);
 
365
}
 
366
 
 
367
void DescendantEntitiesProxyModelTest::testDifferentParentDown()
 
368
{
 
369
  DynamicTreeModel *model = new DynamicTreeModel(this);
 
370
 
 
371
  DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
 
372
  proxy->setSourceModel(model);
 
373
 
 
374
  QList<int> ancestorRows;
 
375
 
 
376
  ModelInsertCommand *ins;
 
377
  int max_runs = 2;
 
378
  for (int i = 0; i < max_runs; i++)
 
379
  {
 
380
    ins = new ModelInsertCommand(model, this);
 
381
    ins->setAncestorRowNumbers(ancestorRows);
 
382
    ins->setStartRow(0);
 
383
    ins->setEndRow(9);
 
384
    ins->doCommand();
 
385
    ancestorRows << 2;
 
386
  }
 
387
 
 
388
  ancestorRows.clear();
 
389
  ancestorRows << 2;
 
390
 
 
391
  ModelMoveCommand *mmc;
 
392
  mmc = new ModelMoveCommand(model, this);
 
393
  mmc->setDestAncestors(ancestorRows);
 
394
  mmc->setStartRow(6);
 
395
  mmc->setEndRow(7);
 
396
  mmc->setDestRow(9);
 
397
  mmc->doCommand();
 
398
 
 
399
  QVERIFY(true);
 
400
}
 
401
 
 
402
void DescendantEntitiesProxyModelTest::testDifferentParentSameLevel()
 
403
{
 
404
  DynamicTreeModel *model = new DynamicTreeModel(this);
 
405
 
 
406
  DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
 
407
  proxy->setSourceModel(model);
 
408
 
 
409
  QList<int> ancestorRows;
 
410
 
 
411
  ModelInsertCommand *ins;
 
412
  int max_runs = 2;
 
413
  for (int i = 0; i < max_runs; i++)
 
414
  {
 
415
    ins = new ModelInsertCommand(model, this);
 
416
    ins->setAncestorRowNumbers(ancestorRows);
 
417
    ins->setStartRow(0);
 
418
    ins->setEndRow(9);
 
419
    ins->doCommand();
 
420
    ancestorRows << 2;
 
421
  }
 
422
 
 
423
  ancestorRows.clear();
 
424
  ancestorRows << 2;
 
425
 
 
426
  ModelMoveCommand *mmc;
 
427
 
 
428
  mmc = new ModelMoveCommand(model, this);
 
429
  mmc->setDestAncestors(ancestorRows);
 
430
  mmc->setStartRow(6);
 
431
  mmc->setEndRow(7);
 
432
  mmc->setDestRow(6);
 
433
  mmc->doCommand();
 
434
 
 
435
  QVERIFY(true);
 
436
 
 
437
}
 
438
 
 
439
void DescendantEntitiesProxyModelTest::testInsertionWithDescendants()
 
440
{
 
441
  DynamicTreeModel *model = new DynamicTreeModel(this);
 
442
 
 
443
  DescendantEntitiesProxyModel *proxy = new DescendantEntitiesProxyModel(this);
 
444
  proxy->setSourceModel(model);
 
445
 
 
446
  // First insert 4 items to the root.
 
447
  ModelInsertCommand *ins = new ModelInsertCommand(model, this);
 
448
  ins->setStartRow(0);
 
449
  ins->setEndRow(3);
 
450
  ins->doCommand();
 
451
 
 
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.
 
457
  descs << pair;
 
458
  pair.first = 2;   // Make the 6th new item
 
459
  pair.second = 5;  // have 5 descendants itself.
 
460
  descs << pair;
 
461
  insDesc->setNumDescendants(descs);
 
462
  insDesc->doCommand();
 
463
 
 
464
  QVERIFY(true);
 
465
}
 
466
 
 
467
 
 
468
QTEST_KDEMAIN(DescendantEntitiesProxyModelTest, GUI)
 
469
#include "descendantentitiesproxymodeltest.moc"