diff options
| author | Peter Penz <[email protected]> | 2011-12-04 18:16:39 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-12-04 18:21:46 +0100 |
| commit | 854b0acd1a259fab40e42c8470bb144c955dcc5a (patch) | |
| tree | 376e1aa31a85dd410ba1d4236cb0b3c26c83763a /src/tests/kitemlistselectionmanagertest.cpp | |
| parent | 031b1a4c19945456a389ddb00630aadf95b0c09a (diff) | |
Fix crash #1 when filtering items
When filtering items it was possible that the current index got
an invalid value which resulted in accessing the URL of a
null-KFileItem.
There is still one (general) open issue in KFileItemModelRolesUpdater
(crash #2) where a KFileItem that is already null gets read.
It is not really related to filtering but can be triggered
quite easy when filtering huge directories with enabled previews.
CCBUG: 287642
Diffstat (limited to 'src/tests/kitemlistselectionmanagertest.cpp')
| -rw-r--r-- | src/tests/kitemlistselectionmanagertest.cpp | 55 |
1 files changed, 50 insertions, 5 deletions
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<QByteArray, QVariant> 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<QByteArray, QVariant> DummyModel::data(int index) const @@ -48,7 +58,6 @@ QHash<QByteArray, QVariant> 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<int>& currentSelection, const QSet<int>& 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<int>(), finalSelection); } +void KItemListSelectionManagerTest::testDeleteCurrentItem_data() +{ + QTest::addColumn<int>("oldCurrentItemIndex"); + QTest::addColumn<int>("removeIndex"); + QTest::addColumn<int>("removeCount"); + QTest::addColumn<int>("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<int>& currentSelection, const QSet<int>& previousSelection) const |
