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