[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kde-baseapps/KDE/4.11] dolphin/src/tests: Add unit test for the calculation of "name" groups with e
From:       Frank Reininghaus <frank78ac () googlemail ! com>
Date:       2013-09-30 22:12:21
Message-ID: E1VQlhV-0000gf-GG () scm ! kde ! org
[Download RAW message or body]

Git commit 54ba8cc85b81431daec5c2909ed205a0a3dcbf4e by Frank Reininghaus.
Committed on 30/09/2013 at 22:09.
Pushed by freininghaus into branch 'KDE/4.11'.

Add unit test for the calculation of "name" groups with expanded items

This prevents a possible regression that would have happened with the
first version of https://git.reviewboard.kde.org/r/112725/

The problem was that isChildItem(int index) would return "false"
incorrectly when the QHash for that item was not initialized yet. The
grouping code would then try to read the "text" from the empty QHash,
which yielded an empty QString, and then accessing the first character
of that string caused a crash.

M  +41   -1    dolphin/src/tests/kfileitemmodeltest.cpp

http://commits.kde.org/kde-baseapps/54ba8cc85b81431daec5c2909ed205a0a3dcbf4e

diff --git a/dolphin/src/tests/kfileitemmodeltest.cpp b/dolphin/src/tests/kfileitemmodeltest.cpp
index d2a3ebd..5dd3417 100644
--- a/dolphin/src/tests/kfileitemmodeltest.cpp
+++ b/dolphin/src/tests/kfileitemmodeltest.cpp
@@ -87,6 +87,7 @@ private slots:
     void removeParentOfHiddenItems();
     void testGeneralParentChildRelationships();
     void testNameRoleGroups();
+    void testNameRoleGroupsWithExpandedItems();
 
 private:
     QStringList itemsInModel() const;
@@ -1324,11 +1325,50 @@ void KFileItemModelTest::testNameRoleGroups()
     QCOMPARE(m_model->groups(), expectedGroups);
 }
 
+void KFileItemModelTest::testNameRoleGroupsWithExpandedItems()
+{
+    QSet<QByteArray> modelRoles = m_model->roles();
+    modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
+    m_model->setRoles(modelRoles);
+
+    QStringList files;
+    files << "a/b.txt" << "a/c.txt" << "d/e.txt" << "d/f.txt";
+
+    m_testDir->createFiles(files);
+
+    m_model->setGroupedSorting(true);
+    m_model->loadDirectory(m_testDir->url());
+    QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
+    QCOMPARE(itemsInModel(), QStringList() << "a" << "d");
+
+    QList<QPair<int, QVariant> > expectedGroups;
+    expectedGroups << QPair<int, QVariant>(0, QLatin1String("A"));
+    expectedGroups << QPair<int, QVariant>(1, QLatin1String("D"));
+    QCOMPARE(m_model->groups(), expectedGroups);
+
+    // Verify that expanding "a" and "d" will not change the groups (except for the index of "D").
+    expectedGroups.clear();
+    expectedGroups << QPair<int, QVariant>(0, QLatin1String("A"));
+    expectedGroups << QPair<int, QVariant>(3, QLatin1String("D"));
+
+    m_model->setExpanded(0, true);
+    QVERIFY(m_model->isExpanded(0));
+    QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
+    QCOMPARE(itemsInModel(), QStringList() << "a" << "b.txt" << "c.txt" << "d");
+    QCOMPARE(m_model->groups(), expectedGroups);
+
+    m_model->setExpanded(3, true);
+    QVERIFY(m_model->isExpanded(3));
+    QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout));
+    QCOMPARE(itemsInModel(), QStringList() << "a" << "b.txt" << "c.txt" << "d" << "e.txt" << "f.txt");
+    QCOMPARE(m_model->groups(), expectedGroups);
+}
+
 QStringList KFileItemModelTest::itemsInModel() const
 {
     QStringList items;
     for (int i = 0; i < m_model->count(); i++) {
-        items << m_model->data(i).value("text").toString();
+        items << m_model->fileItem(i).text();
     }
     return items;
 }
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic