]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/tests/kitemlistselectionmanagertest.cpp
Merge branch 'release/21.12'
[dolphin.git] / src / tests / kitemlistselectionmanagertest.cpp
index 8403de70160b846bc1fbe9e0fa63f50090dc208e..7f87fdcc85b3170e2d55acf5e84ce817e3bde925 100644 (file)
@@ -1,36 +1,25 @@
-/***************************************************************************
- *   Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com>             *
- *   Copyright (C) 2011 by Frank Reininghaus <frank78ac@googlemail.com>    *
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- *   This program is distributed in the hope that it will be useful,       *
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
- *   GNU General Public License for more details.                          *
- *                                                                         *
- *   You should have received a copy of the GNU General Public License     *
- *   along with this program; if not, write to the                         *
- *   Free Software Foundation, Inc.,                                       *
- *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
- ***************************************************************************/
+/*
+ * SPDX-FileCopyrightText: 2011 Peter Penz <peter.penz19@gmail.com>
+ * SPDX-FileCopyrightText: 2011 Frank Reininghaus <frank78ac@googlemail.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #include "kitemviews/kitemmodelbase.h"
 #include "kitemviews/kitemlistselectionmanager.h"
 
 #include <QTest>
 #include <QSignalSpy>
+#include <QStandardPaths>
 
 class DummyModel : public KItemModelBase
 {
+    Q_OBJECT
 public:
     DummyModel();
     void setCount(int count);
-    virtual int count() const;
-    virtual QHash<QByteArray, QVariant> data(int index) const;
+    int count() const override;
+    QHash<QByteArray, QVariant> data(int index) const override;
 
 private:
     int m_count;
@@ -54,7 +43,7 @@ int DummyModel::count() const
 
 QHash<QByteArray, QVariant> DummyModel::data(int index) const
 {
-    Q_UNUSED(index);
+    Q_UNUSED(index)
     return QHash<QByteArray, QVariant>();
 }
 
@@ -63,7 +52,8 @@ class KItemListSelectionManagerTest : public QObject
 {
     Q_OBJECT
 
-private slots:
+private Q_SLOTS:
+    void initTestCase();
     void init();
     void cleanup();
 
@@ -88,6 +78,11 @@ private:
     DummyModel* m_model;
 };
 
+void KItemListSelectionManagerTest::initTestCase()
+{
+    QStandardPaths::setTestModeEnabled(true);
+}
+
 void KItemListSelectionManagerTest::init()
 {
     m_model = new DummyModel();
@@ -98,10 +93,10 @@ void KItemListSelectionManagerTest::init()
 void KItemListSelectionManagerTest::cleanup()
 {
     delete m_selectionManager;
-    m_selectionManager = 0;
+    m_selectionManager = nullptr;
 
     delete m_model;
-    m_model = 0;
+    m_model = nullptr;
 }
 
 void KItemListSelectionManagerTest::testConstructor()
@@ -114,7 +109,7 @@ void KItemListSelectionManagerTest::testConstructor()
 
 void KItemListSelectionManagerTest::testCurrentItemAnchorItem()
 {
-    QSignalSpy spyCurrent(m_selectionManager, SIGNAL(currentChanged(int,int)));
+    QSignalSpy spyCurrent(m_selectionManager, &KItemListSelectionManager::currentChanged);
 
     // Set current item and check that the selection manager emits the currentChanged(int,int) signal correctly.
     m_selectionManager->setCurrentItem(4);
@@ -322,39 +317,38 @@ namespace {
     };
 }
 
-Q_DECLARE_METATYPE(KItemSet);
-Q_DECLARE_METATYPE(ChangeType);
-Q_DECLARE_METATYPE(KItemRange);
-Q_DECLARE_METATYPE(KItemRangeList);
-Q_DECLARE_METATYPE(KItemListSelectionManager::SelectionMode);
-Q_DECLARE_METATYPE(QList<int>);
+Q_DECLARE_METATYPE(KItemSet)
+Q_DECLARE_METATYPE(ChangeType)
+Q_DECLARE_METATYPE(KItemRange)
+Q_DECLARE_METATYPE(KItemRangeList)
+Q_DECLARE_METATYPE(KItemListSelectionManager::SelectionMode)
+Q_DECLARE_METATYPE(QList<int>)
 
 /**
  * The following function provides a generic way to test the selection functionality.
  *
  * The test is data-driven and takes the following arguments:
  *
- * \param initialSelection  The selection at the beginning.
- * \param anchor            This item will be the anchor item.
- * \param current           This item will be the current item.
- * \param expectedSelection Expected selection after anchor and current are set.
- * \param changeType        Type of the change that is done then:
- *                          - NoChange
- *                          - InsertItems -> data.at(0) provides the KItemRangeList. \sa KItemListSelectionManager::itemsInserted()
- *                          - RemoveItems -> data.at(0) provides the KItemRangeList. \sa KItemListSelectionManager::itemsRemoved()
- *                          - MoveItems   -> data.at(0) provides the KItemRange containing the original indices,
- *                                           data.at(1) provides the list containing the new indices
- *                                          \sa KItemListSelectionManager::itemsMoved(), KItemModelBase::itemsMoved()
- *                          - EndAnchoredSelection
- *                          - SetSelected -> data.at(0) provides the index where the selection process starts,
- *                                           data.at(1) provides the number of indices to be selected,
- *                                           data.at(2) provides the selection mode.
- *                                          \sa KItemListSelectionManager::setSelected()
- * \param data              A list of QVariants which will be cast to the arguments needed for the chosen ChangeType (see above).
- * \param finalSelection    The expected final selection.
+ * param initialSelection  The selection at the beginning.
+ * param anchor            This item will be the anchor item.
+ * param current           This item will be the current item.
+ * param expectedSelection Expected selection after anchor and current are set.
+ * param changeType        Type of the change that is done then:
+ *                        - NoChange
+ *                        - InsertItems -> data.at(0) provides the KItemRangeList. \sa KItemListSelectionManager::itemsInserted()
+ *                        - RemoveItems -> data.at(0) provides the KItemRangeList. \sa KItemListSelectionManager::itemsRemoved()
+ *                        - MoveItems   -> data.at(0) provides the KItemRange containing the original indices,
+ *                                         data.at(1) provides the list containing the new indices
+ *                                        \sa KItemListSelectionManager::itemsMoved(), KItemModelBase::itemsMoved()
+ *                        - EndAnchoredSelection
+ *                        - SetSelected -> data.at(0) provides the index where the selection process starts,
+ *                                         data.at(1) provides the number of indices to be selected,
+ *                                         data.at(2) provides the selection mode.
+ *                                        \sa KItemListSelectionManager::setSelected()
+ * param data              A list of QVariants which will be cast to the arguments needed for the chosen ChangeType (see above).
+ * param finalSelection    The expected final selection.
  *
  */
