]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Test setting the current item and anchor item
authorFrank Reininghaus <frank78ac@googlemail.com>
Tue, 9 Aug 2011 17:44:49 +0000 (19:44 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Tue, 9 Aug 2011 17:44:49 +0000 (19:44 +0200)
src/tests/kitemlistselectionmanagertest.cpp

index 6fdf01b84c3644f65015718cbfdeb39eb7903a88..3d0c318ffc9467ec59d20fecfe53746b8c63000a 100644 (file)
@@ -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<int>(spyCurrent.at(0).at(0)), 4);
+    spyCurrent.takeFirst();
+
+    m_selectionManager->setCurrentItem(2);
+    QCOMPARE(m_selectionManager->currentItem(), 2);
+    QCOMPARE(spyCurrent.count(), 1);
+    QCOMPARE(qvariant_cast<int>(spyCurrent.at(0).at(0)), 2);
+    QCOMPARE(qvariant_cast<int>(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<int>(spyAnchor.at(0).at(0)), 3);
+    spyAnchor.takeFirst();
+
+    m_selectionManager->setAnchorItem(5);
+    QCOMPARE(m_selectionManager->anchorItem(), 5);
+    QCOMPARE(spyAnchor.count(), 1);
+    QCOMPARE(qvariant_cast<int>(spyAnchor.at(0).at(0)), 5);
+    QCOMPARE(qvariant_cast<int>(spyAnchor.at(0).at(1)), 3);
+    spyAnchor.takeFirst();
+}
+
 void KItemListSelectionManagerTest::testSetSelected_data()
 {
     QTest::addColumn<int>("index");