diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/compositor/compositor.pro | 4 | ||||
-rw-r--r-- | tests/auto/compositor/mockclient.cpp | 4 | ||||
-rw-r--r-- | tests/auto/compositor/mockclient.h | 5 | ||||
-rw-r--r-- | tests/auto/compositor/mockseat.cpp | 56 | ||||
-rw-r--r-- | tests/auto/compositor/mockseat.h | 58 | ||||
-rw-r--r-- | tests/auto/compositor/testinputdevice.cpp | 70 | ||||
-rw-r--r-- | tests/auto/compositor/testinputdevice.h | 65 | ||||
-rw-r--r-- | tests/auto/compositor/tst_compositor.cpp | 73 |
8 files changed, 335 insertions, 0 deletions
diff --git a/tests/auto/compositor/compositor.pro b/tests/auto/compositor/compositor.pro index d173d2ed6..035beeb41 100644 --- a/tests/auto/compositor/compositor.pro +++ b/tests/auto/compositor/compositor.pro @@ -24,7 +24,11 @@ SOURCES += tst_compositor.cpp \ testcompositor.cpp \ testkeyboardgrabber.cpp \ mockclient.cpp \ + mockseat.cpp \ + testinputdevice.cpp HEADERS += testcompositor.h \ testkeyboardgrabber.h \ mockclient.h \ + mockseat.h \ + testinputdevice.h diff --git a/tests/auto/compositor/mockclient.cpp b/tests/auto/compositor/mockclient.cpp index 9bbe56519..8f2bbbc6d 100644 --- a/tests/auto/compositor/mockclient.cpp +++ b/tests/auto/compositor/mockclient.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "mockclient.h" +#include "mockseat.h" #include <QElapsedTimer> #include <QSocketNotifier> @@ -145,6 +146,9 @@ 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 == "wl_seat") { + wl_seat *s = static_cast<wl_seat *>(wl_registry_bind(registry, id, &wl_seat_interface, 1)); + m_seats << new MockSeat(s); } } diff --git a/tests/auto/compositor/mockclient.h b/tests/auto/compositor/mockclient.h index de1084ab9..04c5dc831 100644 --- a/tests/auto/compositor/mockclient.h +++ b/tests/auto/compositor/mockclient.h @@ -44,6 +44,9 @@ #include <QObject> #include <QImage> #include <QRect> +#include <QList> + +class MockSeat; class ShmBuffer { @@ -74,6 +77,8 @@ public: wl_registry *registry; wl_shell *wlshell; + QList<MockSeat *> m_seats; + QRect geometry; int fd; diff --git a/tests/auto/compositor/mockseat.cpp b/tests/auto/compositor/mockseat.cpp new file mode 100644 index 000000000..ff6e449dd --- /dev/null +++ b/tests/auto/compositor/mockseat.cpp @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2014 LG Electronics Ltd., author: <mikko.levonmaa@lge.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "mockseat.h" + +MockSeat::MockSeat(wl_seat *seat) + : m_seat(seat) +{ + // Bind to the keyboard interface so that the compositor has + // the right resource associations + m_keyboard = wl_seat_get_keyboard(seat); +} + +MockSeat::~MockSeat() +{ + wl_keyboard_destroy(m_keyboard); + wl_seat_destroy(m_seat); +} diff --git a/tests/auto/compositor/mockseat.h b/tests/auto/compositor/mockseat.h new file mode 100644 index 000000000..19b777619 --- /dev/null +++ b/tests/auto/compositor/mockseat.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2014 LG Electronics Ltd., author: <mikko.levonmaa@lge.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef MOCKSEAT +#define MOCKSEAT + +#include <QObject> +#include <wayland-client.h> + +class MockSeat : public QObject +{ + Q_OBJECT + +public: + MockSeat(wl_seat *seat); + ~MockSeat(); + + wl_seat *m_seat; + wl_keyboard *m_keyboard; +}; +#endif diff --git a/tests/auto/compositor/testinputdevice.cpp b/tests/auto/compositor/testinputdevice.cpp new file mode 100644 index 000000000..627578514 --- /dev/null +++ b/tests/auto/compositor/testinputdevice.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2014 LG Electronics, Inc., author: <mikko.levonmaa@lge.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "testinputdevice.h" + +#include <QMouseEvent> + +TestInputDevice::TestInputDevice(QWaylandCompositor *compositor, QWaylandInputDevice::CapabilityFlags caps) + : QWaylandInputDevice(compositor, caps) +{ + m_queryCount = 0; +} + +TestInputDevice::~TestInputDevice() +{ +} + +bool TestInputDevice::isOwner(QInputEvent *event) +{ + m_queryCount++; + QMouseEvent *me = dynamic_cast<QMouseEvent *>(event); + return m_events.contains(me); +} + +QList<QMouseEvent *> TestInputDevice::createMouseEvents(int count) +{ + for (int i = 0; i < count; i++) { + m_events.append(new QMouseEvent(QEvent::MouseMove, QPointF(10 + i, 10 + i), Qt::NoButton, Qt::NoButton, Qt::NoModifier)); + } + return m_events; +} + diff --git a/tests/auto/compositor/testinputdevice.h b/tests/auto/compositor/testinputdevice.h new file mode 100644 index 000000000..cc930843a --- /dev/null +++ b/tests/auto/compositor/testinputdevice.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2014 LG Electronics, Inc., author: <mikko.levonmaa@lge.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QWaylandInputDevice> +#include <QList> + +class QInputEvent; +class QMouseEvent; + +class TestInputDevice : public QWaylandInputDevice +{ + +public: + + TestInputDevice(QWaylandCompositor *compositor, QWaylandInputDevice::CapabilityFlags caps); + ~TestInputDevice(); + + bool isOwner(QInputEvent *event); + + QList<QMouseEvent *> createMouseEvents(int count); + + int queryCount() { return m_queryCount; } + +private: + int m_queryCount; + QList<QMouseEvent *> m_events; +}; diff --git a/tests/auto/compositor/tst_compositor.cpp b/tests/auto/compositor/tst_compositor.cpp index 3a11d7be5..2e404a79d 100644 --- a/tests/auto/compositor/tst_compositor.cpp +++ b/tests/auto/compositor/tst_compositor.cpp @@ -45,6 +45,8 @@ #include "QtCompositor/private/qwlkeyboard_p.h" #include "QtCompositor/private/qwlinputdevice_p.h" +#include "QtCompositor/private/qwlcompositor_p.h" +#include "testinputdevice.h" #include "qwaylandbufferref.h" @@ -64,6 +66,8 @@ public: private slots: void inputDeviceCapabilities(); void keyboardGrab(); + void inputDeviceCreation(); + void inputDeviceKeyboardFocus(); void singleClient(); void multipleClients(); void geometry(); @@ -323,5 +327,74 @@ void tst_WaylandCompositor::inputDeviceCapabilities() QTRY_COMPARE(k, dev.keyboardDevice()); } +void tst_WaylandCompositor::inputDeviceCreation() +{ + TestCompositor compositor; + TestInputDevice dev1(&compositor, QWaylandInputDevice::Pointer | QWaylandInputDevice::Keyboard); + TestInputDevice dev2(&compositor, QWaylandInputDevice::Pointer | QWaylandInputDevice::Keyboard); + + compositor.handle()->registerInputDevice(&dev1); + compositor.handle()->registerInputDevice(&dev2); + + // The compositor will create the default input device + QTRY_COMPARE(compositor.handle()->inputDevices().count(), 3); + // Test the order + QTRY_COMPARE(compositor.handle()->inputDevices().at(0), &dev2); + QTRY_COMPARE(compositor.handle()->inputDevices().at(1), &dev1); + QTRY_COMPARE(compositor.handle()->inputDevices().at(2), compositor.defaultInputDevice()); + + QList<QMouseEvent *> allEvents; + allEvents += dev1.createMouseEvents(2); + allEvents += dev2.createMouseEvents(5); + foreach (QMouseEvent *me, allEvents) { + compositor.inputDeviceFor(me); + } + + // The first input device will only get called exatly the number of times it has created + // the events + QTRY_COMPARE(dev1.queryCount(), 2); + // The second will get called the total number of times as it sits as the first item in + // the registered input devices list + QTRY_COMPARE(dev2.queryCount(), 7); +} + +void tst_WaylandCompositor::inputDeviceKeyboardFocus() +{ + TestCompositor compositor; + + + TestInputDevice dev1(&compositor, QWaylandInputDevice::Keyboard); + TestInputDevice dev2(&compositor, QWaylandInputDevice::Keyboard); + + compositor.handle()->registerInputDevice(&dev1); + compositor.handle()->registerInputDevice(&dev2); + + // Create client after all the input devices have been set up as the mock client + // does not dynamically listen to new seats + MockClient client; + wl_surface *surface = client.createSurface(); + QTRY_COMPARE(compositor.surfaces.size(), 1); + + QWaylandSurface *waylandSurface = compositor.surfaces.at(0); + QList<QWaylandInputDevice *> devices = compositor.handle()->inputDevices(); + foreach (QWaylandInputDevice *dev, devices) { + dev->setKeyboardFocus(waylandSurface); + } + QTRY_COMPARE(compositor.defaultInputDevice()->keyboardFocus(), waylandSurface); + QTRY_COMPARE(dev1.keyboardFocus(), waylandSurface); + QTRY_COMPARE(dev2.keyboardFocus(), waylandSurface); + + wl_surface_destroy(surface); + QTRY_VERIFY(compositor.surfaces.size() == 0); + // This will normally be called for example in the quick compositor + // but here call it manually to get rid of the surface and have it reset + // the focus + compositor.handle()->cleanupGraphicsResources(); + + QTRY_VERIFY(!compositor.defaultInputDevice()->keyboardFocus()); + QTRY_VERIFY(!dev1.keyboardFocus()); + QTRY_VERIFY(!dev2.keyboardFocus()); +} + #include <tst_compositor.moc> QTEST_MAIN(tst_WaylandCompositor); |