summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJohan Klokkhammer Helsing <johan.helsing@qt.io>2018-02-19 15:28:01 +0100
committerJohan Helsing <johan.helsing@qt.io>2018-02-26 11:19:37 +0000
commit5b69d5f05fdf187ae8a5f08e9a57375cbbd7f142 (patch)
tree5db8f7de8dc1006b69bc387d6ec2a750f0343d01 /tests
parentec495c98189f1d849e793108b09b5af0ce2c8984 (diff)
Client tests: Use generated classes for mocking shells
Removes a lot of boiler-plate code and makes the two shells more similar. This also makes it easier to extend the shells with additional mocking functionality. Change-Id: I4a846b06eeda695527d7c5679df339beae983af6 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/client/shared/mockcompositor.cpp6
-rw-r--r--tests/auto/client/shared/mockcompositor.h6
-rw-r--r--tests/auto/client/shared/mockshell.cpp180
-rw-r--r--tests/auto/client/shared/mockwlshell.cpp52
-rw-r--r--tests/auto/client/shared/mockwlshell.h45
-rw-r--r--tests/auto/client/shared/mockxdgshellv6.cpp59
-rw-r--r--tests/auto/client/shared/mockxdgshellv6.h45
-rw-r--r--tests/auto/client/shared/shared.pri4
8 files changed, 160 insertions, 237 deletions
diff --git a/tests/auto/client/shared/mockcompositor.cpp b/tests/auto/client/shared/mockcompositor.cpp
index bdeca4e23..2f1d68b01 100644
--- a/tests/auto/client/shared/mockcompositor.cpp
+++ b/tests/auto/client/shared/mockcompositor.cpp
@@ -30,6 +30,8 @@
#include "mockinput.h"
#include "mockoutput.h"
#include "mocksurface.h"
+#include "mockwlshell.h"
+#include "mockxdgshellv6.h"
#include <wayland-xdg-shell-unstable-v6-server-protocol.h>
@@ -331,8 +333,8 @@ Compositor::Compositor()
m_touch = m_seat->touch();
m_outputs.append(new Output(m_display, QSize(1920, 1080), QPoint(0, 0)));
- wl_global_create(m_display, &wl_shell_interface, 1, this, bindShell);
- wl_global_create(m_display, &zxdg_shell_v6_interface, 1, this, bindXdgShellV6);
+ m_wlShell.reset(new WlShell(m_display));
+ m_xdgShellV6.reset(new XdgShellV6(m_display));
m_loop = wl_display_get_event_loop(m_display);
m_fd = wl_event_loop_get_fd(m_loop);
diff --git a/tests/auto/client/shared/mockcompositor.h b/tests/auto/client/shared/mockcompositor.h
index d4cf5f367..747da38fa 100644
--- a/tests/auto/client/shared/mockcompositor.h
+++ b/tests/auto/client/shared/mockcompositor.h
@@ -52,6 +52,8 @@ class Seat;
class DataDeviceManager;
class Surface;
class Output;
+class WlShell;
+class XdgShellV6;
class Compositor
{
@@ -98,8 +100,6 @@ public:
private:
static void bindCompositor(wl_client *client, void *data, uint32_t version, uint32_t id);
- static void bindShell(wl_client *client, void *data, uint32_t version, uint32_t id);
- static void bindXdgShellV6(wl_client *client, void *compositorData, uint32_t version, uint32_t id);
static Surface *resolveSurface(const QVariant &v);
static Output *resolveOutput(const QVariant &v);
@@ -121,6 +121,8 @@ private:
QScopedPointer<DataDeviceManager> m_data_device_manager;
QVector<Surface *> m_surfaces;
QVector<Output *> m_outputs;
+ QScopedPointer<WlShell> m_wlShell;
+ QScopedPointer<XdgShellV6> m_xdgShellV6;
};
void registerResource(wl_list *list, wl_resource *resource);
diff --git a/tests/auto/client/shared/mockshell.cpp b/tests/auto/client/shared/mockshell.cpp
deleted file mode 100644
index d5eede22e..000000000
--- a/tests/auto/client/shared/mockshell.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "mockcompositor.h"
-#include "mocksurface.h"
-
-namespace Impl {
-
-void shell_surface_pong(wl_client *client,
- wl_resource *surface_resource,
- uint32_t serial)
-{
- Q_UNUSED(client);
- Q_UNUSED(surface_resource);
- Q_UNUSED(serial);
-}
-
-void shell_surface_move(wl_client *client,
- wl_resource *surface_resource,
- wl_resource *input_device_resource,
- uint32_t time)
-{
- Q_UNUSED(client);
- Q_UNUSED(surface_resource);
- Q_UNUSED(input_device_resource);
- Q_UNUSED(time);
-}
-
-void shell_surface_resize(wl_client *client,
- wl_resource *surface_resource,
- wl_resource *input_device_resource,
- uint32_t time,
- uint32_t edges)
-{
- Q_UNUSED(client);
- Q_UNUSED(surface_resource);
- Q_UNUSED(input_device_resource);
- Q_UNUSED(time);
- Q_UNUSED(edges);
-
-}
-
-void shell_surface_set_toplevel(wl_client *client,
- wl_resource *surface_resource)
-{
- Q_UNUSED(client);
- Q_UNUSED(surface_resource);
-}
-
-void shell_surface_set_transient(wl_client *client,
- wl_resource *surface_resource,
- wl_resource *parent_surface_resource,
- int x,
- int y,
- uint32_t flags)
-{
-
- Q_UNUSED(client);
- Q_UNUSED(surface_resource);
- Q_UNUSED(parent_surface_resource);
- Q_UNUSED(x);
- Q_UNUSED(y);
- Q_UNUSED(flags);
-}
-
-void shell_surface_set_fullscreen(wl_client *client,
- wl_resource *surface_resource,
- uint32_t method,
- uint32_t framerate,
- wl_resource *output)
-{
- Q_UNUSED(client);
- Q_UNUSED(surface_resource);
- Q_UNUSED(method);
- Q_UNUSED(framerate);
- Q_UNUSED(output);
-}
-
-void shell_surface_set_popup(wl_client *client, wl_resource *resource,
- wl_resource *input_device, uint32_t time,
- wl_resource *parent,
- int32_t x, int32_t y,
- uint32_t flags)
-{
- Q_UNUSED(client);
- Q_UNUSED(resource);
- Q_UNUSED(input_device);
- Q_UNUSED(time);
- Q_UNUSED(parent);
- Q_UNUSED(x);
- Q_UNUSED(y);
- Q_UNUSED(flags);
-}
-
-void shell_surface_set_maximized(wl_client *client,
- wl_resource *surface_resource,
- wl_resource *output)
-{
- Q_UNUSED(client);
- Q_UNUSED(surface_resource);
- Q_UNUSED(output);
-}
-
-void shell_surface_set_title(wl_client *client,
- wl_resource *surface_resource,
- const char *title)
-{
- Q_UNUSED(client);
- Q_UNUSED(surface_resource);
- Q_UNUSED(title);
-}
-
-void shell_surface_set_class(wl_client *client,
- wl_resource *surface_resource,
- const char *class_)
-{
- Q_UNUSED(client);
- Q_UNUSED(surface_resource);
- Q_UNUSED(class_);
-}
-
-static void get_shell_surface(wl_client *client, wl_resource *compositorResource, uint32_t id, wl_resource *surfaceResource)
-{
- static const struct wl_shell_surface_interface shellSurfaceInterface = {
- shell_surface_pong,
- shell_surface_move,
- shell_surface_resize,
- shell_surface_set_toplevel,
- shell_surface_set_transient,
- shell_surface_set_fullscreen,
- shell_surface_set_popup,
- shell_surface_set_maximized,
- shell_surface_set_title,
- shell_surface_set_class
- };
-
- int version = wl_resource_get_version(compositorResource);
- wl_resource *shellSurface = wl_resource_create(client, &wl_shell_surface_interface, version, id);
- wl_resource_set_implementation(shellSurface, &shellSurfaceInterface, surfaceResource->data, nullptr);
- Surface *surf = Surface::fromResource(surfaceResource);
- surf->map();
-}
-
-void Compositor::bindShell(wl_client *client, void *compositorData, uint32_t version, uint32_t id)
-{
- static const struct wl_shell_interface shellInterface = {
- get_shell_surface
- };
-
- wl_resource *resource = wl_resource_create(client, &wl_shell_interface, static_cast<int>(version), id);
- wl_resource_set_implementation(resource, &shellInterface, compositorData, nullptr);
-}
-
-}
-
diff --git a/tests/auto/client/shared/mockwlshell.cpp b/tests/auto/client/shared/mockwlshell.cpp
new file mode 100644
index 000000000..b7700713f
--- /dev/null
+++ b/tests/auto/client/shared/mockwlshell.cpp
@@ -0,0 +1,52 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mockwlshell.h"
+#include "mocksurface.h"
+
+namespace Impl {
+
+class WlShellSurface : public QtWaylandServer::wl_shell_surface
+{
+public:
+ explicit WlShellSurface(::wl_client *client, int id, Surface *surface);
+ void shell_surface_destroy_resource(Resource *) override { delete this; }
+};
+
+WlShellSurface::WlShellSurface(wl_client *client, int id, Surface *surface)
+ : QtWaylandServer::wl_shell_surface(client, id, 1)
+{
+ surface->map();
+}
+
+void WlShell::shell_get_shell_surface(QtWaylandServer::wl_shell::Resource *resource, uint32_t id, wl_resource *surface)
+{
+ new WlShellSurface(resource->client(), id, Surface::fromResource(surface));
+}
+
+} // namespace Impl
diff --git a/tests/auto/client/shared/mockwlshell.h b/tests/auto/client/shared/mockwlshell.h
new file mode 100644
index 000000000..c6000c7b2
--- /dev/null
+++ b/tests/auto/client/shared/mockwlshell.h
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qwayland-server-wayland.h>
+
+#ifndef MOCKWLSHELL_H
+#define MOCKWLSHELL_H
+
+namespace Impl {
+
+class WlShell : public QtWaylandServer::wl_shell
+{
+public:
+ explicit WlShell(::wl_display *display) : wl_shell(display, 1) {}
+ void shell_get_shell_surface(Resource *resource, uint32_t id, ::wl_resource *surface) override;
+};
+
+} // namespace Impl
+
+#endif // MOCKWLSHELL_H
diff --git a/tests/auto/client/shared/mockxdgshellv6.cpp b/tests/auto/client/shared/mockxdgshellv6.cpp
index b26ac1c8d..f909fa108 100644
--- a/tests/auto/client/shared/mockxdgshellv6.cpp
+++ b/tests/auto/client/shared/mockxdgshellv6.cpp
@@ -26,11 +26,9 @@
**
****************************************************************************/
-#include "mockcompositor.h"
+#include "mockxdgshellv6.h"
#include "mocksurface.h"
-#include <qwayland-server-xdg-shell-unstable-v6.h>
-
namespace Impl {
class XdgSurfaceV6;
@@ -50,7 +48,7 @@ public:
class XdgSurfaceV6 : public QtWaylandServer::zxdg_surface_v6
{
public:
- XdgSurfaceV6(wl_client *client, uint32_t id, int version, Surface *surface);
+ XdgSurfaceV6(wl_client *client, uint32_t id, Surface *surface);
void zxdg_surface_v6_destroy_resource(Resource *) override { delete this; }
void zxdg_surface_v6_get_toplevel(Resource *resource, uint32_t id) override;
void zxdg_surface_v6_destroy(Resource *resource) override
@@ -68,8 +66,8 @@ void XdgToplevelV6::zxdg_toplevel_v6_destroy(QtWaylandServer::zxdg_toplevel_v6::
wl_resource_destroy(resource->handle);
}
-XdgSurfaceV6::XdgSurfaceV6(wl_client *client, uint32_t id, int version, Surface *surface)
- : QtWaylandServer::zxdg_surface_v6(client, id, version)
+XdgSurfaceV6::XdgSurfaceV6(wl_client *client, uint32_t id, Surface *surface)
+ : QtWaylandServer::zxdg_surface_v6(client, id, 1)
, m_surface(surface)
{
}
@@ -81,52 +79,9 @@ void XdgSurfaceV6::zxdg_surface_v6_get_toplevel(QtWaylandServer::zxdg_surface_v6
m_surface->map();
}
-
-void shell_destroy(struct wl_client *client,
- struct wl_resource *resource)
-{
- Q_UNUSED(client);
- Q_UNUSED(resource);
-}
-
-void create_positioner(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id)
-{
- Q_UNUSED(client);
- Q_UNUSED(resource);
- Q_UNUSED(id);
-}
-
-void get_xdg_surface(struct wl_client *client,
- struct wl_resource *compositorResource,
- uint32_t id,
- struct wl_resource *surfaceResource)
+void Impl::XdgShellV6::zxdg_shell_v6_get_xdg_surface(QtWaylandServer::zxdg_shell_v6::Resource *resource, uint32_t id, wl_resource *surface)
{
- int version = wl_resource_get_version(compositorResource);
- new XdgSurfaceV6(client, id, version, Surface::fromResource(surfaceResource));
+ new XdgSurfaceV6(resource->client(), id, Surface::fromResource(surface));
}
-void pong(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t serial)
-{
- Q_UNUSED(client);
- Q_UNUSED(resource);
- Q_UNUSED(serial);
-}
-
-void Compositor::bindXdgShellV6(wl_client *client, void *compositorData, uint32_t version, uint32_t id)
-{
- static const struct zxdg_shell_v6_interface shellInterface = {
- shell_destroy,
- create_positioner,
- get_xdg_surface,
- pong
- };
-
- wl_resource *resource = wl_resource_create(client, &zxdg_shell_v6_interface, static_cast<int>(version), id);
- wl_resource_set_implementation(resource, &shellInterface, compositorData, nullptr);
-}
-
-}
+} // namespace Impl
diff --git a/tests/auto/client/shared/mockxdgshellv6.h b/tests/auto/client/shared/mockxdgshellv6.h
new file mode 100644
index 000000000..d72606d24
--- /dev/null
+++ b/tests/auto/client/shared/mockxdgshellv6.h
@@ -0,0 +1,45 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qwayland-server-xdg-shell-unstable-v6.h>
+
+#ifndef MOCKXDGSHELLV6_H
+#define MOCKXDGSHELLV6_H
+
+namespace Impl {
+
+class XdgShellV6 : public QtWaylandServer::zxdg_shell_v6
+{
+public:
+ explicit XdgShellV6(::wl_display *display) : zxdg_shell_v6(display, 1) {}
+ void zxdg_shell_v6_get_xdg_surface(Resource *resource, uint32_t id, ::wl_resource *surface) override;
+};
+
+} // namespace Impl
+
+#endif // MOCKXDGSHELLV6_H
diff --git a/tests/auto/client/shared/shared.pri b/tests/auto/client/shared/shared.pri
index 608664bb7..991dd29d1 100644
--- a/tests/auto/client/shared/shared.pri
+++ b/tests/auto/client/shared/shared.pri
@@ -14,7 +14,7 @@ INCLUDEPATH += ../shared
SOURCES += \
../shared/mockcompositor.cpp \
../shared/mockinput.cpp \
- ../shared/mockshell.cpp \
+ ../shared/mockwlshell.cpp \
../shared/mockxdgshellv6.cpp \
../shared/mocksurface.cpp \
../shared/mockoutput.cpp
@@ -22,5 +22,7 @@ SOURCES += \
HEADERS += \
../shared/mockcompositor.h \
../shared/mockinput.h \
+ ../shared/mockwlshell.h \
+ ../shared/mockxdgshellv6.h \
../shared/mocksurface.h \
../shared/mockoutput.h