Directory: | ./ |
---|---|
File: | autotests/client/xdg_output.cpp |
Date: | 2024-01-22 17:25:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 116 | 117 | 99.1% |
Branches: | 161 | 326 | 49.4% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /******************************************************************** | ||
2 | Copyright 2018 David Edmundson <davidedmundson@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 | #include <QtTest> | ||
21 | |||
22 | #include "../../server/display.h" | ||
23 | #include "../../server/output.h" | ||
24 | #include "../../server/xdg_output.h" | ||
25 | |||
26 | #include "../../src/client/connection_thread.h" | ||
27 | #include "../../src/client/event_queue.h" | ||
28 | #include "../../src/client/output.h" | ||
29 | #include "../../src/client/registry.h" | ||
30 | #include "../../src/client/xdgoutput.h" | ||
31 | |||
32 | #include "../../tests/globals.h" | ||
33 | |||
34 | class TestXdgOutput : public QObject | ||
35 | { | ||
36 | Q_OBJECT | ||
37 | public: | ||
38 | explicit TestXdgOutput(QObject* parent = nullptr); | ||
39 | private Q_SLOTS: | ||
40 | void init(); | ||
41 | void cleanup(); | ||
42 | |||
43 | void testChanges_data(); | ||
44 | void testChanges(); | ||
45 | |||
46 | private: | ||
47 | 1 | struct { | |
48 | std::unique_ptr<Wrapland::Server::Display> display; | ||
49 | std::unique_ptr<Wrapland::Server::output> output; | ||
50 | Wrapland::Server::globals globals; | ||
51 | } server; | ||
52 | |||
53 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::string m_name = "HDMI-A"; |
54 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::string m_make = "Foocorp"; |
55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | std::string m_model = "Barmodel"; |
56 | std::string m_description; | ||
57 | |||
58 | Wrapland::Client::ConnectionThread* m_connection; | ||
59 | Wrapland::Client::EventQueue* m_queue; | ||
60 | QThread* m_thread; | ||
61 | }; | ||
62 | |||
63 | constexpr auto socket_name{"wrapland-test-xdg-output-0"}; | ||
64 | |||
65 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
3 | TestXdgOutput::TestXdgOutput(QObject* parent) |
66 | 1 | : QObject(parent) | |
67 | 1 | , m_connection(nullptr) | |
68 | 1 | , m_thread(nullptr) | |
69 | 1 | { | |
70 | 1 | } | |
71 | |||
72 | 3 | void TestXdgOutput::init() | |
73 | { | ||
74 | 3 | server.display = std::make_unique<Wrapland::Server::Display>(); | |
75 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | server.display->set_socket_name(socket_name); |
76 | 3 | server.display->start(); | |
77 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | QVERIFY(server.display->running()); |
78 | |||
79 | 6 | server.globals.output_manager | |
80 | 6 | = std::make_unique<Wrapland::Server::output_manager>(*server.display); | |
81 | 3 | server.globals.output_manager->create_xdg_manager(); | |
82 | |||
83 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | Wrapland::Server::output_metadata meta{.name = m_name, .make = m_make, .model = m_model}; |
84 | 6 | server.output | |
85 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | = std::make_unique<Wrapland::Server::output>(meta, *server.globals.output_manager); |
86 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | m_description = server.output->get_metadata().description; |
87 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | server.output->add_mode(Wrapland::Server::output_mode{QSize(1920, 1080), 60000, true, 1}); |
88 | |||
89 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | auto state = server.output->get_state(); |
90 | 3 | state.enabled = true; | |
91 | |||
92 | // Not a sensible position for one monitor but works for this test. And a 1.5 scale factor. | ||
93 | 3 | state.geometry = QRectF(QPoint(11, 12), QSize(1280, 720)); | |
94 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | server.output->set_state(state); |
95 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | server.output->done(); |
96 | |||
97 | // setup connection | ||
98 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | m_connection = new Wrapland::Client::ConnectionThread; |
99 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | QSignalSpy connectedSpy(m_connection, &Wrapland::Client::ConnectionThread::establishedChanged); |
100 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | m_connection->setSocketName(socket_name); |
101 | |||
102 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | m_thread = new QThread(this); |
103 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | m_connection->moveToThread(m_thread); |
104 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | m_thread->start(); |
105 | |||
106 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | m_connection->establishConnection(); |
107 |
6/12✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
|
3 | QVERIFY(connectedSpy.count() || connectedSpy.wait()); |
108 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | QCOMPARE(connectedSpy.count(), 1); |
109 | |||
110 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | m_queue = new Wrapland::Client::EventQueue(this); |
111 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | QVERIFY(!m_queue->isValid()); |
112 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | m_queue->setup(m_connection); |
113 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | QVERIFY(m_queue->isValid()); |
114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | } |
115 | |||
116 | 3 | void TestXdgOutput::cleanup() | |
117 | { | ||
118 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (m_queue) { |
119 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | delete m_queue; |
120 | 3 | m_queue = nullptr; | |
121 | 3 | } | |
122 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (m_thread) { |
123 | 3 | m_thread->quit(); | |
124 | 3 | m_thread->wait(); | |
125 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | delete m_thread; |
126 | 3 | m_thread = nullptr; | |
127 | 3 | } | |
128 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | delete m_connection; |
129 | 3 | m_connection = nullptr; | |
130 | |||
131 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | server = {}; |
132 | 3 | } | |
133 | |||
134 | 1 | void TestXdgOutput::testChanges_data() | |
135 | { | ||
136 | 1 | QTest::addColumn<int>("client_version"); | |
137 | |||
138 | 1 | QTest::newRow("v1") << 1; | |
139 | 1 | QTest::newRow("v2") << 2; | |
140 | 1 | QTest::newRow("v3") << 3; | |
141 | 1 | } | |
142 | |||
143 | 3 | void TestXdgOutput::testChanges() | |
144 | { | ||
145 | // Verify the server modes. | ||
146 | 3 | QFETCH(int, client_version); | |
147 | |||
148 | 3 | Wrapland::Client::Registry registry; | |
149 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | QSignalSpy announced(®istry, SIGNAL(outputAnnounced(quint32, quint32))); |
150 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | QSignalSpy xdgOutputAnnounced(®istry, SIGNAL(xdgOutputAnnounced(quint32, quint32))); |
151 | |||
152 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | registry.setEventQueue(m_queue); |
153 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | registry.create(m_connection->display()); |
154 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | QVERIFY(registry.isValid()); |
155 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | registry.setup(); |
156 |
5/10✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 3 times.
|
3 | QVERIFY(announced.wait()); |
157 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (xdgOutputAnnounced.count() != 1) { |
158 | ✗ | QVERIFY(xdgOutputAnnounced.wait()); | |
159 | } | ||
160 | |||
161 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | Wrapland::Client::Output output; |
162 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | QSignalSpy outputChanged(&output, SIGNAL(changed())); |
163 | |||
164 |
5/10✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
|
6 | output.setup(registry.bindOutput(announced.first().first().value<quint32>(), |
165 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | announced.first().last().value<quint32>())); |
166 |
5/10✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 3 times.
|
3 | QVERIFY(outputChanged.wait()); |
167 | |||
168 |
5/10✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
|
3 | QVERIFY(xdgOutputAnnounced.first().last().value<quint32>() |
169 | >= static_cast<quint32>(client_version)); | ||
170 | |||
171 | 3 | std::unique_ptr<Wrapland::Client::XdgOutputManager> xdgOutputManager( | |
172 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | registry.createXdgOutputManager( |
173 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | xdgOutputAnnounced.first().first().value<quint32>(), client_version, this)); |
174 | |||
175 | 3 | std::unique_ptr<Wrapland::Client::XdgOutput> xdgOutput( | |
176 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | xdgOutputManager->getXdgOutput(&output, this)); |
177 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | QSignalSpy xdgOutputChanged(xdgOutput.get(), SIGNAL(changed())); |
178 | |||
179 | // check details are sent on client bind | ||
180 |
5/10✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 3 times.
|
3 | QVERIFY(xdgOutputChanged.wait()); |
181 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | xdgOutputChanged.clear(); |
182 | |||
183 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
|
3 | QCOMPARE(xdgOutput->logicalPosition(), QPoint(11, 12)); |
184 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
|
3 | QCOMPARE(xdgOutput->logicalSize(), QSize(1280, 720)); |
185 | |||
186 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if (client_version == 1) { |
187 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | QCOMPARE(xdgOutput->name(), ""); |
188 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | QCOMPARE(xdgOutput->description(), ""); |
189 | 1 | } else { | |
190 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | QCOMPARE(xdgOutput->name(), m_name); |
191 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
|
2 | QCOMPARE(xdgOutput->description(), m_description); |
192 | } | ||
193 | |||
194 | // dynamic updates | ||
195 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | auto state = server.output->get_state(); |
196 | 3 | state.geometry = QRectF(QPoint(1000, 2000), QSize(100, 200)); | |
197 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | server.output->set_state(state); |
198 | |||
199 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | std::string updated_description = "Updated xdg-output description"; |
200 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | auto metadata = server.output->get_metadata(); |
201 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | metadata.description = updated_description; |
202 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | server.output->set_metadata(metadata); |
203 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | server.output->done(); |
204 | |||
205 |
5/10✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 3 times.
|
3 | QVERIFY(xdgOutputChanged.wait()); |
206 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
|
3 | QCOMPARE(xdgOutputChanged.count(), 1); |
207 | |||
208 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
|
3 | QCOMPARE(xdgOutput->logicalPosition(), QPoint(1000, 2000)); |
209 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
|
3 | QCOMPARE(xdgOutput->logicalSize(), QSize(100, 200)); |
210 | |||
211 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if (client_version == 1) { |
212 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | QCOMPARE(xdgOutput->description(), ""); |
213 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
3 | } else if (client_version == 2) { |
214 | // Description is immutable in version 2. | ||
215 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | QCOMPARE(xdgOutput->description(), m_description); |
216 | 1 | } else { | |
217 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | QCOMPARE(xdgOutput->description(), updated_description); |
218 | } | ||
219 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | } |
220 | |||
221 |
4/8✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
1 | QTEST_GUILESS_MAIN(TestXdgOutput) |
222 | #include "xdg_output.moc" | ||
223 |