-
 void KItemListSelectionManagerTest::testChangeSelection_data()
 {
     QTest::addColumn<KItemSet>("initialSelection");
@@ -445,13 +439,13 @@ void KItemListSelectionManagerTest::testChangeSelection()
     QFETCH(QList<QVariant>, data);
     QFETCH(KItemSet, finalSelection);
 
-    QSignalSpy spySelectionChanged(m_selectionManager, SIGNAL(selectionChanged(KItemSet,KItemSet)));
+    QSignalSpy spySelectionChanged(m_selectionManager, &KItemListSelectionManager::selectionChanged);
 
     // Initial selection should be empty
     QVERIFY(!m_selectionManager->hasSelection());
     QVERIFY(m_selectionManager->selectedItems().isEmpty());
 
-    // Perform the initial selectiion
+    // Perform the initial selection
     m_selectionManager->setSelectedItems(initialSelection);
 
     verifySelectionChange(spySelectionChanged, initialSelection, KItemSet());
@@ -572,6 +566,6 @@ void KItemListSelectionManagerTest::verifySelectionChange(QSignalSpy& spy,
     }
 }
 
-QTEST_MAIN(KItemListSelectionManagerTest)
+QTEST_GUILESS_MAIN(KItemListSelectionManagerTest)
 
 #include "kitemlistselectionmanagertest.moc"