]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/kitemlistcontrollertest.cpp
KFileItemModel: interface cleanups
[dolphin.git] / src / tests / kitemlistcontrollertest.cpp
1 /***************************************************************************
2 * Copyright (C) 2012 by Frank Reininghaus <frank78ac@googlemail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include <qtest_kde.h>
21 #include <qtestmouse.h>
22 #include <qtestkeyboard.h>
23
24 #include "kitemviews/kitemlistcontainer.h"
25 #include "kitemviews/kfileitemlistview.h"
26 #include "kitemviews/kfileitemmodel.h"
27 #include "kitemviews/kitemlistcontroller.h"
28 #include "kitemviews/kitemlistselectionmanager.h"
29 #include "kitemviews/private/kitemlistviewlayouter.h"
30 #include "testdir.h"
31
32 namespace {
33 const int DefaultTimeout = 2000;
34 };
35
36 Q_DECLARE_METATYPE(KFileItemListView::Layout);
37 Q_DECLARE_METATYPE(Qt::Orientation);
38 Q_DECLARE_METATYPE(KItemListController::SelectionBehavior);
39 Q_DECLARE_METATYPE(QSet<int>);
40
41 class KItemListControllerTest : public QObject
42 {
43 Q_OBJECT
44
45 private slots:
46 void initTestCase();
47 void cleanupTestCase();
48
49 void init();
50 void cleanup();
51
52 void testKeyboardNavigation_data();
53 void testKeyboardNavigation();
54
55 private:
56 /**
57 * Make sure that the number of columns in the view is equal to \a count
58 * by changing the geometry of the container.
59 */
60 void adjustGeometryForColumnCount(int count);
61
62 private:
63 KFileItemListView* m_view;
64 KItemListController* m_controller;
65 KItemListSelectionManager* m_selectionManager;
66 KFileItemModel* m_model;
67 TestDir* m_testDir;
68 KItemListContainer* m_container;
69 };
70
71 /**
72 * This function initializes the member objects, creates the temporary files, and
73 * shows the view on the screen on startup. This could also be done before every
74 * single test, but this would make the time needed to run the test much larger.
75 */
76 void KItemListControllerTest::initTestCase()
77 {
78 qRegisterMetaType<QSet<int> >("QSet<int>");
79
80 m_testDir = new TestDir();
81 m_model = new KFileItemModel();
82 m_container = new KItemListContainer();
83 m_controller = m_container->controller();
84 m_controller->setSelectionBehavior(KItemListController::MultiSelection);
85 m_selectionManager = m_controller->selectionManager();
86
87 m_view = new KFileItemListView();
88 m_controller->setView(m_view);
89 m_controller->setModel(m_model);
90
91 QStringList files;
92 files
93 << "a1" << "a2" << "a3"
94 << "b1"
95 << "c1" << "c2" << "c3" << "c4" << "c5"
96 << "d1" << "d2" << "d3" << "d4"
97 << "e1" << "e2" << "e3" << "e4" << "e5" << "e6" << "e7";
98
99 m_testDir->createFiles(files);
100 m_model->loadDirectory(m_testDir->url());
101 QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(directoryLoadingCompleted()), DefaultTimeout));
102
103 m_container->show();
104 QTest::qWaitForWindowShown(m_container);
105 }
106
107 void KItemListControllerTest::cleanupTestCase()
108 {
109 delete m_view;
110 m_view = 0;
111
112 delete m_container;
113 m_container = 0;
114 m_controller = 0;
115
116 delete m_model;
117 m_model = 0;
118
119 delete m_testDir;
120 m_testDir = 0;
121 }
122
123 /** Before each test, the current item, selection, and item size are reset to the defaults. */
124 void KItemListControllerTest::init()
125 {
126 m_selectionManager->setCurrentItem(0);
127 QCOMPARE(m_selectionManager->currentItem(), 0);
128
129 m_selectionManager->clearSelection();
130 QVERIFY(!m_selectionManager->hasSelection());
131
132 const QSizeF itemSize(50, 50);
133 m_view->setItemSize(itemSize);
134 QCOMPARE(m_view->itemSize(), itemSize);
135 }
136
137 void KItemListControllerTest::cleanup()
138 {
139 }
140
141 /**
142 * \class KeyPress is a small helper struct that represents a key press event,
143 * including the key and the keyboard modifiers.
144 */
145 struct KeyPress {
146
147 KeyPress(Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier) :
148 m_key(key),
149 m_modifier(modifier)
150 {}
151
152 Qt::Key m_key;
153 Qt::KeyboardModifiers m_modifier;
154 };
155
156 /**
157 * \class ViewState is a small helper struct that represents a certain state
158 * of the view, including the current item, the selected items in MultiSelection
159 * mode (in the other modes, the selection is either empty or equal to the
160 * current item), and the information whether items were activated by the last
161 * key press.
162 */
163 struct ViewState {
164
165 ViewState(int current, const QSet<int> selection, bool activated = false) :
166 m_current(current),
167 m_selection(selection),
168 m_activated(activated)
169 {}
170
171 int m_current;
172 QSet<int> m_selection;
173 bool m_activated;
174 };
175
176 // We have to define a typedef for the pair in order to make the test compile.
177 typedef QPair<KeyPress, ViewState> keyPressViewStatePair;
178 Q_DECLARE_METATYPE(QList<keyPressViewStatePair>);
179
180 /**
181 * This function provides the data for the actual test function
182 * KItemListControllerTest::testKeyboardNavigation().
183 * It tests all possible combinations of view layouts, selection behaviors,
184 * and enabled/disabled groupings for different column counts, and
185 * provides a list of key presses and the states that the view should be in
186 * after the key press event.
187 */
188 void KItemListControllerTest::testKeyboardNavigation_data()
189 {
190 QTest::addColumn<KFileItemListView::Layout>("layout");
191 QTest::addColumn<Qt::Orientation>("scrollOrientation");
192 QTest::addColumn<int>("columnCount");
193 QTest::addColumn<KItemListController::SelectionBehavior>("selectionBehavior");
194 QTest::addColumn<bool>("groupingEnabled");
195 QTest::addColumn<QList<QPair<KeyPress, ViewState> > >("testList");
196
197 QList<KFileItemListView::Layout> layoutList;
198 QHash<KFileItemListView::Layout, QString> layoutNames;
199 layoutList.append(KFileItemListView::IconsLayout);
200 layoutNames[KFileItemListView::IconsLayout] = "Icons";
201 layoutList.append(KFileItemListView::CompactLayout);
202 layoutNames[KFileItemListView::CompactLayout] = "Compact";
203 layoutList.append(KFileItemListView::DetailsLayout);
204 layoutNames[KFileItemListView::DetailsLayout] = "Details";
205
206 QList<KItemListController::SelectionBehavior> selectionBehaviorList;
207 QHash<KItemListController::SelectionBehavior, QString> selectionBehaviorNames;
208 selectionBehaviorList.append(KItemListController::NoSelection);
209 selectionBehaviorNames[KItemListController::NoSelection] = "NoSelection";
210 selectionBehaviorList.append(KItemListController::SingleSelection);
211 selectionBehaviorNames[KItemListController::SingleSelection] = "SingleSelection";
212 selectionBehaviorList.append(KItemListController::MultiSelection);
213 selectionBehaviorNames[KItemListController::MultiSelection] = "MultiSelection";
214
215 QList<bool> groupingEnabledList;
216 QHash<bool, QString> groupingEnabledNames;
217 groupingEnabledList.append(false);
218 groupingEnabledNames[false] = "ungrouped";
219 groupingEnabledList.append(true);
220 groupingEnabledNames[true] = "grouping enabled";
221
222 foreach (KFileItemListView::Layout layout, layoutList) {
223 // The following settings depend on the layout.
224 // Note that 'columns' are actually 'rows' in
225 // Compact layout.
226 Qt::Orientation scrollOrientation;
227 QList<int> columnCountList;
228 Qt::Key nextItemKey;
229 Qt::Key previousItemKey;
230 Qt::Key nextRowKey;
231 Qt::Key previousRowKey;
232
233 switch (layout) {
234 case KFileItemListView::IconsLayout:
235 scrollOrientation = Qt::Vertical;
236 columnCountList << 1 << 3 << 5;
237 nextItemKey = Qt::Key_Right;
238 previousItemKey = Qt::Key_Left;
239 nextRowKey = Qt::Key_Down;
240 previousRowKey = Qt::Key_Up;
241 break;
242 case KFileItemListView::CompactLayout:
243 scrollOrientation = Qt::Horizontal;
244 columnCountList << 1 << 3 << 5;
245 nextItemKey = Qt::Key_Down;
246 previousItemKey = Qt::Key_Up;
247 nextRowKey = Qt::Key_Right;
248 previousRowKey = Qt::Key_Left;
249 break;
250 case KFileItemListView::DetailsLayout:
251 scrollOrientation = Qt::Vertical;
252 columnCountList << 1;
253 nextItemKey = Qt::Key_Down;
254 previousItemKey = Qt::Key_Up;
255 nextRowKey = Qt::Key_Down;
256 previousRowKey = Qt::Key_Up;
257 break;
258 }
259
260 foreach (int columnCount, columnCountList) {
261 foreach (KItemListController::SelectionBehavior selectionBehavior, selectionBehaviorList) {
262 foreach (bool groupingEnabled, groupingEnabledList) {
263 QList<QPair<KeyPress, ViewState> > testList;
264
265 // First, key presses which should have the same effect
266 // for any layout and any number of columns.
267 testList
268 << qMakePair(KeyPress(nextItemKey), ViewState(1, QSet<int>() << 1))
269 << qMakePair(KeyPress(Qt::Key_Return), ViewState(1, QSet<int>() << 1, true))
270 << qMakePair(KeyPress(Qt::Key_Enter), ViewState(1, QSet<int>() << 1, true))
271 << qMakePair(KeyPress(nextItemKey), ViewState(2, QSet<int>() << 2))
272 << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, QSet<int>() << 2 << 3))
273 << qMakePair(KeyPress(Qt::Key_Return), ViewState(3, QSet<int>() << 2 << 3, true))
274 << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(2, QSet<int>() << 2))
275 << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(3, QSet<int>() << 2 << 3))
276 << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, QSet<int>() << 2 << 3))
277 << qMakePair(KeyPress(Qt::Key_Return), ViewState(4, QSet<int>() << 2 << 3, true))
278 << qMakePair(KeyPress(previousItemKey), ViewState(3, QSet<int>() << 3))
279 << qMakePair(KeyPress(Qt::Key_Home, Qt::ShiftModifier), ViewState(0, QSet<int>() << 0 << 1 << 2 << 3))
280 << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(1, QSet<int>() << 0 << 1 << 2 << 3))
281 << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, QSet<int>() << 0 << 2 << 3))
282 << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(1, QSet<int>() << 0 << 1 << 2 << 3))
283 << qMakePair(KeyPress(Qt::Key_End), ViewState(19, QSet<int>() << 19))
284 << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(18, QSet<int>() << 18 << 19))
285 << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, QSet<int>() << 0))
286 << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, QSet<int>()))
287 << qMakePair(KeyPress(Qt::Key_Enter), ViewState(0, QSet<int>(), true))
288 << qMakePair(KeyPress(Qt::Key_Space, Qt::ControlModifier), ViewState(0, QSet<int>() << 0));
289
290 // Next, we test combinations of key presses which only work for a
291 // particular number of columns and either enabled or disabled grouping.
292
293 // One column.
294 if (columnCount == 1) {
295 testList
296 << qMakePair(KeyPress(nextRowKey), ViewState(1, QSet<int>() << 1))
297 << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(2, QSet<int>() << 1 << 2))
298 << qMakePair(KeyPress(nextRowKey, Qt::ControlModifier), ViewState(3, QSet<int>() << 1 << 2))
299 << qMakePair(KeyPress(previousRowKey), ViewState(2, QSet<int>() << 2))
300 << qMakePair(KeyPress(previousItemKey), ViewState(1, QSet<int>() << 1))
301 << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, QSet<int>() << 0));
302 }
303
304 // Multiple columns: we test both 3 and 5 columns with grouping
305 // enabled or disabled. For each case, the layout of the items
306 // in the view is shown (both using file names and indices) to
307 // make it easier to understand what the tests do.
308
309 if (columnCount == 3 && !groupingEnabled) {
310 // 3 columns, no grouping:
311 //
312 // a1 a2 a3 | 0 1 2
313 // b1 c1 c2 | 3 4 5
314 // c3 c4 c5 | 6 7 8
315 // d1 d2 d3 | 9 10 11
316 // d4 e1 e2 | 12 13 14
317 // e3 e4 e5 | 15 16 17
318 // e6 e7 | 18 19
319 testList
320 << qMakePair(KeyPress(nextRowKey), ViewState(3, QSet<int>() << 3))
321 << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(4, QSet<int>() << 3))
322 << qMakePair(KeyPress(nextRowKey), ViewState(7, QSet<int>() << 7))
323 << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(8, QSet<int>() << 7 << 8))
324 << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(9, QSet<int>() << 7 << 8 << 9))
325 << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(8, QSet<int>() << 7 << 8))
326 << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(7, QSet<int>() << 7))
327 << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(6, QSet<int>() << 6 << 7))
328 << qMakePair(KeyPress(previousItemKey, Qt::ShiftModifier), ViewState(5, QSet<int>() << 5 << 6 << 7))
329 << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(6, QSet<int>() << 6 << 7))
330 << qMakePair(KeyPress(nextItemKey, Qt::ShiftModifier), ViewState(7, QSet<int>() << 7))
331 << qMakePair(KeyPress(nextRowKey), ViewState(10, QSet<int>() << 10))
332 << qMakePair(KeyPress(nextItemKey), ViewState(11, QSet<int>() << 11))
333 << qMakePair(KeyPress(nextRowKey), ViewState(14, QSet<int>() << 14))
334 << qMakePair(KeyPress(nextRowKey), ViewState(17, QSet<int>() << 17))
335 << qMakePair(KeyPress(nextRowKey), ViewState(19, QSet<int>() << 19))
336 << qMakePair(KeyPress(previousRowKey), ViewState(17, QSet<int>() << 17))
337 << qMakePair(KeyPress(Qt::Key_End), ViewState(19, QSet<int>() << 19))
338 << qMakePair(KeyPress(previousRowKey), ViewState(16, QSet<int>() << 16))
339 << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, QSet<int>() << 0));
340 }
341
342 if (columnCount == 5 && !groupingEnabled) {
343 // 5 columns, no grouping:
344 //
345 // a1 a2 a3 b1 c1 | 0 1 2 3 4
346 // c2 c3 c4 c5 d1 | 5 6 7 8 9
347 // d2 d3 d4 e1 e2 | 10 11 12 13 14
348 // e3 e4 e5 e6 e7 | 15 16 17 18 19
349 testList
350 << qMakePair(KeyPress(nextRowKey), ViewState(5, QSet<int>() << 5))
351 << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(6, QSet<int>() << 5))
352 << qMakePair(KeyPress(nextRowKey), ViewState(11, QSet<int>() << 11))
353 << qMakePair(KeyPress(nextItemKey), ViewState(12, QSet<int>() << 12))
354 << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(17, QSet<int>() << 12 << 13 << 14 << 15 << 16 << 17))
355 << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(12, QSet<int>() << 12))
356 << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(7, QSet<int>() << 7 << 8 << 9 << 10 << 11 << 12))
357 << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(12, QSet<int>() << 12))
358 << qMakePair(KeyPress(Qt::Key_End, Qt::ControlModifier), ViewState(19, QSet<int>() << 12))
359 << qMakePair(KeyPress(previousRowKey), ViewState(14, QSet<int>() << 14))
360 << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, QSet<int>() << 0));
361 }
362
363 if (columnCount == 3 && groupingEnabled) {
364 // 3 columns, with grouping:
365 //
366 // a1 a2 a3 | 0 1 2
367 // b1 | 3
368 // c1 c2 c3 | 4 5 6
369 // c4 c5 | 7 8
370 // d1 d2 d3 | 9 10 11
371 // d4 | 12
372 // e1 e2 e3 | 13 14 15
373 // e4 e5 e6 | 16 17 18
374 // e7 | 19
375 testList
376 << qMakePair(KeyPress(nextItemKey), ViewState(1, QSet<int>() << 1))
377 << qMakePair(KeyPress(nextItemKey), ViewState(2, QSet<int>() << 2))
378 << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(3, QSet<int>() << 2 << 3))
379 << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(6, QSet<int>() << 2 << 3 << 4 << 5 << 6))
380 << qMakePair(KeyPress(nextRowKey), ViewState(8, QSet<int>() << 8))
381 << qMakePair(KeyPress(nextRowKey), ViewState(11, QSet<int>() << 11))
382 << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(12, QSet<int>() << 11))
383 << qMakePair(KeyPress(nextRowKey), ViewState(13, QSet<int>() << 13))
384 << qMakePair(KeyPress(nextRowKey), ViewState(16, QSet<int>() << 16))
385 << qMakePair(KeyPress(nextItemKey), ViewState(17, QSet<int>() << 17))
386 << qMakePair(KeyPress(nextRowKey), ViewState(19, QSet<int>() << 19))
387 << qMakePair(KeyPress(previousRowKey), ViewState(17, QSet<int>() << 17))
388 << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, QSet<int>() << 0));
389 }
390
391 if (columnCount == 5 && groupingEnabled) {
392 // 5 columns, with grouping:
393 //
394 // a1 a2 a3 | 0 1 2
395 // b1 | 3
396 // c1 c2 c3 c4 c5 | 4 5 6 7 8
397 // d1 d2 d3 d4 | 9 10 11 12
398 // e1 e2 e3 e4 e5 | 13 14 15 16 17
399 // e6 e7 | 18 19
400 testList
401 << qMakePair(KeyPress(nextItemKey), ViewState(1, QSet<int>() << 1))
402 << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(3, QSet<int>() << 1 << 2 << 3))
403 << qMakePair(KeyPress(nextRowKey, Qt::ShiftModifier), ViewState(5, QSet<int>() << 1 << 2 << 3 << 4 << 5))
404 << qMakePair(KeyPress(nextItemKey), ViewState(6, QSet<int>() << 6))
405 << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(7, QSet<int>() << 6))
406 << qMakePair(KeyPress(nextItemKey, Qt::ControlModifier), ViewState(8, QSet<int>() << 6))
407 << qMakePair(KeyPress(nextRowKey), ViewState(12, QSet<int>() << 12))
408 << qMakePair(KeyPress(nextRowKey), ViewState(17, QSet<int>() << 17))
409 << qMakePair(KeyPress(nextRowKey), ViewState(19, QSet<int>() << 19))
410 << qMakePair(KeyPress(previousRowKey), ViewState(17, QSet<int>() << 17))
411 << qMakePair(KeyPress(Qt::Key_End, Qt::ShiftModifier), ViewState(19, QSet<int>() << 17 << 18 << 19))
412 << qMakePair(KeyPress(previousRowKey, Qt::ShiftModifier), ViewState(14, QSet<int>() << 14 << 15 << 16 << 17))
413 << qMakePair(KeyPress(Qt::Key_Home), ViewState(0, QSet<int>() << 0));
414 }
415
416 const QString testName =
417 layoutNames[layout] + ", " +
418 QString("%1 columns, ").arg(columnCount) +
419 selectionBehaviorNames[selectionBehavior] + ", " +
420 groupingEnabledNames[groupingEnabled];
421
422 const QByteArray testNameAscii = testName.toAscii();
423
424 QTest::newRow(testNameAscii.data())
425 << layout
426 << scrollOrientation
427 << columnCount
428 << selectionBehavior
429 << groupingEnabled
430 << testList;
431 }
432 }
433 }
434 }
435 }
436
437 /**
438 * This function sets the view's properties according to the data provided by
439 * KItemListControllerTest::testKeyboardNavigation_data().
440 *
441 * The list \a testList contains pairs of key presses, which are sent to the
442 * container, and expected view states, which are verified then.
443 */
444 void KItemListControllerTest::testKeyboardNavigation()
445 {
446 QFETCH(KFileItemListView::Layout, layout);
447 QFETCH(Qt::Orientation, scrollOrientation);
448 QFETCH(int, columnCount);
449 QFETCH(KItemListController::SelectionBehavior, selectionBehavior);
450 QFETCH(bool, groupingEnabled);
451 QFETCH(QList<keyPressViewStatePair>, testList);
452
453 m_view->setItemLayout(layout);
454 QCOMPARE(m_view->itemLayout(), layout);
455
456 m_view->setScrollOrientation(scrollOrientation);
457 QCOMPARE(m_view->scrollOrientation(), scrollOrientation);
458
459 m_controller->setSelectionBehavior(selectionBehavior);
460 QCOMPARE(m_controller->selectionBehavior(), selectionBehavior);
461
462 m_model->setGroupedSorting(groupingEnabled);
463 QCOMPARE(m_model->groupedSorting(), groupingEnabled);
464
465 adjustGeometryForColumnCount(columnCount);
466 QCOMPARE(m_view->m_layouter->m_columnCount, columnCount);
467
468 QSignalSpy spySingleItemActivated(m_controller, SIGNAL(itemActivated(int)));
469 QSignalSpy spyMultipleItemsActivated(m_controller, SIGNAL(itemsActivated(QSet<int>)));
470
471 while (!testList.isEmpty()) {
472 const QPair<KeyPress, ViewState> test = testList.takeFirst();
473 const Qt::Key key = test.first.m_key;
474 const Qt::KeyboardModifiers modifier = test.first.m_modifier;
475 const int current = test.second.m_current;
476 const QSet<int> selection = test.second.m_selection;
477 const bool activated = test.second.m_activated;
478
479 QTest::keyClick(m_container, key, modifier);
480
481 QCOMPARE(m_selectionManager->currentItem(), current);
482 switch (selectionBehavior) {
483 case KItemListController::NoSelection: QVERIFY(m_selectionManager->selectedItems().isEmpty()); break;
484 case KItemListController::SingleSelection: QCOMPARE(m_selectionManager->selectedItems(), QSet<int>() << current); break;
485 case KItemListController::MultiSelection: QCOMPARE(m_selectionManager->selectedItems(), selection); break;
486 }
487
488 if (activated) {
489 switch (selectionBehavior) {
490 case KItemListController::MultiSelection:
491 if (!selection.isEmpty()) {
492 // The selected items should be activated.
493 if (selection.count() == 1) {
494 QVERIFY(!spySingleItemActivated.isEmpty());
495 QCOMPARE(qvariant_cast<int>(spySingleItemActivated.takeFirst().at(0)), selection.toList().at(0));
496 QVERIFY(spyMultipleItemsActivated.isEmpty());
497 } else {
498 QVERIFY(spySingleItemActivated.isEmpty());
499 QVERIFY(!spyMultipleItemsActivated.isEmpty());
500 QCOMPARE(qvariant_cast<QSet<int> >(spyMultipleItemsActivated.takeFirst().at(0)), selection);
501 }
502 break;
503 }
504 // No items are selected. Therefore, the current item should be activated.
505 // This is handled by falling through to the NoSelection/SingleSelection case.
506 case KItemListController::NoSelection:
507 case KItemListController::SingleSelection:
508 // In NoSelection and SingleSelection mode, the current item should be activated.
509 QVERIFY(!spySingleItemActivated.isEmpty());
510 QCOMPARE(qvariant_cast<int>(spySingleItemActivated.takeFirst().at(0)), current);
511 QVERIFY(spyMultipleItemsActivated.isEmpty());
512 break;
513 }
514 }
515 }
516 }
517
518 void KItemListControllerTest::adjustGeometryForColumnCount(int count)
519 {
520 const QSize size = m_view->itemSize().toSize();
521
522 QRect rect = m_container->geometry();
523 rect.setSize(size * count);
524 m_container->setGeometry(rect);
525
526 // Increase the size of the container until the correct column count is reached.
527 while (m_view->m_layouter->m_columnCount < count) {
528 rect = m_container->geometry();
529 rect.setSize(rect.size() + size);
530 m_container->setGeometry(rect);
531 }
532 }
533
534 QTEST_KDEMAIN(KItemListControllerTest, GUI)
535
536 #include "kitemlistcontrollertest.moc"