diff --git a/autotests/libinput/device_test.cpp b/autotests/libinput/device_test.cpp index 85650f63fd..5e2632bfc4 100644 --- a/autotests/libinput/device_test.cpp +++ b/autotests/libinput/device_test.cpp @@ -22,6 +22,8 @@ along with this program. If not, see . #include +#include + using namespace KWin::LibInput; class TestLibinputDevice : public QObject @@ -60,6 +62,8 @@ private Q_SLOTS: void testLeftHanded(); void testSupportedButtons_data(); void testSupportedButtons(); + void testAlphaNumericKeyboard_data(); + void testAlphaNumericKeyboard(); }; void TestLibinputDevice::testStaticGetter() @@ -503,5 +507,57 @@ void TestLibinputDevice::testSupportedButtons() QTEST(d.supportedButtons(), "expectedButtons"); } +void TestLibinputDevice::testAlphaNumericKeyboard_data() +{ + QTest::addColumn>("supportedKeys"); + QTest::addColumn("isAlpha"); + + QVector keys; + + for (int i = KEY_1; i <= KEY_0; i++) { + keys << i; + QByteArray row = QByteArrayLiteral("number"); + row.append(QByteArray::number(i)); + QTest::newRow(row.constData()) << keys << false; + } + for (int i = KEY_Q; i <= KEY_P; i++) { + keys << i; + QByteArray row = QByteArrayLiteral("alpha"); + row.append(QByteArray::number(i)); + QTest::newRow(row.constData()) << keys << false; + } + for (int i = KEY_A; i <= KEY_L; i++) { + keys << i; + QByteArray row = QByteArrayLiteral("alpha"); + row.append(QByteArray::number(i)); + QTest::newRow(row.constData()) << keys << false; + } + for (int i = KEY_Z; i < KEY_M; i++) { + keys << i; + QByteArray row = QByteArrayLiteral("alpha"); + row.append(QByteArray::number(i)); + QTest::newRow(row.constData()) << keys << false; + } + // adding a different key should not result in it becoming alphanumeric keyboard + keys << KEY_SEMICOLON; + QTest::newRow("semicolon") << keys << false; + + // last but not least the M which should turn everything on + keys << KEY_M; + QTest::newRow("alphanumeric") << keys << true; +} + +void TestLibinputDevice::testAlphaNumericKeyboard() +{ + QFETCH(QVector, supportedKeys); + libinput_device device; + device.keyboard = true; + device.keys = supportedKeys; + + Device d(&device); + QCOMPARE(d.isKeyboard(), true); + QTEST(d.isAlphaNumericKeyboard(), "isAlpha"); +} + QTEST_GUILESS_MAIN(TestLibinputDevice) #include "device_test.moc" diff --git a/autotests/libinput/mock_libinput.cpp b/autotests/libinput/mock_libinput.cpp index bc725d52a1..8c4563db9e 100644 --- a/autotests/libinput/mock_libinput.cpp +++ b/autotests/libinput/mock_libinput.cpp @@ -24,7 +24,7 @@ along with this program. If not, see . int libinput_device_keyboard_has_key(struct libinput_device *device, uint32_t code) { - return 0; + return device->keys.contains(code); } int libinput_device_has_capability(struct libinput_device *device, enum libinput_device_capability capability) diff --git a/autotests/libinput/mock_libinput.h b/autotests/libinput/mock_libinput.h index b13a65407f..37dee285d1 100644 --- a/autotests/libinput/mock_libinput.h +++ b/autotests/libinput/mock_libinput.h @@ -22,6 +22,7 @@ along with this program. If not, see . #include #include +#include struct libinput_device { bool keyboard = false; @@ -48,6 +49,7 @@ struct libinput_device { bool leftHanded = false; int setLeftHandedReturnValue = 0; Qt::MouseButtons supportedButtons; + QVector keys; }; #endif