┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests/kfileitemmodeltest.cpp
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2013-01-27 14:09:39 +0100
committerFrank Reininghaus <[email protected]>2013-01-27 14:09:39 +0100
commit891ee0c41a3b2e80aa8191a6f8152c6095ce0351 (patch)
tree05c7eb689e5482884805d230023a2664d6e6a01c /src/tests/kfileitemmodeltest.cpp
parentd27c16d7516911c892bebbc517f42f457719cb44 (diff)
Add a unit test for a recently fixed crash
Before commit 90c7fd400c34e6d4d583c54c04631856c387d359, adding a KFileItem with an empty path caused a crash in KFileItemModel::expandedParentsCountCompare().
Diffstat (limited to 'src/tests/kfileitemmodeltest.cpp')
-rw-r--r--src/tests/kfileitemmodeltest.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp
index 9d53ea7e6..65368b75b 100644
--- a/src/tests/kfileitemmodeltest.cpp
+++ b/src/tests/kfileitemmodeltest.cpp
@@ -72,10 +72,9 @@ private slots:
void testExpandItems();
void testExpandParentItems();
void testSorting();
-
void testIndexForKeyboardSearch();
-
void testNameFilter();
+ void testEmptyPath();
private:
bool isModelConsistent() const;
@@ -774,6 +773,31 @@ void KFileItemModelTest::testNameFilter()
QCOMPARE(m_model->count(), 5);
}
+/**
+ * Verifies that we do not crash when adding a KFileItem with an empty path.
+ * Before this issue was fixed, KFileItemModel::expandedParentsCountCompare()
+ * tried to always read the first character of the path, even if the path is empty.
+ */
+void KFileItemModelTest::testEmptyPath()
+{
+ QSet<QByteArray> roles;
+ roles.insert("text");
+ roles.insert("isExpanded");
+ roles.insert("isExpandable");
+ roles.insert("expandedParentsCount");
+ m_model->setRoles(roles);
+
+ const KUrl emptyUrl;
+ QVERIFY(emptyUrl.path().isEmpty());
+
+ const KUrl url("file:///test/");
+
+ KFileItemList items;
+ items << KFileItem(emptyUrl, QString(), KFileItem::Unknown) << KFileItem(url, QString(), KFileItem::Unknown);
+ m_model->slotNewItems(items);
+ m_model->slotCompleted();
+}
+
bool KFileItemModelTest::isModelConsistent() const
{
if (m_model->m_items.count() != m_model->m_itemData.count()) {