Changeset View
Changeset View
Standalone View
Standalone View
autotests/client/test_text_input.cpp
1 | /******************************************************************** | 1 | /******************************************************************** | ||
---|---|---|---|---|---|
2 | Copyright 2016 Martin Gräßlin <mgraesslin@kde.org> | 2 | Copyright 2016 Martin Gräßlin <mgraesslin@kde.org> | ||
3 | Copyright 2018 Roman Gilg <subdiff@gmail.com> | ||||
3 | 4 | | |||
4 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | 6 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | 7 | 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 | 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 | 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 | 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 | act as a proxy defined in Section 6 of version 3 of the license. | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 44 | private Q_SLOTS: | |||
63 | void testTextDirection_data(); | 64 | void testTextDirection_data(); | ||
64 | void testTextDirection(); | 65 | void testTextDirection(); | ||
65 | void testLanguage_data(); | 66 | void testLanguage_data(); | ||
66 | void testLanguage(); | 67 | void testLanguage(); | ||
67 | void testKeyEvent_data(); | 68 | void testKeyEvent_data(); | ||
68 | void testKeyEvent(); | 69 | void testKeyEvent(); | ||
69 | void testPreEdit_data(); | 70 | void testPreEdit_data(); | ||
70 | void testPreEdit(); | 71 | void testPreEdit(); | ||
72 | void testPreEditv3_data(); | ||||
73 | void testPreEditv3(); | ||||
71 | void testCommit_data(); | 74 | void testCommit_data(); | ||
72 | void testCommit(); | 75 | void testCommit(); | ||
73 | 76 | | |||
74 | private: | 77 | private: | ||
75 | SurfaceInterface *waitForSurface(); | 78 | SurfaceInterface *waitForSurface(); | ||
76 | TextInput *createTextInput(TextInputInterfaceVersion version); | 79 | TextInput *createTextInput(TextInputInterfaceVersion version); | ||
77 | Display *m_display = nullptr; | 80 | Display *m_display = nullptr; | ||
78 | SeatInterface *m_seatInterface = nullptr; | 81 | SeatInterface *m_seatInterface = nullptr; | ||
79 | CompositorInterface *m_compositorInterface = nullptr; | 82 | CompositorInterface *m_compositorInterface = nullptr; | ||
80 | TextInputManagerInterface *m_textInputManagerV0Interface = nullptr; | 83 | TextInputManagerInterface *m_textInputManagerV0Interface = nullptr; | ||
81 | TextInputManagerInterface *m_textInputManagerV2Interface = nullptr; | 84 | TextInputManagerInterface *m_textInputManagerV2Interface = nullptr; | ||
85 | TextInputManagerInterface *m_textInputManagerV3Interface = nullptr; | ||||
82 | ConnectionThread *m_connection = nullptr; | 86 | ConnectionThread *m_connection = nullptr; | ||
83 | QThread *m_thread = nullptr; | 87 | QThread *m_thread = nullptr; | ||
84 | EventQueue *m_queue = nullptr; | 88 | EventQueue *m_queue = nullptr; | ||
85 | Seat *m_seat = nullptr; | 89 | Seat *m_seat = nullptr; | ||
86 | Keyboard *m_keyboard = nullptr; | 90 | Keyboard *m_keyboard = nullptr; | ||
87 | Compositor *m_compositor = nullptr; | 91 | Compositor *m_compositor = nullptr; | ||
88 | TextInputManager *m_textInputManagerV0 = nullptr; | 92 | TextInputManager *m_textInputManagerV0 = nullptr; | ||
89 | TextInputManager *m_textInputManagerV2 = nullptr; | 93 | TextInputManager *m_textInputManagerV2 = nullptr; | ||
94 | TextInputManager *m_textInputManagerV3 = nullptr; | ||||
90 | }; | 95 | }; | ||
91 | 96 | | |||
92 | static const QString s_socketName = QStringLiteral("kwayland-test-text-input-0"); | 97 | static const QString s_socketName = QStringLiteral("kwayland-test-text-input-0"); | ||
93 | 98 | | |||
94 | void TextInputTest::init() | 99 | void TextInputTest::init() | ||
95 | { | 100 | { | ||
96 | delete m_display; | 101 | delete m_display; | ||
97 | m_display = new Display(this); | 102 | m_display = new Display(this); | ||
98 | m_display->setSocketName(s_socketName); | 103 | m_display->setSocketName(s_socketName); | ||
99 | m_display->start(); | 104 | m_display->start(); | ||
100 | QVERIFY(m_display->isRunning()); | 105 | QVERIFY(m_display->isRunning()); | ||
101 | m_display->createShm(); | 106 | m_display->createShm(); | ||
102 | m_seatInterface = m_display->createSeat(); | 107 | m_seatInterface = m_display->createSeat(); | ||
103 | m_seatInterface->setHasKeyboard(true); | 108 | m_seatInterface->setHasKeyboard(true); | ||
104 | m_seatInterface->setHasTouch(true); | 109 | m_seatInterface->setHasTouch(true); | ||
105 | m_seatInterface->create(); | 110 | m_seatInterface->create(); | ||
106 | m_compositorInterface = m_display->createCompositor(); | 111 | m_compositorInterface = m_display->createCompositor(); | ||
107 | m_compositorInterface->create(); | 112 | m_compositorInterface->create(); | ||
108 | m_textInputManagerV0Interface = m_display->createTextInputManager(TextInputInterfaceVersion::UnstableV0); | 113 | m_textInputManagerV0Interface = m_display->createTextInputManager(TextInputInterfaceVersion::UnstableV0); | ||
109 | m_textInputManagerV0Interface->create(); | 114 | m_textInputManagerV0Interface->create(); | ||
110 | m_textInputManagerV2Interface = m_display->createTextInputManager(TextInputInterfaceVersion::UnstableV2); | 115 | m_textInputManagerV2Interface = m_display->createTextInputManager(TextInputInterfaceVersion::UnstableV2); | ||
111 | m_textInputManagerV2Interface->create(); | 116 | m_textInputManagerV2Interface->create(); | ||
117 | m_textInputManagerV3Interface = m_display->createTextInputManager(TextInputInterfaceVersion::UnstableV3); | ||||
118 | m_textInputManagerV3Interface->create(); | ||||
112 | 119 | | |||
113 | // setup connection | 120 | // setup connection | ||
114 | m_connection = new KWayland::Client::ConnectionThread; | 121 | m_connection = new KWayland::Client::ConnectionThread; | ||
115 | QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); | 122 | QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); | ||
116 | QVERIFY(connectedSpy.isValid()); | 123 | QVERIFY(connectedSpy.isValid()); | ||
117 | m_connection->setSocketName(s_socketName); | 124 | m_connection->setSocketName(s_socketName); | ||
118 | 125 | | |||
119 | m_thread = new QThread(this); | 126 | m_thread = new QThread(this); | ||
Show All 34 Lines | 160 | m_textInputManagerV0 = registry.createTextInputManager(registry.interface(Registry::Interface::TextInputManagerUnstableV0).name, | |||
154 | registry.interface(Registry::Interface::TextInputManagerUnstableV0).version, | 161 | registry.interface(Registry::Interface::TextInputManagerUnstableV0).version, | ||
155 | this); | 162 | this); | ||
156 | QVERIFY(m_textInputManagerV0->isValid()); | 163 | QVERIFY(m_textInputManagerV0->isValid()); | ||
157 | 164 | | |||
158 | m_textInputManagerV2 = registry.createTextInputManager(registry.interface(Registry::Interface::TextInputManagerUnstableV2).name, | 165 | m_textInputManagerV2 = registry.createTextInputManager(registry.interface(Registry::Interface::TextInputManagerUnstableV2).name, | ||
159 | registry.interface(Registry::Interface::TextInputManagerUnstableV2).version, | 166 | registry.interface(Registry::Interface::TextInputManagerUnstableV2).version, | ||
160 | this); | 167 | this); | ||
161 | QVERIFY(m_textInputManagerV2->isValid()); | 168 | QVERIFY(m_textInputManagerV2->isValid()); | ||
169 | | ||||
170 | m_textInputManagerV3 = registry.createTextInputManager(registry.interface(Registry::Interface::TextInputManagerUnstableV3).name, | ||||
171 | registry.interface(Registry::Interface::TextInputManagerUnstableV3).version, | ||||
172 | this); | ||||
173 | QVERIFY(m_textInputManagerV3->isValid()); | ||||
162 | } | 174 | } | ||
163 | 175 | | |||
164 | void TextInputTest::cleanup() | 176 | void TextInputTest::cleanup() | ||
165 | { | 177 | { | ||
166 | #define CLEANUP(variable) \ | 178 | #define CLEANUP(variable) \ | ||
167 | if (variable) { \ | 179 | if (variable) { \ | ||
168 | delete variable; \ | 180 | delete variable; \ | ||
169 | variable = nullptr; \ | 181 | variable = nullptr; \ | ||
170 | } | 182 | } | ||
171 | CLEANUP(m_textInputManagerV0) | 183 | CLEANUP(m_textInputManagerV0) | ||
172 | CLEANUP(m_textInputManagerV2) | 184 | CLEANUP(m_textInputManagerV2) | ||
185 | CLEANUP(m_textInputManagerV3) | ||||
173 | CLEANUP(m_keyboard) | 186 | CLEANUP(m_keyboard) | ||
174 | CLEANUP(m_seat) | 187 | CLEANUP(m_seat) | ||
175 | CLEANUP(m_compositor) | 188 | CLEANUP(m_compositor) | ||
176 | CLEANUP(m_queue) | 189 | CLEANUP(m_queue) | ||
177 | if (m_connection) { | 190 | if (m_connection) { | ||
178 | m_connection->deleteLater(); | 191 | m_connection->deleteLater(); | ||
179 | m_connection = nullptr; | 192 | m_connection = nullptr; | ||
180 | } | 193 | } | ||
181 | if (m_thread) { | 194 | if (m_thread) { | ||
182 | m_thread->quit(); | 195 | m_thread->quit(); | ||
183 | m_thread->wait(); | 196 | m_thread->wait(); | ||
184 | delete m_thread; | 197 | delete m_thread; | ||
185 | m_thread = nullptr; | 198 | m_thread = nullptr; | ||
186 | } | 199 | } | ||
187 | 200 | | |||
188 | CLEANUP(m_textInputManagerV0Interface) | 201 | CLEANUP(m_textInputManagerV0Interface) | ||
189 | CLEANUP(m_textInputManagerV2Interface) | 202 | CLEANUP(m_textInputManagerV2Interface) | ||
203 | CLEANUP(m_textInputManagerV3Interface) | ||||
190 | CLEANUP(m_compositorInterface) | 204 | CLEANUP(m_compositorInterface) | ||
191 | CLEANUP(m_seatInterface) | 205 | CLEANUP(m_seatInterface) | ||
192 | CLEANUP(m_display) | 206 | CLEANUP(m_display) | ||
193 | #undef CLEANUP | 207 | #undef CLEANUP | ||
194 | } | 208 | } | ||
195 | 209 | | |||
196 | SurfaceInterface *TextInputTest::waitForSurface() | 210 | SurfaceInterface *TextInputTest::waitForSurface() | ||
197 | { | 211 | { | ||
Show All 12 Lines | |||||
210 | 224 | | |||
211 | TextInput *TextInputTest::createTextInput(TextInputInterfaceVersion version) | 225 | TextInput *TextInputTest::createTextInput(TextInputInterfaceVersion version) | ||
212 | { | 226 | { | ||
213 | switch (version) { | 227 | switch (version) { | ||
214 | case TextInputInterfaceVersion::UnstableV0: | 228 | case TextInputInterfaceVersion::UnstableV0: | ||
215 | return m_textInputManagerV0->createTextInput(m_seat); | 229 | return m_textInputManagerV0->createTextInput(m_seat); | ||
216 | case TextInputInterfaceVersion::UnstableV2: | 230 | case TextInputInterfaceVersion::UnstableV2: | ||
217 | return m_textInputManagerV2->createTextInput(m_seat); | 231 | return m_textInputManagerV2->createTextInput(m_seat); | ||
232 | case TextInputInterfaceVersion::UnstableV3: | ||||
233 | return m_textInputManagerV3->createTextInput(m_seat); | ||||
218 | default: | 234 | default: | ||
219 | Q_UNREACHABLE(); | 235 | Q_UNREACHABLE(); | ||
220 | return nullptr; | 236 | return nullptr; | ||
221 | } | 237 | } | ||
222 | } | 238 | } | ||
223 | 239 | | |||
224 | void TextInputTest::testEnterLeave_data() | 240 | void TextInputTest::testEnterLeave_data() | ||
225 | { | 241 | { | ||
226 | QTest::addColumn<TextInputInterfaceVersion>("version"); | 242 | QTest::addColumn<TextInputInterfaceVersion>("version"); | ||
227 | QTest::addColumn<bool>("updatesDirectly"); | 243 | QTest::addColumn<bool>("updatesDirectly"); | ||
244 | QTest::addColumn<bool>("clientCommits"); | ||||
228 | 245 | | |||
229 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0 << false; | 246 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0 << false << false; | ||
230 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2 << true; | 247 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2 << true << false; | ||
248 | QTest::newRow("UnstableV3") << TextInputInterfaceVersion::UnstableV3 << true << true; | ||||
231 | } | 249 | } | ||
232 | 250 | | |||
233 | void TextInputTest::testEnterLeave() | 251 | void TextInputTest::testEnterLeave() | ||
234 | { | 252 | { | ||
235 | // this test verifies that enter leave are sent correctly | 253 | // this test verifies that enter leave are sent correctly | ||
236 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 254 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||
237 | QFETCH(TextInputInterfaceVersion, version); | 255 | QFETCH(TextInputInterfaceVersion, version); | ||
238 | QScopedPointer<TextInput> textInput(createTextInput(version)); | 256 | QScopedPointer<TextInput> textInput(createTextInput(version)); | ||
Show All 9 Lines | |||||
248 | 266 | | |||
249 | // now let's try to enter it | 267 | // now let's try to enter it | ||
250 | QVERIFY(!m_seatInterface->focusedTextInput()); | 268 | QVERIFY(!m_seatInterface->focusedTextInput()); | ||
251 | QVERIFY(!m_seatInterface->focusedTextInputSurface()); | 269 | QVERIFY(!m_seatInterface->focusedTextInputSurface()); | ||
252 | m_seatInterface->setFocusedKeyboardSurface(serverSurface); | 270 | m_seatInterface->setFocusedKeyboardSurface(serverSurface); | ||
253 | QCOMPARE(m_seatInterface->focusedTextInputSurface(), serverSurface); | 271 | QCOMPARE(m_seatInterface->focusedTextInputSurface(), serverSurface); | ||
254 | // text input not yet set for the surface | 272 | // text input not yet set for the surface | ||
255 | QFETCH(bool, updatesDirectly); | 273 | QFETCH(bool, updatesDirectly); | ||
274 | QFETCH(bool, clientCommits); | ||||
256 | QCOMPARE(bool(m_seatInterface->focusedTextInput()), updatesDirectly); | 275 | QCOMPARE(bool(m_seatInterface->focusedTextInput()), updatesDirectly); | ||
257 | QCOMPARE(textInputChangedSpy.isEmpty(), !updatesDirectly); | 276 | QCOMPARE(textInputChangedSpy.isEmpty(), !updatesDirectly); | ||
258 | textInput->enable(surface.data()); | 277 | textInput->enable(surface.data()); | ||
259 | // this should trigger on server side | 278 | // this should trigger on server side | ||
260 | if (!updatesDirectly) { | 279 | if (!updatesDirectly) { | ||
261 | QVERIFY(textInputChangedSpy.wait()); | 280 | QVERIFY(textInputChangedSpy.wait()); | ||
262 | } | 281 | } | ||
263 | QCOMPARE(textInputChangedSpy.count(), 1); | 282 | QCOMPARE(textInputChangedSpy.count(), 1); | ||
264 | auto serverTextInput = m_seatInterface->focusedTextInput(); | 283 | auto serverTextInput = m_seatInterface->focusedTextInput(); | ||
265 | QVERIFY(serverTextInput); | 284 | QVERIFY(serverTextInput); | ||
266 | QCOMPARE(serverTextInput->interfaceVersion(), version); | 285 | QCOMPARE(serverTextInput->interfaceVersion(), version); | ||
267 | QSignalSpy enabledChangedSpy(serverTextInput, &TextInputInterface::enabledChanged); | 286 | QSignalSpy enabledChangedSpy(serverTextInput, &TextInputInterface::enabledChanged); | ||
268 | QVERIFY(enabledChangedSpy.isValid()); | 287 | QVERIFY(enabledChangedSpy.isValid()); | ||
288 | if (clientCommits) { | ||||
289 | textInput->commit(); | ||||
290 | } | ||||
269 | if (updatesDirectly) { | 291 | if (updatesDirectly) { | ||
270 | QVERIFY(enabledChangedSpy.wait()); | 292 | QVERIFY(enabledChangedSpy.wait()); | ||
271 | enabledChangedSpy.clear(); | 293 | enabledChangedSpy.clear(); | ||
272 | } | 294 | } | ||
273 | QCOMPARE(serverTextInput->surface().data(), serverSurface); | 295 | QCOMPARE(serverTextInput->surface().data(), serverSurface); | ||
274 | QVERIFY(serverTextInput->isEnabled()); | 296 | QVERIFY(serverTextInput->isEnabled()); | ||
275 | 297 | | |||
276 | // and trigger an enter | 298 | // and trigger an enter | ||
Show All 17 Lines | |||||
294 | QVERIFY(m_seatInterface->focusedTextInput()); | 316 | QVERIFY(m_seatInterface->focusedTextInput()); | ||
295 | QVERIFY(enteredSpy.wait()); | 317 | QVERIFY(enteredSpy.wait()); | ||
296 | QCOMPARE(enteredSpy.count(), 2); | 318 | QCOMPARE(enteredSpy.count(), 2); | ||
297 | QCOMPARE(textInput->enteredSurface(), surface.data()); | 319 | QCOMPARE(textInput->enteredSurface(), surface.data()); | ||
298 | QVERIFY(serverTextInput->isEnabled()); | 320 | QVERIFY(serverTextInput->isEnabled()); | ||
299 | 321 | | |||
300 | // let's deactivate on client side | 322 | // let's deactivate on client side | ||
301 | textInput->disable(surface.data()); | 323 | textInput->disable(surface.data()); | ||
324 | if (clientCommits) { | ||||
325 | textInput->commit(); | ||||
326 | } | ||||
302 | QVERIFY(enabledChangedSpy.wait()); | 327 | QVERIFY(enabledChangedSpy.wait()); | ||
303 | QCOMPARE(enabledChangedSpy.count(), 1); | 328 | QCOMPARE(enabledChangedSpy.count(), 1); | ||
304 | QVERIFY(!serverTextInput->isEnabled()); | 329 | QVERIFY(!serverTextInput->isEnabled()); | ||
305 | // does not trigger a leave | 330 | // does not trigger a leave | ||
306 | QCOMPARE(textInputChangedSpy.count(), 3); | 331 | QCOMPARE(textInputChangedSpy.count(), 3); | ||
307 | // should still be the same text input | 332 | // should still be the same text input | ||
308 | QCOMPARE(m_seatInterface->focusedTextInput(), serverTextInput); | 333 | QCOMPARE(m_seatInterface->focusedTextInput(), serverTextInput); | ||
309 | //reset | 334 | //reset | ||
310 | textInput->enable(surface.data()); | 335 | textInput->enable(surface.data()); | ||
336 | if (clientCommits) { | ||||
337 | textInput->commit(); | ||||
338 | } | ||||
311 | QVERIFY(enabledChangedSpy.wait()); | 339 | QVERIFY(enabledChangedSpy.wait()); | ||
312 | 340 | | |||
313 | //trigger an enter again and leave, but this | 341 | //trigger an enter again and leave, but this | ||
314 | //time we try sending an event after the surface is unbound | 342 | //time we try sending an event after the surface is unbound | ||
315 | //but not yet destroyed. It should work without errors | 343 | //but not yet destroyed. It should work without errors | ||
316 | QCOMPARE(textInput->enteredSurface(), surface.data()); | 344 | QCOMPARE(textInput->enteredSurface(), surface.data()); | ||
317 | connect(serverSurface, &Resource::unbound, [=]() { | 345 | connect(serverSurface, &Resource::unbound, [=]() { | ||
318 | m_seatInterface->setFocusedKeyboardSurface(nullptr); | 346 | m_seatInterface->setFocusedKeyboardSurface(nullptr); | ||
319 | }); | 347 | }); | ||
320 | //delete the client and wait for the server to catch up | 348 | //delete the client and wait for the server to catch up | ||
321 | QSignalSpy unboundSpy(serverSurface, &QObject::destroyed); | 349 | QSignalSpy unboundSpy(serverSurface, &QObject::destroyed); | ||
322 | surface.reset(); | 350 | surface.reset(); | ||
323 | QVERIFY(unboundSpy.wait()); | 351 | QVERIFY(unboundSpy.wait()); | ||
324 | QVERIFY(leftSpy.wait()); | 352 | QVERIFY(leftSpy.wait()); | ||
325 | QVERIFY(!textInput->enteredSurface()); | 353 | QVERIFY(!textInput->enteredSurface()); | ||
326 | } | 354 | } | ||
327 | 355 | | |||
328 | void TextInputTest::testShowHidePanel_data() | 356 | void TextInputTest::testShowHidePanel_data() | ||
329 | { | 357 | { | ||
330 | QTest::addColumn<TextInputInterfaceVersion>("version"); | 358 | QTest::addColumn<TextInputInterfaceVersion>("version"); | ||
331 | 359 | | |||
332 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | 360 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | ||
333 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | 361 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | ||
362 | // v3 does not support this anymore | ||||
334 | } | 363 | } | ||
335 | 364 | | |||
336 | void TextInputTest::testShowHidePanel() | 365 | void TextInputTest::testShowHidePanel() | ||
337 | { | 366 | { | ||
338 | // this test verifies that the requests for show/hide panel work | 367 | // this test verifies that the requests for show/hide panel work | ||
339 | // and that status is properly sent to the client | 368 | // and that status is properly sent to the client | ||
340 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 369 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||
341 | auto serverSurface = waitForSurface(); | 370 | auto serverSurface = waitForSurface(); | ||
Show All 28 Lines | |||||
370 | ti->setInputPanelState(false, QRect(0, 0, 0, 0)); | 399 | ti->setInputPanelState(false, QRect(0, 0, 0, 0)); | ||
371 | QVERIFY(inputPanelStateChangedSpy.wait()); | 400 | QVERIFY(inputPanelStateChangedSpy.wait()); | ||
372 | QCOMPARE(textInput->isInputPanelVisible(), false); | 401 | QCOMPARE(textInput->isInputPanelVisible(), false); | ||
373 | } | 402 | } | ||
374 | 403 | | |||
375 | void TextInputTest::testCursorRectangle_data() | 404 | void TextInputTest::testCursorRectangle_data() | ||
376 | { | 405 | { | ||
377 | QTest::addColumn<TextInputInterfaceVersion>("version"); | 406 | QTest::addColumn<TextInputInterfaceVersion>("version"); | ||
407 | QTest::addColumn<bool>("clientCommits"); | ||||
378 | 408 | | |||
379 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | 409 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0 << false; | ||
380 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | 410 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2 << false; | ||
411 | QTest::newRow("UnstableV3") << TextInputInterfaceVersion::UnstableV3 << true; | ||||
381 | } | 412 | } | ||
382 | 413 | | |||
383 | void TextInputTest::testCursorRectangle() | 414 | void TextInputTest::testCursorRectangle() | ||
384 | { | 415 | { | ||
385 | // this test verifies that passing the cursor rectangle from client to server works | 416 | // this test verifies that passing the cursor rectangle from client to server works | ||
386 | // and that setting visibility state from server to client works | 417 | // and that setting visibility state from server to client works | ||
387 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 418 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||
388 | auto serverSurface = waitForSurface(); | 419 | auto serverSurface = waitForSurface(); | ||
389 | QVERIFY(serverSurface); | 420 | QVERIFY(serverSurface); | ||
390 | QFETCH(TextInputInterfaceVersion, version); | 421 | QFETCH(TextInputInterfaceVersion, version); | ||
391 | QScopedPointer<TextInput> textInput(createTextInput(version)); | 422 | QScopedPointer<TextInput> textInput(createTextInput(version)); | ||
392 | QVERIFY(!textInput.isNull()); | 423 | QVERIFY(!textInput.isNull()); | ||
393 | textInput->enable(surface.data()); | 424 | textInput->enable(surface.data()); | ||
394 | m_connection->flush(); | 425 | m_connection->flush(); | ||
395 | m_display->dispatchEvents(); | 426 | m_display->dispatchEvents(); | ||
396 | 427 | | |||
397 | m_seatInterface->setFocusedKeyboardSurface(serverSurface); | 428 | m_seatInterface->setFocusedKeyboardSurface(serverSurface); | ||
398 | auto ti = m_seatInterface->focusedTextInput(); | 429 | auto ti = m_seatInterface->focusedTextInput(); | ||
399 | QVERIFY(ti); | 430 | QVERIFY(ti); | ||
400 | QCOMPARE(ti->cursorRectangle(), QRect()); | 431 | QCOMPARE(ti->cursorRectangle(), QRect()); | ||
401 | QSignalSpy cursorRectangleChangedSpy(ti, &TextInputInterface::cursorRectangleChanged); | 432 | QSignalSpy cursorRectangleChangedSpy(ti, &TextInputInterface::cursorRectangleChanged); | ||
402 | QVERIFY(cursorRectangleChangedSpy.isValid()); | 433 | QVERIFY(cursorRectangleChangedSpy.isValid()); | ||
403 | 434 | | |||
404 | textInput->setCursorRectangle(QRect(10, 20, 30, 40)); | 435 | textInput->setCursorRectangle(QRect(10, 20, 30, 40)); | ||
436 | QFETCH(bool, clientCommits); | ||||
437 | if (clientCommits) { | ||||
438 | textInput->commit(); | ||||
439 | } | ||||
405 | QVERIFY(cursorRectangleChangedSpy.wait()); | 440 | QVERIFY(cursorRectangleChangedSpy.wait()); | ||
406 | QCOMPARE(ti->cursorRectangle(), QRect(10, 20, 30, 40)); | 441 | QCOMPARE(ti->cursorRectangle(), QRect(10, 20, 30, 40)); | ||
407 | } | 442 | } | ||
408 | 443 | | |||
409 | void TextInputTest::testPreferredLanguage_data() | 444 | void TextInputTest::testPreferredLanguage_data() | ||
410 | { | 445 | { | ||
411 | QTest::addColumn<TextInputInterfaceVersion>("version"); | 446 | QTest::addColumn<TextInputInterfaceVersion>("version"); | ||
412 | 447 | | |||
413 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | 448 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | ||
414 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | 449 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | ||
450 | // v3 does not support this anymore | ||||
415 | } | 451 | } | ||
416 | 452 | | |||
417 | void TextInputTest::testPreferredLanguage() | 453 | void TextInputTest::testPreferredLanguage() | ||
418 | { | 454 | { | ||
419 | // this test verifies that passing the preferred language from client to server works | 455 | // this test verifies that passing the preferred language from client to server works | ||
420 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 456 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||
421 | auto serverSurface = waitForSurface(); | 457 | auto serverSurface = waitForSurface(); | ||
422 | QVERIFY(serverSurface); | 458 | QVERIFY(serverSurface); | ||
Show All 17 Lines | |||||
440 | } | 476 | } | ||
441 | 477 | | |||
442 | void TextInputTest::testReset_data() | 478 | void TextInputTest::testReset_data() | ||
443 | { | 479 | { | ||
444 | QTest::addColumn<TextInputInterfaceVersion>("version"); | 480 | QTest::addColumn<TextInputInterfaceVersion>("version"); | ||
445 | 481 | | |||
446 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | 482 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | ||
447 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | 483 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | ||
484 | // v3 does not support this anymore | ||||
448 | } | 485 | } | ||
449 | 486 | | |||
450 | void TextInputTest::testReset() | 487 | void TextInputTest::testReset() | ||
451 | { | 488 | { | ||
452 | // this test verifies that the reset request is properly passed from client to server | 489 | // this test verifies that the reset request is properly passed from client to server | ||
453 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 490 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||
454 | auto serverSurface = waitForSurface(); | 491 | auto serverSurface = waitForSurface(); | ||
455 | QVERIFY(serverSurface); | 492 | QVERIFY(serverSurface); | ||
Show All 13 Lines | |||||
469 | 506 | | |||
470 | textInput->reset(); | 507 | textInput->reset(); | ||
471 | QVERIFY(resetRequestedSpy.wait()); | 508 | QVERIFY(resetRequestedSpy.wait()); | ||
472 | } | 509 | } | ||
473 | 510 | | |||
474 | void TextInputTest::testSurroundingText_data() | 511 | void TextInputTest::testSurroundingText_data() | ||
475 | { | 512 | { | ||
476 | QTest::addColumn<TextInputInterfaceVersion>("version"); | 513 | QTest::addColumn<TextInputInterfaceVersion>("version"); | ||
514 | QTest::addColumn<bool>("clientCommits"); | ||||
477 | 515 | | |||
478 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | 516 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0 << false; | ||
479 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | 517 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2 << false; | ||
518 | QTest::newRow("UnstableV3") << TextInputInterfaceVersion::UnstableV3 << true; | ||||
480 | } | 519 | } | ||
481 | 520 | | |||
482 | void TextInputTest::testSurroundingText() | 521 | void TextInputTest::testSurroundingText() | ||
483 | { | 522 | { | ||
484 | // this test verifies that surrounding text is properly passed around | 523 | // this test verifies that surrounding text is properly passed around | ||
485 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 524 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||
486 | auto serverSurface = waitForSurface(); | 525 | auto serverSurface = waitForSurface(); | ||
487 | QVERIFY(serverSurface); | 526 | QVERIFY(serverSurface); | ||
Show All 10 Lines | |||||
498 | QVERIFY(ti->surroundingText().isEmpty()); | 537 | QVERIFY(ti->surroundingText().isEmpty()); | ||
499 | QCOMPARE(ti->surroundingTextCursorPosition(), 0); | 538 | QCOMPARE(ti->surroundingTextCursorPosition(), 0); | ||
500 | QCOMPARE(ti->surroundingTextSelectionAnchor(), 0); | 539 | QCOMPARE(ti->surroundingTextSelectionAnchor(), 0); | ||
501 | 540 | | |||
502 | QSignalSpy surroundingTextChangedSpy(ti, &TextInputInterface::surroundingTextChanged); | 541 | QSignalSpy surroundingTextChangedSpy(ti, &TextInputInterface::surroundingTextChanged); | ||
503 | QVERIFY(surroundingTextChangedSpy.isValid()); | 542 | QVERIFY(surroundingTextChangedSpy.isValid()); | ||
504 | 543 | | |||
505 | textInput->setSurroundingText(QStringLiteral("100 €, 100 $"), 5, 6); | 544 | textInput->setSurroundingText(QStringLiteral("100 €, 100 $"), 5, 6); | ||
545 | QFETCH(bool, clientCommits); | ||||
546 | if (clientCommits) { | ||||
547 | textInput->commit(); | ||||
548 | } | ||||
zzag: Personal opinion: tests have to be easy to follow, it's okay if we copy some code. I'd prefer… | |||||
506 | QVERIFY(surroundingTextChangedSpy.wait()); | 549 | QVERIFY(surroundingTextChangedSpy.wait()); | ||
507 | QCOMPARE(ti->surroundingText(), QStringLiteral("100 €, 100 $").toUtf8()); | 550 | QCOMPARE(ti->surroundingText(), QStringLiteral("100 €, 100 $").toUtf8()); | ||
508 | QCOMPARE(ti->surroundingTextCursorPosition(), QStringLiteral("100 €, 100 $").toUtf8().indexOf(',')); | 551 | QCOMPARE(ti->surroundingTextCursorPosition(), QStringLiteral("100 €, 100 $").toUtf8().indexOf(',')); | ||
509 | QCOMPARE(ti->surroundingTextSelectionAnchor(), QStringLiteral("100 €, 100 $").toUtf8().indexOf(' ', ti->surroundingTextCursorPosition())); | 552 | QCOMPARE(ti->surroundingTextSelectionAnchor(), QStringLiteral("100 €, 100 $").toUtf8().indexOf(' ', ti->surroundingTextCursorPosition())); | ||
510 | } | 553 | } | ||
511 | 554 | | |||
512 | void TextInputTest::testContentHints_data() | 555 | void TextInputTest::testContentHints_data() | ||
513 | { | 556 | { | ||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 628 | << (TextInputInterface::ContentHint::AutoCompletion | | |||
587 | TextInputInterface::ContentHint::AutoCapitalization | | 630 | TextInputInterface::ContentHint::AutoCapitalization | | ||
588 | TextInputInterface::ContentHint::LowerCase | | 631 | TextInputInterface::ContentHint::LowerCase | | ||
589 | TextInputInterface::ContentHint::UpperCase | | 632 | TextInputInterface::ContentHint::UpperCase | | ||
590 | TextInputInterface::ContentHint::TitleCase | | 633 | TextInputInterface::ContentHint::TitleCase | | ||
591 | TextInputInterface::ContentHint::HiddenText | | 634 | TextInputInterface::ContentHint::HiddenText | | ||
592 | TextInputInterface::ContentHint::SensitiveData | | 635 | TextInputInterface::ContentHint::SensitiveData | | ||
593 | TextInputInterface::ContentHint::Latin | | 636 | TextInputInterface::ContentHint::Latin | | ||
594 | TextInputInterface::ContentHint::MultiLine); | 637 | TextInputInterface::ContentHint::MultiLine); | ||
638 | | ||||
639 | // same for version 3 | ||||
640 | | ||||
641 | QTest::newRow("completion/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentHints(TextInput::ContentHint::AutoCompletion) << TextInputInterface::ContentHints(TextInputInterface::ContentHint::AutoCompletion); | ||||
642 | QTest::newRow("Correction/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentHints(TextInput::ContentHint::AutoCorrection) << TextInputInterface::ContentHints(TextInputInterface::ContentHint::AutoCorrection); | ||||
643 | QTest::newRow("Capitalization/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentHints(TextInput::ContentHint::AutoCapitalization) << TextInputInterface::ContentHints(TextInputInterface::ContentHint::AutoCapitalization); | ||||
644 | QTest::newRow("Lowercase/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentHints(TextInput::ContentHint::LowerCase) << TextInputInterface::ContentHints(TextInputInterface::ContentHint::LowerCase); | ||||
645 | QTest::newRow("Uppercase/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentHints(TextInput::ContentHint::UpperCase) << TextInputInterface::ContentHints(TextInputInterface::ContentHint::UpperCase); | ||||
646 | QTest::newRow("Titlecase/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentHints(TextInput::ContentHint::TitleCase) << TextInputInterface::ContentHints(TextInputInterface::ContentHint::TitleCase); | ||||
647 | QTest::newRow("HiddenText/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentHints(TextInput::ContentHint::HiddenText) << TextInputInterface::ContentHints(TextInputInterface::ContentHint::HiddenText); | ||||
648 | QTest::newRow("SensitiveData/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentHints(TextInput::ContentHint::SensitiveData) << TextInputInterface::ContentHints(TextInputInterface::ContentHint::SensitiveData); | ||||
649 | QTest::newRow("Latin/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentHints(TextInput::ContentHint::Latin) << TextInputInterface::ContentHints(TextInputInterface::ContentHint::Latin); | ||||
650 | QTest::newRow("Multiline/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentHints(TextInput::ContentHint::MultiLine) << TextInputInterface::ContentHints(TextInputInterface::ContentHint::MultiLine); | ||||
651 | | ||||
652 | QTest::newRow("autos/v3") << TextInputInterfaceVersion::UnstableV3 | ||||
653 | << (TextInput::ContentHint::AutoCompletion | TextInput::ContentHint::AutoCorrection | TextInput::ContentHint::AutoCapitalization) | ||||
654 | << (TextInputInterface::ContentHint::AutoCompletion | TextInputInterface::ContentHint::AutoCorrection | TextInputInterface::ContentHint::AutoCapitalization); | ||||
655 | | ||||
656 | // all has combinations which don't make sense - what's both lowercase and uppercase? | ||||
657 | QTest::newRow("all/v3") << TextInputInterfaceVersion::UnstableV3 | ||||
658 | << (TextInput::ContentHint::AutoCompletion | | ||||
659 | TextInput::ContentHint::AutoCorrection | | ||||
660 | TextInput::ContentHint::AutoCapitalization | | ||||
661 | TextInput::ContentHint::LowerCase | | ||||
662 | TextInput::ContentHint::UpperCase | | ||||
663 | TextInput::ContentHint::TitleCase | | ||||
664 | TextInput::ContentHint::HiddenText | | ||||
665 | TextInput::ContentHint::SensitiveData | | ||||
666 | TextInput::ContentHint::Latin | | ||||
667 | TextInput::ContentHint::MultiLine) | ||||
668 | << (TextInputInterface::ContentHint::AutoCompletion | | ||||
669 | TextInputInterface::ContentHint::AutoCorrection | | ||||
670 | TextInputInterface::ContentHint::AutoCapitalization | | ||||
671 | TextInputInterface::ContentHint::LowerCase | | ||||
672 | TextInputInterface::ContentHint::UpperCase | | ||||
673 | TextInputInterface::ContentHint::TitleCase | | ||||
674 | TextInputInterface::ContentHint::HiddenText | | ||||
675 | TextInputInterface::ContentHint::SensitiveData | | ||||
676 | TextInputInterface::ContentHint::Latin | | ||||
677 | TextInputInterface::ContentHint::MultiLine); | ||||
595 | } | 678 | } | ||
596 | 679 | | |||
597 | void TextInputTest::testContentHints() | 680 | void TextInputTest::testContentHints() | ||
598 | { | 681 | { | ||
599 | // this test verifies that content hints are properly passed from client to server | 682 | // this test verifies that content hints are properly passed from client to server | ||
600 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 683 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||
601 | auto serverSurface = waitForSurface(); | 684 | auto serverSurface = waitForSurface(); | ||
602 | QVERIFY(serverSurface); | 685 | QVERIFY(serverSurface); | ||
603 | QFETCH(TextInputInterfaceVersion, version); | 686 | QFETCH(TextInputInterfaceVersion, version); | ||
604 | QScopedPointer<TextInput> textInput(createTextInput(version)); | 687 | QScopedPointer<TextInput> textInput(createTextInput(version)); | ||
605 | QVERIFY(!textInput.isNull()); | 688 | QVERIFY(!textInput.isNull()); | ||
606 | textInput->enable(surface.data()); | 689 | textInput->enable(surface.data()); | ||
607 | m_connection->flush(); | 690 | m_connection->flush(); | ||
608 | m_display->dispatchEvents(); | 691 | m_display->dispatchEvents(); | ||
609 | 692 | | |||
610 | m_seatInterface->setFocusedKeyboardSurface(serverSurface); | 693 | m_seatInterface->setFocusedKeyboardSurface(serverSurface); | ||
611 | auto ti = m_seatInterface->focusedTextInput(); | 694 | auto ti = m_seatInterface->focusedTextInput(); | ||
612 | QVERIFY(ti); | 695 | QVERIFY(ti); | ||
613 | QCOMPARE(ti->contentHints(), TextInputInterface::ContentHints()); | 696 | QCOMPARE(ti->contentHints(), TextInputInterface::ContentHints()); | ||
614 | 697 | | |||
615 | QSignalSpy contentTypeChangedSpy(ti, &TextInputInterface::contentTypeChanged); | 698 | QSignalSpy contentTypeChangedSpy(ti, &TextInputInterface::contentTypeChanged); | ||
616 | QVERIFY(contentTypeChangedSpy.isValid()); | 699 | QVERIFY(contentTypeChangedSpy.isValid()); | ||
617 | QFETCH(TextInput::ContentHints, clientHints); | 700 | QFETCH(TextInput::ContentHints, clientHints); | ||
618 | textInput->setContentType(clientHints, TextInput::ContentPurpose::Normal); | 701 | textInput->setContentType(clientHints, TextInput::ContentPurpose::Normal); | ||
702 | textInput->commit(); // only needed for v3 | ||||
619 | QVERIFY(contentTypeChangedSpy.wait()); | 703 | QVERIFY(contentTypeChangedSpy.wait()); | ||
620 | QTEST(ti->contentHints(), "serverHints"); | 704 | QTEST(ti->contentHints(), "serverHints"); | ||
621 | 705 | | |||
622 | // setting to same should not trigger an update | 706 | // setting to same should not trigger an update | ||
623 | textInput->setContentType(clientHints, TextInput::ContentPurpose::Normal); | 707 | textInput->setContentType(clientHints, TextInput::ContentPurpose::Normal); | ||
708 | textInput->commit(); | ||||
624 | QVERIFY(!contentTypeChangedSpy.wait(100)); | 709 | QVERIFY(!contentTypeChangedSpy.wait(100)); | ||
625 | 710 | | |||
626 | // unsetting should work | 711 | // unsetting should work | ||
627 | textInput->setContentType(TextInput::ContentHints(), TextInput::ContentPurpose::Normal); | 712 | textInput->setContentType(TextInput::ContentHints(), TextInput::ContentPurpose::Normal); | ||
713 | textInput->commit(); | ||||
628 | QVERIFY(contentTypeChangedSpy.wait()); | 714 | QVERIFY(contentTypeChangedSpy.wait()); | ||
629 | QCOMPARE(ti->contentHints(), TextInputInterface::ContentHints()); | 715 | QCOMPARE(ti->contentHints(), TextInputInterface::ContentHints()); | ||
630 | } | 716 | } | ||
631 | 717 | | |||
632 | void TextInputTest::testContentPurpose_data() | 718 | void TextInputTest::testContentPurpose_data() | ||
633 | { | 719 | { | ||
634 | QTest::addColumn<TextInputInterfaceVersion>("version"); | 720 | QTest::addColumn<TextInputInterfaceVersion>("version"); | ||
635 | QTest::addColumn<TextInput::ContentPurpose>("clientPurpose"); | 721 | QTest::addColumn<TextInput::ContentPurpose>("clientPurpose"); | ||
636 | QTest::addColumn<TextInputInterface::ContentPurpose>("serverPurpose"); | 722 | QTest::addColumn<TextInputInterface::ContentPurpose>("serverPurpose"); | ||
637 | 723 | | |||
638 | QTest::newRow("Alpha/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Alpha << TextInputInterface::ContentPurpose::Alpha; | 724 | QTest::newRow("Alpha/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Alpha << TextInputInterface::ContentPurpose::Alpha; | ||
639 | QTest::newRow("Digits/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Digits << TextInputInterface::ContentPurpose::Digits; | 725 | QTest::newRow("Digits/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Digits << TextInputInterface::ContentPurpose::Digits; | ||
640 | QTest::newRow("Number/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Number << TextInputInterface::ContentPurpose::Number; | 726 | QTest::newRow("Number/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Number << TextInputInterface::ContentPurpose::Number; | ||
641 | QTest::newRow("Phone/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Phone << TextInputInterface::ContentPurpose::Phone; | 727 | QTest::newRow("Phone/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Phone << TextInputInterface::ContentPurpose::Phone; | ||
642 | QTest::newRow("Url/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Url << TextInputInterface::ContentPurpose::Url; | 728 | QTest::newRow("Url/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Url << TextInputInterface::ContentPurpose::Url; | ||
643 | QTest::newRow("Email/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Email << TextInputInterface::ContentPurpose::Email; | 729 | QTest::newRow("Email/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Email << TextInputInterface::ContentPurpose::Email; | ||
644 | QTest::newRow("Name/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Name << TextInputInterface::ContentPurpose::Name; | 730 | QTest::newRow("Name/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Name << TextInputInterface::ContentPurpose::Name; | ||
645 | QTest::newRow("Password/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Password << TextInputInterface::ContentPurpose::Password; | 731 | QTest::newRow("Password/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Password << TextInputInterface::ContentPurpose::Password; | ||
732 | QTest::newRow("Pin/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Pin << TextInputInterface::ContentPurpose::Password; | ||||
646 | QTest::newRow("Date/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Date << TextInputInterface::ContentPurpose::Date; | 733 | QTest::newRow("Date/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Date << TextInputInterface::ContentPurpose::Date; | ||
647 | QTest::newRow("Time/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Time << TextInputInterface::ContentPurpose::Time; | 734 | QTest::newRow("Time/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Time << TextInputInterface::ContentPurpose::Time; | ||
648 | QTest::newRow("Datetime/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::DateTime << TextInputInterface::ContentPurpose::DateTime; | 735 | QTest::newRow("Datetime/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::DateTime << TextInputInterface::ContentPurpose::DateTime; | ||
649 | QTest::newRow("Terminal/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Terminal << TextInputInterface::ContentPurpose::Terminal; | 736 | QTest::newRow("Terminal/v0") << TextInputInterfaceVersion::UnstableV0 << TextInput::ContentPurpose::Terminal << TextInputInterface::ContentPurpose::Terminal; | ||
650 | 737 | | |||
651 | QTest::newRow("Alpha/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Alpha << TextInputInterface::ContentPurpose::Alpha; | 738 | QTest::newRow("Alpha/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Alpha << TextInputInterface::ContentPurpose::Alpha; | ||
652 | QTest::newRow("Digits/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Digits << TextInputInterface::ContentPurpose::Digits; | 739 | QTest::newRow("Digits/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Digits << TextInputInterface::ContentPurpose::Digits; | ||
653 | QTest::newRow("Number/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Number << TextInputInterface::ContentPurpose::Number; | 740 | QTest::newRow("Number/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Number << TextInputInterface::ContentPurpose::Number; | ||
654 | QTest::newRow("Phone/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Phone << TextInputInterface::ContentPurpose::Phone; | 741 | QTest::newRow("Phone/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Phone << TextInputInterface::ContentPurpose::Phone; | ||
655 | QTest::newRow("Url/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Url << TextInputInterface::ContentPurpose::Url; | 742 | QTest::newRow("Url/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Url << TextInputInterface::ContentPurpose::Url; | ||
656 | QTest::newRow("Email/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Email << TextInputInterface::ContentPurpose::Email; | 743 | QTest::newRow("Email/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Email << TextInputInterface::ContentPurpose::Email; | ||
657 | QTest::newRow("Name/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Name << TextInputInterface::ContentPurpose::Name; | 744 | QTest::newRow("Name/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Name << TextInputInterface::ContentPurpose::Name; | ||
658 | QTest::newRow("Password/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Password << TextInputInterface::ContentPurpose::Password; | 745 | QTest::newRow("Password/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Password << TextInputInterface::ContentPurpose::Password; | ||
746 | QTest::newRow("Pin/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Pin << TextInputInterface::ContentPurpose::Password; | ||||
659 | QTest::newRow("Date/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Date << TextInputInterface::ContentPurpose::Date; | 747 | QTest::newRow("Date/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Date << TextInputInterface::ContentPurpose::Date; | ||
660 | QTest::newRow("Time/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Time << TextInputInterface::ContentPurpose::Time; | 748 | QTest::newRow("Time/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Time << TextInputInterface::ContentPurpose::Time; | ||
661 | QTest::newRow("Datetime/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::DateTime << TextInputInterface::ContentPurpose::DateTime; | 749 | QTest::newRow("Datetime/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::DateTime << TextInputInterface::ContentPurpose::DateTime; | ||
662 | QTest::newRow("Terminal/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Terminal << TextInputInterface::ContentPurpose::Terminal; | 750 | QTest::newRow("Terminal/v2") << TextInputInterfaceVersion::UnstableV2 << TextInput::ContentPurpose::Terminal << TextInputInterface::ContentPurpose::Terminal; | ||
751 | | ||||
752 | QTest::newRow("Alpha/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::Alpha << TextInputInterface::ContentPurpose::Alpha; | ||||
753 | QTest::newRow("Digits/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::Digits << TextInputInterface::ContentPurpose::Digits; | ||||
754 | QTest::newRow("Number/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::Number << TextInputInterface::ContentPurpose::Number; | ||||
755 | QTest::newRow("Phone/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::Phone << TextInputInterface::ContentPurpose::Phone; | ||||
756 | QTest::newRow("Url/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::Url << TextInputInterface::ContentPurpose::Url; | ||||
757 | QTest::newRow("Email/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::Email << TextInputInterface::ContentPurpose::Email; | ||||
758 | QTest::newRow("Name/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::Name << TextInputInterface::ContentPurpose::Name; | ||||
759 | QTest::newRow("Password/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::Password << TextInputInterface::ContentPurpose::Password; | ||||
760 | QTest::newRow("Pin/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::Pin << TextInputInterface::ContentPurpose::Pin; | ||||
761 | QTest::newRow("Date/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::Date << TextInputInterface::ContentPurpose::Date; | ||||
762 | QTest::newRow("Time/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::Time << TextInputInterface::ContentPurpose::Time; | ||||
763 | QTest::newRow("Datetime/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::DateTime << TextInputInterface::ContentPurpose::DateTime; | ||||
764 | QTest::newRow("Terminal/v3") << TextInputInterfaceVersion::UnstableV3 << TextInput::ContentPurpose::Terminal << TextInputInterface::ContentPurpose::Terminal; | ||||
663 | } | 765 | } | ||
664 | 766 | | |||
665 | void TextInputTest::testContentPurpose() | 767 | void TextInputTest::testContentPurpose() | ||
666 | { | 768 | { | ||
667 | // this test verifies that content purpose are properly passed from client to server | 769 | // this test verifies that content purpose are properly passed from client to server | ||
668 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 770 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||
669 | auto serverSurface = waitForSurface(); | 771 | auto serverSurface = waitForSurface(); | ||
670 | QVERIFY(serverSurface); | 772 | QVERIFY(serverSurface); | ||
671 | QFETCH(TextInputInterfaceVersion, version); | 773 | QFETCH(TextInputInterfaceVersion, version); | ||
672 | QScopedPointer<TextInput> textInput(createTextInput(version)); | 774 | QScopedPointer<TextInput> textInput(createTextInput(version)); | ||
673 | QVERIFY(!textInput.isNull()); | 775 | QVERIFY(!textInput.isNull()); | ||
674 | textInput->enable(surface.data()); | 776 | textInput->enable(surface.data()); | ||
675 | m_connection->flush(); | 777 | m_connection->flush(); | ||
676 | m_display->dispatchEvents(); | 778 | m_display->dispatchEvents(); | ||
677 | 779 | | |||
678 | m_seatInterface->setFocusedKeyboardSurface(serverSurface); | 780 | m_seatInterface->setFocusedKeyboardSurface(serverSurface); | ||
679 | auto ti = m_seatInterface->focusedTextInput(); | 781 | auto ti = m_seatInterface->focusedTextInput(); | ||
680 | QVERIFY(ti); | 782 | QVERIFY(ti); | ||
681 | QCOMPARE(ti->contentPurpose(), TextInputInterface::ContentPurpose::Normal); | 783 | QCOMPARE(ti->contentPurpose(), TextInputInterface::ContentPurpose::Normal); | ||
682 | 784 | | |||
683 | QSignalSpy contentTypeChangedSpy(ti, &TextInputInterface::contentTypeChanged); | 785 | QSignalSpy contentTypeChangedSpy(ti, &TextInputInterface::contentTypeChanged); | ||
684 | QVERIFY(contentTypeChangedSpy.isValid()); | 786 | QVERIFY(contentTypeChangedSpy.isValid()); | ||
685 | QFETCH(TextInput::ContentPurpose, clientPurpose); | 787 | QFETCH(TextInput::ContentPurpose, clientPurpose); | ||
686 | textInput->setContentType(TextInput::ContentHints(), clientPurpose); | 788 | textInput->setContentType(TextInput::ContentHints(), clientPurpose); | ||
789 | textInput->commit(); | ||||
687 | QVERIFY(contentTypeChangedSpy.wait()); | 790 | QVERIFY(contentTypeChangedSpy.wait()); | ||
688 | QTEST(ti->contentPurpose(), "serverPurpose"); | 791 | QTEST(ti->contentPurpose(), "serverPurpose"); | ||
689 | 792 | | |||
690 | // setting to same should not trigger an update | 793 | // setting to same should not trigger an update | ||
691 | textInput->setContentType(TextInput::ContentHints(), clientPurpose); | 794 | textInput->setContentType(TextInput::ContentHints(), clientPurpose); | ||
795 | textInput->commit(); | ||||
692 | QVERIFY(!contentTypeChangedSpy.wait(100)); | 796 | QVERIFY(!contentTypeChangedSpy.wait(100)); | ||
693 | 797 | | |||
694 | // unsetting should work | 798 | // unsetting should work | ||
695 | textInput->setContentType(TextInput::ContentHints(), TextInput::ContentPurpose::Normal); | 799 | textInput->setContentType(TextInput::ContentHints(), TextInput::ContentPurpose::Normal); | ||
800 | textInput->commit(); | ||||
696 | QVERIFY(contentTypeChangedSpy.wait()); | 801 | QVERIFY(contentTypeChangedSpy.wait()); | ||
697 | QCOMPARE(ti->contentPurpose(), TextInputInterface::ContentPurpose::Normal); | 802 | QCOMPARE(ti->contentPurpose(), TextInputInterface::ContentPurpose::Normal); | ||
698 | } | 803 | } | ||
699 | 804 | | |||
700 | void TextInputTest::testTextDirection_data() | 805 | void TextInputTest::testTextDirection_data() | ||
701 | { | 806 | { | ||
702 | QTest::addColumn<TextInputInterfaceVersion>("version"); | 807 | QTest::addColumn<TextInputInterfaceVersion>("version"); | ||
703 | QTest::addColumn<Qt::LayoutDirection>("textDirection"); | 808 | QTest::addColumn<Qt::LayoutDirection>("textDirection"); | ||
704 | 809 | | |||
705 | QTest::newRow("ltr/v0") << TextInputInterfaceVersion::UnstableV0 << Qt::LeftToRight; | 810 | QTest::newRow("ltr/v0") << TextInputInterfaceVersion::UnstableV0 << Qt::LeftToRight; | ||
706 | QTest::newRow("rtl/v0") << TextInputInterfaceVersion::UnstableV0 << Qt::RightToLeft; | 811 | QTest::newRow("rtl/v0") << TextInputInterfaceVersion::UnstableV0 << Qt::RightToLeft; | ||
707 | 812 | | |||
708 | QTest::newRow("ltr/v2") << TextInputInterfaceVersion::UnstableV2 << Qt::LeftToRight; | 813 | QTest::newRow("ltr/v2") << TextInputInterfaceVersion::UnstableV2 << Qt::LeftToRight; | ||
709 | QTest::newRow("rtl/v2") << TextInputInterfaceVersion::UnstableV2 << Qt::RightToLeft; | 814 | QTest::newRow("rtl/v2") << TextInputInterfaceVersion::UnstableV2 << Qt::RightToLeft; | ||
815 | | ||||
816 | // v3 does not support this anymore | ||||
710 | } | 817 | } | ||
711 | 818 | | |||
712 | void TextInputTest::testTextDirection() | 819 | void TextInputTest::testTextDirection() | ||
713 | { | 820 | { | ||
714 | // this test verifies that the text direction is sent from server to client | 821 | // this test verifies that the text direction is sent from server to client | ||
715 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 822 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||
716 | auto serverSurface = waitForSurface(); | 823 | auto serverSurface = waitForSurface(); | ||
717 | QVERIFY(serverSurface); | 824 | QVERIFY(serverSurface); | ||
Show All 28 Lines | |||||
746 | } | 853 | } | ||
747 | 854 | | |||
748 | void TextInputTest::testLanguage_data() | 855 | void TextInputTest::testLanguage_data() | ||
749 | { | 856 | { | ||
750 | QTest::addColumn<TextInputInterfaceVersion>("version"); | 857 | QTest::addColumn<TextInputInterfaceVersion>("version"); | ||
751 | 858 | | |||
752 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | 859 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | ||
753 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | 860 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | ||
861 | // v3 does not support this anymore | ||||
754 | } | 862 | } | ||
755 | 863 | | |||
756 | void TextInputTest::testLanguage() | 864 | void TextInputTest::testLanguage() | ||
757 | { | 865 | { | ||
758 | // this test verifies that language is sent from server to client | 866 | // this test verifies that language is sent from server to client | ||
759 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 867 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||
760 | auto serverSurface = waitForSurface(); | 868 | auto serverSurface = waitForSurface(); | ||
761 | QVERIFY(serverSurface); | 869 | QVERIFY(serverSurface); | ||
Show All 26 Lines | |||||
788 | } | 896 | } | ||
789 | 897 | | |||
790 | void TextInputTest::testKeyEvent_data() | 898 | void TextInputTest::testKeyEvent_data() | ||
791 | { | 899 | { | ||
792 | QTest::addColumn<TextInputInterfaceVersion>("version"); | 900 | QTest::addColumn<TextInputInterfaceVersion>("version"); | ||
793 | 901 | | |||
794 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | 902 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | ||
795 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | 903 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | ||
904 | // v3 does not support this anymore | ||||
796 | } | 905 | } | ||
797 | 906 | | |||
798 | void TextInputTest::testKeyEvent() | 907 | void TextInputTest::testKeyEvent() | ||
799 | { | 908 | { | ||
800 | qRegisterMetaType<Qt::KeyboardModifiers>(); | 909 | qRegisterMetaType<Qt::KeyboardModifiers>(); | ||
801 | qRegisterMetaType<TextInput::KeyState>(); | 910 | qRegisterMetaType<TextInput::KeyState>(); | ||
802 | // this test verifies that key events are properly sent to the client | 911 | // this test verifies that key events are properly sent to the client | ||
803 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 912 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 956 | { | |||
880 | ti->preEdit(QByteArrayLiteral("foobar"), QByteArray()); | 989 | ti->preEdit(QByteArrayLiteral("foobar"), QByteArray()); | ||
881 | QVERIFY(composingTextChangedSpy.wait()); | 990 | QVERIFY(composingTextChangedSpy.wait()); | ||
882 | QCOMPARE(composingTextChangedSpy.count(), 2); | 991 | QCOMPARE(composingTextChangedSpy.count(), 2); | ||
883 | QCOMPARE(textInput->composingText(), QByteArrayLiteral("foobar")); | 992 | QCOMPARE(textInput->composingText(), QByteArrayLiteral("foobar")); | ||
884 | QCOMPARE(textInput->composingFallbackText(), QByteArray()); | 993 | QCOMPARE(textInput->composingFallbackText(), QByteArray()); | ||
885 | QCOMPARE(textInput->composingTextCursorPosition(), 6); | 994 | QCOMPARE(textInput->composingTextCursorPosition(), 6); | ||
886 | } | 995 | } | ||
887 | 996 | | |||
888 | void TextInputTest::testCommit_data() | 997 | void TextInputTest::testPreEditv3_data() | ||
889 | { | 998 | { | ||
890 | QTest::addColumn<TextInputInterfaceVersion>("version"); | 999 | QTest::addColumn<TextInputInterfaceVersion>("version"); | ||
891 | 1000 | | |||
892 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0; | 1001 | QTest::newRow("UnstableV3") << TextInputInterfaceVersion::UnstableV3; | ||
zzag: If there is only one row, we don't need _data(). | |||||
893 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2; | 1002 | } | ||
1003 | | ||||
1004 | void TextInputTest::testPreEditv3() | ||||
1005 | { | ||||
1006 | // this test verifies that pre-edit is correctly passed to the client | ||||
1007 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||||
1008 | auto serverSurface = waitForSurface(); | ||||
1009 | QVERIFY(serverSurface); | ||||
1010 | QFETCH(TextInputInterfaceVersion, version); | ||||
1011 | QScopedPointer<TextInput> textInput(createTextInput(version)); | ||||
1012 | QVERIFY(!textInput.isNull()); | ||||
1013 | // verify default values | ||||
1014 | QVERIFY(textInput->composingText().isEmpty()); | ||||
1015 | QVERIFY(textInput->composingFallbackText().isEmpty()); | ||||
1016 | QCOMPARE(textInput->composingTextCursorPosition(), 0); | ||||
1017 | | ||||
1018 | textInput->enable(surface.data()); | ||||
1019 | textInput->commit(); | ||||
1020 | m_connection->flush(); | ||||
1021 | m_display->dispatchEvents(); | ||||
1022 | | ||||
1023 | m_seatInterface->setFocusedKeyboardSurface(serverSurface); | ||||
1024 | auto ti = m_seatInterface->focusedTextInput(); | ||||
1025 | QVERIFY(ti); | ||||
1026 | | ||||
1027 | // now let's pass through some pre-edit events | ||||
1028 | QSignalSpy composingTextChangedSpy(textInput.data(), &TextInput::composingTextChanged); | ||||
1029 | QVERIFY(composingTextChangedSpy.isValid()); | ||||
1030 | ti->preEdit(QByteArrayLiteral("foo"), QByteArrayLiteral("bar")); | ||||
1031 | ti->done(); | ||||
1032 | | ||||
1033 | QVERIFY(composingTextChangedSpy.wait()); | ||||
1034 | QCOMPARE(composingTextChangedSpy.count(), 1); | ||||
1035 | QCOMPARE(textInput->composingText(), QByteArrayLiteral("foo")); | ||||
1036 | QCOMPARE(textInput->composingFallbackText(), QByteArray()); | ||||
1037 | QCOMPARE(textInput->composingTextCursorPosition(), 0); | ||||
1038 | | ||||
1039 | ti->preEdit(QByteArrayLiteral("foobar"), QByteArray()); | ||||
1040 | ti->done(); | ||||
1041 | QVERIFY(composingTextChangedSpy.wait()); | ||||
1042 | QCOMPARE(composingTextChangedSpy.count(), 2); | ||||
1043 | QCOMPARE(textInput->composingText(), QByteArrayLiteral("foobar")); | ||||
1044 | QCOMPARE(textInput->composingFallbackText(), QByteArray()); | ||||
1045 | QCOMPARE(textInput->composingTextCursorPosition(), 0); | ||||
1046 | | ||||
1047 | ti->setPreEditCursor(1); | ||||
1048 | // no change yet | ||||
1049 | QVERIFY(!composingTextChangedSpy.wait(500)); | ||||
1050 | QCOMPARE(composingTextChangedSpy.count(), 2); | ||||
1051 | QCOMPARE(textInput->composingText(), QByteArrayLiteral("foobar")); | ||||
1052 | QCOMPARE(textInput->composingFallbackText(), QByteArray()); | ||||
1053 | QCOMPARE(textInput->composingTextCursorPosition(), 0); | ||||
1054 | ti->done(); | ||||
1055 | QVERIFY(composingTextChangedSpy.wait()); | ||||
1056 | QCOMPARE(composingTextChangedSpy.count(), 3); | ||||
1057 | QCOMPARE(textInput->composingText(), QByteArrayLiteral("foobar")); | ||||
1058 | QCOMPARE(textInput->composingFallbackText(), QByteArray()); | ||||
1059 | QCOMPARE(textInput->composingTextCursorPosition(), 1); | ||||
1060 | } | ||||
1061 | | ||||
1062 | void TextInputTest::testCommit_data() | ||||
1063 | { | ||||
1064 | QTest::addColumn<TextInputInterfaceVersion>("version"); | ||||
1065 | QTest::addColumn<bool>("clientCommits"); | ||||
1066 | QTest::addColumn<bool>("serverDone"); | ||||
1067 | QTest::addColumn<bool>("setsCursor"); | ||||
1068 | | ||||
1069 | QTest::newRow("UnstableV0") << TextInputInterfaceVersion::UnstableV0 << false << false << true; | ||||
1070 | QTest::newRow("UnstableV2") << TextInputInterfaceVersion::UnstableV2 << false << false << true; | ||||
1071 | QTest::newRow("UnstableV3") << TextInputInterfaceVersion::UnstableV3 << true << true << false; | ||||
894 | } | 1072 | } | ||
895 | 1073 | | |||
896 | void TextInputTest::testCommit() | 1074 | void TextInputTest::testCommit() | ||
897 | { | 1075 | { | ||
898 | // this test verifies that the commit is handled correctly by the client | 1076 | // this test verifies that the commit is handled correctly by the client | ||
899 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | 1077 | QScopedPointer<Surface> surface(m_compositor->createSurface()); | ||
900 | auto serverSurface = waitForSurface(); | 1078 | auto serverSurface = waitForSurface(); | ||
901 | QVERIFY(serverSurface); | 1079 | QVERIFY(serverSurface); | ||
902 | QFETCH(TextInputInterfaceVersion, version); | 1080 | QFETCH(TextInputInterfaceVersion, version); | ||
903 | QScopedPointer<TextInput> textInput(createTextInput(version)); | 1081 | QScopedPointer<TextInput> textInput(createTextInput(version)); | ||
904 | QVERIFY(!textInput.isNull()); | 1082 | QVERIFY(!textInput.isNull()); | ||
905 | // verify default values | 1083 | // verify default values | ||
906 | QCOMPARE(textInput->commitText(), QByteArray()); | 1084 | QCOMPARE(textInput->commitText(), QByteArray()); | ||
907 | QCOMPARE(textInput->cursorPosition(), 0); | 1085 | QCOMPARE(textInput->cursorPosition(), 0); | ||
908 | QCOMPARE(textInput->anchorPosition(), 0); | 1086 | QCOMPARE(textInput->anchorPosition(), 0); | ||
909 | QCOMPARE(textInput->deleteSurroundingText().beforeLength, 0u); | 1087 | QCOMPARE(textInput->deleteSurroundingText().beforeLength, 0u); | ||
910 | QCOMPARE(textInput->deleteSurroundingText().afterLength, 0u); | 1088 | QCOMPARE(textInput->deleteSurroundingText().afterLength, 0u); | ||
911 | 1089 | | |||
1090 | QFETCH(bool, clientCommits); | ||||
1091 | QFETCH(bool, serverDone); | ||||
1092 | QFETCH(bool, setsCursor); | ||||
1093 | | ||||
912 | textInput->enable(surface.data()); | 1094 | textInput->enable(surface.data()); | ||
1095 | if (clientCommits) { | ||||
1096 | textInput->commit(); | ||||
1097 | } | ||||
913 | m_connection->flush(); | 1098 | m_connection->flush(); | ||
914 | m_display->dispatchEvents(); | 1099 | m_display->dispatchEvents(); | ||
915 | 1100 | | |||
916 | m_seatInterface->setFocusedKeyboardSurface(serverSurface); | 1101 | m_seatInterface->setFocusedKeyboardSurface(serverSurface); | ||
917 | auto ti = m_seatInterface->focusedTextInput(); | 1102 | auto ti = m_seatInterface->focusedTextInput(); | ||
918 | QVERIFY(ti); | 1103 | QVERIFY(ti); | ||
919 | 1104 | | |||
920 | // now let's commit | 1105 | // now let's commit | ||
921 | QSignalSpy committedSpy(textInput.data(), &TextInput::committed); | 1106 | QSignalSpy committedSpy(textInput.data(), &TextInput::committed); | ||
922 | QVERIFY(committedSpy.isValid()); | 1107 | QVERIFY(committedSpy.isValid()); | ||
923 | ti->setCursorPosition(3, 4); | 1108 | ti->setCursorPosition(3, 4); | ||
924 | ti->deleteSurroundingText(2, 1); | 1109 | ti->deleteSurroundingText(2, 1); | ||
925 | ti->commit(QByteArrayLiteral("foo")); | 1110 | ti->commit(QByteArrayLiteral("foo")); | ||
1111 | if (serverDone) { | ||||
1112 | ti->done(); | ||||
1113 | } | ||||
926 | 1114 | | |||
927 | QVERIFY(committedSpy.wait()); | 1115 | QVERIFY(committedSpy.wait()); | ||
928 | QCOMPARE(textInput->commitText(), QByteArrayLiteral("foo")); | 1116 | QCOMPARE(textInput->commitText(), QByteArrayLiteral("foo")); | ||
929 | QCOMPARE(textInput->cursorPosition(), 3); | 1117 | QCOMPARE(textInput->cursorPosition(), setsCursor ? 3 : 0); | ||
930 | QCOMPARE(textInput->anchorPosition(), 4); | 1118 | QCOMPARE(textInput->anchorPosition(), setsCursor ? 4 : 0); | ||
931 | QCOMPARE(textInput->deleteSurroundingText().beforeLength, 2u); | 1119 | QCOMPARE(textInput->deleteSurroundingText().beforeLength, 2u); | ||
932 | QCOMPARE(textInput->deleteSurroundingText().afterLength, 1u); | 1120 | QCOMPARE(textInput->deleteSurroundingText().afterLength, 1u); | ||
933 | } | 1121 | } | ||
934 | 1122 | | |||
935 | QTEST_GUILESS_MAIN(TextInputTest) | 1123 | QTEST_GUILESS_MAIN(TextInputTest) | ||
936 | #include "test_text_input.moc" | 1124 | #include "test_text_input.moc" |
Personal opinion: tests have to be easy to follow, it's okay if we copy some code. I'd prefer to have a specialized test, e.g. testSurroundingTextV3.