File indexing completed on 2024-04-28 05:45:21

0001 /*
0002  * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
0003  * SPDX-FileCopyrightText: 2011 Frank Reininghaus <frank78ac@googlemail.com>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #include "kitemviews/kitemlistselectionmanager.h"
0009 #include "kitemviews/kitemmodelbase.h"
0010 
0011 #include <QSignalSpy>
0012 #include <QStandardPaths>
0013 #include <QTest>
0014 
0015 class DummyModel : public KItemModelBase
0016 {
0017     Q_OBJECT
0018 public:
0019     DummyModel();
0020     void setCount(int count);
0021     int count() const override;
0022     QHash<QByteArray, QVariant> data(int index) const override;
0023 
0024 private:
0025     int m_count;
0026 };
0027 
0028 DummyModel::DummyModel()
0029     : KItemModelBase()
0030     , m_count(100)
0031 {
0032 }
0033 
0034 void DummyModel::setCount(int count)
0035 {
0036     m_count = count;
0037 }
0038 
0039 int DummyModel::count() const
0040 {
0041     return m_count;
0042 }
0043 
0044 QHash<QByteArray, QVariant> DummyModel::data(int index) const
0045 {
0046     Q_UNUSED(index)
0047     return QHash<QByteArray, QVariant>();
0048 }
0049 
0050 class KItemListSelectionManagerTest : public QObject
0051 {
0052     Q_OBJECT
0053 
0054 private Q_SLOTS:
0055     void initTestCase();
0056     void init();
0057     void cleanup();
0058 
0059     void testConstructor();
0060 
0061     void testCurrentItemAnchorItem();
0062     void testSetSelected_data();
0063     void testSetSelected();
0064     void testItemsInserted();
0065     void testItemsRemoved();
0066     void testAnchoredSelection();
0067     void testChangeSelection_data();
0068     void testChangeSelection();
0069     void testDeleteCurrentItem_data();
0070     void testDeleteCurrentItem();
0071     void testAnchoredSelectionAfterMovingItems();
0072 
0073 private:
0074     void verifySelectionChange(QSignalSpy &spy, const KItemSet &currentSelection, const KItemSet &previousSelection) const;
0075 
0076     KItemListSelectionManager *m_selectionManager;
0077     DummyModel *m_model;
0078 };
0079 
0080 void KItemListSelectionManagerTest::initTestCase()
0081 {
0082     QStandardPaths::setTestModeEnabled(true);
0083 }
0084 
0085 void KItemListSelectionManagerTest::init()
0086 {
0087     m_model = new DummyModel();
0088     m_selectionManager = new KItemListSelectionManager();
0089     m_selectionManager->setModel(m_model);
0090 }
0091 
0092 void KItemListSelectionManagerTest::cleanup()
0093 {
0094     delete m_selectionManager;
0095     m_selectionManager = nullptr;
0096 
0097     delete m_model;
0098     m_model = nullptr;
0099 }
0100 
0101 void KItemListSelectionManagerTest::testConstructor()
0102 {
0103     QVERIFY(!m_selectionManager->hasSelection());
0104     QCOMPARE(m_selectionManager->selectedItems().count(), 0);
0105     QCOMPARE(m_selectionManager->currentItem(), 0);
0106     QCOMPARE(m_selectionManager->m_anchorItem, -1);
0107 }
0108 
0109 void KItemListSelectionManagerTest::testCurrentItemAnchorItem()
0110 {
0111     QSignalSpy spyCurrent(m_selectionManager, &KItemListSelectionManager::currentChanged);
0112 
0113     // Set current item and check that the selection manager emits the currentChanged(int,int) signal correctly.
0114     m_selectionManager->setCurrentItem(4);
0115     QCOMPARE(m_selectionManager->currentItem(), 4);
0116     QCOMPARE(spyCurrent.count(), 1);
0117     QCOMPARE(qvariant_cast<int>(spyCurrent.at(0).at(0)), 4);
0118     spyCurrent.takeFirst();
0119 
0120     // Begin an anchored selection.
0121     m_selectionManager->beginAnchoredSelection(5);
0122     QVERIFY(m_selectionManager->isAnchoredSelectionActive());
0123     QCOMPARE(m_selectionManager->m_anchorItem, 5);
0124 
0125     // Items between current and anchor should be selected now
0126     QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 4 << 5);
0127     QVERIFY(m_selectionManager->hasSelection());
0128 
0129     // Change current item again and check the selection
0130     m_selectionManager->setCurrentItem(2);
0131     QCOMPARE(m_selectionManager->currentItem(), 2);
0132     QCOMPARE(spyCurrent.count(), 1);
0133     QCOMPARE(qvariant_cast<int>(spyCurrent.at(0).at(0)), 2);
0134     QCOMPARE(qvariant_cast<int>(spyCurrent.at(0).at(1)), 4);
0135     spyCurrent.takeFirst();
0136 
0137     QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 2 << 3 << 4 << 5);
0138     QVERIFY(m_selectionManager->hasSelection());
0139 
0140     // Inserting items should update current item and anchor item.
0141     m_selectionManager->itemsInserted(KItemRangeList() << KItemRange(0, 1) << KItemRange(2, 2) << KItemRange(6, 3));
0142 
0143     QCOMPARE(m_selectionManager->currentItem(), 5);
0144     QCOMPARE(spyCurrent.count(), 1);
0145     QCOMPARE(qvariant_cast<int>(spyCurrent.at(0).at(0)), 5);
0146     QCOMPARE(qvariant_cast<int>(spyCurrent.at(0).at(1)), 2);
0147     spyCurrent.takeFirst();
0148 
0149     QCOMPARE(m_selectionManager->m_anchorItem, 8);
0150 
0151     QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 5 << 6 << 7 << 8);
0152     QVERIFY(m_selectionManager->hasSelection());
0153 
0154     // Removing items should update current item and anchor item.
0155     m_selectionManager->itemsRemoved(KItemRangeList() << KItemRange(0, 2) << KItemRange(2, 1) << KItemRange(9, 2));
0156 
0157     QCOMPARE(m_selectionManager->currentItem(), 2);
0158     QCOMPARE(spyCurrent.count(), 1);
0159     QCOMPARE(qvariant_cast<int>(spyCurrent.at(0).at(0)), 2);
0160     QCOMPARE(qvariant_cast<int>(spyCurrent.at(0).at(1)), 5);
0161     spyCurrent.takeFirst();
0162 
0163     QCOMPARE(m_selectionManager->m_anchorItem, 5);
0164 
0165     QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 2 << 3 << 4 << 5);
0166     QVERIFY(m_selectionManager->hasSelection());
0167 
0168     // Verify that clearSelection() also clears the anchored selection.
0169     m_selectionManager->clearSelection();
0170     QCOMPARE(m_selectionManager->selectedItems(), KItemSet());
0171     QVERIFY(!m_selectionManager->hasSelection());
0172 
0173     m_selectionManager->endAnchoredSelection();
0174     QVERIFY(!m_selectionManager->isAnchoredSelectionActive());
0175 }
0176 
0177 void KItemListSelectionManagerTest::testSetSelected_data()
0178 {
0179     QTest::addColumn<int>("index");
0180     QTest::addColumn<int>("count");
0181     QTest::addColumn<int>("expectedSelectionCount");
0182 
0183     QTest::newRow("Select all") << 0 << 100 << 100;
0184     QTest::newRow("Sub selection 15 items") << 20 << 15 << 15;
0185     QTest::newRow("Sub selection 1 item") << 20 << 1 << 1;
0186     QTest::newRow("Too small index") << -1 << 100 << 0;
0187     QTest::newRow("Too large index") << 100 << 100 << 0;
0188     QTest::newRow("Too large count") << 0 << 100000 << 100;
0189     QTest::newRow("Too small count") << 0 << 0 << 0;
0190 }
0191 
0192 void KItemListSelectionManagerTest::testSetSelected()
0193 {
0194     QFETCH(int, index);
0195     QFETCH(int, count);
0196     QFETCH(int, expectedSelectionCount);
0197     m_selectionManager->setSelected(index, count);
0198     QCOMPARE(m_selectionManager->selectedItems().count(), expectedSelectionCount);
0199 }
0200 
0201 void KItemListSelectionManagerTest::testItemsInserted()
0202 {
0203     // Select items 10 to 12
0204     m_selectionManager->setSelected(10, 3);
0205     KItemSet selectedItems = m_selectionManager->selectedItems();
0206     QCOMPARE(selectedItems.count(), 3);
0207     QVERIFY(selectedItems.contains(10));
0208     QVERIFY(selectedItems.contains(11));
0209     QVERIFY(selectedItems.contains(12));
0210 
0211     // Insert items 0 to 4 -> selection must be 15 to 17
0212     m_selectionManager->itemsInserted(KItemRangeList() << KItemRange(0, 5));
0213     selectedItems = m_selectionManager->selectedItems();
0214     QCOMPARE(selectedItems.count(), 3);
0215     QVERIFY(selectedItems.contains(15));
0216     QVERIFY(selectedItems.contains(16));
0217     QVERIFY(selectedItems.contains(17));
0218 
0219     // Insert 3 items between the selections
0220     m_selectionManager->itemsInserted(KItemRangeList() << KItemRange(15, 1) << KItemRange(16, 1) << KItemRange(17, 1));
0221     selectedItems = m_selectionManager->selectedItems();
0222     QCOMPARE(selectedItems.count(), 3);
0223     QVERIFY(selectedItems.contains(16));
0224     QVERIFY(selectedItems.contains(18));
0225     QVERIFY(selectedItems.contains(20));
0226 }
0227 
0228 void KItemListSelectionManagerTest::testItemsRemoved()
0229 {
0230     // Select items 10 to 15
0231     m_selectionManager->setSelected(10, 6);
0232     KItemSet selectedItems = m_selectionManager->selectedItems();
0233     QCOMPARE(selectedItems.count(), 6);
0234     for (int i = 10; i <= 15; ++i) {
0235         QVERIFY(selectedItems.contains(i));
0236     }
0237 
0238     // Remove items 0 to 4 -> selection must be 5 to 10
0239     m_selectionManager->itemsRemoved(KItemRangeList() << KItemRange(0, 5));
0240     selectedItems = m_selectionManager->selectedItems();
0241     QCOMPARE(selectedItems.count(), 6);
0242     for (int i = 5; i <= 10; ++i) {
0243         QVERIFY(selectedItems.contains(i));
0244     }
0245 
0246     // Remove the items 6 , 8 and 10
0247     m_selectionManager->itemsRemoved(KItemRangeList() << KItemRange(6, 1) << KItemRange(8, 1) << KItemRange(10, 1));
0248     selectedItems = m_selectionManager->selectedItems();
0249     QCOMPARE(selectedItems.count(), 3);
0250     QVERIFY(selectedItems.contains(5));
0251     QVERIFY(selectedItems.contains(6));
0252     QVERIFY(selectedItems.contains(7));
0253 }
0254 
0255 void KItemListSelectionManagerTest::testAnchoredSelection()
0256 {
0257     m_selectionManager->beginAnchoredSelection(5);
0258     QVERIFY(m_selectionManager->isAnchoredSelectionActive());
0259     QCOMPARE(m_selectionManager->m_anchorItem, 5);
0260 
0261     m_selectionManager->setCurrentItem(6);
0262     QCOMPARE(m_selectionManager->currentItem(), 6);
0263     QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 5 << 6);
0264 
0265     m_selectionManager->setCurrentItem(4);
0266     QCOMPARE(m_selectionManager->currentItem(), 4);
0267     QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 4 << 5);
0268 
0269     m_selectionManager->setCurrentItem(7);
0270     QCOMPARE(m_selectionManager->currentItem(), 7);
0271     QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 5 << 6 << 7);
0272 
0273     // Ending the anchored selection should not change the selected items.
0274     m_selectionManager->endAnchoredSelection();
0275     QVERIFY(!m_selectionManager->isAnchoredSelectionActive());
0276     QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 5 << 6 << 7);
0277 
0278     // Start a new anchored selection that overlaps the previous one
0279     m_selectionManager->beginAnchoredSelection(9);
0280     QVERIFY(m_selectionManager->isAnchoredSelectionActive());
0281     QCOMPARE(m_selectionManager->m_anchorItem, 9);
0282 
0283     m_selectionManager->setCurrentItem(6);
0284     QCOMPARE(m_selectionManager->currentItem(), 6);
0285     QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 5 << 6 << 7 << 8 << 9);
0286 
0287     m_selectionManager->setCurrentItem(10);
0288     QCOMPARE(m_selectionManager->currentItem(), 10);
0289     QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 5 << 6 << 7 << 9 << 10);
0290 
0291     m_selectionManager->endAnchoredSelection();
0292     QVERIFY(!m_selectionManager->isAnchoredSelectionActive());
0293     QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 5 << 6 << 7 << 9 << 10);
0294 }
0295 
0296 namespace
0297 {
0298 enum ChangeType { NoChange, InsertItems, RemoveItems, MoveItems, EndAnchoredSelection, SetSelected };
0299 }
0300 
0301 Q_DECLARE_METATYPE(KItemSet)
0302 Q_DECLARE_METATYPE(ChangeType)
0303 Q_DECLARE_METATYPE(KItemRange)
0304 Q_DECLARE_METATYPE(KItemRangeList)
0305 Q_DECLARE_METATYPE(KItemListSelectionManager::SelectionMode)
0306 Q_DECLARE_METATYPE(QList<int>)
0307 
0308 /**
0309  * The following function provides a generic way to test the selection functionality.
0310  *
0311  * The test is data-driven and takes the following arguments:
0312  *
0313  * param initialSelection  The selection at the beginning.
0314  * param anchor            This item will be the anchor item.
0315  * param current           This item will be the current item.
0316  * param expectedSelection Expected selection after anchor and current are set.
0317  * param changeType        Type of the change that is done then:
0318  *                        - NoChange
0319  *                        - InsertItems -> data.at(0) provides the KItemRangeList. \sa KItemListSelectionManager::itemsInserted()
0320  *                        - RemoveItems -> data.at(0) provides the KItemRangeList. \sa KItemListSelectionManager::itemsRemoved()
0321  *                        - MoveItems   -> data.at(0) provides the KItemRange containing the original indices,
0322  *                                         data.at(1) provides the list containing the new indices
0323  *                                        \sa KItemListSelectionManager::itemsMoved(), KItemModelBase::itemsMoved()
0324  *                        - EndAnchoredSelection
0325  *                        - SetSelected -> data.at(0) provides the index where the selection process starts,
0326  *                                         data.at(1) provides the number of indices to be selected,
0327  *                                         data.at(2) provides the selection mode.
0328  *                                        \sa KItemListSelectionManager::setSelected()
0329  * param data              A list of QVariants which will be cast to the arguments needed for the chosen ChangeType (see above).
0330  * param finalSelection    The expected final selection.
0331  *
0332  */
0333 void KItemListSelectionManagerTest::testChangeSelection_data()
0334 {
0335     QTest::addColumn<KItemSet>("initialSelection");
0336     QTest::addColumn<int>("anchor");
0337     QTest::addColumn<int>("current");
0338     QTest::addColumn<KItemSet>("expectedSelection");
0339     QTest::addColumn<ChangeType>("changeType");
0340     QTest::addColumn<QList<QVariant>>("data");
0341     QTest::addColumn<KItemSet>("finalSelection");
0342 
0343     QTest::newRow("No change") << (KItemSet() << 5 << 6) << 2 << 3 << (KItemSet() << 2 << 3 << 5 << 6) << NoChange << QList<QVariant>{}
0344                                << (KItemSet() << 2 << 3 << 5 << 6);
0345 
0346     QTest::newRow("Insert Items") << (KItemSet() << 5 << 6) << 2 << 3 << (KItemSet() << 2 << 3 << 5 << 6) << InsertItems
0347                                   << QList<QVariant>{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(5, 2) << KItemRange(10, 5))}
0348                                   << (KItemSet() << 3 << 4 << 8 << 9);
0349 
0350     QTest::newRow("Remove Items") << (KItemSet() << 5 << 6) << 2 << 3 << (KItemSet() << 2 << 3 << 5 << 6) << RemoveItems
0351                                   << QList<QVariant>{QVariant::fromValue(KItemRangeList() << KItemRange(1, 1) << KItemRange(3, 1) << KItemRange(10, 5))}
0352                                   << (KItemSet() << 1 << 2 << 3 << 4);
0353 
0354     QTest::newRow("Empty Anchored Selection") << KItemSet() << 2 << 2 << KItemSet() << EndAnchoredSelection << QList<QVariant>{} << KItemSet();
0355 
0356     QTest::newRow("Toggle selection") << (KItemSet() << 1 << 3 << 4) << 6 << 8 << (KItemSet() << 1 << 3 << 4 << 6 << 7 << 8) << SetSelected
0357                                       << QList<QVariant>{0, 10, QVariant::fromValue(KItemListSelectionManager::Toggle)} << (KItemSet() << 0 << 2 << 5 << 9);
0358 
0359     // Swap items 2, 3 and 4, 5
0360     QTest::newRow("Move items") << (KItemSet() << 0 << 1 << 2 << 3) << -1 << -1 << (KItemSet() << 0 << 1 << 2 << 3) << MoveItems
0361                                 << QList<QVariant>{QVariant::fromValue(KItemRange(2, 4)), QVariant::fromValue(QList<int>{4, 5, 2, 3})}
0362                                 << (KItemSet() << 0 << 1 << 4 << 5);
0363 
0364     QTest::newRow("Move items with active anchored selection")
0365         << KItemSet() << 0 << 3 << (KItemSet() << 0 << 1 << 2 << 3) << MoveItems
0366         << QList<QVariant>{QVariant::fromValue(KItemRange(2, 4)), QVariant::fromValue(QList<int>{4, 5, 2, 3})} << (KItemSet() << 0 << 1 << 4 << 5);
0367 
0368     // Revert sort order
0369     QTest::newRow("Revert sort order") << (KItemSet() << 0 << 1) << 3 << 4 << (KItemSet() << 0 << 1 << 3 << 4) << MoveItems
0370                                        << QList<QVariant>{QVariant::fromValue(KItemRange(0, 10)), QVariant::fromValue(QList<int>{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})}
0371                                        << (KItemSet() << 5 << 6 << 8 << 9);
0372 }
0373 
0374 void KItemListSelectionManagerTest::testChangeSelection()
0375 {
0376     QFETCH(KItemSet, initialSelection);
0377     QFETCH(int, anchor);
0378     QFETCH(int, current);
0379     QFETCH(KItemSet, expectedSelection);
0380     QFETCH(ChangeType, changeType);
0381     QFETCH(QList<QVariant>, data);
0382     QFETCH(KItemSet, finalSelection);
0383 
0384     QSignalSpy spySelectionChanged(m_selectionManager, &KItemListSelectionManager::selectionChanged);
0385 
0386     // Initial selection should be empty
0387     QVERIFY(!m_selectionManager->hasSelection());
0388     QVERIFY(m_selectionManager->selectedItems().isEmpty());
0389 
0390     // Perform the initial selection
0391     m_selectionManager->setSelectedItems(initialSelection);
0392 
0393     verifySelectionChange(spySelectionChanged, initialSelection, KItemSet());
0394 
0395     // Perform an anchored selection.
0396     // Note that current and anchor index are equal first because this is the case in typical uses of the
0397     // selection manager, and because this makes it easier to test the correctness of the signal's arguments.
0398     m_selectionManager->setCurrentItem(anchor);
0399     m_selectionManager->beginAnchoredSelection(anchor);
0400     m_selectionManager->setCurrentItem(current);
0401     QCOMPARE(m_selectionManager->m_anchorItem, anchor);
0402     QCOMPARE(m_selectionManager->currentItem(), current);
0403 
0404     verifySelectionChange(spySelectionChanged, expectedSelection, initialSelection);
0405 
0406     // Change the model by inserting or removing items.
0407     switch (changeType) {
0408     case InsertItems:
0409         m_selectionManager->itemsInserted(data.at(0).value<KItemRangeList>());
0410         break;
0411     case RemoveItems:
0412         m_selectionManager->itemsRemoved(data.at(0).value<KItemRangeList>());
0413         break;
0414     case MoveItems:
0415         m_selectionManager->itemsMoved(data.at(0).value<KItemRange>(), data.at(1).value<QList<int>>());
0416         break;
0417     case EndAnchoredSelection:
0418         m_selectionManager->endAnchoredSelection();
0419         QVERIFY(!m_selectionManager->isAnchoredSelectionActive());
0420         break;
0421     case SetSelected:
0422         m_selectionManager->setSelected(data.at(0).value<int>(), // index
0423                                         data.at(1).value<int>(), // count
0424                                         data.at(2).value<KItemListSelectionManager::SelectionMode>());
0425         break;
0426     case NoChange:
0427         break;
0428     }
0429 
0430     verifySelectionChange(spySelectionChanged, finalSelection, expectedSelection);
0431 
0432     // Finally, clear the selection
0433     m_selectionManager->clearSelection();
0434 
0435     verifySelectionChange(spySelectionChanged, KItemSet(), finalSelection);
0436 }
0437 
0438 void KItemListSelectionManagerTest::testDeleteCurrentItem_data()
0439 {
0440     QTest::addColumn<int>("oldCurrentItemIndex");
0441     QTest::addColumn<int>("removeIndex");
0442     QTest::addColumn<int>("removeCount");
0443     QTest::addColumn<int>("newCurrentItemIndex");
0444 
0445     QTest::newRow("Remove before") << 50 << 0 << 10 << 40;
0446     QTest::newRow("Remove after") << 50 << 51 << 10 << 50;
0447     QTest::newRow("Remove exactly current item") << 50 << 50 << 1 << 50;
0448     QTest::newRow("Remove around current item") << 50 << 45 << 10 << 45;
0449     QTest::newRow("Remove all except one item") << 50 << 1 << 99 << 0;
0450 }
0451 
0452 void KItemListSelectionManagerTest::testDeleteCurrentItem()
0453 {
0454     QFETCH(int, oldCurrentItemIndex);
0455     QFETCH(int, removeIndex);
0456     QFETCH(int, removeCount);
0457     QFETCH(int, newCurrentItemIndex);
0458 
0459     m_selectionManager->setCurrentItem(oldCurrentItemIndex);
0460 
0461     const int newCount = m_model->count() - removeCount;
0462     m_model->setCount(newCount);
0463     m_selectionManager->itemsRemoved(KItemRangeList() << KItemRange(removeIndex, removeCount));
0464 
0465     QCOMPARE(m_selectionManager->currentItem(), newCurrentItemIndex);
0466 }
0467 
0468 void KItemListSelectionManagerTest::testAnchoredSelectionAfterMovingItems()
0469 {
0470     m_selectionManager->setCurrentItem(4);
0471     m_selectionManager->beginAnchoredSelection(4);
0472 
0473     // Reverse the items between 0 and 5.
0474     m_selectionManager->itemsMoved(KItemRange(0, 6), {5, 4, 3, 2, 1, 0});
0475 
0476     QCOMPARE(m_selectionManager->currentItem(), 1);
0477     QCOMPARE(m_selectionManager->m_anchorItem, 1);
0478 
0479     // Make 2 the current item -> 1 and 2 should be selected.
0480     m_selectionManager->setCurrentItem(2);
0481     QCOMPARE(m_selectionManager->selectedItems(), KItemSet() << 1 << 2);
0482 }
0483 
0484 void KItemListSelectionManagerTest::verifySelectionChange(QSignalSpy &spy, const KItemSet &currentSelection, const KItemSet &previousSelection) const
0485 {
0486     QCOMPARE(m_selectionManager->selectedItems(), currentSelection);
0487     QCOMPARE(m_selectionManager->hasSelection(), !currentSelection.isEmpty());
0488     for (int index = 0; index < m_selectionManager->model()->count(); ++index) {
0489         if (currentSelection.contains(index)) {
0490             QVERIFY(m_selectionManager->isSelected(index));
0491         } else {
0492             QVERIFY(!m_selectionManager->isSelected(index));
0493         }
0494     }
0495 
0496     if (currentSelection == previousSelection) {
0497         QCOMPARE(spy.count(), 0);
0498     } else {
0499         QCOMPARE(spy.count(), 1);
0500         QList<QVariant> arguments = spy.takeFirst();
0501         QCOMPARE(qvariant_cast<KItemSet>(arguments.at(0)), currentSelection);
0502         QCOMPARE(qvariant_cast<KItemSet>(arguments.at(1)), previousSelection);
0503     }
0504 }
0505 
0506 QTEST_GUILESS_MAIN(KItemListSelectionManagerTest)
0507 
0508 #include "kitemlistselectionmanagertest.moc"