diff options
author | Johan Klokkhammer Helsing <johan.helsing@theqtcompany.com> | 2016-03-31 16:17:30 +0200 |
---|---|---|
committer | Giulio Camuffo <giulio.camuffo@kdab.com> | 2016-04-11 06:24:22 +0000 |
commit | f2e42b438d221ab007e9d3a0cbac1d34634b66e6 (patch) | |
tree | 0e7ec81a4076a6a4464c0acf907120abc6e67df8 | |
parent | 0b16a83b9d292d98d0ef6d2541af0eb58a8504f2 (diff) |
Add basic tests for xdg-shell compositor API
Tests the following functionality:
* xdg_shell can be found and bound using the registry
* xdg_surfaces can be created
* window geometry is handled correctly (not including subsurfaces)
* app_id
Change-Id: I76942da2b245f91fe567059e175fe9ceb98edb6a
Reviewed-by: Giulio Camuffo <giulio.camuffo@kdab.com>
-rw-r--r-- | tests/auto/compositor/compositor.pro | 4 | ||||
-rw-r--r-- | tests/auto/compositor/mockclient.cpp | 9 | ||||
-rw-r--r-- | tests/auto/compositor/mockclient.h | 3 | ||||
-rw-r--r-- | tests/auto/compositor/tst_compositor.cpp | 103 |
4 files changed, 114 insertions, 5 deletions
diff --git a/tests/auto/compositor/compositor.pro b/tests/auto/compositor/compositor.pro index d5094d87b..9f9044fdf 100644 --- a/tests/auto/compositor/compositor.pro +++ b/tests/auto/compositor/compositor.pro @@ -1,4 +1,5 @@ CONFIG += testcase link_pkgconfig +CONFIG += wayland-scanner TARGET = tst_compositor QT += testlib @@ -20,6 +21,9 @@ config_xkbcommon { DEFINES += QT_NO_WAYLAND_XKB } +WAYLANDCLIENTSOURCES += \ + ../../../src/3rdparty/protocol/xdg-shell.xml \ + SOURCES += tst_compositor.cpp \ testcompositor.cpp \ testkeyboardgrabber.cpp \ diff --git a/tests/auto/compositor/mockclient.cpp b/tests/auto/compositor/mockclient.cpp index d4765b894..9b6d327a9 100644 --- a/tests/auto/compositor/mockclient.cpp +++ b/tests/auto/compositor/mockclient.cpp @@ -50,6 +50,7 @@ MockClient::MockClient() , output(0) , registry(0) , wlshell(0) + , xdgShell(nullptr) { if (!display) qFatal("MockClient(): wl_display_connect() failed"); @@ -143,6 +144,8 @@ void MockClient::handleGlobal(uint32_t id, const QByteArray &interface) shm = static_cast<wl_shm *>(wl_registry_bind(registry, id, &wl_shm_interface, 1)); } else if (interface == "wl_shell") { wlshell = static_cast<wl_shell *>(wl_registry_bind(registry, id, &wl_shell_interface, 1)); + } else if (interface == "xdg_shell") { + xdgShell = static_cast<xdg_shell *>(wl_registry_bind(registry, id, &xdg_shell_interface, 1)); } else if (interface == "wl_seat") { wl_seat *s = static_cast<wl_seat *>(wl_registry_bind(registry, id, &wl_seat_interface, 1)); m_seats << new MockSeat(s); @@ -161,6 +164,12 @@ wl_shell_surface *MockClient::createShellSurface(wl_surface *surface) return wl_shell_get_shell_surface(wlshell, surface); } +xdg_surface *MockClient::createXdgSurface(wl_surface *surface) +{ + flushDisplay(); + return xdg_shell_get_xdg_surface(xdgShell, surface); +} + ShmBuffer::ShmBuffer(const QSize &size, wl_shm *shm) : handle(0) { diff --git a/tests/auto/compositor/mockclient.h b/tests/auto/compositor/mockclient.h index 3592227dc..33ada638a 100644 --- a/tests/auto/compositor/mockclient.h +++ b/tests/auto/compositor/mockclient.h @@ -27,6 +27,7 @@ ****************************************************************************/ #include <wayland-client.h> +#include <wayland-xdg-shell-client-protocol.h> #include <QObject> #include <QImage> @@ -56,6 +57,7 @@ public: wl_surface *createSurface(); wl_shell_surface *createShellSurface(wl_surface *surface); + xdg_surface *createXdgSurface(wl_surface *surface); wl_display *display; wl_compositor *compositor; @@ -63,6 +65,7 @@ public: wl_shm *shm; wl_registry *registry; wl_shell *wlshell; + xdg_shell *xdgShell; QList<MockSeat *> m_seats; diff --git a/tests/auto/compositor/tst_compositor.cpp b/tests/auto/compositor/tst_compositor.cpp index 0fc855c6e..5178357f6 100644 --- a/tests/auto/compositor/tst_compositor.cpp +++ b/tests/auto/compositor/tst_compositor.cpp @@ -35,18 +35,18 @@ #include "qwaylandbufferref.h" #include "qwaylandinput.h" +#include <QtWaylandCompositor/QWaylandXdgShell> +#include <QtWaylandCompositor/QWaylandSurface> +#include <QtWaylandCompositor/QWaylandResource> + #include <QtTest/QtTest> class tst_WaylandCompositor : public QObject { Q_OBJECT -public: - tst_WaylandCompositor() { - setenv("XDG_RUNTIME_DIR", ".", 1); - } - private slots: + void init(); void inputDeviceCapabilities(); void keyboardGrab(); void inputDeviceCreation(); @@ -56,8 +56,16 @@ private slots: void geometry(); void mapSurface(); void frameCallback(); + void advertisesXdgShellSupport(); + void createsXdgSurfaces(); + void reportsXdgSurfaceWindowGeometry(); + void setsXdgAppId(); }; +void tst_WaylandCompositor::init() { + qputenv("XDG_RUNTIME_DIR", "."); +} + void tst_WaylandCompositor::singleClient() { TestCompositor compositor; @@ -365,5 +373,90 @@ void tst_WaylandCompositor::inputDeviceKeyboardFocus() QTRY_VERIFY(!compositor.defaultInputDevice()->keyboardFocus()); } +class XdgTestCompositor: public TestCompositor { + Q_OBJECT +public: + XdgTestCompositor() : xdgShell(this) {} + QWaylandXdgShell xdgShell; +}; + +void tst_WaylandCompositor::advertisesXdgShellSupport() +{ + XdgTestCompositor compositor; + compositor.create(); + + MockClient client; + QTRY_VERIFY(&client.xdgShell); +} + +void tst_WaylandCompositor::createsXdgSurfaces() +{ + XdgTestCompositor compositor; + compositor.create(); + + MockClient client; + QTRY_VERIFY(&client.xdgShell); + + QSignalSpy xdgSurfaceCreatedSpy(&compositor.xdgShell, &QWaylandXdgShell::xdgSurfaceCreated); + QWaylandXdgSurface *xdgSurface = nullptr; + QObject::connect(&compositor.xdgShell, &QWaylandXdgShell::xdgSurfaceCreated, [&](QWaylandXdgSurface *s) { + xdgSurface = s; + }); + + wl_surface *surface = client.createSurface(); + client.createXdgSurface(surface); + QTRY_COMPARE(xdgSurfaceCreatedSpy.count(), 1); + QTRY_VERIFY(xdgSurface); + QTRY_VERIFY(xdgSurface->surface()); +} + +void tst_WaylandCompositor::reportsXdgSurfaceWindowGeometry() +{ + XdgTestCompositor compositor; + compositor.create(); + + QWaylandXdgSurface *xdgSurface = nullptr; + QObject::connect(&compositor.xdgShell, &QWaylandXdgShell::xdgSurfaceCreated, [&](QWaylandXdgSurface *s) { + xdgSurface = s; + }); + + MockClient client; + wl_surface *surface = client.createSurface(); + xdg_surface *clientXdgSurface = client.createXdgSurface(surface); + QSize size(256, 256); + ShmBuffer buffer(size, client.shm); + wl_surface_attach(surface, buffer.handle, 0, 0); + wl_surface_damage(surface, 0, 0, size.width(), size.height()); + wl_surface_commit(surface); + + QTRY_VERIFY(xdgSurface); + QTRY_COMPARE(xdgSurface->windowGeometry(), QRect(QPoint(0, 0), QSize(256, 256))); + + xdg_surface_set_window_geometry(clientXdgSurface, 10, 20, 100, 50); + wl_surface_commit(surface); + + QTRY_COMPARE(xdgSurface->windowGeometry(), QRect(QPoint(10, 20), QSize(100, 50))); +} + +void tst_WaylandCompositor::setsXdgAppId() +{ + XdgTestCompositor compositor; + compositor.create(); + + QWaylandXdgSurface *xdgSurface = nullptr; + QObject::connect(&compositor.xdgShell, &QWaylandXdgShell::xdgSurfaceCreated, [&](QWaylandXdgSurface *s) { + xdgSurface = s; + }); + + MockClient client; + wl_surface *surface = client.createSurface(); + xdg_surface *clientXdgSurface = client.createXdgSurface(surface); + + xdg_surface_set_app_id(clientXdgSurface, "org.foo.bar"); + + QTRY_VERIFY(xdgSurface); + QTRY_COMPARE(xdgSurface->appId(), QString("org.foo.bar")); +} + #include <tst_compositor.moc> QTEST_MAIN(tst_WaylandCompositor); |