]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/kfileitemmodeltest.cpp
Do not select items when navigating back/forward with the mouse
[dolphin.git] / src / tests / kfileitemmodeltest.cpp
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2011 by Frank Reininghaus <frank78ac@googlemail.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (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 *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
20
21 #include <qtest_kde.h>
22
23 #include <KDirLister>
24 #include <kio/job.h>
25
26 #include "kitemviews/kfileitemmodel.h"
27 #include "kitemviews/private/kfileitemmodeldirlister.h"
28 #include "testdir.h"
29
30 void myMessageOutput(QtMsgType type, const char* msg)
31 {
32 switch (type) {
33 case QtDebugMsg:
34 break;
35 case QtWarningMsg:
36 break;
37 case QtCriticalMsg:
38 fprintf(stderr, "Critical: %s\n", msg);
39 break;
40 case QtFatalMsg:
41 fprintf(stderr, "Fatal: %s\n", msg);
42 abort();
43 default:
44 break;
45 }
46 }
47
48 namespace {
49 const int DefaultTimeout = 5000;
50 };
51
52 Q_DECLARE_METATYPE(KItemRangeList)
53 Q_DECLARE_METATYPE(QList<int>)
54
55 class KFileItemModelTest : public QObject
56 {
57 Q_OBJECT
58
59 private slots:
60 void init();
61 void cleanup();
62
63 void testDefaultRoles();
64 void testDefaultSortRole();
65 void testDefaultGroupedSorting();
66 void testNewItems();
67 void testRemoveItems();
68 void testDirLoadingCompleted();
69 void testSetData();
70 void testSetDataWithModifiedSortRole_data();
71 void testSetDataWithModifiedSortRole();
72 void testChangeSortRole();
73 void testResortAfterChangingName();
74 void testModelConsistencyWhenInsertingItems();
75 void testItemRangeConsistencyWhenInsertingItems();
76 void testExpandItems();
77 void testExpandParentItems();
78 void testMakeExpandedItemHidden();
79 void testRemoveFilteredExpandedItems();
80 void testSorting();
81 void testIndexForKeyboardSearch();
82 void testNameFilter();
83 void testEmptyPath();
84 void testRefreshExpandedItem();
85 void testRemoveHiddenItems();
86 void collapseParentOfHiddenItems();
87 void removeParentOfHiddenItems();
88 void testGeneralParentChildRelationships();
89 void testNameRoleGroups();
90 void testNameRoleGroupsWithExpandedItems();
91
92 private:
93 QStringList itemsInModel() const;
94
95 private:
96 KFileItemModel* m_model;
97 TestDir* m_testDir;
98 };
99
100 void KFileItemModelTest::init()
101 {
102 // The item-model tests result in a huge number of debugging
103 // output from kdelibs. Only show critical and fatal messages.
104 qInstallMsgHandler(myMessageOutput);
105
106 qRegisterMetaType<KItemRange>("KItemRange");
107 qRegisterMetaType<KItemRangeList>("KItemRangeList");
108 qRegisterMetaType<KFileItemList>("KFileItemList");
109
110 m_testDir = new TestDir();
111 m_model = new KFileItemModel();
112 m_model->m_dirLister->setAutoUpdate(false);
113
114 // Reduce the timer interval to make the test run faster.
115 m_model->m_resortAllItemsTimer->setInterval(0);
116 }
117
118 void KFileItemModelTest::cleanup()
119 {
120 delete m_model;
121 m_model = 0;
122
123 delete m_testDir;
124 m_testDir = 0;
125 }
126
127 void KFileItemModelTest::testDefaultRoles()
128 {
129 const QSet<QByteArray> roles = m_model->roles();
130 QCOMPARE(roles.count(), 3);
131 QVERIFY(roles.contains("text"));
132 QVERIFY(roles.contains("isDir"));
133 QVERIFY(roles.contains("isLink"));
134 }
135
136 void KFileItemModelTest::testDefaultSortRole()
137 {
138 QCOMPARE(m_model->sortRole(), QByteArray("text"));
139
140 QStringList files;
141 files << "c.txt" << "a.txt" << "b.txt";
142
143 m_testDir->createFiles(files);
144
145 m_model->loadDirectory(m_testDir->url());
146 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
147
148 QCOMPARE(m_model->count(), 3);
149 QCOMPARE(m_model->data(0)["text"].toString(), QString("a.txt"));
150 QCOMPARE(m_model->data(1)["text"].toString(), QString("b.txt"));
151 QCOMPARE(m_model->data(2)["text"].toString(), QString("c.txt"));
152 }
153
154 void KFileItemModelTest::testDefaultGroupedSorting()
155 {
156 QCOMPARE(m_model->groupedSorting(), false);
157 }
158
159 void KFileItemModelTest::testNewItems()
160 {
161 QStringList files;
162 files << "a.txt" << "b.txt" << "c.txt";
163 m_testDir->createFiles(files);
164
165 m_model->loadDirectory(m_testDir->url());
166 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
167
168 QCOMPARE(m_model->count(), 3);
169
170 QVERIFY(m_model->isConsistent());
171 }
172
173 void KFileItemModelTest::testRemoveItems()
174 {
175 m_testDir->createFile("a.txt");
176 m_testDir->createFile("b.txt");
177 m_model->loadDirectory(m_testDir->url());
178 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
179 QCOMPARE(m_model->count(), 2);
180 QVERIFY(m_model->isConsistent());
181
182 m_testDir->removeFile("a.txt");
183 m_model->m_dirLister->updateDirectory(m_testDir->url());
184 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsRemoved(KItemRangeList)), DefaultTimeout));
185 QCOMPARE(m_model->count(), 1);
186 QVERIFY(m_model->isConsistent());
187 }
188
189 void KFileItemModelTest::testDirLoadingCompleted()
190 {
191 QSignalSpy loadingCompletedSpy(m_model, SIGNAL(directoryLoadingCompleted()));
192 QSignalSpy itemsInsertedSpy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
193 QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
194
195 m_testDir->createFiles(QStringList() << "a.txt" << "b.txt" << "c.txt");
196
197 m_model->loadDirectory(m_testDir->url());
198 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout));
199 QCOMPARE(loadingCompletedSpy.count(), 1);
200 QCOMPARE(itemsInsertedSpy.count(), 1);
201 QCOMPARE(itemsRemovedSpy.count(), 0);
202 QCOMPARE(m_model->count(), 3);
203
204 m_testDir->createFiles(QStringList() << "d.txt" << "e.txt");
205 m_model->m_dirLister->updateDirectory(m_testDir->url());
206 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout));
207 QCOMPARE(loadingCompletedSpy.count(), 2);
208 QCOMPARE(itemsInsertedSpy.count(), 2);
209 QCOMPARE(itemsRemovedSpy.count(), 0);
210 QCOMPARE(m_model->count(), 5);
211
212 m_testDir->removeFile("a.txt");
213 m_testDir->createFile("f.txt");
214 m_model->m_dirLister->updateDirectory(m_testDir->url());
215 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout));
216 QCOMPARE(loadingCompletedSpy.count(), 3);
217 QCOMPARE(itemsInsertedSpy.count(), 3);
218 QCOMPARE(itemsRemovedSpy.count(), 1);
219 QCOMPARE(m_model->count(), 5);
220
221 m_testDir->removeFile("b.txt");
222 m_model->m_dirLister->updateDirectory(m_testDir->url());
223 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsRemoved(KItemRangeList)), DefaultTimeout));
224 QCOMPARE(loadingCompletedSpy.count(), 4);
225 QCOMPARE(itemsInsertedSpy.count(), 3);
226 QCOMPARE(itemsRemovedSpy.count(), 2);
227 QCOMPARE(m_model->count(), 4);
228
229 QVERIFY(m_model->isConsistent());
230 }
231
232 void KFileItemModelTest::testSetData()
233 {
234 m_testDir->createFile("a.txt");
235
236 m_model->loadDirectory(m_testDir->url());
237 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
238
239 QHash<QByteArray, QVariant> values;
240 values.insert("customRole1", "Test1");
241 values.insert("customRole2", "Test2");
242
243 QSignalSpy itemsChangedSpy(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)));
244 m_model->setData(0, values);
245 QCOMPARE(itemsChangedSpy.count(), 1);
246
247 values = m_model->data(0);
248 QCOMPARE(values.value("customRole1").toString(), QString("Test1"));
249 QCOMPARE(values.value("customRole2").toString(), QString("Test2"));
250 QVERIFY(m_model->isConsistent());
251 }
252
253 void KFileItemModelTest::testSetDataWithModifiedSortRole_data()
254 {
255 QTest::addColumn<int>("changedIndex");
256 QTest::addColumn<int>("changedRating");
257 QTest::addColumn<bool>("expectMoveSignal");
258 QTest::addColumn<int>("ratingIndex0");
259 QTest::addColumn<int>("ratingIndex1");
260 QTest::addColumn<int>("ratingIndex2");
261
262 // Default setup:
263 // Index 0 = rating 2
264 // Index 1 = rating 4
265 // Index 2 = rating 6
266
267 QTest::newRow("Index 0: Rating 3") << 0 << 3 << false << 3 << 4 << 6;
268 QTest::newRow("Index 0: Rating 5") << 0 << 5 << true << 4 << 5 << 6;
269 QTest::newRow("Index 0: Rating 8") << 0 << 8 << true << 4 << 6 << 8;
270
271 QTest::newRow("Index 2: Rating 1") << 2 << 1 << true << 1 << 2 << 4;
272 QTest::newRow("Index 2: Rating 3") << 2 << 3 << true << 2 << 3 << 4;
273 QTest::newRow("Index 2: Rating 5") << 2 << 5 << false << 2 << 4 << 5;
274 }
275
276 void KFileItemModelTest::testSetDataWithModifiedSortRole()
277 {
278 QFETCH(int, changedIndex);
279 QFETCH(int, changedRating);
280 QFETCH(bool, expectMoveSignal);
281 QFETCH(int, ratingIndex0);
282 QFETCH(int, ratingIndex1);
283 QFETCH(int, ratingIndex2);
284
285 // Changing the value of a sort-role must result in
286 // a reordering of the items.
287 QCOMPARE(m_model->sortRole(), QByteArray("text"));
288 m_model->setSortRole("rating");
289 QCOMPARE(m_model->sortRole(), QByteArray("rating"));
290
291 QStringList files;
292 files << "a.txt" << "b.txt" << "c.txt";
293 m_testDir->createFiles(files);
294
295 m_model->loadDirectory(m_testDir->url());
296 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
297
298 // Fill the "rating" role of each file:
299 // a.txt -> 2
300 // b.txt -> 4
301 // c.txt -> 6
302
303 QHash<QByteArray, QVariant> ratingA;
304 ratingA.insert("rating", 2);
305 m_model->setData(0, ratingA);
306
307 QHash<QByteArray, QVariant> ratingB;
308 ratingB.insert("rating", 4);
309 m_model->setData(1, ratingB);
310
311 QHash<QByteArray, QVariant> ratingC;
312 ratingC.insert("rating", 6);
313 m_model->setData(2, ratingC);
314
315 QCOMPARE(m_model->data(0).value("rating").toInt(), 2);
316 QCOMPARE(m_model->data(1).value("rating").toInt(), 4);
317 QCOMPARE(m_model->data(2).value("rating").toInt(), 6);
318
319 // Now change the rating from a.txt. This usually results
320 // in reordering of the items.
321 QHash<QByteArray, QVariant> rating;
322 rating.insert("rating", changedRating);
323 m_model->setData(changedIndex, rating);
324
325 if (expectMoveSignal) {
326 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)), DefaultTimeout));
327 }
328
329 QCOMPARE(m_model->data(0).value("rating").toInt(), ratingIndex0);
330 QCOMPARE(m_model->data(1).value("rating").toInt(), ratingIndex1);
331 QCOMPARE(m_model->data(2).value("rating").toInt(), ratingIndex2);
332 QVERIFY(m_model->isConsistent());
333 }
334
335 void KFileItemModelTest::testChangeSortRole()
336 {
337 QCOMPARE(m_model->sortRole(), QByteArray("text"));
338
339 QStringList files;
340 files << "a.txt" << "b.jpg" << "c.txt";
341 m_testDir->createFiles(files);
342
343 m_model->loadDirectory(m_testDir->url());
344 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
345 QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.jpg" << "c.txt");
346
347 // Simulate that KFileItemModelRolesUpdater determines the mime type.
348 // Resorting the files by 'type' will only work immediately if their
349 // mime types are known.
350 for (int index = 0; index < m_model->count(); ++index) {
351 m_model->fileItem(index).determineMimeType();
352 }
353
354 // Now: sort by type.
355 QSignalSpy spyItemsMoved(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)));
356 m_model->setSortRole("type");
357 QCOMPARE(m_model->sortRole(), QByteArray("type"));
358 QVERIFY(!spyItemsMoved.isEmpty());
359
360 // The actual order of the files might depend on the translation of the
361 // result of KFileItem::mimeComment() in the user's language.
362 QStringList version1;
363 version1 << "b.jpg" << "a.txt" << "c.txt";
364
365 QStringList version2;
366 version2 << "a.txt" << "c.txt" << "b.jpg";
367
368 const bool ok1 = (itemsInModel() == version1);
369 const bool ok2 = (itemsInModel() == version2);
370
371 QVERIFY(ok1 || ok2);
372 }
373
374 void KFileItemModelTest::testResortAfterChangingName()
375 {
376 // We sort by size in a directory where all files have the same size.
377 // Therefore, the files are sorted by their names.
378 m_model->setSortRole("size");
379
380 QStringList files;
381 files << "a.txt" << "b.txt" << "c.txt";
382 m_testDir->createFiles(files);
383
384 m_model->loadDirectory(m_testDir->url());
385 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
386 QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt");
387
388 // We rename a.txt to d.txt. Even though the size has not changed at all,
389 // the model must re-sort the items.
390 QHash<QByteArray, QVariant> data;
391 data.insert("text", "d.txt");
392 m_model->setData(0, data);
393
394 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)), DefaultTimeout));
395 QCOMPARE(itemsInModel(), QStringList() << "b.txt" << "c.txt" << "d.txt");
396
397 // We rename d.txt back to a.txt using the dir lister's refreshItems() signal.
398 const KFileItem fileItemD = m_model->fileItem(2);
399 KFileItem fileItemA = fileItemD;
400 KUrl urlA = fileItemA.url();
401 urlA.setFileName("a.txt");
402 fileItemA.setUrl(urlA);
403
404 m_model->slotRefreshItems(QList<QPair<KFileItem, KFileItem> >() << qMakePair(fileItemD, fileItemA));
405
406 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)), DefaultTimeout));
407 QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt");
408 }
409
410 void KFileItemModelTest::testModelConsistencyWhenInsertingItems()
411 {
412 //QSKIP("Temporary disabled", SkipSingle);
413
414 // KFileItemModel prevents that inserting a punch of items sequentially
415 // results in an itemsInserted()-signal for each item. Instead internally
416 // a timeout is given that collects such operations and results in only
417 // one itemsInserted()-signal. However in this test we want to stress
418 // KFileItemModel to do a lot of insert operation and hence decrease
419 // the timeout to 1 millisecond.
420 m_testDir->createFile("1");
421 m_model->loadDirectory(m_testDir->url());
422 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
423 QCOMPARE(m_model->count(), 1);
424
425 // Insert 10 items for 20 times. After each insert operation the model consistency
426 // is checked.
427 QSet<int> insertedItems;
428 for (int i = 0; i < 20; ++i) {
429 QSignalSpy spy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
430
431 for (int j = 0; j < 10; ++j) {
432 int itemName = qrand();
433 while (insertedItems.contains(itemName)) {
434 itemName = qrand();
435 }
436 insertedItems.insert(itemName);
437
438 m_testDir->createFile(QString::number(itemName));
439 }
440
441 m_model->m_dirLister->updateDirectory(m_testDir->url());
442 if (spy.count() == 0) {
443 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
444 }
445
446 QVERIFY(m_model->isConsistent());
447 }
448
449 QCOMPARE(m_model->count(), 201);
450 }
451
452 void KFileItemModelTest::testItemRangeConsistencyWhenInsertingItems()
453 {
454 QStringList files;
455 files << "B" << "E" << "G";
456 m_testDir->createFiles(files);
457
458 // Due to inserting the 3 items one item-range with index == 0 and
459 // count == 3 must be given
460 QSignalSpy spy1(m_model, SIGNAL(itemsInserted(KItemRangeList)));
461 m_model->loadDirectory(m_testDir->url());
462 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
463
464 QCOMPARE(spy1.count(), 1);
465 QList<QVariant> arguments = spy1.takeFirst();
466 KItemRangeList itemRangeList = arguments.at(0).value<KItemRangeList>();
467 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 3));
468
469 // The indexes of the item-ranges must always be related to the model before
470 // the items have been inserted. Having:
471 // 0 1 2
472 // B E G
473 // and inserting A, C, D, F the resulting model will be:
474 // 0 1 2 3 4 5 6
475 // A B C D E F G
476 // and the item-ranges must be:
477 // index: 0, count: 1 for A
478 // index: 1, count: 2 for B, C
479 // index: 2, count: 1 for G
480
481 files.clear();
482 files << "A" << "C" << "D" << "F";
483 m_testDir->createFiles(files);
484
485 QSignalSpy spy2(m_model, SIGNAL(itemsInserted(KItemRangeList)));
486 m_model->m_dirLister->updateDirectory(m_testDir->url());
487 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
488
489 QCOMPARE(spy2.count(), 1);
490 arguments = spy2.takeFirst();
491 itemRangeList = arguments.at(0).value<KItemRangeList>();
492 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 1) << KItemRange(1, 2) << KItemRange(2, 1));
493 }
494
495 void KFileItemModelTest::testExpandItems()
496 {
497 // Test expanding subfolders in a folder with the items "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1".
498 // Besides testing the basic item expansion functionality, the test makes sure that
499 // KFileItemModel::expansionLevelsCompare(const KFileItem& a, const KFileItem& b)
500 // yields the correct result for "a/a/1" and "a/a-1/", whis is non-trivial because they share the
501 // first three characters.
502 QSet<QByteArray> modelRoles = m_model->roles();
503 modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
504 m_model->setRoles(modelRoles);
505
506 QStringList files;
507 files << "a/a/1" << "a/a-1/1"; // missing folders are created automatically
508 m_testDir->createFiles(files);
509
510 // Store the URLs of all folders in a set.
511 QSet<KUrl> allFolders;
512 allFolders << KUrl(m_testDir->name() + 'a') << KUrl(m_testDir->name() + "a/a") << KUrl(m_testDir->name() + "a/a-1");
513
514 m_model->loadDirectory(m_testDir->url());
515 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
516
517 // So far, the model contains only "a/"
518 QCOMPARE(m_model->count(), 1);
519 QVERIFY(m_model->isExpandable(0));
520 QVERIFY(!m_model->isExpanded(0));
521 QVERIFY(m_model->expandedDirectories().empty());
522
523 QSignalSpy spyInserted(m_model, SIGNAL(itemsInserted(KItemRangeList)));
524
525 // Expand the folder "a/" -> "a/a/" and "a/a-1/" become visible
526 m_model->setExpanded(0, true);
527 QVERIFY(m_model->isExpanded(0));
528 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
529 QCOMPARE(m_model->count(), 3); // 3 items: "a/", "a/a/", "a/a-1/"
530 QCOMPARE(m_model->expandedDirectories(), QSet<KUrl>() << KUrl(m_testDir->name() + 'a'));
531
532 QCOMPARE(spyInserted.count(), 1);
533 KItemRangeList itemRangeList = spyInserted.takeFirst().at(0).value<KItemRangeList>();
534 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(1, 2)); // 2 new items "a/a/" and "a/a-1/" with indices 1 and 2
535
536 QVERIFY(m_model->isExpandable(1));
537 QVERIFY(!m_model->isExpanded(1));
538 QVERIFY(m_model->isExpandable(2));
539 QVERIFY(!m_model->isExpanded(2));
540
541 // Expand the folder "a/a/" -> "a/a/1" becomes visible
542 m_model->setExpanded(1, true);
543 QVERIFY(m_model->isExpanded(1));
544 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
545 QCOMPARE(m_model->count(), 4); // 4 items: "a/", "a/a/", "a/a/1", "a/a-1/"
546 QCOMPARE(m_model->expandedDirectories(), QSet<KUrl>() << KUrl(m_testDir->name() + 'a') << KUrl(m_testDir->name() + "a/a"));
547
548 QCOMPARE(spyInserted.count(), 1);
549 itemRangeList = spyInserted.takeFirst().at(0).value<KItemRangeList>();
550 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(2, 1)); // 1 new item "a/a/1" with index 2
551
552 QVERIFY(!m_model->isExpandable(2));
553 QVERIFY(!m_model->isExpanded(2));
554
555 // Expand the folder "a/a-1/" -> "a/a-1/1" becomes visible
556 m_model->setExpanded(3, true);
557 QVERIFY(m_model->isExpanded(3));
558 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
559 QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1"
560 QCOMPARE(m_model->expandedDirectories(), allFolders);
561
562 QCOMPARE(spyInserted.count(), 1);
563 itemRangeList = spyInserted.takeFirst().at(0).value<KItemRangeList>();
564 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(4, 1)); // 1 new item "a/a-1/1" with index 4
565
566 QVERIFY(!m_model->isExpandable(4));
567 QVERIFY(!m_model->isExpanded(4));
568
569 QSignalSpy spyRemoved(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
570
571 // Collapse the top-level folder -> all other items should disappear
572 m_model->setExpanded(0, false);
573 QVERIFY(!m_model->isExpanded(0));
574 QCOMPARE(m_model->count(), 1);
575 QVERIFY(!m_model->expandedDirectories().contains(KUrl(m_testDir->name() + 'a'))); // TODO: Make sure that child URLs are also removed
576
577 QCOMPARE(spyRemoved.count(), 1);
578 itemRangeList = spyRemoved.takeFirst().at(0).value<KItemRangeList>();
579 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(1, 4)); // 4 items removed
580 QVERIFY(m_model->isConsistent());
581
582 // Clear the model, reload the folder and try to restore the expanded folders.
583 m_model->clear();
584 QCOMPARE(m_model->count(), 0);
585 QVERIFY(m_model->expandedDirectories().empty());
586
587 m_model->loadDirectory(m_testDir->url());
588 m_model->restoreExpandedDirectories(allFolders);
589 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout));
590 QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1"
591 QVERIFY(m_model->isExpanded(0));
592 QVERIFY(m_model->isExpanded(1));
593 QVERIFY(!m_model->isExpanded(2));
594 QVERIFY(m_model->isExpanded(3));
595 QVERIFY(!m_model->isExpanded(4));
596 QCOMPARE(m_model->expandedDirectories(), allFolders);
597 QVERIFY(m_model->isConsistent());
598
599 // Move to a sub folder, then call restoreExpandedFolders() *before* going back.
600 // This is how DolphinView restores the expanded folders when navigating in history.
601 m_model->loadDirectory(KUrl(m_testDir->name() + "a/a/"));
602 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout));
603 QCOMPARE(m_model->count(), 1); // 1 item: "1"
604 m_model->restoreExpandedDirectories(allFolders);
605 m_model->loadDirectory(m_testDir->url());
606 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout));
607 QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1"
608 QCOMPARE(m_model->expandedDirectories(), allFolders);
609 }
610
611 void KFileItemModelTest::testExpandParentItems()
612 {
613 // Create a tree structure of folders:
614 // a 1/
615 // a 1/b1/
616 // a 1/b1/c1/
617 // a2/
618 // a2/b2/
619 // a2/b2/c2/
620 // a2/b2/c2/d2/
621 QSet<QByteArray> modelRoles = m_model->roles();
622 modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
623 m_model->setRoles(modelRoles);
624
625 QStringList files;
626 files << "a 1/b1/c1/file.txt" << "a2/b2/c2/d2/file.txt"; // missing folders are created automatically
627 m_testDir->createFiles(files);
628
629 m_model->loadDirectory(m_testDir->url());
630 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
631
632 // So far, the model contains only "a 1/" and "a2/".
633 QCOMPARE(m_model->count(), 2);
634 QVERIFY(m_model->expandedDirectories().empty());
635
636 // Expand the parents of "a2/b2/c2".
637 m_model->expandParentDirectories(KUrl(m_testDir->name() + "a2/b2/c2"));
638 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout));
639
640 // The model should now contain "a 1/", "a2/", "a2/b2/", and "a2/b2/c2/".
641 // It's important that only the parents of "a1/b1/c1" are expanded.
642 QCOMPARE(m_model->count(), 4);
643 QVERIFY(!m_model->isExpanded(0));
644 QVERIFY(m_model->isExpanded(1));
645 QVERIFY(m_model->isExpanded(2));
646 QVERIFY(!m_model->isExpanded(3));
647
648 // Expand the parents of "a 1/b1".
649 m_model->expandParentDirectories(KUrl(m_testDir->name() + "a 1/b1"));
650 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout));
651
652 // The model should now contain "a 1/", "a 1/b1/", "a2/", "a2/b2", and "a2/b2/c2/".
653 // It's important that only the parents of "a 1/b1/" and "a2/b2/c2/" are expanded.
654 QCOMPARE(m_model->count(), 5);
655 QVERIFY(m_model->isExpanded(0));
656 QVERIFY(!m_model->isExpanded(1));
657 QVERIFY(m_model->isExpanded(2));
658 QVERIFY(m_model->isExpanded(3));
659 QVERIFY(!m_model->isExpanded(4));
660 QVERIFY(m_model->isConsistent());
661 }
662
663 /**
664 * Renaming an expanded folder by prepending its name with a dot makes it
665 * hidden. Verify that this does not cause an inconsistent model state and
666 * a crash later on, see https://bugs.kde.org/show_bug.cgi?id=311947
667 */
668 void KFileItemModelTest::testMakeExpandedItemHidden()
669 {
670 QSet<QByteArray> modelRoles = m_model->roles();
671 modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
672 m_model->setRoles(modelRoles);
673
674 QStringList files;
675 m_testDir->createFile("1a/2a/3a");
676 m_testDir->createFile("1a/2a/3b");
677 m_testDir->createFile("1a/2b");
678 m_testDir->createFile("1b");
679
680 m_model->loadDirectory(m_testDir->url());
681 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
682
683 // So far, the model contains only "1a/" and "1b".
684 QCOMPARE(m_model->count(), 2);
685 m_model->setExpanded(0, true);
686 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
687
688 // Now "1a/2a" and "1a/2b" have appeared.
689 QCOMPARE(m_model->count(), 4);
690 m_model->setExpanded(1, true);
691 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
692 QCOMPARE(m_model->count(), 6);
693
694 // Rename "1a/2" and make it hidden.
695 const QString oldPath = m_model->fileItem(0).url().path() + "/2a";
696 const QString newPath = m_model->fileItem(0).url().path() + "/.2a";
697
698 KIO::SimpleJob* job = KIO::rename(oldPath, newPath, KIO::HideProgressInfo);
699 bool ok = job->exec();
700 QVERIFY(ok);
701 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsRemoved(KItemRangeList)), DefaultTimeout));
702
703 // "1a/2" and its subfolders have disappeared now.
704 QVERIFY(m_model->isConsistent());
705 QCOMPARE(m_model->count(), 3);
706
707 m_model->setExpanded(0, false);
708 QCOMPARE(m_model->count(), 2);
709
710 }
711
712 void KFileItemModelTest::testRemoveFilteredExpandedItems()
713 {
714 QSet<QByteArray> originalModelRoles = m_model->roles();
715 QSet<QByteArray> modelRoles = originalModelRoles;
716 modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
717 m_model->setRoles(modelRoles);
718
719 QStringList files;
720 files << "folder/child" << "file"; // missing folders are created automatically
721 m_testDir->createFiles(files);
722
723 m_model->loadDirectory(m_testDir->url());
724 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
725
726 // So far, the model contains only "folder/" and "file".
727 QCOMPARE(m_model->count(), 2);
728 QVERIFY(m_model->isExpandable(0));
729 QVERIFY(!m_model->isExpandable(1));
730 QVERIFY(!m_model->isExpanded(0));
731 QVERIFY(!m_model->isExpanded(1));
732 QCOMPARE(itemsInModel(), QStringList() << "folder" << "file");
733
734 // Expand "folder" -> "folder/child" becomes visible.
735 m_model->setExpanded(0, true);
736 QVERIFY(m_model->isExpanded(0));
737 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
738 QCOMPARE(itemsInModel(), QStringList() << "folder" << "child" << "file");
739
740 // Add a name filter.
741 m_model->setNameFilter("f");
742 QCOMPARE(itemsInModel(), QStringList() << "folder" << "file");
743
744 m_model->setNameFilter("fo");
745 QCOMPARE(itemsInModel(), QStringList() << "folder");
746
747 // Remove all expanded items by changing the roles
748 m_model->setRoles(originalModelRoles);
749 QVERIFY(!m_model->isExpanded(0));
750 QCOMPARE(itemsInModel(), QStringList() << "folder");
751
752 // Remove the name filter and verify that "folder/child" does not reappear.
753 m_model->setNameFilter(QString());
754 QCOMPARE(itemsInModel(), QStringList() << "folder" << "file");
755 }
756
757 void KFileItemModelTest::testSorting()
758 {
759 // Create some files with different sizes and modification times to check the different sorting options
760 QDateTime now = QDateTime::currentDateTime();
761
762 QSet<QByteArray> roles;
763 roles.insert("text");
764 roles.insert("isExpanded");
765 roles.insert("isExpandable");
766 roles.insert("expandedParentsCount");
767 m_model->setRoles(roles);
768
769 m_testDir->createDir("c/c-2");
770 m_testDir->createFile("c/c-2/c-3");
771 m_testDir->createFile("c/c-1");
772
773 m_testDir->createFile("a", "A file", now.addDays(-3));
774 m_testDir->createFile("b", "A larger file", now.addDays(0));
775 m_testDir->createDir("c", now.addDays(-2));
776 m_testDir->createFile("d", "The largest file in this directory", now.addDays(-1));
777 m_testDir->createFile("e", "An even larger file", now.addDays(-4));
778 m_testDir->createFile(".f");
779
780 m_model->loadDirectory(m_testDir->url());
781 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
782
783 int index = m_model->index(KUrl(m_testDir->url().url() + 'c'));
784 m_model->setExpanded(index, true);
785 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
786
787 index = m_model->index(KUrl(m_testDir->url().url() + "c/c-2"));
788 m_model->setExpanded(index, true);
789 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
790
791 // Default: Sort by Name, ascending
792 QCOMPARE(m_model->sortRole(), QByteArray("text"));
793 QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder);
794 QVERIFY(m_model->sortDirectoriesFirst());
795 QVERIFY(!m_model->showHiddenFiles());
796 QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "a" << "b" << "d" << "e");
797
798 QSignalSpy spyItemsMoved(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)));
799
800 // Sort by Name, ascending, 'Sort Folders First' disabled
801 m_model->setSortDirectoriesFirst(false);
802 QCOMPARE(m_model->sortRole(), QByteArray("text"));
803 QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder);
804 QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c" << "c-1" << "c-2" << "c-3" << "d" << "e");
805 QCOMPARE(spyItemsMoved.count(), 1);
806 QCOMPARE(spyItemsMoved.takeFirst().at(1).value<QList<int> >(), QList<int>() << 2 << 4 << 5 << 3 << 0 << 1 << 6 << 7);
807
808 // Sort by Name, descending
809 m_model->setSortDirectoriesFirst(true);
810 m_model->setSortOrder(Qt::DescendingOrder);
811 QCOMPARE(m_model->sortRole(), QByteArray("text"));
812 QCOMPARE(m_model->sortOrder(), Qt::DescendingOrder);
813 QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "e" << "d" << "b" << "a");
814 QCOMPARE(spyItemsMoved.count(), 2);
815 QCOMPARE(spyItemsMoved.takeFirst().at(1).value<QList<int> >(), QList<int>() << 4 << 5 << 0 << 3 << 1 << 2 << 6 << 7);
816 QCOMPARE(spyItemsMoved.takeFirst().at(1).value<QList<int> >(), QList<int>() << 0 << 1 << 2 << 3 << 7 << 6 << 5 << 4);
817
818 // Sort by Date, descending
819 m_model->setSortDirectoriesFirst(true);
820 m_model->setSortRole("date");
821 QCOMPARE(m_model->sortRole(), QByteArray("date"));
822 QCOMPARE(m_model->sortOrder(), Qt::DescendingOrder);
823 QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "b" << "d" << "a" << "e");
824 QCOMPARE(spyItemsMoved.count(), 1);
825 QCOMPARE(spyItemsMoved.takeFirst().at(1).value<QList<int> >(), QList<int>() << 0 << 1 << 2 << 3 << 7 << 5 << 4 << 6);
826
827 // Sort by Date, ascending
828 m_model->setSortOrder(Qt::AscendingOrder);
829 QCOMPARE(m_model->sortRole(), QByteArray("date"));
830 QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder);
831 QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "e" << "a" << "d" << "b");
832 QCOMPARE(spyItemsMoved.count(), 1);
833 QCOMPARE(spyItemsMoved.takeFirst().at(1).value<QList<int> >(), QList<int>() << 0 << 1 << 2 << 3 << 7 << 6 << 5 << 4);
834
835 // Sort by Date, ascending, 'Sort Folders First' disabled
836 m_model->setSortDirectoriesFirst(false);
837 QCOMPARE(m_model->sortRole(), QByteArray("date"));
838 QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder);
839 QVERIFY(!m_model->sortDirectoriesFirst());
840 QCOMPARE(itemsInModel(), QStringList() << "e" << "a" << "c" << "c-1" << "c-2" << "c-3" << "d" << "b");
841 QCOMPARE(spyItemsMoved.count(), 1);
842 QCOMPARE(spyItemsMoved.takeFirst().at(1).value<QList<int> >(), QList<int>() << 2 << 4 << 5 << 3 << 0 << 1 << 6 << 7);
843
844 // Sort by Name, ascending, 'Sort Folders First' disabled
845 m_model->setSortRole("text");
846 QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder);
847 QVERIFY(!m_model->sortDirectoriesFirst());
848 QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c" << "c-1" << "c-2" << "c-3" << "d" << "e");
849 QCOMPARE(spyItemsMoved.count(), 1);
850 QCOMPARE(spyItemsMoved.takeFirst().at(1).value<QList<int> >(), QList<int>() << 7 << 0 << 2 << 3 << 4 << 5 << 6 << 1);
851
852 // Sort by Size, ascending, 'Sort Folders First' disabled
853 m_model->setSortRole("size");
854 QCOMPARE(m_model->sortRole(), QByteArray("size"));
855 QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder);
856 QVERIFY(!m_model->sortDirectoriesFirst());
857 QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "a" << "b" << "e" << "d");
858 QCOMPARE(spyItemsMoved.count(), 1);
859 QCOMPARE(spyItemsMoved.takeFirst().at(1).value<QList<int> >(), QList<int>() << 4 << 5 << 0 << 3 << 1 << 2 << 7 << 6);
860
861 QSKIP("2 tests of testSorting() are temporary deactivated as in KFileItemModel resortAllItems() "
862 "always emits a itemsMoved() signal. Before adjusting the tests think about probably introducing "
863 "another signal", SkipSingle);
864 // Internal note: Check comment in KFileItemModel::resortAllItems() for details.
865
866 // In 'Sort by Size' mode, folders are always first -> changing 'Sort Folders First' does not resort the model
867 m_model->setSortDirectoriesFirst(true);
868 QCOMPARE(m_model->sortRole(), QByteArray("size"));
869 QCOMPARE(m_model->sortOrder(), Qt::AscendingOrder);
870 QVERIFY(m_model->sortDirectoriesFirst());
871 QCOMPARE(itemsInModel(), QStringList() << "c" << "a" << "b" << "e" << "d");
872 QCOMPARE(spyItemsMoved.count(), 0);
873
874 // Sort by Size, descending, 'Sort Folders First' enabled
875 m_model->setSortOrder(Qt::DescendingOrder);
876 QCOMPARE(m_model->sortRole(), QByteArray("size"));
877 QCOMPARE(m_model->sortOrder(), Qt::DescendingOrder);
878 QVERIFY(m_model->sortDirectoriesFirst());
879 QCOMPARE(itemsInModel(), QStringList() << "c" << "d" << "e" << "b" << "a");
880 QCOMPARE(spyItemsMoved.count(), 1);
881 QCOMPARE(spyItemsMoved.takeFirst().at(1).value<QList<int> >(), QList<int>() << 0 << 4 << 3 << 2 << 1);
882
883 // TODO: Sort by other roles; show/hide hidden files
884 }
885
886 void KFileItemModelTest::testIndexForKeyboardSearch()
887 {
888 QStringList files;
889 files << "a" << "aa" << "Image.jpg" << "Image.png" << "Text" << "Text1" << "Text2" << "Text11";
890 m_testDir->createFiles(files);
891
892 m_model->loadDirectory(m_testDir->url());
893 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
894
895 // Search from index 0
896 QCOMPARE(m_model->indexForKeyboardSearch("a", 0), 0);
897 QCOMPARE(m_model->indexForKeyboardSearch("aa", 0), 1);
898 QCOMPARE(m_model->indexForKeyboardSearch("i", 0), 2);
899 QCOMPARE(m_model->indexForKeyboardSearch("image", 0), 2);
900 QCOMPARE(m_model->indexForKeyboardSearch("image.jpg", 0), 2);
901 QCOMPARE(m_model->indexForKeyboardSearch("image.png", 0), 3);
902 QCOMPARE(m_model->indexForKeyboardSearch("t", 0), 4);
903 QCOMPARE(m_model->indexForKeyboardSearch("text", 0), 4);
904 QCOMPARE(m_model->indexForKeyboardSearch("text1", 0), 5);
905 QCOMPARE(m_model->indexForKeyboardSearch("text2", 0), 6);
906 QCOMPARE(m_model->indexForKeyboardSearch("text11", 0), 7);
907
908 // Start a search somewhere in the middle
909 QCOMPARE(m_model->indexForKeyboardSearch("a", 1), 1);
910 QCOMPARE(m_model->indexForKeyboardSearch("i", 3), 3);
911 QCOMPARE(m_model->indexForKeyboardSearch("t", 5), 5);
912 QCOMPARE(m_model->indexForKeyboardSearch("text1", 6), 7);
913
914 // Test searches that go past the last item back to index 0
915 QCOMPARE(m_model->indexForKeyboardSearch("a", 2), 0);
916 QCOMPARE(m_model->indexForKeyboardSearch("i", 7), 2);
917 QCOMPARE(m_model->indexForKeyboardSearch("image.jpg", 3), 2);
918 QCOMPARE(m_model->indexForKeyboardSearch("text2", 7), 6);
919
920 // Test searches that yield no result
921 QCOMPARE(m_model->indexForKeyboardSearch("aaa", 0), -1);
922 QCOMPARE(m_model->indexForKeyboardSearch("b", 0), -1);
923 QCOMPARE(m_model->indexForKeyboardSearch("image.svg", 0), -1);
924 QCOMPARE(m_model->indexForKeyboardSearch("text3", 0), -1);
925 QCOMPARE(m_model->indexForKeyboardSearch("text3", 5), -1);
926
927 // Test upper case searches (note that search is case insensitive)
928 QCOMPARE(m_model->indexForKeyboardSearch("A", 0), 0);
929 QCOMPARE(m_model->indexForKeyboardSearch("aA", 0), 1);
930 QCOMPARE(m_model->indexForKeyboardSearch("TexT", 5), 5);
931 QCOMPARE(m_model->indexForKeyboardSearch("IMAGE", 4), 2);
932
933 // TODO: Maybe we should also test keyboard searches in directories which are not sorted by Name?
934 }
935
936 void KFileItemModelTest::testNameFilter()
937 {
938 QStringList files;
939 files << "A1" << "A2" << "Abc" << "Bcd" << "Cde";
940 m_testDir->createFiles(files);
941
942 m_model->loadDirectory(m_testDir->url());
943 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
944
945 m_model->setNameFilter("A"); // Shows A1, A2 and Abc
946 QCOMPARE(m_model->count(), 3);
947
948 m_model->setNameFilter("A2"); // Shows only A2
949 QCOMPARE(m_model->count(), 1);
950
951 m_model->setNameFilter("A2"); // Shows only A1
952 QCOMPARE(m_model->count(), 1);
953
954 m_model->setNameFilter("Bc"); // Shows "Abc" and "Bcd"
955 QCOMPARE(m_model->count(), 2);
956
957 m_model->setNameFilter("bC"); // Shows "Abc" and "Bcd"
958 QCOMPARE(m_model->count(), 2);
959
960 m_model->setNameFilter(QString()); // Shows again all items
961 QCOMPARE(m_model->count(), 5);
962 }
963
964 /**
965 * Verifies that we do not crash when adding a KFileItem with an empty path.
966 * Before this issue was fixed, KFileItemModel::expandedParentsCountCompare()
967 * tried to always read the first character of the path, even if the path is empty.
968 */
969 void KFileItemModelTest::testEmptyPath()
970 {
971 QSet<QByteArray> roles;
972 roles.insert("text");
973 roles.insert("isExpanded");
974 roles.insert("isExpandable");
975 roles.insert("expandedParentsCount");
976 m_model->setRoles(roles);
977
978 const KUrl emptyUrl;
979 QVERIFY(emptyUrl.path().isEmpty());
980
981 const KUrl url("file:///test/");
982
983 KFileItemList items;
984 items << KFileItem(emptyUrl, QString(), KFileItem::Unknown) << KFileItem(url, QString(), KFileItem::Unknown);
985 m_model->slotItemsAdded(emptyUrl, items);
986 m_model->slotCompleted();
987 }
988
989 /**
990 * Verifies that the 'isExpanded' state of folders does not change when the
991 * 'refreshItems' signal is received, see https://bugs.kde.org/show_bug.cgi?id=299675.
992 */
993 void KFileItemModelTest::testRefreshExpandedItem()
994 {
995 QSet<QByteArray> modelRoles = m_model->roles();
996 modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
997 m_model->setRoles(modelRoles);
998
999 QStringList files;
1000 files << "a/1" << "a/2" << "3" << "4";
1001 m_testDir->createFiles(files);
1002
1003 m_model->loadDirectory(m_testDir->url());
1004 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1005 QCOMPARE(m_model->count(), 3); // "a/", "3", "4"
1006
1007 m_model->setExpanded(0, true);
1008 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1009 QCOMPARE(m_model->count(), 5); // "a/", "a/1", "a/2", "3", "4"
1010 QVERIFY(m_model->isExpanded(0));
1011
1012 QSignalSpy spyItemsChanged(m_model, SIGNAL(itemsChanged(KItemRangeList,QSet<QByteArray>)));
1013
1014 const KFileItem item = m_model->fileItem(0);
1015 m_model->slotRefreshItems(QList<QPair<KFileItem, KFileItem> >() << qMakePair(item, item));
1016 QVERIFY(!spyItemsChanged.isEmpty());
1017
1018 QCOMPARE(m_model->count(), 5); // "a/", "a/1", "a/2", "3", "4"
1019 QVERIFY(m_model->isExpanded(0));
1020 }
1021
1022 /**
1023 * Verify that removing hidden files and folders from the model does not
1024 * result in a crash, see https://bugs.kde.org/show_bug.cgi?id=314046
1025 */
1026 void KFileItemModelTest::testRemoveHiddenItems()
1027 {
1028 m_testDir->createDir(".a");
1029 m_testDir->createDir(".b");
1030 m_testDir->createDir("c");
1031 m_testDir->createDir("d");
1032 m_testDir->createFiles(QStringList() << ".f" << ".g" << "h" << "i");
1033
1034 QSignalSpy spyItemsInserted(m_model, SIGNAL(itemsInserted(KItemRangeList)));
1035 QSignalSpy spyItemsRemoved(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
1036
1037 m_model->setShowHiddenFiles(true);
1038 m_model->loadDirectory(m_testDir->url());
1039 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1040 QCOMPARE(itemsInModel(), QStringList() << ".a" << ".b" << "c" << "d" <<".f" << ".g" << "h" << "i");
1041 QCOMPARE(spyItemsInserted.count(), 1);
1042 QCOMPARE(spyItemsRemoved.count(), 0);
1043 KItemRangeList itemRangeList = spyItemsInserted.takeFirst().at(0).value<KItemRangeList>();
1044 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 8));
1045
1046 m_model->setShowHiddenFiles(false);
1047 QCOMPARE(itemsInModel(), QStringList() << "c" << "d" << "h" << "i");
1048 QCOMPARE(spyItemsInserted.count(), 0);
1049 QCOMPARE(spyItemsRemoved.count(), 1);
1050 itemRangeList = spyItemsRemoved.takeFirst().at(0).value<KItemRangeList>();
1051 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 2) << KItemRange(4, 2));
1052
1053 m_model->setShowHiddenFiles(true);
1054 QCOMPARE(itemsInModel(), QStringList() << ".a" << ".b" << "c" << "d" <<".f" << ".g" << "h" << "i");
1055 QCOMPARE(spyItemsInserted.count(), 1);
1056 QCOMPARE(spyItemsRemoved.count(), 0);
1057 itemRangeList = spyItemsInserted.takeFirst().at(0).value<KItemRangeList>();
1058 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 2) << KItemRange(2, 2));
1059
1060 m_model->clear();
1061 QCOMPARE(itemsInModel(), QStringList());
1062 QCOMPARE(spyItemsInserted.count(), 0);
1063 QCOMPARE(spyItemsRemoved.count(), 1);
1064 itemRangeList = spyItemsRemoved.takeFirst().at(0).value<KItemRangeList>();
1065 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 8));
1066
1067 // Hiding hidden files makes the dir lister emit its itemsDeleted signal.
1068 // Verify that this does not make the model crash.
1069 m_model->setShowHiddenFiles(false);
1070 }
1071
1072 /**
1073 * Verify that filtered items are removed when their parent is collapsed.
1074 */
1075 void KFileItemModelTest::collapseParentOfHiddenItems()
1076 {
1077 QSet<QByteArray> modelRoles = m_model->roles();
1078 modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
1079 m_model->setRoles(modelRoles);
1080
1081 QStringList files;
1082 files << "a/1" << "a/b/1" << "a/b/c/1" << "a/b/c/d/1";
1083 m_testDir->createFiles(files);
1084
1085 m_model->loadDirectory(m_testDir->url());
1086 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1087 QCOMPARE(m_model->count(), 1); // Only "a/"
1088
1089 // Expand "a/".
1090 m_model->setExpanded(0, true);
1091 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1092 QCOMPARE(m_model->count(), 3); // 3 items: "a/", "a/b/", "a/1"
1093
1094 // Expand "a/b/".
1095 m_model->setExpanded(1, true);
1096 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1097 QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/b/", "a/b/c", "a/b/1", "a/1"
1098
1099 // Expand "a/b/c/".
1100 m_model->setExpanded(2, true);
1101 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1102 QCOMPARE(m_model->count(), 7); // 7 items: "a/", "a/b/", "a/b/c", "a/b/c/d/", "a/b/c/1", "a/b/1", "a/1"
1103
1104 // Set a name filter that matches nothing -> only the expanded folders remain.
1105 m_model->setNameFilter("xyz");
1106 QCOMPARE(m_model->count(), 3);
1107 QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c");
1108
1109 // Collapse the folder "a/".
1110 QSignalSpy spyItemsRemoved(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
1111 m_model->setExpanded(0, false);
1112 QCOMPARE(spyItemsRemoved.count(), 1);
1113 QCOMPARE(m_model->count(), 1);
1114 QCOMPARE(itemsInModel(), QStringList() << "a");
1115
1116 // Remove the filter -> no files should appear (and we should not get a crash).
1117 m_model->setNameFilter(QString());
1118 QCOMPARE(m_model->count(), 1);
1119 }
1120
1121 /**
1122 * Verify that filtered items are removed when their parent is deleted.
1123 */
1124 void KFileItemModelTest::removeParentOfHiddenItems()
1125 {
1126 QSet<QByteArray> modelRoles = m_model->roles();
1127 modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
1128 m_model->setRoles(modelRoles);
1129
1130 QStringList files;
1131 files << "a/1" << "a/b/1" << "a/b/c/1" << "a/b/c/d/1";
1132 m_testDir->createFiles(files);
1133
1134 m_model->loadDirectory(m_testDir->url());
1135 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1136 QCOMPARE(m_model->count(), 1); // Only "a/"
1137
1138 // Expand "a/".
1139 m_model->setExpanded(0, true);
1140 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1141 QCOMPARE(m_model->count(), 3); // 3 items: "a/", "a/b/", "a/1"
1142
1143 // Expand "a/b/".
1144 m_model->setExpanded(1, true);
1145 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1146 QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/b/", "a/b/c", "a/b/1", "a/1"
1147
1148 // Expand "a/b/c/".
1149 m_model->setExpanded(2, true);
1150 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1151 QCOMPARE(m_model->count(), 7); // 7 items: "a/", "a/b/", "a/b/c", "a/b/c/d/", "a/b/c/1", "a/b/1", "a/1"
1152
1153 // Set a name filter that matches nothing -> only the expanded folders remain.
1154 m_model->setNameFilter("xyz");
1155 QCOMPARE(m_model->count(), 3);
1156 QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c");
1157
1158 // Simulate the deletion of the directory "a/b/".
1159 QSignalSpy spyItemsRemoved(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
1160 m_model->slotItemsDeleted(KFileItemList() << m_model->fileItem(1));
1161 QCOMPARE(spyItemsRemoved.count(), 1);
1162 QCOMPARE(m_model->count(), 1);
1163 QCOMPARE(itemsInModel(), QStringList() << "a");
1164
1165 // Remove the filter -> only the file "a/1" should appear.
1166 m_model->setNameFilter(QString());
1167 QCOMPARE(m_model->count(), 2);
1168 QCOMPARE(itemsInModel(), QStringList() << "a" << "1");
1169 }
1170
1171 /**
1172 * Create a tree structure where parent-child relationships can not be
1173 * determined by parsing the URLs, and verify that KFileItemModel
1174 * handles them correctly.
1175 */
1176 void KFileItemModelTest::testGeneralParentChildRelationships()
1177 {
1178 QSet<QByteArray> modelRoles = m_model->roles();
1179 modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
1180 m_model->setRoles(modelRoles);
1181
1182 QStringList files;
1183 files << "parent1/realChild1/realGrandChild1" << "parent2/realChild2/realGrandChild2";
1184 m_testDir->createFiles(files);
1185
1186 m_model->loadDirectory(m_testDir->url());
1187 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1188 QCOMPARE(itemsInModel(), QStringList() << "parent1" << "parent2");
1189
1190 // Expand all folders.
1191 m_model->setExpanded(0, true);
1192 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1193 QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "parent2");
1194
1195 m_model->setExpanded(1, true);
1196 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1197 QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "parent2");
1198
1199 m_model->setExpanded(3, true);
1200 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1201 QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "parent2" << "realChild2");
1202
1203 m_model->setExpanded(4, true);
1204 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1205 QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "parent2" << "realChild2" << "realGrandChild2");
1206
1207 // Add some more children and grand-children.
1208 const KUrl parent1 = m_model->fileItem(0).url();
1209 const KUrl parent2 = m_model->fileItem(3).url();
1210 const KUrl realChild1 = m_model->fileItem(1).url();
1211 const KUrl realChild2 = m_model->fileItem(4).url();
1212
1213 m_model->slotItemsAdded(parent1, KFileItemList() << KFileItem(KUrl("child1"), QString(), KFileItem::Unknown));
1214 m_model->slotCompleted();
1215 QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2");
1216
1217 m_model->slotItemsAdded(parent2, KFileItemList() << KFileItem(KUrl("child2"), QString(), KFileItem::Unknown));
1218 m_model->slotCompleted();
1219 QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2" << "child2");
1220
1221 m_model->slotItemsAdded(realChild1, KFileItemList() << KFileItem(KUrl("grandChild1"), QString(), KFileItem::Unknown));
1222 m_model->slotCompleted();
1223 QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "grandChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2" << "child2");
1224
1225 m_model->slotItemsAdded(realChild1, KFileItemList() << KFileItem(KUrl("grandChild1"), QString(), KFileItem::Unknown));
1226 m_model->slotCompleted();
1227 QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "grandChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2" << "child2");
1228
1229 m_model->slotItemsAdded(realChild2, KFileItemList() << KFileItem(KUrl("grandChild2"), QString(), KFileItem::Unknown));
1230 m_model->slotCompleted();
1231 QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "grandChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "grandChild2" << "realGrandChild2" << "child2");
1232
1233 // Set a name filter that matches nothing -> only expanded folders remain.
1234 QSignalSpy itemsRemovedSpy(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
1235 m_model->setNameFilter("xyz");
1236 QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "parent2" << "realChild2");
1237 QCOMPARE(itemsRemovedSpy.count(), 1);
1238 QList<QVariant> arguments = itemsRemovedSpy.takeFirst();
1239 KItemRangeList itemRangeList = arguments.at(0).value<KItemRangeList>();
1240 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(2, 3) << KItemRange(7, 3));
1241
1242 // Collapse "parent1".
1243 m_model->setExpanded(0, false);
1244 QCOMPARE(itemsInModel(), QStringList() << "parent1" << "parent2" << "realChild2");
1245 QCOMPARE(itemsRemovedSpy.count(), 1);
1246 arguments = itemsRemovedSpy.takeFirst();
1247 itemRangeList = arguments.at(0).value<KItemRangeList>();
1248 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(1, 1));
1249
1250 // Remove "parent2".
1251 m_model->slotItemsDeleted(KFileItemList() << m_model->fileItem(1));
1252 QCOMPARE(itemsInModel(), QStringList() << "parent1");
1253 QCOMPARE(itemsRemovedSpy.count(), 1);
1254 arguments = itemsRemovedSpy.takeFirst();
1255 itemRangeList = arguments.at(0).value<KItemRangeList>();
1256 QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(1, 2));
1257
1258 // Clear filter, verify that no items reappear.
1259 m_model->setNameFilter(QString());
1260 QCOMPARE(itemsInModel(), QStringList() << "parent1");
1261 }
1262
1263 void KFileItemModelTest::testNameRoleGroups()
1264 {
1265 QStringList files;
1266 files << "b.txt" << "c.txt" << "d.txt" << "e.txt";
1267
1268 m_testDir->createFiles(files);
1269
1270 m_model->setGroupedSorting(true);
1271 m_model->loadDirectory(m_testDir->url());
1272 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1273 QCOMPARE(itemsInModel(), QStringList() << "b.txt" << "c.txt" << "d.txt" << "e.txt");
1274
1275 QList<QPair<int, QVariant> > expectedGroups;
1276 expectedGroups << QPair<int, QVariant>(0, QLatin1String("B"));
1277 expectedGroups << QPair<int, QVariant>(1, QLatin1String("C"));
1278 expectedGroups << QPair<int, QVariant>(2, QLatin1String("D"));
1279 expectedGroups << QPair<int, QVariant>(3, QLatin1String("E"));
1280 QCOMPARE(m_model->groups(), expectedGroups);
1281
1282 // Rename d.txt to a.txt.
1283 QHash<QByteArray, QVariant> data;
1284 data.insert("text", "a.txt");
1285 m_model->setData(2, data);
1286 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)), DefaultTimeout));
1287 QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt" << "e.txt");
1288
1289 expectedGroups.clear();
1290 expectedGroups << QPair<int, QVariant>(0, QLatin1String("A"));
1291 expectedGroups << QPair<int, QVariant>(1, QLatin1String("B"));
1292 expectedGroups << QPair<int, QVariant>(2, QLatin1String("C"));
1293 expectedGroups << QPair<int, QVariant>(3, QLatin1String("E"));
1294 QCOMPARE(m_model->groups(), expectedGroups);
1295
1296 // Rename c.txt to d.txt.
1297 data.insert("text", "d.txt");
1298 m_model->setData(2, data);
1299 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)), DefaultTimeout));
1300 QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "d.txt" << "e.txt");
1301
1302 expectedGroups.clear();
1303 expectedGroups << QPair<int, QVariant>(0, QLatin1String("A"));
1304 expectedGroups << QPair<int, QVariant>(1, QLatin1String("B"));
1305 expectedGroups << QPair<int, QVariant>(2, QLatin1String("D"));
1306 expectedGroups << QPair<int, QVariant>(3, QLatin1String("E"));
1307 QCOMPARE(m_model->groups(), expectedGroups);
1308
1309 // Change d.txt back to c.txt, but this time using the dir lister's refreshItems() signal.
1310 const KFileItem fileItemD = m_model->fileItem(2);
1311 KFileItem fileItemC = fileItemD;
1312 KUrl urlC = fileItemC.url();
1313 urlC.setFileName("c.txt");
1314 fileItemC.setUrl(urlC);
1315
1316 m_model->slotRefreshItems(QList<QPair<KFileItem, KFileItem> >() << qMakePair(fileItemD, fileItemC));
1317 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsMoved(KItemRange,QList<int>)), DefaultTimeout));
1318 QCOMPARE(itemsInModel(), QStringList() << "a.txt" << "b.txt" << "c.txt" << "e.txt");
1319
1320 expectedGroups.clear();
1321 expectedGroups << QPair<int, QVariant>(0, QLatin1String("A"));
1322 expectedGroups << QPair<int, QVariant>(1, QLatin1String("B"));
1323 expectedGroups << QPair<int, QVariant>(2, QLatin1String("C"));
1324 expectedGroups << QPair<int, QVariant>(3, QLatin1String("E"));
1325 QCOMPARE(m_model->groups(), expectedGroups);
1326 }
1327
1328 void KFileItemModelTest::testNameRoleGroupsWithExpandedItems()
1329 {
1330 QSet<QByteArray> modelRoles = m_model->roles();
1331 modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
1332 m_model->setRoles(modelRoles);
1333
1334 QStringList files;
1335 files << "a/b.txt" << "a/c.txt" << "d/e.txt" << "d/f.txt";
1336
1337 m_testDir->createFiles(files);
1338
1339 m_model->setGroupedSorting(true);
1340 m_model->loadDirectory(m_testDir->url());
1341 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1342 QCOMPARE(itemsInModel(), QStringList() << "a" << "d");
1343
1344 QList<QPair<int, QVariant> > expectedGroups;
1345 expectedGroups << QPair<int, QVariant>(0, QLatin1String("A"));
1346 expectedGroups << QPair<int, QVariant>(1, QLatin1String("D"));
1347 QCOMPARE(m_model->groups(), expectedGroups);
1348
1349 // Verify that expanding "a" and "d" will not change the groups (except for the index of "D").
1350 expectedGroups.clear();
1351 expectedGroups << QPair<int, QVariant>(0, QLatin1String("A"));
1352 expectedGroups << QPair<int, QVariant>(3, QLatin1String("D"));
1353
1354 m_model->setExpanded(0, true);
1355 QVERIFY(m_model->isExpanded(0));
1356 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1357 QCOMPARE(itemsInModel(), QStringList() << "a" << "b.txt" << "c.txt" << "d");
1358 QCOMPARE(m_model->groups(), expectedGroups);
1359
1360 m_model->setExpanded(3, true);
1361 QVERIFY(m_model->isExpanded(3));
1362 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
1363 QCOMPARE(itemsInModel(), QStringList() << "a" << "b.txt" << "c.txt" << "d" << "e.txt" << "f.txt");
1364 QCOMPARE(m_model->groups(), expectedGroups);
1365 }
1366
1367 QStringList KFileItemModelTest::itemsInModel() const
1368 {
1369 QStringList items;
1370 for (int i = 0; i < m_model->count(); i++) {
1371 items << m_model->fileItem(i).text();
1372 }
1373 return items;
1374 }
1375
1376 QTEST_KDEMAIN(KFileItemModelTest, NoGUI)
1377
1378 #include "kfileitemmodeltest.moc"