Changeset View
Changeset View
Standalone View
Standalone View
autotests/client/test_xdg_output.cpp
- This file was added.
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 | // Qt | ||||
21 | #include <QtTest/QtTest> | ||||
22 | // KWin | ||||
23 | #include "../../src/client/connection_thread.h" | ||||
24 | #include "../../src/client/event_queue.h" | ||||
25 | #include "../../src/client/dpms.h" | ||||
26 | #include "../../src/client/output.h" | ||||
27 | #include "../../src/client/xdgoutput.h" | ||||
28 | #include "../../src/client/registry.h" | ||||
29 | #include "../../src/server/display.h" | ||||
30 | #include "../../src/server/dpms_interface.h" | ||||
31 | #include "../../src/server/output_interface.h" | ||||
32 | #include "../../src/server/xdgoutput_interface.h" | ||||
33 | | ||||
34 | // Wayland | ||||
35 | | ||||
36 | class TestXdgOutput : public QObject | ||||
37 | { | ||||
38 | Q_OBJECT | ||||
39 | public: | ||||
40 | explicit TestXdgOutput(QObject *parent = nullptr); | ||||
41 | private Q_SLOTS: | ||||
42 | void init(); | ||||
43 | void cleanup(); | ||||
44 | void testChanges(); | ||||
45 | private: | ||||
46 | KWayland::Server::Display *m_display; | ||||
47 | KWayland::Server::OutputInterface *m_serverOutput; | ||||
48 | KWayland::Server::XdgOutputManagerInterface *m_serverXdgOutputManager; | ||||
49 | KWayland::Server::XdgOutputInterface *m_serverXdgOutput; | ||||
50 | KWayland::Client::ConnectionThread *m_connection; | ||||
51 | KWayland::Client::EventQueue *m_queue; | ||||
52 | QThread *m_thread; | ||||
53 | }; | ||||
54 | | ||||
55 | static const QString s_socketName = QStringLiteral("kwin-test-xdg-output-0"); | ||||
56 | | ||||
57 | TestXdgOutput::TestXdgOutput(QObject *parent) | ||||
58 | : QObject(parent) | ||||
59 | , m_display(nullptr) | ||||
60 | , m_serverOutput(nullptr) | ||||
61 | , m_connection(nullptr) | ||||
62 | , m_thread(nullptr) | ||||
63 | { | ||||
64 | } | ||||
65 | | ||||
66 | void TestXdgOutput::init() | ||||
67 | { | ||||
68 | using namespace KWayland::Server; | ||||
69 | delete m_display; | ||||
70 | m_display = new Display(this); | ||||
71 | m_display->setSocketName(s_socketName); | ||||
72 | m_display->start(); | ||||
73 | QVERIFY(m_display->isRunning()); | ||||
74 | | ||||
75 | m_serverOutput = m_display->createOutput(this); | ||||
76 | m_serverOutput->addMode(QSize(1920, 1080), OutputInterface::ModeFlags(OutputInterface::ModeFlag::Preferred)); | ||||
77 | m_serverOutput->setCurrentMode(QSize(1920, 1080)); | ||||
78 | m_serverOutput->create(); | ||||
79 | | ||||
80 | m_serverXdgOutputManager = m_display->createXdgOutputManager(this); | ||||
81 | m_serverXdgOutputManager->create(); | ||||
82 | m_serverXdgOutput = m_serverXdgOutputManager->createXdgOutput(m_serverOutput, this); | ||||
83 | m_serverXdgOutput->setLogicalSize(QSize(1280, 720)); //a 1.5 scale factor | ||||
84 | m_serverXdgOutput->setLogicalPosition(QPoint(11,12)); //not a sensible value for one monitor, but works for this test | ||||
85 | m_serverXdgOutput->done(); | ||||
86 | | ||||
87 | // setup connection | ||||
88 | m_connection = new KWayland::Client::ConnectionThread; | ||||
89 | QSignalSpy connectedSpy(m_connection, SIGNAL(connected())); | ||||
90 | m_connection->setSocketName(s_socketName); | ||||
91 | | ||||
92 | m_thread = new QThread(this); | ||||
93 | m_connection->moveToThread(m_thread); | ||||
94 | m_thread->start(); | ||||
95 | | ||||
96 | m_connection->initConnection(); | ||||
97 | QVERIFY(connectedSpy.wait()); | ||||
98 | | ||||
99 | m_queue = new KWayland::Client::EventQueue(this); | ||||
100 | QVERIFY(!m_queue->isValid()); | ||||
101 | m_queue->setup(m_connection); | ||||
102 | QVERIFY(m_queue->isValid()); | ||||
103 | } | ||||
104 | | ||||
105 | void TestXdgOutput::cleanup() | ||||
106 | { | ||||
107 | if (m_queue) { | ||||
108 | delete m_queue; | ||||
109 | m_queue = nullptr; | ||||
110 | } | ||||
111 | if (m_thread) { | ||||
112 | m_thread->quit(); | ||||
113 | m_thread->wait(); | ||||
114 | delete m_thread; | ||||
115 | m_thread = nullptr; | ||||
116 | } | ||||
117 | delete m_connection; | ||||
118 | m_connection = nullptr; | ||||
119 | | ||||
120 | delete m_serverOutput; | ||||
121 | m_serverOutput = nullptr; | ||||
122 | | ||||
123 | delete m_display; | ||||
124 | m_display = nullptr; | ||||
125 | } | ||||
126 | | ||||
127 | void TestXdgOutput::testChanges() | ||||
128 | { | ||||
129 | // verify the server modes | ||||
130 | using namespace KWayland::Server; | ||||
131 | using namespace KWayland::Client; | ||||
132 | KWayland::Client::Registry registry; | ||||
133 | QSignalSpy announced(®istry, SIGNAL(outputAnnounced(quint32,quint32))); | ||||
134 | QSignalSpy xdgOutputAnnounced(®istry, SIGNAL(xdgOutputAnnounced(quint32,quint32))); | ||||
135 | | ||||
136 | registry.setEventQueue(m_queue); | ||||
137 | registry.create(m_connection->display()); | ||||
138 | QVERIFY(registry.isValid()); | ||||
139 | registry.setup(); | ||||
140 | QVERIFY(announced.wait()); | ||||
141 | if (xdgOutputAnnounced.count() != 1) { | ||||
142 | QVERIFY(xdgOutputAnnounced.wait()); | ||||
143 | } | ||||
144 | | ||||
145 | KWayland::Client::Output output; | ||||
146 | QSignalSpy outputChanged(&output, SIGNAL(changed())); | ||||
147 | | ||||
148 | output.setup(registry.bindOutput(announced.first().first().value<quint32>(), announced.first().last().value<quint32>())); | ||||
149 | QVERIFY(outputChanged.wait()); | ||||
150 | | ||||
151 | QScopedPointer<KWayland::Client::XdgOutputManager> xdgOutputManager(registry.createXdgOutputManager(xdgOutputAnnounced.first().first().value<quint32>(), xdgOutputAnnounced.first().last().value<quint32>(), this)); | ||||
152 | | ||||
153 | QScopedPointer<KWayland::Client::XdgOutput> xdgOutput(xdgOutputManager->getXdgOutput(&output, this)); | ||||
154 | QSignalSpy xdgOutputChanged(xdgOutput.data(), SIGNAL(changed())); | ||||
155 | | ||||
156 | //check details are sent on client bind | ||||
157 | QVERIFY(xdgOutputChanged.wait()); | ||||
158 | xdgOutputChanged.clear(); | ||||
159 | QCOMPARE(xdgOutput->logicalPosition(), QPoint(11,12)); | ||||
160 | QCOMPARE(xdgOutput->logicalSize(), QSize(1280,720)); | ||||
161 | | ||||
162 | //dynamic updates | ||||
163 | m_serverXdgOutput->setLogicalPosition(QPoint(1000, 2000)); | ||||
164 | m_serverXdgOutput->setLogicalSize(QSize(100,200)); | ||||
165 | m_serverXdgOutput->done(); | ||||
166 | | ||||
167 | QVERIFY(xdgOutputChanged.wait()); | ||||
168 | QCOMPARE(xdgOutputChanged.count(), 1); | ||||
169 | QCOMPARE(xdgOutput->logicalPosition(), QPoint(1000, 2000)); | ||||
170 | QCOMPARE(xdgOutput->logicalSize(), QSize(100,200)); | ||||
171 | } | ||||
172 | | ||||
173 | QTEST_GUILESS_MAIN(TestXdgOutput) | ||||
174 | #include "test_xdg_output.moc" |