From 27523b6ecb2451e7f1632e644d7f62be4b580898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 30 May 2016 08:22:04 +0200 Subject: [PATCH] [autotests/libinput] Add test case for Device::isAlphaNumericKeyboard --- autotests/libinput/device_test.cpp | 56 ++++++++++++++++++++++++++++ autotests/libinput/mock_libinput.cpp | 2 +- autotests/libinput/mock_libinput.h | 2 + 3 files changed, 59 insertions(+), 1 deletion(-) 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