diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2012-03-07 10:40:31 +0100 |
---|---|---|
committer | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2012-03-07 11:04:45 +0100 |
commit | 609b8a18d0fb10cbee4a71a68ccee25a29fb071b (patch) | |
tree | 7af33214a2074881e55d8d014ff517f5f157bd8a /tests | |
parent | efccc708d4578ff231bba2fba38bbb861dabcbe1 (diff) |
Added testing of key events to client auto test.
This requires passing on the native key code as well when calling into
QWindowSystemInterface from QWaylandInputDevice.
Change-Id: Iea1f98dcc9e050bb42cc48927da17aa54085a5e8
Reviewed-by: Laszlo Agocs <laszlo.p.agocs@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/client/mockcompositor.cpp | 14 | ||||
-rw-r--r-- | tests/auto/client/mockcompositor.h | 4 | ||||
-rw-r--r-- | tests/auto/client/mockinput.cpp | 21 | ||||
-rw-r--r-- | tests/auto/client/tst_client.cpp | 19 |
4 files changed, 56 insertions, 2 deletions
diff --git a/tests/auto/client/mockcompositor.cpp b/tests/auto/client/mockcompositor.cpp index 39bd6e3e7..c751bccb2 100644 --- a/tests/auto/client/mockcompositor.cpp +++ b/tests/auto/client/mockcompositor.cpp @@ -114,6 +114,20 @@ void MockCompositor::sendMouseRelease(const QSharedPointer<MockSurface> &surface processCommand(command); } +void MockCompositor::sendKeyPress(const QSharedPointer<MockSurface> &surface, uint code) +{ + Command command = makeCommand(Impl::Compositor::sendKeyPress, m_compositor); + command.parameters << QVariant::fromValue(surface) << code; + processCommand(command); +} + +void MockCompositor::sendKeyRelease(const QSharedPointer<MockSurface> &surface, uint code) +{ + Command command = makeCommand(Impl::Compositor::sendKeyRelease, m_compositor); + command.parameters << QVariant::fromValue(surface) << code; + processCommand(command); +} + QSharedPointer<MockSurface> MockCompositor::surface() { QSharedPointer<MockSurface> result; diff --git a/tests/auto/client/mockcompositor.h b/tests/auto/client/mockcompositor.h index ece197277..18de0e6cb 100644 --- a/tests/auto/client/mockcompositor.h +++ b/tests/auto/client/mockcompositor.h @@ -80,6 +80,8 @@ public: static void setKeyboardFocus(void *data, const QList<QVariant> ¶meters); static void sendMousePress(void *data, const QList<QVariant> ¶meters); static void sendMouseRelease(void *data, const QList<QVariant> ¶meters); + static void sendKeyPress(void *data, const QList<QVariant> ¶meters); + static void sendKeyRelease(void *data, const QList<QVariant> ¶meters); private: static void bindCompositor(wl_client *client, void *data, uint32_t version, uint32_t id); @@ -142,6 +144,8 @@ public: void setKeyboardFocus(const QSharedPointer<MockSurface> &surface); void sendMousePress(const QSharedPointer<MockSurface> &surface, const QPoint &pos); void sendMouseRelease(const QSharedPointer<MockSurface> &surface); + void sendKeyPress(const QSharedPointer<MockSurface> &surface, uint code); + void sendKeyRelease(const QSharedPointer<MockSurface> &surface, uint code); QSharedPointer<MockSurface> surface(); diff --git a/tests/auto/client/mockinput.cpp b/tests/auto/client/mockinput.cpp index 9d6286db2..b5c90d7ed 100644 --- a/tests/auto/client/mockinput.cpp +++ b/tests/auto/client/mockinput.cpp @@ -121,5 +121,26 @@ void Compositor::sendMouseRelease(void *data, const QList<QVariant> ¶meters) wl_input_device_send_button(compositor->m_input.pointer_focus_resource, compositor->time(), 0x110, 0); } +void Compositor::sendKeyPress(void *data, const QList<QVariant> ¶meters) +{ + Compositor *compositor = static_cast<Compositor *>(data); + wl_surface *surface = resolveSurface(parameters.first()); + if (!surface) + return; + + QPoint pos = parameters.last().toPoint(); + wl_input_device_send_key(compositor->m_input.keyboard_focus_resource, compositor->time(), parameters.last().toUInt() - 8, 1); +} + +void Compositor::sendKeyRelease(void *data, const QList<QVariant> ¶meters) +{ + Compositor *compositor = static_cast<Compositor *>(data); + wl_surface *surface = resolveSurface(parameters.first()); + if (!surface) + return; + + wl_input_device_send_key(compositor->m_input.keyboard_focus_resource, compositor->time(), parameters.last().toUInt() - 8, 0); +} + } diff --git a/tests/auto/client/tst_client.cpp b/tests/auto/client/tst_client.cpp index fdcb12991..9b63337c5 100644 --- a/tests/auto/client/tst_client.cpp +++ b/tests/auto/client/tst_client.cpp @@ -55,6 +55,7 @@ public: , keyReleaseEventCount(0) , mousePressEventCount(0) , mouseReleaseEventCount(0) + , keyCode(0) { setSurfaceType(QSurface::RasterSurface); setGeometry(0, 0, 32, 32); @@ -71,14 +72,16 @@ public: ++focusOutEventCount; } - void keyPressEvent(QKeyEvent *) + void keyPressEvent(QKeyEvent *event) { ++keyPressEventCount; + keyCode = event->nativeScanCode(); } - void keyReleaseEvent(QKeyEvent *) + void keyReleaseEvent(QKeyEvent *event) { ++keyReleaseEventCount; + keyCode = event->nativeScanCode(); } void mousePressEvent(QMouseEvent *event) @@ -99,6 +102,7 @@ public: int mousePressEventCount; int mouseReleaseEventCount; + uint keyCode; QPoint mousePressPos; }; @@ -166,6 +170,17 @@ void tst_WaylandClient::events() QTRY_COMPARE(window.focusInEventCount, 2); QTRY_COMPARE(QGuiApplication::focusWindow(), &window); + uint keyCode = 80; // arbitrarily chosen + QCOMPARE(window.keyPressEventCount, 0); + compositor->sendKeyPress(surface, keyCode); + QTRY_COMPARE(window.keyPressEventCount, 1); + QTRY_COMPARE(window.keyCode, keyCode); + + QCOMPARE(window.keyReleaseEventCount, 0); + compositor->sendKeyRelease(surface, keyCode); + QTRY_COMPARE(window.keyReleaseEventCount, 1); + QCOMPARE(window.keyCode, keyCode); + QPoint mousePressPos(16, 16); QCOMPARE(window.mousePressEventCount, 0); compositor->sendMousePress(surface, mousePressPos); |