X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/aeb16937ced1bf426c2ca21dcc270f9e4a96645c..c8d8556950005dfd96ebdb41d2f43ad90356367c:/src/tests/kitemlistselectionmanagertest.cpp diff --git a/src/tests/kitemlistselectionmanagertest.cpp b/src/tests/kitemlistselectionmanagertest.cpp index 2fa6f677b..7f79197a9 100644 --- a/src/tests/kitemlistselectionmanagertest.cpp +++ b/src/tests/kitemlistselectionmanagertest.cpp @@ -27,18 +27,28 @@ class DummyModel : public KItemModelBase { public: DummyModel(); + void setCount(int count); virtual int count() const; virtual QHash data(int index) const; + +private: + int m_count; }; DummyModel::DummyModel() : - KItemModelBase() + KItemModelBase(), + m_count(100) +{ +} + +void DummyModel::setCount(int count) { + m_count = count; } int DummyModel::count() const { - return 100; + return m_count; } QHash DummyModel::data(int index) const @@ -48,7 +58,6 @@ QHash DummyModel::data(int index) const } - class KItemListSelectionManagerTest : public QObject { Q_OBJECT @@ -67,24 +76,30 @@ private slots: void testAnchoredSelection(); void testChangeSelection_data(); void testChangeSelection(); + void testDeleteCurrentItem_data(); + void testDeleteCurrentItem(); private: void verifySelectionChange(QSignalSpy& spy, const QSet& currentSelection, const QSet& previousSelection) const; KItemListSelectionManager* m_selectionManager; + DummyModel* m_model; }; void KItemListSelectionManagerTest::init() { + m_model = new DummyModel(); m_selectionManager = new KItemListSelectionManager(); - m_selectionManager->setModel(new DummyModel()); + m_selectionManager->setModel(m_model); } void KItemListSelectionManagerTest::cleanup() { - delete m_selectionManager->model(); delete m_selectionManager; m_selectionManager = 0; + + delete m_model; + m_model = 0; } void KItemListSelectionManagerTest::testConstructor() @@ -474,6 +489,36 @@ void KItemListSelectionManagerTest::testChangeSelection() verifySelectionChange(spySelectionChanged, QSet(), finalSelection); } +void KItemListSelectionManagerTest::testDeleteCurrentItem_data() +{ + QTest::addColumn("oldCurrentItemIndex"); + QTest::addColumn("removeIndex"); + QTest::addColumn("removeCount"); + QTest::addColumn("newCurrentItemIndex"); + + QTest::newRow("Remove before") << 50 << 0 << 10 << 40; + QTest::newRow("Remove after") << 50 << 51 << 10 << 50; + QTest::newRow("Remove exactly current item") << 50 << 50 << 1 << 50; + QTest::newRow("Remove around current item") << 50 << 45 << 10 << 50; + QTest::newRow("Remove all except one item") << 50 << 1 << 99 << 0; +} + +void KItemListSelectionManagerTest::testDeleteCurrentItem() +{ + QFETCH(int, oldCurrentItemIndex); + QFETCH(int, removeIndex); + QFETCH(int, removeCount); + QFETCH(int, newCurrentItemIndex); + + m_selectionManager->setCurrentItem(oldCurrentItemIndex); + + const int newCount = m_model->count() - removeCount; + m_model->setCount(newCount); + m_selectionManager->itemsRemoved(KItemRangeList() << KItemRange(removeIndex, removeCount)); + + QCOMPARE(m_selectionManager->currentItem(), newCurrentItemIndex); +} + void KItemListSelectionManagerTest::verifySelectionChange(QSignalSpy& spy, const QSet& currentSelection, const QSet& previousSelection) const