]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/tests/kfileitemmodeltest.cpp
GIT_SILENT made messages (after extraction)
[dolphin.git] / src / tests / kfileitemmodeltest.cpp
index f527fbc61b2043bd7d45bed1e44bbe7add949652..7a22a1a7f7eb75dd50b5923a0ab513706f9cb9c6 100644 (file)
 #include <QTimer>
 #include <QMimeData>
 
+#include <KDirLister>
 #include <kio/job.h>
 
 #include "kitemviews/kfileitemmodel.h"
-#include "kitemviews/private/kfileitemmodeldirlister.h"
 #include "testdir.h"
 
 void myMessageOutput(QtMsgType type, const QMessageLogContext& context, const QString& msg)
@@ -814,16 +814,16 @@ void KFileItemModelTest::testSorting()
 {
     // testDir structure is as follows
     // ./
+    // ├─ .g/
     // ├─ a
     // ├─ b
     // ├─ c/
     // │  ├─ c-2/
     // │  │  ├─ c-3
     // │  ├─ c-1
+    // ├─ .f
     // ├─ d
     // ├─ e
-    // ├─ .f
-    // ├─ .g/
 
     QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
     QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved);
@@ -968,10 +968,20 @@ void KFileItemModelTest::testSorting()
     // 'Show Hidden Files' enabled
     m_model->setShowHiddenFiles(true);
     QVERIFY(m_model->showHiddenFiles());
-    QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "d" << "e" << "b" << "a" << ".g" << ".f");
+    QVERIFY(!m_model->sortHiddenLast());
+    QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << ".g" << "d" << "e" << "b" << "a" << ".f");
     QCOMPARE(itemsMovedSpy.count(), 0);
     QCOMPARE(itemsInsertedSpy.count(), 1);
-    QCOMPARE(itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>(), KItemRangeList() << KItemRange(8, 2));
+    QCOMPARE(itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>(), KItemRangeList() << KItemRange(4, 1) << KItemRange(8, 1));
+
+    // 'Sort Hidden Files Last' enabled
+    m_model->setSortHiddenLast(true);
+    QVERIFY(m_model->sortHiddenLast());
+    QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "d" << "e" << "b" << "a" << ".g" << ".f");
+    QCOMPARE(itemsMovedSpy.count(), 1);
+    QCOMPARE(itemsInsertedSpy.count(), 0);
+    QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(4, 5));
+    QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 8 << 4 << 5 << 6 << 7);
 
     // Sort by Name
     m_model->setSortRole("text");
@@ -1151,7 +1161,7 @@ void KFileItemModelTest::testRemoveHiddenItems()
     m_model->setShowHiddenFiles(true);
     m_model->loadDirectory(m_testDir->url());
     QVERIFY(itemsInsertedSpy.wait());
-    QCOMPARE(itemsInModel(), QStringList() << "c" << "d" << "h" << "i" << ".a" << ".b" <<".f" << ".g");
+    QCOMPARE(itemsInModel(), QStringList() << ".a" << ".b" << "c" << "d" <<".f" << ".g" << "h" << "i");
     QCOMPARE(itemsInsertedSpy.count(), 1);
     QCOMPARE(itemsRemovedSpy.count(), 0);
     KItemRangeList itemRangeList = itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>();
@@ -1162,14 +1172,14 @@ void KFileItemModelTest::testRemoveHiddenItems()
     QCOMPARE(itemsInsertedSpy.count(), 0);
     QCOMPARE(itemsRemovedSpy.count(), 1);
     itemRangeList = itemsRemovedSpy.takeFirst().at(0).value<KItemRangeList>();
-    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(4, 4));
+    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 2) << KItemRange(4, 2));
 
     m_model->setShowHiddenFiles(true);
-    QCOMPARE(itemsInModel(), QStringList() << "c" << "d" << "h" << "i" << ".a" << ".b" <<".f" << ".g");
+    QCOMPARE(itemsInModel(), QStringList() << ".a" << ".b" << "c" << "d" <<".f" << ".g" << "h" << "i");
     QCOMPARE(itemsInsertedSpy.count(), 1);
     QCOMPARE(itemsRemovedSpy.count(), 0);
     itemRangeList = itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>();
-    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(4, 4));
+    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 2) << KItemRange(2, 2));
 
     m_model->clear();
     QCOMPARE(itemsInModel(), QStringList());
