]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tests/kfileitemlistviewtest.cpp
775602f9f899924e54091e797979fafdf75e9348
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "kitemviews/kfileitemlistview.h"
21 #include "kitemviews/kfileitemmodel.h"
22 #include "kitemviews/private/kfileitemmodeldirlister.h"
25 #include <QGraphicsView>
29 class KFileItemListViewTest
: public QObject
36 void testGroupedItemChanges();
39 KFileItemListView
* m_listView
;
40 KFileItemModel
* m_model
;
42 QGraphicsView
* m_graphicsView
;
45 void KFileItemListViewTest::init()
47 qRegisterMetaType
<KItemRangeList
>("KItemRangeList");
48 qRegisterMetaType
<KFileItemList
>("KFileItemList");
50 m_testDir
= new TestDir();
51 m_model
= new KFileItemModel();
52 m_model
->m_dirLister
->setAutoUpdate(false);
54 m_listView
= new KFileItemListView();
55 m_listView
->onModelChanged(m_model
, nullptr);
57 m_graphicsView
= new QGraphicsView();
58 m_graphicsView
->show();
59 QVERIFY(QTest::qWaitForWindowExposed(m_graphicsView
));
62 void KFileItemListViewTest::cleanup()
64 delete m_graphicsView
;
65 m_graphicsView
= nullptr;
78 * If grouping is enabled, the group headers must be updated
79 * when items have been inserted or removed. This updating
80 * may only be done after all multiple ranges have been inserted
81 * or removed and not after each individual range (see description
82 * in #ifndef QT_NO_DEBUG-block of KItemListView::slotItemsInserted()
83 * and KItemListView::slotItemsRemoved()). This test inserts and
84 * removes multiple ranges and will trigger the Q_ASSERT in the
85 * ifndef QT_NO_DEBUG-block in case if a group-header will be updated
88 void KFileItemListViewTest::testGroupedItemChanges()
90 QSignalSpy
itemsInsertedSpy(m_model
, &KFileItemModel::itemsInserted
);
91 QVERIFY(itemsInsertedSpy
.isValid());
92 QSignalSpy
itemsRemovedSpy(m_model
, &KFileItemModel::itemsRemoved
);
93 QVERIFY(itemsRemovedSpy
.isValid());
95 m_model
->setGroupedSorting(true);
97 m_testDir
->createFiles({"1", "3", "5"});
98 m_model
->loadDirectory(m_testDir
->url());
99 QVERIFY(itemsInsertedSpy
.wait());
100 QCOMPARE(m_model
->count(), 3);
102 m_testDir
->createFiles({"2", "4"});
103 m_model
->m_dirLister
->updateDirectory(m_testDir
->url());
104 QVERIFY(itemsInsertedSpy
.wait());
105 QCOMPARE(m_model
->count(), 5);
107 m_testDir
->removeFiles({"1", "3", "5"});
108 m_model
->m_dirLister
->updateDirectory(m_testDir
->url());
109 QVERIFY(itemsRemovedSpy
.wait());
110 QCOMPARE(m_model
->count(), 2);
113 QTEST_MAIN(KFileItemListViewTest
)
115 #include "kfileitemlistviewtest.moc"