2011-07-30 18:13:09 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.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 *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "kitemviews/kfileitemlistview.h"
|
|
|
|
#include "kitemviews/kfileitemmodel.h"
|
2012-05-17 09:46:16 +00:00
|
|
|
#include "kitemviews/private/kfileitemmodeldirlister.h"
|
2011-07-30 18:13:09 +00:00
|
|
|
#include "testdir.h"
|
|
|
|
|
|
|
|
#include <QGraphicsView>
|
2014-12-18 13:56:46 +00:00
|
|
|
#include <QTest>
|
|
|
|
#include <QSignalSpy>
|
2011-07-30 18:13:09 +00:00
|
|
|
|
|
|
|
class KFileItemListViewTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
2012-05-17 09:46:16 +00:00
|
|
|
void testGroupedItemChanges();
|
2011-07-30 18:13:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
KFileItemListView* m_listView;
|
|
|
|
KFileItemModel* m_model;
|
|
|
|
TestDir* m_testDir;
|
|
|
|
QGraphicsView* m_graphicsView;
|
|
|
|
};
|
|
|
|
|
|
|
|
void KFileItemListViewTest::init()
|
|
|
|
{
|
|
|
|
qRegisterMetaType<KItemRangeList>("KItemRangeList");
|
|
|
|
qRegisterMetaType<KFileItemList>("KFileItemList");
|
|
|
|
|
|
|
|
m_testDir = new TestDir();
|
2012-05-17 09:46:16 +00:00
|
|
|
m_model = new KFileItemModel();
|
|
|
|
m_model->m_dirLister->setAutoUpdate(false);
|
2011-07-30 18:13:09 +00:00
|
|
|
|
|
|
|
m_listView = new KFileItemListView();
|
2017-11-21 09:52:14 +00:00
|
|
|
m_listView->onModelChanged(m_model, nullptr);
|
2011-07-30 18:13:09 +00:00
|
|
|
|
|
|
|
m_graphicsView = new QGraphicsView();
|
|
|
|
m_graphicsView->show();
|
2015-02-26 16:40:06 +00:00
|
|
|
QTest::qWaitForWindowExposed(m_graphicsView);
|
2011-07-30 18:13:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KFileItemListViewTest::cleanup()
|
|
|
|
{
|
|
|
|
delete m_graphicsView;
|
2017-11-21 09:52:14 +00:00
|
|
|
m_graphicsView = nullptr;
|
2011-07-30 18:13:09 +00:00
|
|
|
|
|
|
|
delete m_listView;
|
2017-11-21 09:52:14 +00:00
|
|
|
m_listView = nullptr;
|
2011-07-30 18:13:09 +00:00
|
|
|
|
|
|
|
delete m_model;
|
2017-11-21 09:52:14 +00:00
|
|
|
m_model = nullptr;
|
2011-07-30 18:13:09 +00:00
|
|
|
|
|
|
|
delete m_testDir;
|
2017-11-21 09:52:14 +00:00
|
|
|
m_testDir = nullptr;
|
2011-07-30 18:13:09 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 09:46:16 +00:00
|
|
|
/**
|
|
|
|
* If grouping is enabled, the group headers must be updated
|
|
|
|
* when items have been inserted or removed. This updating
|
|
|
|
* may only be done after all multiple ranges have been inserted
|
|
|
|
* or removed and not after each individual range (see description
|
|
|
|
* in #ifndef QT_NO_DEBUG-block of KItemListView::slotItemsInserted()
|
|
|
|
* and KItemListView::slotItemsRemoved()). This test inserts and
|
|
|
|
* removes multiple ranges and will trigger the Q_ASSERT in the
|
|
|
|
* ifndef QT_NO_DEBUG-block in case if a group-header will be updated
|
|
|
|
* too early.
|
|
|
|
*/
|
|
|
|
void KFileItemListViewTest::testGroupedItemChanges()
|
|
|
|
{
|
2018-02-03 19:46:08 +00:00
|
|
|
QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
|
2014-12-24 07:49:47 +00:00
|
|
|
QVERIFY(itemsInsertedSpy.isValid());
|
2018-02-03 19:46:08 +00:00
|
|
|
QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved);
|
2014-12-24 07:49:47 +00:00
|
|
|
QVERIFY(itemsRemovedSpy.isValid());
|
2014-12-18 13:56:46 +00:00
|
|
|
|
2012-05-17 09:46:16 +00:00
|
|
|
m_model->setGroupedSorting(true);
|
|
|
|
|
2014-11-10 07:45:38 +00:00
|
|
|
m_testDir->createFiles({"1", "3", "5"});
|
2012-05-17 09:46:16 +00:00
|
|
|
m_model->loadDirectory(m_testDir->url());
|
2014-12-18 13:56:46 +00:00
|
|
|
QVERIFY(itemsInsertedSpy.wait());
|
2012-05-17 09:46:16 +00:00
|
|
|
QCOMPARE(m_model->count(), 3);
|
|
|
|
|
2014-11-10 07:45:38 +00:00
|
|
|
m_testDir->createFiles({"2", "4"});
|
2012-05-17 09:46:16 +00:00
|
|
|
m_model->m_dirLister->updateDirectory(m_testDir->url());
|
2014-12-18 13:56:46 +00:00
|
|
|
QVERIFY(itemsInsertedSpy.wait());
|
2012-05-17 09:46:16 +00:00
|
|
|
QCOMPARE(m_model->count(), 5);
|
|
|
|
|
2014-12-18 13:56:46 +00:00
|
|
|
m_testDir->removeFiles({"1", "3", "5"});
|
2012-05-17 09:46:16 +00:00
|
|
|
m_model->m_dirLister->updateDirectory(m_testDir->url());
|
2014-12-18 13:56:46 +00:00
|
|
|
QVERIFY(itemsRemovedSpy.wait());
|
2012-05-17 09:46:16 +00:00
|
|
|
QCOMPARE(m_model->count(), 2);
|
|
|
|
}
|
|
|
|
|
2014-10-18 12:36:34 +00:00
|
|
|
QTEST_MAIN(KFileItemListViewTest)
|
2011-07-30 18:13:09 +00:00
|
|
|
|
|
|
|
#include "kfileitemlistviewtest.moc"
|