2020-03-15 15:19:28 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
|
2015-09-09 11:04:11 +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
|
|
|
|
*/
|
2015-09-09 11:04:11 +00:00
|
|
|
// Qt
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2015-09-09 11:04:11 +00:00
|
|
|
// KWin
|
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/slide.h"
|
2022-04-22 09:27:33 +00:00
|
|
|
|
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/region.h"
|
|
|
|
#include "KWayland/Client/registry.h"
|
|
|
|
#include "KWayland/Client/slide.h"
|
2021-08-29 05:11:06 +00:00
|
|
|
#include "KWayland/Client/surface.h"
|
2015-09-09 11:04:11 +00:00
|
|
|
|
|
|
|
class TestSlide : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TestSlide(QObject *parent = nullptr);
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testCreate();
|
2016-05-30 12:00:24 +00:00
|
|
|
void testSurfaceDestroy();
|
2015-09-09 11:04:11 +00:00
|
|
|
|
|
|
|
private:
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display *m_display;
|
|
|
|
KWin::CompositorInterface *m_compositorInterface;
|
|
|
|
KWin::SlideManagerInterface *m_slideManagerInterface;
|
2015-09-09 11:04:11 +00:00
|
|
|
KWayland::Client::ConnectionThread *m_connection;
|
|
|
|
KWayland::Client::Compositor *m_compositor;
|
|
|
|
KWayland::Client::SlideManager *m_slideManager;
|
|
|
|
KWayland::Client::EventQueue *m_queue;
|
|
|
|
QThread *m_thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwayland-test-wayland-slide-0");
|
|
|
|
|
|
|
|
TestSlide::TestSlide(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_display(nullptr)
|
|
|
|
, m_compositorInterface(nullptr)
|
|
|
|
, m_connection(nullptr)
|
|
|
|
, m_compositor(nullptr)
|
|
|
|
, m_queue(nullptr)
|
|
|
|
, m_thread(nullptr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestSlide::init()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2015-09-09 11:04:11 +00:00
|
|
|
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);
|
2015-09-09 11:04:11 +00:00
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
|
|
|
|
|
|
|
// setup connection
|
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
|
2015-09-09 11:04:11 +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());
|
|
|
|
|
|
|
|
m_queue = new KWayland::Client::EventQueue(this);
|
|
|
|
QVERIFY(!m_queue->isValid());
|
|
|
|
m_queue->setup(m_connection);
|
|
|
|
QVERIFY(m_queue->isValid());
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
KWayland::Client::Registry registry;
|
|
|
|
QSignalSpy compositorSpy(®istry, &KWayland::Client::Registry::compositorAnnounced);
|
2015-09-09 11:04:11 +00:00
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
QSignalSpy slideSpy(®istry, &KWayland::Client::Registry::slideAnnounced);
|
2015-09-09 11:04:11 +00:00
|
|
|
|
2016-05-30 09:55:10 +00:00
|
|
|
QVERIFY(!registry.eventQueue());
|
|
|
|
registry.setEventQueue(m_queue);
|
|
|
|
QCOMPARE(registry.eventQueue(), m_queue);
|
|
|
|
registry.create(m_connection->display());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
2015-09-09 11:04:11 +00:00
|
|
|
|
2020-12-09 20:13:19 +00:00
|
|
|
m_compositorInterface = new CompositorInterface(m_display, m_display);
|
2015-09-09 11:04:11 +00:00
|
|
|
QVERIFY(compositorSpy.wait());
|
2016-05-30 09:55:10 +00:00
|
|
|
m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this);
|
2015-09-09 11:04:11 +00:00
|
|
|
|
2020-12-09 20:13:19 +00:00
|
|
|
m_slideManagerInterface = new SlideManagerInterface(m_display, m_display);
|
2015-09-09 11:04:11 +00:00
|
|
|
|
|
|
|
QVERIFY(slideSpy.wait());
|
2016-05-30 09:55:10 +00:00
|
|
|
m_slideManager = registry.createSlideManager(slideSpy.first().first().value<quint32>(), slideSpy.first().last().value<quint32>(), this);
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestSlide::cleanup()
|
|
|
|
{
|
2022-04-19 10:14:26 +00:00
|
|
|
#define CLEANUP(variable) \
|
|
|
|
if (variable) { \
|
|
|
|
delete variable; \
|
|
|
|
variable = nullptr; \
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
2016-05-30 09:55:10 +00:00
|
|
|
CLEANUP(m_compositor)
|
|
|
|
CLEANUP(m_slideManager)
|
|
|
|
CLEANUP(m_queue)
|
|
|
|
if (m_connection) {
|
|
|
|
m_connection->deleteLater();
|
|
|
|
m_connection = nullptr;
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
2016-05-30 09:55:10 +00:00
|
|
|
CLEANUP(m_display)
|
|
|
|
#undef CLEANUP
|
2020-12-01 11:03:48 +00:00
|
|
|
// these are the children of the display
|
|
|
|
m_compositorInterface = nullptr;
|
|
|
|
m_slideManagerInterface = nullptr;
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestSlide::testCreate()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &KWin::CompositorInterface::surfaceCreated);
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2015-09-09 11:04:11 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
auto serverSurface = serverSurfaceCreated.first().first().value<KWin::SurfaceInterface *>();
|
|
|
|
QSignalSpy slideChanged(serverSurface, &KWin::SurfaceInterface::slideOnShowHideChanged);
|
2015-09-09 11:04:11 +00:00
|
|
|
|
2022-08-01 21:29:02 +00:00
|
|
|
auto slide = m_slideManager->createSlide(surface.get(), surface.get());
|
2015-09-09 11:04:11 +00:00
|
|
|
slide->setLocation(KWayland::Client::Slide::Location::Top);
|
|
|
|
slide->setOffset(15);
|
|
|
|
slide->commit();
|
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
|
|
|
|
QVERIFY(slideChanged.wait());
|
2023-09-13 17:59:29 +00:00
|
|
|
QCOMPARE(serverSurface->slideOnShowHide()->location(), KWin::SlideInterface::Location::Top);
|
2015-09-09 11:04:11 +00:00
|
|
|
QCOMPARE(serverSurface->slideOnShowHide()->offset(), 15);
|
2016-05-30 09:58:59 +00:00
|
|
|
|
|
|
|
// and destroy
|
2023-09-07 10:56:54 +00:00
|
|
|
QSignalSpy destroyedSpy(serverSurface->slideOnShowHide(), &QObject::destroyed);
|
2016-05-30 09:58:59 +00:00
|
|
|
delete slide;
|
|
|
|
QVERIFY(destroyedSpy.wait());
|
2015-09-09 11:04:11 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 12:00:24 +00:00
|
|
|
void TestSlide::testSurfaceDestroy()
|
|
|
|
{
|
2023-09-13 17:59:29 +00:00
|
|
|
using namespace KWin;
|
2016-05-30 12:00:24 +00:00
|
|
|
QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated);
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface(m_compositor->createSurface());
|
2016-05-30 12:00:24 +00:00
|
|
|
QVERIFY(serverSurfaceCreated.wait());
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
auto serverSurface = serverSurfaceCreated.first().first().value<SurfaceInterface *>();
|
2016-05-30 12:00:24 +00:00
|
|
|
QSignalSpy slideChanged(serverSurface, &SurfaceInterface::slideOnShowHideChanged);
|
|
|
|
|
2022-11-08 21:15:17 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Slide> slide(m_slideManager->createSlide(surface.get()));
|
2016-05-30 12:00:24 +00:00
|
|
|
slide->commit();
|
|
|
|
surface->commit(KWayland::Client::Surface::CommitFlag::None);
|
|
|
|
QVERIFY(slideChanged.wait());
|
|
|
|
auto serverSlide = serverSurface->slideOnShowHide();
|
2023-09-07 10:56:54 +00:00
|
|
|
QVERIFY(serverSlide);
|
2016-05-30 12:00:24 +00:00
|
|
|
|
|
|
|
// destroy the parent surface
|
|
|
|
QSignalSpy surfaceDestroyedSpy(serverSurface, &QObject::destroyed);
|
2023-09-07 10:56:54 +00:00
|
|
|
QSignalSpy slideDestroyedSpy(serverSlide, &QObject::destroyed);
|
2016-05-30 12:00:24 +00:00
|
|
|
surface.reset();
|
|
|
|
QVERIFY(surfaceDestroyedSpy.wait());
|
|
|
|
QVERIFY(slideDestroyedSpy.isEmpty());
|
|
|
|
// destroy the slide
|
|
|
|
slide.reset();
|
|
|
|
QVERIFY(slideDestroyedSpy.wait());
|
|
|
|
}
|
|
|
|
|
2015-11-11 07:36:31 +00:00
|
|
|
QTEST_GUILESS_MAIN(TestSlide)
|
2015-09-09 11:04:11 +00:00
|
|
|
#include "test_wayland_slide.moc"
|