summaryrefslogtreecommitdiffstats
path: root/tests/auto/client/client
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/client/client')
-rw-r--r--tests/auto/client/client/client.pro28
-rw-r--r--tests/auto/client/client/mockcompositor.cpp372
-rw-r--r--tests/auto/client/client/mockcompositor.h203
-rw-r--r--tests/auto/client/client/mockinput.cpp462
-rw-r--r--tests/auto/client/client/mockinput.h170
-rw-r--r--tests/auto/client/client/mockoutput.cpp67
-rw-r--r--tests/auto/client/client/mockshell.cpp180
-rw-r--r--tests/auto/client/client/mocksurface.cpp138
-rw-r--r--tests/auto/client/client/mocksurface.h71
-rw-r--r--tests/auto/client/client/tst_client.cpp355
10 files changed, 2046 insertions, 0 deletions
diff --git a/tests/auto/client/client/client.pro b/tests/auto/client/client/client.pro
new file mode 100644
index 000000000..006d130a0
--- /dev/null
+++ b/tests/auto/client/client/client.pro
@@ -0,0 +1,28 @@
+CONFIG += testcase link_pkgconfig
+TARGET = tst_client
+
+QT += testlib
+QT += core-private gui-private
+
+!contains(QT_CONFIG, no-pkg-config) {
+ PKGCONFIG += wayland-client wayland-server
+} else {
+ LIBS += -lwayland-client -lwayland-server
+}
+
+CONFIG += wayland-scanner
+WAYLANDSERVERSOURCES += \
+ ../../../../src/3rdparty/protocol/wayland.xml
+
+SOURCES += \
+ tst_client.cpp \
+ mockcompositor.cpp \
+ mockinput.cpp \
+ mockshell.cpp \
+ mocksurface.cpp \
+ mockoutput.cpp
+
+HEADERS += \
+ mockcompositor.h \
+ mockinput.h \
+ mocksurface.h
diff --git a/tests/auto/client/client/mockcompositor.cpp b/tests/auto/client/client/mockcompositor.cpp
new file mode 100644
index 000000000..45a35ea7d
--- /dev/null
+++ b/tests/auto/client/client/mockcompositor.cpp
@@ -0,0 +1,372 @@
+/****************************************************************************
+**
+** 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 "mockinput.h"
+#include "mocksurface.h"
+
+#include <stdio.h>
+MockCompositor::MockCompositor()
+ : m_alive(true)
+ , m_ready(false)
+ , m_compositor(0)
+{
+ pthread_create(&m_thread, 0, run, this);
+
+ m_mutex.lock();
+ m_waitCondition.wait(&m_mutex);
+ m_mutex.unlock();
+}
+
+MockCompositor::~MockCompositor()
+{
+ m_alive = false;
+ m_waitCondition.wakeOne();
+ pthread_join(m_thread, 0);
+}
+
+void MockCompositor::lock()
+{
+ m_mutex.lock();
+}
+
+void MockCompositor::unlock()
+{
+ m_mutex.unlock();
+}
+
+void MockCompositor::applicationInitialized()
+{
+ m_ready = true;
+}
+
+int MockCompositor::waylandFileDescriptor() const
+{
+ return m_compositor->fileDescriptor();
+}
+
+void MockCompositor::processWaylandEvents()
+{
+ m_waitCondition.wakeOne();
+}
+
+void MockCompositor::setOutputGeometry(const QRect &rect)
+{
+ Command command = makeCommand(Impl::Compositor::setOutputGeometry, m_compositor);
+ command.parameters << rect;
+ processCommand(command);
+}
+
+void MockCompositor::setKeyboardFocus(const QSharedPointer<MockSurface> &surface)
+{
+ Command command = makeCommand(Impl::Compositor::setKeyboardFocus, m_compositor);
+ command.parameters << QVariant::fromValue(surface);
+ processCommand(command);
+}
+
+void MockCompositor::sendMousePress(const QSharedPointer<MockSurface> &surface, const QPoint &pos)
+{
+ Command command = makeCommand(Impl::Compositor::sendMousePress, m_compositor);
+ command.parameters << QVariant::fromValue(surface) << pos;
+ processCommand(command);
+}
+
+void MockCompositor::sendMouseRelease(const QSharedPointer<MockSurface> &surface)
+{
+ Command command = makeCommand(Impl::Compositor::sendMouseRelease, m_compositor);
+ command.parameters << QVariant::fromValue(surface);
+ processCommand(command);
+}
+
+void MockCompositor::sendKeyPress(const QSharedPointer<MockSurface> &surface, uint code)
+{
+ Command command = makeCommand(Impl::Compositor::sendKeyPress, m_compositor);
+ command.parameters << QVariant::fromValue(surface) << code;
+ processCommand(command);
+}
+
+void MockCompositor::sendKeyRelease(const QSharedPointer<MockSurface> &surface, uint code)
+{
+ Command command = makeCommand(Impl::Compositor::sendKeyRelease, m_compositor);
+ command.parameters << QVariant::fromValue(surface) << code;
+ processCommand(command);
+}
+
+void MockCompositor::sendTouchDown(const QSharedPointer<MockSurface> &surface, const QPoint &position, int id)
+{
+ Command command = makeCommand(Impl::Compositor::sendTouchDown, m_compositor);
+ command.parameters << QVariant::fromValue(surface) << position << id;
+ processCommand(command);
+}
+
+void MockCompositor::sendTouchMotion(const QSharedPointer<MockSurface> &surface, const QPoint &position, int id)
+{
+ Command command = makeCommand(Impl::Compositor::sendTouchMotion, m_compositor);
+ command.parameters << QVariant::fromValue(surface) << position << id;
+ processCommand(command);
+}
+
+void MockCompositor::sendTouchUp(const QSharedPointer<MockSurface> &surface, int id)
+{
+ Command command = makeCommand(Impl::Compositor::sendTouchUp, m_compositor);
+ command.parameters << QVariant::fromValue(surface) << id;
+ processCommand(command);
+}
+
+void MockCompositor::sendTouchFrame(const QSharedPointer<MockSurface> &surface)
+{
+ Command command = makeCommand(Impl::Compositor::sendTouchFrame, m_compositor);
+ command.parameters << QVariant::fromValue(surface);
+ processCommand(command);
+}
+
+void MockCompositor::sendDataDeviceDataOffer(const QSharedPointer<MockSurface> &surface)
+{
+ Command command = makeCommand(Impl::Compositor::sendDataDeviceDataOffer, m_compositor);
+ command.parameters << QVariant::fromValue(surface);
+ processCommand(command);
+}
+
+void MockCompositor::sendDataDeviceEnter(const QSharedPointer<MockSurface> &surface, const QPoint& position)
+{
+ Command command = makeCommand(Impl::Compositor::sendDataDeviceEnter, m_compositor);
+ command.parameters << QVariant::fromValue(surface) << QVariant::fromValue(position);
+ processCommand(command);
+}
+
+void MockCompositor::sendDataDeviceMotion(const QPoint &position)
+{
+ Command command = makeCommand(Impl::Compositor::sendDataDeviceMotion, m_compositor);
+ command.parameters << QVariant::fromValue(position);
+ processCommand(command);
+}
+
+void MockCompositor::sendDataDeviceDrop(const QSharedPointer<MockSurface> &surface)
+{
+ Command command = makeCommand(Impl::Compositor::sendDataDeviceDrop, m_compositor);
+ command.parameters << QVariant::fromValue(surface);
+ processCommand(command);
+}
+
+void MockCompositor::sendDataDeviceLeave(const QSharedPointer<MockSurface> &surface)
+{
+ Command command = makeCommand(Impl::Compositor::sendDataDeviceLeave, m_compositor);
+ command.parameters << QVariant::fromValue(surface);
+ processCommand(command);
+}
+
+void MockCompositor::waitForStartDrag()
+{
+ Command command = makeCommand(Impl::Compositor::waitForStartDrag, m_compositor);
+ processCommand(command);
+}
+
+QSharedPointer<MockSurface> MockCompositor::surface()
+{
+ QSharedPointer<MockSurface> result;
+ lock();
+ QVector<Impl::Surface *> surfaces = m_compositor->surfaces();
+ foreach (Impl::Surface *surface, surfaces) {
+ // we don't want to mistake the cursor surface for a window surface
+ if (surface->isMapped()) {
+ result = surface->mockSurface();
+ break;
+ }
+ }
+ unlock();
+ return result;
+}
+
+MockCompositor::Command MockCompositor::makeCommand(Command::Callback callback, void *target)
+{
+ Command command;
+ command.callback = callback;
+ command.target = target;
+ return command;
+}
+
+void MockCompositor::processCommand(const Command &command)
+{
+ lock();
+ m_commandQueue << command;
+ unlock();
+
+ m_waitCondition.wakeOne();
+}
+
+void MockCompositor::dispatchCommands()
+{
+ lock();
+ int count = m_commandQueue.length();
+ unlock();
+
+ for (int i = 0; i < count; ++i) {
+ lock();
+ const Command command = m_commandQueue.takeFirst();
+ unlock();
+ command.callback(command.target, command.parameters);
+ }
+}
+
+void *MockCompositor::run(void *data)
+{
+ MockCompositor *controller = static_cast<MockCompositor *>(data);
+
+ Impl::Compositor compositor;
+
+ controller->m_compositor = &compositor;
+ controller->m_waitCondition.wakeOne();
+
+ while (!controller->m_ready) {
+ controller->dispatchCommands();
+ compositor.dispatchEvents(20);
+ }
+
+ while (controller->m_alive) {
+ {
+ QMutexLocker locker(&controller->m_mutex);
+ if (controller->m_commandQueue.isEmpty())
+ controller->m_waitCondition.wait(&controller->m_mutex);
+ }
+ controller->dispatchCommands();
+ compositor.dispatchEvents(20);
+ }
+
+ return 0;
+}
+
+namespace Impl {
+
+Compositor::Compositor()
+ : m_display(wl_display_create())
+ , m_startDragSeen(false)
+ , m_time(0)
+{
+ wl_list_init(&m_outputResources);
+
+ if (wl_display_add_socket(m_display, 0)) {
+ fprintf(stderr, "Fatal: Failed to open server socket\n");
+ exit(EXIT_FAILURE);
+ }
+
+ wl_global_create(m_display, &wl_compositor_interface, 1, this, bindCompositor);
+
+ m_data_device_manager.reset(new DataDeviceManager(this, m_display));
+
+ wl_display_init_shm(m_display);
+
+ m_seat.reset(new Seat(this, m_display));
+ m_pointer = m_seat->pointer();
+ m_keyboard = m_seat->keyboard();
+ m_touch = m_seat->touch();
+
+ wl_global_create(m_display, &wl_output_interface, 1, this, bindOutput);
+ wl_global_create(m_display, &wl_shell_interface, 1, this, bindShell);
+
+ m_loop = wl_display_get_event_loop(m_display);
+ m_fd = wl_event_loop_get_fd(m_loop);
+}
+
+Compositor::~Compositor()
+{
+ wl_display_destroy(m_display);
+}
+
+void Compositor::dispatchEvents(int timeout)
+{
+ wl_display_flush_clients(m_display);
+ wl_event_loop_dispatch(m_loop, timeout);
+}
+
+static void compositor_create_surface(wl_client *client, wl_resource *compositorResource, uint32_t id)
+{
+ Compositor *compositor = static_cast<Compositor *>(compositorResource->data);
+ compositor->addSurface(new Surface(client, id, wl_resource_get_version(compositorResource), compositor));
+}
+
+static void compositor_create_region(wl_client *client, wl_resource *compositorResource, uint32_t id)
+{
+ Q_UNUSED(client);
+ Q_UNUSED(compositorResource);
+ Q_UNUSED(id);
+}
+
+void Compositor::bindCompositor(wl_client *client, void *compositorData, uint32_t version, uint32_t id)
+{
+ static const struct wl_compositor_interface compositorInterface = {
+ compositor_create_surface,
+ compositor_create_region
+ };
+
+ wl_resource *resource = wl_resource_create(client, &wl_compositor_interface, static_cast<int>(version), id);
+ wl_resource_set_implementation(resource, &compositorInterface, compositorData, nullptr);
+}
+
+static void unregisterResourceCallback(wl_listener *listener, void *data)
+{
+ struct wl_resource *resource = reinterpret_cast<struct wl_resource *>(data);
+ wl_list_remove(&resource->link);
+ delete listener;
+}
+
+void registerResource(wl_list *list, wl_resource *resource)
+{
+ wl_list_insert(list, &resource->link);
+
+ wl_listener *listener = new wl_listener;
+ listener->notify = unregisterResourceCallback;
+
+ wl_signal_add(&resource->destroy_signal, listener);
+}
+
+QVector<Surface *> Compositor::surfaces() const
+{
+ return m_surfaces;
+}
+
+uint32_t Compositor::nextSerial()
+{
+ return wl_display_next_serial(m_display);
+}
+
+void Compositor::addSurface(Surface *surface)
+{
+ m_surfaces << surface;
+}
+
+void Compositor::removeSurface(Surface *surface)
+{
+ m_surfaces.removeOne(surface);
+ if (m_keyboard->focus() == surface)
+ m_keyboard->setFocus(0);
+ if (m_pointer->focus() == surface)
+ m_pointer->setFocus(0, QPoint());
+}
+
+}
+
diff --git a/tests/auto/client/client/mockcompositor.h b/tests/auto/client/client/mockcompositor.h
new file mode 100644
index 000000000..dd6450fc9
--- /dev/null
+++ b/tests/auto/client/client/mockcompositor.h
@@ -0,0 +1,203 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#ifndef MOCKCOMPOSITOR_H
+#define MOCKCOMPOSITOR_H
+
+#include <pthread.h>
+#include <qglobal.h>
+#include <wayland-server.h>
+
+#include <QImage>
+#include <QMutex>
+#include <QRect>
+#include <QSharedPointer>
+#include <QVariant>
+#include <QVector>
+#include <QWaitCondition>
+
+namespace Impl {
+
+typedef void (**Implementation)(void);
+
+class Keyboard;
+class Pointer;
+class Touch;
+class Seat;
+class DataDeviceManager;
+class Surface;
+
+class Compositor
+{
+public:
+ Compositor();
+ ~Compositor();
+
+ int fileDescriptor() const { return m_fd; }
+ void dispatchEvents(int timeout = 0);
+
+ uint32_t nextSerial();
+ uint32_t time() { return ++m_time; }
+
+ static void setOutputGeometry(void *compositor, const QList<QVariant> &parameters);
+
+ QVector<Surface *> surfaces() const;
+
+ void addSurface(Surface *surface);
+ void removeSurface(Surface *surface);
+
+ static void setKeyboardFocus(void *data, const QList<QVariant> &parameters);
+ static void sendMousePress(void *data, const QList<QVariant> &parameters);
+ static void sendMouseRelease(void *data, const QList<QVariant> &parameters);
+ static void sendKeyPress(void *data, const QList<QVariant> &parameters);
+ static void sendKeyRelease(void *data, const QList<QVariant> &parameters);
+ static void sendTouchDown(void *data, const QList<QVariant> &parameters);
+ static void sendTouchUp(void *data, const QList<QVariant> &parameters);
+ static void sendTouchMotion(void *data, const QList<QVariant> &parameters);
+ static void sendTouchFrame(void *data, const QList<QVariant> &parameters);
+ static void sendDataDeviceDataOffer(void *data, const QList<QVariant> &parameters);
+ static void sendDataDeviceEnter(void *data, const QList<QVariant> &parameters);
+ static void sendDataDeviceMotion(void *data, const QList<QVariant> &parameters);
+ static void sendDataDeviceDrop(void *data, const QList<QVariant> &parameters);
+ static void sendDataDeviceLeave(void *data, const QList<QVariant> &parameters);
+ static void waitForStartDrag(void *data, const QList<QVariant> &parameters);
+
+public:
+ bool m_startDragSeen;
+
+private:
+ static void bindCompositor(wl_client *client, void *data, uint32_t version, uint32_t id);
+ static void bindOutput(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);
+
+ void initShm();
+
+ void sendOutputGeometry(wl_resource *resource);
+ void sendOutputMode(wl_resource *resource);
+
+ QRect m_outputGeometry;
+
+ wl_display *m_display;
+ wl_event_loop *m_loop;
+ wl_shm *m_shm;
+ int m_fd;
+
+ wl_list m_outputResources;
+ uint32_t m_time;
+
+ QScopedPointer<Seat> m_seat;
+ Pointer *m_pointer;
+ Keyboard *m_keyboard;
+ Touch *m_touch;
+ QScopedPointer<DataDeviceManager> m_data_device_manager;
+ QVector<Surface *> m_surfaces;
+};
+
+void registerResource(wl_list *list, wl_resource *resource);
+
+}
+
+class MockSurface
+{
+public:
+ Impl::Surface *handle() const { return m_surface; }
+
+ QImage image;
+
+private:
+ MockSurface(Impl::Surface *surface);
+ friend class Impl::Compositor;
+ friend class Impl::Surface;
+
+ Impl::Surface *m_surface;
+};
+
+Q_DECLARE_METATYPE(QSharedPointer<MockSurface>)
+
+class MockCompositor
+{
+public:
+ MockCompositor();
+ ~MockCompositor();
+
+ void applicationInitialized();
+
+ int waylandFileDescriptor() const;
+ void processWaylandEvents();
+
+ void setOutputGeometry(const QRect &rect);
+ void setKeyboardFocus(const QSharedPointer<MockSurface> &surface);
+ void sendMousePress(const QSharedPointer<MockSurface> &surface, const QPoint &pos);
+ void sendMouseRelease(const QSharedPointer<MockSurface> &surface);
+ void sendKeyPress(const QSharedPointer<MockSurface> &surface, uint code);
+ void sendKeyRelease(const QSharedPointer<MockSurface> &surface, uint code);
+ void sendTouchDown(const QSharedPointer<MockSurface> &surface, const QPoint &position, int id);
+ void sendTouchMotion(const QSharedPointer<MockSurface> &surface, const QPoint &position, int id);
+ void sendTouchUp(const QSharedPointer<MockSurface> &surface, int id);
+ void sendTouchFrame(const QSharedPointer<MockSurface> &surface);
+ void sendDataDeviceDataOffer(const QSharedPointer<MockSurface> &surface);
+ void sendDataDeviceEnter(const QSharedPointer<MockSurface> &surface, const QPoint &position);
+ void sendDataDeviceMotion(const QPoint &position);
+ void sendDataDeviceDrop(const QSharedPointer<MockSurface> &surface);
+ void sendDataDeviceLeave(const QSharedPointer<MockSurface> &surface);
+ void waitForStartDrag();
+
+ QSharedPointer<MockSurface> surface();
+
+ void lock();
+ void unlock();
+
+private:
+ struct Command
+ {
+ typedef void (*Callback)(void *target, const QList<QVariant> &parameters);
+
+ Callback callback;
+ void *target;
+ QList<QVariant> parameters;
+ };
+
+ static Command makeCommand(Command::Callback callback, void *target);
+
+ void processCommand(const Command &command);
+ void dispatchCommands();
+
+ static void *run(void *data);
+
+ bool m_alive;
+ bool m_ready;
+ pthread_t m_thread;
+ QMutex m_mutex;
+ QWaitCondition m_waitCondition;
+
+ Impl::Compositor *m_compositor;
+
+ QList<Command> m_commandQueue;
+};
+
+#endif
diff --git a/tests/auto/client/client/mockinput.cpp b/tests/auto/client/client/mockinput.cpp
new file mode 100644
index 000000000..fe06bf79b
--- /dev/null
+++ b/tests/auto/client/client/mockinput.cpp
@@ -0,0 +1,462 @@
+/****************************************************************************
+**
+** 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 "mockinput.h"
+#include "mocksurface.h"
+
+namespace Impl {
+
+static Surface *resolveSurface(const QVariant &v)
+{
+ QSharedPointer<MockSurface> mockSurface = v.value<QSharedPointer<MockSurface> >();
+ return mockSurface ? mockSurface->handle() : 0;
+}
+
+void Compositor::setKeyboardFocus(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ compositor->m_keyboard->setFocus(resolveSurface(parameters.first()));
+}
+
+void Compositor::sendMousePress(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+ if (!surface)
+ return;
+
+ QPoint pos = parameters.last().toPoint();
+ compositor->m_pointer->setFocus(surface, pos);
+ compositor->m_pointer->sendMotion(pos);
+ compositor->m_pointer->sendButton(0x110, 1);
+}
+
+void Compositor::sendMouseRelease(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+ if (!surface)
+ return;
+
+ compositor->m_pointer->sendButton(0x110, 0);
+}
+
+void Compositor::sendKeyPress(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+ if (!surface)
+ return;
+
+ compositor->m_keyboard->sendKey(parameters.last().toUInt() - 8, 1);
+}
+
+void Compositor::sendKeyRelease(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+ if (!surface)
+ return;
+
+ compositor->m_keyboard->sendKey(parameters.last().toUInt() - 8, 0);
+}
+
+void Compositor::sendTouchDown(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+
+ Q_ASSERT(compositor);
+ Q_ASSERT(surface);
+
+ QPoint position = parameters.at(1).toPoint();
+ int id = parameters.at(2).toInt();
+
+ compositor->m_touch->sendDown(surface, position, id);
+}
+
+void Compositor::sendTouchUp(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+
+ Q_ASSERT(compositor);
+ Q_ASSERT(surface);
+
+ int id = parameters.at(1).toInt();
+
+ compositor->m_touch->sendUp(surface, id);
+}
+
+void Compositor::sendTouchMotion(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+
+ Q_ASSERT(compositor);
+ Q_ASSERT(surface);
+
+ QPoint position = parameters.at(1).toPoint();
+ int id = parameters.at(2).toInt();
+
+ compositor->m_touch->sendMotion(surface, position, id);
+}
+
+void Compositor::sendTouchFrame(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+
+ Q_ASSERT(compositor);
+ Q_ASSERT(surface);
+
+ compositor->m_touch->sendFrame(surface);
+}
+
+void Compositor::sendDataDeviceDataOffer(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+
+ Q_ASSERT(compositor);
+ Q_ASSERT(surface);
+
+ compositor->m_data_device_manager->dataDevice()->sendDataOffer(surface->resource()->client());
+}
+
+void Compositor::sendDataDeviceEnter(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+ QPoint position = parameters.at(1).toPoint();
+
+ Q_ASSERT(compositor);
+ Q_ASSERT(surface);
+
+ compositor->m_data_device_manager->dataDevice()->sendEnter(surface, position);
+}
+
+void Compositor::sendDataDeviceMotion(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Q_ASSERT(compositor);
+ QPoint position = parameters.first().toPoint();
+ compositor->m_data_device_manager->dataDevice()->sendMotion(position);
+}
+
+void Compositor::sendDataDeviceDrop(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+
+ Q_ASSERT(compositor);
+ Q_ASSERT(surface);
+
+ compositor->m_data_device_manager->dataDevice()->sendDrop(surface);
+}
+
+void Compositor::sendDataDeviceLeave(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Surface *surface = resolveSurface(parameters.first());
+
+ Q_ASSERT(compositor);
+ Q_ASSERT(surface);
+
+ compositor->m_data_device_manager->dataDevice()->sendLeave(surface);
+}
+
+void Compositor::waitForStartDrag(void *data, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(data);
+ Q_ASSERT(compositor);
+ while (!compositor->m_startDragSeen) {
+ wl_display_flush_clients(compositor->m_display);
+ wl_event_loop_dispatch(compositor->m_loop, 100);
+ }
+ compositor->m_startDragSeen = false;
+}
+
+Seat::Seat(Compositor *compositor, struct ::wl_display *display)
+ : wl_seat(display, 2)
+ , m_compositor(compositor)
+ , m_keyboard(new Keyboard(compositor))
+ , m_pointer(new Pointer(compositor))
+ , m_touch(new Touch(compositor))
+{
+}
+
+Seat::~Seat()
+{
+}
+
+void Seat::seat_bind_resource(Resource *resource)
+{
+ send_capabilities(resource->handle, capability_keyboard | capability_pointer | capability_touch);
+}
+
+void Seat::seat_get_keyboard(Resource *resource, uint32_t id)
+{
+ m_keyboard->add(resource->client(), id, resource->version());
+}
+
+void Seat::seat_get_pointer(Resource *resource, uint32_t id)
+{
+ m_pointer->add(resource->client(), id, resource->version());
+}
+
+void Seat::seat_get_touch(Resource *resource, uint32_t id)
+{
+ m_touch->add(resource->client(), id, resource->version());
+}
+
+Keyboard::Keyboard(Compositor *compositor)
+ : wl_keyboard()
+ , m_compositor(compositor)
+ , m_focusResource(Q_NULLPTR)
+ , m_focus(Q_NULLPTR)
+{
+}
+
+Keyboard::~Keyboard()
+{
+}
+
+void Keyboard::setFocus(Surface *surface)
+{
+ if (m_focusResource && m_focus != surface) {
+ uint32_t serial = m_compositor->nextSerial();
+ send_leave(m_focusResource->handle, serial, m_focus->resource()->handle);
+ }
+
+ Resource *resource = surface ? resourceMap().value(surface->resource()->client()) : 0;
+
+ if (resource && (m_focus != surface || m_focusResource != resource)) {
+ uint32_t serial = m_compositor->nextSerial();
+ send_modifiers(resource->handle, serial, 0, 0, 0, 0);
+ send_enter(resource->handle, serial, surface->resource()->handle, QByteArray());
+ }
+
+ m_focusResource = resource;
+ m_focus = surface;
+}
+
+void Keyboard::sendKey(uint32_t key, uint32_t state)
+{
+ if (m_focusResource) {
+ uint32_t serial = m_compositor->nextSerial();
+ send_key(m_focusResource->handle, serial, m_compositor->time(), key, state);
+ }
+}
+
+
+void Keyboard::keyboard_destroy_resource(wl_keyboard::Resource *resource)
+{
+ if (m_focusResource == resource)
+ m_focusResource = 0;
+}
+
+Pointer::Pointer(Compositor *compositor)
+ : wl_pointer()
+ , m_compositor(compositor)
+ , m_focusResource(Q_NULLPTR)
+ , m_focus(Q_NULLPTR)
+{
+}
+
+Pointer::~Pointer()
+{
+
+}
+
+void Pointer::setFocus(Surface *surface, const QPoint &pos)
+{
+ if (m_focusResource && m_focus != surface) {
+ uint32_t serial = m_compositor->nextSerial();
+ send_leave(m_focusResource->handle, serial, m_focus->resource()->handle);
+ }
+
+ Resource *resource = surface ? resourceMap().value(surface->resource()->client()) : 0;
+
+ if (resource && (m_focus != surface || resource != m_focusResource)) {
+ uint32_t serial = m_compositor->nextSerial();
+ send_enter(resource->handle, serial, surface->resource()->handle,
+ wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y()));
+ }
+
+ m_focusResource = resource;
+ m_focus = surface;
+}
+
+void Pointer::sendMotion(const QPoint &pos)
+{
+ if (m_focusResource)
+ send_motion(m_focusResource->handle, m_compositor->time(),
+ wl_fixed_from_int(pos.x()), wl_fixed_from_int(pos.y()));
+}
+
+void Pointer::sendButton(uint32_t button, uint32_t state)
+{
+ if (m_focusResource) {
+ uint32_t serial = m_compositor->nextSerial();
+ send_button(m_focusResource->handle, serial, m_compositor->time(),
+ button, state);
+ }
+}
+
+void Pointer::pointer_destroy_resource(wl_pointer::Resource *resource)
+{
+ if (m_focusResource == resource)
+ m_focusResource = 0;
+}
+
+Touch::Touch(Compositor *compositor)
+ : wl_touch()
+ , m_compositor(compositor)
+{
+}
+
+void Touch::sendDown(Surface *surface, const QPoint &position, int id)
+{
+ uint32_t serial = m_compositor->nextSerial();
+ uint32_t time = m_compositor->time();
+ Q_ASSERT(surface);
+ Resource *resource = resourceMap().value(surface->resource()->client());
+ Q_ASSERT(resource);
+ wl_touch_send_down(resource->handle, serial, time, surface->resource()->handle, id, position.x(), position.y());
+}
+
+void Touch::sendUp(Surface *surface, int id)
+{
+ Resource *resource = resourceMap().value(surface->resource()->client());
+ wl_touch_send_up(resource->handle, m_compositor->nextSerial(), m_compositor->time(), id);
+}
+
+void Touch::sendMotion(Surface *surface, const QPoint &position, int id)
+{
+ Resource *resource = resourceMap().value(surface->resource()->client());
+ uint32_t time = m_compositor->time();
+ wl_touch_send_motion(resource->handle, time, id, position.x(), position.y());
+}
+
+void Touch::sendFrame(Surface *surface)
+{
+ Resource *resource = resourceMap().value(surface->resource()->client());
+ wl_touch_send_frame(resource->handle);
+}
+
+DataOffer::DataOffer()
+ : wl_data_offer()
+{
+
+}
+
+DataDevice::DataDevice(Compositor *compositor)
+ : wl_data_device()
+ , m_compositor(compositor)
+ , m_dataOffer(nullptr)
+ , m_focus(nullptr)
+{
+
+}
+
+void DataDevice::sendDataOffer(wl_client *client)
+{
+ m_dataOffer = new QtWaylandServer::wl_data_offer(client, 0, 1);
+ Resource *resource = resourceMap().value(client);
+ send_data_offer(resource->handle, m_dataOffer->resource()->handle);
+}
+
+void DataDevice::sendEnter(Surface *surface, const QPoint& position)
+{
+ uint serial = m_compositor->nextSerial();
+ m_focus = surface;
+ Resource *resource = resourceMap().value(surface->resource()->client());
+ send_enter(resource->handle, serial, surface->resource()->handle, position.x(), position.y(), m_dataOffer->resource()->handle);
+}
+
+void DataDevice::sendMotion(const QPoint &position)
+{
+ uint32_t time = m_compositor->time();
+ Resource *resource = resourceMap().value(m_focus->resource()->client());
+ send_motion(resource->handle, time, position.x(), position.y());
+}
+
+void DataDevice::sendDrop(Surface *surface)
+{
+ Resource *resource = resourceMap().value(surface->resource()->client());
+ send_drop(resource->handle);
+}
+
+void DataDevice::sendLeave(Surface *surface)
+{
+ Resource *resource = resourceMap().value(surface->resource()->client());
+ send_leave(resource->handle);
+}
+
+DataDevice::~DataDevice()
+{
+
+}
+
+void DataDevice::data_device_start_drag(QtWaylandServer::wl_data_device::Resource *resource, wl_resource *source, wl_resource *origin, wl_resource *icon, uint32_t serial)
+{
+ m_compositor->m_startDragSeen = true;
+}
+
+DataDeviceManager::DataDeviceManager(Compositor *compositor, wl_display *display)
+ : wl_data_device_manager(display, 1)
+ , m_compositor(compositor)
+{
+
+}
+
+DataDeviceManager::~DataDeviceManager()
+{
+
+}
+
+DataDevice *DataDeviceManager::dataDevice() const
+{
+ return m_data_device.data();
+}
+
+void DataDeviceManager::data_device_manager_get_data_device(Resource *resource, uint32_t id, struct ::wl_resource *seat)
+{
+ if (!m_data_device)
+ m_data_device.reset(new DataDevice(m_compositor));
+ m_data_device->add(resource->client(), id, 1);
+}
+
+void DataDeviceManager::data_device_manager_create_data_source(QtWaylandServer::wl_data_device_manager::Resource *resource, uint32_t id)
+{
+ new QtWaylandServer::wl_data_source(resource->client(), id, 1);
+}
+
+}
diff --git a/tests/auto/client/client/mockinput.h b/tests/auto/client/client/mockinput.h
new file mode 100644
index 000000000..031be2a4a
--- /dev/null
+++ b/tests/auto/client/client/mockinput.h
@@ -0,0 +1,170 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Klarälvdalens Datakonsult AB (KDAB).
+** 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$
+**
+****************************************************************************/
+
+#ifndef MOCKINPUT_H
+#define MOCKINPUT_H
+
+#include <qglobal.h>
+
+#include "qwayland-server-wayland.h"
+
+#include "mockcompositor.h"
+
+namespace Impl {
+
+class Keyboard;
+class Pointer;
+
+class Seat : public QtWaylandServer::wl_seat
+{
+public:
+ Seat(Compositor *compositor, struct ::wl_display *display);
+ ~Seat();
+
+ Compositor *compositor() const { return m_compositor; }
+
+ Keyboard *keyboard() const { return m_keyboard.data(); }
+ Pointer *pointer() const { return m_pointer.data(); }
+ Touch *touch() const { return m_touch.data(); }
+
+protected:
+ void seat_bind_resource(Resource *resource) Q_DECL_OVERRIDE;
+ void seat_get_keyboard(Resource *resource, uint32_t id) Q_DECL_OVERRIDE;
+ void seat_get_pointer(Resource *resource, uint32_t id) Q_DECL_OVERRIDE;
+ void seat_get_touch(Resource *resource, uint32_t id) Q_DECL_OVERRIDE;
+
+private:
+ Compositor *m_compositor;
+
+ QScopedPointer<Keyboard> m_keyboard;
+ QScopedPointer<Pointer> m_pointer;
+ QScopedPointer<Touch> m_touch;
+};
+
+class Keyboard : public QtWaylandServer::wl_keyboard
+{
+public:
+ Keyboard(Compositor *compositor);
+ ~Keyboard();
+
+ Surface *focus() const { return m_focus; }
+ void setFocus(Surface *surface);
+
+ void sendKey(uint32_t key, uint32_t state);
+
+protected:
+ void keyboard_destroy_resource(wl_keyboard::Resource *resource) Q_DECL_OVERRIDE;
+
+private:
+ Compositor *m_compositor;
+
+ Resource *m_focusResource;
+ Surface *m_focus;
+};
+
+class Pointer : public QtWaylandServer::wl_pointer
+{
+public:
+ Pointer(Compositor *compositor);
+ ~Pointer();
+
+ Surface *focus() const { return m_focus; }
+
+ void setFocus(Surface *surface, const QPoint &pos);
+ void sendMotion(const QPoint &pos);
+ void sendButton(uint32_t button, uint32_t state);
+
+protected:
+ void pointer_destroy_resource(wl_pointer::Resource *resource) Q_DECL_OVERRIDE;
+
+private:
+ Compositor *m_compositor;
+
+ Resource *m_focusResource;
+ Surface *m_focus;
+};
+
+class Touch : public QtWaylandServer::wl_touch
+{
+public:
+ Touch(Compositor *compositor);
+ void sendDown(Surface *surface, const QPoint &position, int id);
+ void sendUp(Surface *surface, int id);
+ void sendMotion(Surface *surface, const QPoint &position, int id);
+ void sendFrame(Surface *surface);
+private:
+ Compositor *m_compositor;
+};
+
+class DataOffer : public QtWaylandServer::wl_data_offer
+{
+public:
+ DataOffer();
+};
+
+class DataDevice : public QtWaylandServer::wl_data_device
+{
+public:
+ DataDevice(Compositor *compositor);
+ void sendDataOffer(wl_client *client);
+ void sendEnter(Surface *surface, const QPoint &position);
+ void sendMotion(const QPoint &position);
+ void sendDrop(Surface *surface);
+ void sendLeave(Surface *surface);
+ ~DataDevice();
+
+protected:
+ void data_device_start_drag(Resource *resource, struct ::wl_resource *source, struct ::wl_resource *origin, struct ::wl_resource *icon, uint32_t serial) override;
+
+private:
+ Compositor *m_compositor;
+ QtWaylandServer::wl_data_offer *m_dataOffer;
+ Surface* m_focus;
+};
+
+class DataDeviceManager : public QtWaylandServer::wl_data_device_manager
+{
+public:
+ DataDeviceManager(Compositor *compositor, struct ::wl_display *display);
+ ~DataDeviceManager();
+ DataDevice *dataDevice() const;
+
+protected:
+ void data_device_manager_get_data_device(Resource *resource, uint32_t id, struct ::wl_resource *seat) Q_DECL_OVERRIDE;
+ void data_device_manager_create_data_source(Resource *resource, uint32_t id) override;
+
+private:
+ Compositor *m_compositor;
+
+ QScopedPointer<DataDevice> m_data_device;
+};
+
+}
+
+#endif // MOCKINPUT_H
diff --git a/tests/auto/client/client/mockoutput.cpp b/tests/auto/client/client/mockoutput.cpp
new file mode 100644
index 000000000..86561976f
--- /dev/null
+++ b/tests/auto/client/client/mockoutput.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** 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"
+
+namespace Impl {
+
+void Compositor::bindOutput(wl_client *client, void *compositorData, uint32_t version, uint32_t id)
+{
+ wl_resource *resource = wl_resource_create(client, &wl_output_interface, static_cast<int>(version), id);
+
+ Compositor *compositor = static_cast<Compositor *>(compositorData);
+ registerResource(&compositor->m_outputResources, resource);
+
+ compositor->sendOutputGeometry(resource);
+ compositor->sendOutputMode(resource);
+}
+
+void Compositor::sendOutputGeometry(wl_resource *resource)
+{
+ const QRect &r = m_outputGeometry;
+ wl_output_send_geometry(resource, r.x(), r.y(), r.width(), r.height(), 0, "", "",0);
+}
+
+void Compositor::sendOutputMode(wl_resource *resource)
+{
+ const QRect &r = m_outputGeometry;
+ wl_output_send_mode(resource, WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED, r.width(), r.height(), 60);
+}
+
+void Compositor::setOutputGeometry(void *c, const QList<QVariant> &parameters)
+{
+ Compositor *compositor = static_cast<Compositor *>(c);
+ compositor->m_outputGeometry = parameters.first().toRect();
+
+ wl_resource *resource;
+ wl_list_for_each(resource, &compositor->m_outputResources, link)
+ compositor->sendOutputGeometry(resource);
+}
+
+}
+
diff --git a/tests/auto/client/client/mockshell.cpp b/tests/auto/client/client/mockshell.cpp
new file mode 100644
index 000000000..d5eede22e
--- /dev/null
+++ b/tests/auto/client/client/mockshell.cpp
@@ -0,0 +1,180 @@
+/****************************************************************************
+**
+** 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/client/mocksurface.cpp b/tests/auto/client/client/mocksurface.cpp
new file mode 100644
index 000000000..55712af11
--- /dev/null
+++ b/tests/auto/client/client/mocksurface.cpp
@@ -0,0 +1,138 @@
+/****************************************************************************
+**
+** 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 "mocksurface.h"
+#include "mockcompositor.h"
+
+namespace Impl {
+
+Surface::Surface(wl_client *client, uint32_t id, int v, Compositor *compositor)
+ : QtWaylandServer::wl_surface(client, id, v)
+ , m_buffer(Q_NULLPTR)
+ , m_compositor(compositor)
+ , m_mockSurface(new MockSurface(this))
+ , m_mapped(false)
+{
+}
+
+Surface::~Surface()
+{
+ m_mockSurface->m_surface = 0;
+}
+
+void Surface::map()
+{
+ m_mapped = true;
+}
+
+bool Surface::isMapped() const
+{
+ return m_mapped;
+}
+
+Surface *Surface::fromResource(struct ::wl_resource *resource)
+{
+ return static_cast<Surface *>(Resource::fromResource(resource)->surface_object);
+}
+
+void Surface::surface_destroy_resource(Resource *)
+{
+ compositor()->removeSurface(this);
+ delete this;
+}
+
+void Surface::surface_destroy(Resource *resource)
+{
+ wl_resource_destroy(resource->handle);
+}
+
+void Surface::surface_attach(Resource *resource,
+ struct wl_resource *buffer, int x, int y)
+{
+ Q_UNUSED(resource);
+ Q_UNUSED(x);
+ Q_UNUSED(y);
+ m_buffer = buffer;
+
+ if (!buffer)
+ m_mockSurface->image = QImage();
+}
+
+void Surface::surface_damage(Resource *resource,
+ int32_t x, int32_t y, int32_t width, int32_t height)
+{
+ Q_UNUSED(resource);
+ Q_UNUSED(x);
+ Q_UNUSED(y);
+ Q_UNUSED(width);
+ Q_UNUSED(height);
+}
+
+void Surface::surface_frame(Resource *resource,
+ uint32_t callback)
+{
+ wl_resource *frameCallback = wl_resource_create(resource->client(), &wl_callback_interface, 1, callback);
+ m_frameCallbackList << frameCallback;
+}
+
+void Surface::surface_commit(Resource *resource)
+{
+ Q_UNUSED(resource);
+
+ if (m_buffer) {
+#if WAYLAND_VERSION_CHECK(1, 2, 0)
+ struct ::wl_shm_buffer *shm_buffer = wl_shm_buffer_get(m_buffer);
+#else
+ struct ::wl_buffer *shm_buffer = 0;
+ if (wl_buffer_is_shm(static_cast<struct ::wl_buffer*>(m_buffer->data)))
+ shm_buffer = static_cast<struct ::wl_buffer*>(m_buffer->data);
+#endif
+
+ if (shm_buffer) {
+ int stride = wl_shm_buffer_get_stride(shm_buffer);
+ uint format = wl_shm_buffer_get_format(shm_buffer);
+ Q_UNUSED(format);
+ void *data = wl_shm_buffer_get_data(shm_buffer);
+ const uchar *char_data = static_cast<const uchar *>(data);
+ QImage img(char_data, wl_shm_buffer_get_width(shm_buffer), wl_shm_buffer_get_height(shm_buffer), stride, QImage::Format_ARGB32_Premultiplied);
+ m_mockSurface->image = img;
+ }
+ }
+
+ foreach (wl_resource *frameCallback, m_frameCallbackList) {
+ wl_callback_send_done(frameCallback, m_compositor->time());
+ wl_resource_destroy(frameCallback);
+ }
+ m_frameCallbackList.clear();
+}
+
+}
+MockSurface::MockSurface(Impl::Surface *surface)
+ : m_surface(surface)
+{
+}
diff --git a/tests/auto/client/client/mocksurface.h b/tests/auto/client/client/mocksurface.h
new file mode 100644
index 000000000..d04386ac8
--- /dev/null
+++ b/tests/auto/client/client/mocksurface.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** 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 <qglobal.h>
+
+#include "qwayland-server-wayland.h"
+
+#include "mockcompositor.h"
+
+namespace Impl {
+
+class Surface : public QtWaylandServer::wl_surface
+{
+public:
+ Surface(wl_client *client, uint32_t id, int v, Compositor *compositor);
+ ~Surface();
+
+ Compositor *compositor() const { return m_compositor; }
+ static Surface *fromResource(struct ::wl_resource *resource);
+ void map();
+ bool isMapped() const;
+
+ QSharedPointer<MockSurface> mockSurface() const { return m_mockSurface; }
+
+protected:
+
+ void surface_destroy_resource(Resource *resource) Q_DECL_OVERRIDE;
+
+ void surface_destroy(Resource *resource) Q_DECL_OVERRIDE;
+ void surface_attach(Resource *resource,
+ struct wl_resource *buffer, int x, int y) Q_DECL_OVERRIDE;
+ void surface_damage(Resource *resource,
+ int32_t x, int32_t y, int32_t width, int32_t height) Q_DECL_OVERRIDE;
+ void surface_frame(Resource *resource,
+ uint32_t callback) Q_DECL_OVERRIDE;
+ void surface_commit(Resource *resource) Q_DECL_OVERRIDE;
+private:
+ wl_resource *m_buffer;
+
+ Compositor *m_compositor;
+ QSharedPointer<MockSurface> m_mockSurface;
+ QList<wl_resource *> m_frameCallbackList;
+ bool m_mapped;
+};
+
+}
diff --git a/tests/auto/client/client/tst_client.cpp b/tests/auto/client/client/tst_client.cpp
new file mode 100644
index 000000000..74363ef5f
--- /dev/null
+++ b/tests/auto/client/client/tst_client.cpp
@@ -0,0 +1,355 @@
+/****************************************************************************
+**
+** 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 <QBackingStore>
+#include <QPainter>
+#include <QScreen>
+#include <QWindow>
+#include <QMimeData>
+#include <QPixmap>
+#include <QDrag>
+
+#include <QtTest/QtTest>
+
+static const QSize screenSize(1600, 1200);
+
+class TestWindow : public QWindow
+{
+public:
+ TestWindow()
+ : focusInEventCount(0)
+ , focusOutEventCount(0)
+ , keyPressEventCount(0)
+ , keyReleaseEventCount(0)
+ , mousePressEventCount(0)
+ , mouseReleaseEventCount(0)
+ , touchEventCount(0)
+ , keyCode(0)
+ {
+ setSurfaceType(QSurface::RasterSurface);
+ setGeometry(0, 0, 32, 32);
+ create();
+ }
+
+ void focusInEvent(QFocusEvent *)
+ {
+ ++focusInEventCount;
+ }
+
+ void focusOutEvent(QFocusEvent *)
+ {
+ ++focusOutEventCount;
+ }
+
+ void keyPressEvent(QKeyEvent *event)
+ {
+ ++keyPressEventCount;
+ keyCode = event->nativeScanCode();
+ }
+
+ void keyReleaseEvent(QKeyEvent *event)
+ {
+ ++keyReleaseEventCount;
+ keyCode = event->nativeScanCode();
+ }
+
+ void mousePressEvent(QMouseEvent *event)
+ {
+ ++mousePressEventCount;
+ mousePressPos = event->pos();
+ }
+
+ void mouseReleaseEvent(QMouseEvent *)
+ {
+ ++mouseReleaseEventCount;
+ }
+
+ void touchEvent(QTouchEvent *event) Q_DECL_OVERRIDE
+ {
+ ++touchEventCount;
+ }
+
+ int focusInEventCount;
+ int focusOutEventCount;
+ int keyPressEventCount;
+ int keyReleaseEventCount;
+ int mousePressEventCount;
+ int mouseReleaseEventCount;
+ int touchEventCount;
+
+ uint keyCode;
+ QPoint mousePressPos;
+};
+
+class tst_WaylandClient : public QObject
+{
+ Q_OBJECT
+public:
+ tst_WaylandClient(MockCompositor *c)
+ : compositor(c)
+ {
+ QSocketNotifier *notifier = new QSocketNotifier(compositor->waylandFileDescriptor(), QSocketNotifier::Read, this);
+ connect(notifier, SIGNAL(activated(int)), this, SLOT(processWaylandEvents()));
+ // connect to the event dispatcher to make sure to flush out the outgoing message queue
+ connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::awake, this, &tst_WaylandClient::processWaylandEvents);
+ connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::aboutToBlock, this, &tst_WaylandClient::processWaylandEvents);
+ }
+
+public slots:
+ void processWaylandEvents()
+ {
+ compositor->processWaylandEvents();
+ }
+
+ void cleanup()
+ {
+ // make sure the surfaces from the last test are properly cleaned up
+ // and don't show up as false positives in the next test
+ QTRY_VERIFY(!compositor->surface());
+ }
+
+private slots:
+ void screen();
+ void createDestroyWindow();
+ void events();
+ void backingStore();
+ void touchDrag();
+ void mouseDrag();
+
+private:
+ MockCompositor *compositor;
+};
+
+void tst_WaylandClient::screen()
+{
+ QTRY_COMPARE(QGuiApplication::primaryScreen()->size(), screenSize);
+}
+
+void tst_WaylandClient::createDestroyWindow()
+{
+ TestWindow window;
+ window.show();
+
+ QTRY_VERIFY(compositor->surface());
+
+ window.destroy();
+ QTRY_VERIFY(!compositor->surface());
+}
+
+void tst_WaylandClient::events()
+{
+ TestWindow window;
+ window.show();
+
+ QSharedPointer<MockSurface> surface;
+ QTRY_VERIFY(surface = compositor->surface());
+
+ QCOMPARE(window.focusInEventCount, 0);
+ compositor->setKeyboardFocus(surface);
+ QTRY_COMPARE(window.focusInEventCount, 1);
+ QTRY_COMPARE(QGuiApplication::focusWindow(), &window);
+
+ QCOMPARE(window.focusOutEventCount, 0);
+ compositor->setKeyboardFocus(QSharedPointer<MockSurface>(0));
+ QTRY_COMPARE(window.focusOutEventCount, 1);
+ QTRY_COMPARE(QGuiApplication::focusWindow(), static_cast<QWindow *>(0));
+
+ compositor->setKeyboardFocus(surface);
+ QTRY_COMPARE(window.focusInEventCount, 2);
+ QTRY_COMPARE(QGuiApplication::focusWindow(), &window);
+
+ uint keyCode = 80; // arbitrarily chosen
+ QCOMPARE(window.keyPressEventCount, 0);
+ compositor->sendKeyPress(surface, keyCode);
+ QTRY_COMPARE(window.keyPressEventCount, 1);
+ QTRY_COMPARE(window.keyCode, keyCode);
+
+ QCOMPARE(window.keyReleaseEventCount, 0);
+ compositor->sendKeyRelease(surface, keyCode);
+ QTRY_COMPARE(window.keyReleaseEventCount, 1);
+ QCOMPARE(window.keyCode, keyCode);
+
+ QPoint mousePressPos(16, 16);
+ QCOMPARE(window.mousePressEventCount, 0);
+ compositor->sendMousePress(surface, mousePressPos);
+ QTRY_COMPARE(window.mousePressEventCount, 1);
+ QTRY_COMPARE(window.mousePressPos, mousePressPos);
+
+ QCOMPARE(window.mouseReleaseEventCount, 0);
+ compositor->sendMouseRelease(surface);
+ QTRY_COMPARE(window.mouseReleaseEventCount, 1);
+
+ const int touchId = 0;
+ compositor->sendTouchDown(surface, QPoint(10, 10), touchId);
+ compositor->sendTouchFrame(surface);
+ QTRY_COMPARE(window.touchEventCount, 1);
+
+ compositor->sendTouchUp(surface, touchId);
+ compositor->sendTouchFrame(surface);
+ QTRY_COMPARE(window.touchEventCount, 2);
+}
+
+void tst_WaylandClient::backingStore()
+{
+ TestWindow window;
+ window.show();
+
+ QSharedPointer<MockSurface> surface;
+ QTRY_VERIFY(surface = compositor->surface());
+
+ QRect rect(QPoint(), window.size());
+
+ QBackingStore backingStore(&window);
+ backingStore.resize(rect.size());
+
+ backingStore.beginPaint(rect);
+
+ QColor color = Qt::magenta;
+
+ QPainter p(backingStore.paintDevice());
+ p.fillRect(rect, color);
+ p.end();
+
+ backingStore.endPaint();
+
+ QVERIFY(surface->image.isNull());
+
+ backingStore.flush(rect);
+
+ QTRY_COMPARE(surface->image.size(), window.frameGeometry().size());
+ QTRY_COMPARE(surface->image.pixel(window.frameMargins().left(), window.frameMargins().top()), color.rgba());
+
+ window.hide();
+
+ // hiding the window should detach the buffer
+ QTRY_VERIFY(surface->image.isNull());
+}
+
+class DndWindow : public QWindow
+{
+ Q_OBJECT
+
+public:
+ DndWindow(QWindow *parent = 0)
+ : QWindow(parent)
+ , dragStarted(false)
+ {
+ QImage cursorImage(64,64,QImage::Format_ARGB32);
+ cursorImage.fill(Qt::blue);
+ m_dragIcon = QPixmap::fromImage(cursorImage);
+ }
+ ~DndWindow(){}
+ bool dragStarted;
+
+protected:
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE
+ {
+ if (dragStarted)
+ return;
+ dragStarted = true;
+
+ QByteArray dataBytes;
+ QMimeData *mimeData = new QMimeData;
+ mimeData->setData("application/x-dnditemdata", dataBytes);
+ QDrag *drag = new QDrag(this);
+ drag->setMimeData(mimeData);
+ drag->setPixmap(m_dragIcon);
+ drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
+ }
+private:
+ QPixmap m_dragIcon;
+};
+
+void tst_WaylandClient::touchDrag()
+{
+ DndWindow window;
+ window.show();
+
+ QSharedPointer<MockSurface> surface;
+ QTRY_VERIFY(surface = compositor->surface());
+
+ compositor->setKeyboardFocus(surface);
+ QTRY_COMPARE(QGuiApplication::focusWindow(), &window);
+
+ const int id = 0;
+ compositor->sendTouchDown(surface, QPoint(10, 10), id);
+ compositor->sendTouchMotion(surface, QPoint(20, 20), id);
+ compositor->sendTouchFrame(surface);
+ compositor->waitForStartDrag();
+ compositor->sendDataDeviceDataOffer(surface);
+ compositor->sendDataDeviceEnter(surface, QPoint(20, 20));
+ compositor->sendDataDeviceMotion( QPoint(21, 21));
+ compositor->sendDataDeviceDrop(surface);
+ compositor->sendDataDeviceLeave(surface);
+ QTRY_VERIFY(window.dragStarted);
+}
+
+void tst_WaylandClient::mouseDrag()
+{
+ DndWindow window;
+ window.show();
+
+ QSharedPointer<MockSurface> surface;
+ QTRY_VERIFY(surface = compositor->surface());
+
+ compositor->setKeyboardFocus(surface);
+ QTRY_COMPARE(QGuiApplication::focusWindow(), &window);
+
+ compositor->sendMousePress(surface, QPoint(10, 10));
+ compositor->sendDataDeviceDataOffer(surface);
+ compositor->sendDataDeviceEnter(surface, QPoint(20, 20));
+ compositor->sendDataDeviceMotion( QPoint(21, 21));
+ compositor->waitForStartDrag();
+ compositor->sendDataDeviceDrop(surface);
+ compositor->sendDataDeviceLeave(surface);
+ QTRY_VERIFY(window.dragStarted);
+}
+
+int main(int argc, char **argv)
+{
+ setenv("XDG_RUNTIME_DIR", ".", 1);
+ setenv("QT_QPA_PLATFORM", "wayland", 1); // force QGuiApplication to use wayland plugin
+
+ // wayland-egl hangs in the test setup when we try to initialize. Until it gets
+ // figured out, avoid clientBufferIntegration() from being called in
+ // QWaylandWindow::createDecorations().
+ setenv("QT_WAYLAND_DISABLE_WINDOWDECORATION", "1", 1);
+
+ MockCompositor compositor;
+ compositor.setOutputGeometry(QRect(QPoint(), screenSize));
+
+ QGuiApplication app(argc, argv);
+ compositor.applicationInitialized();
+
+ tst_WaylandClient tc(&compositor);
+ return QTest::qExec(&tc, argc, argv);
+}
+
+#include <tst_client.moc>