X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/63e82a2b3bba25fbfaa3d283264cc0c61d11cfe8..5070666ad2cd5fe3e559adca00a52aed5d137153:/src/tests/kfileitemmodeltest.cpp diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index 7315083fa..f8398c578 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright (C) 2011 by Peter Penz * + * Copyright (C) 2011 by Frank Reininghaus * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -41,6 +42,7 @@ private slots: void testDefaultSortRole(); void testDefaultGroupRole(); void testNewItems(); + void testRemoveItems(); void testModelConsistencyWhenInsertingItems(); void testItemRangeConsistencyWhenInsertingItems(); void testExpandItems(); @@ -48,6 +50,8 @@ private slots: void testExpansionLevelsCompare_data(); void testExpansionLevelsCompare(); + void testIndexForKeyboardSearch(); + private: bool isModelConsistent() const; @@ -124,6 +128,19 @@ void KFileItemModelTest::testNewItems() QVERIFY(isModelConsistent()); } +void KFileItemModelTest::testRemoveItems() +{ + m_testDir->createFile("a.txt"); + m_dirLister->openUrl(m_testDir->url()); + QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + QCOMPARE(m_model->count(), 1); + + m_testDir->removeFile("a.txt"); + m_dirLister->updateDirectory(m_testDir->url()); + QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsRemoved(KItemRangeList)), DefaultTimeout)); + QCOMPARE(m_model->count(), 0); +} + void KFileItemModelTest::testModelConsistencyWhenInsertingItems() { QSKIP("Temporary disabled", SkipSingle); @@ -313,6 +330,56 @@ void KFileItemModelTest::testExpansionLevelsCompare() QCOMPARE(m_model->expansionLevelsCompare(a, b), result); } +void KFileItemModelTest::testIndexForKeyboardSearch() +{ + QStringList files; + files << "a" << "aa" << "Image.jpg" << "Image.png" << "Text" << "Text1" << "Text2" << "Text11"; + m_testDir->createFiles(files); + + m_dirLister->openUrl(m_testDir->url()); + QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(itemsInserted(KItemRangeList)), DefaultTimeout)); + + // Search from index 0 + QCOMPARE(m_model->indexForKeyboardSearch("a", 0), 0); + QCOMPARE(m_model->indexForKeyboardSearch("aa", 0), 1); + QCOMPARE(m_model->indexForKeyboardSearch("i", 0), 2); + QCOMPARE(m_model->indexForKeyboardSearch("image", 0), 2); + QCOMPARE(m_model->indexForKeyboardSearch("image.jpg", 0), 2); + QCOMPARE(m_model->indexForKeyboardSearch("image.png", 0), 3); + QCOMPARE(m_model->indexForKeyboardSearch("t", 0), 4); + QCOMPARE(m_model->indexForKeyboardSearch("text", 0), 4); + QCOMPARE(m_model->indexForKeyboardSearch("text1", 0), 5); + QCOMPARE(m_model->indexForKeyboardSearch("text2", 0), 6); + QCOMPARE(m_model->indexForKeyboardSearch("text11", 0), 7); + + // Start a search somewhere in the middle + QCOMPARE(m_model->indexForKeyboardSearch("a", 1), 1); + QCOMPARE(m_model->indexForKeyboardSearch("i", 3), 3); + QCOMPARE(m_model->indexForKeyboardSearch("t", 5), 5); + QCOMPARE(m_model->indexForKeyboardSearch("text1", 6), 7); + + // Test searches that go past the last item back to index 0 + QCOMPARE(m_model->indexForKeyboardSearch("a", 2), 0); + QCOMPARE(m_model->indexForKeyboardSearch("i", 7), 2); + QCOMPARE(m_model->indexForKeyboardSearch("image.jpg", 3), 2); + QCOMPARE(m_model->indexForKeyboardSearch("text2", 7), 6); + + // Test searches that yield no result + QCOMPARE(m_model->indexForKeyboardSearch("aaa", 0), -1); + QCOMPARE(m_model->indexForKeyboardSearch("b", 0), -1); + QCOMPARE(m_model->indexForKeyboardSearch("image.svg", 0), -1); + QCOMPARE(m_model->indexForKeyboardSearch("text3", 0), -1); + QCOMPARE(m_model->indexForKeyboardSearch("text3", 5), -1); + + // Test upper case searches (note that search is case insensitive) + QCOMPARE(m_model->indexForKeyboardSearch("A", 0), 0); + QCOMPARE(m_model->indexForKeyboardSearch("aA", 0), 1); + QCOMPARE(m_model->indexForKeyboardSearch("TexT", 5), 5); + QCOMPARE(m_model->indexForKeyboardSearch("IMAGE", 4), 2); + + // TODO: Maybe we should also test keyboard searches in directories which are not sorted by Name? +} + bool KFileItemModelTest::isModelConsistent() const { for (int i = 0; i < m_model->count(); ++i) {