Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/shell_client_test.cpp
Show All 21 Lines | |||||
22 | #include "platform.h" | 22 | #include "platform.h" | ||
23 | #include "shell_client.h" | 23 | #include "shell_client.h" | ||
24 | #include "screens.h" | 24 | #include "screens.h" | ||
25 | #include "wayland_server.h" | 25 | #include "wayland_server.h" | ||
26 | #include "workspace.h" | 26 | #include "workspace.h" | ||
27 | 27 | | |||
28 | #include <KWayland/Client/connection_thread.h> | 28 | #include <KWayland/Client/connection_thread.h> | ||
29 | #include <KWayland/Client/compositor.h> | 29 | #include <KWayland/Client/compositor.h> | ||
30 | #include <KWayland/Client/event_queue.h> | | |||
31 | #include <KWayland/Client/registry.h> | | |||
32 | #include <KWayland/Client/shell.h> | 30 | #include <KWayland/Client/shell.h> | ||
33 | #include <KWayland/Client/shm_pool.h> | | |||
34 | #include <KWayland/Client/surface.h> | 31 | #include <KWayland/Client/surface.h> | ||
35 | 32 | | |||
36 | #include <KWayland/Server/shell_interface.h> | 33 | #include <KWayland/Server/shell_interface.h> | ||
37 | 34 | | |||
38 | #include <QThread> | | |||
39 | | ||||
40 | using namespace KWin; | 35 | using namespace KWin; | ||
41 | using namespace KWayland::Client; | 36 | using namespace KWayland::Client; | ||
42 | 37 | | |||
43 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_shell_client-0"); | 38 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_shell_client-0"); | ||
44 | 39 | | |||
45 | class TestShellClient : public QObject | 40 | class TestShellClient : public QObject | ||
46 | { | 41 | { | ||
47 | Q_OBJECT | 42 | Q_OBJECT | ||
48 | private Q_SLOTS: | 43 | private Q_SLOTS: | ||
49 | void initTestCase(); | 44 | void initTestCase(); | ||
50 | void init(); | 45 | void init(); | ||
51 | void cleanup(); | 46 | void cleanup(); | ||
52 | 47 | | |||
53 | void testMapUnmapMap(); | 48 | void testMapUnmapMap(); | ||
54 | | ||||
55 | private: | | |||
56 | KWayland::Client::Compositor *m_compositor = nullptr; | | |||
57 | Shell *m_shell = nullptr; | | |||
58 | ShmPool *m_shm = nullptr; | | |||
59 | EventQueue *m_queue = nullptr; | | |||
60 | ConnectionThread *m_connection = nullptr; | | |||
61 | QThread *m_thread = nullptr; | | |||
62 | }; | 49 | }; | ||
63 | 50 | | |||
64 | void TestShellClient::initTestCase() | 51 | void TestShellClient::initTestCase() | ||
65 | { | 52 | { | ||
66 | qRegisterMetaType<KWin::ShellClient*>(); | 53 | qRegisterMetaType<KWin::ShellClient*>(); | ||
67 | qRegisterMetaType<KWin::AbstractClient*>(); | 54 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
68 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 55 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
69 | QVERIFY(workspaceCreatedSpy.isValid()); | 56 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
70 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | 57 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||
71 | QMetaObject::invokeMethod(kwinApp()->platform(), "setOutputCount", Qt::DirectConnection, Q_ARG(int, 2)); | 58 | QMetaObject::invokeMethod(kwinApp()->platform(), "setOutputCount", Qt::DirectConnection, Q_ARG(int, 2)); | ||
72 | waylandServer()->init(s_socketName.toLocal8Bit()); | 59 | waylandServer()->init(s_socketName.toLocal8Bit()); | ||
73 | 60 | | |||
74 | kwinApp()->start(); | 61 | kwinApp()->start(); | ||
75 | QVERIFY(workspaceCreatedSpy.wait()); | 62 | QVERIFY(workspaceCreatedSpy.wait()); | ||
76 | QCOMPARE(screens()->count(), 2); | 63 | QCOMPARE(screens()->count(), 2); | ||
77 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | 64 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | ||
78 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | 65 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | ||
79 | waylandServer()->initWorkspace(); | 66 | waylandServer()->initWorkspace(); | ||
80 | } | 67 | } | ||
81 | 68 | | |||
82 | void TestShellClient::init() | 69 | void TestShellClient::init() | ||
83 | { | 70 | { | ||
84 | // setup connection | 71 | QVERIFY(Test::setupWaylandConnection(s_socketName)); | ||
85 | m_connection = new ConnectionThread; | | |||
86 | QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); | | |||
87 | QVERIFY(connectedSpy.isValid()); | | |||
88 | m_connection->setSocketName(s_socketName); | | |||
89 | | ||||
90 | m_thread = new QThread(this); | | |||
91 | m_connection->moveToThread(m_thread); | | |||
92 | m_thread->start(); | | |||
93 | | ||||
94 | m_connection->initConnection(); | | |||
95 | QVERIFY(connectedSpy.wait()); | | |||
96 | | ||||
97 | m_queue = new EventQueue(this); | | |||
98 | QVERIFY(!m_queue->isValid()); | | |||
99 | m_queue->setup(m_connection); | | |||
100 | QVERIFY(m_queue->isValid()); | | |||
101 | | ||||
102 | Registry registry; | | |||
103 | registry.setEventQueue(m_queue); | | |||
104 | QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); | | |||
105 | QVERIFY(allAnnounced.isValid()); | | |||
106 | registry.create(m_connection->display()); | | |||
107 | QVERIFY(registry.isValid()); | | |||
108 | registry.setup(); | | |||
109 | QVERIFY(allAnnounced.wait()); | | |||
110 | | ||||
111 | m_compositor = registry.createCompositor(registry.interface(Registry::Interface::Compositor).name, | | |||
112 | registry.interface(Registry::Interface::Compositor).version, | | |||
113 | this); | | |||
114 | QVERIFY(m_compositor->isValid()); | | |||
115 | m_shm = registry.createShmPool(registry.interface(Registry::Interface::Shm).name, | | |||
116 | registry.interface(Registry::Interface::Shm).version, | | |||
117 | this); | | |||
118 | QVERIFY(m_shm->isValid()); | | |||
119 | m_shell = registry.createShell(registry.interface(Registry::Interface::Shell).name, | | |||
120 | registry.interface(Registry::Interface::Shell).version, | | |||
121 | this); | | |||
122 | QVERIFY(m_shell->isValid()); | | |||
123 | 72 | | |||
124 | screens()->setCurrent(0); | 73 | screens()->setCurrent(0); | ||
125 | KWin::Cursor::setPos(QPoint(1280, 512)); | 74 | KWin::Cursor::setPos(QPoint(1280, 512)); | ||
126 | } | 75 | } | ||
127 | 76 | | |||
128 | void TestShellClient::cleanup() | 77 | void TestShellClient::cleanup() | ||
129 | { | 78 | { | ||
130 | #define CLEANUP(name) \ | 79 | Test::destroyWaylandConnection(); | ||
131 | if (name) { \ | | |||
132 | delete name; \ | | |||
133 | name = nullptr; \ | | |||
134 | } | | |||
135 | CLEANUP(m_compositor) | | |||
136 | CLEANUP(m_shm) | | |||
137 | CLEANUP(m_shell) | | |||
138 | CLEANUP(m_queue) | | |||
139 | | ||||
140 | if (m_connection) { | | |||
141 | m_connection->deleteLater(); | | |||
142 | m_connection = nullptr; | | |||
143 | } | | |||
144 | if (m_thread) { | | |||
145 | m_thread->quit(); | | |||
146 | m_thread->wait(); | | |||
147 | delete m_thread; | | |||
148 | m_thread = nullptr; | | |||
149 | } | | |||
150 | #undef CLEANUP | | |||
151 | } | 80 | } | ||
152 | 81 | | |||
153 | void TestShellClient::testMapUnmapMap() | 82 | void TestShellClient::testMapUnmapMap() | ||
154 | { | 83 | { | ||
155 | // this test verifies that mapping a previously mapped window works correctly | 84 | // this test verifies that mapping a previously mapped window works correctly | ||
156 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 85 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
157 | QVERIFY(clientAddedSpy.isValid()); | 86 | QVERIFY(clientAddedSpy.isValid()); | ||
158 | 87 | | |||
159 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 88 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
160 | QScopedPointer<ShellSurface> shellSurface(m_shell->createSurface(surface.data())); | 89 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | ||
161 | 90 | | |||
162 | // now let's render | 91 | // now let's render | ||
163 | QImage img(QSize(100, 50), QImage::Format_ARGB32); | 92 | Test::render(surface.data(), QSize(100, 50), Qt::blue); | ||
164 | img.fill(Qt::blue); | | |||
165 | surface->attachBuffer(m_shm->createBuffer(img)); | | |||
166 | surface->damage(QRect(0, 0, 100, 50)); | | |||
167 | surface->commit(Surface::CommitFlag::None); | | |||
168 | 93 | | |||
169 | QVERIFY(clientAddedSpy.isEmpty()); | 94 | QVERIFY(clientAddedSpy.isEmpty()); | ||
170 | QVERIFY(clientAddedSpy.wait()); | 95 | QVERIFY(clientAddedSpy.wait()); | ||
171 | auto client = clientAddedSpy.first().first().value<ShellClient*>(); | 96 | auto client = clientAddedSpy.first().first().value<ShellClient*>(); | ||
172 | QVERIFY(client); | 97 | QVERIFY(client); | ||
173 | QVERIFY(client->isShown(true)); | 98 | QVERIFY(client->isShown(true)); | ||
174 | QCOMPARE(workspace()->activeClient(), client); | 99 | QCOMPARE(workspace()->activeClient(), client); | ||
175 | 100 | | |||
176 | // now unmap | 101 | // now unmap | ||
177 | QSignalSpy hiddenSpy(client, &ShellClient::windowHidden); | 102 | QSignalSpy hiddenSpy(client, &ShellClient::windowHidden); | ||
178 | QVERIFY(hiddenSpy.isValid()); | 103 | QVERIFY(hiddenSpy.isValid()); | ||
179 | QSignalSpy windowClosedSpy(client, &ShellClient::windowClosed); | 104 | QSignalSpy windowClosedSpy(client, &ShellClient::windowClosed); | ||
180 | QVERIFY(windowClosedSpy.isValid()); | 105 | QVERIFY(windowClosedSpy.isValid()); | ||
181 | surface->attachBuffer(Buffer::Ptr()); | 106 | surface->attachBuffer(Buffer::Ptr()); | ||
182 | surface->commit(Surface::CommitFlag::None); | 107 | surface->commit(Surface::CommitFlag::None); | ||
183 | QVERIFY(hiddenSpy.wait()); | 108 | QVERIFY(hiddenSpy.wait()); | ||
184 | QVERIFY(windowClosedSpy.isEmpty()); | 109 | QVERIFY(windowClosedSpy.isEmpty()); | ||
185 | QVERIFY(!workspace()->activeClient()); | 110 | QVERIFY(!workspace()->activeClient()); | ||
186 | 111 | | |||
187 | QSignalSpy windowShownSpy(client, &ShellClient::windowShown); | 112 | QSignalSpy windowShownSpy(client, &ShellClient::windowShown); | ||
188 | QVERIFY(windowShownSpy.isValid()); | 113 | QVERIFY(windowShownSpy.isValid()); | ||
189 | surface->attachBuffer(m_shm->createBuffer(img)); | 114 | Test::render(surface.data(), QSize(100, 50), Qt::blue); | ||
190 | surface->damage(QRect(0, 0, 100, 50)); | | |||
191 | surface->commit(Surface::CommitFlag::None); | | |||
192 | QCOMPARE(clientAddedSpy.count(), 1); | 115 | QCOMPARE(clientAddedSpy.count(), 1); | ||
193 | QVERIFY(windowShownSpy.wait()); | 116 | QVERIFY(windowShownSpy.wait()); | ||
194 | QCOMPARE(windowShownSpy.count(), 1); | 117 | QCOMPARE(windowShownSpy.count(), 1); | ||
195 | QCOMPARE(clientAddedSpy.count(), 1); | 118 | QCOMPARE(clientAddedSpy.count(), 1); | ||
196 | QCOMPARE(workspace()->activeClient(), client); | 119 | QCOMPARE(workspace()->activeClient(), client); | ||
197 | 120 | | |||
198 | // let's unmap again | 121 | // let's unmap again | ||
199 | surface->attachBuffer(Buffer::Ptr()); | 122 | surface->attachBuffer(Buffer::Ptr()); | ||
Show All 13 Lines |