2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-06-03 09:24:36 +00:00
|
|
|
|
2020-03-15 15:19:28 +00:00
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
2016-06-03 09:24:36 +00:00
|
|
|
// Qt
|
2018-11-06 06:22:36 +00:00
|
|
|
#include <QtTest>
|
2016-06-03 09:24:36 +00:00
|
|
|
// client
|
2020-04-29 13:59:23 +00:00
|
|
|
#include "KWayland/Client/compositor.h"
|
|
|
|
#include "KWayland/Client/connection_thread.h"
|
|
|
|
#include "KWayland/Client/event_queue.h"
|
|
|
|
#include "KWayland/Client/plasmashell.h"
|
|
|
|
#include "KWayland/Client/registry.h"
|
|
|
|
#include "KWayland/Client/surface.h"
|
2016-06-03 09:24:36 +00:00
|
|
|
// server
|
|
|
|
#include "../../src/server/display.h"
|
|
|
|
#include "../../src/server/compositor_interface.h"
|
2016-06-13 14:26:27 +00:00
|
|
|
#include "../../src/server/plasmashell_interface.h"
|
|
|
|
|
|
|
|
#include <wayland-client-protocol.h>
|
2016-06-03 09:24:36 +00:00
|
|
|
|
2020-08-05 12:21:04 +00:00
|
|
|
#include <cerrno> // For EPROTO
|
2017-05-05 12:17:40 +00:00
|
|
|
|
2016-06-03 09:24:36 +00:00
|
|
|
using namespace KWayland::Client;
|
2020-04-29 14:56:38 +00:00
|
|
|
using namespace KWaylandServer;
|
2016-06-03 09:24:36 +00:00
|
|
|
|
|
|
|
class ErrorTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
2016-06-13 14:26:27 +00:00
|
|
|
void testMultiplePlasmaShellSurfacesForSurface();
|
2016-06-03 09:24:36 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Display *m_display = nullptr;
|
|
|
|
CompositorInterface *m_ci = nullptr;
|
2016-06-13 14:26:27 +00:00
|
|
|
PlasmaShellInterface *m_psi = nullptr;
|
2016-06-03 09:24:36 +00:00
|
|
|
ConnectionThread *m_connection = nullptr;
|
|
|
|
QThread *m_thread = nullptr;
|
|
|
|
EventQueue *m_queue = nullptr;
|
|
|
|
Compositor *m_compositor = nullptr;
|
2016-06-13 14:26:27 +00:00
|
|
|
PlasmaShell *m_plasmaShell = nullptr;
|
2016-06-03 09:24:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwayland-test-error-0");
|
|
|
|
|
|
|
|
void ErrorTest::init()
|
|
|
|
{
|
|
|
|
delete m_display;
|
|
|
|
m_display = new Display(this);
|
|
|
|
m_display->setSocketName(s_socketName);
|
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
|
|
|
m_display->createShm();
|
|
|
|
m_ci = m_display->createCompositor(m_display);
|
2016-06-13 14:26:27 +00:00
|
|
|
m_psi = m_display->createPlasmaShell(m_display);
|
|
|
|
m_psi->create();
|
2016-06-03 09:24:36 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
m_queue->setup(m_connection);
|
|
|
|
|
|
|
|
Registry registry;
|
|
|
|
QSignalSpy interfacesAnnouncedSpy(®istry, &Registry::interfacesAnnounced);
|
|
|
|
QVERIFY(interfacesAnnouncedSpy.isValid());
|
|
|
|
registry.setEventQueue(m_queue);
|
|
|
|
registry.create(m_connection);
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
QVERIFY(interfacesAnnouncedSpy.wait());
|
|
|
|
|
|
|
|
m_compositor = registry.createCompositor(registry.interface(Registry::Interface::Compositor).name,
|
|
|
|
registry.interface(Registry::Interface::Compositor).version,
|
|
|
|
this);
|
|
|
|
QVERIFY(m_compositor);
|
2016-06-13 14:26:27 +00:00
|
|
|
m_plasmaShell = registry.createPlasmaShell(registry.interface(Registry::Interface::PlasmaShell).name,
|
|
|
|
registry.interface(Registry::Interface::PlasmaShell).version,
|
|
|
|
this);
|
|
|
|
QVERIFY(m_plasmaShell);
|
2016-06-03 09:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ErrorTest::cleanup()
|
|
|
|
{
|
|
|
|
#define CLEANUP(variable) \
|
|
|
|
if (variable) { \
|
|
|
|
delete variable; \
|
|
|
|
variable = nullptr; \
|
|
|
|
}
|
2016-06-13 14:26:27 +00:00
|
|
|
CLEANUP(m_plasmaShell)
|
2016-06-03 09:24:36 +00:00
|
|
|
CLEANUP(m_compositor)
|
|
|
|
CLEANUP(m_queue)
|
|
|
|
if (m_connection) {
|
|
|
|
m_connection->deleteLater();
|
|
|
|
m_connection = nullptr;
|
|
|
|
}
|
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
2016-06-13 14:26:27 +00:00
|
|
|
CLEANUP(m_psi)
|
2016-06-03 09:24:36 +00:00
|
|
|
CLEANUP(m_ci)
|
|
|
|
CLEANUP(m_display)
|
|
|
|
#undef CLEANUP
|
|
|
|
}
|
|
|
|
|
2016-06-13 14:26:27 +00:00
|
|
|
void ErrorTest::testMultiplePlasmaShellSurfacesForSurface()
|
|
|
|
{
|
|
|
|
// this test verifies that creating two ShellSurfaces for the same Surface triggers a protocol error
|
|
|
|
QSignalSpy errorSpy(m_connection, &ConnectionThread::errorOccurred);
|
|
|
|
QVERIFY(errorSpy.isValid());
|
|
|
|
// PlasmaShell is too smart and doesn't allow us to create a second PlasmaShellSurface
|
|
|
|
// thus we need to cheat by creating a surface manually
|
|
|
|
auto surface = wl_compositor_create_surface(*m_compositor);
|
|
|
|
QScopedPointer<PlasmaShellSurface> shellSurface1(m_plasmaShell->createSurface(surface));
|
|
|
|
QScopedPointer<PlasmaShellSurface> shellSurface2(m_plasmaShell->createSurface(surface));
|
|
|
|
QVERIFY(!m_connection->hasError());
|
|
|
|
QVERIFY(errorSpy.wait());
|
|
|
|
QVERIFY(m_connection->hasError());
|
|
|
|
QCOMPARE(m_connection->errorCode(), EPROTO);
|
|
|
|
wl_surface_destroy(surface);
|
|
|
|
}
|
|
|
|
|
2016-06-03 09:24:36 +00:00
|
|
|
QTEST_GUILESS_MAIN(ErrorTest)
|
|
|
|
#include "test_error.moc"
|