@@ -1216,11 +1226,16 @@ void KFileItemModelTest::collapseParentOfHiddenItems()
     QVERIFY(itemsInsertedSpy.wait());
     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"
 
-    // Set a name filter that matches nothing -> only the expanded folders remain.
+    // Set a name filter that matches nothing -> nothing should remain.
     m_model->setNameFilter("xyz");
     QCOMPARE(itemsRemovedSpy.count(), 1);
-    QCOMPARE(m_model->count(), 3);
-    QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c");
+    QCOMPARE(m_model->count(), 0); //Everything is hidden
+    QCOMPARE(itemsInModel(), QStringList());
+
+    //Filter by the file names. Folder "d" will be hidden since it was collapsed
+    m_model->setNameFilter("1");
+    QCOMPARE(itemsRemovedSpy.count(), 1); // nothing was removed, itemsRemovedSpy count will remain the same:
+    QCOMPARE(m_model->count(), 6); // 6 items: "a/", "a/b/", "a/b/c", "a/b/c/1", "a/b/1", "a/1"
 
     // Collapse the folder "a/".
     m_model->setExpanded(0, false);
@@ -1228,9 +1243,11 @@ void KFileItemModelTest::collapseParentOfHiddenItems()
     QCOMPARE(m_model->count(), 1);
     QCOMPARE(itemsInModel(), QStringList() << "a");
 
-    // Remove the filter -> no files should appear (and we should not get a crash).
+    // Remove the filter -> "a" should still appear (and we should not get a crash).
     m_model->setNameFilter(QString());
+    QCOMPARE(itemsRemovedSpy.count(), 2); // nothing was removed, itemsRemovedSpy count will remain the same:
     QCOMPARE(m_model->count(), 1);
+    QCOMPARE(itemsInModel(), QStringList() << "a");
 }
 
 /**
@@ -1266,9 +1283,15 @@ void KFileItemModelTest::removeParentOfHiddenItems()
     QVERIFY(itemsInsertedSpy.wait());
     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"
 
-    // Set a name filter that matches nothing -> only the expanded folders remain.
+    // Set a name filter that matches nothing -> nothing should remain.
     m_model->setNameFilter("xyz");
     QCOMPARE(itemsRemovedSpy.count(), 1);
+    QCOMPARE(m_model->count(), 0);
+    QCOMPARE(itemsInModel(), QStringList());
+
+    // Filter by "c". Folder "b" will also be shown because it is its parent.
+    m_model->setNameFilter("c");
+    QCOMPARE(itemsRemovedSpy.count(), 1); // nothing was removed, itemsRemovedSpy count will remain the same:
     QCOMPARE(m_model->count(), 3);
     QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c");
 
@@ -1339,21 +1362,22 @@ void KFileItemModelTest::testGeneralParentChildRelationships()
     m_model->slotCompleted();
     QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "grandChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2" << "child2");
 
-    m_model->slotItemsAdded(realChild1, KFileItemList() << KFileItem(QUrl("grandChild1"), QString(), KFileItem::Unknown));
-    m_model->slotCompleted();
-    QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "grandChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "realGrandChild2" << "child2");
-
     m_model->slotItemsAdded(realChild2, KFileItemList() << KFileItem(QUrl("grandChild2"), QString(), KFileItem::Unknown));
     m_model->slotCompleted();
     QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "grandChild1" << "realGrandChild1" << "child1" << "parent2" << "realChild2" << "grandChild2" << "realGrandChild2" << "child2");
 
-    // Set a name filter that matches nothing -> only expanded folders remain.
+    // Set a name filter that matches nothing -> nothing will remain.
     m_model->setNameFilter("xyz");
-    QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "parent2" << "realChild2");
+    QCOMPARE(itemsInModel(), QStringList());
     QCOMPARE(itemsRemovedSpy.count(), 1);
     QList<QVariant> arguments = itemsRemovedSpy.takeFirst();
     KItemRangeList itemRangeList = arguments.at(0).value<KItemRangeList>();
-    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(2, 3) << KItemRange(7, 3));
+    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 10));
+
+    // Set a name filter that matches only "realChild". Their prarents should still show.
+    m_model->setNameFilter("realChild");
+    QCOMPARE(itemsInModel(), QStringList() << "parent1" << "realChild1" << "parent2" << "realChild2");
+    QCOMPARE(itemsRemovedSpy.count(), 0);  // nothing was removed, itemsRemovedSpy will not be called this time
 
     // Collapse "parent1".
     m_model->setExpanded(0, false);