diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2016-04-20 10:41:20 +0200 |
---|---|---|
committer | Johan Helsing <johan.helsing@qt.io> | 2016-09-30 13:55:30 +0000 |
commit | f7896fdc6505d8c6f3b3a239884dadab034e1fb5 (patch) | |
tree | 11f73dd52db4ecf33d5289b234f72500bd3c8a91 /tests | |
parent | 863bf669ed0b8fce782c177dfcfa1702fc28196a (diff) | |
download | qtwayland-f7896fdc6505d8c6f3b3a239884dadab034e1fb5.tar.gz |
C++ API and tests for the ivi-application extension
Note, this is only an implementation of the ivi-application extension,
not ivi-controller which contains layer management interfaces.
Task-number: QTBUG-53149
Change-Id: Ic5a31156de1768f846b714a9aee9bbf8a945cbbe
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/compositor/compositor/compositor.pro | 1 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/mockclient.cpp | 29 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/mockclient.h | 9 | ||||
-rw-r--r-- | tests/auto/compositor/compositor/tst_compositor.cpp | 154 |
4 files changed, 192 insertions, 1 deletions
diff --git a/tests/auto/compositor/compositor/compositor.pro b/tests/auto/compositor/compositor/compositor.pro index a3748697..1d4456f6 100644 --- a/tests/auto/compositor/compositor/compositor.pro +++ b/tests/auto/compositor/compositor/compositor.pro @@ -23,6 +23,7 @@ config_xkbcommon { WAYLANDCLIENTSOURCES += \ ../../../../src/3rdparty/protocol/xdg-shell.xml \ + ../../../../src/3rdparty/protocol/ivi-application.xml \ SOURCES += \ tst_compositor.cpp \ diff --git a/tests/auto/compositor/compositor/mockclient.cpp b/tests/auto/compositor/compositor/mockclient.cpp index 9b6d327a..f2fbc5de 100644 --- a/tests/auto/compositor/compositor/mockclient.cpp +++ b/tests/auto/compositor/compositor/mockclient.cpp @@ -51,6 +51,9 @@ MockClient::MockClient() , registry(0) , wlshell(0) , xdgShell(nullptr) + , iviApplication(nullptr) + , error(0 /* means no error according to spec */) + , protocolError({0, 0, nullptr}) { if (!display) qFatal("MockClient(): wl_display_connect() failed"); @@ -117,12 +120,28 @@ void MockClient::outputScale(void *, wl_output *, int) void MockClient::readEvents() { + if (error) + return; wl_display_dispatch(display); } void MockClient::flushDisplay() { - wl_display_dispatch_pending(display); + if (error) + return; + + if (wl_display_prepare_read(display) == 0) { + wl_display_read_events(display); + } + + if (wl_display_dispatch_pending(display) < 0) { + error = wl_display_get_error(display); + if (error == EPROTO) { + protocolError.code = wl_display_get_protocol_error(display, &protocolError.interface, &protocolError.id); + return; + } + } + wl_display_flush(display); } @@ -146,6 +165,8 @@ void MockClient::handleGlobal(uint32_t id, const QByteArray &interface) 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 == "ivi_application") { + iviApplication = static_cast<ivi_application *>(wl_registry_bind(registry, id, &ivi_application_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); @@ -170,6 +191,12 @@ xdg_surface *MockClient::createXdgSurface(wl_surface *surface) return xdg_shell_get_xdg_surface(xdgShell, surface); } +ivi_surface *MockClient::createIviSurface(wl_surface *surface, uint iviId) +{ + flushDisplay(); + return ivi_application_surface_create(iviApplication, iviId, surface); +} + ShmBuffer::ShmBuffer(const QSize &size, wl_shm *shm) : handle(0) { diff --git a/tests/auto/compositor/compositor/mockclient.h b/tests/auto/compositor/compositor/mockclient.h index 33ada638..ed9319af 100644 --- a/tests/auto/compositor/compositor/mockclient.h +++ b/tests/auto/compositor/compositor/mockclient.h @@ -28,6 +28,7 @@ #include <wayland-client.h> #include <wayland-xdg-shell-client-protocol.h> +#include <wayland-ivi-application-client-protocol.h> #include <QObject> #include <QImage> @@ -58,6 +59,7 @@ public: wl_surface *createSurface(); wl_shell_surface *createShellSurface(wl_surface *surface); xdg_surface *createXdgSurface(wl_surface *surface); + ivi_surface *createIviSurface(wl_surface *surface, uint iviId); wl_display *display; wl_compositor *compositor; @@ -66,12 +68,19 @@ public: wl_registry *registry; wl_shell *wlshell; xdg_shell *xdgShell; + ivi_application *iviApplication; QList<MockSeat *> m_seats; QRect geometry; int fd; + int error; + struct { + uint id; + uint code; + const wl_interface *interface; + } protocolError; private slots: void readEvents(); diff --git a/tests/auto/compositor/compositor/tst_compositor.cpp b/tests/auto/compositor/compositor/tst_compositor.cpp index d6c72b34..3052b7b4 100644 --- a/tests/auto/compositor/compositor/tst_compositor.cpp +++ b/tests/auto/compositor/compositor/tst_compositor.cpp @@ -36,9 +36,12 @@ #include "qwaylandseat.h" #include <QtWaylandCompositor/QWaylandXdgShellV5> +#include <QtWaylandCompositor/QWaylandIviApplication> +#include <QtWaylandCompositor/QWaylandIviSurface> #include <QtWaylandCompositor/QWaylandSurface> #include <QtWaylandCompositor/QWaylandResource> #include <qwayland-xdg-shell.h> +#include <qwayland-ivi-application.h> #include <QtTest/QtTest> @@ -57,11 +60,18 @@ private slots: void geometry(); void mapSurface(); void frameCallback(); + void advertisesXdgShellSupport(); void createsXdgSurfaces(); void reportsXdgSurfaceWindowGeometry(); void setsXdgAppId(); void sendsXdgConfigure(); + + void advertisesIviApplicationSupport(); + void createsIviSurfaces(); + void emitsErrorOnSameIviId(); + void sendsIviConfigure(); + void destroysIviSurfaces(); }; void tst_WaylandCompositor::init() { @@ -572,5 +582,149 @@ void tst_WaylandCompositor::sendsXdgConfigure() QTRY_VERIFY(!xdgSurface->resizing()); } +class IviTestCompositor: public TestCompositor { + Q_OBJECT +public: + IviTestCompositor() : iviApplication(this) {} + QWaylandIviApplication iviApplication; +}; + +void tst_WaylandCompositor::advertisesIviApplicationSupport() +{ + IviTestCompositor compositor; + compositor.create(); + + MockClient client; + QTRY_VERIFY(&client.iviApplication); +} + +void tst_WaylandCompositor::createsIviSurfaces() +{ + IviTestCompositor compositor; + compositor.create(); + + MockClient client; + QTRY_VERIFY(&client.iviApplication); + + QSignalSpy iviSurfaceCreatedSpy(&compositor.iviApplication, &QWaylandIviApplication::iviSurfaceRequested); + QWaylandIviSurface *iviSurface = nullptr; + QObject::connect(&compositor.iviApplication, &QWaylandIviApplication::iviSurfaceCreated, [&](QWaylandIviSurface *s) { + iviSurface = s; + }); + + wl_surface *surface = client.createSurface(); + client.createIviSurface(surface, 123); + QTRY_COMPARE(iviSurfaceCreatedSpy.count(), 1); + QTRY_VERIFY(iviSurface); + QTRY_VERIFY(iviSurface->surface()); + QTRY_COMPARE(iviSurface->iviId(), 123u); +} + +void tst_WaylandCompositor::emitsErrorOnSameIviId() +{ + IviTestCompositor compositor; + compositor.create(); + + { + MockClient firstClient; + QTRY_VERIFY(&firstClient.iviApplication); + + QWaylandIviSurface *firstIviSurface = nullptr; + QObject::connect(&compositor.iviApplication, &QWaylandIviApplication::iviSurfaceCreated, [&](QWaylandIviSurface *s) { + firstIviSurface = s; + }); + + firstClient.createIviSurface(firstClient.createSurface(), 123); + QTRY_VERIFY(firstIviSurface); + QTRY_COMPARE(firstIviSurface->iviId(), 123u); + + { + MockClient secondClient; + QTRY_VERIFY(&secondClient.iviApplication); + QTRY_COMPARE(compositor.clients().count(), 2); + + secondClient.createIviSurface(secondClient.createSurface(), 123); + compositor.flushClients(); + + QTRY_COMPARE(secondClient.error, EPROTO); + QTRY_COMPARE(secondClient.protocolError.interface, &ivi_application_interface); + QTRY_COMPARE(static_cast<ivi_application_error>(secondClient.protocolError.code), IVI_APPLICATION_ERROR_IVI_ID); + QTRY_COMPARE(compositor.clients().count(), 1); + } + } + + // The other clients have passed out of scope and have been destroyed, + // it should now be ok to create new application with the same id + MockClient thirdClient; + QTRY_VERIFY(&thirdClient.iviApplication); + + QWaylandIviSurface *thirdIviSurface = nullptr; + QObject::connect(&compositor.iviApplication, &QWaylandIviApplication::iviSurfaceCreated, [&](QWaylandIviSurface *s) { + thirdIviSurface = s; + }); + thirdClient.createIviSurface(thirdClient.createSurface(), 123); + compositor.flushClients(); + + QTRY_VERIFY(thirdIviSurface); + QTRY_COMPARE(thirdIviSurface->iviId(), 123u); + QTRY_COMPARE(thirdClient.error, 0); +} + +void tst_WaylandCompositor::sendsIviConfigure() +{ + class MockIviSurface : public QtWayland::ivi_surface + { + public: + MockIviSurface(::ivi_surface *iviSurface) : QtWayland::ivi_surface(iviSurface) {} + void ivi_surface_configure(int32_t width, int32_t height) Q_DECL_OVERRIDE + { + configureSize = QSize(width, height); + } + QSize configureSize; + }; + + IviTestCompositor compositor; + compositor.create(); + + MockClient client; + QTRY_VERIFY(&client.iviApplication); + + QWaylandIviSurface *iviSurface = nullptr; + QObject::connect(&compositor.iviApplication, &QWaylandIviApplication::iviSurfaceCreated, [&](QWaylandIviSurface *s) { + iviSurface = s; + }); + + wl_surface *surface = client.createSurface(); + ivi_surface *clientIviSurface = client.createIviSurface(surface, 123); + MockIviSurface mockIviSurface(clientIviSurface); + + QTRY_VERIFY(iviSurface); + iviSurface->sendConfigure(QSize(800, 600)); + compositor.flushClients(); + + QTRY_COMPARE(mockIviSurface.configureSize, QSize(800, 600)); +} + +void tst_WaylandCompositor::destroysIviSurfaces() +{ + IviTestCompositor compositor; + compositor.create(); + + MockClient client; + QTRY_VERIFY(&client.iviApplication); + + QWaylandIviSurface *iviSurface = nullptr; + QObject::connect(&compositor.iviApplication, &QWaylandIviApplication::iviSurfaceCreated, [&](QWaylandIviSurface *s) { + iviSurface = s; + }); + + QtWayland::ivi_surface mockIviSurface(client.createIviSurface(client.createSurface(), 123)); + QTRY_VERIFY(iviSurface); + + QSignalSpy destroySpy(iviSurface, SIGNAL(destroyed())); + mockIviSurface.destroy(); + QTRY_VERIFY(destroySpy.count() == 1); +} + #include <tst_compositor.moc> QTEST_MAIN(tst_WaylandCompositor); |