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::Screencasting *m_screencasting = nullptr; | ||||
58 | | ||||
59 | KWayland::Server::ScreencastingInterface *m_screencastingInterface = nullptr; | ||||
60 | | ||||
61 | QThread *m_thread; | ||||
62 | KWayland::Server::Display *m_display = nullptr; | ||||
63 | }; | ||||
64 | | ||||
65 | static const QString s_socketName = QStringLiteral("kwin-wayland-server-screencasting-test-0"); | ||||
66 | | ||||
67 | void TestScreencastingInterface::initTestCase() | ||||
68 | { | ||||
69 | delete m_display; | ||||
70 | m_display = new KWayland::Server::Display(this); | ||||
71 | m_display->setSocketName(s_socketName); | ||||
72 | m_display->start(); | ||||
73 | QVERIFY(m_display->isRunning()); | ||||
74 | | ||||
75 | // setup connection | ||||
76 | m_connection = new KWayland::Client::ConnectionThread; | ||||
77 | QSignalSpy connectedSpy(m_connection, &KWayland::Client::ConnectionThread::connected); | ||||
78 | QVERIFY(connectedSpy.isValid()); | ||||
79 | m_connection->setSocketName(s_socketName); | ||||
80 | | ||||
81 | m_thread = new QThread(this); | ||||
82 | m_connection->moveToThread(m_thread); | ||||
83 | m_thread->start(); | ||||
84 | | ||||
85 | m_connection->initConnection(); | ||||
86 | QVERIFY(connectedSpy.wait()); | ||||
87 | | ||||
88 | m_queue = new KWayland::Client::EventQueue(this); | ||||
89 | QVERIFY(!m_queue->isValid()); | ||||
90 | m_queue->setup(m_connection); | ||||
91 | QVERIFY(m_queue->isValid()); | ||||
92 | | ||||
93 | KWayland::Client::Registry registry; | ||||
94 | | ||||
95 | QSignalSpy screencastingSpy(®istry, &KWayland::Client::Registry::screencastingAnnounced); | ||||
96 | QVERIFY(screencastingSpy.isValid()); | ||||
97 | m_screencastingInterface = m_display->createScreencastingInterface(this); | ||||
98 | | ||||
99 | connect(®istry, &KWayland::Client::Registry::screencastingAnnounced, this, [this, ®istry] (quint32 name, quint32 version) { | ||||
100 | Q_ASSERT(version == 1); | ||||
101 | m_screencasting = new KWayland::Client::Screencasting(®istry, name, version, this); | ||||
102 | }); | ||||
103 | registry.setEventQueue(m_queue); | ||||
104 | registry.create(m_connection->display()); | ||||
105 | QVERIFY(registry.isValid()); | ||||
106 | registry.setup(); | ||||
107 | wl_display_flush(m_connection->display()); | ||||
108 | | ||||
109 | QVERIFY(m_screencastingInterface); | ||||
110 | QVERIFY(m_screencasting || screencastingSpy.wait(50000)); | ||||
111 | QVERIFY(m_screencasting); | ||||
112 | } | ||||
113 | | ||||
114 | TestScreencastingInterface::~TestScreencastingInterface() | ||||
115 | { | ||||
116 | delete m_queue; | ||||
117 | m_queue = nullptr; | ||||
118 | | ||||
119 | if (m_thread) { | ||||
120 | m_thread->quit(); | ||||
121 | m_thread->wait(); | ||||
122 | delete m_thread; | ||||
123 | m_thread = nullptr; | ||||
124 | } | ||||
125 | m_connection->deleteLater(); | ||||
126 | m_connection = nullptr; | ||||
127 | | ||||
128 | delete m_display; | ||||
129 | } | ||||
130 | | ||||
131 | void TestScreencastingInterface::testAdd() | ||||
132 | { | ||||
133 | QSignalSpy spySourcesChanged(m_screencasting, &KWayland::Client::Screencasting::sourcesChanged); | ||||
134 | | ||||
135 | QCOMPARE(m_screencasting->sources().count(), 0); | ||||
136 | bool triggered = false; | ||||
137 | auto f = [&] (const KWayland::Server::ScreencastingSource &, wl_resource *) { | ||||
138 | triggered = true; | ||||
139 | }; | ||||
140 | auto serverSource = KWayland::Server::ScreencastingSource(1, "potatoes", "video-display", true, {0,0,200,200}, f); | ||||
141 | m_screencastingInterface->addSource(serverSource); | ||||
142 | QVERIFY(spySourcesChanged.count() || spySourcesChanged.wait()); | ||||
143 | QCOMPARE(m_screencasting->sources().count(), 1); | ||||
144 | } | ||||
145 | | ||||
146 | QTEST_GUILESS_MAIN(TestScreencastingInterface) | ||||
147 | #include "test_screencasting.moc" |