Changeset View
Changeset View
Standalone View
Standalone View
autotests/server/test_screencasting.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2020 Aleix Pol Gonzalez <aleixpol@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | // Qt | ||||
21 | #include <QHash> | ||||
22 | #include <QThread> | ||||
23 | #include <QtTest> | ||||
24 | | ||||
25 | #include <wayland-client.h> | ||||
26 | | ||||
27 | // WaylandServer | ||||
28 | #include "../../src/server/compositor_interface.h" | ||||
29 | #include "../../src/server/display.h" | ||||
30 | #include "../../src/server/seat_interface.h" | ||||
31 | #include "../../src/server/screencasting_interface.h" | ||||
32 | | ||||
33 | #include "../../src/client/connection_thread.h" | ||||
34 | #include "../../src/client/event_queue.h" | ||||
35 | #include "../../src/client/registry.h" | ||||
36 | #include "../../src/client/seat.h" | ||||
37 | #include "../../src/client/screencasting.h" | ||||
38 | #include "../../src/client/compositor.h" | ||||
39 | #include "../../src/client/screencasting.h" | ||||
40 | | ||||
41 | class TestScreencastingInterface : public QObject | ||||
42 | { | ||||
43 | Q_OBJECT | ||||
44 | public: | ||||
45 | TestScreencastingInterface() | ||||
46 | {} | ||||
47 | | ||||
48 | ~TestScreencastingInterface() override; | ||||
49 | | ||||
50 | private Q_SLOTS: | ||||
51 | void initTestCase(); | ||||
52 | void testAdd(); | ||||
53 | | ||||
54 | private: | ||||
55 | KWayland::Client::ConnectionThread *m_connection; | ||||
56 | KWayland::Client::EventQueue *m_queue = nullptr; | ||||
57 | KWayland::Client::Compositor *m_compositor; | ||||
58 | KWayland::Client::Screencasting *m_screencasting = nullptr; | ||||
59 | | ||||
60 | KWayland::Server::ScreencastingInterface *m_screencastingInterface = nullptr; | ||||
61 | | ||||
62 | QThread *m_thread; | ||||
63 | KWayland::Server::Display *m_display; | ||||
64 | KWayland::Server::CompositorInterface *m_compositorInterface; | ||||
65 | }; | ||||
66 | | ||||
67 | static const QString s_socketName = QStringLiteral("kwin-wayland-server-tablet-test-0"); | ||||
68 | | ||||
69 | void TestScreencastingInterface::initTestCase() | ||||
70 | { | ||||
71 | delete m_display; | ||||
72 | m_display = new KWayland::Server::Display(this); | ||||
73 | m_display->setSocketName(s_socketName); | ||||
74 | m_display->start(); | ||||
75 | QVERIFY(m_display->isRunning()); | ||||
76 | | ||||
77 | // setup connection | ||||
78 | m_connection = new KWayland::Client::ConnectionThread; | ||||
79 | QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected); | ||||
80 | QVERIFY(connectedSpy.isValid()); | ||||
81 | m_connection->setSocketName(s_socketName); | ||||
82 | | ||||
83 | m_thread = new QThread(this); | ||||
84 | m_connection->moveToThread(m_thread); | ||||
85 | m_thread->start(); | ||||
86 | | ||||
87 | m_connection->initConnection(); | ||||
88 | QVERIFY(connectedSpy.wait()); | ||||
89 | | ||||
90 | m_queue = new KWayland::Client::EventQueue(this); | ||||
91 | QVERIFY(!m_queue->isValid()); | ||||
92 | m_queue->setup(m_connection); | ||||
93 | QVERIFY(m_queue->isValid()); | ||||
94 | | ||||
95 | KWayland::Client::Registry registry; | ||||
96 | QSignalSpy compositorSpy(®istry, &KWayland::Client::Registry::compositorAnnounced); | ||||
97 | QVERIFY(compositorSpy.isValid()); | ||||
98 | | ||||
99 | QSignalSpy screencastingSpy(®istry, &KWayland::Client::Registry::screencastingAnnounced); | ||||
100 | QVERIFY(screencastingSpy.isValid()); | ||||
101 | m_screencastingInterface = m_display->createScreencastingInterface(this); | ||||
102 | | ||||
103 | connect(®istry, &KWayland::Client::Registry::screencastingAnnounced, this, [this, ®istry] (quint32 name, quint32 version) { | ||||
104 | Q_ASSERT(version == 1); | ||||
105 | m_screencasting = registry.createScreencasting(name, version, this); | ||||
106 | }); | ||||
107 | QVERIFY(!registry.eventQueue()); | ||||
108 | registry.setEventQueue(m_queue); | ||||
109 | QCOMPARE(registry.eventQueue(), m_queue); | ||||
110 | registry.create(m_connection->display()); | ||||
111 | QVERIFY(registry.isValid()); | ||||
112 | registry.setup(); | ||||
113 | | ||||
114 | m_compositorInterface = m_display->createCompositor(m_display); | ||||
115 | m_compositorInterface->create(); | ||||
116 | QVERIFY(m_compositorInterface->isValid()); | ||||
117 | | ||||
118 | QVERIFY(compositorSpy.wait()); | ||||
119 | m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this); | ||||
120 | | ||||
121 | QVERIFY(m_screencastingInterface); | ||||
122 | QVERIFY(screencastingSpy.wait(50000)); | ||||
123 | QVERIFY(m_screencasting); | ||||
124 | } | ||||
125 | | ||||
126 | TestScreencastingInterface::~TestScreencastingInterface() | ||||
127 | { | ||||
128 | if (m_queue) { | ||||
129 | delete m_queue; | ||||
130 | m_queue = nullptr; | ||||
131 | } | ||||
132 | if (m_thread) { | ||||
133 | m_thread->quit(); | ||||
134 | m_thread->wait(); | ||||
135 | delete m_thread; | ||||
136 | m_thread = nullptr; | ||||
137 | } | ||||
138 | m_connection->deleteLater(); | ||||
139 | m_connection = nullptr; | ||||
140 | | ||||
141 | delete m_display; | ||||
142 | } | ||||
143 | | ||||
144 | void TestScreencastingInterface::testAdd() | ||||
145 | { | ||||
146 | QCOMPARE(m_screencasting->sources().count(), 0); | ||||
147 | bool triggered = false; | ||||
148 | auto f = [&] (const KWayland::Server::ScreencastingSource &, wl_resource *){ | ||||
149 | triggered = true; | ||||
150 | }; | ||||
151 | auto serverSource = KWayland::Server::ScreencastingSource(1, "potatoes", "video-display", true, {0,0,200,200}, f); | ||||
152 | m_screencastingInterface->addSource(serverSource); | ||||
153 | QCOMPARE(m_screencasting->sources().count(), 1); | ||||
154 | } | ||||
155 | | ||||
156 | QTEST_GUILESS_MAIN(TestScreencastingInterface) | ||||
157 | #include "test_screencasting.moc" |