Add client-side tests for ivi-application

Tests ivi surface creation and configuration.

Task-number: QTBUG-66512
Change-Id: Idff60eb99eb34b7fce1c935bd036ef18a8f97d7c
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
This commit is contained in:
Johan Klokkhammer Helsing 2018-03-08 12:32:59 +01:00 committed by Johan Helsing
parent 45dbab401a
commit 08d8136071
7 changed files with 221 additions and 0 deletions

View File

@ -2,5 +2,6 @@ TEMPLATE=subdirs
SUBDIRS += \
client \
iviapplication \
xdgshellv6 \
wl_connect

View File

@ -0,0 +1,5 @@
include (../shared/shared.pri)
TARGET = tst_client_iviapplication
SOURCES += tst_iviapplication.cpp

View File

@ -32,6 +32,7 @@
#include "mocksurface.h"
#include "mockwlshell.h"
#include "mockxdgshellv6.h"
#include "mockiviapplication.h"
#include <wayland-xdg-shell-unstable-v6-server-protocol.h>
@ -227,6 +228,14 @@ void MockCompositor::sendShellSurfaceConfigure(const QSharedPointer<MockSurface>
processCommand(command);
}
void MockCompositor::sendIviSurfaceConfigure(const QSharedPointer<MockIviSurface> iviSurface, const QSize &size)
{
Command command = makeCommand(Impl::Compositor::sendIviSurfaceConfigure, m_compositor);
command.parameters << QVariant::fromValue(iviSurface);
command.parameters << QVariant::fromValue(size);
processCommand(command);
}
void MockCompositor::sendXdgToplevelV6Configure(const QSharedPointer<MockXdgToplevelV6> toplevel, const QSize &size)
{
Command command = makeCommand(Impl::Compositor::sendXdgToplevelV6Configure, m_compositor);
@ -267,6 +276,16 @@ QSharedPointer<MockOutput> MockCompositor::output(int index)
return result;
}
QSharedPointer<MockIviSurface> MockCompositor::iviSurface(int index)
{
QSharedPointer<MockIviSurface> result;
lock();
if (Impl::IviSurface *toplevel = m_compositor->iviApplication()->iviSurfaces().value(index, nullptr))
result = toplevel->mockIviSurface();
unlock();
return result;
}
QSharedPointer<MockXdgToplevelV6> MockCompositor::xdgToplevelV6(int index)
{
QSharedPointer<MockXdgToplevelV6> result;
@ -357,6 +376,7 @@ Compositor::Compositor()
m_touch = m_seat->touch();
m_outputs.append(new Output(m_display, QSize(1920, 1080), QPoint(0, 0)));
m_iviApplication.reset(new IviApplication(m_display));
m_wlShell.reset(new WlShell(m_display));
m_xdgShellV6.reset(new XdgShellV6(m_display));
@ -426,6 +446,11 @@ QVector<Output *> Compositor::outputs() const
return m_outputs;
}
IviApplication *Compositor::iviApplication() const
{
return m_iviApplication.data();
}
XdgShellV6 *Compositor::xdgShellV6() const
{
return m_xdgShellV6.data();
@ -460,6 +485,12 @@ Output *Compositor::resolveOutput(const QVariant &v)
return mockOutput ? mockOutput->handle() : nullptr;
}
IviSurface *Compositor::resolveIviSurface(const QVariant &v)
{
QSharedPointer<MockIviSurface> mockIviSurface = v.value<QSharedPointer<MockIviSurface>>();
return mockIviSurface ? mockIviSurface->handle() : nullptr;
}
XdgToplevelV6 *Compositor::resolveToplevel(const QVariant &v)
{
QSharedPointer<MockXdgToplevelV6> mockToplevel = v.value<QSharedPointer<MockXdgToplevelV6>>();

View File

@ -30,6 +30,7 @@
#define MOCKCOMPOSITOR_H
#include "mockxdgshellv6.h"
#include "mockiviapplication.h"
#include <pthread.h>
#include <qglobal.h>
@ -54,6 +55,7 @@ class Seat;
class DataDeviceManager;
class Surface;
class Output;
class IviApplication;
class WlShell;
class XdgShellV6;
@ -72,6 +74,7 @@ public:
QVector<Surface *> surfaces() const;
QVector<Output *> outputs() const;
IviApplication *iviApplication() const;
XdgShellV6 *xdgShellV6() const;
void addSurface(Surface *surface);
@ -99,6 +102,7 @@ public:
static void sendSurfaceEnter(void *data, const QList<QVariant> &parameters);
static void sendSurfaceLeave(void *data, const QList<QVariant> &parameters);
static void sendShellSurfaceConfigure(void *data, const QList<QVariant> &parameters);
static void sendIviSurfaceConfigure(void *data, const QList<QVariant> &parameters);
static void sendXdgToplevelV6Configure(void *data, const QList<QVariant> &parameters);
public:
@ -108,6 +112,7 @@ private:
static void bindCompositor(wl_client *client, void *data, uint32_t version, uint32_t id);
static Surface *resolveSurface(const QVariant &v);
static Output *resolveOutput(const QVariant &v);
static IviSurface *resolveIviSurface(const QVariant &v);
static XdgToplevelV6 *resolveToplevel(const QVariant &v);
void initShm();
@ -128,6 +133,7 @@ private:
QScopedPointer<DataDeviceManager> m_data_device_manager;
QVector<Surface *> m_surfaces;
QVector<Output *> m_outputs;
QScopedPointer<IviApplication> m_iviApplication;
QScopedPointer<WlShell> m_wlShell;
QScopedPointer<XdgShellV6> m_xdgShellV6;
};
@ -153,6 +159,22 @@ private:
Q_DECLARE_METATYPE(QSharedPointer<MockSurface>)
class MockIviSurface
{
public:
Impl::IviSurface *handle() const { return m_iviSurface; }
const uint iviId;
private:
MockIviSurface(Impl::IviSurface *iviSurface) : iviId(iviSurface->iviId()), m_iviSurface(iviSurface) {}
friend class Impl::Compositor;
friend class Impl::IviSurface;
Impl::IviSurface *m_iviSurface;
};
Q_DECLARE_METATYPE(QSharedPointer<MockIviSurface>)
class MockXdgToplevelV6
{
public:
@ -211,11 +233,13 @@ public:
void sendSurfaceEnter(const QSharedPointer<MockSurface> &surface, QSharedPointer<MockOutput> &output);
void sendSurfaceLeave(const QSharedPointer<MockSurface> &surface, QSharedPointer<MockOutput> &output);
void sendShellSurfaceConfigure(const QSharedPointer<MockSurface> surface, const QSize &size = QSize(0, 0));
void sendIviSurfaceConfigure(const QSharedPointer<MockIviSurface> iviSurface, const QSize &size);
void sendXdgToplevelV6Configure(const QSharedPointer<MockXdgToplevelV6> toplevel, const QSize &size = QSize(0, 0));
void waitForStartDrag();
QSharedPointer<MockSurface> surface();
QSharedPointer<MockOutput> output(int index = 0);
QSharedPointer<MockIviSurface> iviSurface(int index = 0);
QSharedPointer<MockXdgToplevelV6> xdgToplevelV6(int index = 0);
void lock();

View File

@ -0,0 +1,72 @@
/****************************************************************************
**
** Copyright (C) 2017 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 "mockiviapplication.h"
#include "mocksurface.h"
#include "mockcompositor.h"
namespace Impl {
void Compositor::sendIviSurfaceConfigure(void *data, const QList<QVariant> &parameters)
{
Q_UNUSED(data);
IviSurface *iviSurface = resolveIviSurface(parameters.at(0));
Q_ASSERT(iviSurface && iviSurface->resource());
QSize size = parameters.at(1).toSize();
Q_ASSERT(!size.isEmpty());
iviSurface->send_configure(size.width(), size.height());
}
IviSurface::IviSurface(IviApplication *iviApplication, Surface *surface, uint iviId, wl_client *client, uint32_t id)
: QtWaylandServer::ivi_surface(client, id, 1)
, m_surface(surface)
, m_iviApplication(iviApplication)
, m_iviId(iviId)
, m_mockIviSurface(new MockIviSurface(this))
{
iviApplication->addIviSurface(this);
surface->map();
}
IviSurface::~IviSurface()
{
m_iviApplication->removeIviSurface(this);
m_mockIviSurface->m_iviSurface = nullptr;
}
void IviSurface::ivi_surface_destroy(Resource *resource)
{
wl_resource_destroy(resource->handle);
}
void IviApplication::ivi_application_surface_create(Resource *resource, uint32_t ivi_id, ::wl_resource *surface, uint32_t id)
{
new IviSurface(this, Surface::fromResource(surface), ivi_id, resource->client(), id);
}
} // namespace Impl

View File

@ -0,0 +1,85 @@
/****************************************************************************
**
** 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$
**
****************************************************************************/
#ifndef MOCKIVIAPPLICATION_H
#define MOCKIVIAPPLICATION_H
#include <qwayland-server-ivi-application.h>
#include <QSharedPointer>
#include <QVector>
class MockIviSurface;
namespace Impl {
class Surface;
class IviApplication;
class IviSurface : public QtWaylandServer::ivi_surface
{
public:
IviSurface(IviApplication *iviApplication, Surface *surface, uint iviId, wl_client *client, uint32_t id);
~IviSurface() override;
IviApplication *iviApplication() const { return m_iviApplication; }
Surface *surface() const { return m_surface; }
uint iviId() const { return m_iviId; }
QSharedPointer<MockIviSurface> mockIviSurface() const { return m_mockIviSurface; }
protected:
void ivi_surface_destroy_resource(Resource *) override { delete this; }
void ivi_surface_destroy(Resource *resource) override;
private:
Surface *m_surface = nullptr;
IviApplication *m_iviApplication = nullptr;
const uint m_iviId = 0;
QSharedPointer<MockIviSurface> m_mockIviSurface;
};
class IviApplication : public QtWaylandServer::ivi_application
{
public:
explicit IviApplication(::wl_display *display) : ivi_application(display, 1) {}
QVector<IviSurface *> iviSurfaces() const { return m_iviSurfaces; }
protected:
void ivi_application_surface_create(Resource *resource, uint32_t ivi_id, ::wl_resource *surface, uint32_t id) override;
private:
void addIviSurface(IviSurface *iviSurface) { m_iviSurfaces.append(iviSurface); }
void removeIviSurface(IviSurface *iviSurface) { m_iviSurfaces.removeOne(iviSurface); }
QVector<IviSurface *> m_iviSurfaces;
friend class IviSurface;
};
} // namespace Impl
#endif // MOCKIVIAPPLICATION_H

View File

@ -6,6 +6,7 @@ QMAKE_USE += wayland-client wayland-server
CONFIG += wayland-scanner
WAYLANDSERVERSOURCES += \
../../../../src/3rdparty/protocol/ivi-application.xml \
../../../../src/3rdparty/protocol/wayland.xml \
../../../../src/3rdparty/protocol/xdg-shell-unstable-v6.xml
@ -14,6 +15,7 @@ INCLUDEPATH += ../shared
SOURCES += \
../shared/mockcompositor.cpp \
../shared/mockinput.cpp \
../shared/mockiviapplication.cpp \
../shared/mockwlshell.cpp \
../shared/mockxdgshellv6.cpp \
../shared/mocksurface.cpp \
@ -22,6 +24,7 @@ SOURCES += \
HEADERS += \
../shared/mockcompositor.h \
../shared/mockinput.h \
../shared/mockiviapplication.h \
../shared/mockwlshell.h \
../shared/mockxdgshellv6.h \
../shared/mocksurface.h \