]>
cloud.milkyroute.net Git - dolphin.git/blob - src/tests/dolphinviewtest_allviewmodes.cpp
1 /***************************************************************************
2 * Copyright (C) 2010 by Frank Reininghaus (frank78ac@googlemail.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 "dolphinviewtest_allviewmodes.h"
22 #include <qtest_kde.h>
26 #include "views/dolphinview.h"
27 #include "views/dolphinmodel.h"
28 #include "views/dolphindirlister.h"
29 #include "views/dolphinsortfilterproxymodel.h"
31 #include <qtestmouse.h>
32 #include <qtestkeyboard.h>
34 DolphinViewTest_AllViewModes::DolphinViewTest_AllViewModes() {
35 // Need to register KFileItemList for use with QSignalSpy
36 qRegisterMetaType
<KFileItemList
>("KFileItemList");
39 void DolphinViewTest_AllViewModes::init() {
40 m_view
->setMode(mode());
41 QVERIFY(verifyCorrectViewMode());
42 m_view
->resize(200, 300);
44 QTest::qWaitForWindowShown(m_view
);
47 void DolphinViewTest_AllViewModes::cleanup() {
53 * testSelection() checks the basic selection funtionality of DolphinView, including:
56 * selectedItemsCount()
62 * and the signal selectionChanged(const KFileItemList& selection)
65 Q_DECLARE_METATYPE(KFileItemList
)
67 void DolphinViewTest_AllViewModes::testSelection() {
68 const int totalItems
= 50;
70 for (int i
= 0; i
< totalItems
; i
++) {
71 createFile(QString("%1").arg(i
));
75 // Start with an empty selection
76 m_view
->clearSelection();
78 QCOMPARE(m_view
->selectedItems().count(), 0);
79 QCOMPARE(m_view
->selectedItemsCount(), 0);
80 QVERIFY(!m_view
->hasSelection());
82 // First some simple tests where either all or no items are selected
84 verifySelectedItemsCount(totalItems
);
86 m_view
->invertSelection();
87 verifySelectedItemsCount(0);
89 m_view
->invertSelection();
90 verifySelectedItemsCount(totalItems
);
92 m_view
->clearSelection();
93 verifySelectedItemsCount(0);
95 // Now we select individual items using mouse clicks
96 QModelIndex index
= itemView()->model()->index(2, 0);
97 itemView()->scrollTo(index
);
98 QTest::mouseClick(itemView()->viewport(), Qt::LeftButton
, Qt::ControlModifier
, itemView()->visualRect(index
).center());
99 verifySelectedItemsCount(1);
101 index
= itemView()->model()->index(45, 0);
102 itemView()->scrollTo(index
);
103 QTest::mouseClick(itemView()->viewport(), Qt::LeftButton
, Qt::ControlModifier
, itemView()->visualRect(index
).center());
104 verifySelectedItemsCount(2);
106 index
= itemView()->model()->index(48, 0);
107 itemView()->scrollTo(index
);
108 QTest::mouseClick(itemView()->viewport(), Qt::LeftButton
, Qt::ShiftModifier
, itemView()->visualRect(index
).center());
109 verifySelectedItemsCount(5);
113 * testKeyboardFocus() checks whether a view grabs the keyboard focus.
115 * A view may never grab the keyboard focus itself and must respect the focus-state
116 * when switching the view mode.
119 void DolphinViewTest_AllViewModes::testKeyboardFocus()
121 const DolphinView::Mode mode
= m_view
->mode();
123 QVERIFY(!m_view
->hasFocus());
124 for (int i
= 0; i
<= DolphinView::MaxModeEnum
; ++i
) {
125 m_view
->setMode(static_cast<DolphinView::Mode
>(i
));
126 QVERIFY(!m_view
->hasFocus());
129 m_view
->setMode(mode
);
133 * verifySelectedItemsCount(int) waits until the DolphinView's selectionChanged(const KFileItemList&)
134 * signal is received and checks that the selection state of the view is as expected.
137 void DolphinViewTest_AllViewModes::verifySelectedItemsCount(int itemsCount
) const
139 QSignalSpy
spySelectionChanged(m_view
, SIGNAL(selectionChanged(const KFileItemList
&)));
140 QVERIFY(QTest::kWaitForSignal(m_view
, SIGNAL(selectionChanged(const KFileItemList
&)), 500));
142 QCOMPARE(m_view
->selectedItems().count(), itemsCount
);
143 QCOMPARE(m_view
->selectedItemsCount(), itemsCount
);
144 QCOMPARE(spySelectionChanged
.count(), 1);
145 QCOMPARE(qvariant_cast
<KFileItemList
>(spySelectionChanged
.at(0).at(0)).count(), itemsCount
);
146 if (itemsCount
!= 0) {
147 QVERIFY(m_view
->hasSelection());
150 QVERIFY(!m_view
->hasSelection());
154 #include "dolphinviewtest_allviewmodes.moc"