┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2013-09-07 18:06:45 +0200
committerFrank Reininghaus <[email protected]>2013-09-07 18:06:53 +0200
commit7e30467679a403f953e2547894febb51e8a3d78b (patch)
treec8be61598aef5796ae2c67633b5842267788785f /src/tests
parent1848854c6dc909ba9eea58de41112a5b444a27cf (diff)
Make expandedParentsCount() work without accessing the data hash
The idea is that we no longer assume that the "expandedParentsCount" for each item will be stored in the QHash. It is only accessed for items which are expanded, and which are not top-level items (i.e., which have an expandedParentsCount > 1). Some unit tests are added to improve the coverage of the affected code. REVIEW: 112562
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/kfileitemmodeltest.cpp37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp
index e55e3eb33..1d9646b3e 100644
--- a/src/tests/kfileitemmodeltest.cpp
+++ b/src/tests/kfileitemmodeltest.cpp
@@ -486,7 +486,8 @@ void KFileItemModelTest::testExpandItems()
// KFileItemModel::expansionLevelsCompare(const KFileItem& a, const KFileItem& b)
// yields the correct result for "a/a/1" and "a/a-1/", whis is non-trivial because they share the
// first three characters.
- QSet<QByteArray> modelRoles = m_model->roles();
+ QSet<QByteArray> originalModelRoles = m_model->roles();
+ QSet<QByteArray> modelRoles = originalModelRoles;
modelRoles << "isExpanded" << "isExpandable" << "expandedParentsCount";
m_model->setRoles(modelRoles);
@@ -593,6 +594,18 @@ void KFileItemModelTest::testExpandItems()
QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout));
QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1"
QCOMPARE(m_model->expandedDirectories(), allFolders);
+
+ // Remove all expanded items by changing the roles
+ spyRemoved.clear();
+ m_model->setRoles(originalModelRoles);
+ QVERIFY(!m_model->isExpanded(0));
+ QCOMPARE(m_model->count(), 1);
+ QVERIFY(!m_model->expandedDirectories().contains(KUrl(m_testDir->name() + 'a')));
+
+ QCOMPARE(spyRemoved.count(), 1);
+ itemRangeList = spyRemoved.takeFirst().at(0).value<KItemRangeList>();
+ QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(1, 4)); // 4 items removed
+ QVERIFY(m_model->isConsistent());
}
void KFileItemModelTest::testExpandParentItems()
@@ -645,6 +658,28 @@ void KFileItemModelTest::testExpandParentItems()
QVERIFY(m_model->isExpanded(3));
QVERIFY(!m_model->isExpanded(4));
QVERIFY(m_model->isConsistent());
+
+ // Expand "a 1/b1/".
+ m_model->setExpanded(1, true);
+ QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout));
+ QCOMPARE(m_model->count(), 6);
+ QVERIFY(m_model->isExpanded(0));
+ QVERIFY(m_model->isExpanded(1));
+ QVERIFY(!m_model->isExpanded(2));
+ QVERIFY(m_model->isExpanded(3));
+ QVERIFY(m_model->isExpanded(4));
+ QVERIFY(!m_model->isExpanded(5));
+ QVERIFY(m_model->isConsistent());
+
+ // Collapse "a 1/b1/" again, and verify that the previous state is restored.
+ m_model->setExpanded(1, false);
+ QCOMPARE(m_model->count(), 5);
+ QVERIFY(m_model->isExpanded(0));
+ QVERIFY(!m_model->isExpanded(1));
+ QVERIFY(m_model->isExpanded(2));
+ QVERIFY(m_model->isExpanded(3));
+ QVERIFY(!m_model->isExpanded(4));
+ QVERIFY(m_model->isConsistent());
}
/**