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
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2022-04-22 09:27:33 +00:00
|
|
|
|
|
|
|
// server
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/compositor.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
#include "wayland/display.h"
|
2023-09-13 05:52:59 +00:00
|
|
|
#include "wayland/plasmashell.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
|
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-13 14:26:27 +00:00
|
|
|
|
|
|
|
#include <wayland-client-protocol.h>
|
2016-06-03 09:24:36 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
#include <cerrno> // For EPROTO
|
2017-05-05 12:17:40 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
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:
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display *m_display = nullptr;
|
2016-06-03 09:24:36 +00:00
|
|
|
CompositorInterface *m_ci = nullptr;
|
2016-06-13 14:26:27 +00:00
|
|
|
PlasmaShellInterface *m_psi = nullptr;
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::ConnectionThread *m_connection = nullptr;
|
2016-06-03 09:24:36 +00:00
|
|
|
QThread *m_thread = nullptr;
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::EventQueue *m_queue = nullptr;
|
|
|
|
KWayland::Client::Compositor *m_compositor = nullptr;
|
|
|
|
KWayland::Client::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;
|
2023-09-13 17:59:29 +00:00
|
|
|
m_display = new KWin::Display(this);
|
2020-10-19 15:52:56 +00:00
|
|
|
m_display->addSocketName(s_socketName);
|
2016-06-03 09:24:36 +00:00
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
|
|
|
m_display->createShm();
|
2020-12-09 20:13:19 +00:00
|
|
|
m_ci = new CompositorInterface(m_display, m_display);
|
|
|
|
m_psi = new PlasmaShellInterface(m_display, m_display);
|
2016-06-03 09:24:36 +00:00
|
|
|
|
|
|
|
// setup connection
|
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
|
2016-06-03 09:24:36 +00:00
|
|
|
m_connection->setSocketName(s_socketName);
|
|
|
|
|
|
|
|
m_thread = new QThread(this);
|
|
|
|
m_connection->moveToThread(m_thread);
|
|
|
|
m_thread->start();
|
|
|
|
|
|
|
|
m_connection->initConnection();
|
|
|
|
QVERIFY(connectedSpy.wait());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
m_queue = new KWayland::Client::EventQueue(this);
|
2016-06-03 09:24:36 +00:00
|
|
|
m_queue->setup(m_connection);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Registry registry;
|
|
|
|
QSignalSpy interfacesAnnouncedSpy(®istry, &KWayland::Client::Registry::interfacesAnnounced);
|
2016-06-03 09:24:36 +00:00
|
|
|
registry.setEventQueue(m_queue);
|
|
|
|
registry.create(m_connection);
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
QVERIFY(interfacesAnnouncedSpy.wait());
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
m_compositor =
|
2022-11-08 21:15:17 +00:00
|
|
|
registry.createCompositor(registry.interface(KWayland::Client::Registry::Interface::Compositor).name, registry.interface(KWayland::Client::Registry::Interface::Compositor).version, this);
|
2016-06-03 09:24:36 +00:00
|
|
|
QVERIFY(m_compositor);
|
2022-11-08 21:15:17 +00:00
|
|
|
m_plasmaShell = registry.createPlasmaShell(registry.interface(KWayland::Client::Registry::Interface::PlasmaShell).name,
|
|
|
|
registry.interface(KWayland::Client::Registry::Interface::PlasmaShell).version,
|
2016-06-13 14:26:27 +00:00
|
|
|
this);
|
|
|
|
QVERIFY(m_plasmaShell);
|
2016-06-03 09:24:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ErrorTest::cleanup()
|
|
|
|
{
|
2022-04-19 10:14:26 +00:00
|
|
|
#define CLEANUP(variable) \
|
|
|
|
if (variable) { \
|
|
|
|
delete variable; \
|
|
|
|
variable = nullptr; \
|
2016-06-03 09:24:36 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
CLEANUP(m_display)
|
|
|
|
#undef CLEANUP
|
2020-10-30 13:36:24 +00:00
|
|
|
// these are the children of the display
|
|
|
|
m_psi = nullptr;
|
|
|
|
m_ci = nullptr;
|
2016-06-03 09:24:36 +00:00
|
|
|
}
|
|
|
|
|
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
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy errorSpy(m_connection, &KWayland::Client::ConnectionThread::errorOccurred);
|
2016-06-13 14:26:27 +00:00
|
|
|
// 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);
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::PlasmaShellSurface> shellSurface1(m_plasmaShell->createSurface(surface));
|
|
|
|
std::unique_ptr<KWayland::Client::PlasmaShellSurface> shellSurface2(m_plasmaShell->createSurface(surface));
|
2016-06-13 14:26:27 +00:00
|
|
|
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"
|