[autotests/libinput] Add test case for Device::isAlphaNumericKeyboard

This commit is contained in:
Martin Gräßlin 2016-05-30 08:22:04 +02:00
parent abe582c27d
commit 27523b6ecb
3 changed files with 59 additions and 1 deletions

View file

@ -22,6 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QtTest/QtTest>
#include <linux/input.h>
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<QVector<quint32>>("supportedKeys");
QTest::addColumn<bool>("isAlpha");
QVector<quint32> 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<quint32>, 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"

View file

@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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)

View file

@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QByteArray>
#include <QSizeF>
#include <QVector>
struct libinput_device {
bool keyboard = false;
@ -48,6 +49,7 @@ struct libinput_device {
bool leftHanded = false;
int setLeftHandedReturnValue = 0;
Qt::MouseButtons supportedButtons;
QVector<quint32> keys;
};
#endif