KWin
Loading...
Searching...
No Matches
device_test.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include <config-kwin.h>
10
12#include "mock_libinput.h"
13
14#include <KSharedConfig>
15
16#include <QDBusConnection>
17#include <QDBusInterface>
18#include <QSignalSpy>
19#include <QTest>
20
21#include <linux/input.h>
22
23using namespace KWin::LibInput;
24
25class TestLibinputDevice : public QObject
26{
27 Q_OBJECT
28private Q_SLOTS:
29 void initTestCase();
30 void testDeviceType_data();
31 void testDeviceType();
32 void testGestureSupport_data();
33 void testGestureSupport();
34 void testNames_data();
35 void testNames();
36 void testProduct();
37 void testVendor();
38 void testTapFingerCount();
39 void testSize_data();
40 void testSize();
41 void testDefaultPointerAcceleration_data();
42 void testDefaultPointerAcceleration();
43 void testDefaultPointerAccelerationProfileFlat_data();
44 void testDefaultPointerAccelerationProfileFlat();
45 void testDefaultPointerAccelerationProfileAdaptive_data();
46 void testDefaultPointerAccelerationProfileAdaptive();
47 void testDefaultClickMethodAreas_data();
48 void testDefaultClickMethodAreas();
49 void testDefaultClickMethodClickfinger_data();
50 void testDefaultClickMethodClickfinger();
51 void testLeftHandedEnabledByDefault_data();
52 void testLeftHandedEnabledByDefault();
53 void testTapEnabledByDefault_data();
54 void testTapEnabledByDefault();
55 void testMiddleEmulationEnabledByDefault_data();
56 void testMiddleEmulationEnabledByDefault();
57 void testNaturalScrollEnabledByDefault_data();
58 void testNaturalScrollEnabledByDefault();
59 void testScrollTwoFingerEnabledByDefault_data();
60 void testScrollTwoFingerEnabledByDefault();
61 void testScrollEdgeEnabledByDefault_data();
62 void testScrollEdgeEnabledByDefault();
63 void testScrollOnButtonDownEnabledByDefault_data();
64 void testScrollOnButtonDownEnabledByDefault();
65 void testDisableWhileTypingEnabledByDefault_data();
66 void testDisableWhileTypingEnabledByDefault();
67 void testLmrTapButtonMapEnabledByDefault_data();
68 void testLmrTapButtonMapEnabledByDefault();
69 void testSupportsDisableWhileTyping_data();
70 void testSupportsDisableWhileTyping();
71 void testSupportsPointerAcceleration_data();
72 void testSupportsPointerAcceleration();
73 void testSupportsLeftHanded_data();
74 void testSupportsLeftHanded();
75 void testSupportsCalibrationMatrix_data();
76 void testSupportsCalibrationMatrix();
77 void testSupportsDisableEvents_data();
78 void testSupportsDisableEvents();
79 void testSupportsDisableEventsOnExternalMouse_data();
80 void testSupportsDisableEventsOnExternalMouse();
81 void testSupportsMiddleEmulation_data();
82 void testSupportsMiddleEmulation();
83 void testSupportsNaturalScroll_data();
84 void testSupportsNaturalScroll();
85 void testSupportsScrollTwoFinger_data();
86 void testSupportsScrollTwoFinger();
87 void testSupportsScrollEdge_data();
88 void testSupportsScrollEdge();
89 void testSupportsScrollOnButtonDown_data();
90 void testSupportsScrollOnButtonDown();
91 void testDefaultScrollButton_data();
92 void testDefaultScrollButton();
93 void testPointerAcceleration_data();
94 void testPointerAcceleration();
95 void testLeftHanded_data();
96 void testLeftHanded();
97 void testSupportedButtons_data();
98 void testSupportedButtons();
99 void testAlphaNumericKeyboard_data();
100 void testAlphaNumericKeyboard();
101 void testEnabled_data();
102 void testEnabled();
103 void testTapToClick_data();
104 void testTapToClick();
105 void testTapAndDragEnabledByDefault_data();
106 void testTapAndDragEnabledByDefault();
107 void testTapAndDrag_data();
108 void testTapAndDrag();
109 void testTapDragLockEnabledByDefault_data();
110 void testTapDragLockEnabledByDefault();
111 void testTapDragLock_data();
112 void testTapDragLock();
113 void testMiddleEmulation_data();
114 void testMiddleEmulation();
115 void testNaturalScroll_data();
116 void testNaturalScroll();
117 void testScrollFactor();
118 void testScrollTwoFinger_data();
119 void testScrollTwoFinger();
120 void testScrollEdge_data();
121 void testScrollEdge();
122 void testScrollButtonDown_data();
123 void testScrollButtonDown();
124 void testScrollButton_data();
125 void testScrollButton();
126 void testDisableWhileTyping_data();
127 void testDisableWhileTyping();
128 void testLmrTapButtonMap_data();
129 void testLmrTapButtonMap();
130 void testLoadEnabled_data();
131 void testLoadEnabled();
132 void testLoadPointerAcceleration_data();
133 void testLoadPointerAcceleration();
134 void testLoadPointerAccelerationProfile_data();
135 void testLoadPointerAccelerationProfile();
136 void testLoadClickMethod_data();
137 void testLoadClickMethod();
138 void testLoadTapToClick_data();
139 void testLoadTapToClick();
140 void testLoadTapAndDrag_data();
141 void testLoadTapAndDrag();
142 void testLoadTapDragLock_data();
143 void testLoadTapDragLock();
144 void testLoadMiddleButtonEmulation_data();
145 void testLoadMiddleButtonEmulation();
146 void testLoadNaturalScroll_data();
147 void testLoadNaturalScroll();
148 void testLoadScrollMethod_data();
149 void testLoadScrollMethod();
150 void testLoadScrollButton_data();
151 void testLoadScrollButton();
152 void testLoadDisableWhileTyping_data();
153 void testLoadDisableWhileTyping();
154 void testLoadLmrTapButtonMap_data();
155 void testLoadLmrTapButtonMap();
156 void testLoadLeftHanded_data();
157 void testLoadLeftHanded();
158 void testOrientation_data();
159 void testOrientation();
160 void testCalibrationWithDefault();
161 void testSwitch_data();
162 void testSwitch();
163};
164
165namespace
166{
167template<typename T>
168T dbusProperty(const QString &name, const char *property)
169{
170 QDBusInterface interface {
171 QStringLiteral("org.kde.kwin.tests.libinputdevice"),
172 QStringLiteral("/org/kde/KWin/InputDevice/") + name,
173 QStringLiteral("org.kde.KWin.InputDevice")
174 };
175 return interface.property(property).value<T>();
176}
177}
178
179void TestLibinputDevice::initTestCase()
180{
181 QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kwin.tests.libinputdevice"));
182}
183
184void TestLibinputDevice::testDeviceType_data()
185{
186 QTest::addColumn<bool>("keyboard");
187 QTest::addColumn<bool>("pointer");
188 QTest::addColumn<bool>("touch");
189 QTest::addColumn<bool>("tabletTool");
190 QTest::addColumn<bool>("switchDevice");
191
192 QTest::newRow("keyboard") << true << false << false << false << false;
193 QTest::newRow("pointer") << false << true << false << false << false;
194 QTest::newRow("touch") << false << false << true << false << false;
195 QTest::newRow("keyboard/pointer") << true << true << false << false << false;
196 QTest::newRow("keyboard/touch") << true << false << true << false << false;
197 QTest::newRow("pointer/touch") << false << true << true << false << false;
198 QTest::newRow("keyboard/pointer/touch") << true << true << true << false << false;
199 QTest::newRow("tabletTool") << false << false << false << true << false;
200 QTest::newRow("switch") << false << false << false << false << true;
201}
202
203void TestLibinputDevice::testDeviceType()
204{
205 // this test verifies that the device type is recognized correctly
206 QFETCH(bool, keyboard);
207 QFETCH(bool, pointer);
208 QFETCH(bool, touch);
209 QFETCH(bool, tabletTool);
210 QFETCH(bool, switchDevice);
211
212 libinput_device device;
213 device.keyboard = keyboard;
214 device.pointer = pointer;
215 device.touch = touch;
216 device.tabletTool = tabletTool;
217 device.switchDevice = switchDevice;
218
219 Device d(&device);
220 QCOMPARE(d.isKeyboard(), keyboard);
221 QCOMPARE(d.property("keyboard").toBool(), keyboard);
222 QCOMPARE(dbusProperty<bool>(d.sysName(), "keyboard"), keyboard);
223 QCOMPARE(d.isPointer(), pointer);
224 QCOMPARE(d.property("pointer").toBool(), pointer);
225 QCOMPARE(dbusProperty<bool>(d.sysName(), "pointer"), pointer);
226 QCOMPARE(d.isTouch(), touch);
227 QCOMPARE(d.property("touch").toBool(), touch);
228 QCOMPARE(dbusProperty<bool>(d.sysName(), "touch"), touch);
229 QCOMPARE(d.isTabletPad(), false);
230 QCOMPARE(d.property("tabletPad").toBool(), false);
231 QCOMPARE(dbusProperty<bool>(d.sysName(), "tabletPad"), false);
232 QCOMPARE(d.isTabletTool(), tabletTool);
233 QCOMPARE(d.property("tabletTool").toBool(), tabletTool);
234 QCOMPARE(dbusProperty<bool>(d.sysName(), "tabletTool"), tabletTool);
235 QCOMPARE(d.isSwitch(), switchDevice);
236 QCOMPARE(d.property("switchDevice").toBool(), switchDevice);
237 QCOMPARE(dbusProperty<bool>(d.sysName(), "switchDevice"), switchDevice);
238
239 QCOMPARE(d.device(), &device);
240}
241
242void TestLibinputDevice::testGestureSupport_data()
243{
244 QTest::addColumn<bool>("supported");
245
246 QTest::newRow("supported") << true;
247 QTest::newRow("not supported") << false;
248}
249
250void TestLibinputDevice::testGestureSupport()
251{
252 // this test verifies whether the Device supports gestures
253 QFETCH(bool, supported);
254 libinput_device device;
255 device.gestureSupported = supported;
256
257 Device d(&device);
258 QCOMPARE(d.supportsGesture(), supported);
259 QCOMPARE(d.property("gestureSupport").toBool(), supported);
260 QCOMPARE(dbusProperty<bool>(d.sysName(), "gestureSupport"), supported);
261}
262
263void TestLibinputDevice::testNames_data()
264{
265 QTest::addColumn<QByteArray>("name");
266 QTest::addColumn<QByteArray>("sysName");
267 QTest::addColumn<QByteArray>("outputName");
268
269 QTest::newRow("empty") << QByteArray() << QByteArrayLiteral("event1") << QByteArray();
270 QTest::newRow("set") << QByteArrayLiteral("awesome test device") << QByteArrayLiteral("event0") << QByteArrayLiteral("hdmi0");
271}
272
273void TestLibinputDevice::testNames()
274{
275 // this test verifies the various name properties of the Device
276 QFETCH(QByteArray, name);
277 QFETCH(QByteArray, sysName);
278 QFETCH(QByteArray, outputName);
279 libinput_device device;
280 device.name = name;
281 device.sysName = sysName;
282 device.outputName = outputName;
283
284 Device d(&device);
285 QCOMPARE(d.name().toUtf8(), name);
286 QCOMPARE(d.property("name").toString().toUtf8(), name);
287 QCOMPARE(dbusProperty<QString>(d.sysName(), "name"), name);
288 QCOMPARE(d.sysName().toUtf8(), sysName);
289 QCOMPARE(d.property("sysName").toString().toUtf8(), sysName);
290 QCOMPARE(dbusProperty<QString>(d.sysName(), "sysName"), sysName);
291 QCOMPARE(d.outputName().toUtf8(), outputName);
292 QCOMPARE(d.property("outputName").toString().toUtf8(), outputName);
293 QCOMPARE(dbusProperty<QString>(d.sysName(), "outputName"), outputName);
294}
295
296void TestLibinputDevice::testProduct()
297{
298 // this test verifies the product property
299 libinput_device device;
300 device.product = 100u;
301 Device d(&device);
302 QCOMPARE(d.product(), 100u);
303 QCOMPARE(d.property("product").toUInt(), 100u);
304 QCOMPARE(dbusProperty<quint32>(d.sysName(), "product"), 100u);
305}
306
307void TestLibinputDevice::testVendor()
308{
309 // this test verifies the vendor property
310 libinput_device device;
311 device.vendor = 200u;
312 Device d(&device);
313 QCOMPARE(d.vendor(), 200u);
314 QCOMPARE(d.property("vendor").toUInt(), 200u);
315 QCOMPARE(dbusProperty<quint32>(d.sysName(), "vendor"), 200u);
316}
317
318void TestLibinputDevice::testTapFingerCount()
319{
320 // this test verifies the tap finger count property
321 libinput_device device;
322 device.tapFingerCount = 3;
323 Device d(&device);
324 QCOMPARE(d.tapFingerCount(), 3);
325 QCOMPARE(d.property("tapFingerCount").toInt(), 3);
326 QCOMPARE(dbusProperty<int>(d.sysName(), "tapFingerCount"), 3);
327}
328
329void TestLibinputDevice::testSize_data()
330{
331 QTest::addColumn<QSizeF>("setSize");
332 QTest::addColumn<int>("returnValue");
333 QTest::addColumn<QSizeF>("expectedSize");
334
335 QTest::newRow("10/20") << QSizeF(10.5, 20.2) << 0 << QSizeF(10.5, 20.2);
336 QTest::newRow("failure") << QSizeF(10, 20) << 1 << QSizeF();
337}
338
339void TestLibinputDevice::testSize()
340{
341 // this test verifies that getting the size works correctly including failures
342 QFETCH(QSizeF, setSize);
343 QFETCH(int, returnValue);
344 libinput_device device;
345 device.deviceSize = setSize;
346 device.deviceSizeReturnValue = returnValue;
347
348 Device d(&device);
349 QTEST(d.size(), "expectedSize");
350 QTEST(d.property("size").toSizeF(), "expectedSize");
351 QTEST(dbusProperty<QSizeF>(d.sysName(), "size"), "expectedSize");
352}
353
354void TestLibinputDevice::testLeftHandedEnabledByDefault_data()
355{
356 QTest::addColumn<bool>("enabled");
357
358 QTest::newRow("enabled") << true;
359 QTest::newRow("disabled") << false;
360}
361
362void TestLibinputDevice::testLeftHandedEnabledByDefault()
363{
364 QFETCH(bool, enabled);
365 libinput_device device;
366 device.leftHandedEnabledByDefault = enabled;
367
368 Device d(&device);
369 QCOMPARE(d.leftHandedEnabledByDefault(), enabled);
370 QCOMPARE(d.property("leftHandedEnabledByDefault").toBool(), enabled);
371 QCOMPARE(dbusProperty<bool>(d.sysName(), "leftHandedEnabledByDefault"), enabled);
372}
373
374void TestLibinputDevice::testTapEnabledByDefault_data()
375{
376 QTest::addColumn<bool>("enabled");
377
378 QTest::newRow("enabled") << true;
379 QTest::newRow("disabled") << false;
380}
381
382void TestLibinputDevice::testTapEnabledByDefault()
383{
384 QFETCH(bool, enabled);
385 libinput_device device;
386 device.tapEnabledByDefault = enabled;
387
388 Device d(&device);
389 QCOMPARE(d.tapToClickEnabledByDefault(), true);
390 QCOMPARE(d.property("tapToClickEnabledByDefault").toBool(), true);
391 QCOMPARE(dbusProperty<bool>(d.sysName(), "tapToClickEnabledByDefault"), true);
392}
393
394void TestLibinputDevice::testMiddleEmulationEnabledByDefault_data()
395{
396 QTest::addColumn<bool>("enabled");
397
398 QTest::newRow("enabled") << true;
399 QTest::newRow("disabled") << false;
400}
401
402void TestLibinputDevice::testMiddleEmulationEnabledByDefault()
403{
404 QFETCH(bool, enabled);
405 libinput_device device;
406 device.middleEmulationEnabledByDefault = enabled;
407
408 Device d(&device);
409 QCOMPARE(d.middleEmulationEnabledByDefault(), enabled);
410 QCOMPARE(d.property("middleEmulationEnabledByDefault").toBool(), enabled);
411 QCOMPARE(dbusProperty<bool>(d.sysName(), "middleEmulationEnabledByDefault"), enabled);
412}
413
414void TestLibinputDevice::testNaturalScrollEnabledByDefault_data()
415{
416 QTest::addColumn<bool>("enabled");
417
418 QTest::newRow("enabled") << true;
419 QTest::newRow("disabled") << false;
420}
421
422void TestLibinputDevice::testNaturalScrollEnabledByDefault()
423{
424 QFETCH(bool, enabled);
425 libinput_device device;
426 device.naturalScrollEnabledByDefault = enabled;
427
428 Device d(&device);
429 QCOMPARE(d.naturalScrollEnabledByDefault(), enabled);
430 QCOMPARE(d.property("naturalScrollEnabledByDefault").toBool(), enabled);
431 QCOMPARE(dbusProperty<bool>(d.sysName(), "naturalScrollEnabledByDefault"), enabled);
432}
433
434void TestLibinputDevice::testScrollTwoFingerEnabledByDefault_data()
435{
436 QTest::addColumn<bool>("enabled");
437
438 QTest::newRow("enabled") << true;
439 QTest::newRow("disabled") << false;
440}
441
442void TestLibinputDevice::testScrollTwoFingerEnabledByDefault()
443{
444 QFETCH(bool, enabled);
445 libinput_device device;
446 device.defaultScrollMethod = enabled ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
447
448 Device d(&device);
449 QCOMPARE(d.scrollTwoFingerEnabledByDefault(), enabled);
450 QCOMPARE(d.property("scrollTwoFingerEnabledByDefault").toBool(), enabled);
451 QCOMPARE(dbusProperty<bool>(d.sysName(), "scrollTwoFingerEnabledByDefault"), enabled);
452}
453
454void TestLibinputDevice::testScrollEdgeEnabledByDefault_data()
455{
456 QTest::addColumn<bool>("enabled");
457
458 QTest::newRow("enabled") << true;
459 QTest::newRow("disabled") << false;
460}
461
462void TestLibinputDevice::testScrollEdgeEnabledByDefault()
463{
464 QFETCH(bool, enabled);
465 libinput_device device;
466 device.defaultScrollMethod = enabled ? LIBINPUT_CONFIG_SCROLL_EDGE : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
467
468 Device d(&device);
469 QCOMPARE(d.scrollEdgeEnabledByDefault(), enabled);
470 QCOMPARE(d.property("scrollEdgeEnabledByDefault").toBool(), enabled);
471 QCOMPARE(dbusProperty<bool>(d.sysName(), "scrollEdgeEnabledByDefault"), enabled);
472}
473
474void TestLibinputDevice::testDefaultPointerAccelerationProfileFlat_data()
475{
476 QTest::addColumn<bool>("enabled");
477
478 QTest::newRow("enabled") << true;
479 QTest::newRow("disabled") << false;
480}
481
482void TestLibinputDevice::testDefaultPointerAccelerationProfileFlat()
483{
484 QFETCH(bool, enabled);
485 libinput_device device;
486 device.defaultPointerAccelerationProfile = enabled ? LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT : LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
487
488 Device d(&device);
489 QCOMPARE(d.defaultPointerAccelerationProfileFlat(), enabled);
490 QCOMPARE(d.property("defaultPointerAccelerationProfileFlat").toBool(), enabled);
491 QCOMPARE(dbusProperty<bool>(d.sysName(), "defaultPointerAccelerationProfileFlat"), enabled);
492}
493
494void TestLibinputDevice::testDefaultPointerAccelerationProfileAdaptive_data()
495{
496 QTest::addColumn<bool>("enabled");
497
498 QTest::newRow("enabled") << true;
499 QTest::newRow("disabled") << false;
500}
501
502void TestLibinputDevice::testDefaultPointerAccelerationProfileAdaptive()
503{
504 QFETCH(bool, enabled);
505 libinput_device device;
506 device.defaultPointerAccelerationProfile = enabled ? LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE : LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
507
508 Device d(&device);
509 QCOMPARE(d.defaultPointerAccelerationProfileAdaptive(), enabled);
510 QCOMPARE(d.property("defaultPointerAccelerationProfileAdaptive").toBool(), enabled);
511 QCOMPARE(dbusProperty<bool>(d.sysName(), "defaultPointerAccelerationProfileAdaptive"), enabled);
512}
513
514void TestLibinputDevice::testDefaultClickMethodAreas_data()
515{
516 QTest::addColumn<bool>("enabled");
517
518 QTest::addRow("enabled") << true;
519 QTest::addRow("disabled") << false;
520}
521
522void TestLibinputDevice::testDefaultClickMethodAreas()
523{
524 QFETCH(bool, enabled);
525 libinput_device device;
526 device.defaultClickMethod = enabled ? LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS : LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
527
528 Device d(&device);
529 QCOMPARE(d.defaultClickMethodAreas(), enabled);
530 QCOMPARE(d.property("defaultClickMethodAreas").toBool(), enabled);
531 QCOMPARE(dbusProperty<bool>(d.sysName(), "defaultClickMethodAreas"), enabled);
532}
533
534void TestLibinputDevice::testDefaultClickMethodClickfinger_data()
535{
536 QTest::addColumn<bool>("enabled");
537
538 QTest::addRow("enabled") << true;
539 QTest::addRow("disabled") << false;
540}
541
542void TestLibinputDevice::testDefaultClickMethodClickfinger()
543{
544 QFETCH(bool, enabled);
545 libinput_device device;
546 device.defaultClickMethod = enabled ? LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER : LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
547
548 Device d(&device);
549 QCOMPARE(d.defaultClickMethodClickfinger(), enabled);
550 QCOMPARE(d.property("defaultClickMethodClickfinger").toBool(), enabled);
551 QCOMPARE(dbusProperty<bool>(d.sysName(), "defaultClickMethodClickfinger"), enabled);
552}
553
554void TestLibinputDevice::testScrollOnButtonDownEnabledByDefault_data()
555{
556 QTest::addColumn<bool>("enabled");
557
558 QTest::newRow("enabled") << true;
559 QTest::newRow("disabled") << false;
560}
561
562void TestLibinputDevice::testScrollOnButtonDownEnabledByDefault()
563{
564 QFETCH(bool, enabled);
565 libinput_device device;
566 device.defaultScrollMethod = enabled ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
567
568 Device d(&device);
569 QCOMPARE(d.scrollOnButtonDownEnabledByDefault(), enabled);
570 QCOMPARE(d.property("scrollOnButtonDownEnabledByDefault").toBool(), enabled);
571 QCOMPARE(dbusProperty<bool>(d.sysName(), "scrollOnButtonDownEnabledByDefault"), enabled);
572}
573
574void TestLibinputDevice::testDefaultScrollButton_data()
575{
576 QTest::addColumn<quint32>("button");
577
578 QTest::newRow("0") << 0u;
579 QTest::newRow("BTN_LEFT") << quint32(BTN_LEFT);
580 QTest::newRow("BTN_RIGHT") << quint32(BTN_RIGHT);
581 QTest::newRow("BTN_MIDDLE") << quint32(BTN_MIDDLE);
582 QTest::newRow("BTN_SIDE") << quint32(BTN_SIDE);
583 QTest::newRow("BTN_EXTRA") << quint32(BTN_EXTRA);
584 QTest::newRow("BTN_FORWARD") << quint32(BTN_FORWARD);
585 QTest::newRow("BTN_BACK") << quint32(BTN_BACK);
586 QTest::newRow("BTN_TASK") << quint32(BTN_TASK);
587}
588
589void TestLibinputDevice::testDefaultScrollButton()
590{
591 libinput_device device;
592 QFETCH(quint32, button);
593 device.defaultScrollButton = button;
594
595 Device d(&device);
596 QCOMPARE(d.defaultScrollButton(), button);
597 QCOMPARE(d.property("defaultScrollButton").value<quint32>(), button);
598 QCOMPARE(dbusProperty<quint32>(d.sysName(), "defaultScrollButton"), button);
599}
600
601void TestLibinputDevice::testSupportsDisableWhileTyping_data()
602{
603 QTest::addColumn<bool>("enabled");
604
605 QTest::newRow("enabled") << true;
606 QTest::newRow("disabled") << false;
607}
608
609void TestLibinputDevice::testSupportsDisableWhileTyping()
610{
611 QFETCH(bool, enabled);
612 libinput_device device;
613 device.supportsDisableWhileTyping = enabled;
614
615 Device d(&device);
616 QCOMPARE(d.supportsDisableWhileTyping(), enabled);
617 QCOMPARE(d.property("supportsDisableWhileTyping").toBool(), enabled);
618 QCOMPARE(dbusProperty<bool>(d.sysName(), "supportsDisableWhileTyping"), enabled);
619}
620
621void TestLibinputDevice::testSupportsPointerAcceleration_data()
622{
623 QTest::addColumn<bool>("enabled");
624
625 QTest::newRow("enabled") << true;
626 QTest::newRow("disabled") << false;
627}
628
629void TestLibinputDevice::testSupportsPointerAcceleration()
630{
631 QFETCH(bool, enabled);
632 libinput_device device;
633 device.supportsPointerAcceleration = enabled;
634
635 Device d(&device);
636 QCOMPARE(d.supportsPointerAcceleration(), enabled);
637 QCOMPARE(d.property("supportsPointerAcceleration").toBool(), enabled);
638 QCOMPARE(dbusProperty<bool>(d.sysName(), "supportsPointerAcceleration"), enabled);
639}
640
641void TestLibinputDevice::testSupportsLeftHanded_data()
642{
643 QTest::addColumn<bool>("enabled");
644
645 QTest::newRow("enabled") << true;
646 QTest::newRow("disabled") << false;
647}
648
649void TestLibinputDevice::testSupportsLeftHanded()
650{
651 QFETCH(bool, enabled);
652 libinput_device device;
653 device.supportsLeftHanded = enabled;
654
655 Device d(&device);
656 QCOMPARE(d.supportsLeftHanded(), enabled);
657 QCOMPARE(d.property("supportsLeftHanded").toBool(), enabled);
658 QCOMPARE(dbusProperty<bool>(d.sysName(), "supportsLeftHanded"), enabled);
659}
660
661void TestLibinputDevice::testSupportsCalibrationMatrix_data()
662{
663 QTest::addColumn<bool>("enabled");
664
665 QTest::newRow("enabled") << true;
666 QTest::newRow("disabled") << false;
667}
668
669void TestLibinputDevice::testSupportsCalibrationMatrix()
670{
671 QFETCH(bool, enabled);
672 libinput_device device;
673 device.supportsCalibrationMatrix = enabled;
674
675 Device d(&device);
676 QCOMPARE(d.supportsCalibrationMatrix(), enabled);
677 QCOMPARE(d.property("supportsCalibrationMatrix").toBool(), enabled);
678 QCOMPARE(dbusProperty<bool>(d.sysName(), "supportsCalibrationMatrix"), enabled);
679}
680
681void TestLibinputDevice::testSupportsDisableEvents_data()
682{
683 QTest::addColumn<bool>("enabled");
684
685 QTest::newRow("enabled") << true;
686 QTest::newRow("disabled") << false;
687}
688
689void TestLibinputDevice::testSupportsDisableEvents()
690{
691 QFETCH(bool, enabled);
692 libinput_device device;
693 device.supportsDisableEvents = enabled;
694
695 Device d(&device);
696 QCOMPARE(d.supportsDisableEvents(), enabled);
697 QCOMPARE(d.property("supportsDisableEvents").toBool(), enabled);
698 QCOMPARE(dbusProperty<bool>(d.sysName(), "supportsDisableEvents"), enabled);
699}
700
701void TestLibinputDevice::testSupportsDisableEventsOnExternalMouse_data()
702{
703 QTest::addColumn<bool>("enabled");
704
705 QTest::newRow("enabled") << true;
706 QTest::newRow("disabled") << false;
707}
708
709void TestLibinputDevice::testSupportsDisableEventsOnExternalMouse()
710{
711 QFETCH(bool, enabled);
712 libinput_device device;
714
715 Device d(&device);
716 QCOMPARE(d.supportsDisableEventsOnExternalMouse(), enabled);
717 QCOMPARE(d.property("supportsDisableEventsOnExternalMouse").toBool(), enabled);
718 QCOMPARE(dbusProperty<bool>(d.sysName(), "supportsDisableEventsOnExternalMouse"), enabled);
719}
720
721void TestLibinputDevice::testSupportsMiddleEmulation_data()
722{
723 QTest::addColumn<bool>("enabled");
724
725 QTest::newRow("enabled") << true;
726 QTest::newRow("disabled") << false;
727}
728
729void TestLibinputDevice::testSupportsMiddleEmulation()
730{
731 QFETCH(bool, enabled);
732 libinput_device device;
733 device.supportsMiddleEmulation = enabled;
734
735 Device d(&device);
736 QCOMPARE(d.supportsMiddleEmulation(), enabled);
737 QCOMPARE(d.property("supportsMiddleEmulation").toBool(), enabled);
738 QCOMPARE(dbusProperty<bool>(d.sysName(), "supportsMiddleEmulation"), enabled);
739}
740
741void TestLibinputDevice::testSupportsNaturalScroll_data()
742{
743 QTest::addColumn<bool>("enabled");
744
745 QTest::newRow("enabled") << true;
746 QTest::newRow("disabled") << false;
747}
748
749void TestLibinputDevice::testSupportsNaturalScroll()
750{
751 QFETCH(bool, enabled);
752 libinput_device device;
753 device.supportsNaturalScroll = enabled;
754
755 Device d(&device);
756 QCOMPARE(d.supportsNaturalScroll(), enabled);
757 QCOMPARE(d.property("supportsNaturalScroll").toBool(), enabled);
758 QCOMPARE(dbusProperty<bool>(d.sysName(), "supportsNaturalScroll"), enabled);
759}
760
761void TestLibinputDevice::testSupportsScrollTwoFinger_data()
762{
763 QTest::addColumn<bool>("enabled");
764
765 QTest::newRow("enabled") << true;
766 QTest::newRow("disabled") << false;
767}
768
769void TestLibinputDevice::testSupportsScrollTwoFinger()
770{
771 QFETCH(bool, enabled);
772 libinput_device device;
773 device.supportedScrollMethods = enabled ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
774
775 Device d(&device);
776 QCOMPARE(d.supportsScrollTwoFinger(), enabled);
777 QCOMPARE(d.property("supportsScrollTwoFinger").toBool(), enabled);
778 QCOMPARE(dbusProperty<bool>(d.sysName(), "supportsScrollTwoFinger"), enabled);
779}
780
781void TestLibinputDevice::testSupportsScrollEdge_data()
782{
783 QTest::addColumn<bool>("enabled");
784
785 QTest::newRow("enabled") << true;
786 QTest::newRow("disabled") << false;
787}
788
789void TestLibinputDevice::testSupportsScrollEdge()
790{
791 QFETCH(bool, enabled);
792 libinput_device device;
793 device.supportedScrollMethods = enabled ? LIBINPUT_CONFIG_SCROLL_EDGE : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
794
795 Device d(&device);
796 QCOMPARE(d.supportsScrollEdge(), enabled);
797 QCOMPARE(d.property("supportsScrollEdge").toBool(), enabled);
798 QCOMPARE(dbusProperty<bool>(d.sysName(), "supportsScrollEdge"), enabled);
799}
800
801void TestLibinputDevice::testSupportsScrollOnButtonDown_data()
802{
803 QTest::addColumn<bool>("enabled");
804
805 QTest::newRow("enabled") << true;
806 QTest::newRow("disabled") << false;
807}
808
809void TestLibinputDevice::testSupportsScrollOnButtonDown()
810{
811 QFETCH(bool, enabled);
812 libinput_device device;
813 device.supportedScrollMethods = enabled ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
814
815 Device d(&device);
816 QCOMPARE(d.supportsScrollOnButtonDown(), enabled);
817 QCOMPARE(d.property("supportsScrollOnButtonDown").toBool(), enabled);
818 QCOMPARE(dbusProperty<bool>(d.sysName(), "supportsScrollOnButtonDown"), enabled);
819}
820
821void TestLibinputDevice::testDefaultPointerAcceleration_data()
822{
823 QTest::addColumn<qreal>("accel");
824
825 QTest::newRow("-1.0") << -1.0;
826 QTest::newRow("-0.5") << -0.5;
827 QTest::newRow("0.0") << 0.0;
828 QTest::newRow("0.3") << 0.3;
829 QTest::newRow("1.0") << 1.0;
830}
831
832void TestLibinputDevice::testDefaultPointerAcceleration()
833{
834 QFETCH(qreal, accel);
835 libinput_device device;
836 device.defaultPointerAcceleration = accel;
837
838 Device d(&device);
839 QCOMPARE(d.defaultPointerAcceleration(), accel);
840 QCOMPARE(d.property("defaultPointerAcceleration").toReal(), accel);
841 QCOMPARE(dbusProperty<qreal>(d.sysName(), "defaultPointerAcceleration"), accel);
842}
843
844void TestLibinputDevice::testPointerAcceleration_data()
845{
846 QTest::addColumn<bool>("supported");
847 QTest::addColumn<bool>("setShouldFail");
848 QTest::addColumn<qreal>("accel");
849 QTest::addColumn<qreal>("setAccel");
850 QTest::addColumn<qreal>("expectedAccel");
851 QTest::addColumn<bool>("expectedChanged");
852
853 QTest::newRow("-1 -> 2.0") << true << false << -1.0 << 2.0 << 1.0 << true;
854 QTest::newRow("0 -> -1.0") << true << false << 0.0 << -1.0 << -1.0 << true;
855 QTest::newRow("1 -> 1") << true << false << 1.0 << 1.0 << 1.0 << false;
856 QTest::newRow("unsupported") << false << false << 0.0 << 1.0 << 0.0 << false;
857 QTest::newRow("set fails") << true << true << -1.0 << 1.0 << -1.0 << false;
858}
859
860void TestLibinputDevice::testPointerAcceleration()
861{
862 QFETCH(bool, supported);
863 QFETCH(bool, setShouldFail);
864 QFETCH(qreal, accel);
865 libinput_device device;
866 device.supportsPointerAcceleration = supported;
867 device.pointerAcceleration = accel;
868 device.setPointerAccelerationReturnValue = setShouldFail;
869
870 Device d(&device);
871 QCOMPARE(d.pointerAcceleration(), accel);
872 QCOMPARE(d.property("pointerAcceleration").toReal(), accel);
873 QCOMPARE(dbusProperty<qreal>(d.sysName(), "pointerAcceleration"), accel);
874
875 QSignalSpy pointerAccelChangedSpy(&d, &Device::pointerAccelerationChanged);
876 QFETCH(qreal, setAccel);
877 d.setPointerAcceleration(setAccel);
878 QTEST(d.pointerAcceleration(), "expectedAccel");
879 QTEST(!pointerAccelChangedSpy.isEmpty(), "expectedChanged");
880 QTEST(dbusProperty<qreal>(d.sysName(), "pointerAcceleration"), "expectedAccel");
881}
882
883void TestLibinputDevice::testLeftHanded_data()
884{
885 QTest::addColumn<bool>("supported");
886 QTest::addColumn<bool>("setShouldFail");
887 QTest::addColumn<bool>("initValue");
888 QTest::addColumn<bool>("setValue");
889 QTest::addColumn<bool>("expectedValue");
890
891 QTest::newRow("unsupported/true") << false << false << true << false << false;
892 QTest::newRow("unsupported/false") << false << false << false << true << false;
893 QTest::newRow("true -> false") << true << false << true << false << false;
894 QTest::newRow("false -> true") << true << false << false << true << true;
895 QTest::newRow("set fails") << true << true << true << false << true;
896 QTest::newRow("true -> true") << true << false << true << true << true;
897 QTest::newRow("false -> false") << true << false << false << false << false;
898}
899
900void TestLibinputDevice::testLeftHanded()
901{
902 QFETCH(bool, supported);
903 QFETCH(bool, setShouldFail);
904 QFETCH(bool, initValue);
905 libinput_device device;
906 device.supportsLeftHanded = supported;
907 device.leftHanded = initValue;
908 device.setLeftHandedReturnValue = setShouldFail;
909
910 Device d(&device);
911 QCOMPARE(d.isLeftHanded(), supported && initValue);
912 QCOMPARE(d.property("leftHanded").toBool(), supported && initValue);
913 QCOMPARE(dbusProperty<bool>(d.sysName(), "leftHanded"), supported && initValue);
914
915 QSignalSpy leftHandedChangedSpy(&d, &Device::leftHandedChanged);
916 QFETCH(bool, setValue);
917 d.setLeftHanded(setValue);
918 QFETCH(bool, expectedValue);
919 QCOMPARE(d.isLeftHanded(), expectedValue);
920 QCOMPARE(leftHandedChangedSpy.isEmpty(), (supported && initValue) == expectedValue);
921 QCOMPARE(dbusProperty<bool>(d.sysName(), "leftHanded"), expectedValue);
922}
923
924void TestLibinputDevice::testSupportedButtons_data()
925{
926 QTest::addColumn<bool>("isPointer");
927 QTest::addColumn<Qt::MouseButtons>("setButtons");
928 QTest::addColumn<Qt::MouseButtons>("expectedButtons");
929
930 QTest::newRow("left") << true << Qt::MouseButtons(Qt::LeftButton) << Qt::MouseButtons(Qt::LeftButton);
931 QTest::newRow("right") << true << Qt::MouseButtons(Qt::RightButton) << Qt::MouseButtons(Qt::RightButton);
932 QTest::newRow("middle") << true << Qt::MouseButtons(Qt::MiddleButton) << Qt::MouseButtons(Qt::MiddleButton);
933 QTest::newRow("extra1") << true << Qt::MouseButtons(Qt::ExtraButton1) << Qt::MouseButtons(Qt::ExtraButton1);
934 QTest::newRow("extra2") << true << Qt::MouseButtons(Qt::ExtraButton2) << Qt::MouseButtons(Qt::ExtraButton2);
935 QTest::newRow("back") << true << Qt::MouseButtons(Qt::BackButton) << Qt::MouseButtons(Qt::BackButton);
936 QTest::newRow("forward") << true << Qt::MouseButtons(Qt::ForwardButton) << Qt::MouseButtons(Qt::ForwardButton);
937 QTest::newRow("task") << true << Qt::MouseButtons(Qt::TaskButton) << Qt::MouseButtons(Qt::TaskButton);
938
939 QTest::newRow("no pointer/left") << false << Qt::MouseButtons(Qt::LeftButton) << Qt::MouseButtons();
940 QTest::newRow("no pointer/right") << false << Qt::MouseButtons(Qt::RightButton) << Qt::MouseButtons();
941 QTest::newRow("no pointer/middle") << false << Qt::MouseButtons(Qt::MiddleButton) << Qt::MouseButtons();
942 QTest::newRow("no pointer/extra1") << false << Qt::MouseButtons(Qt::ExtraButton1) << Qt::MouseButtons();
943 QTest::newRow("no pointer/extra2") << false << Qt::MouseButtons(Qt::ExtraButton2) << Qt::MouseButtons();
944 QTest::newRow("no pointer/back") << false << Qt::MouseButtons(Qt::BackButton) << Qt::MouseButtons();
945 QTest::newRow("no pointer/forward") << false << Qt::MouseButtons(Qt::ForwardButton) << Qt::MouseButtons();
946 QTest::newRow("no pointer/task") << false << Qt::MouseButtons(Qt::TaskButton) << Qt::MouseButtons();
947
948 QTest::newRow("all") << true
949 << Qt::MouseButtons(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton | Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::BackButton | Qt::ForwardButton | Qt::TaskButton)
950 << Qt::MouseButtons(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton | Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::BackButton | Qt::ForwardButton | Qt::TaskButton);
951}
952
953void TestLibinputDevice::testSupportedButtons()
954{
955 libinput_device device;
956 QFETCH(bool, isPointer);
957 device.pointer = isPointer;
958 QFETCH(Qt::MouseButtons, setButtons);
959 device.supportedButtons = setButtons;
960
961 Device d(&device);
962 QCOMPARE(d.isPointer(), isPointer);
963 QTEST(d.supportedButtons(), "expectedButtons");
964 QTEST(Qt::MouseButtons(dbusProperty<int>(d.sysName(), "supportedButtons")), "expectedButtons");
965}
966
967void TestLibinputDevice::testAlphaNumericKeyboard_data()
968{
969 QTest::addColumn<QList<quint32>>("supportedKeys");
970 QTest::addColumn<bool>("isAlpha");
971
972 QList<quint32> keys;
973
974 for (int i = KEY_1; i <= KEY_0; i++) {
975 keys << i;
976 QByteArray row = QByteArrayLiteral("number");
977 row.append(QByteArray::number(i));
978 QTest::newRow(row.constData()) << keys << false;
979 }
980 for (int i = KEY_Q; i <= KEY_P; i++) {
981 keys << i;
982 QByteArray row = QByteArrayLiteral("alpha");
983 row.append(QByteArray::number(i));
984 QTest::newRow(row.constData()) << keys << false;
985 }
986 for (int i = KEY_A; i <= KEY_L; i++) {
987 keys << i;
988 QByteArray row = QByteArrayLiteral("alpha");
989 row.append(QByteArray::number(i));
990 QTest::newRow(row.constData()) << keys << false;
991 }
992 for (int i = KEY_Z; i < KEY_M; i++) {
993 keys << i;
994 QByteArray row = QByteArrayLiteral("alpha");
995 row.append(QByteArray::number(i));
996 QTest::newRow(row.constData()) << keys << false;
997 }
998 // adding a different key should not result in it becoming alphanumeric keyboard
999 keys << KEY_SEMICOLON;
1000 QTest::newRow("semicolon") << keys << false;
1001
1002 // last but not least the M which should turn everything on
1003 keys << KEY_M;
1004 QTest::newRow("alphanumeric") << keys << true;
1005}
1006
1007void TestLibinputDevice::testAlphaNumericKeyboard()
1008{
1009 QFETCH(QList<quint32>, supportedKeys);
1010 libinput_device device;
1011 device.keyboard = true;
1012 device.keys = supportedKeys;
1013
1014 Device d(&device);
1015 QCOMPARE(d.isKeyboard(), true);
1016 QTEST(d.isAlphaNumericKeyboard(), "isAlpha");
1017 QTEST(dbusProperty<bool>(d.sysName(), "alphaNumericKeyboard"), "isAlpha");
1018}
1019
1020void TestLibinputDevice::testEnabled_data()
1021{
1022 QTest::addColumn<bool>("supported");
1023 QTest::addColumn<bool>("setShouldFail");
1024 QTest::addColumn<bool>("initValue");
1025 QTest::addColumn<bool>("setValue");
1026 QTest::addColumn<bool>("expectedValue");
1027
1028 QTest::newRow("unsupported/true") << false << false << true << false << true;
1029 QTest::newRow("unsupported/false") << false << false << false << true << true;
1030 QTest::newRow("true -> false") << true << false << true << false << false;
1031 QTest::newRow("false -> true") << true << false << false << true << true;
1032 QTest::newRow("set fails") << true << true << true << false << true;
1033 QTest::newRow("true -> true") << true << false << true << true << true;
1034 QTest::newRow("false -> false") << true << false << false << false << false;
1035}
1036
1037void TestLibinputDevice::testEnabled()
1038{
1039 libinput_device device;
1040 QFETCH(bool, supported);
1041 QFETCH(bool, setShouldFail);
1042 QFETCH(bool, initValue);
1043 device.supportsDisableEvents = supported;
1044 device.enabled = initValue;
1045 device.setEnableModeReturnValue = setShouldFail;
1046
1047 Device d(&device);
1048 QCOMPARE(d.isEnabled(), !supported || initValue);
1049 QCOMPARE(d.property("enabled").toBool(), !supported || initValue);
1050 QCOMPARE(dbusProperty<bool>(d.sysName(), "enabled"), !supported || initValue);
1051
1052 QSignalSpy enabledChangedSpy(&d, &Device::enabledChanged);
1053 QFETCH(bool, setValue);
1054 d.setEnabled(setValue);
1055 QFETCH(bool, expectedValue);
1056 QCOMPARE(d.isEnabled(), expectedValue);
1057
1058 QCOMPARE(dbusProperty<bool>(d.sysName(), "enabled"), expectedValue);
1059}
1060
1061void TestLibinputDevice::testTapToClick_data()
1062{
1063 QTest::addColumn<int>("fingerCount");
1064 QTest::addColumn<bool>("initValue");
1065 QTest::addColumn<bool>("setValue");
1066 QTest::addColumn<bool>("setShouldFail");
1067 QTest::addColumn<bool>("expectedValue");
1068
1069 QTest::newRow("unsupported") << 0 << false << true << true << false;
1070 QTest::newRow("true -> false") << 1 << true << false << false << false;
1071 QTest::newRow("false -> true") << 2 << false << true << false << true;
1072 QTest::newRow("set fails") << 3 << true << false << true << true;
1073 QTest::newRow("true -> true") << 2 << true << true << false << true;
1074 QTest::newRow("false -> false") << 1 << false << false << false << false;
1075}
1076
1077void TestLibinputDevice::testTapToClick()
1078{
1079 libinput_device device;
1080 QFETCH(int, fingerCount);
1081 QFETCH(bool, initValue);
1082 QFETCH(bool, setShouldFail);
1083 device.tapFingerCount = fingerCount;
1084 device.tapToClick = initValue;
1085 device.setTapToClickReturnValue = setShouldFail;
1086
1087 Device d(&device);
1088 QCOMPARE(d.tapFingerCount(), fingerCount);
1089 QCOMPARE(d.isTapToClick(), initValue);
1090 QCOMPARE(d.property("tapToClick").toBool(), initValue);
1091 QCOMPARE(dbusProperty<bool>(d.sysName(), "tapToClick"), initValue);
1092
1093 QSignalSpy tapToClickChangedSpy(&d, &Device::tapToClickChanged);
1094 QFETCH(bool, setValue);
1095 d.setTapToClick(setValue);
1096 QFETCH(bool, expectedValue);
1097 QCOMPARE(d.isTapToClick(), expectedValue);
1098 QCOMPARE(tapToClickChangedSpy.isEmpty(), initValue == expectedValue);
1099 QCOMPARE(dbusProperty<bool>(d.sysName(), "tapToClick"), expectedValue);
1100}
1101
1102void TestLibinputDevice::testTapAndDragEnabledByDefault_data()
1103{
1104 QTest::addColumn<bool>("enabled");
1105
1106 QTest::newRow("enabled") << true;
1107 QTest::newRow("disabled") << false;
1108}
1109
1110void TestLibinputDevice::testTapAndDragEnabledByDefault()
1111{
1112 QFETCH(bool, enabled);
1113 libinput_device device;
1114 device.tapAndDragEnabledByDefault = enabled;
1115
1116 Device d(&device);
1117 QCOMPARE(d.tapAndDragEnabledByDefault(), true);
1118 QCOMPARE(d.property("tapAndDragEnabledByDefault").toBool(), true);
1119 QCOMPARE(dbusProperty<bool>(d.sysName(), "tapAndDragEnabledByDefault"), true);
1120}
1121
1122void TestLibinputDevice::testTapAndDrag_data()
1123{
1124 QTest::addColumn<bool>("initValue");
1125 QTest::addColumn<bool>("setValue");
1126 QTest::addColumn<bool>("setShouldFail");
1127 QTest::addColumn<bool>("expectedValue");
1128
1129 QTest::newRow("true -> false") << true << false << false << false;
1130 QTest::newRow("false -> true") << false << true << false << true;
1131 QTest::newRow("set fails") << true << false << true << true;
1132 QTest::newRow("true -> true") << true << true << false << true;
1133 QTest::newRow("false -> false") << false << false << false << false;
1134}
1135
1136void TestLibinputDevice::testTapAndDrag()
1137{
1138 libinput_device device;
1139 QFETCH(bool, initValue);
1140 QFETCH(bool, setShouldFail);
1141 device.tapAndDrag = initValue;
1142 device.setTapAndDragReturnValue = setShouldFail;
1143
1144 Device d(&device);
1145 QCOMPARE(d.isTapAndDrag(), initValue);
1146 QCOMPARE(d.property("tapAndDrag").toBool(), initValue);
1147 QCOMPARE(dbusProperty<bool>(d.sysName(), "tapAndDrag"), initValue);
1148
1149 QSignalSpy tapAndDragChangedSpy(&d, &Device::tapAndDragChanged);
1150 QFETCH(bool, setValue);
1151 d.setTapAndDrag(setValue);
1152 QFETCH(bool, expectedValue);
1153 QCOMPARE(d.isTapAndDrag(), expectedValue);
1154 QCOMPARE(tapAndDragChangedSpy.isEmpty(), initValue == expectedValue);
1155 QCOMPARE(dbusProperty<bool>(d.sysName(), "tapAndDrag"), expectedValue);
1156}
1157
1158void TestLibinputDevice::testTapDragLockEnabledByDefault_data()
1159{
1160 QTest::addColumn<bool>("enabled");
1161
1162 QTest::newRow("enabled") << true;
1163 QTest::newRow("disabled") << false;
1164}
1165
1166void TestLibinputDevice::testTapDragLockEnabledByDefault()
1167{
1168 QFETCH(bool, enabled);
1169 libinput_device device;
1170 device.tapDragLockEnabledByDefault = enabled;
1171
1172 Device d(&device);
1173 QCOMPARE(d.tapDragLockEnabledByDefault(), enabled);
1174 QCOMPARE(d.property("tapDragLockEnabledByDefault").toBool(), enabled);
1175 QCOMPARE(dbusProperty<bool>(d.sysName(), "tapDragLockEnabledByDefault"), enabled);
1176}
1177
1178void TestLibinputDevice::testTapDragLock_data()
1179{
1180 QTest::addColumn<bool>("initValue");
1181 QTest::addColumn<bool>("setValue");
1182 QTest::addColumn<bool>("setShouldFail");
1183 QTest::addColumn<bool>("expectedValue");
1184
1185 QTest::newRow("true -> false") << true << false << false << false;
1186 QTest::newRow("false -> true") << false << true << false << true;
1187 QTest::newRow("set fails") << true << false << true << true;
1188 QTest::newRow("true -> true") << true << true << false << true;
1189 QTest::newRow("false -> false") << false << false << false << false;
1190}
1191
1192void TestLibinputDevice::testTapDragLock()
1193{
1194 libinput_device device;
1195 QFETCH(bool, initValue);
1196 QFETCH(bool, setShouldFail);
1197 device.tapDragLock = initValue;
1198 device.setTapDragLockReturnValue = setShouldFail;
1199
1200 Device d(&device);
1201 QCOMPARE(d.isTapDragLock(), initValue);
1202 QCOMPARE(d.property("tapDragLock").toBool(), initValue);
1203 QCOMPARE(dbusProperty<bool>(d.sysName(), "tapDragLock"), initValue);
1204
1205 QSignalSpy tapDragLockChangedSpy(&d, &Device::tapDragLockChanged);
1206 QFETCH(bool, setValue);
1207 d.setTapDragLock(setValue);
1208 QFETCH(bool, expectedValue);
1209 QCOMPARE(d.isTapDragLock(), expectedValue);
1210 QCOMPARE(tapDragLockChangedSpy.isEmpty(), initValue == expectedValue);
1211 QCOMPARE(dbusProperty<bool>(d.sysName(), "tapDragLock"), expectedValue);
1212}
1213
1214void TestLibinputDevice::testMiddleEmulation_data()
1215{
1216 QTest::addColumn<bool>("initValue");
1217 QTest::addColumn<bool>("setValue");
1218 QTest::addColumn<bool>("setShouldFail");
1219 QTest::addColumn<bool>("expectedValue");
1220 QTest::addColumn<bool>("supportsMiddleButton");
1221
1222 QTest::newRow("true -> false") << true << false << false << false << true;
1223 QTest::newRow("false -> true") << false << true << false << true << true;
1224 QTest::newRow("set fails") << true << false << true << true << true;
1225 QTest::newRow("true -> true") << true << true << false << true << true;
1226 QTest::newRow("false -> false") << false << false << false << false << true;
1227
1228 QTest::newRow("false -> true, unsupported") << false << true << true << false << false;
1229}
1230
1231void TestLibinputDevice::testMiddleEmulation()
1232{
1233 libinput_device device;
1234 QFETCH(bool, initValue);
1235 QFETCH(bool, setShouldFail);
1236 QFETCH(bool, supportsMiddleButton);
1237 device.supportsMiddleEmulation = supportsMiddleButton;
1238 device.middleEmulation = initValue;
1239 device.setMiddleEmulationReturnValue = setShouldFail;
1240
1241 Device d(&device);
1242 QCOMPARE(d.isMiddleEmulation(), initValue);
1243 QCOMPARE(d.property("middleEmulation").toBool(), initValue);
1244 QCOMPARE(dbusProperty<bool>(d.sysName(), "middleEmulation"), initValue);
1245
1246 QSignalSpy middleEmulationChangedSpy(&d, &Device::middleEmulationChanged);
1247 QFETCH(bool, setValue);
1248 d.setMiddleEmulation(setValue);
1249 QFETCH(bool, expectedValue);
1250 QCOMPARE(d.isMiddleEmulation(), expectedValue);
1251 QCOMPARE(d.property("middleEmulation").toBool(), expectedValue);
1252 QCOMPARE(middleEmulationChangedSpy.isEmpty(), initValue == expectedValue);
1253 QCOMPARE(dbusProperty<bool>(d.sysName(), "middleEmulation"), expectedValue);
1254}
1255
1256void TestLibinputDevice::testNaturalScroll_data()
1257{
1258 QTest::addColumn<bool>("initValue");
1259 QTest::addColumn<bool>("setValue");
1260 QTest::addColumn<bool>("setShouldFail");
1261 QTest::addColumn<bool>("expectedValue");
1262 QTest::addColumn<bool>("supportsNaturalScroll");
1263
1264 QTest::newRow("true -> false") << true << false << false << false << true;
1265 QTest::newRow("false -> true") << false << true << false << true << true;
1266 QTest::newRow("set fails") << true << false << true << true << true;
1267 QTest::newRow("true -> true") << true << true << false << true << true;
1268 QTest::newRow("false -> false") << false << false << false << false << true;
1269
1270 QTest::newRow("false -> true, unsupported") << false << true << true << false << false;
1271}
1272
1273void TestLibinputDevice::testNaturalScroll()
1274{
1275 libinput_device device;
1276 QFETCH(bool, initValue);
1277 QFETCH(bool, setShouldFail);
1278 QFETCH(bool, supportsNaturalScroll);
1279 device.supportsNaturalScroll = supportsNaturalScroll;
1280 device.naturalScroll = initValue;
1281 device.setNaturalScrollReturnValue = setShouldFail;
1282
1283 Device d(&device);
1284 QCOMPARE(d.isNaturalScroll(), initValue);
1285 QCOMPARE(d.property("naturalScroll").toBool(), initValue);
1286 QCOMPARE(dbusProperty<bool>(d.sysName(), "naturalScroll"), initValue);
1287
1288 QSignalSpy naturalScrollChangedSpy(&d, &Device::naturalScrollChanged);
1289 QFETCH(bool, setValue);
1290 d.setNaturalScroll(setValue);
1291 QFETCH(bool, expectedValue);
1292 QCOMPARE(d.isNaturalScroll(), expectedValue);
1293 QCOMPARE(d.property("naturalScroll").toBool(), expectedValue);
1294 QCOMPARE(naturalScrollChangedSpy.isEmpty(), initValue == expectedValue);
1295 QCOMPARE(dbusProperty<bool>(d.sysName(), "naturalScroll"), expectedValue);
1296}
1297
1298void TestLibinputDevice::testScrollFactor()
1299{
1300 libinput_device device;
1301
1302 qreal initValue = 1.0;
1303
1304 Device d(&device);
1305 QCOMPARE(d.scrollFactor(), initValue);
1306 QCOMPARE(d.property("scrollFactor").toReal(), initValue);
1307 QCOMPARE(dbusProperty<qreal>(d.sysName(), "scrollFactor"), initValue);
1308
1309 QSignalSpy scrollFactorChangedSpy(&d, &Device::scrollFactorChanged);
1310
1311 qreal expectedValue = 2.0;
1312
1313 d.setScrollFactor(expectedValue);
1314 QCOMPARE(d.scrollFactor(), expectedValue);
1315 QCOMPARE(d.property("scrollFactor").toReal(), expectedValue);
1316 QCOMPARE(scrollFactorChangedSpy.isEmpty(), false);
1317 QCOMPARE(dbusProperty<qreal>(d.sysName(), "scrollFactor"), expectedValue);
1318}
1319
1320void TestLibinputDevice::testScrollTwoFinger_data()
1321{
1322 QTest::addColumn<bool>("initValue");
1323 QTest::addColumn<bool>("otherValue");
1324 QTest::addColumn<bool>("setValue");
1325 QTest::addColumn<bool>("setShouldFail");
1326 QTest::addColumn<bool>("expectedValue");
1327 QTest::addColumn<bool>("supportsScrollTwoFinger");
1328
1329 QTest::newRow("true -> false") << true << false << false << false << false << true;
1330 QTest::newRow("other -> false") << false << true << false << false << false << true;
1331 QTest::newRow("false -> true") << false << false << true << false << true << true;
1332 QTest::newRow("set fails") << true << false << false << true << true << true;
1333 QTest::newRow("true -> true") << true << false << true << false << true << true;
1334 QTest::newRow("false -> false") << false << false << false << false << false << true;
1335
1336 QTest::newRow("false -> true, unsupported") << false << false << true << true << false << false;
1337}
1338
1339void TestLibinputDevice::testScrollTwoFinger()
1340{
1341 libinput_device device;
1342 QFETCH(bool, initValue);
1343 QFETCH(bool, otherValue);
1344 QFETCH(bool, setShouldFail);
1345 QFETCH(bool, supportsScrollTwoFinger);
1346 device.supportedScrollMethods = (supportsScrollTwoFinger ? LIBINPUT_CONFIG_SCROLL_2FG : LIBINPUT_CONFIG_SCROLL_NO_SCROLL) | LIBINPUT_CONFIG_SCROLL_EDGE;
1347 device.scrollMethod = initValue ? LIBINPUT_CONFIG_SCROLL_2FG : otherValue ? LIBINPUT_CONFIG_SCROLL_EDGE
1348 : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
1349 device.setScrollMethodReturnValue = setShouldFail;
1350
1351 Device d(&device);
1352 QCOMPARE(d.isScrollTwoFinger(), initValue);
1353 QCOMPARE(d.property("scrollTwoFinger").toBool(), initValue);
1354 QCOMPARE(d.property("scrollEdge").toBool(), otherValue);
1355 QCOMPARE(dbusProperty<bool>(d.sysName(), "scrollTwoFinger"), initValue);
1356 QCOMPARE(dbusProperty<bool>(d.sysName(), "scrollEdge"), otherValue);
1357
1358 QSignalSpy scrollMethodChangedSpy(&d, &Device::scrollMethodChanged);
1359 QFETCH(bool, setValue);
1360 d.setScrollTwoFinger(setValue);
1361 QFETCH(bool, expectedValue);
1362 QCOMPARE(d.isScrollTwoFinger(), expectedValue);
1363 QCOMPARE(d.property("scrollTwoFinger").toBool(), expectedValue);
1364 QCOMPARE(scrollMethodChangedSpy.isEmpty(), initValue == expectedValue);
1365 QCOMPARE(dbusProperty<bool>(d.sysName(), "scrollTwoFinger"), expectedValue);
1366}
1367
1368void TestLibinputDevice::testScrollEdge_data()
1369{
1370 QTest::addColumn<bool>("initValue");
1371 QTest::addColumn<bool>("otherValue");
1372 QTest::addColumn<bool>("setValue");
1373 QTest::addColumn<bool>("setShouldFail");
1374 QTest::addColumn<bool>("expectedValue");
1375 QTest::addColumn<bool>("supportsScrollEdge");
1376
1377 QTest::newRow("true -> false") << true << false << false << false << false << true;
1378 QTest::newRow("other -> false") << false << true << false << false << false << true;
1379 QTest::newRow("false -> true") << false << false << true << false << true << true;
1380 QTest::newRow("set fails") << true << false << false << true << true << true;
1381 QTest::newRow("true -> true") << true << false << true << false << true << true;
1382 QTest::newRow("false -> false") << false << false << false << false << false << true;
1383
1384 QTest::newRow("false -> true, unsupported") << false << false << true << true << false << false;
1385}
1386
1387void TestLibinputDevice::testScrollEdge()
1388{
1389 libinput_device device;
1390 QFETCH(bool, initValue);
1391 QFETCH(bool, otherValue);
1392 QFETCH(bool, setShouldFail);
1393 QFETCH(bool, supportsScrollEdge);
1394 device.supportedScrollMethods = (supportsScrollEdge ? LIBINPUT_CONFIG_SCROLL_EDGE : LIBINPUT_CONFIG_SCROLL_NO_SCROLL) | LIBINPUT_CONFIG_SCROLL_2FG;
1395 device.scrollMethod = initValue ? LIBINPUT_CONFIG_SCROLL_EDGE : otherValue ? LIBINPUT_CONFIG_SCROLL_2FG
1396 : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
1397 device.setScrollMethodReturnValue = setShouldFail;
1398
1399 Device d(&device);
1400 QCOMPARE(d.isScrollEdge(), initValue);
1401 QCOMPARE(d.property("scrollEdge").toBool(), initValue);
1402 QCOMPARE(d.property("scrollTwoFinger").toBool(), otherValue);
1403 QCOMPARE(dbusProperty<bool>(d.sysName(), "scrollEdge"), initValue);
1404 QCOMPARE(dbusProperty<bool>(d.sysName(), "scrollTwoFinger"), otherValue);
1405
1406 QSignalSpy scrollMethodChangedSpy(&d, &Device::scrollMethodChanged);
1407 QFETCH(bool, setValue);
1408 d.setScrollEdge(setValue);
1409 QFETCH(bool, expectedValue);
1410 QCOMPARE(d.isScrollEdge(), expectedValue);
1411 QCOMPARE(d.property("scrollEdge").toBool(), expectedValue);
1412 QCOMPARE(scrollMethodChangedSpy.isEmpty(), initValue == expectedValue);
1413 QCOMPARE(dbusProperty<bool>(d.sysName(), "scrollEdge"), expectedValue);
1414}
1415
1416void TestLibinputDevice::testScrollButtonDown_data()
1417{
1418 QTest::addColumn<bool>("initValue");
1419 QTest::addColumn<bool>("otherValue");
1420 QTest::addColumn<bool>("setValue");
1421 QTest::addColumn<bool>("setShouldFail");
1422 QTest::addColumn<bool>("expectedValue");
1423 QTest::addColumn<bool>("supportsScrollButtonDown");
1424
1425 QTest::newRow("true -> false") << true << false << false << false << false << true;
1426 QTest::newRow("other -> false") << false << true << false << false << false << true;
1427 QTest::newRow("false -> true") << false << false << true << false << true << true;
1428 QTest::newRow("set fails") << true << false << false << true << true << true;
1429 QTest::newRow("true -> true") << true << false << true << false << true << true;
1430 QTest::newRow("false -> false") << false << false << false << false << false << true;
1431
1432 QTest::newRow("false -> true, unsupported") << false << false << true << true << false << false;
1433}
1434
1435void TestLibinputDevice::testScrollButtonDown()
1436{
1437 libinput_device device;
1438 QFETCH(bool, initValue);
1439 QFETCH(bool, otherValue);
1440 QFETCH(bool, setShouldFail);
1441 QFETCH(bool, supportsScrollButtonDown);
1442 device.supportedScrollMethods = (supportsScrollButtonDown ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : LIBINPUT_CONFIG_SCROLL_NO_SCROLL) | LIBINPUT_CONFIG_SCROLL_2FG;
1443 device.scrollMethod = initValue ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : otherValue ? LIBINPUT_CONFIG_SCROLL_2FG
1444 : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
1445 device.setScrollMethodReturnValue = setShouldFail;
1446
1447 Device d(&device);
1448 QCOMPARE(d.isScrollOnButtonDown(), initValue);
1449 QCOMPARE(d.property("scrollOnButtonDown").toBool(), initValue);
1450 QCOMPARE(d.property("scrollTwoFinger").toBool(), otherValue);
1451 QCOMPARE(dbusProperty<bool>(d.sysName(), "scrollOnButtonDown"), initValue);
1452 QCOMPARE(dbusProperty<bool>(d.sysName(), "scrollTwoFinger"), otherValue);
1453
1454 QSignalSpy scrollMethodChangedSpy(&d, &Device::scrollMethodChanged);
1455 QFETCH(bool, setValue);
1456 d.setScrollOnButtonDown(setValue);
1457 QFETCH(bool, expectedValue);
1458 QCOMPARE(d.isScrollOnButtonDown(), expectedValue);
1459 QCOMPARE(d.property("scrollOnButtonDown").toBool(), expectedValue);
1460 QCOMPARE(scrollMethodChangedSpy.isEmpty(), initValue == expectedValue);
1461 QCOMPARE(dbusProperty<bool>(d.sysName(), "scrollOnButtonDown"), expectedValue);
1462}
1463
1464void TestLibinputDevice::testScrollButton_data()
1465{
1466 QTest::addColumn<quint32>("initValue");
1467 QTest::addColumn<quint32>("setValue");
1468 QTest::addColumn<quint32>("expectedValue");
1469 QTest::addColumn<bool>("setShouldFail");
1470 QTest::addColumn<bool>("scrollOnButton");
1471
1472 QTest::newRow("BTN_LEFT -> BTN_RIGHT") << quint32(BTN_LEFT) << quint32(BTN_RIGHT) << quint32(BTN_RIGHT) << false << true;
1473 QTest::newRow("BTN_LEFT -> BTN_LEFT") << quint32(BTN_LEFT) << quint32(BTN_LEFT) << quint32(BTN_LEFT) << false << true;
1474 QTest::newRow("set should fail") << quint32(BTN_LEFT) << quint32(BTN_RIGHT) << quint32(BTN_LEFT) << true << true;
1475 QTest::newRow("not scroll on button") << quint32(BTN_LEFT) << quint32(BTN_RIGHT) << quint32(BTN_LEFT) << false << false;
1476}
1477
1478void TestLibinputDevice::testScrollButton()
1479{
1480 libinput_device device;
1481 QFETCH(quint32, initValue);
1482 QFETCH(bool, setShouldFail);
1483 QFETCH(bool, scrollOnButton);
1484 device.scrollButton = initValue;
1485 device.supportedScrollMethods = scrollOnButton ? LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN : LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
1486 device.setScrollButtonReturnValue = setShouldFail;
1487
1488 Device d(&device);
1489 QCOMPARE(d.scrollButton(), initValue);
1490 QCOMPARE(d.property("scrollButton").value<quint32>(), initValue);
1491 QCOMPARE(dbusProperty<quint32>(d.sysName(), "scrollButton"), initValue);
1492
1493 QSignalSpy scrollButtonChangedSpy(&d, &Device::scrollButtonChanged);
1494 QFETCH(quint32, setValue);
1495 d.setScrollButton(setValue);
1496 QFETCH(quint32, expectedValue);
1497 QCOMPARE(d.scrollButton(), expectedValue);
1498 QCOMPARE(d.property("scrollButton").value<quint32>(), expectedValue);
1499 QCOMPARE(scrollButtonChangedSpy.isEmpty(), initValue == expectedValue);
1500 QCOMPARE(dbusProperty<quint32>(d.sysName(), "scrollButton"), expectedValue);
1501}
1502
1503void TestLibinputDevice::testDisableWhileTypingEnabledByDefault_data()
1504{
1505 QTest::addColumn<bool>("enabled");
1506
1507 QTest::newRow("enabled") << true;
1508 QTest::newRow("disabled") << false;
1509}
1510
1511void TestLibinputDevice::testDisableWhileTypingEnabledByDefault()
1512{
1513 QFETCH(bool, enabled);
1514 libinput_device device;
1515 device.disableWhileTypingEnabledByDefault = enabled ? LIBINPUT_CONFIG_DWT_ENABLED : LIBINPUT_CONFIG_DWT_DISABLED;
1516
1517 Device d(&device);
1518 QCOMPARE(d.disableWhileTypingEnabledByDefault(), enabled);
1519 QCOMPARE(d.property("disableWhileTypingEnabledByDefault").toBool(), enabled);
1520 QCOMPARE(dbusProperty<bool>(d.sysName(), "disableWhileTypingEnabledByDefault"), enabled);
1521}
1522
1523void TestLibinputDevice::testLmrTapButtonMapEnabledByDefault_data()
1524{
1525 QTest::addColumn<bool>("enabled");
1526
1527 QTest::newRow("enabled") << true;
1528 QTest::newRow("disabled") << false;
1529}
1530
1531void TestLibinputDevice::testLmrTapButtonMapEnabledByDefault()
1532{
1533 QFETCH(bool, enabled);
1534 libinput_device device;
1535 device.defaultTapButtonMap = enabled ? LIBINPUT_CONFIG_TAP_MAP_LMR : LIBINPUT_CONFIG_TAP_MAP_LRM;
1536
1537 Device d(&device);
1538 QCOMPARE(d.lmrTapButtonMapEnabledByDefault(), enabled);
1539 QCOMPARE(d.property("lmrTapButtonMapEnabledByDefault").toBool(), enabled);
1540 QCOMPARE(dbusProperty<bool>(d.sysName(), "lmrTapButtonMapEnabledByDefault"), enabled);
1541}
1542
1543void TestLibinputDevice::testLmrTapButtonMap_data()
1544{
1545 QTest::addColumn<bool>("initValue");
1546 QTest::addColumn<bool>("setValue");
1547 QTest::addColumn<bool>("setShouldFail");
1548 QTest::addColumn<bool>("expectedValue");
1549 QTest::addColumn<int>("fingerCount");
1550
1551 QTest::newRow("true -> false") << true << false << false << false << 3;
1552 QTest::newRow("false -> true") << false << true << false << true << 3;
1553 QTest::newRow("true -> false") << true << false << false << false << 2;
1554 QTest::newRow("false -> true") << false << true << false << true << 2;
1555
1556 QTest::newRow("set fails") << true << false << true << true << 3;
1557
1558 QTest::newRow("true -> true") << true << true << false << true << 3;
1559 QTest::newRow("false -> false") << false << false << false << false << 3;
1560 QTest::newRow("true -> true") << true << true << false << true << 2;
1561 QTest::newRow("false -> false") << false << false << false << false << 2;
1562
1563 QTest::newRow("false -> true, fingerCount 0") << false << true << true << false << 0;
1564
1565 // TODO: is this a fail in libinput?
1566 // QTest::newRow("false -> true, fingerCount 1") << false << true << true << false << 1;
1567}
1568
1569void TestLibinputDevice::testLmrTapButtonMap()
1570{
1571 libinput_device device;
1572 QFETCH(bool, initValue);
1573 QFETCH(bool, setShouldFail);
1574 QFETCH(int, fingerCount);
1575 device.tapFingerCount = fingerCount;
1576 device.tapButtonMap = initValue ? LIBINPUT_CONFIG_TAP_MAP_LMR : LIBINPUT_CONFIG_TAP_MAP_LRM;
1577 device.setTapButtonMapReturnValue = setShouldFail;
1578
1579 Device d(&device);
1580 QCOMPARE(d.lmrTapButtonMap(), initValue);
1581 QCOMPARE(d.property("lmrTapButtonMap").toBool(), initValue);
1582
1583 QSignalSpy tapButtonMapChangedSpy(&d, &Device::tapButtonMapChanged);
1584 QFETCH(bool, setValue);
1585 d.setLmrTapButtonMap(setValue);
1586 QFETCH(bool, expectedValue);
1587 QCOMPARE(d.lmrTapButtonMap(), expectedValue);
1588 QCOMPARE(d.property("lmrTapButtonMap").toBool(), expectedValue);
1589 QCOMPARE(tapButtonMapChangedSpy.isEmpty(), initValue == expectedValue);
1590}
1591
1592void TestLibinputDevice::testDisableWhileTyping_data()
1593{
1594 QTest::addColumn<bool>("initValue");
1595 QTest::addColumn<bool>("setValue");
1596 QTest::addColumn<bool>("setShouldFail");
1597 QTest::addColumn<bool>("expectedValue");
1598 QTest::addColumn<bool>("supportsDisableWhileTyping");
1599
1600 QTest::newRow("true -> false") << true << false << false << false << true;
1601 QTest::newRow("false -> true") << false << true << false << true << true;
1602 QTest::newRow("set fails") << true << false << true << true << true;
1603 QTest::newRow("true -> true") << true << true << false << true << true;
1604 QTest::newRow("false -> false") << false << false << false << false << true;
1605
1606 QTest::newRow("false -> true, unsupported") << false << true << true << false << false;
1607}
1608
1609void TestLibinputDevice::testDisableWhileTyping()
1610{
1611 libinput_device device;
1612 QFETCH(bool, initValue);
1613 QFETCH(bool, setShouldFail);
1614 QFETCH(bool, supportsDisableWhileTyping);
1615 device.supportsDisableWhileTyping = supportsDisableWhileTyping;
1616 device.disableWhileTyping = initValue ? LIBINPUT_CONFIG_DWT_ENABLED : LIBINPUT_CONFIG_DWT_DISABLED;
1617 device.setDisableWhileTypingReturnValue = setShouldFail;
1618
1619 Device d(&device);
1620 QCOMPARE(d.isDisableWhileTyping(), initValue);
1621 QCOMPARE(d.property("disableWhileTyping").toBool(), initValue);
1622 QCOMPARE(dbusProperty<bool>(d.sysName(), "disableWhileTyping"), initValue);
1623
1624 QSignalSpy disableWhileTypingChangedSpy(&d, &Device::disableWhileTypingChanged);
1625 QFETCH(bool, setValue);
1626 d.setDisableWhileTyping(setValue);
1627 QFETCH(bool, expectedValue);
1628 QCOMPARE(d.isDisableWhileTyping(), expectedValue);
1629 QCOMPARE(d.property("disableWhileTyping").toBool(), expectedValue);
1630 QCOMPARE(disableWhileTypingChangedSpy.isEmpty(), initValue == expectedValue);
1631 QCOMPARE(dbusProperty<bool>(d.sysName(), "disableWhileTyping"), expectedValue);
1632}
1633
1634void TestLibinputDevice::testLoadEnabled_data()
1635{
1636 QTest::addColumn<bool>("initValue");
1637 QTest::addColumn<bool>("configValue");
1638
1639 QTest::newRow("false -> true") << false << true;
1640 QTest::newRow("true -> false") << true << false;
1641 QTest::newRow("true -> true") << true << true;
1642 QTest::newRow("false -> false") << false << false;
1643}
1644
1645void TestLibinputDevice::testLoadEnabled()
1646{
1647 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
1648 KConfigGroup inputConfig(config, QStringLiteral("Test"));
1649 QFETCH(bool, configValue);
1650 QFETCH(bool, initValue);
1651 inputConfig.writeEntry("Enabled", configValue);
1652
1653 libinput_device device;
1654 device.supportsDisableEvents = true;
1655 device.enabled = initValue;
1656 device.setEnableModeReturnValue = false;
1657
1658 Device d(&device);
1659 QCOMPARE(d.isEnabled(), initValue);
1660 // no config group set, should not change
1661 d.loadConfiguration();
1662 QCOMPARE(d.isEnabled(), initValue);
1663
1664 // set the group
1665 d.setConfig(inputConfig);
1666 d.loadConfiguration();
1667 QCOMPARE(d.isEnabled(), configValue);
1668
1669 // and try to store
1670 if (configValue != initValue) {
1671 d.setEnabled(initValue);
1672 QCOMPARE(inputConfig.readEntry("Enabled", configValue), initValue);
1673 }
1674}
1675
1676void TestLibinputDevice::testLoadPointerAcceleration_data()
1677{
1678 QTest::addColumn<qreal>("initValue");
1679 QTest::addColumn<qreal>("configValue");
1680
1681 QTest::newRow("-0.2 -> 0.9") << -0.2 << 0.9;
1682 QTest::newRow("0.0 -> -1.0") << 0.0 << -1.0;
1683 QTest::newRow("0.123 -> -0.456") << 0.123 << -0.456;
1684 QTest::newRow("0.7 -> 0.7") << 0.7 << 0.7;
1685}
1686
1687void TestLibinputDevice::testLoadPointerAcceleration()
1688{
1689 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
1690 KConfigGroup inputConfig(config, QStringLiteral("Test"));
1691 QFETCH(qreal, configValue);
1692 QFETCH(qreal, initValue);
1693 inputConfig.writeEntry("PointerAcceleration", configValue);
1694
1695 libinput_device device;
1696 device.supportsPointerAcceleration = true;
1697 device.pointerAcceleration = initValue;
1698 device.setPointerAccelerationReturnValue = false;
1699
1700 Device d(&device);
1701 QCOMPARE(d.pointerAcceleration(), initValue);
1702 QCOMPARE(d.property("pointerAcceleration").toReal(), initValue);
1703 // no config group set, should not change
1704 d.loadConfiguration();
1705 QCOMPARE(d.pointerAcceleration(), initValue);
1706 QCOMPARE(d.property("pointerAcceleration").toReal(), initValue);
1707
1708 // set the group
1709 d.setConfig(inputConfig);
1710 d.loadConfiguration();
1711 QCOMPARE(d.pointerAcceleration(), configValue);
1712 QCOMPARE(d.property("pointerAcceleration").toReal(), configValue);
1713
1714 // and try to store
1715 if (configValue != initValue) {
1716 d.setPointerAcceleration(initValue);
1717 QCOMPARE(inputConfig.readEntry("PointerAcceleration", configValue), initValue);
1718 }
1719}
1720
1721void TestLibinputDevice::testLoadPointerAccelerationProfile_data()
1722{
1723 QTest::addColumn<quint32>("initValue");
1724 QTest::addColumn<QString>("initValuePropNameString");
1725 QTest::addColumn<quint32>("configValue");
1726 QTest::addColumn<QString>("configValuePropNameString");
1727
1728 QTest::newRow("pointerAccelerationProfileFlat -> pointerAccelerationProfileAdaptive")
1729 << (quint32)LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT << "pointerAccelerationProfileFlat"
1730 << (quint32)LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE << "pointerAccelerationProfileAdaptive";
1731 QTest::newRow("pointerAccelerationProfileAdaptive -> pointerAccelerationProfileFlat")
1732 << (quint32)LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE << "pointerAccelerationProfileAdaptive"
1733 << (quint32)LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT << "pointerAccelerationProfileFlat";
1734 QTest::newRow("pointerAccelerationProfileAdaptive -> pointerAccelerationProfileAdaptive")
1735 << (quint32)LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE << "pointerAccelerationProfileAdaptive" << (quint32)LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE << "pointerAccelerationProfileAdaptive";
1736}
1737
1738void TestLibinputDevice::testLoadPointerAccelerationProfile()
1739{
1740 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
1741 KConfigGroup inputConfig(config, QStringLiteral("Test"));
1742 QFETCH(quint32, initValue);
1743 QFETCH(quint32, configValue);
1744 QFETCH(QString, initValuePropNameString);
1745 QFETCH(QString, configValuePropNameString);
1746
1747 QByteArray initValuePropName = initValuePropNameString.toLatin1();
1748 QByteArray configValuePropName = configValuePropNameString.toLatin1();
1749
1750 inputConfig.writeEntry("PointerAccelerationProfile", configValue);
1751
1752 libinput_device device;
1753 device.supportedPointerAccelerationProfiles = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT | LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
1754 device.pointerAccelerationProfile = (libinput_config_accel_profile)initValue;
1756
1757 Device d(&device);
1758 QCOMPARE(d.property(initValuePropName).toBool(), true);
1759 QCOMPARE(d.property(configValuePropName).toBool(), initValue == configValue);
1760 // no config group set, should not change
1761 d.loadConfiguration();
1762 QCOMPARE(d.property(initValuePropName).toBool(), true);
1763 QCOMPARE(d.property(configValuePropName).toBool(), initValue == configValue);
1764
1765 // set the group
1766 d.setConfig(inputConfig);
1767 d.loadConfiguration();
1768 QCOMPARE(d.property(initValuePropName).toBool(), initValue == configValue);
1769 QCOMPARE(d.property(configValuePropName).toBool(), true);
1770 QCOMPARE(dbusProperty<bool>(d.sysName(), initValuePropName), initValue == configValue);
1771 QCOMPARE(dbusProperty<bool>(d.sysName(), configValuePropName), true);
1772
1773 // and try to store
1774 if (configValue != initValue) {
1775 d.setProperty(initValuePropName, true);
1776 QCOMPARE(inputConfig.readEntry("PointerAccelerationProfile", configValue), initValue);
1777 }
1778}
1779
1780void TestLibinputDevice::testLoadClickMethod_data()
1781{
1782 QTest::addColumn<quint32>("initValue");
1783 QTest::addColumn<QString>("initValuePropNameString");
1784 QTest::addColumn<quint32>("configValue");
1785 QTest::addColumn<QString>("configValuePropNameString");
1786
1787 QTest::newRow("clickMethodAreas -> clickMethodClickfinger")
1788 << static_cast<quint32>(LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) << "clickMethodAreas"
1789 << static_cast<quint32>(LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) << "clickMethodClickfinger";
1790 QTest::newRow("clickMethodClickfinger -> clickMethodAreas")
1791 << static_cast<quint32>(LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) << "clickMethodClickfinger"
1792 << static_cast<quint32>(LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) << "clickMethodAreas";
1793 QTest::newRow("clickMethodAreas -> clickMethodAreas")
1794 << static_cast<quint32>(LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) << "clickMethodAreas"
1795 << static_cast<quint32>(LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS) << "clickMethodAreas";
1796 QTest::newRow("clickMethodClickfinger -> clickMethodClickfinger")
1797 << static_cast<quint32>(LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) << "clickMethodClickfinger"
1798 << static_cast<quint32>(LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) << "clickMethodClickfinger";
1799}
1800
1801void TestLibinputDevice::testLoadClickMethod()
1802{
1803 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
1804 KConfigGroup inputConfig(config, QStringLiteral("Test"));
1805 QFETCH(quint32, initValue);
1806 QFETCH(quint32, configValue);
1807 QFETCH(QString, initValuePropNameString);
1808 QFETCH(QString, configValuePropNameString);
1809
1810 QByteArray initValuePropName = initValuePropNameString.toLatin1();
1811 QByteArray configValuePropName = configValuePropNameString.toLatin1();
1812
1813 inputConfig.writeEntry("ClickMethod", configValue);
1814
1815 libinput_device device;
1816 device.supportedClickMethods = LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS | LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
1817 device.clickMethod = (libinput_config_click_method)initValue;
1818 device.setClickMethodReturnValue = false;
1819
1820 Device d(&device);
1821 QCOMPARE(d.property(initValuePropName).toBool(), true);
1822 QCOMPARE(d.property(configValuePropName).toBool(), initValue == configValue);
1823 // no config group set, should not change
1824 d.loadConfiguration();
1825 QCOMPARE(d.property(initValuePropName).toBool(), true);
1826 QCOMPARE(d.property(configValuePropName).toBool(), initValue == configValue);
1827
1828 // set the group
1829 d.setConfig(inputConfig);
1830 d.loadConfiguration();
1831 QCOMPARE(d.property(initValuePropName).toBool(), initValue == configValue);
1832 QCOMPARE(d.property(configValuePropName).toBool(), true);
1833 QCOMPARE(dbusProperty<bool>(d.sysName(), initValuePropName), initValue == configValue);
1834 QCOMPARE(dbusProperty<bool>(d.sysName(), configValuePropName), true);
1835
1836 // and try to store
1837 if (configValue != initValue) {
1838 d.setProperty(initValuePropName, true);
1839 QCOMPARE(inputConfig.readEntry("ClickMethod", configValue), initValue);
1840 }
1841}
1842
1843void TestLibinputDevice::testLoadTapToClick_data()
1844{
1845 QTest::addColumn<bool>("initValue");
1846 QTest::addColumn<bool>("configValue");
1847
1848 QTest::newRow("false -> true") << false << true;
1849 QTest::newRow("true -> false") << true << false;
1850 QTest::newRow("true -> true") << true << true;
1851 QTest::newRow("false -> false") << false << false;
1852}
1853
1854void TestLibinputDevice::testLoadTapToClick()
1855{
1856 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
1857 KConfigGroup inputConfig(config, QStringLiteral("Test"));
1858 QFETCH(bool, configValue);
1859 QFETCH(bool, initValue);
1860 inputConfig.writeEntry("TapToClick", configValue);
1861
1862 libinput_device device;
1863 device.tapFingerCount = 2;
1864 device.tapToClick = initValue;
1865 device.setTapToClickReturnValue = false;
1866
1867 Device d(&device);
1868 QCOMPARE(d.isTapToClick(), initValue);
1869 // no config group set, should not change
1870 d.loadConfiguration();
1871 QCOMPARE(d.isTapToClick(), initValue);
1872
1873 // set the group
1874 d.setConfig(inputConfig);
1875 d.loadConfiguration();
1876 QCOMPARE(d.isTapToClick(), configValue);
1877
1878 // and try to store
1879 if (configValue != initValue) {
1880 d.setTapToClick(initValue);
1881 QCOMPARE(inputConfig.readEntry("TapToClick", configValue), initValue);
1882 }
1883}
1884
1885void TestLibinputDevice::testLoadTapAndDrag_data()
1886{
1887 QTest::addColumn<bool>("initValue");
1888 QTest::addColumn<bool>("configValue");
1889
1890 QTest::newRow("false -> true") << false << true;
1891 QTest::newRow("true -> false") << true << false;
1892 QTest::newRow("true -> true") << true << true;
1893 QTest::newRow("false -> false") << false << false;
1894}
1895
1896void TestLibinputDevice::testLoadTapAndDrag()
1897{
1898 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
1899 KConfigGroup inputConfig(config, QStringLiteral("Test"));
1900 QFETCH(bool, configValue);
1901 QFETCH(bool, initValue);
1902 inputConfig.writeEntry("TapAndDrag", configValue);
1903
1904 libinput_device device;
1905 device.tapAndDrag = initValue;
1906 device.setTapAndDragReturnValue = false;
1907
1908 Device d(&device);
1909 QCOMPARE(d.isTapAndDrag(), initValue);
1910 // no config group set, should not change
1911 d.loadConfiguration();
1912 QCOMPARE(d.isTapAndDrag(), initValue);
1913
1914 // set the group
1915 d.setConfig(inputConfig);
1916 d.loadConfiguration();
1917 QCOMPARE(d.isTapAndDrag(), configValue);
1918
1919 // and try to store
1920 if (configValue != initValue) {
1921 d.setTapAndDrag(initValue);
1922 QCOMPARE(inputConfig.readEntry("TapAndDrag", configValue), initValue);
1923 }
1924}
1925
1926void TestLibinputDevice::testLoadTapDragLock_data()
1927{
1928 QTest::addColumn<bool>("initValue");
1929 QTest::addColumn<bool>("configValue");
1930
1931 QTest::newRow("false -> true") << false << true;
1932 QTest::newRow("true -> false") << true << false;
1933 QTest::newRow("true -> true") << true << true;
1934 QTest::newRow("false -> false") << false << false;
1935}
1936
1937void TestLibinputDevice::testLoadTapDragLock()
1938{
1939 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
1940 KConfigGroup inputConfig(config, QStringLiteral("Test"));
1941 QFETCH(bool, configValue);
1942 QFETCH(bool, initValue);
1943 inputConfig.writeEntry("TapDragLock", configValue);
1944
1945 libinput_device device;
1946 device.tapDragLock = initValue;
1947 device.setTapDragLockReturnValue = false;
1948
1949 Device d(&device);
1950 QCOMPARE(d.isTapDragLock(), initValue);
1951 // no config group set, should not change
1952 d.loadConfiguration();
1953 QCOMPARE(d.isTapDragLock(), initValue);
1954
1955 // set the group
1956 d.setConfig(inputConfig);
1957 d.loadConfiguration();
1958 QCOMPARE(d.isTapDragLock(), configValue);
1959
1960 // and try to store
1961 if (configValue != initValue) {
1962 d.setTapDragLock(initValue);
1963 QCOMPARE(inputConfig.readEntry("TapDragLock", configValue), initValue);
1964 }
1965}
1966
1967void TestLibinputDevice::testLoadMiddleButtonEmulation_data()
1968{
1969 QTest::addColumn<bool>("initValue");
1970 QTest::addColumn<bool>("configValue");
1971
1972 QTest::newRow("false -> true") << false << true;
1973 QTest::newRow("true -> false") << true << false;
1974 QTest::newRow("true -> true") << true << true;
1975 QTest::newRow("false -> false") << false << false;
1976}
1977
1978void TestLibinputDevice::testLoadMiddleButtonEmulation()
1979{
1980 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
1981 KConfigGroup inputConfig(config, QStringLiteral("Test"));
1982 QFETCH(bool, configValue);
1983 QFETCH(bool, initValue);
1984 inputConfig.writeEntry("MiddleButtonEmulation", configValue);
1985
1986 libinput_device device;
1987 device.supportsMiddleEmulation = true;
1988 device.middleEmulation = initValue;
1989 device.setMiddleEmulationReturnValue = false;
1990
1991 Device d(&device);
1992 QCOMPARE(d.isMiddleEmulation(), initValue);
1993 // no config group set, should not change
1994 d.loadConfiguration();
1995 QCOMPARE(d.isMiddleEmulation(), initValue);
1996
1997 // set the group
1998 d.setConfig(inputConfig);
1999 d.loadConfiguration();
2000 QCOMPARE(d.isMiddleEmulation(), configValue);
2001
2002 // and try to store
2003 if (configValue != initValue) {
2004 d.setMiddleEmulation(initValue);
2005 QCOMPARE(inputConfig.readEntry("MiddleButtonEmulation", configValue), initValue);
2006 }
2007}
2008
2009void TestLibinputDevice::testLoadNaturalScroll_data()
2010{
2011 QTest::addColumn<bool>("initValue");
2012 QTest::addColumn<bool>("configValue");
2013
2014 QTest::newRow("false -> true") << false << true;
2015 QTest::newRow("true -> false") << true << false;
2016 QTest::newRow("true -> true") << true << true;
2017 QTest::newRow("false -> false") << false << false;
2018}
2019
2020void TestLibinputDevice::testLoadNaturalScroll()
2021{
2022 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
2023 KConfigGroup inputConfig(config, QStringLiteral("Test"));
2024 QFETCH(bool, configValue);
2025 QFETCH(bool, initValue);
2026 inputConfig.writeEntry("NaturalScroll", configValue);
2027
2028 libinput_device device;
2029 device.supportsNaturalScroll = true;
2030 device.naturalScroll = initValue;
2031 device.setNaturalScrollReturnValue = false;
2032
2033 Device d(&device);
2034 QCOMPARE(d.isNaturalScroll(), initValue);
2035 // no config group set, should not change
2036 d.loadConfiguration();
2037 QCOMPARE(d.isNaturalScroll(), initValue);
2038
2039 // set the group
2040 d.setConfig(inputConfig);
2041 d.loadConfiguration();
2042 QCOMPARE(d.isNaturalScroll(), configValue);
2043
2044 // and try to store
2045 if (configValue != initValue) {
2046 d.setNaturalScroll(initValue);
2047 QCOMPARE(inputConfig.readEntry("NaturalScroll", configValue), initValue);
2048 }
2049}
2050
2051void TestLibinputDevice::testLoadScrollMethod_data()
2052{
2053 QTest::addColumn<quint32>("initValue");
2054 QTest::addColumn<QString>("initValuePropNameString");
2055 QTest::addColumn<quint32>("configValue");
2056 QTest::addColumn<QString>("configValuePropNameString");
2057
2058 QTest::newRow("scrollTwoFinger -> scrollEdge") << (quint32)LIBINPUT_CONFIG_SCROLL_2FG << "scrollTwoFinger" << (quint32)LIBINPUT_CONFIG_SCROLL_EDGE << "scrollEdge";
2059 QTest::newRow("scrollOnButtonDown -> scrollTwoFinger") << (quint32)LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN << "scrollOnButtonDown" << (quint32)LIBINPUT_CONFIG_SCROLL_2FG << "scrollTwoFinger";
2060 QTest::newRow("scrollEdge -> scrollEdge") << (quint32)LIBINPUT_CONFIG_SCROLL_EDGE << "scrollEdge" << (quint32)LIBINPUT_CONFIG_SCROLL_EDGE << "scrollEdge";
2061}
2062
2063void TestLibinputDevice::testLoadScrollMethod()
2064{
2065 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
2066 KConfigGroup inputConfig(config, QStringLiteral("Test"));
2067 QFETCH(quint32, initValue);
2068 QFETCH(quint32, configValue);
2069 QFETCH(QString, initValuePropNameString);
2070 QFETCH(QString, configValuePropNameString);
2071
2072 QByteArray initValuePropName = initValuePropNameString.toLatin1();
2073 QByteArray configValuePropName = configValuePropNameString.toLatin1();
2074
2075 inputConfig.writeEntry("ScrollMethod", configValue);
2076
2077 libinput_device device;
2078 device.supportedScrollMethods = LIBINPUT_CONFIG_SCROLL_2FG | LIBINPUT_CONFIG_SCROLL_EDGE | LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
2079 device.scrollMethod = (libinput_config_scroll_method)initValue;
2080 device.setScrollMethodReturnValue = false;
2081
2082 Device d(&device);
2083 QCOMPARE(d.property(initValuePropName).toBool(), true);
2084 QCOMPARE(d.property(configValuePropName).toBool(), initValue == configValue);
2085 // no config group set, should not change
2086 d.loadConfiguration();
2087 QCOMPARE(d.property(initValuePropName).toBool(), true);
2088 QCOMPARE(d.property(configValuePropName).toBool(), initValue == configValue);
2089
2090 // set the group
2091 d.setConfig(inputConfig);
2092 d.loadConfiguration();
2093 QCOMPARE(d.property(initValuePropName).toBool(), initValue == configValue);
2094 QCOMPARE(d.property(configValuePropName).toBool(), true);
2095
2096 // and try to store
2097 if (configValue != initValue) {
2098 d.setProperty(initValuePropName, true);
2099 QCOMPARE(inputConfig.readEntry("ScrollMethod", configValue), initValue);
2100 }
2101}
2102
2103void TestLibinputDevice::testLoadScrollButton_data()
2104{
2105 QTest::addColumn<quint32>("initValue");
2106 QTest::addColumn<quint32>("configValue");
2107
2108 QTest::newRow("BTN_LEFT -> BTN_RIGHT") << quint32(BTN_LEFT) << quint32(BTN_RIGHT);
2109 QTest::newRow("BTN_LEFT -> BTN_LEFT") << quint32(BTN_LEFT) << quint32(BTN_LEFT);
2110}
2111
2112void TestLibinputDevice::testLoadScrollButton()
2113{
2114 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
2115 KConfigGroup inputConfig(config, QStringLiteral("Test"));
2116 QFETCH(quint32, configValue);
2117 QFETCH(quint32, initValue);
2118 inputConfig.writeEntry("ScrollButton", configValue);
2119
2120 libinput_device device;
2121 device.supportedScrollMethods = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
2122 device.scrollMethod = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
2123 device.scrollButton = initValue;
2124 device.setScrollButtonReturnValue = false;
2125
2126 Device d(&device);
2127 QCOMPARE(d.isScrollOnButtonDown(), true);
2128 QCOMPARE(d.scrollButton(), initValue);
2129 // no config group set, should not change
2130 d.loadConfiguration();
2131 QCOMPARE(d.isScrollOnButtonDown(), true);
2132 QCOMPARE(d.scrollButton(), initValue);
2133
2134 // set the group
2135 d.setConfig(inputConfig);
2136 d.loadConfiguration();
2137 QCOMPARE(d.isScrollOnButtonDown(), true);
2138 QCOMPARE(d.scrollButton(), configValue);
2139
2140 // and try to store
2141 if (configValue != initValue) {
2142 d.setScrollButton(initValue);
2143 QCOMPARE(inputConfig.readEntry("ScrollButton", configValue), initValue);
2144 }
2145}
2146
2147void TestLibinputDevice::testLoadLeftHanded_data()
2148{
2149 QTest::addColumn<bool>("initValue");
2150 QTest::addColumn<bool>("configValue");
2151
2152 QTest::newRow("false -> true") << false << true;
2153 QTest::newRow("true -> false") << true << false;
2154 QTest::newRow("true -> true") << true << true;
2155 QTest::newRow("false -> false") << false << false;
2156}
2157
2158void TestLibinputDevice::testLoadLeftHanded()
2159{
2160 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
2161 KConfigGroup inputConfig(config, QStringLiteral("Test"));
2162 QFETCH(bool, configValue);
2163 QFETCH(bool, initValue);
2164 inputConfig.writeEntry("LeftHanded", configValue);
2165
2166 libinput_device device;
2167 device.supportsLeftHanded = true;
2168 device.leftHanded = initValue;
2169 device.setLeftHandedReturnValue = false;
2170
2171 Device d(&device);
2172 QCOMPARE(d.isLeftHanded(), initValue);
2173 // no config group set, should not change
2174 d.loadConfiguration();
2175 QCOMPARE(d.isLeftHanded(), initValue);
2176
2177 // set the group
2178 d.setConfig(inputConfig);
2179 d.loadConfiguration();
2180 QCOMPARE(d.isLeftHanded(), configValue);
2181
2182 // and try to store
2183 if (configValue != initValue) {
2184 d.setLeftHanded(initValue);
2185 QCOMPARE(inputConfig.readEntry("LeftHanded", configValue), initValue);
2186 }
2187}
2188
2189void TestLibinputDevice::testLoadDisableWhileTyping_data()
2190{
2191 QTest::addColumn<bool>("initValue");
2192 QTest::addColumn<bool>("configValue");
2193
2194 QTest::newRow("false -> true") << false << true;
2195 QTest::newRow("true -> false") << true << false;
2196 QTest::newRow("true -> true") << true << true;
2197 QTest::newRow("false -> false") << false << false;
2198}
2199
2200void TestLibinputDevice::testLoadDisableWhileTyping()
2201{
2202 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
2203 KConfigGroup inputConfig(config, QStringLiteral("Test"));
2204 QFETCH(bool, configValue);
2205 QFETCH(bool, initValue);
2206 inputConfig.writeEntry("DisableWhileTyping", configValue);
2207
2208 libinput_device device;
2209 device.supportsDisableWhileTyping = true;
2210 device.disableWhileTyping = initValue ? LIBINPUT_CONFIG_DWT_ENABLED : LIBINPUT_CONFIG_DWT_DISABLED;
2211 device.setDisableWhileTypingReturnValue = false;
2212
2213 Device d(&device);
2214 QCOMPARE(d.isDisableWhileTyping(), initValue);
2215 // no config group set, should not change
2216 d.loadConfiguration();
2217 QCOMPARE(d.isDisableWhileTyping(), initValue);
2218
2219 // set the group
2220 d.setConfig(inputConfig);
2221 d.loadConfiguration();
2222 QCOMPARE(d.isDisableWhileTyping(), configValue);
2223
2224 // and try to store
2225 if (configValue != initValue) {
2226 d.setDisableWhileTyping(initValue);
2227 QCOMPARE(inputConfig.readEntry("DisableWhileTyping", configValue), initValue);
2228 }
2229}
2230
2231void TestLibinputDevice::testLoadLmrTapButtonMap_data()
2232{
2233 QTest::addColumn<bool>("initValue");
2234 QTest::addColumn<bool>("configValue");
2235
2236 QTest::newRow("false -> true") << false << true;
2237 QTest::newRow("true -> false") << true << false;
2238 QTest::newRow("true -> true") << true << true;
2239 QTest::newRow("false -> false") << false << false;
2240}
2241
2242void TestLibinputDevice::testLoadLmrTapButtonMap()
2243{
2244 auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
2245 KConfigGroup inputConfig(config, QStringLiteral("Test"));
2246 QFETCH(bool, configValue);
2247 QFETCH(bool, initValue);
2248 inputConfig.writeEntry("LmrTapButtonMap", configValue);
2249
2250 libinput_device device;
2251 device.tapFingerCount = 3;
2252 device.tapButtonMap = initValue ? LIBINPUT_CONFIG_TAP_MAP_LMR : LIBINPUT_CONFIG_TAP_MAP_LRM;
2253 device.setTapButtonMapReturnValue = false;
2254
2255 Device d(&device);
2256 QCOMPARE(d.lmrTapButtonMap(), initValue);
2257 // no config group set, should not change
2258 d.loadConfiguration();
2259 QCOMPARE(d.lmrTapButtonMap(), initValue);
2260 QCOMPARE(dbusProperty<bool>(d.sysName(), "lmrTapButtonMap"), initValue);
2261
2262 // set the group
2263 d.setConfig(inputConfig);
2264 d.loadConfiguration();
2265 QCOMPARE(d.lmrTapButtonMap(), configValue);
2266 QCOMPARE(dbusProperty<bool>(d.sysName(), "lmrTapButtonMap"), configValue);
2267
2268 // and try to store
2269 if (configValue != initValue) {
2270 d.setLmrTapButtonMap(initValue);
2271 QCOMPARE(inputConfig.readEntry("LmrTapButtonMap", configValue), initValue);
2272 }
2273}
2274
2275void TestLibinputDevice::testOrientation_data()
2276{
2277 QTest::addColumn<Qt::ScreenOrientation>("orientation");
2278 QTest::addColumn<float>("m11");
2279 QTest::addColumn<float>("m12");
2280 QTest::addColumn<float>("m13");
2281 QTest::addColumn<float>("m21");
2282 QTest::addColumn<float>("m22");
2283 QTest::addColumn<float>("m23");
2284 QTest::addColumn<bool>("defaultIsIdentity");
2285
2286 QTest::newRow("Primary") << Qt::PrimaryOrientation << 1.0f << 2.0f << 3.0f << 4.0f << 5.0f << 6.0f << false;
2287 QTest::newRow("Landscape") << Qt::LandscapeOrientation << 1.0f << 2.0f << 3.0f << 4.0f << 5.0f << 6.0f << false;
2288 QTest::newRow("Portrait") << Qt::PortraitOrientation << 0.0f << -1.0f << 1.0f << 1.0f << 0.0f << 0.0f << true;
2289 QTest::newRow("InvertedLandscape") << Qt::InvertedLandscapeOrientation << -1.0f << 0.0f << 1.0f << 0.0f << -1.0f << 1.0f << true;
2290 QTest::newRow("InvertedPortrait") << Qt::InvertedPortraitOrientation << 0.0f << 1.0f << 0.0f << -1.0f << 0.0f << 1.0f << true;
2291}
2292
2293void TestLibinputDevice::testOrientation()
2294{
2295 libinput_device device;
2296 device.supportsCalibrationMatrix = true;
2297 device.defaultCalibrationMatrix = std::array<float, 6>{{1.0, 2.0, 3.0, 4.0, 5.0, 6.0}};
2298 QFETCH(bool, defaultIsIdentity);
2299 device.defaultCalibrationMatrixIsIdentity = defaultIsIdentity;
2300 Device d(&device);
2301 QFETCH(Qt::ScreenOrientation, orientation);
2302 d.setOrientation(orientation);
2303 QTEST(device.calibrationMatrix[0], "m11");
2304 QTEST(device.calibrationMatrix[1], "m12");
2305 QTEST(device.calibrationMatrix[2], "m13");
2306 QTEST(device.calibrationMatrix[3], "m21");
2307 QTEST(device.calibrationMatrix[4], "m22");
2308 QTEST(device.calibrationMatrix[5], "m23");
2309}
2310
2311void TestLibinputDevice::testCalibrationWithDefault()
2312{
2313 libinput_device device;
2314 device.supportsCalibrationMatrix = true;
2315 device.defaultCalibrationMatrix = std::array<float, 6>{{2.0, 3.0, 0.0, 4.0, 5.0, 0.0}};
2317 Device d(&device);
2318 d.setOrientation(Qt::PortraitOrientation);
2319 QCOMPARE(device.calibrationMatrix[0], 3.0f);
2320 QCOMPARE(device.calibrationMatrix[1], -2.0f);
2321 QCOMPARE(device.calibrationMatrix[2], 2.0f);
2322 QCOMPARE(device.calibrationMatrix[3], 5.0f);
2323 QCOMPARE(device.calibrationMatrix[4], -4.0f);
2324 QCOMPARE(device.calibrationMatrix[5], 4.0f);
2325}
2326
2327void TestLibinputDevice::testSwitch_data()
2328{
2329 QTest::addColumn<bool>("lid");
2330 QTest::addColumn<bool>("tablet");
2331
2332 QTest::newRow("lid") << true << false;
2333 QTest::newRow("tablet") << false << true;
2334}
2335
2336void TestLibinputDevice::testSwitch()
2337{
2338 libinput_device device;
2339 device.switchDevice = true;
2340 QFETCH(bool, lid);
2341 QFETCH(bool, tablet);
2342 device.lidSwitch = lid;
2343 device.tabletModeSwitch = tablet;
2344
2345 Device d(&device);
2346 QCOMPARE(d.isSwitch(), true);
2347 QCOMPARE(d.isLidSwitch(), lid);
2348 QCOMPARE(d.property("lidSwitch").toBool(), lid);
2349 QCOMPARE(dbusProperty<bool>(d.sysName(), "lidSwitch"), lid);
2350 QCOMPARE(d.isTabletModeSwitch(), tablet);
2351 QCOMPARE(d.property("tabletModeSwitch").toBool(), tablet);
2352 QCOMPARE(dbusProperty<bool>(d.sysName(), "tabletModeSwitch"), tablet);
2353}
2354
2355QTEST_GUILESS_MAIN(TestLibinputDevice)
2356#include "device_test.moc"
int setScrollMethodReturnValue
quint32 supportedScrollMethods
bool tapDragLockEnabledByDefault
int setNaturalScrollReturnValue
int setScrollButtonReturnValue
bool setClickMethodReturnValue
std::array< float, 6 > defaultCalibrationMatrix
QByteArray outputName
enum libinput_config_dwt_state disableWhileTypingEnabledByDefault
quint32 supportedClickMethods
QList< quint32 > keys
bool supportsCalibrationMatrix
enum libinput_config_scroll_method defaultScrollMethod
int setPointerAccelerationReturnValue
int setMiddleEmulationReturnValue
bool supportsDisableWhileTyping
enum libinput_config_scroll_method scrollMethod
bool setPointerAccelerationProfileReturnValue
qreal pointerAcceleration
int setTapButtonMapReturnValue
enum libinput_config_accel_profile pointerAccelerationProfile
enum libinput_config_dwt_state disableWhileTyping
enum libinput_config_accel_profile defaultPointerAccelerationProfile
bool leftHandedEnabledByDefault
std::array< float, 6 > calibrationMatrix
quint32 defaultScrollButton
qreal defaultPointerAcceleration
QByteArray name
enum libinput_config_tap_button_map tapButtonMap
enum libinput_config_click_method clickMethod
bool supportsPointerAcceleration
bool tapAndDragEnabledByDefault
enum libinput_config_tap_button_map defaultTapButtonMap
bool naturalScrollEnabledByDefault
bool supportsDisableEventsOnExternalMouse
bool middleEmulationEnabledByDefault
bool defaultCalibrationMatrixIsIdentity
int setDisableWhileTypingReturnValue
QByteArray sysName
bool supportsMiddleEmulation
enum libinput_config_click_method defaultClickMethod
int setTapDragLockReturnValue
quint32 supportedPointerAccelerationProfiles
Qt::MouseButtons supportedButtons