2020-06-16 14:58:21 +00:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Qt
|
|
|
|
#include <QHash>
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QSignalSpy>
|
|
|
|
#include <QTest>
|
2020-06-16 14:58:21 +00:00
|
|
|
#include <QThread>
|
|
|
|
|
|
|
|
#include <wayland-client.h>
|
|
|
|
|
|
|
|
// WaylandServer
|
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/screencast_v1.h"
|
|
|
|
#include "wayland/seat.h"
|
2020-06-16 14:58:21 +00:00
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
#include <KWayland/Client/compositor.h>
|
2020-06-16 14:58:21 +00:00
|
|
|
#include <KWayland/Client/connection_thread.h>
|
|
|
|
#include <KWayland/Client/event_queue.h>
|
|
|
|
#include <KWayland/Client/registry.h>
|
|
|
|
#include <KWayland/Client/seat.h>
|
|
|
|
|
|
|
|
#include "qwayland-zkde-screencast-unstable-v1.h"
|
|
|
|
|
2020-09-04 14:45:47 +00:00
|
|
|
class ScreencastStreamV1 : public QObject, public QtWayland::zkde_screencast_stream_unstable_v1
|
2020-06-16 14:58:21 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-09-04 14:45:47 +00:00
|
|
|
|
2020-06-16 14:58:21 +00:00
|
|
|
public:
|
2020-09-04 14:45:47 +00:00
|
|
|
ScreencastStreamV1(::zkde_screencast_stream_unstable_v1 *obj, QObject *parent)
|
2020-06-16 14:58:21 +00:00
|
|
|
: QObject(parent)
|
|
|
|
, zkde_screencast_stream_unstable_v1(obj)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
void zkde_screencast_stream_unstable_v1_created(uint32_t node) override
|
|
|
|
{
|
2020-06-16 14:58:21 +00:00
|
|
|
Q_EMIT created(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void created(quint32 node);
|
|
|
|
};
|
2020-09-04 14:45:47 +00:00
|
|
|
|
|
|
|
class ScreencastV1 : public QObject, public QtWayland::zkde_screencast_unstable_v1
|
2020-06-16 14:58:21 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-09-04 14:45:47 +00:00
|
|
|
|
2020-06-16 14:58:21 +00:00
|
|
|
public:
|
2020-09-04 14:45:47 +00:00
|
|
|
ScreencastV1(QObject *parent)
|
2020-06-16 14:58:21 +00:00
|
|
|
: QObject(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-29 05:11:06 +00:00
|
|
|
ScreencastStreamV1 *createWindowStream(const QString &uuid)
|
|
|
|
{
|
2020-09-04 14:45:47 +00:00
|
|
|
return new ScreencastStreamV1(stream_window(uuid, 2), this);
|
2020-06-16 14:58:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-04 14:45:47 +00:00
|
|
|
class TestScreencastV1Interface : public QObject
|
2020-06-16 14:58:21 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2020-09-04 14:45:47 +00:00
|
|
|
|
2020-06-16 14:58:21 +00:00
|
|
|
public:
|
2020-09-04 14:45:47 +00:00
|
|
|
TestScreencastV1Interface()
|
2020-06-16 14:58:21 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-09-04 14:45:47 +00:00
|
|
|
~TestScreencastV1Interface() override;
|
2020-06-16 14:58:21 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void testCreate();
|
|
|
|
|
|
|
|
private:
|
|
|
|
KWayland::Client::ConnectionThread *m_connection;
|
|
|
|
KWayland::Client::EventQueue *m_queue = nullptr;
|
2020-09-04 14:45:47 +00:00
|
|
|
ScreencastV1 *m_screencast = nullptr;
|
2020-06-16 14:58:21 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::ScreencastV1Interface *m_screencastInterface = nullptr;
|
2020-06-16 14:58:21 +00:00
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QPointer<KWin::ScreencastStreamV1Interface> m_triggered = nullptr;
|
2020-06-16 14:58:21 +00:00
|
|
|
QThread *m_thread;
|
2023-09-13 17:59:29 +00:00
|
|
|
KWin::Display *m_display = nullptr;
|
2020-06-16 14:58:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("kwin-wayland-server-screencast-test-0");
|
|
|
|
|
2020-09-04 14:45:47 +00:00
|
|
|
void TestScreencastV1Interface::initTestCase()
|
2020-06-16 14:58:21 +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);
|
2020-06-16 14:58:21 +00:00
|
|
|
m_display->start();
|
|
|
|
QVERIFY(m_display->isRunning());
|
|
|
|
|
|
|
|
// setup connection
|
|
|
|
m_connection = new KWayland::Client::ConnectionThread;
|
|
|
|
QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
|
|
|
|
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());
|
|
|
|
|
|
|
|
KWayland::Client::Registry registry;
|
|
|
|
|
|
|
|
QSignalSpy screencastSpy(®istry, &KWayland::Client::Registry::interfacesAnnounced);
|
2023-09-13 17:59:29 +00:00
|
|
|
m_screencastInterface = new KWin::ScreencastV1Interface(m_display, this);
|
2021-08-29 05:11:06 +00:00
|
|
|
connect(m_screencastInterface,
|
2023-09-13 17:59:29 +00:00
|
|
|
&KWin::ScreencastV1Interface::windowScreencastRequested,
|
2021-08-29 05:11:06 +00:00
|
|
|
this,
|
2023-09-13 17:59:29 +00:00
|
|
|
[this](KWin::ScreencastStreamV1Interface *stream, const QString &winid) {
|
2021-08-29 05:11:06 +00:00
|
|
|
stream->sendCreated(123);
|
|
|
|
m_triggered = stream;
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(®istry,
|
|
|
|
&KWayland::Client::Registry::interfaceAnnounced,
|
|
|
|
this,
|
|
|
|
[this, ®istry](const QByteArray &interfaceName, quint32 name, quint32 version) {
|
|
|
|
if (interfaceName != "zkde_screencast_unstable_v1")
|
|
|
|
return;
|
|
|
|
m_screencast = new ScreencastV1(this);
|
|
|
|
m_screencast->init(&*registry, name, version);
|
|
|
|
});
|
2020-06-16 14:58:21 +00:00
|
|
|
registry.setEventQueue(m_queue);
|
|
|
|
registry.create(m_connection->display());
|
|
|
|
QVERIFY(registry.isValid());
|
|
|
|
registry.setup();
|
|
|
|
wl_display_flush(m_connection->display());
|
|
|
|
|
|
|
|
QVERIFY(m_screencastInterface);
|
|
|
|
QVERIFY(m_screencast || screencastSpy.wait());
|
|
|
|
QVERIFY(m_screencast);
|
|
|
|
}
|
|
|
|
|
2020-09-04 14:45:47 +00:00
|
|
|
TestScreencastV1Interface::~TestScreencastV1Interface()
|
2020-06-16 14:58:21 +00:00
|
|
|
{
|
|
|
|
delete m_queue;
|
|
|
|
m_queue = nullptr;
|
|
|
|
|
|
|
|
if (m_thread) {
|
|
|
|
m_thread->quit();
|
|
|
|
m_thread->wait();
|
|
|
|
delete m_thread;
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
|
|
|
m_connection->deleteLater();
|
|
|
|
m_connection = nullptr;
|
|
|
|
|
|
|
|
delete m_display;
|
|
|
|
}
|
|
|
|
|
2020-09-04 14:45:47 +00:00
|
|
|
void TestScreencastV1Interface::testCreate()
|
2020-06-16 14:58:21 +00:00
|
|
|
{
|
|
|
|
auto stream = m_screencast->createWindowStream("3");
|
|
|
|
QVERIFY(stream);
|
|
|
|
|
2020-09-04 14:45:47 +00:00
|
|
|
QSignalSpy spyWorking(stream, &ScreencastStreamV1::created);
|
2020-06-16 14:58:21 +00:00
|
|
|
QVERIFY(spyWorking.count() || spyWorking.wait());
|
|
|
|
QVERIFY(m_triggered);
|
|
|
|
|
2023-09-13 17:59:29 +00:00
|
|
|
QSignalSpy spyStop(m_triggered, &KWin::ScreencastStreamV1Interface::finished);
|
2020-06-16 14:58:21 +00:00
|
|
|
stream->close();
|
|
|
|
QVERIFY(spyStop.count() || spyStop.wait());
|
|
|
|
}
|
|
|
|
|
2020-09-04 14:45:47 +00:00
|
|
|
QTEST_GUILESS_MAIN(TestScreencastV1Interface)
|
2020-06-16 14:58:21 +00:00
|
|
|
|
|
|
|
#include "test_screencast.moc"
|