[autotests] Fix failing KeyboardLayoutTest::testNumLock()

Summary:
Since Qt::KeypadModifier is set only for keypad keys and not the NumLock
key, we need to press at least one keypad key to determine whether
numlock is actually on. On the other hand, we know that when numlock is
on, the corresponding LED is also on. So we could check the LED rather
than press two keys.

Test Plan: testKeyboardLayout passes.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D27789
This commit is contained in:
Vlad Zahorodnii 2020-03-02 17:37:08 +02:00
parent bbcc51fabf
commit 5d580b9fb2

View file

@ -471,16 +471,16 @@ void KeyboardLayoutTest::testNumLock()
QTRY_COMPARE(xkb->layoutName(), QStringLiteral("English (US)"));
// by default not set
QVERIFY(!xkb->modifiers().testFlag(Qt::KeypadModifier));
QVERIFY(!xkb->leds().testFlag(Xkb::LED::NumLock));
quint32 timestamp = 0;
kwinApp()->platform()->keyboardKeyPressed(KEY_NUMLOCK, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(KEY_NUMLOCK, timestamp++);
// now it should be on
QVERIFY(xkb->modifiers().testFlag(Qt::KeypadModifier));
QVERIFY(xkb->leds().testFlag(Xkb::LED::NumLock));
// and back to off
kwinApp()->platform()->keyboardKeyPressed(KEY_NUMLOCK, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(KEY_NUMLOCK, timestamp++);
QVERIFY(!xkb->modifiers().testFlag(Qt::KeypadModifier));
QVERIFY(!xkb->leds().testFlag(Xkb::LED::NumLock));
// let's reconfigure to enable through config
auto group = kwinApp()->inputConfig()->group("Keyboard");
@ -488,22 +488,22 @@ void KeyboardLayoutTest::testNumLock()
group.sync();
xkb->reconfigure();
// now it should be on
QVERIFY(xkb->modifiers().testFlag(Qt::KeypadModifier));
QVERIFY(xkb->leds().testFlag(Xkb::LED::NumLock));
// pressing should result in it being off
kwinApp()->platform()->keyboardKeyPressed(KEY_NUMLOCK, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(KEY_NUMLOCK, timestamp++);
QVERIFY(!xkb->modifiers().testFlag(Qt::KeypadModifier));
QVERIFY(!xkb->leds().testFlag(Xkb::LED::NumLock));
// pressing again should enable it
kwinApp()->platform()->keyboardKeyPressed(KEY_NUMLOCK, timestamp++);
kwinApp()->platform()->keyboardKeyReleased(KEY_NUMLOCK, timestamp++);
QVERIFY(xkb->modifiers().testFlag(Qt::KeypadModifier));
QVERIFY(xkb->leds().testFlag(Xkb::LED::NumLock));
// now reconfigure to disable on load
group.writeEntry("NumLock", 1);
group.sync();
xkb->reconfigure();
QVERIFY(!xkb->modifiers().testFlag(Qt::KeypadModifier));
QVERIFY(!xkb->leds().testFlag(Xkb::LED::NumLock));
}