Warning, file /plasma/kwin/autotests/test_virtual_desktops.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2012 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 #include "input.h" 0010 #include "virtualdesktops.h" 0011 // KDE 0012 #include <KConfigGroup> 0013 0014 #include <QAction> 0015 #include <QtTest> 0016 0017 namespace KWin 0018 { 0019 0020 InputRedirection *InputRedirection::s_self = nullptr; 0021 0022 void InputRedirection::registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action) 0023 { 0024 } 0025 0026 void InputRedirection::registerTouchpadSwipeShortcut(SwipeDirection, uint fingerCount, QAction *) 0027 { 0028 } 0029 0030 void InputRedirection::registerRealtimeTouchpadSwipeShortcut(SwipeDirection, uint fingerCount, QAction *, std::function<void(qreal)> progressCallback) 0031 { 0032 } 0033 0034 void InputRedirection::registerTouchscreenSwipeShortcut(SwipeDirection, uint, QAction *, std::function<void(qreal)>) 0035 { 0036 } 0037 0038 } 0039 0040 Q_DECLARE_METATYPE(Qt::Orientation) 0041 0042 using namespace KWin; 0043 0044 class TestVirtualDesktops : public QObject 0045 { 0046 Q_OBJECT 0047 private Q_SLOTS: 0048 void init(); 0049 void cleanup(); 0050 void count_data(); 0051 void count(); 0052 void navigationWrapsAround_data(); 0053 void navigationWrapsAround(); 0054 void current_data(); 0055 void current(); 0056 void currentChangeOnCountChange_data(); 0057 void currentChangeOnCountChange(); 0058 void next_data(); 0059 void next(); 0060 void previous_data(); 0061 void previous(); 0062 void left_data(); 0063 void left(); 0064 void right_data(); 0065 void right(); 0066 void above_data(); 0067 void above(); 0068 void below_data(); 0069 void below(); 0070 void updateGrid_data(); 0071 void updateGrid(); 0072 void updateLayout_data(); 0073 void updateLayout(); 0074 void name_data(); 0075 void name(); 0076 void switchToShortcuts(); 0077 void changeRows(); 0078 void load(); 0079 void save(); 0080 0081 private: 0082 void addDirectionColumns(); 0083 void testDirection(const QString &actionName, VirtualDesktopManager::Direction direction); 0084 }; 0085 0086 void TestVirtualDesktops::init() 0087 { 0088 VirtualDesktopManager::create(); 0089 } 0090 0091 void TestVirtualDesktops::cleanup() 0092 { 0093 delete VirtualDesktopManager::self(); 0094 } 0095 0096 static const uint s_countInitValue = 2; 0097 0098 void TestVirtualDesktops::count_data() 0099 { 0100 QTest::addColumn<uint>("request"); 0101 QTest::addColumn<uint>("result"); 0102 QTest::addColumn<bool>("signal"); 0103 QTest::addColumn<bool>("removedSignal"); 0104 0105 QTest::newRow("Minimum") << (uint)1 << (uint)1 << true << true; 0106 QTest::newRow("Below Minimum") << (uint)0 << (uint)1 << true << true; 0107 QTest::newRow("Normal Value") << (uint)10 << (uint)10 << true << false; 0108 QTest::newRow("Maximum") << VirtualDesktopManager::maximum() << VirtualDesktopManager::maximum() << true << false; 0109 QTest::newRow("Above Maximum") << VirtualDesktopManager::maximum() + 1 << VirtualDesktopManager::maximum() << true << false; 0110 QTest::newRow("Unchanged") << s_countInitValue << s_countInitValue << false << false; 0111 } 0112 0113 void TestVirtualDesktops::count() 0114 { 0115 VirtualDesktopManager *vds = VirtualDesktopManager::self(); 0116 QCOMPARE(vds->count(), (uint)0); 0117 // start with a useful desktop count 0118 vds->setCount(s_countInitValue); 0119 0120 QSignalSpy spy(vds, &VirtualDesktopManager::countChanged); 0121 QSignalSpy desktopsRemoved(vds, &VirtualDesktopManager::desktopRemoved); 0122 0123 auto vdToRemove = vds->desktops().last(); 0124 0125 QFETCH(uint, request); 0126 QFETCH(uint, result); 0127 QFETCH(bool, signal); 0128 QFETCH(bool, removedSignal); 0129 vds->setCount(request); 0130 QCOMPARE(vds->count(), result); 0131 QCOMPARE(spy.isEmpty(), !signal); 0132 if (!spy.isEmpty()) { 0133 QList<QVariant> arguments = spy.takeFirst(); 0134 QCOMPARE(arguments.count(), 2); 0135 QCOMPARE(arguments.at(0).type(), QVariant::UInt); 0136 QCOMPARE(arguments.at(1).type(), QVariant::UInt); 0137 QCOMPARE(arguments.at(0).toUInt(), s_countInitValue); 0138 QCOMPARE(arguments.at(1).toUInt(), result); 0139 } 0140 QCOMPARE(desktopsRemoved.isEmpty(), !removedSignal); 0141 if (!desktopsRemoved.isEmpty()) { 0142 QList<QVariant> arguments = desktopsRemoved.takeFirst(); 0143 QCOMPARE(arguments.count(), 1); 0144 QCOMPARE(arguments.at(0).value<KWin::VirtualDesktop *>(), vdToRemove); 0145 } 0146 } 0147 0148 void TestVirtualDesktops::navigationWrapsAround_data() 0149 { 0150 QTest::addColumn<bool>("init"); 0151 QTest::addColumn<bool>("request"); 0152 QTest::addColumn<bool>("result"); 0153 QTest::addColumn<bool>("signal"); 0154 0155 QTest::newRow("enable") << false << true << true << true; 0156 QTest::newRow("disable") << true << false << false << true; 0157 QTest::newRow("keep enabled") << true << true << true << false; 0158 QTest::newRow("keep disabled") << false << false << false << false; 0159 } 0160 0161 void TestVirtualDesktops::navigationWrapsAround() 0162 { 0163 VirtualDesktopManager *vds = VirtualDesktopManager::self(); 0164 QCOMPARE(vds->isNavigationWrappingAround(), false); 0165 QFETCH(bool, init); 0166 QFETCH(bool, request); 0167 QFETCH(bool, result); 0168 QFETCH(bool, signal); 0169 0170 // set to init value 0171 vds->setNavigationWrappingAround(init); 0172 QCOMPARE(vds->isNavigationWrappingAround(), init); 0173 0174 QSignalSpy spy(vds, &VirtualDesktopManager::navigationWrappingAroundChanged); 0175 vds->setNavigationWrappingAround(request); 0176 QCOMPARE(vds->isNavigationWrappingAround(), result); 0177 QCOMPARE(spy.isEmpty(), !signal); 0178 } 0179 0180 void TestVirtualDesktops::current_data() 0181 { 0182 QTest::addColumn<uint>("count"); 0183 QTest::addColumn<uint>("init"); 0184 QTest::addColumn<uint>("request"); 0185 QTest::addColumn<uint>("result"); 0186 QTest::addColumn<bool>("signal"); 0187 0188 QTest::newRow("lower") << (uint)4 << (uint)3 << (uint)2 << (uint)2 << true; 0189 QTest::newRow("higher") << (uint)4 << (uint)1 << (uint)2 << (uint)2 << true; 0190 QTest::newRow("maximum") << (uint)4 << (uint)1 << (uint)4 << (uint)4 << true; 0191 QTest::newRow("above maximum") << (uint)4 << (uint)1 << (uint)5 << (uint)1 << false; 0192 QTest::newRow("minimum") << (uint)4 << (uint)2 << (uint)1 << (uint)1 << true; 0193 QTest::newRow("below minimum") << (uint)4 << (uint)2 << (uint)0 << (uint)2 << false; 0194 QTest::newRow("unchanged") << (uint)4 << (uint)2 << (uint)2 << (uint)2 << false; 0195 } 0196 0197 void TestVirtualDesktops::current() 0198 { 0199 VirtualDesktopManager *vds = VirtualDesktopManager::self(); 0200 QCOMPARE(vds->current(), (uint)0); 0201 QFETCH(uint, count); 0202 vds->setCount(count); 0203 QFETCH(uint, init); 0204 QVERIFY(vds->setCurrent(init)); 0205 QCOMPARE(vds->current(), init); 0206 0207 QSignalSpy spy(vds, &VirtualDesktopManager::currentChanged); 0208 0209 QFETCH(uint, request); 0210 QFETCH(uint, result); 0211 QFETCH(bool, signal); 0212 QCOMPARE(vds->setCurrent(request), signal); 0213 QCOMPARE(vds->current(), result); 0214 QCOMPARE(spy.isEmpty(), !signal); 0215 if (!spy.isEmpty()) { 0216 QList<QVariant> arguments = spy.takeFirst(); 0217 QCOMPARE(arguments.count(), 2); 0218 QCOMPARE(arguments.at(0).type(), QVariant::UInt); 0219 QCOMPARE(arguments.at(1).type(), QVariant::UInt); 0220 QCOMPARE(arguments.at(0).toUInt(), init); 0221 QCOMPARE(arguments.at(1).toUInt(), result); 0222 } 0223 } 0224 0225 void TestVirtualDesktops::currentChangeOnCountChange_data() 0226 { 0227 QTest::addColumn<uint>("initCount"); 0228 QTest::addColumn<uint>("initCurrent"); 0229 QTest::addColumn<uint>("request"); 0230 QTest::addColumn<uint>("current"); 0231 QTest::addColumn<bool>("signal"); 0232 0233 QTest::newRow("increment") << (uint)4 << (uint)2 << (uint)5 << (uint)2 << false; 0234 QTest::newRow("increment on last") << (uint)4 << (uint)4 << (uint)5 << (uint)4 << false; 0235 QTest::newRow("decrement") << (uint)4 << (uint)2 << (uint)3 << (uint)2 << false; 0236 QTest::newRow("decrement on second last") << (uint)4 << (uint)3 << (uint)3 << (uint)3 << false; 0237 QTest::newRow("decrement on last") << (uint)4 << (uint)4 << (uint)3 << (uint)3 << true; 0238 QTest::newRow("multiple decrement") << (uint)4 << (uint)2 << (uint)1 << (uint)1 << true; 0239 } 0240 0241 void TestVirtualDesktops::currentChangeOnCountChange() 0242 { 0243 VirtualDesktopManager *vds = VirtualDesktopManager::self(); 0244 QFETCH(uint, initCount); 0245 QFETCH(uint, initCurrent); 0246 vds->setCount(initCount); 0247 vds->setCurrent(initCurrent); 0248 0249 QSignalSpy spy(vds, &VirtualDesktopManager::currentChanged); 0250 0251 QFETCH(uint, request); 0252 QFETCH(uint, current); 0253 QFETCH(bool, signal); 0254 0255 vds->setCount(request); 0256 QCOMPARE(vds->current(), current); 0257 QCOMPARE(spy.isEmpty(), !signal); 0258 } 0259 0260 void TestVirtualDesktops::addDirectionColumns() 0261 { 0262 QTest::addColumn<uint>("initCount"); 0263 QTest::addColumn<uint>("initCurrent"); 0264 QTest::addColumn<bool>("wrap"); 0265 QTest::addColumn<uint>("result"); 0266 } 0267 0268 void TestVirtualDesktops::testDirection(const QString &actionName, VirtualDesktopManager::Direction direction) 0269 { 0270 VirtualDesktopManager *vds = VirtualDesktopManager::self(); 0271 QFETCH(uint, initCount); 0272 QFETCH(uint, initCurrent); 0273 vds->setCount(initCount); 0274 vds->setCurrent(initCurrent); 0275 0276 QFETCH(bool, wrap); 0277 QFETCH(uint, result); 0278 QCOMPARE(vds->inDirection(nullptr, direction, wrap)->x11DesktopNumber(), result); 0279 0280 vds->setNavigationWrappingAround(wrap); 0281 vds->initShortcuts(); 0282 QAction *action = vds->findChild<QAction *>(actionName); 0283 QVERIFY(action); 0284 action->trigger(); 0285 QCOMPARE(vds->current(), result); 0286 QCOMPARE(vds->inDirection(initCurrent, direction, wrap), result); 0287 } 0288 0289 void TestVirtualDesktops::next_data() 0290 { 0291 addDirectionColumns(); 0292 0293 QTest::newRow("one desktop, wrap") << (uint)1 << (uint)1 << true << (uint)1; 0294 QTest::newRow("one desktop, no wrap") << (uint)1 << (uint)1 << false << (uint)1; 0295 QTest::newRow("desktops, wrap") << (uint)4 << (uint)1 << true << (uint)2; 0296 QTest::newRow("desktops, no wrap") << (uint)4 << (uint)1 << false << (uint)2; 0297 QTest::newRow("desktops at end, wrap") << (uint)4 << (uint)4 << true << (uint)1; 0298 QTest::newRow("desktops at end, no wrap") << (uint)4 << (uint)4 << false << (uint)4; 0299 } 0300 0301 void TestVirtualDesktops::next() 0302 { 0303 testDirection(QStringLiteral("Switch to Next Desktop"), VirtualDesktopManager::Direction::Next); 0304 } 0305 0306 void TestVirtualDesktops::previous_data() 0307 { 0308 addDirectionColumns(); 0309 0310 QTest::newRow("one desktop, wrap") << (uint)1 << (uint)1 << true << (uint)1; 0311 QTest::newRow("one desktop, no wrap") << (uint)1 << (uint)1 << false << (uint)1; 0312 QTest::newRow("desktops, wrap") << (uint)4 << (uint)3 << true << (uint)2; 0313 QTest::newRow("desktops, no wrap") << (uint)4 << (uint)3 << false << (uint)2; 0314 QTest::newRow("desktops at start, wrap") << (uint)4 << (uint)1 << true << (uint)4; 0315 QTest::newRow("desktops at start, no wrap") << (uint)4 << (uint)1 << false << (uint)1; 0316 } 0317 0318 void TestVirtualDesktops::previous() 0319 { 0320 testDirection(QStringLiteral("Switch to Previous Desktop"), VirtualDesktopManager::Direction::Previous); 0321 } 0322 0323 void TestVirtualDesktops::left_data() 0324 { 0325 addDirectionColumns(); 0326 QTest::newRow("one desktop, wrap") << (uint)1 << (uint)1 << true << (uint)1; 0327 QTest::newRow("one desktop, no wrap") << (uint)1 << (uint)1 << false << (uint)1; 0328 QTest::newRow("desktops, wrap, 1st row") << (uint)4 << (uint)2 << true << (uint)1; 0329 QTest::newRow("desktops, no wrap, 1st row") << (uint)4 << (uint)2 << false << (uint)1; 0330 QTest::newRow("desktops, wrap, 2nd row") << (uint)4 << (uint)4 << true << (uint)3; 0331 QTest::newRow("desktops, no wrap, 2nd row") << (uint)4 << (uint)4 << false << (uint)3; 0332 0333 QTest::newRow("desktops at start, wrap, 1st row") << (uint)4 << (uint)1 << true << (uint)2; 0334 QTest::newRow("desktops at start, no wrap, 1st row") << (uint)4 << (uint)1 << false << (uint)1; 0335 QTest::newRow("desktops at start, wrap, 2nd row") << (uint)4 << (uint)3 << true << (uint)4; 0336 QTest::newRow("desktops at start, no wrap, 2nd row") << (uint)4 << (uint)3 << false << (uint)3; 0337 0338 QTest::newRow("non symmetric, start") << (uint)5 << (uint)5 << false << (uint)4; 0339 QTest::newRow("non symmetric, end, no wrap") << (uint)5 << (uint)4 << false << (uint)4; 0340 QTest::newRow("non symmetric, end, wrap") << (uint)5 << (uint)4 << true << (uint)5; 0341 } 0342 0343 void TestVirtualDesktops::left() 0344 { 0345 testDirection(QStringLiteral("Switch One Desktop to the Left"), VirtualDesktopManager::Direction::Left); 0346 } 0347 0348 void TestVirtualDesktops::right_data() 0349 { 0350 addDirectionColumns(); 0351 QTest::newRow("one desktop, wrap") << (uint)1 << (uint)1 << true << (uint)1; 0352 QTest::newRow("one desktop, no wrap") << (uint)1 << (uint)1 << false << (uint)1; 0353 QTest::newRow("desktops, wrap, 1st row") << (uint)4 << (uint)1 << true << (uint)2; 0354 QTest::newRow("desktops, no wrap, 1st row") << (uint)4 << (uint)1 << false << (uint)2; 0355 QTest::newRow("desktops, wrap, 2nd row") << (uint)4 << (uint)3 << true << (uint)4; 0356 QTest::newRow("desktops, no wrap, 2nd row") << (uint)4 << (uint)3 << false << (uint)4; 0357 0358 QTest::newRow("desktops at start, wrap, 1st row") << (uint)4 << (uint)2 << true << (uint)1; 0359 QTest::newRow("desktops at start, no wrap, 1st row") << (uint)4 << (uint)2 << false << (uint)2; 0360 QTest::newRow("desktops at start, wrap, 2nd row") << (uint)4 << (uint)4 << true << (uint)3; 0361 QTest::newRow("desktops at start, no wrap, 2nd row") << (uint)4 << (uint)4 << false << (uint)4; 0362 0363 QTest::newRow("non symmetric, start") << (uint)5 << (uint)4 << false << (uint)5; 0364 QTest::newRow("non symmetric, end, no wrap") << (uint)5 << (uint)5 << false << (uint)5; 0365 QTest::newRow("non symmetric, end, wrap") << (uint)5 << (uint)5 << true << (uint)4; 0366 } 0367 0368 void TestVirtualDesktops::right() 0369 { 0370 testDirection(QStringLiteral("Switch One Desktop to the Right"), VirtualDesktopManager::Direction::Right); 0371 } 0372 0373 void TestVirtualDesktops::above_data() 0374 { 0375 addDirectionColumns(); 0376 QTest::newRow("one desktop, wrap") << (uint)1 << (uint)1 << true << (uint)1; 0377 QTest::newRow("one desktop, no wrap") << (uint)1 << (uint)1 << false << (uint)1; 0378 QTest::newRow("desktops, wrap, 1st column") << (uint)4 << (uint)3 << true << (uint)1; 0379 QTest::newRow("desktops, no wrap, 1st column") << (uint)4 << (uint)3 << false << (uint)1; 0380 QTest::newRow("desktops, wrap, 2nd column") << (uint)4 << (uint)4 << true << (uint)2; 0381 QTest::newRow("desktops, no wrap, 2nd column") << (uint)4 << (uint)4 << false << (uint)2; 0382 0383 QTest::newRow("desktops at start, wrap, 1st column") << (uint)4 << (uint)1 << true << (uint)3; 0384 QTest::newRow("desktops at start, no wrap, 1st column") << (uint)4 << (uint)1 << false << (uint)1; 0385 QTest::newRow("desktops at start, wrap, 2nd column") << (uint)4 << (uint)2 << true << (uint)4; 0386 QTest::newRow("desktops at start, no wrap, 2nd column") << (uint)4 << (uint)2 << false << (uint)2; 0387 } 0388 0389 void TestVirtualDesktops::above() 0390 { 0391 testDirection(QStringLiteral("Switch One Desktop Up"), VirtualDesktopManager::Direction::Up); 0392 } 0393 0394 void TestVirtualDesktops::below_data() 0395 { 0396 addDirectionColumns(); 0397 QTest::newRow("one desktop, wrap") << (uint)1 << (uint)1 << true << (uint)1; 0398 QTest::newRow("one desktop, no wrap") << (uint)1 << (uint)1 << false << (uint)1; 0399 QTest::newRow("desktops, wrap, 1st column") << (uint)4 << (uint)1 << true << (uint)3; 0400 QTest::newRow("desktops, no wrap, 1st column") << (uint)4 << (uint)1 << false << (uint)3; 0401 QTest::newRow("desktops, wrap, 2nd column") << (uint)4 << (uint)2 << true << (uint)4; 0402 QTest::newRow("desktops, no wrap, 2nd column") << (uint)4 << (uint)2 << false << (uint)4; 0403 0404 QTest::newRow("desktops at start, wrap, 1st column") << (uint)4 << (uint)3 << true << (uint)1; 0405 QTest::newRow("desktops at start, no wrap, 1st column") << (uint)4 << (uint)3 << false << (uint)3; 0406 QTest::newRow("desktops at start, wrap, 2nd column") << (uint)4 << (uint)4 << true << (uint)2; 0407 QTest::newRow("desktops at start, no wrap, 2nd column") << (uint)4 << (uint)4 << false << (uint)4; 0408 } 0409 0410 void TestVirtualDesktops::below() 0411 { 0412 testDirection(QStringLiteral("Switch One Desktop Down"), VirtualDesktopManager::Direction::Down); 0413 } 0414 0415 void TestVirtualDesktops::updateGrid_data() 0416 { 0417 QTest::addColumn<uint>("initCount"); 0418 QTest::addColumn<QSize>("size"); 0419 QTest::addColumn<Qt::Orientation>("orientation"); 0420 QTest::addColumn<QPoint>("coords"); 0421 QTest::addColumn<uint>("desktop"); 0422 const Qt::Orientation h = Qt::Horizontal; 0423 const Qt::Orientation v = Qt::Vertical; 0424 0425 QTest::newRow("one desktop, h") << (uint)1 << QSize(1, 1) << h << QPoint(0, 0) << (uint)1; 0426 QTest::newRow("one desktop, v") << (uint)1 << QSize(1, 1) << v << QPoint(0, 0) << (uint)1; 0427 QTest::newRow("one desktop, h, 0") << (uint)1 << QSize(1, 1) << h << QPoint(1, 0) << (uint)0; 0428 QTest::newRow("one desktop, v, 0") << (uint)1 << QSize(1, 1) << v << QPoint(0, 1) << (uint)0; 0429 0430 QTest::newRow("two desktops, h, 1") << (uint)2 << QSize(2, 1) << h << QPoint(0, 0) << (uint)1; 0431 QTest::newRow("two desktops, h, 2") << (uint)2 << QSize(2, 1) << h << QPoint(1, 0) << (uint)2; 0432 QTest::newRow("two desktops, h, 3") << (uint)2 << QSize(2, 1) << h << QPoint(0, 1) << (uint)0; 0433 QTest::newRow("two desktops, h, 4") << (uint)2 << QSize(2, 1) << h << QPoint(2, 0) << (uint)0; 0434 0435 QTest::newRow("two desktops, v, 1") << (uint)2 << QSize(2, 1) << v << QPoint(0, 0) << (uint)1; 0436 QTest::newRow("two desktops, v, 2") << (uint)2 << QSize(2, 1) << v << QPoint(1, 0) << (uint)2; 0437 QTest::newRow("two desktops, v, 3") << (uint)2 << QSize(2, 1) << v << QPoint(0, 1) << (uint)0; 0438 QTest::newRow("two desktops, v, 4") << (uint)2 << QSize(2, 1) << v << QPoint(2, 0) << (uint)0; 0439 0440 QTest::newRow("four desktops, h, one row, 1") << (uint)4 << QSize(4, 1) << h << QPoint(0, 0) << (uint)1; 0441 QTest::newRow("four desktops, h, one row, 2") << (uint)4 << QSize(4, 1) << h << QPoint(1, 0) << (uint)2; 0442 QTest::newRow("four desktops, h, one row, 3") << (uint)4 << QSize(4, 1) << h << QPoint(2, 0) << (uint)3; 0443 QTest::newRow("four desktops, h, one row, 4") << (uint)4 << QSize(4, 1) << h << QPoint(3, 0) << (uint)4; 0444 0445 QTest::newRow("four desktops, v, one column, 1") << (uint)4 << QSize(1, 4) << v << QPoint(0, 0) << (uint)1; 0446 QTest::newRow("four desktops, v, one column, 2") << (uint)4 << QSize(1, 4) << v << QPoint(0, 1) << (uint)2; 0447 QTest::newRow("four desktops, v, one column, 3") << (uint)4 << QSize(1, 4) << v << QPoint(0, 2) << (uint)3; 0448 QTest::newRow("four desktops, v, one column, 4") << (uint)4 << QSize(1, 4) << v << QPoint(0, 3) << (uint)4; 0449 0450 QTest::newRow("four desktops, h, grid, 1") << (uint)4 << QSize(2, 2) << h << QPoint(0, 0) << (uint)1; 0451 QTest::newRow("four desktops, h, grid, 2") << (uint)4 << QSize(2, 2) << h << QPoint(1, 0) << (uint)2; 0452 QTest::newRow("four desktops, h, grid, 3") << (uint)4 << QSize(2, 2) << h << QPoint(0, 1) << (uint)3; 0453 QTest::newRow("four desktops, h, grid, 4") << (uint)4 << QSize(2, 2) << h << QPoint(1, 1) << (uint)4; 0454 QTest::newRow("four desktops, h, grid, 0/3") << (uint)4 << QSize(2, 2) << h << QPoint(0, 3) << (uint)0; 0455 0456 QTest::newRow("three desktops, h, grid, 1") << (uint)3 << QSize(2, 2) << h << QPoint(0, 0) << (uint)1; 0457 QTest::newRow("three desktops, h, grid, 2") << (uint)3 << QSize(2, 2) << h << QPoint(1, 0) << (uint)2; 0458 QTest::newRow("three desktops, h, grid, 3") << (uint)3 << QSize(2, 2) << h << QPoint(0, 1) << (uint)3; 0459 QTest::newRow("three desktops, h, grid, 4") << (uint)3 << QSize(2, 2) << h << QPoint(1, 1) << (uint)0; 0460 } 0461 0462 void TestVirtualDesktops::updateGrid() 0463 { 0464 VirtualDesktopManager *vds = VirtualDesktopManager::self(); 0465 QFETCH(uint, initCount); 0466 vds->setCount(initCount); 0467 VirtualDesktopGrid grid; 0468 0469 QFETCH(QSize, size); 0470 QFETCH(Qt::Orientation, orientation); 0471 QCOMPARE(vds->desktops().count(), int(initCount)); 0472 grid.update(size, orientation, vds->desktops()); 0473 QCOMPARE(grid.size(), size); 0474 QCOMPARE(grid.width(), size.width()); 0475 QCOMPARE(grid.height(), size.height()); 0476 QFETCH(QPoint, coords); 0477 QFETCH(uint, desktop); 0478 QCOMPARE(grid.at(coords), vds->desktopForX11Id(desktop)); 0479 if (desktop != 0) { 0480 QCOMPARE(grid.gridCoords(desktop), coords); 0481 } 0482 } 0483 0484 void TestVirtualDesktops::updateLayout_data() 0485 { 0486 QTest::addColumn<uint>("desktop"); 0487 QTest::addColumn<QSize>("result"); 0488 0489 QTest::newRow("01") << (uint)1 << QSize(1, 1); 0490 QTest::newRow("02") << (uint)2 << QSize(1, 2); 0491 QTest::newRow("03") << (uint)3 << QSize(2, 2); 0492 QTest::newRow("04") << (uint)4 << QSize(2, 2); 0493 QTest::newRow("05") << (uint)5 << QSize(3, 2); 0494 QTest::newRow("06") << (uint)6 << QSize(3, 2); 0495 QTest::newRow("07") << (uint)7 << QSize(4, 2); 0496 QTest::newRow("08") << (uint)8 << QSize(4, 2); 0497 QTest::newRow("09") << (uint)9 << QSize(5, 2); 0498 QTest::newRow("10") << (uint)10 << QSize(5, 2); 0499 QTest::newRow("11") << (uint)11 << QSize(6, 2); 0500 QTest::newRow("12") << (uint)12 << QSize(6, 2); 0501 QTest::newRow("13") << (uint)13 << QSize(7, 2); 0502 QTest::newRow("14") << (uint)14 << QSize(7, 2); 0503 QTest::newRow("15") << (uint)15 << QSize(8, 2); 0504 QTest::newRow("16") << (uint)16 << QSize(8, 2); 0505 QTest::newRow("17") << (uint)17 << QSize(9, 2); 0506 QTest::newRow("18") << (uint)18 << QSize(9, 2); 0507 QTest::newRow("19") << (uint)19 << QSize(10, 2); 0508 QTest::newRow("20") << (uint)20 << QSize(10, 2); 0509 } 0510 0511 void TestVirtualDesktops::updateLayout() 0512 { 0513 VirtualDesktopManager *vds = VirtualDesktopManager::self(); 0514 QSignalSpy spy(vds, &VirtualDesktopManager::layoutChanged); 0515 // call update layout - implicitly through setCount 0516 QFETCH(uint, desktop); 0517 QFETCH(QSize, result); 0518 vds->setCount(desktop); 0519 QCOMPARE(vds->grid().size(), result); 0520 QCOMPARE(spy.count(), 1); 0521 const QVariantList &arguments = spy.at(0); 0522 QCOMPARE(arguments.at(0).toInt(), result.width()); 0523 QCOMPARE(arguments.at(1).toInt(), result.height()); 0524 // calling update layout again should not change anything 0525 vds->updateLayout(); 0526 QCOMPARE(vds->grid().size(), result); 0527 QCOMPARE(spy.count(), 2); 0528 const QVariantList &arguments2 = spy.at(1); 0529 QCOMPARE(arguments2.at(0).toInt(), result.width()); 0530 QCOMPARE(arguments2.at(1).toInt(), result.height()); 0531 } 0532 0533 void TestVirtualDesktops::name_data() 0534 { 0535 QTest::addColumn<uint>("initCount"); 0536 QTest::addColumn<uint>("desktop"); 0537 QTest::addColumn<QString>("desktopName"); 0538 0539 QTest::newRow("desktop 1") << (uint)5 << (uint)1 << "Desktop 1"; 0540 QTest::newRow("desktop 2") << (uint)5 << (uint)2 << "Desktop 2"; 0541 QTest::newRow("desktop 3") << (uint)5 << (uint)3 << "Desktop 3"; 0542 QTest::newRow("desktop 4") << (uint)5 << (uint)4 << "Desktop 4"; 0543 QTest::newRow("desktop 5") << (uint)5 << (uint)5 << "Desktop 5"; 0544 } 0545 0546 void TestVirtualDesktops::name() 0547 { 0548 VirtualDesktopManager *vds = VirtualDesktopManager::self(); 0549 QFETCH(uint, initCount); 0550 vds->setCount(initCount); 0551 QFETCH(uint, desktop); 0552 0553 const VirtualDesktop *vd = vds->desktopForX11Id(desktop); 0554 QTEST(vd->name(), "desktopName"); 0555 } 0556 0557 void TestVirtualDesktops::switchToShortcuts() 0558 { 0559 VirtualDesktopManager *vds = VirtualDesktopManager::self(); 0560 vds->setCount(vds->maximum()); 0561 vds->setCurrent(vds->maximum()); 0562 QCOMPARE(vds->current(), vds->maximum()); 0563 vds->initShortcuts(); 0564 const QString toDesktop = QStringLiteral("Switch to Desktop %1"); 0565 for (uint i = 1; i <= vds->maximum(); ++i) { 0566 const QString desktop(toDesktop.arg(i)); 0567 QAction *action = vds->findChild<QAction *>(desktop); 0568 QVERIFY2(action, desktop.toUtf8().constData()); 0569 action->trigger(); 0570 QCOMPARE(vds->current(), i); 0571 } 0572 // invoke switchTo not from a QAction 0573 QMetaObject::invokeMethod(vds, "slotSwitchTo"); 0574 // should still be on max 0575 QCOMPARE(vds->current(), vds->maximum()); 0576 } 0577 0578 void TestVirtualDesktops::changeRows() 0579 { 0580 VirtualDesktopManager *vds = VirtualDesktopManager::self(); 0581 0582 vds->setCount(4); 0583 vds->setRows(4); 0584 QCOMPARE(vds->rows(), 4); 0585 0586 vds->setRows(5); 0587 QCOMPARE(vds->rows(), 4); 0588 0589 vds->setCount(2); 0590 QCOMPARE(vds->rows(), 2); 0591 } 0592 0593 void TestVirtualDesktops::load() 0594 { 0595 VirtualDesktopManager *vds = VirtualDesktopManager::self(); 0596 // no config yet, load should not change anything 0597 vds->load(); 0598 QCOMPARE(vds->count(), (uint)0); 0599 // empty config should create one desktop 0600 KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); 0601 vds->setConfig(config); 0602 vds->load(); 0603 QCOMPARE(vds->count(), (uint)1); 0604 // setting a sensible number 0605 config->group("Desktops").writeEntry("Number", 4); 0606 vds->load(); 0607 QCOMPARE(vds->count(), (uint)4); 0608 0609 // setting the config value and reloading should update 0610 config->group("Desktops").writeEntry("Number", 5); 0611 vds->load(); 0612 QCOMPARE(vds->count(), (uint)5); 0613 } 0614 0615 void TestVirtualDesktops::save() 0616 { 0617 VirtualDesktopManager *vds = VirtualDesktopManager::self(); 0618 vds->setCount(4); 0619 // no config yet, just to ensure it actually works 0620 vds->save(); 0621 KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); 0622 vds->setConfig(config); 0623 0624 // now save should create the group "Desktops" 0625 QCOMPARE(config->hasGroup("Desktops"), false); 0626 vds->save(); 0627 QCOMPARE(config->hasGroup("Desktops"), true); 0628 KConfigGroup desktops = config->group("Desktops"); 0629 QCOMPARE(desktops.readEntry<int>("Number", 1), 4); 0630 QCOMPARE(desktops.hasKey("Name_1"), false); 0631 QCOMPARE(desktops.hasKey("Name_2"), false); 0632 QCOMPARE(desktops.hasKey("Name_3"), false); 0633 QCOMPARE(desktops.hasKey("Name_4"), false); 0634 } 0635 0636 QTEST_MAIN(TestVirtualDesktops) 0637 #include "test_virtual_desktops.moc"