diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2019-08-23 09:25:56 +0200 |
---|---|---|
committer | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2019-08-27 12:35:33 +0200 |
commit | b6703d94d833c73dbe7fd252c4b61db455f5c2f5 (patch) | |
tree | 9a4adc7ee9f1a1b6ef165ee8189d56439bcc4e4f | |
parent | 4400d48cb6e8ab1b8676e198d4882b7a52310935 (diff) | |
download | qtwayland-b6703d94d833c73dbe7fd252c4b61db455f5c2f5.tar.gz |
Client tests: Add test for a simple wl_touch tap
Change-Id: I35aec950da0ac0d10cf1fa0c4bc1f56ba232cf89
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
-rw-r--r-- | tests/auto/client/seatv5/tst_seatv5.cpp | 60 | ||||
-rw-r--r-- | tests/auto/client/shared/coreprotocol.cpp | 34 | ||||
-rw-r--r-- | tests/auto/client/shared/coreprotocol.h | 4 |
3 files changed, 98 insertions, 0 deletions
diff --git a/tests/auto/client/seatv5/tst_seatv5.cpp b/tests/auto/client/seatv5/tst_seatv5.cpp index c2b1b0e4..76a68b86 100644 --- a/tests/auto/client/seatv5/tst_seatv5.cpp +++ b/tests/auto/client/seatv5/tst_seatv5.cpp @@ -67,6 +67,7 @@ private slots: // Touch tests void createsTouch(); + void singleTap(); }; void tst_seatv5::bindsToSeat() @@ -387,5 +388,64 @@ void tst_seatv5::createsTouch() QCOMPOSITOR_TRY_COMPARE(touch()->resourceMap().first()->version(), 5); } +class TouchWindow : public QRasterWindow { +public: + TouchWindow() + { + resize(64, 64); + show(); + } + void touchEvent(QTouchEvent *event) override + { + QRasterWindow::touchEvent(event); + m_events.append(Event{event}); + } + struct Event // Because I didn't find a convenient way to copy it entirely + { + explicit Event() = default; + explicit Event(const QTouchEvent *event) + : type(event->type()) + , touchPointStates(event->touchPointStates()) + , touchPoints(event->touchPoints()) + { + } + const QEvent::Type type{}; + const Qt::TouchPointStates touchPointStates{}; + const QList<QTouchEvent::TouchPoint> touchPoints; + }; + QVector<Event> m_events; +}; + +void tst_seatv5::singleTap() +{ + TouchWindow window; + QCOMPOSITOR_TRY_VERIFY(xdgSurface() && xdgSurface()->m_committedConfigureSerial); + + exec([=] { + auto *t = touch(); + auto *c = client(); + t->sendDown(xdgToplevel()->surface(), {32, 32}, 1); + t->sendFrame(c); + t->sendUp(c, 1); + t->sendFrame(c); + }); + + QTRY_VERIFY(!window.m_events.empty()); + { + auto e = window.m_events.takeFirst(); + QCOMPARE(e.type, QEvent::TouchBegin); + QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointPressed); + QCOMPARE(e.touchPoints.length(), 1); + QCOMPARE(e.touchPoints.first().pos(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top())); + } + { + auto e = window.m_events.takeFirst(); + QCOMPARE(e.type, QEvent::TouchEnd); + QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointReleased); + QCOMPARE(e.touchPoints.length(), 1); + QCOMPARE(e.touchPoints.first().pos(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top())); + } +} + QCOMPOSITOR_TEST_MAIN(tst_seatv5) #include "tst_seatv5.moc" diff --git a/tests/auto/client/shared/coreprotocol.cpp b/tests/auto/client/shared/coreprotocol.cpp index 006c4a80..120c256c 100644 --- a/tests/auto/client/shared/coreprotocol.cpp +++ b/tests/auto/client/shared/coreprotocol.cpp @@ -397,6 +397,40 @@ void Pointer::pointer_set_cursor(Resource *resource, uint32_t serial, wl_resourc emit setCursor(serial); } +uint Touch::sendDown(Surface *surface, const QPointF &position, int id) +{ + wl_fixed_t x = wl_fixed_from_double(position.x()); + wl_fixed_t y = wl_fixed_from_double(position.y()); + uint serial = m_seat->m_compositor->nextSerial(); + auto time = m_seat->m_compositor->currentTimeMilliseconds(); + wl_client *client = surface->resource()->client(); + + const auto touchResources = resourceMap().values(client); + for (auto *r : touchResources) + wl_touch::send_down(r->handle, serial, time, surface->resource()->handle, id, x, y); + + return serial; +} + +uint Touch::sendUp(wl_client *client, int id) +{ + uint serial = m_seat->m_compositor->nextSerial(); + auto time = m_seat->m_compositor->currentTimeMilliseconds(); + + const auto touchResources = resourceMap().values(client); + for (auto *r : touchResources) + wl_touch::send_up(r->handle, serial, time, id); + + return serial; +} + +void Touch::sendFrame(wl_client *client) +{ + const auto touchResources = resourceMap().values(client); + for (auto *r : touchResources) + send_frame(r->handle); +} + uint Keyboard::sendEnter(Surface *surface) { auto serial = m_seat->m_compositor->nextSerial(); diff --git a/tests/auto/client/shared/coreprotocol.h b/tests/auto/client/shared/coreprotocol.h index 6905ab5d..50812c29 100644 --- a/tests/auto/client/shared/coreprotocol.h +++ b/tests/auto/client/shared/coreprotocol.h @@ -316,6 +316,10 @@ class Touch : public QObject, public QtWaylandServer::wl_touch Q_OBJECT public: explicit Touch(Seat *seat) : m_seat(seat) {} + uint sendDown(Surface *surface, const QPointF &position, int id); + uint sendUp(wl_client *client, int id); + void sendFrame(wl_client *client); + Seat *m_seat = nullptr; }; |