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 08:47:23 +0200 |
commit | c744945d9c7e26503272a30827762c8098f21e4c (patch) | |
tree | b126e106170e5951564640a0207a44c34adb0cb3 /tests | |
parent | 7a88090775dd666af318cd715988cfaa02109ff1 (diff) | |
download | qtwayland-c744945d9c7e26503272a30827762c8098f21e4c.tar.gz |
Client tests: Add touch infrastructure and simple test
This doesn't test much, but adds the infrastructure needed for more
thorough tests later on.
More or less exactly matches the mocking for wl_keyboard and wl_pointer.
Change-Id: I563bb9be7ccaaf0aa83611e84d051cc307455ccb
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/client/seatv5/tst_seatv5.cpp | 13 | ||||
-rw-r--r-- | tests/auto/client/shared/coreprotocol.cpp | 29 | ||||
-rw-r--r-- | tests/auto/client/shared/coreprotocol.h | 16 | ||||
-rw-r--r-- | tests/auto/client/shared/mockcompositor.cpp | 2 | ||||
-rw-r--r-- | tests/auto/client/shared/mockcompositor.h | 1 |
5 files changed, 54 insertions, 7 deletions
diff --git a/tests/auto/client/seatv5/tst_seatv5.cpp b/tests/auto/client/seatv5/tst_seatv5.cpp index 4e5d6cce..c2b1b0e4 100644 --- a/tests/auto/client/seatv5/tst_seatv5.cpp +++ b/tests/auto/client/seatv5/tst_seatv5.cpp @@ -41,7 +41,7 @@ public: removeAll<Seat>(); - uint capabilities = MockCompositor::Seat::capability_pointer; + uint capabilities = MockCompositor::Seat::capability_pointer | MockCompositor::Seat::capability_touch; int version = 5; add<Seat>(capabilities, version); }); @@ -54,6 +54,8 @@ class tst_seatv5 : public QObject, private SeatV5Compositor private slots: void cleanup() { QTRY_VERIFY2(isClean(), qPrintable(dirtyMessage())); } void bindsToSeat(); + + // Pointer tests void createsPointer(); void setsCursorOnEnter(); void usesEnterSerial(); @@ -62,6 +64,9 @@ private slots: void fingerScroll(); void fingerScrollSlow(); void wheelDiscreteScroll(); + + // Touch tests + void createsTouch(); }; void tst_seatv5::bindsToSeat() @@ -376,5 +381,11 @@ void tst_seatv5::wheelDiscreteScroll() } } +void tst_seatv5::createsTouch() +{ + QCOMPOSITOR_TRY_COMPARE(touch()->resourceMap().size(), 1); + QCOMPOSITOR_TRY_COMPARE(touch()->resourceMap().first()->version(), 5); +} + 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 5f51e417..006c4a80 100644 --- a/tests/auto/client/shared/coreprotocol.cpp +++ b/tests/auto/client/shared/coreprotocol.cpp @@ -192,14 +192,14 @@ Seat::~Seat() qDeleteAll(m_oldPointers); delete m_pointer; + qDeleteAll(m_oldTouchs); + delete m_touch; + qDeleteAll(m_oldKeyboards); delete m_keyboard; } void Seat::setCapabilities(uint capabilities) { - // TODO: Add support for touch - Q_ASSERT(~capabilities & capability_touch); - m_capabilities = capabilities; if (m_capabilities & capability_pointer) { @@ -210,6 +210,14 @@ void Seat::setCapabilities(uint capabilities) { m_pointer = nullptr; } + if (m_capabilities & capability_touch) { + if (!m_touch) + m_touch = (new Touch(this)); + } else if (m_touch) { + m_oldTouchs << m_touch; + m_touch = nullptr; + } + if (m_capabilities & capability_keyboard) { if (!m_keyboard) m_keyboard = (new Keyboard(this)); @@ -237,6 +245,21 @@ void Seat::seat_get_pointer(Resource *resource, uint32_t id) m_pointer->add(resource->client(), id, resource->version()); } +void Seat::seat_get_touch(QtWaylandServer::wl_seat::Resource *resource, uint32_t id) +{ + if (~m_capabilities & capability_touch) { + qWarning() << "Client requested a wl_touch without the capability being available." + << "This Could be a race condition when hotunplugging," + << "but is most likely a client error"; + Touch *touch = new Touch(this); + touch->add(resource->client(), id, resource->version()); + // TODO: mark as destroyed + m_oldTouchs << touch; + return; + } + m_touch->add(resource->client(), id, resource->version()); +} + void Seat::seat_get_keyboard(QtWaylandServer::wl_seat::Resource *resource, uint32_t id) { if (~m_capabilities & capability_keyboard) { diff --git a/tests/auto/client/shared/coreprotocol.h b/tests/auto/client/shared/coreprotocol.h index 2347a836..6905ab5d 100644 --- a/tests/auto/client/shared/coreprotocol.h +++ b/tests/auto/client/shared/coreprotocol.h @@ -38,6 +38,7 @@ namespace MockCompositor { class WlCompositor; class Output; class Pointer; +class Touch; class Keyboard; class CursorRole; class ShmPool; @@ -236,7 +237,7 @@ class Seat : public Global, public QtWaylandServer::wl_seat { Q_OBJECT public: - explicit Seat(CoreCompositor *compositor, uint capabilities = Seat::capability_pointer | Seat::capability_keyboard, int version = 5); + explicit Seat(CoreCompositor *compositor, uint capabilities = Seat::capability_pointer | Seat::capability_keyboard | Seat::capability_touch, int version = 5); ~Seat() override; void send_capabilities(Resource *resource, uint capabilities) = delete; // Use wrapper instead void send_capabilities(uint capabilities) = delete; // Use wrapper instead @@ -247,6 +248,9 @@ public: Pointer* m_pointer = nullptr; QVector<Pointer *> m_oldPointers; + Touch* m_touch = nullptr; + QVector<Touch *> m_oldTouchs; + Keyboard* m_keyboard = nullptr; QVector<Keyboard *> m_oldKeyboards; @@ -259,8 +263,8 @@ protected: } void seat_get_pointer(Resource *resource, uint32_t id) override; + void seat_get_touch(Resource *resource, uint32_t id) override; void seat_get_keyboard(Resource *resource, uint32_t id) override; -// void seat_get_touch(Resource *resource, uint32_t id) override; // void seat_release(Resource *resource) override; }; @@ -307,6 +311,14 @@ public: Surface *m_surface = nullptr; }; +class Touch : public QObject, public QtWaylandServer::wl_touch +{ + Q_OBJECT +public: + explicit Touch(Seat *seat) : m_seat(seat) {} + Seat *m_seat = nullptr; +}; + class Keyboard : public QObject, public QtWaylandServer::wl_keyboard { Q_OBJECT diff --git a/tests/auto/client/shared/mockcompositor.cpp b/tests/auto/client/shared/mockcompositor.cpp index 6b9af429..5f2d8907 100644 --- a/tests/auto/client/shared/mockcompositor.cpp +++ b/tests/auto/client/shared/mockcompositor.cpp @@ -41,7 +41,7 @@ DefaultCompositor::DefaultCompositor() add<SubCompositor>(); auto *output = add<Output>(); output->m_data.physicalSize = output->m_data.mode.physicalSizeForDpi(96); - add<Seat>(Seat::capability_pointer | Seat::capability_keyboard); + add<Seat>(Seat::capability_pointer | Seat::capability_keyboard | Seat::capability_touch); add<XdgWmBase>(); add<Shm>(); // TODO: other shells, viewporter, xdgoutput etc diff --git a/tests/auto/client/shared/mockcompositor.h b/tests/auto/client/shared/mockcompositor.h index aa85a4ae..3cb9b337 100644 --- a/tests/auto/client/shared/mockcompositor.h +++ b/tests/auto/client/shared/mockcompositor.h @@ -60,6 +60,7 @@ public: XdgToplevel *xdgToplevel(int i = 0) { return get<XdgWmBase>()->toplevel(i); } XdgPopup *xdgPopup(int i = 0) { return get<XdgWmBase>()->popup(i); } Pointer *pointer() { auto *seat = get<Seat>(); Q_ASSERT(seat); return seat->m_pointer; } + Touch *touch() { auto *seat = get<Seat>(); Q_ASSERT(seat); return seat->m_touch; } Surface *cursorSurface() { auto *p = pointer(); return p ? p->cursorSurface() : nullptr; } Keyboard *keyboard() { auto *seat = get<Seat>(); Q_ASSERT(seat); return seat->m_keyboard; } uint sendXdgShellPing(); |