KWin
Loading...
Searching...
No Matches
test_screencast.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7// Qt
8#include <QHash>
9#include <QSignalSpy>
10#include <QTest>
11#include <QThread>
12
13#include <wayland-client.h>
14
15// WaylandServer
16#include "wayland/compositor.h"
17#include "wayland/display.h"
19#include "wayland/seat.h"
20
21#include <KWayland/Client/compositor.h>
22#include <KWayland/Client/connection_thread.h>
23#include <KWayland/Client/event_queue.h>
24#include <KWayland/Client/registry.h>
25#include <KWayland/Client/seat.h>
26
27#include "qwayland-zkde-screencast-unstable-v1.h"
28
29class ScreencastStreamV1 : public QObject, public QtWayland::zkde_screencast_stream_unstable_v1
30{
31 Q_OBJECT
32
33public:
34 ScreencastStreamV1(::zkde_screencast_stream_unstable_v1 *obj, QObject *parent)
35 : QObject(parent)
36 , zkde_screencast_stream_unstable_v1(obj)
37 {
38 }
39
40 void zkde_screencast_stream_unstable_v1_created(uint32_t node) override
41 {
42 Q_EMIT created(node);
43 }
44
45Q_SIGNALS:
46 void created(quint32 node);
47};
48
49class ScreencastV1 : public QObject, public QtWayland::zkde_screencast_unstable_v1
50{
51 Q_OBJECT
52
53public:
54 ScreencastV1(QObject *parent)
55 : QObject(parent)
56 {
57 }
58
60 {
61 return new ScreencastStreamV1(stream_window(uuid, 2), this);
62 }
63};
64
65class TestScreencastV1Interface : public QObject
66{
67 Q_OBJECT
68
69public:
73
75
76private Q_SLOTS:
77 void initTestCase();
78 void testCreate();
79
80private:
81 KWayland::Client::ConnectionThread *m_connection;
82 KWayland::Client::EventQueue *m_queue = nullptr;
83 ScreencastV1 *m_screencast = nullptr;
84
85 KWin::ScreencastV1Interface *m_screencastInterface = nullptr;
86
87 QPointer<KWin::ScreencastStreamV1Interface> m_triggered = nullptr;
88 QThread *m_thread;
89 KWin::Display *m_display = nullptr;
90};
91
92static const QString s_socketName = QStringLiteral("kwin-wayland-server-screencast-test-0");
93
94void TestScreencastV1Interface::initTestCase()
95{
96 delete m_display;
97 m_display = new KWin::Display(this);
98 m_display->addSocketName(s_socketName);
99 m_display->start();
100 QVERIFY(m_display->isRunning());
101
102 // setup connection
103 m_connection = new KWayland::Client::ConnectionThread;
104 QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected);
105 m_connection->setSocketName(s_socketName);
106
107 m_thread = new QThread(this);
108 m_connection->moveToThread(m_thread);
109 m_thread->start();
110
111 m_connection->initConnection();
112 QVERIFY(connectedSpy.wait());
113
114 m_queue = new KWayland::Client::EventQueue(this);
115 QVERIFY(!m_queue->isValid());
116 m_queue->setup(m_connection);
117 QVERIFY(m_queue->isValid());
118
119 KWayland::Client::Registry registry;
120
121 QSignalSpy screencastSpy(&registry, &KWayland::Client::Registry::interfacesAnnounced);
122 m_screencastInterface = new KWin::ScreencastV1Interface(m_display, this);
123 connect(m_screencastInterface,
125 this,
126 [this](KWin::ScreencastStreamV1Interface *stream, const QString &winid) {
127 stream->sendCreated(123);
128 m_triggered = stream;
129 });
130
131 connect(&registry,
132 &KWayland::Client::Registry::interfaceAnnounced,
133 this,
134 [this, &registry](const QByteArray &interfaceName, quint32 name, quint32 version) {
135 if (interfaceName != "zkde_screencast_unstable_v1")
136 return;
137 m_screencast = new ScreencastV1(this);
138 m_screencast->init(&*registry, name, version);
139 });
140 registry.setEventQueue(m_queue);
141 registry.create(m_connection->display());
142 QVERIFY(registry.isValid());
143 registry.setup();
144 wl_display_flush(m_connection->display());
145
146 QVERIFY(m_screencastInterface);
147 QVERIFY(m_screencast || screencastSpy.wait());
148 QVERIFY(m_screencast);
149}
150
152{
153 delete m_queue;
154 m_queue = nullptr;
155
156 if (m_thread) {
157 m_thread->quit();
158 m_thread->wait();
159 delete m_thread;
160 m_thread = nullptr;
161 }
162 m_connection->deleteLater();
163 m_connection = nullptr;
164
165 delete m_display;
166}
167
168void TestScreencastV1Interface::testCreate()
169{
170 auto stream = m_screencast->createWindowStream("3");
171 QVERIFY(stream);
172
173 QSignalSpy spyWorking(stream, &ScreencastStreamV1::created);
174 QVERIFY(spyWorking.count() || spyWorking.wait());
175 QVERIFY(m_triggered);
176
177 QSignalSpy spyStop(m_triggered, &KWin::ScreencastStreamV1Interface::finished);
178 stream->close();
179 QVERIFY(spyStop.count() || spyStop.wait());
180}
181
182QTEST_GUILESS_MAIN(TestScreencastV1Interface)
183
184#include "test_screencast.moc"
Class holding the Wayland server display loop.
Definition display.h:34
bool addSocketName(const QString &name=QString())
Definition display.cpp:68
bool isRunning() const
Definition display.cpp:144
bool start()
Definition display.cpp:92
void windowScreencastRequested(ScreencastStreamV1Interface *stream, const QString &winid, CursorMode mode)
void created(quint32 node)
void zkde_screencast_stream_unstable_v1_created(uint32_t node) override
ScreencastStreamV1(::zkde_screencast_stream_unstable_v1 *obj, QObject *parent)
ScreencastStreamV1 * createWindowStream(const QString &uuid)
ScreencastV1(QObject *parent)
KWayland::Client::Registry * registry
constexpr int version