Commit 4f8f9849 authored by Martin Flöser's avatar Martin Flöser
Browse files

[autotest] Add tests for ServerSideDecoration protocol

REVIEW: 126301
parent d2f01dbb
......@@ -222,3 +222,14 @@ add_executable(testDataDevice ${testDataDevice_SRCS})
target_link_libraries( testDataDevice Qt5::Test Qt5::Gui KF5::WaylandClient KF5::WaylandServer Wayland::Client)
add_test(kwayland-testDataDevice testDataDevice)
ecm_mark_as_test(testDataDevice)
########################################################
# Test ServerSideDecoration
########################################################
set( testServerSideDecoration_SRCS
test_server_side_decoration.cpp
)
add_executable(testServerSideDecoration ${testServerSideDecoration_SRCS})
target_link_libraries( testServerSideDecoration Qt5::Test Qt5::Gui KF5::WaylandClient KF5::WaylandServer Wayland::Client)
add_test(kwayland-testServerSideDecoration testServerSideDecoration)
ecm_mark_as_test(testServerSideDecoration)
/********************************************************************
Copyright 2015 Martin Gräßlin <mgraesslin@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
// Qt
#include <QtTest/QtTest>
// KWin
#include "../../src/client/compositor.h"
#include "../../src/client/connection_thread.h"
#include "../../src/client/event_queue.h"
#include "../../src/client/registry.h"
#include "../../src/client/server_decoration.h"
#include "../../src/client/surface.h"
#include "../../src/server/display.h"
#include "../../src/server/compositor_interface.h"
#include "../../src/server/server_decoration_interface.h"
class TestServerSideDecoration : public QObject
{
Q_OBJECT
public:
explicit TestServerSideDecoration(QObject *parent = nullptr);
private Q_SLOTS:
void init();
void cleanup();
void testCreate_data();
void testCreate();
void testRequest_data();
void testRequest();
private:
KWayland::Server::Display *m_display = nullptr;
KWayland::Server::CompositorInterface *m_compositorInterface = nullptr;
KWayland::Server::ServerSideDecorationManagerInterface *m_serverSideDecorationManagerInterface = nullptr;
KWayland::Client::ConnectionThread *m_connection = nullptr;
KWayland::Client::Compositor *m_compositor = nullptr;
KWayland::Client::EventQueue *m_queue = nullptr;
KWayland::Client::ServerSideDecorationManager *m_serverSideDecorationManager = nullptr;
QThread *m_thread = nullptr;
KWayland::Client::Registry *m_registry = nullptr;
};
static const QString s_socketName = QStringLiteral("kwayland-test-wayland-server-side-decoration-0");
TestServerSideDecoration::TestServerSideDecoration(QObject *parent)
: QObject(parent)
{
}
void TestServerSideDecoration::init()
{
using namespace KWayland::Server;
using namespace KWayland::Client;
delete m_display;
m_display = new Display(this);
m_display->setSocketName(s_socketName);
m_display->start();
QVERIFY(m_display->isRunning());
// setup connection
m_connection = new KWayland::Client::ConnectionThread;
QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected);
QVERIFY(connectedSpy.isValid());
m_connection->setSocketName(s_socketName);
m_thread = new QThread(this);
m_connection->moveToThread(m_thread);
m_thread->start();
m_connection->initConnection();
QVERIFY(connectedSpy.wait());
m_queue = new EventQueue(this);
QVERIFY(!m_queue->isValid());
m_queue->setup(m_connection);
QVERIFY(m_queue->isValid());
m_registry = new Registry();
QSignalSpy compositorSpy(m_registry, &Registry::compositorAnnounced);
QVERIFY(compositorSpy.isValid());
QSignalSpy serverSideDecoManagerSpy(m_registry, &Registry::serverSideDecorationManagerAnnounced);
QVERIFY(serverSideDecoManagerSpy.isValid());
QVERIFY(!m_registry->eventQueue());
m_registry->setEventQueue(m_queue);
QCOMPARE(m_registry->eventQueue(), m_queue);
m_registry->create(m_connection);
QVERIFY(m_registry->isValid());
m_registry->setup();
m_compositorInterface = m_display->createCompositor(m_display);
m_compositorInterface->create();
QVERIFY(m_compositorInterface->isValid());
QVERIFY(compositorSpy.wait());
m_compositor = m_registry->createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
m_serverSideDecorationManagerInterface = m_display->createServerSideDecorationManager(m_display);
m_serverSideDecorationManagerInterface->create();
QVERIFY(m_serverSideDecorationManagerInterface->isValid());
QVERIFY(serverSideDecoManagerSpy.wait());
m_serverSideDecorationManager = m_registry->createServerSideDecorationManager(serverSideDecoManagerSpy.first().first().value<quint32>(),
serverSideDecoManagerSpy.first().last().value<quint32>(), this);
}
void TestServerSideDecoration::cleanup()
{
if (m_compositor) {
delete m_compositor;
m_compositor = nullptr;
}
if (m_serverSideDecorationManager) {
delete m_serverSideDecorationManager;
m_serverSideDecorationManager = nullptr;
}
if (m_queue) {
delete m_queue;
m_queue = nullptr;
}
if (m_registry) {
delete m_registry;
m_registry = nullptr;
}
if (m_thread) {
m_thread->quit();
m_thread->wait();
delete m_thread;
m_thread = nullptr;
}
delete m_connection;
m_connection = nullptr;
delete m_display;
m_display = nullptr;
}
void TestServerSideDecoration::testCreate_data()
{
using namespace KWayland::Client;
using namespace KWayland::Server;
QTest::addColumn<ServerSideDecorationManagerInterface::Mode>("serverMode");
QTest::addColumn<ServerSideDecoration::Mode>("clientMode");
QTest::newRow("none") << ServerSideDecorationManagerInterface::Mode::None << ServerSideDecoration::Mode::None;
QTest::newRow("client") << ServerSideDecorationManagerInterface::Mode::Client << ServerSideDecoration::Mode::Client;
QTest::newRow("server") << ServerSideDecorationManagerInterface::Mode::Server << ServerSideDecoration::Mode::Server;
}
void TestServerSideDecoration::testCreate()
{
using namespace KWayland::Client;
using namespace KWayland::Server;
QFETCH(KWayland::Server::ServerSideDecorationManagerInterface::Mode, serverMode);
m_serverSideDecorationManagerInterface->setDefaultMode(serverMode);
QCOMPARE(m_serverSideDecorationManagerInterface->defaultMode(), serverMode);
QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated);
QVERIFY(serverSurfaceCreated.isValid());
QSignalSpy decorationCreated(m_serverSideDecorationManagerInterface, &ServerSideDecorationManagerInterface::decorationCreated);
QVERIFY(decorationCreated.isValid());
QScopedPointer<Surface> surface(m_compositor->createSurface());
QVERIFY(serverSurfaceCreated.wait());
auto serverSurface = serverSurfaceCreated.first().first().value<SurfaceInterface*>();
QVERIFY(!ServerSideDecorationInterface::get(serverSurface));
// create server side deco
QScopedPointer<ServerSideDecoration> serverSideDecoration(m_serverSideDecorationManager->create(surface.data()));
QCOMPARE(serverSideDecoration->mode(), ServerSideDecoration::Mode::None);
QSignalSpy modeChangedSpy(serverSideDecoration.data(), &ServerSideDecoration::modeChanged);
QVERIFY(modeChangedSpy.isValid());
QVERIFY(decorationCreated.wait());
auto serverDeco = decorationCreated.first().first().value<ServerSideDecorationInterface*>();
QVERIFY(serverDeco);
QCOMPARE(serverDeco, ServerSideDecorationInterface::get(serverSurface));
QCOMPARE(serverDeco->surface(), serverSurface);
// after binding the client should get the default mode
QVERIFY(modeChangedSpy.wait());
QCOMPARE(modeChangedSpy.count(), 1);
QTEST(serverSideDecoration->mode(), "clientMode");
}
void TestServerSideDecoration::testRequest_data()
{
using namespace KWayland::Client;
using namespace KWayland::Server;
QTest::addColumn<ServerSideDecorationManagerInterface::Mode>("defaultMode");
QTest::addColumn<ServerSideDecoration::Mode>("clientMode");
QTest::addColumn<ServerSideDecoration::Mode>("clientRequestMode");
QTest::addColumn<ServerSideDecorationManagerInterface::Mode>("serverRequestedMode");
const auto serverNone = ServerSideDecorationManagerInterface::Mode::None;
const auto serverClient = ServerSideDecorationManagerInterface::Mode::Client;
const auto serverServer = ServerSideDecorationManagerInterface::Mode::Server;
const auto clientNone = ServerSideDecoration::Mode::None;
const auto clientClient = ServerSideDecoration::Mode::Client;
const auto clientServer = ServerSideDecoration::Mode::Server;
QTest::newRow("none->none") << serverNone << clientNone << clientNone << serverNone;
QTest::newRow("none->client") << serverNone << clientNone << clientClient << serverClient;
QTest::newRow("none->server") << serverNone << clientNone << clientServer << serverServer;
QTest::newRow("client->none") << serverClient << clientClient << clientNone << serverNone;
QTest::newRow("client->client") << serverClient << clientClient << clientClient << serverClient;
QTest::newRow("client->server") << serverClient << clientClient << clientServer << serverServer;
QTest::newRow("server->none") << serverServer << clientServer << clientNone << serverNone;
QTest::newRow("server->client") << serverServer << clientServer << clientClient << serverClient;
QTest::newRow("server->server") << serverServer << clientServer << clientServer << serverServer;
}
void TestServerSideDecoration::testRequest()
{
using namespace KWayland::Client;
using namespace KWayland::Server;
QFETCH(KWayland::Server::ServerSideDecorationManagerInterface::Mode, defaultMode);
m_serverSideDecorationManagerInterface->setDefaultMode(defaultMode);
QCOMPARE(m_serverSideDecorationManagerInterface->defaultMode(), defaultMode);
QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated);
QVERIFY(serverSurfaceCreated.isValid());
QSignalSpy decorationCreated(m_serverSideDecorationManagerInterface, &ServerSideDecorationManagerInterface::decorationCreated);
QVERIFY(decorationCreated.isValid());
// create server side deco
QScopedPointer<Surface> surface(m_compositor->createSurface());
QScopedPointer<ServerSideDecoration> serverSideDecoration(m_serverSideDecorationManager->create(surface.data()));
QCOMPARE(serverSideDecoration->mode(), ServerSideDecoration::Mode::None);
QSignalSpy modeChangedSpy(serverSideDecoration.data(), &ServerSideDecoration::modeChanged);
QVERIFY(modeChangedSpy.isValid());
QVERIFY(decorationCreated.wait());
auto serverDeco = decorationCreated.first().first().value<ServerSideDecorationInterface*>();
QVERIFY(serverDeco);
QSignalSpy modeSpy(serverDeco, &ServerSideDecorationInterface::modeRequested);
QVERIFY(modeSpy.isValid());
// after binding the client should get the default mode
QVERIFY(modeChangedSpy.wait());
QCOMPARE(modeChangedSpy.count(), 1);
QTEST(serverSideDecoration->mode(), "clientMode");
// request a change
QFETCH(ServerSideDecoration::Mode, clientRequestMode);
serverSideDecoration->requestMode(clientRequestMode);
// mode not yet changed
QTEST(serverSideDecoration->mode(), "clientMode");
QVERIFY(modeSpy.wait());
QCOMPARE(modeSpy.count(), 1);
QFETCH(ServerSideDecorationManagerInterface::Mode, serverRequestedMode);
QCOMPARE(modeSpy.first().first().value<ServerSideDecorationManagerInterface::Mode>(), serverRequestedMode);
// mode not yet changed
QCOMPARE(serverDeco->mode(), defaultMode);
serverDeco->setMode(serverRequestedMode);
QCOMPARE(serverDeco->mode(), serverRequestedMode);
// should be sent to client
QVERIFY(modeChangedSpy.wait());
QCOMPARE(modeChangedSpy.count(), 2);
QCOMPARE(serverSideDecoration->mode(), clientRequestMode);
}
QTEST_GUILESS_MAIN(TestServerSideDecoration)
#include "test_server_side_decoration.moc"
......@@ -27,6 +27,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include "../../src/client/registry.h"
#include "../../src/client/output.h"
#include "../../src/client/seat.h"
#include "../../src/client/server_decoration.h"
#include "../../src/client/shell.h"
#include "../../src/client/subcompositor.h"
#include "../../src/server/compositor_interface.h"
......@@ -38,6 +39,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include "../../src/server/shell_interface.h"
#include "../../src/server/blur_interface.h"
#include "../../src/server/contrast_interface.h"
#include "../../src/server/server_decoration_interface.h"
#include "../../src/server/slide_interface.h"
#include "../../src/server/subcompositor_interface.h"
#include "../../src/server/outputmanagement_interface.h"
......@@ -45,6 +47,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
// Wayland
#include <wayland-client-protocol.h>
#include <wayland-dpms-client-protocol.h>
#include <wayland-server-decoration-client-protocol.h>
class TestWaylandRegistry : public QObject
{
......@@ -67,6 +70,7 @@ private Q_SLOTS:
void testBindContrastManager();
void testBindSlideManager();
void testBindDpmsManager();
void testBindServerSideDecorationManager();
void testGlobalSync();
void testGlobalSyncThreaded();
void testRemoval();
......@@ -84,6 +88,7 @@ private:
KWayland::Server::SubCompositorInterface *m_subcompositor;
KWayland::Server::DataDeviceManagerInterface *m_dataDeviceManager;
KWayland::Server::OutputManagementInterface *m_outputManagement;
KWayland::Server::ServerSideDecorationManagerInterface *m_serverSideDecorationManager;
};
static const QString s_socketName = QStringLiteral("kwin-test-wayland-registry-0");
......@@ -99,6 +104,7 @@ TestWaylandRegistry::TestWaylandRegistry(QObject *parent)
, m_subcompositor(nullptr)
, m_dataDeviceManager(nullptr)
, m_outputManagement(nullptr)
, m_serverSideDecorationManager(nullptr)
{
}
......@@ -129,6 +135,8 @@ void TestWaylandRegistry::init()
m_display->createContrastManager(this)->create();
m_display->createSlideManager(this)->create();
m_display->createDpmsManager()->create();
m_serverSideDecorationManager = m_display->createServerSideDecorationManager();
m_serverSideDecorationManager->create();
}
void TestWaylandRegistry::cleanup()
......@@ -251,6 +259,11 @@ void TestWaylandRegistry::testBindDpmsManager()
TEST_BIND(KWayland::Client::Registry::Interface::Dpms, SIGNAL(dpmsAnnounced(quint32,quint32)), bindDpmsManager, org_kde_kwin_dpms_manager_destroy)
}
void TestWaylandRegistry::testBindServerSideDecorationManager()
{
TEST_BIND(KWayland::Client::Registry::Interface::ServerSideDecorationManager, SIGNAL(serverSideDecorationManagerAnnounced(quint32,quint32)), bindServerSideDecorationManager, org_kde_kwin_server_decoration_manager_destroy)
}
#undef TEST_BIND
void TestWaylandRegistry::testRemoval()
......@@ -284,6 +297,8 @@ void TestWaylandRegistry::testRemoval()
QVERIFY(subCompositorAnnouncedSpy.isValid());
QSignalSpy outputManagementAnnouncedSpy(&registry, SIGNAL(outputManagementAnnounced(quint32,quint32)));
QVERIFY(outputManagementAnnouncedSpy.isValid());
QSignalSpy serverSideDecorationManagerAnnouncedSpy(&registry, &Registry::serverSideDecorationManagerAnnounced);
QVERIFY(serverSideDecorationManagerAnnouncedSpy.isValid());
QVERIFY(!registry.isValid());
registry.create(connection.display());
......@@ -297,6 +312,7 @@ void TestWaylandRegistry::testRemoval()
QVERIFY(!seatAnnouncedSpy.isEmpty());
QVERIFY(!subCompositorAnnouncedSpy.isEmpty());
QVERIFY(!outputManagementAnnouncedSpy.isEmpty());
QVERIFY(!serverSideDecorationManagerAnnouncedSpy.isEmpty());
QVERIFY(registry.hasInterface(KWayland::Client::Registry::Interface::Compositor));
QVERIFY(registry.hasInterface(KWayland::Client::Registry::Interface::Output));
......@@ -307,6 +323,7 @@ void TestWaylandRegistry::testRemoval()
QVERIFY(registry.hasInterface(KWayland::Client::Registry::Interface::SubCompositor));
QVERIFY(!registry.hasInterface(KWayland::Client::Registry::Interface::FullscreenShell));
QVERIFY(registry.hasInterface(KWayland::Client::Registry::Interface::OutputManagement));
QVERIFY(registry.hasInterface(KWayland::Client::Registry::Interface::ServerSideDecorationManager));
QVERIFY(!registry.interfaces(KWayland::Client::Registry::Interface::Compositor).isEmpty());
QVERIFY(!registry.interfaces(KWayland::Client::Registry::Interface::Output).isEmpty());
......@@ -317,6 +334,7 @@ void TestWaylandRegistry::testRemoval()
QVERIFY(!registry.interfaces(KWayland::Client::Registry::Interface::SubCompositor).isEmpty());
QVERIFY(registry.interfaces(KWayland::Client::Registry::Interface::FullscreenShell).isEmpty());
QVERIFY(!registry.interfaces(KWayland::Client::Registry::Interface::OutputManagement).isEmpty());
QVERIFY(!registry.interfaces(KWayland::Client::Registry::Interface::ServerSideDecorationManager).isEmpty());
QSignalSpy seatRemovedSpy(&registry, SIGNAL(seatRemoved(quint32)));
QVERIFY(seatRemovedSpy.isValid());
......@@ -326,6 +344,7 @@ void TestWaylandRegistry::testRemoval()
Output *output = registry.createOutput(registry.interface(Registry::Interface::Output).name, registry.interface(Registry::Interface::Output).version, &registry);
Compositor *compositor = registry.createCompositor(registry.interface(Registry::Interface::Compositor).name, registry.interface(Registry::Interface::Compositor).version, &registry);
SubCompositor *subcompositor = registry.createSubCompositor(registry.interface(Registry::Interface::SubCompositor).name, registry.interface(Registry::Interface::SubCompositor).version, &registry);
ServerSideDecorationManager *serverSideDeco = registry.createServerSideDecorationManager(registry.interface(Registry::Interface::ServerSideDecorationManager).name, registry.interface(Registry::Interface::ServerSideDecorationManager).version, &registry);
connection.flush();
m_display->dispatchEvents();
QSignalSpy seatObjectRemovedSpy(seat, &Seat::removed);
......@@ -404,6 +423,18 @@ void TestWaylandRegistry::testRemoval()
QVERIFY(!registry.hasInterface(KWayland::Client::Registry::Interface::OutputManagement));
QVERIFY(registry.interfaces(KWayland::Client::Registry::Interface::OutputManagement).isEmpty());
QSignalSpy serverSideDecoManagerRemovedSpy(&registry, &Registry::serverSideDecorationManagerRemoved);
QVERIFY(serverSideDecoManagerRemovedSpy.isValid());
QSignalSpy serverSideDecoManagerObjectRemovedSpy(serverSideDeco, &ServerSideDecorationManager::removed);
QVERIFY(serverSideDecoManagerObjectRemovedSpy.isValid());
delete m_serverSideDecorationManager;
QVERIFY(serverSideDecoManagerRemovedSpy.wait());
QCOMPARE(serverSideDecoManagerRemovedSpy.first().first(), serverSideDecorationManagerAnnouncedSpy.first().first());
QVERIFY(!registry.hasInterface(KWayland::Client::Registry::Interface::ServerSideDecorationManager));
QVERIFY(registry.interfaces(KWayland::Client::Registry::Interface::ServerSideDecorationManager).isEmpty());
QCOMPARE(serverSideDecoManagerObjectRemovedSpy.count(), 1);
// cannot test shmRemoved as there is no functionality for it
// verify everything has been removed only once
......@@ -412,6 +443,7 @@ void TestWaylandRegistry::testRemoval()
QCOMPARE(outputObjectRemovedSpy.count(), 1);
QCOMPARE(compositorObjectRemovedSpy.count(), 1);
QCOMPARE(subcompositorObjectRemovedSpy.count(), 1);
QCOMPARE(serverSideDecoManagerObjectRemovedSpy.count(), 1);
}
void TestWaylandRegistry::testDestroy()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment