Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/debug_console_test.cpp
Show All 21 Lines | |||||
22 | #include "debug_console.h" | 22 | #include "debug_console.h" | ||
23 | #include "screens.h" | 23 | #include "screens.h" | ||
24 | #include "shell_client.h" | 24 | #include "shell_client.h" | ||
25 | #include "wayland_server.h" | 25 | #include "wayland_server.h" | ||
26 | #include "xcbutils.h" | 26 | #include "xcbutils.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> | 31 | #include <KWayland/Client/shm_pool.h> | ||
34 | #include <KWayland/Client/surface.h> | 32 | #include <KWayland/Client/surface.h> | ||
35 | 33 | | |||
36 | #include <QPainter> | 34 | #include <QPainter> | ||
37 | #include <QRasterWindow> | 35 | #include <QRasterWindow> | ||
38 | 36 | | |||
39 | namespace KWin | 37 | namespace KWin | ||
40 | { | 38 | { | ||
41 | 39 | | |||
42 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_debug_console-0"); | 40 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_debug_console-0"); | ||
43 | 41 | | |||
44 | class DebugConsoleTest : public QObject | 42 | class DebugConsoleTest : public QObject | ||
45 | { | 43 | { | ||
46 | Q_OBJECT | 44 | Q_OBJECT | ||
47 | private Q_SLOTS: | 45 | private Q_SLOTS: | ||
48 | void initTestCase(); | 46 | void initTestCase(); | ||
47 | void cleanup(); | ||||
49 | void topLevelTest_data(); | 48 | void topLevelTest_data(); | ||
50 | void topLevelTest(); | 49 | void topLevelTest(); | ||
51 | void testX11Client(); | 50 | void testX11Client(); | ||
52 | void testX11Unmanaged(); | 51 | void testX11Unmanaged(); | ||
53 | void testWaylandClient(); | 52 | void testWaylandClient(); | ||
54 | void testInternalWindow(); | 53 | void testInternalWindow(); | ||
55 | }; | 54 | }; | ||
56 | 55 | | |||
Show All 11 Lines | 57 | { | |||
68 | QVERIFY(workspaceCreatedSpy.wait()); | 67 | QVERIFY(workspaceCreatedSpy.wait()); | ||
69 | QCOMPARE(screens()->count(), 2); | 68 | QCOMPARE(screens()->count(), 2); | ||
70 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | 69 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | ||
71 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | 70 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | ||
72 | setenv("QT_QPA_PLATFORM", "wayland", true); | 71 | setenv("QT_QPA_PLATFORM", "wayland", true); | ||
73 | waylandServer()->initWorkspace(); | 72 | waylandServer()->initWorkspace(); | ||
74 | } | 73 | } | ||
75 | 74 | | |||
75 | void DebugConsoleTest::cleanup() | ||||
76 | { | ||||
77 | Test::destroyWaylandConnection(); | ||||
78 | } | ||||
79 | | ||||
76 | void DebugConsoleTest::topLevelTest_data() | 80 | void DebugConsoleTest::topLevelTest_data() | ||
77 | { | 81 | { | ||
78 | QTest::addColumn<int>("row"); | 82 | QTest::addColumn<int>("row"); | ||
79 | QTest::addColumn<int>("column"); | 83 | QTest::addColumn<int>("column"); | ||
80 | QTest::addColumn<bool>("expectedValid"); | 84 | QTest::addColumn<bool>("expectedValid"); | ||
81 | 85 | | |||
82 | // this tests various combinations of row/column on the top level whether they are valid | 86 | // this tests various combinations of row/column on the top level whether they are valid | ||
83 | // valid are rows 0-4 with column 0, everything else is invalid | 87 | // valid are rows 0-4 with column 0, everything else is invalid | ||
▲ Show 20 Lines • Show All 219 Lines • ▼ Show 20 Line(s) | 296 | { | |||
303 | QVERIFY(!model.index(0, 2, waylandTopLevelIndex).isValid()); | 307 | QVERIFY(!model.index(0, 2, waylandTopLevelIndex).isValid()); | ||
304 | QVERIFY(!model.index(1, 0, waylandTopLevelIndex).isValid()); | 308 | QVERIFY(!model.index(1, 0, waylandTopLevelIndex).isValid()); | ||
305 | 309 | | |||
306 | // we need to create a wayland window | 310 | // we need to create a wayland window | ||
307 | QSignalSpy rowsInsertedSpy(&model, &QAbstractItemModel::rowsInserted); | 311 | QSignalSpy rowsInsertedSpy(&model, &QAbstractItemModel::rowsInserted); | ||
308 | QVERIFY(rowsInsertedSpy.isValid()); | 312 | QVERIFY(rowsInsertedSpy.isValid()); | ||
309 | 313 | | |||
310 | // create our connection | 314 | // create our connection | ||
311 | using namespace KWayland::Client; | 315 | QVERIFY(Test::setupWaylandConnection(s_socketName)); | ||
312 | // setup connection | | |||
313 | QScopedPointer<ConnectionThread> connection(new ConnectionThread); | | |||
314 | QSignalSpy connectedSpy(connection.data(), &ConnectionThread::connected); | | |||
315 | QVERIFY(connectedSpy.isValid()); | | |||
316 | connection->setSocketName(s_socketName); | | |||
317 | | ||||
318 | QScopedPointer<QThread> thread(new QThread); | | |||
319 | connection->moveToThread(thread.data()); | | |||
320 | thread->start(); | | |||
321 | | ||||
322 | connection->initConnection(); | | |||
323 | QVERIFY(connectedSpy.wait()); | | |||
324 | | ||||
325 | QScopedPointer<EventQueue> queue(new EventQueue); | | |||
326 | QVERIFY(!queue->isValid()); | | |||
327 | queue->setup(connection.data()); | | |||
328 | QVERIFY(queue->isValid()); | | |||
329 | | ||||
330 | Registry registry; | | |||
331 | registry.setEventQueue(queue.data()); | | |||
332 | QSignalSpy interfacesAnnouncedSpy(®istry, &Registry::interfacesAnnounced); | | |||
333 | QVERIFY(interfacesAnnouncedSpy.isValid()); | | |||
334 | registry.create(connection.data()); | | |||
335 | QVERIFY(registry.isValid()); | | |||
336 | registry.setup(); | | |||
337 | QVERIFY(interfacesAnnouncedSpy.wait()); | | |||
338 | | ||||
339 | QScopedPointer<Compositor> compositor(registry.createCompositor(registry.interface(Registry::Interface::Compositor).name, registry.interface(Registry::Interface::Compositor).version)); | | |||
340 | QVERIFY(compositor->isValid()); | | |||
341 | QScopedPointer<ShmPool> shm(registry.createShmPool(registry.interface(Registry::Interface::Shm).name, registry.interface(Registry::Interface::Shm).version)); | | |||
342 | QVERIFY(shm->isValid()); | | |||
343 | QScopedPointer<Shell> shell(registry.createShell(registry.interface(Registry::Interface::Shell).name, registry.interface(Registry::Interface::Shell).version)); | | |||
344 | QVERIFY(shell->isValid()); | | |||
345 | 316 | | |||
346 | // create the Surface and ShellSurface | 317 | // create the Surface and ShellSurface | ||
347 | QScopedPointer<Surface> surface(compositor->createSurface()); | 318 | using namespace KWayland::Client; | ||
319 | QScopedPointer<Surface> surface(Test::createSurface()); | ||||
348 | QVERIFY(surface->isValid()); | 320 | QVERIFY(surface->isValid()); | ||
349 | QScopedPointer<ShellSurface> shellSurface(shell->createSurface(surface.data())); | 321 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | ||
350 | QVERIFY(shellSurface->isValid()); | 322 | QVERIFY(shellSurface->isValid()); | ||
351 | QImage img(10, 10, QImage::Format_ARGB32); | 323 | Test::render(surface.data(), QSize(10, 10), Qt::red); | ||
352 | img.fill(Qt::red); | | |||
353 | surface->attachBuffer(shm->createBuffer(img)); | | |||
354 | surface->damage(QRect(0, 0, 10, 10)); | | |||
355 | surface->commit(Surface::CommitFlag::None); | | |||
356 | 324 | | |||
357 | // now we have the window, it should be added to our model | 325 | // now we have the window, it should be added to our model | ||
358 | QVERIFY(rowsInsertedSpy.wait()); | 326 | QVERIFY(rowsInsertedSpy.wait()); | ||
359 | QCOMPARE(rowsInsertedSpy.count(), 1); | 327 | QCOMPARE(rowsInsertedSpy.count(), 1); | ||
360 | 328 | | |||
361 | QVERIFY(model.hasChildren(waylandTopLevelIndex)); | 329 | QVERIFY(model.hasChildren(waylandTopLevelIndex)); | ||
362 | QCOMPARE(model.rowCount(waylandTopLevelIndex), 1); | 330 | QCOMPARE(model.rowCount(waylandTopLevelIndex), 1); | ||
363 | QCOMPARE(rowsInsertedSpy.first().at(0).value<QModelIndex>(), waylandTopLevelIndex); | 331 | QCOMPARE(rowsInsertedSpy.first().at(0).value<QModelIndex>(), waylandTopLevelIndex); | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
405 | 373 | | |||
406 | // now close the window again, it should be removed from the model | 374 | // now close the window again, it should be removed from the model | ||
407 | QSignalSpy rowsRemovedSpy(&model, &QAbstractItemModel::rowsRemoved); | 375 | QSignalSpy rowsRemovedSpy(&model, &QAbstractItemModel::rowsRemoved); | ||
408 | QVERIFY(rowsRemovedSpy.isValid()); | 376 | QVERIFY(rowsRemovedSpy.isValid()); | ||
409 | 377 | | |||
410 | surface->attachBuffer(Buffer::Ptr()); | 378 | surface->attachBuffer(Buffer::Ptr()); | ||
411 | surface->commit(Surface::CommitFlag::None); | 379 | surface->commit(Surface::CommitFlag::None); | ||
412 | shellSurface.reset(); | 380 | shellSurface.reset(); | ||
413 | connection->flush(); | 381 | Test::flushWaylandConnection(); | ||
414 | qDebug() << rowsRemovedSpy.count(); | 382 | qDebug() << rowsRemovedSpy.count(); | ||
415 | QEXPECT_FAIL("", "Deleting a ShellSurface does not result in the server removing the ShellClient", Continue); | 383 | QEXPECT_FAIL("", "Deleting a ShellSurface does not result in the server removing the ShellClient", Continue); | ||
416 | QVERIFY(rowsRemovedSpy.wait()); | 384 | QVERIFY(rowsRemovedSpy.wait()); | ||
417 | // also destroy the connection to ensure the ShellSurface goes away | | |||
418 | surface.reset(); | 385 | surface.reset(); | ||
419 | shell.reset(); | | |||
420 | shm.reset(); | | |||
421 | compositor.reset(); | | |||
422 | connection.take()->deleteLater(); | | |||
423 | thread->quit(); | | |||
424 | QVERIFY(thread->wait()); | | |||
425 | 386 | | |||
426 | QVERIFY(rowsRemovedSpy.wait()); | 387 | QVERIFY(rowsRemovedSpy.wait()); | ||
427 | QCOMPARE(rowsRemovedSpy.count(), 1); | 388 | QCOMPARE(rowsRemovedSpy.count(), 1); | ||
428 | QCOMPARE(rowsRemovedSpy.first().first().value<QModelIndex>(), waylandTopLevelIndex); | 389 | QCOMPARE(rowsRemovedSpy.first().first().value<QModelIndex>(), waylandTopLevelIndex); | ||
429 | QCOMPARE(rowsRemovedSpy.first().at(1).value<int>(), 0); | 390 | QCOMPARE(rowsRemovedSpy.first().at(1).value<int>(), 0); | ||
430 | QCOMPARE(rowsRemovedSpy.first().at(2).value<int>(), 0); | 391 | QCOMPARE(rowsRemovedSpy.first().at(2).value<int>(), 0); | ||
431 | 392 | | |||
432 | // the child should be gone again | 393 | // the child should be gone again | ||
▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines |