Changeset View
Changeset View
Standalone View
Standalone View
autotests/client/test_wayland_appmenu.cpp
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2017 David Edmundson <davidedmundson@kde.org> | ||||
3 | Copyright 2014 Martin Gräßlin <mgraesslin@kde.org> | ||||
4 | | ||||
5 | This library is free software; you can redistribute it and/or | ||||
6 | modify it under the terms of the GNU Lesser General Public | ||||
7 | License as published by the Free Software Foundation; either | ||||
8 | version 2.1 of the License, or (at your option) version 3, or any | ||||
9 | later version accepted by the membership of KDE e.V. (or its | ||||
10 | successor approved by the membership of KDE e.V.), which shall | ||||
11 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
12 | | ||||
13 | This library is distributed in the hope that it will be useful, | ||||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
16 | Lesser General Public License for more details. | ||||
17 | | ||||
18 | You should have received a copy of the GNU Lesser General Public | ||||
19 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
20 | *********************************************************************/ | ||||
21 | // Qt | ||||
22 | #include <QtTest/QtTest> | ||||
23 | // KWin | ||||
24 | #include "../../src/client/compositor.h" | ||||
25 | #include "../../src/client/connection_thread.h" | ||||
26 | #include "../../src/client/event_queue.h" | ||||
27 | #include "../../src/client/region.h" | ||||
28 | #include "../../src/client/registry.h" | ||||
29 | #include "../../src/client/surface.h" | ||||
30 | #include "../../src/client/appmenu.h" | ||||
31 | #include "../../src/server/display.h" | ||||
32 | #include "../../src/server/compositor_interface.h" | ||||
33 | #include "../../src/server/region_interface.h" | ||||
34 | #include "../../src/server/appmenu_interface.h" | ||||
35 | | ||||
36 | using namespace KWayland::Client; | ||||
37 | | ||||
38 | Q_DECLARE_METATYPE(KWayland::Server::AppMenuInterface::InterfaceAddress); | ||||
39 | | ||||
40 | class TestAppmenu : public QObject | ||||
41 | { | ||||
42 | Q_OBJECT | ||||
43 | public: | ||||
44 | explicit TestAppmenu(QObject *parent = nullptr); | ||||
45 | private Q_SLOTS: | ||||
46 | void init(); | ||||
47 | void cleanup(); | ||||
48 | | ||||
49 | void testCreateAndSet(); | ||||
50 | | ||||
51 | private: | ||||
52 | KWayland::Server::Display *m_display; | ||||
53 | KWayland::Server::CompositorInterface *m_compositorInterface; | ||||
54 | KWayland::Server::AppMenuManagerInterface *m_appmenuManagerInterface; | ||||
55 | KWayland::Client::ConnectionThread *m_connection; | ||||
56 | KWayland::Client::Compositor *m_compositor; | ||||
57 | KWayland::Client::AppMenuManager *m_appmenuManager; | ||||
58 | KWayland::Client::EventQueue *m_queue; | ||||
59 | QThread *m_thread; | ||||
60 | }; | ||||
61 | | ||||
62 | static const QString s_socketName = QStringLiteral("kwayland-test-wayland-appmenu-0"); | ||||
63 | | ||||
64 | TestAppmenu::TestAppmenu(QObject *parent) | ||||
65 | : QObject(parent) | ||||
66 | , m_display(nullptr) | ||||
67 | , m_compositorInterface(nullptr) | ||||
68 | , m_connection(nullptr) | ||||
69 | , m_compositor(nullptr) | ||||
70 | , m_queue(nullptr) | ||||
71 | , m_thread(nullptr) | ||||
72 | { | ||||
73 | } | ||||
74 | | ||||
75 | void TestAppmenu::init() | ||||
76 | { | ||||
77 | using namespace KWayland::Server; | ||||
78 | qRegisterMetaType<AppMenuInterface::InterfaceAddress>(); | ||||
79 | delete m_display; | ||||
80 | m_display = new Display(this); | ||||
81 | m_display->setSocketName(s_socketName); | ||||
82 | m_display->start(); | ||||
83 | QVERIFY(m_display->isRunning()); | ||||
84 | | ||||
85 | // setup connection | ||||
86 | m_connection = new KWayland::Client::ConnectionThread; | ||||
87 | QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); | ||||
88 | QVERIFY(connectedSpy.isValid()); | ||||
89 | m_connection->setSocketName(s_socketName); | ||||
90 | | ||||
91 | m_thread = new QThread(this); | ||||
92 | m_connection->moveToThread(m_thread); | ||||
93 | m_thread->start(); | ||||
94 | | ||||
95 | m_connection->initConnection(); | ||||
96 | QVERIFY(connectedSpy.wait()); | ||||
97 | | ||||
98 | m_queue = new KWayland::Client::EventQueue(this); | ||||
99 | QVERIFY(!m_queue->isValid()); | ||||
100 | m_queue->setup(m_connection); | ||||
101 | QVERIFY(m_queue->isValid()); | ||||
102 | | ||||
103 | Registry registry; | ||||
104 | QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); | ||||
105 | QVERIFY(compositorSpy.isValid()); | ||||
106 | | ||||
107 | QSignalSpy appmenuSpy(®istry, &Registry::appMenuAnnounced); | ||||
108 | QVERIFY(appmenuSpy.isValid()); | ||||
109 | | ||||
110 | QVERIFY(!registry.eventQueue()); | ||||
111 | registry.setEventQueue(m_queue); | ||||
112 | QCOMPARE(registry.eventQueue(), m_queue); | ||||
113 | registry.create(m_connection->display()); | ||||
114 | QVERIFY(registry.isValid()); | ||||
115 | registry.setup(); | ||||
116 | | ||||
117 | m_compositorInterface = m_display->createCompositor(m_display); | ||||
118 | m_compositorInterface->create(); | ||||
119 | QVERIFY(m_compositorInterface->isValid()); | ||||
120 | | ||||
121 | QVERIFY(compositorSpy.wait()); | ||||
122 | m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this); | ||||
123 | | ||||
124 | m_appmenuManagerInterface = m_display->createAppMenuManagerInterface(m_display); | ||||
125 | m_appmenuManagerInterface->create(); | ||||
126 | QVERIFY(m_appmenuManagerInterface->isValid()); | ||||
127 | | ||||
128 | QVERIFY(appmenuSpy.wait()); | ||||
129 | m_appmenuManager = registry.createAppMenuManager(appmenuSpy.first().first().value<quint32>(), appmenuSpy.first().last().value<quint32>(), this); | ||||
130 | } | ||||
131 | | ||||
132 | void TestAppmenu::cleanup() | ||||
133 | { | ||||
134 | #define CLEANUP(variable) \ | ||||
135 | if (variable) { \ | ||||
136 | delete variable; \ | ||||
137 | variable = nullptr; \ | ||||
138 | } | ||||
139 | CLEANUP(m_compositor) | ||||
140 | CLEANUP(m_appmenuManager) | ||||
141 | CLEANUP(m_queue) | ||||
142 | if (m_connection) { | ||||
143 | m_connection->deleteLater(); | ||||
144 | m_connection = nullptr; | ||||
145 | } | ||||
146 | if (m_thread) { | ||||
147 | m_thread->quit(); | ||||
148 | m_thread->wait(); | ||||
149 | delete m_thread; | ||||
150 | m_thread = nullptr; | ||||
151 | } | ||||
152 | CLEANUP(m_compositorInterface) | ||||
153 | CLEANUP(m_appmenuManagerInterface) | ||||
154 | CLEANUP(m_display) | ||||
155 | #undef CLEANUP | ||||
156 | } | ||||
157 | | ||||
158 | void TestAppmenu::testCreateAndSet() | ||||
159 | { | ||||
160 | QSignalSpy serverSurfaceCreated(m_compositorInterface, SIGNAL(surfaceCreated(KWayland::Server::SurfaceInterface*))); | ||||
161 | QVERIFY(serverSurfaceCreated.isValid()); | ||||
162 | | ||||
163 | QScopedPointer<KWayland::Client::Surface> surface(m_compositor->createSurface()); | ||||
164 | QVERIFY(serverSurfaceCreated.wait()); | ||||
165 | | ||||
166 | auto serverSurface = serverSurfaceCreated.first().first().value<KWayland::Server::SurfaceInterface*>(); | ||||
167 | QSignalSpy appMenuCreated(m_appmenuManagerInterface, &KWayland::Server::AppMenuManagerInterface::appMenuCreated); | ||||
168 | | ||||
169 | QCOMPARE(m_appmenuManagerInterface->appMenuForSurface(serverSurface), nullptr); | ||||
170 | | ||||
171 | auto appmenu = m_appmenuManager->create(surface.data(), surface.data()); | ||||
172 | QVERIFY(appMenuCreated.wait()); | ||||
173 | auto appMenuInterface = appMenuCreated.first().first().value<KWayland::Server::AppMenuInterface*>(); | ||||
174 | QCOMPARE(m_appmenuManagerInterface->appMenuForSurface(serverSurface), appMenuInterface); | ||||
175 | | ||||
176 | QCOMPARE(appMenuInterface->address().serviceName, QString()); | ||||
177 | QCOMPARE(appMenuInterface->address().objectPath, QString()); | ||||
178 | | ||||
179 | QSignalSpy appMenuChangedSpy(appMenuInterface, &KWayland::Server::AppMenuInterface::addressChanged); | ||||
180 | | ||||
181 | appmenu->setAddress("net.somename", "/test/path"); | ||||
182 | | ||||
183 | QVERIFY(appMenuChangedSpy.wait()); | ||||
184 | QCOMPARE(appMenuInterface->address().serviceName, "net.somename"); | ||||
185 | QCOMPARE(appMenuInterface->address().objectPath, "/test/path"); | ||||
186 | | ||||
187 | // and destroy | ||||
188 | QSignalSpy destroyedSpy(appMenuInterface, &QObject::destroyed); | ||||
189 | QVERIFY(destroyedSpy.isValid()); | ||||
190 | delete appmenu; | ||||
191 | QVERIFY(destroyedSpy.wait()); | ||||
192 | QCOMPARE(m_appmenuManagerInterface->appMenuForSurface(serverSurface), nullptr); | ||||
193 | } | ||||
194 | | ||||
195 | QTEST_GUILESS_MAIN(TestAppmenu) | ||||
196 | #include "test_wayland_appmenu.moc" |