From 84aa4e75b492c74ce29fcadd572bee338f009b0b Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Tue, 9 Aug 2011 19:44:49 +0200 Subject: [PATCH] Test setting the current item and anchor item --- src/tests/kitemlistselectionmanagertest.cpp | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/tests/kitemlistselectionmanagertest.cpp b/src/tests/kitemlistselectionmanagertest.cpp index 6fdf01b84..3d0c318ff 100644 --- a/src/tests/kitemlistselectionmanagertest.cpp +++ b/src/tests/kitemlistselectionmanagertest.cpp @@ -58,6 +58,7 @@ private slots: void testConstructor(); + void testCurrentItemAnchorItem(); void testSetSelected_data(); void testSetSelected(); void testItemsInserted(); @@ -88,6 +89,40 @@ void KItemListSelectionManagerTest::testConstructor() QCOMPARE(m_selectionManager->anchorItem(), -1); } +void KItemListSelectionManagerTest::testCurrentItemAnchorItem() +{ + QSignalSpy spyCurrent(m_selectionManager, SIGNAL(currentChanged(int,int))); + QSignalSpy spyAnchor(m_selectionManager, SIGNAL(anchorChanged(int,int)));; + + // Set current item and check that the selection manager emits the currentChanged(int,int) signal correctly. + m_selectionManager->setCurrentItem(4); + QCOMPARE(m_selectionManager->currentItem(), 4); + QCOMPARE(spyCurrent.count(), 1); + QCOMPARE(qvariant_cast(spyCurrent.at(0).at(0)), 4); + spyCurrent.takeFirst(); + + m_selectionManager->setCurrentItem(2); + QCOMPARE(m_selectionManager->currentItem(), 2); + QCOMPARE(spyCurrent.count(), 1); + QCOMPARE(qvariant_cast(spyCurrent.at(0).at(0)), 2); + QCOMPARE(qvariant_cast(spyCurrent.at(0).at(1)), 4); + spyCurrent.takeFirst(); + + // Set anchor item and check that the selection manager emits the anchorChanged(int,int) signal correctly. + m_selectionManager->setAnchorItem(3); + QCOMPARE(m_selectionManager->anchorItem(), 3); + QCOMPARE(spyAnchor.count(), 1); + QCOMPARE(qvariant_cast(spyAnchor.at(0).at(0)), 3); + spyAnchor.takeFirst(); + + m_selectionManager->setAnchorItem(5); + QCOMPARE(m_selectionManager->anchorItem(), 5); + QCOMPARE(spyAnchor.count(), 1); + QCOMPARE(qvariant_cast(spyAnchor.at(0).at(0)), 5); + QCOMPARE(qvariant_cast(spyAnchor.at(0).at(1)), 3); + spyAnchor.takeFirst(); +} + void KItemListSelectionManagerTest::testSetSelected_data() { QTest::addColumn("index"); -- 2.47.3