diff --git a/autotests/integration/CMakeLists.txt b/autotests/integration/CMakeLists.txt --- a/autotests/integration/CMakeLists.txt +++ b/autotests/integration/CMakeLists.txt @@ -2,7 +2,7 @@ add_definitions(-DKWINQPAPATH="${CMAKE_BINARY_DIR}/plugins/qpa/") add_subdirectory(helper) -add_library(KWinIntegrationTestFramework STATIC kwin_wayland_test.cpp) +add_library(KWinIntegrationTestFramework STATIC kwin_wayland_test.cpp test_helpers.cpp) target_link_libraries(KWinIntegrationTestFramework kwin Qt5::Test) function(integrationTest) diff --git a/autotests/integration/debug_console_test.cpp b/autotests/integration/debug_console_test.cpp --- a/autotests/integration/debug_console_test.cpp +++ b/autotests/integration/debug_console_test.cpp @@ -27,8 +27,6 @@ #include #include -#include -#include #include #include #include @@ -46,6 +44,7 @@ Q_OBJECT private Q_SLOTS: void initTestCase(); + void cleanup(); void topLevelTest_data(); void topLevelTest(); void testX11Client(); @@ -73,6 +72,11 @@ waylandServer()->initWorkspace(); } +void DebugConsoleTest::cleanup() +{ + Test::destroyWaylandConnection(); +} + void DebugConsoleTest::topLevelTest_data() { QTest::addColumn("row"); @@ -308,51 +312,15 @@ QVERIFY(rowsInsertedSpy.isValid()); // create our connection - using namespace KWayland::Client; - // setup connection - QScopedPointer connection(new ConnectionThread); - QSignalSpy connectedSpy(connection.data(), &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - connection->setSocketName(s_socketName); - - QScopedPointer thread(new QThread); - connection->moveToThread(thread.data()); - thread->start(); - - connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - QScopedPointer queue(new EventQueue); - QVERIFY(!queue->isValid()); - queue->setup(connection.data()); - QVERIFY(queue->isValid()); - - Registry registry; - registry.setEventQueue(queue.data()); - QSignalSpy interfacesAnnouncedSpy(®istry, &Registry::interfacesAnnounced); - QVERIFY(interfacesAnnouncedSpy.isValid()); - registry.create(connection.data()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(interfacesAnnouncedSpy.wait()); - - QScopedPointer compositor(registry.createCompositor(registry.interface(Registry::Interface::Compositor).name, registry.interface(Registry::Interface::Compositor).version)); - QVERIFY(compositor->isValid()); - QScopedPointer shm(registry.createShmPool(registry.interface(Registry::Interface::Shm).name, registry.interface(Registry::Interface::Shm).version)); - QVERIFY(shm->isValid()); - QScopedPointer shell(registry.createShell(registry.interface(Registry::Interface::Shell).name, registry.interface(Registry::Interface::Shell).version)); - QVERIFY(shell->isValid()); + QVERIFY(Test::setupWaylandConnection(s_socketName)); // create the Surface and ShellSurface - QScopedPointer surface(compositor->createSurface()); + using namespace KWayland::Client; + QScopedPointer surface(Test::createSurface()); QVERIFY(surface->isValid()); - QScopedPointer shellSurface(shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(shellSurface->isValid()); - QImage img(10, 10, QImage::Format_ARGB32); - img.fill(Qt::red); - surface->attachBuffer(shm->createBuffer(img)); - surface->damage(QRect(0, 0, 10, 10)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(10, 10), Qt::red); // now we have the window, it should be added to our model QVERIFY(rowsInsertedSpy.wait()); @@ -410,18 +378,11 @@ surface->attachBuffer(Buffer::Ptr()); surface->commit(Surface::CommitFlag::None); shellSurface.reset(); - connection->flush(); + Test::flushWaylandConnection(); qDebug() << rowsRemovedSpy.count(); QEXPECT_FAIL("", "Deleting a ShellSurface does not result in the server removing the ShellClient", Continue); QVERIFY(rowsRemovedSpy.wait()); - // also destroy the connection to ensure the ShellSurface goes away surface.reset(); - shell.reset(); - shm.reset(); - compositor.reset(); - connection.take()->deleteLater(); - thread->quit(); - QVERIFY(thread->wait()); QVERIFY(rowsRemovedSpy.wait()); QCOMPARE(rowsRemovedSpy.count(), 1); diff --git a/autotests/integration/decoration_input_test.cpp b/autotests/integration/decoration_input_test.cpp --- a/autotests/integration/decoration_input_test.cpp +++ b/autotests/integration/decoration_input_test.cpp @@ -33,8 +33,6 @@ #include #include -#include -#include #include #include #include @@ -74,14 +72,6 @@ private: AbstractClient *showWindow(); - KWayland::Client::ConnectionThread *m_connection = nullptr; - KWayland::Client::Compositor *m_compositor = nullptr; - KWayland::Client::ServerSideDecorationManager *m_deco = nullptr; - KWayland::Client::Seat *m_seat = nullptr; - KWayland::Client::ShmPool *m_shm = nullptr; - KWayland::Client::Shell *m_shell = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; #define MOTION(target) \ @@ -105,25 +95,21 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); VERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); + Surface *surface = Test::createSurface(Test::waylandCompositor()); VERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); VERIFY(shellSurface); - auto deco = m_deco->create(surface, surface); + auto deco = Test::waylandServerSideDecoration()->create(surface, surface); QSignalSpy decoSpy(deco, &ServerSideDecoration::modeChanged); VERIFY(decoSpy.isValid()); VERIFY(decoSpy.wait()); deco->requestMode(ServerSideDecoration::Mode::Server); VERIFY(decoSpy.wait()); COMPARE(deco->mode(), ServerSideDecoration::Mode::Server); // let's render - QImage img(QSize(500, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 500, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface, QSize(500, 50), Qt::blue); - m_connection->flush(); + Test::flushWaylandConnection(); VERIFY(clientAddedSpy.wait()); AbstractClient *c = workspace()->activeClient(); VERIFY(c); @@ -166,88 +152,16 @@ void DecorationInputTest::init() { using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); - QSignalSpy decorationSpy(®istry, &Registry::serverSideDecorationManagerAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - QVERIFY(seatSpy.isValid()); - QVERIFY(decorationSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - QVERIFY(!seatSpy.isEmpty()); - QVERIFY(!decorationSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); - m_seat = registry.createSeat(seatSpy.first().first().value(), seatSpy.first().last().value(), this); - QVERIFY(m_seat->isValid()); - m_deco = registry.createServerSideDecorationManager(decorationSpy.first().first().value(), decorationSpy.first().last().value()); - QVERIFY(m_deco->isValid()); - QSignalSpy hasPointerSpy(m_seat, &Seat::hasPointerChanged); - QVERIFY(hasPointerSpy.isValid()); - QVERIFY(hasPointerSpy.wait()); + QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat | Test::AdditionalWaylandInterface::Decoration)); + QVERIFY(Test::waitForWaylandPointer()); screens()->setCurrent(0); Cursor::setPos(QPoint(640, 512)); } void DecorationInputTest::cleanup() { - delete m_compositor; - m_compositor = nullptr; - delete m_deco; - m_deco = nullptr; - delete m_seat; - m_seat = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_connection->deleteLater(); - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - m_connection = nullptr; - } + Test::destroyWaylandConnection(); } void DecorationInputTest::testAxis_data() diff --git a/autotests/integration/dont_crash_cancel_animation.cpp b/autotests/integration/dont_crash_cancel_animation.cpp --- a/autotests/integration/dont_crash_cancel_animation.cpp +++ b/autotests/integration/dont_crash_cancel_animation.cpp @@ -33,13 +33,11 @@ #include -#include #include #include #include #include #include -#include namespace KWin { @@ -58,12 +56,6 @@ private: void unlock(); AbstractClient *showWindow(); - KWayland::Client::ConnectionThread *m_connection = nullptr; - KWayland::Client::Compositor *m_compositor = nullptr; - KWayland::Client::ShmPool *m_shm = nullptr; - KWayland::Client::Shell *m_shell = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; void DontCrashCancelAnimationFromAnimationEndedTest::initTestCase() @@ -83,69 +75,12 @@ void DontCrashCancelAnimationFromAnimationEndedTest::init() { - using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); + QVERIFY(Test::setupWaylandConnection(s_socketName)); } void DontCrashCancelAnimationFromAnimationEndedTest::cleanup() { - delete m_compositor; - m_compositor = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_connection->deleteLater(); - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - m_connection = nullptr; - } + Test::destroyWaylandConnection(); } void DontCrashCancelAnimationFromAnimationEndedTest::testScript() @@ -169,18 +104,14 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); + Surface *surface = Test::createSurface(Test::waylandCompositor()); QVERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); QVERIFY(shellSurface); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface, QSize(100, 50), Qt::blue); - m_connection->flush(); + Test::flushWaylandConnection(); QVERIFY(clientAddedSpy.wait()); AbstractClient *c = workspace()->activeClient(); QVERIFY(c); diff --git a/autotests/integration/dont_crash_empty_deco.cpp b/autotests/integration/dont_crash_empty_deco.cpp --- a/autotests/integration/dont_crash_empty_deco.cpp +++ b/autotests/integration/dont_crash_empty_deco.cpp @@ -28,17 +28,6 @@ #include "shell_client.h" #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include #include @@ -54,18 +43,7 @@ private Q_SLOTS: void initTestCase(); void init(); - void cleanup(); void testBug361551(); - -private: - KWayland::Client::ConnectionThread *m_connection = nullptr; - KWayland::Client::Compositor *m_compositor = nullptr; - KWayland::Client::ServerSideDecorationManager *m_deco = nullptr; - KWayland::Client::Seat *m_seat = nullptr; - KWayland::Client::ShmPool *m_shm = nullptr; - KWayland::Client::Shell *m_shell = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; void DontCrashEmptyDecorationTest::initTestCase() @@ -94,91 +72,10 @@ void DontCrashEmptyDecorationTest::init() { - using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); - QSignalSpy decorationSpy(®istry, &Registry::serverSideDecorationManagerAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - QVERIFY(seatSpy.isValid()); - QVERIFY(decorationSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - QVERIFY(!seatSpy.isEmpty()); - QVERIFY(!decorationSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); - m_seat = registry.createSeat(seatSpy.first().first().value(), seatSpy.first().last().value(), this); - QVERIFY(m_seat->isValid()); - m_deco = registry.createServerSideDecorationManager(decorationSpy.first().first().value(), decorationSpy.first().last().value()); - QVERIFY(m_deco->isValid()); - QSignalSpy hasPointerSpy(m_seat, &Seat::hasPointerChanged); - QVERIFY(hasPointerSpy.isValid()); - QVERIFY(hasPointerSpy.wait()); - screens()->setCurrent(0); Cursor::setPos(QPoint(640, 512)); } -void DontCrashEmptyDecorationTest::cleanup() -{ - delete m_compositor; - m_compositor = nullptr; - delete m_deco; - m_deco = nullptr; - delete m_seat; - m_seat = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_connection->deleteLater(); - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - m_connection = nullptr; - } -} - void DontCrashEmptyDecorationTest::testBug361551() { // this test verifies that resizing an X11 window to an invalid size does not result in crash on unmap diff --git a/autotests/integration/dont_crash_no_border.cpp b/autotests/integration/dont_crash_no_border.cpp --- a/autotests/integration/dont_crash_no_border.cpp +++ b/autotests/integration/dont_crash_no_border.cpp @@ -29,15 +29,8 @@ #include "shell_client.h" #include -#include -#include -#include -#include -#include #include #include -#include -#include #include #include @@ -57,16 +50,6 @@ void init(); void cleanup(); void testCreateWindow(); - -private: - KWayland::Client::ConnectionThread *m_connection = nullptr; - KWayland::Client::Compositor *m_compositor = nullptr; - KWayland::Client::ServerSideDecorationManager *m_deco = nullptr; - KWayland::Client::Seat *m_seat = nullptr; - KWayland::Client::ShmPool *m_shm = nullptr; - KWayland::Client::Shell *m_shell = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; void DontCrashNoBorder::initTestCase() @@ -100,89 +83,15 @@ void DontCrashNoBorder::init() { - using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); - QSignalSpy decorationSpy(®istry, &Registry::serverSideDecorationManagerAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - QVERIFY(seatSpy.isValid()); - QVERIFY(decorationSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - QVERIFY(!seatSpy.isEmpty()); - QVERIFY(!decorationSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); - m_seat = registry.createSeat(seatSpy.first().first().value(), seatSpy.first().last().value(), this); - QVERIFY(m_seat->isValid()); - m_deco = registry.createServerSideDecorationManager(decorationSpy.first().first().value(), decorationSpy.first().last().value()); - QVERIFY(m_deco->isValid()); - QSignalSpy hasPointerSpy(m_seat, &Seat::hasPointerChanged); - QVERIFY(hasPointerSpy.isValid()); - QVERIFY(hasPointerSpy.wait()); + QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration)); screens()->setCurrent(0); Cursor::setPos(QPoint(640, 512)); } void DontCrashNoBorder::cleanup() { - delete m_compositor; - m_compositor = nullptr; - delete m_deco; - m_deco = nullptr; - delete m_seat; - m_seat = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_connection->deleteLater(); - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - m_connection = nullptr; - } + Test::destroyWaylandConnection(); } void DontCrashNoBorder::testCreateWindow() @@ -192,25 +101,21 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); - QVERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + QScopedPointer surface(Test::createSurface()); + QVERIFY(!surface.isNull()); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(shellSurface); - auto deco = m_deco->create(surface, surface); - QSignalSpy decoSpy(deco, &ServerSideDecoration::modeChanged); + QScopedPointer deco(Test::waylandServerSideDecoration()->create(surface.data())); + QSignalSpy decoSpy(deco.data(), &ServerSideDecoration::modeChanged); QVERIFY(decoSpy.isValid()); QVERIFY(decoSpy.wait()); deco->requestMode(ServerSideDecoration::Mode::Server); QVERIFY(decoSpy.wait()); QCOMPARE(deco->mode(), ServerSideDecoration::Mode::Server); // let's render - QImage img(QSize(500, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 500, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(500, 50), Qt::blue); - m_connection->flush(); + Test::flushWaylandConnection(); QVERIFY(clientAddedSpy.wait()); AbstractClient *c = workspace()->activeClient(); QVERIFY(c); diff --git a/autotests/integration/input_stacking_order.cpp b/autotests/integration/input_stacking_order.cpp --- a/autotests/integration/input_stacking_order.cpp +++ b/autotests/integration/input_stacking_order.cpp @@ -57,13 +57,6 @@ private: void render(KWayland::Client::Surface *surface); - KWayland::Client::ConnectionThread *m_connection = nullptr; - KWayland::Client::Compositor *m_compositor = nullptr; - KWayland::Client::Seat *m_seat = nullptr; - KWayland::Client::ShmPool *m_shm = nullptr; - KWayland::Client::Shell *m_shell = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; void InputStackingOrderTest::initTestCase() @@ -89,91 +82,22 @@ void InputStackingOrderTest::init() { using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - QVERIFY(seatSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - QVERIFY(!seatSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); - m_seat = registry.createSeat(seatSpy.first().first().value(), seatSpy.first().last().value(), this); - QVERIFY(m_seat->isValid()); - QSignalSpy hasPointerSpy(m_seat, &Seat::hasPointerChanged); - QVERIFY(hasPointerSpy.isValid()); - QVERIFY(hasPointerSpy.wait()); + QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); + QVERIFY(Test::waitForWaylandPointer()); screens()->setCurrent(0); Cursor::setPos(QPoint(640, 512)); } void InputStackingOrderTest::cleanup() { - delete m_compositor; - m_compositor = nullptr; - delete m_seat; - m_seat = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_connection->deleteLater(); - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - m_connection = nullptr; - } + Test::destroyWaylandConnection(); } void InputStackingOrderTest::render(KWayland::Client::Surface *surface) { - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(KWayland::Client::Surface::CommitFlag::None); - m_connection->flush(); + Test::render(surface, QSize(100, 50), Qt::blue); + Test::flushWaylandConnection(); } void InputStackingOrderTest::testPointerFocusUpdatesOnStackingOrderChange() @@ -184,7 +108,7 @@ // other window should gain focus without a mouse event in between using namespace KWayland::Client; // create pointer and signal spy for enter and leave signals - auto pointer = m_seat->createPointer(m_seat); + auto pointer = Test::waylandSeat()->createPointer(Test::waylandSeat()); QVERIFY(pointer); QVERIFY(pointer->isValid()); QSignalSpy enteredSpy(pointer, &Pointer::entered); @@ -195,18 +119,18 @@ // now create the two windows and make them overlap QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface1 = m_compositor->createSurface(m_compositor); + Surface *surface1 = Test::createSurface(Test::waylandCompositor()); QVERIFY(surface1); - ShellSurface *shellSurface1 = m_shell->createSurface(surface1, surface1); + ShellSurface *shellSurface1 = Test::createShellSurface(surface1, surface1); QVERIFY(shellSurface1); render(surface1); QVERIFY(clientAddedSpy.wait()); AbstractClient *window1 = workspace()->activeClient(); QVERIFY(window1); - Surface *surface2 = m_compositor->createSurface(m_compositor); + Surface *surface2 = Test::createSurface(Test::waylandCompositor()); QVERIFY(surface2); - ShellSurface *shellSurface2 = m_shell->createSurface(surface2, surface2); + ShellSurface *shellSurface2 = Test::createShellSurface(surface2, surface2); QVERIFY(shellSurface2); render(surface2); QVERIFY(clientAddedSpy.wait()); diff --git a/autotests/integration/kwin_wayland_test.h b/autotests/integration/kwin_wayland_test.h --- a/autotests/integration/kwin_wayland_test.h +++ b/autotests/integration/kwin_wayland_test.h @@ -25,6 +25,23 @@ // Qt #include +namespace KWayland +{ +namespace Client +{ +class ConnectionThread; +class Compositor; +class PlasmaShell; +class PlasmaWindowManagement; +class Seat; +class ServerSideDecorationManager; +class Shell; +class ShellSurface; +class ShmPool; +class Surface; +} +} + namespace KWin { @@ -50,8 +67,61 @@ QMetaObject::Connection m_xwaylandFailConnection; }; +namespace Test +{ + +enum class AdditionalWaylandInterface { + Seat = 1 << 0, + Decoration = 1 << 1, + PlasmaShell = 1 << 2, + WindowManagement = 1 << 3 +}; +Q_DECLARE_FLAGS(AdditionalWaylandInterfaces, AdditionalWaylandInterface) +/** + * Creates a Wayland Connection in a dedicated thread and creates various + * client side objects which can be used to create windows. + * @param socketName The name of the Wayland socket to connect to. + * @returns @c true if created successfully, @c false if there was an error + * @see destroyWaylandConnection + **/ +bool setupWaylandConnection(const QString &socketName, AdditionalWaylandInterfaces flags = AdditionalWaylandInterfaces()); + +/** + * Destroys the Wayland Connection created with @link{setupWaylandConnection}. + * This can be called from cleanup in order to ensure that no Wayland Connection + * leaks into the next test method. + * @see setupWaylandConnection + */ +void destroyWaylandConnection(); + +KWayland::Client::ConnectionThread *waylandConnection(); +KWayland::Client::Compositor *waylandCompositor(); +KWayland::Client::Shell *waylandShell(); +KWayland::Client::ShmPool *waylandShmPool(); +KWayland::Client::Seat *waylandSeat(); +KWayland::Client::ServerSideDecorationManager *waylandServerSideDecoration(); +KWayland::Client::PlasmaShell *waylandPlasmaShell(); +KWayland::Client::PlasmaWindowManagement *waylandWindowManagement(); + +bool waitForWaylandPointer(); +bool waitForWaylandTouch(); + +void flushWaylandConnection(); + +KWayland::Client::Surface *createSurface(QObject *parent = nullptr); +KWayland::Client::ShellSurface *createShellSurface(KWayland::Client::Surface *surface, QObject *parent = nullptr); + +/** + * Creates a shared memory buffer of @p size in @p color and attaches it to the @p surface. + * The @p surface gets damaged and committed, thus it's rendered. + **/ +void render(KWayland::Client::Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format = QImage::Format_ARGB32); +} + } +Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::Test::AdditionalWaylandInterfaces) + #define WAYLANDTEST_MAIN_HELPER(TestObject, DPI) \ int main(int argc, char *argv[]) \ { \ diff --git a/autotests/integration/lockscreen.cpp b/autotests/integration/lockscreen.cpp --- a/autotests/integration/lockscreen.cpp +++ b/autotests/integration/lockscreen.cpp @@ -30,7 +30,6 @@ #include #include -#include #include #include #include @@ -83,8 +82,6 @@ KWayland::Client::Seat *m_seat = nullptr; KWayland::Client::ShmPool *m_shm = nullptr; KWayland::Client::Shell *m_shell = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; class HelperEffect : public Effect @@ -167,16 +164,12 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); VERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); + Surface *surface = Test::createSurface(m_compositor); VERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); VERIFY(shellSurface); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface, QSize(100, 50), Qt::blue); m_connection->flush(); VERIFY(clientAddedSpy.wait()); @@ -212,82 +205,21 @@ void LockScreenTest::init() { - using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - QVERIFY(seatSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - QVERIFY(!seatSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); - m_seat = registry.createSeat(seatSpy.first().first().value(), seatSpy.first().last().value(), this); - QVERIFY(m_seat->isValid()); - QSignalSpy hasPointerSpy(m_seat, &Seat::hasPointerChanged); - QVERIFY(hasPointerSpy.isValid()); - QVERIFY(hasPointerSpy.wait()); + QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); + QVERIFY(Test::waitForWaylandPointer()); + m_connection = Test::waylandConnection(); + m_compositor = Test::waylandCompositor(); + m_shell = Test::waylandShell(); + m_shm = Test::waylandShmPool(); + m_seat = Test::waylandSeat(); screens()->setCurrent(0); Cursor::setPos(QPoint(640, 512)); } void LockScreenTest::cleanup() { - delete m_compositor; - m_compositor = nullptr; - delete m_seat; - m_seat = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_connection->deleteLater(); - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - m_connection = nullptr; - } + Test::destroyWaylandConnection(); } void LockScreenTest::testPointer() diff --git a/autotests/integration/maximize_test.cpp b/autotests/integration/maximize_test.cpp --- a/autotests/integration/maximize_test.cpp +++ b/autotests/integration/maximize_test.cpp @@ -25,10 +25,7 @@ #include "wayland_server.h" #include "workspace.h" -#include #include -#include -#include #include #include #include @@ -39,8 +36,6 @@ #include #include -#include - using namespace KWin; using namespace KWayland::Client; @@ -56,15 +51,6 @@ void testMaximizedPassedToDeco(); void testInitiallyMaximized(); - -private: - KWayland::Client::Compositor *m_compositor = nullptr; - Shell *m_shell = nullptr; - ShmPool *m_shm = nullptr; - EventQueue *m_queue = nullptr; - ServerSideDecorationManager *m_ssd = nullptr; - ConnectionThread *m_connection = nullptr; - QThread *m_thread = nullptr; }; void TestMaximized::initTestCase() @@ -87,94 +73,27 @@ void TestMaximized::init() { - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - - m_compositor = registry.createCompositor(registry.interface(Registry::Interface::Compositor).name, - registry.interface(Registry::Interface::Compositor).version, - this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(registry.interface(Registry::Interface::Shm).name, - registry.interface(Registry::Interface::Shm).version, - this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(registry.interface(Registry::Interface::Shell).name, - registry.interface(Registry::Interface::Shell).version, - this); - QVERIFY(m_shell->isValid()); - m_ssd = registry.createServerSideDecorationManager(registry.interface(Registry::Interface::ServerSideDecorationManager).name, - registry.interface(Registry::Interface::ServerSideDecorationManager).version, - this); - QVERIFY(m_ssd); + QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration)); screens()->setCurrent(0); KWin::Cursor::setPos(QPoint(1280, 512)); } void TestMaximized::cleanup() { -#define CLEANUP(name) \ - if (name) { \ - delete name; \ - name = nullptr; \ - } - CLEANUP(m_compositor) - CLEANUP(m_shm) - CLEANUP(m_shell) - CLEANUP(m_ssd) - CLEANUP(m_queue) - - if (m_connection) { - m_connection->deleteLater(); - m_connection = nullptr; - } - if (m_thread) { - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - } -#undef CLEANUP + Test::destroyWaylandConnection(); } void TestMaximized::testMaximizedPassedToDeco() { // this test verifies that when a ShellClient gets maximized the Decoration receives the signal QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(m_compositor->createSurface()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); - QScopedPointer ssd(m_ssd->create(surface.data())); + QScopedPointer surface(Test::createSurface()); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); + QScopedPointer ssd(Test::waylandServerSideDecoration()->create(surface.data())); - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); QSignalSpy sizeChangedSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangedSpy.isValid()); @@ -231,8 +150,8 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(m_compositor->createSurface()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer surface(Test::createSurface()); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QSignalSpy sizeChangedSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangedSpy.isValid()); @@ -242,11 +161,7 @@ QCOMPARE(shellSurface->size(), QSize(1280, 1024)); // now let's render in an incorrect size - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); QVERIFY(clientAddedSpy.isEmpty()); QVERIFY(clientAddedSpy.wait()); diff --git a/autotests/integration/move_resize_window_test.cpp b/autotests/integration/move_resize_window_test.cpp --- a/autotests/integration/move_resize_window_test.cpp +++ b/autotests/integration/move_resize_window_test.cpp @@ -30,11 +30,8 @@ #include #include -#include -#include #include #include -#include #include #include @@ -71,11 +68,7 @@ private: KWayland::Client::ConnectionThread *m_connection = nullptr; KWayland::Client::Compositor *m_compositor = nullptr; - KWayland::Client::ShmPool *m_shm = nullptr; KWayland::Client::Shell *m_shell = nullptr; - KWayland::Client::PlasmaShell *m_plasmaShell = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; void MoveResizeWindowTest::initTestCase() @@ -95,74 +88,17 @@ void MoveResizeWindowTest::init() { - using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); - m_plasmaShell = registry.createPlasmaShell(registry.interface(Registry::Interface::PlasmaShell).name, registry.interface(Registry::Interface::PlasmaShell).version, this); - QVERIFY(m_plasmaShell->isValid()); + QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::PlasmaShell)); + m_connection = Test::waylandConnection(); + m_compositor = Test::waylandCompositor(); + m_shell = Test::waylandShell(); screens()->setCurrent(0); } void MoveResizeWindowTest::cleanup() { - delete m_compositor; - m_compositor = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_plasmaShell; - m_plasmaShell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - } - + Test::destroyWaylandConnection(); } void MoveResizeWindowTest::testMove() @@ -172,19 +108,15 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); m_connection->flush(); QVERIFY(clientAddedSpy.wait()); @@ -274,19 +206,15 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); m_connection->flush(); QVERIFY(clientAddedSpy.wait()); @@ -322,30 +250,26 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface1(m_compositor->createSurface()); + QScopedPointer surface1(Test::createSurface()); QVERIFY(!surface1.isNull()); - QScopedPointer surface2(m_compositor->createSurface()); + QScopedPointer surface2(Test::createSurface()); QVERIFY(!surface2.isNull()); - QScopedPointer surface3(m_compositor->createSurface()); + QScopedPointer surface3(Test::createSurface()); QVERIFY(!surface3.isNull()); - QScopedPointer surface4(m_compositor->createSurface()); + QScopedPointer surface4(Test::createSurface()); QVERIFY(!surface4.isNull()); - QScopedPointer shellSurface1(m_shell->createSurface(surface1.data())); + QScopedPointer shellSurface1(Test::createShellSurface(surface1.data())); QVERIFY(!shellSurface1.isNull()); - QScopedPointer shellSurface2(m_shell->createSurface(surface2.data())); + QScopedPointer shellSurface2(Test::createShellSurface(surface2.data())); QVERIFY(!shellSurface2.isNull()); - QScopedPointer shellSurface3(m_shell->createSurface(surface3.data())); + QScopedPointer shellSurface3(Test::createShellSurface(surface3.data())); QVERIFY(!shellSurface3.isNull()); - QScopedPointer shellSurface4(m_shell->createSurface(surface4.data())); + QScopedPointer shellSurface4(Test::createShellSurface(surface4.data())); QVERIFY(!shellSurface4.isNull()); auto renderWindow = [this, &clientAddedSpy] (Surface *surface, const QString &methodCall, const QRect &expectedGeometry) { // let's render - QImage img(QSize(10, 10), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 10, 10)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface, QSize(10, 10), Qt::blue); m_connection->flush(); QVERIFY(clientAddedSpy.wait()); @@ -365,15 +289,11 @@ renderWindow(surface3.data(), QStringLiteral("slotWindowPackRight"), QRect(1270, 507, 10, 10)); renderWindow(surface4.data(), QStringLiteral("slotWindowPackDown"), QRect(635, 1014, 10, 10)); - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); m_connection->flush(); QVERIFY(clientAddedSpy.wait()); @@ -407,34 +327,26 @@ QVERIFY(clientAddedSpy.isValid()); // block geometry helper - QScopedPointer surface1(m_compositor->createSurface()); + QScopedPointer surface1(Test::createSurface()); QVERIFY(!surface1.isNull()); - QScopedPointer shellSurface1(m_shell->createSurface(surface1.data())); + QScopedPointer shellSurface1(Test::createShellSurface(surface1.data())); QVERIFY(!shellSurface1.isNull()); - QImage img1(QSize(650, 514), QImage::Format_ARGB32); - img1.fill(Qt::blue); - surface1->attachBuffer(m_shm->createBuffer(img1)); - surface1->damage(QRect(0, 0, 650, 514)); - surface1->commit(Surface::CommitFlag::None); + Test::render(surface1.data(), QSize(650, 514), Qt::blue); m_connection->flush(); QVERIFY(clientAddedSpy.wait()); clientAddedSpy.clear(); workspace()->slotWindowPackRight(); workspace()->slotWindowPackDown(); - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); m_connection->flush(); QVERIFY(clientAddedSpy.wait()); @@ -449,11 +361,7 @@ QFETCH(QString, methodCall); QMetaObject::invokeMethod(workspace(), methodCall.toLocal8Bit().constData()); QVERIFY(sizeChangeSpy.wait()); - QImage img2(shellSurface->size(), QImage::Format_ARGB32); - img2.fill(Qt::red); - surface->attachBuffer(m_shm->createBuffer(img2)); - surface->damage(QRect(QPoint(0, 0), shellSurface->size())); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), shellSurface->size(), Qt::red); QSignalSpy geometryChangedSpy(c, &AbstractClient::geometryChanged); QVERIFY(geometryChangedSpy.isValid()); @@ -486,19 +394,15 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); m_connection->flush(); QVERIFY(clientAddedSpy.wait()); @@ -547,22 +451,18 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); // and a PlasmaShellSurface - QScopedPointer plasmaSurface(m_plasmaShell->createSurface(surface.data())); + QScopedPointer plasmaSurface(Test::waylandPlasmaShell()->createSurface(surface.data())); QVERIFY(!plasmaSurface.isNull()); QFETCH(KWayland::Client::PlasmaShellSurface::Role, role); plasmaSurface->setRole(role); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); m_connection->flush(); QVERIFY(clientAddedSpy.wait()); diff --git a/autotests/integration/plasma_surface_test.cpp b/autotests/integration/plasma_surface_test.cpp --- a/autotests/integration/plasma_surface_test.cpp +++ b/autotests/integration/plasma_surface_test.cpp @@ -52,11 +52,8 @@ private: ConnectionThread *m_connection = nullptr; KWayland::Client::Compositor *m_compositor = nullptr; - ShmPool *m_shm = nullptr; Shell *m_shell = nullptr; PlasmaShell *m_plasmaShell = nullptr; - EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; void PlasmaSurfaceTest::initTestCase() @@ -72,70 +69,15 @@ void PlasmaSurfaceTest::init() { - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - - m_compositor = registry.createCompositor(registry.interface(Registry::Interface::Compositor).name, - registry.interface(Registry::Interface::Compositor).version, - this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(registry.interface(Registry::Interface::Shm).name, - registry.interface(Registry::Interface::Shm).version, - this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(registry.interface(Registry::Interface::Shell).name, - registry.interface(Registry::Interface::Shell).version, - this); - QVERIFY(m_shell->isValid()); - m_plasmaShell = registry.createPlasmaShell(registry.interface(Registry::Interface::PlasmaShell).name, - registry.interface(Registry::Interface::PlasmaShell).version, - this); - QVERIFY(m_plasmaShell->isValid()); + QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::PlasmaShell)); + m_compositor = Test::waylandCompositor(); + m_shell = Test::waylandShell(); + m_plasmaShell = Test::waylandPlasmaShell(); } void PlasmaSurfaceTest::cleanup() { -#define CLEANUP(name) delete name; name = nullptr; - CLEANUP(m_plasmaShell) - CLEANUP(m_shell) - CLEANUP(m_shm) - CLEANUP(m_compositor) - CLEANUP(m_queue) - if (m_connection) { - m_connection->deleteLater(); - m_connection = nullptr; - } - if (m_thread) { - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - } -#undef CLEANUP + Test::destroyWaylandConnection(); } void PlasmaSurfaceTest::testRoleOnAllDesktops_data() @@ -154,22 +96,18 @@ void PlasmaSurfaceTest::testRoleOnAllDesktops() { // this test verifies that a ShellClient is set on all desktops when the role changes - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); QScopedPointer plasmaSurface(m_plasmaShell->createSurface(surface.data())); QVERIFY(!plasmaSurface.isNull()); QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); // now render to map the window - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(); + Test::render(surface.data(), QSize(100, 50), Qt::blue); QVERIFY(clientAddedSpy.wait()); AbstractClient *c = workspace()->activeClient(); QVERIFY(c); @@ -189,16 +127,14 @@ // let's create a second window where we init a little bit different // first creating the PlasmaSurface then the Shell Surface - QScopedPointer surface2(m_compositor->createSurface()); + QScopedPointer surface2(Test::createSurface()); QVERIFY(!surface2.isNull()); QScopedPointer plasmaSurface2(m_plasmaShell->createSurface(surface2.data())); QVERIFY(!plasmaSurface2.isNull()); plasmaSurface2->setRole(role); - QScopedPointer shellSurface2(m_shell->createSurface(surface2.data())); + QScopedPointer shellSurface2(Test::createShellSurface(surface2.data())); QVERIFY(!shellSurface2.isNull()); - surface2->attachBuffer(m_shm->createBuffer(img)); - surface2->damage(QRect(0, 0, 100, 50)); - surface2->commit(); + Test::render(surface2.data(), QSize(100, 50), Qt::blue); QVERIFY(clientAddedSpy.wait()); QVERIFY(workspace()->activeClient() != c); @@ -228,9 +164,9 @@ void PlasmaSurfaceTest::testAcceptsFocus() { // this test verifies that some surface roles don't get focus - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); QScopedPointer plasmaSurface(m_plasmaShell->createSurface(surface.data())); QVERIFY(!plasmaSurface.isNull()); @@ -241,11 +177,7 @@ QVERIFY(clientAddedSpy.isValid()); // now render to map the window - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(); + Test::render(surface.data(), QSize(100, 50), Qt::blue); QVERIFY(clientAddedSpy.wait()); auto c = clientAddedSpy.first().first().value(); diff --git a/autotests/integration/plasmawindow_test.cpp b/autotests/integration/plasmawindow_test.cpp --- a/autotests/integration/plasmawindow_test.cpp +++ b/autotests/integration/plasmawindow_test.cpp @@ -29,12 +29,8 @@ #include #include -#include -#include #include -#include #include -#include #include #include //screenlocker @@ -67,13 +63,9 @@ void testDestroyedButNotUnmapped(); private: - ConnectionThread *m_connection = nullptr; PlasmaWindowManagement *m_windowManagement = nullptr; KWayland::Client::Compositor *m_compositor = nullptr; Shell *m_shell = nullptr; - ShmPool *m_shm = nullptr; - EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; void PlasmaWindowTest::initTestCase() @@ -98,77 +90,18 @@ void PlasmaWindowTest::init() { - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - - m_windowManagement = registry.createPlasmaWindowManagement(registry.interface(Registry::Interface::PlasmaWindowManagement).name, - registry.interface(Registry::Interface::PlasmaWindowManagement).version, - this); - QVERIFY(m_windowManagement); - m_compositor = registry.createCompositor(registry.interface(Registry::Interface::Compositor).name, - registry.interface(Registry::Interface::Compositor).version, - this); - QVERIFY(m_compositor); - m_shm = registry.createShmPool(registry.interface(Registry::Interface::Shm).name, - registry.interface(Registry::Interface::Shm).version, - this); - QVERIFY(m_shm); - m_shell = registry.createShell(registry.interface(Registry::Interface::Shell).name, - registry.interface(Registry::Interface::Shell).version, - this); - QVERIFY(m_shell); + QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::WindowManagement)); + m_windowManagement = Test::waylandWindowManagement(); + m_compositor = Test::waylandCompositor(); + m_shell = Test::waylandShell(); screens()->setCurrent(0); Cursor::setPos(QPoint(640, 512)); } void PlasmaWindowTest::cleanup() { -#define CLEANUP(name) \ - if (name) { \ - delete name; \ - name = nullptr; \ - } - CLEANUP(m_windowManagement) - CLEANUP(m_shm) - CLEANUP(m_shell) - CLEANUP(m_compositor) - CLEANUP(m_queue) -#undef CLEANUP - if (m_connection) { - m_connection->deleteLater(); - m_connection = nullptr; - } - if (m_thread) { - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - } + Test::destroyWaylandConnection(); } void PlasmaWindowTest::testCreateDestroyX11PlasmaWindow() @@ -304,35 +237,27 @@ QVERIFY(plasmaWindowCreatedSpy.isValid()); // first create the parent window - QScopedPointer parentSurface(m_compositor->createSurface()); - QScopedPointer parentShellSurface(m_shell->createSurface(parentSurface.data())); + QScopedPointer parentSurface(Test::createSurface()); + QScopedPointer parentShellSurface(Test::createShellSurface(parentSurface.data())); // map that window - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - parentSurface->attachBuffer(m_shm->createBuffer(img)); - parentSurface->damage(QRect(0, 0, 100, 50)); - parentSurface->commit(); + Test::render(parentSurface.data(), QSize(100, 50), Qt::blue); // this should create a plasma window QVERIFY(plasmaWindowCreatedSpy.wait()); // now let's create a popup window for it - QScopedPointer popupSurface(m_compositor->createSurface()); - QScopedPointer popupShellSurface(m_shell->createSurface(popupSurface.data())); + QScopedPointer popupSurface(Test::createSurface()); + QScopedPointer popupShellSurface(Test::createShellSurface(popupSurface.data())); popupShellSurface->setTransient(parentSurface.data(), QPoint(0, 0), ShellSurface::TransientFlag::NoFocus); // let's map it - popupSurface->attachBuffer(m_shm->createBuffer(img)); - popupSurface->damage(QRect(0, 0, 100, 50)); - popupSurface->commit(); + Test::render(popupSurface.data(), QSize(100, 50), Qt::blue); // this should not create a plasma window QVERIFY(!plasmaWindowCreatedSpy.wait()); // now the same with an already mapped surface when we create the shell surface - QScopedPointer popup2Surface(m_compositor->createSurface()); - popup2Surface->attachBuffer(m_shm->createBuffer(img)); - popup2Surface->damage(QRect(0, 0, 100, 50)); - popup2Surface->commit(); - QScopedPointer popup2ShellSurface(m_shell->createSurface(popup2Surface.data())); + QScopedPointer popup2Surface(Test::createSurface()); + Test::render(popup2Surface.data(), QSize(100, 50), Qt::blue); + QScopedPointer popup2ShellSurface(Test::createShellSurface(popup2Surface.data())); popup2ShellSurface->setTransient(popupSurface.data(), QPoint(0, 0), ShellSurface::TransientFlag::NoFocus); // this should not create a plasma window @@ -409,14 +334,10 @@ QVERIFY(plasmaWindowCreatedSpy.isValid()); // first create the parent window - QScopedPointer parentSurface(m_compositor->createSurface()); - QScopedPointer parentShellSurface(m_shell->createSurface(parentSurface.data())); + QScopedPointer parentSurface(Test::createSurface()); + QScopedPointer parentShellSurface(Test::createShellSurface(parentSurface.data())); // map that window - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - parentSurface->attachBuffer(m_shm->createBuffer(img)); - parentSurface->damage(QRect(0, 0, 100, 50)); - parentSurface->commit(); + Test::render(parentSurface.data(), QSize(100, 50), Qt::blue); // this should create a plasma window QVERIFY(plasmaWindowCreatedSpy.wait()); QCOMPARE(plasmaWindowCreatedSpy.count(), 1); diff --git a/autotests/integration/pointer_input.cpp b/autotests/integration/pointer_input.cpp --- a/autotests/integration/pointer_input.cpp +++ b/autotests/integration/pointer_input.cpp @@ -33,8 +33,6 @@ #include #include -#include -#include #include #include #include @@ -75,13 +73,9 @@ private: void render(KWayland::Client::Surface *surface, const QSize &size = QSize(100, 50)); - KWayland::Client::ConnectionThread *m_connection = nullptr; KWayland::Client::Compositor *m_compositor = nullptr; KWayland::Client::Seat *m_seat = nullptr; - KWayland::Client::ShmPool *m_shm = nullptr; KWayland::Client::Shell *m_shell = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; void PointerInputTest::initTestCase() @@ -111,92 +105,25 @@ void PointerInputTest::init() { - using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - QVERIFY(seatSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - QVERIFY(!seatSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); - m_seat = registry.createSeat(seatSpy.first().first().value(), seatSpy.first().last().value(), this); - QVERIFY(m_seat->isValid()); - QSignalSpy hasPointerSpy(m_seat, &Seat::hasPointerChanged); - QVERIFY(hasPointerSpy.isValid()); - QVERIFY(hasPointerSpy.wait()); + QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); + QVERIFY(Test::waitForWaylandPointer()); + m_compositor = Test::waylandCompositor(); + m_shell = Test::waylandShell(); + m_seat = Test::waylandSeat(); screens()->setCurrent(0); Cursor::setPos(QPoint(640, 512)); } void PointerInputTest::cleanup() { - delete m_compositor; - m_compositor = nullptr; - delete m_seat; - m_seat = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_connection->deleteLater(); - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - m_connection = nullptr; - } + Test::destroyWaylandConnection(); } void PointerInputTest::render(KWayland::Client::Surface *surface, const QSize &size) { - QImage img(size, QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(QPoint(0, 0), size)); - surface->commit(KWayland::Client::Surface::CommitFlag::None); - m_connection->flush(); + Test::render(surface, size, Qt::blue); + Test::flushWaylandConnection(); } void PointerInputTest::testWarpingUpdatesFocus() @@ -215,9 +142,9 @@ // create a window QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); + Surface *surface = Test::createSurface(m_compositor); QVERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); QVERIFY(shellSurface); render(surface); QVERIFY(clientAddedSpy.wait()); @@ -262,9 +189,9 @@ // create a window QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); + Surface *surface = Test::createSurface(m_compositor); QVERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); QVERIFY(shellSurface); render(surface); QVERIFY(clientAddedSpy.wait()); @@ -304,9 +231,9 @@ // create a window QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); + Surface *surface = Test::createSurface(m_compositor); QVERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); QVERIFY(shellSurface); render(surface, QSize(1280, 1024)); QVERIFY(clientAddedSpy.wait()); @@ -383,9 +310,9 @@ // create a window QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); + Surface *surface = Test::createSurface(m_compositor); QVERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); QVERIFY(shellSurface); render(surface); QVERIFY(clientAddedSpy.wait()); @@ -453,9 +380,9 @@ // create a window QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); + Surface *surface = Test::createSurface(m_compositor); QVERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); QVERIFY(shellSurface); render(surface); QVERIFY(clientAddedSpy.wait()); @@ -501,17 +428,17 @@ // create two windows QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface1 = m_compositor->createSurface(m_compositor); + Surface *surface1 = Test::createSurface(m_compositor); QVERIFY(surface1); - ShellSurface *shellSurface1 = m_shell->createSurface(surface1, surface1); + ShellSurface *shellSurface1 = Test::createShellSurface(surface1, surface1); QVERIFY(shellSurface1); render(surface1); QVERIFY(clientAddedSpy.wait()); AbstractClient *window1 = workspace()->activeClient(); QVERIFY(window1); - Surface *surface2 = m_compositor->createSurface(m_compositor); + Surface *surface2 = Test::createSurface(m_compositor); QVERIFY(surface2); - ShellSurface *shellSurface2 = m_shell->createSurface(surface2, surface2); + ShellSurface *shellSurface2 = Test::createShellSurface(surface2, surface2); QVERIFY(shellSurface2); render(surface2); QVERIFY(clientAddedSpy.wait()); @@ -561,17 +488,17 @@ // create two windows QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface1 = m_compositor->createSurface(m_compositor); + Surface *surface1 = Test::createSurface(m_compositor); QVERIFY(surface1); - ShellSurface *shellSurface1 = m_shell->createSurface(surface1, surface1); + ShellSurface *shellSurface1 = Test::createShellSurface(surface1, surface1); QVERIFY(shellSurface1); render(surface1, QSize(800, 800)); QVERIFY(clientAddedSpy.wait()); AbstractClient *window1 = workspace()->activeClient(); QVERIFY(window1); - Surface *surface2 = m_compositor->createSurface(m_compositor); + Surface *surface2 = Test::createSurface(m_compositor); QVERIFY(surface2); - ShellSurface *shellSurface2 = m_shell->createSurface(surface2, surface2); + ShellSurface *shellSurface2 = Test::createShellSurface(surface2, surface2); QVERIFY(shellSurface2); render(surface2, QSize(800, 800)); QVERIFY(clientAddedSpy.wait()); @@ -647,17 +574,17 @@ // create two windows QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface1 = m_compositor->createSurface(m_compositor); + Surface *surface1 = Test::createSurface(m_compositor); QVERIFY(surface1); - ShellSurface *shellSurface1 = m_shell->createSurface(surface1, surface1); + ShellSurface *shellSurface1 = Test::createShellSurface(surface1, surface1); QVERIFY(shellSurface1); render(surface1, QSize(800, 800)); QVERIFY(clientAddedSpy.wait()); AbstractClient *window1 = workspace()->activeClient(); QVERIFY(window1); - Surface *surface2 = m_compositor->createSurface(m_compositor); + Surface *surface2 = Test::createSurface(m_compositor); QVERIFY(surface2); - ShellSurface *shellSurface2 = m_shell->createSurface(surface2, surface2); + ShellSurface *shellSurface2 = Test::createShellSurface(surface2, surface2); QVERIFY(shellSurface2); render(surface2, QSize(800, 800)); QVERIFY(clientAddedSpy.wait()); @@ -737,19 +664,19 @@ // create two windows QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface1 = m_compositor->createSurface(m_compositor); + Surface *surface1 = Test::createSurface(m_compositor); QVERIFY(surface1); - ShellSurface *shellSurface1 = m_shell->createSurface(surface1, surface1); + ShellSurface *shellSurface1 = Test::createShellSurface(surface1, surface1); QVERIFY(shellSurface1); render(surface1, QSize(800, 800)); QVERIFY(clientAddedSpy.wait()); AbstractClient *window1 = workspace()->activeClient(); QVERIFY(window1); QSignalSpy window1DestroyedSpy(window1, &QObject::destroyed); QVERIFY(window1DestroyedSpy.isValid()); - Surface *surface2 = m_compositor->createSurface(m_compositor); + Surface *surface2 = Test::createSurface(m_compositor); QVERIFY(surface2); - ShellSurface *shellSurface2 = m_shell->createSurface(surface2, surface2); + ShellSurface *shellSurface2 = Test::createShellSurface(surface2, surface2); QVERIFY(shellSurface2); render(surface2, QSize(800, 800)); QVERIFY(clientAddedSpy.wait()); @@ -817,9 +744,9 @@ // create a window QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); + Surface *surface = Test::createSurface(m_compositor); QVERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); QVERIFY(shellSurface); render(surface); QVERIFY(clientAddedSpy.wait()); @@ -833,29 +760,29 @@ QVERIFY(enteredSpy.wait()); // create a cursor on the pointer - Surface *cursorSurface = m_compositor->createSurface(m_compositor); + Surface *cursorSurface = Test::createSurface(m_compositor); QVERIFY(cursorSurface); QSignalSpy cursorRenderedSpy(cursorSurface, &Surface::frameRendered); QVERIFY(cursorRenderedSpy.isValid()); QImage red = QImage(QSize(10, 10), QImage::Format_ARGB32); red.fill(Qt::red); - cursorSurface->attachBuffer(m_shm->createBuffer(red)); + cursorSurface->attachBuffer(Test::waylandShmPool()->createBuffer(red)); cursorSurface->damage(QRect(0, 0, 10, 10)); cursorSurface->commit(); pointer->setCursor(cursorSurface, QPoint(5, 5)); QVERIFY(cursorRenderedSpy.wait()); QCOMPARE(p->cursorImage(), red); QCOMPARE(p->cursorHotSpot(), QPoint(5, 5)); // change hotspot pointer->setCursor(cursorSurface, QPoint(6, 6)); - m_connection->flush(); + Test::flushWaylandConnection(); QTRY_COMPARE(p->cursorHotSpot(), QPoint(6, 6)); QCOMPARE(p->cursorImage(), red); // change the buffer QImage blue = QImage(QSize(10, 10), QImage::Format_ARGB32); blue.fill(Qt::blue); - auto b = m_shm->createBuffer(blue); + auto b = Test::waylandShmPool()->createBuffer(blue); cursorSurface->attachBuffer(b); cursorSurface->damage(QRect(0, 0, 10, 10)); cursorSurface->commit(); @@ -865,7 +792,7 @@ // hide the cursor pointer->setCursor(nullptr); - m_connection->flush(); + Test::flushWaylandConnection(); QTRY_VERIFY(p->cursorImage().isNull()); // move cursor somewhere else, should reset to fallback cursor @@ -904,9 +831,9 @@ // now let's create a window QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); + Surface *surface = Test::createSurface(m_compositor); QVERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); QVERIFY(shellSurface); render(surface); QVERIFY(clientAddedSpy.wait()); diff --git a/autotests/integration/quick_tiling_test.cpp b/autotests/integration/quick_tiling_test.cpp --- a/autotests/integration/quick_tiling_test.cpp +++ b/autotests/integration/quick_tiling_test.cpp @@ -28,10 +28,7 @@ #include #include -#include -#include #include -#include #include #include @@ -63,10 +60,7 @@ private: KWayland::Client::ConnectionThread *m_connection = nullptr; KWayland::Client::Compositor *m_compositor = nullptr; - KWayland::Client::ShmPool *m_shm = nullptr; KWayland::Client::Shell *m_shell = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; void QuickTilingTest::initTestCase() @@ -97,71 +91,17 @@ void QuickTilingTest::init() { - using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); + QVERIFY(Test::setupWaylandConnection(s_socketName)); + m_connection = Test::waylandConnection(); + m_compositor = Test::waylandCompositor(); + m_shell = Test::waylandShell(); screens()->setCurrent(0); } void QuickTilingTest::cleanup() { - delete m_compositor; - m_compositor = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_connection->deleteLater(); - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - m_connection = nullptr; - } + Test::destroyWaylandConnection(); } void QuickTilingTest::testQuickTiling_data() @@ -194,19 +134,15 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); m_connection->flush(); QVERIFY(clientAddedSpy.wait()); @@ -235,11 +171,7 @@ QCOMPARE(sizeChangeSpy.first().first().toSize(), expectedGeometry.size()); // attach a new image - img = QImage(expectedGeometry.size(), QImage::Format_ARGB32); - img.fill(Qt::red); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(QPoint(0, 0), expectedGeometry.size())); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), expectedGeometry.size(), Qt::red); m_connection->flush(); QVERIFY(geometryChangedSpy.wait()); @@ -276,19 +208,15 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); m_connection->flush(); QVERIFY(clientAddedSpy.wait()); @@ -329,11 +257,7 @@ QCOMPARE(sizeChangeSpy.first().first().toSize(), QSize(1280, 1024)); // attach a new image - img = QImage(QSize(1280, 1024), QImage::Format_ARGB32); - img.fill(Qt::red); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 1280, 1024)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(1280, 1024), Qt::red); m_connection->flush(); QVERIFY(geometryChangedSpy.wait()); @@ -363,11 +287,7 @@ QCOMPARE(sizeChangeSpy.last().first().toSize(), QSize(100, 50)); // render again - img = QImage(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::yellow); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::yellow); m_connection->flush(); QVERIFY(geometryChangedSpy.wait()); @@ -396,19 +316,15 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); m_connection->flush(); QVERIFY(clientAddedSpy.wait()); @@ -477,19 +393,15 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); QVERIFY(sizeChangeSpy.isValid()); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); m_connection->flush(); QVERIFY(clientAddedSpy.wait()); diff --git a/autotests/integration/shell_client_test.cpp b/autotests/integration/shell_client_test.cpp --- a/autotests/integration/shell_client_test.cpp +++ b/autotests/integration/shell_client_test.cpp @@ -27,16 +27,11 @@ #include #include -#include -#include #include -#include #include #include -#include - using namespace KWin; using namespace KWayland::Client; @@ -51,14 +46,6 @@ void cleanup(); void testMapUnmapMap(); - -private: - KWayland::Client::Compositor *m_compositor = nullptr; - Shell *m_shell = nullptr; - ShmPool *m_shm = nullptr; - EventQueue *m_queue = nullptr; - ConnectionThread *m_connection = nullptr; - QThread *m_thread = nullptr; }; void TestShellClient::initTestCase() @@ -81,90 +68,28 @@ void TestShellClient::init() { - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - - m_compositor = registry.createCompositor(registry.interface(Registry::Interface::Compositor).name, - registry.interface(Registry::Interface::Compositor).version, - this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(registry.interface(Registry::Interface::Shm).name, - registry.interface(Registry::Interface::Shm).version, - this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(registry.interface(Registry::Interface::Shell).name, - registry.interface(Registry::Interface::Shell).version, - this); - QVERIFY(m_shell->isValid()); + QVERIFY(Test::setupWaylandConnection(s_socketName)); screens()->setCurrent(0); KWin::Cursor::setPos(QPoint(1280, 512)); } void TestShellClient::cleanup() { -#define CLEANUP(name) \ - if (name) { \ - delete name; \ - name = nullptr; \ - } - CLEANUP(m_compositor) - CLEANUP(m_shm) - CLEANUP(m_shell) - CLEANUP(m_queue) - - if (m_connection) { - m_connection->deleteLater(); - m_connection = nullptr; - } - if (m_thread) { - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - } -#undef CLEANUP + Test::destroyWaylandConnection(); } void TestShellClient::testMapUnmapMap() { // this test verifies that mapping a previously mapped window works correctly QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(m_compositor->createSurface()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer surface(Test::createSurface()); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); // now let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); QVERIFY(clientAddedSpy.isEmpty()); QVERIFY(clientAddedSpy.wait()); @@ -186,9 +111,7 @@ QSignalSpy windowShownSpy(client, &ShellClient::windowShown); QVERIFY(windowShownSpy.isValid()); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), QSize(100, 50), Qt::blue); QCOMPARE(clientAddedSpy.count(), 1); QVERIFY(windowShownSpy.wait()); QCOMPARE(windowShownSpy.count(), 1); diff --git a/autotests/integration/start_test.cpp b/autotests/integration/start_test.cpp --- a/autotests/integration/start_test.cpp +++ b/autotests/integration/start_test.cpp @@ -26,10 +26,7 @@ #include #include -#include -#include #include -#include #include namespace KWin @@ -42,6 +39,7 @@ Q_OBJECT private Q_SLOTS: void initTestCase(); + void cleanup(); void testScreens(); void testNoWindowsAtStart(); void testCreateWindow(); @@ -57,6 +55,11 @@ QVERIFY(workspaceCreatedSpy.wait()); } +void StartTest::cleanup() +{ + Test::destroyWaylandConnection(); +} + void StartTest::testScreens() { QCOMPARE(screens()->count(), 1); @@ -78,48 +81,22 @@ { // first we need to connect to the server using namespace KWayland::Client; - auto connection = new ConnectionThread; - QSignalSpy connectedSpy(connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - connection->setSocketName(s_socketName); - QThread *thread = new QThread(this); - connection->moveToThread(thread); - thread->start(); - connection->initConnection(); - QVERIFY(connectedSpy.wait()); + QVERIFY(Test::setupWaylandConnection(s_socketName)); QSignalSpy shellClientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(shellClientAddedSpy.isValid()); QSignalSpy shellClientRemovedSpy(waylandServer(), &WaylandServer::shellClientRemoved); QVERIFY(shellClientRemovedSpy.isValid()); { - EventQueue queue; - queue.setup(connection); - Registry registry; - registry.setEventQueue(&queue); - registry.create(connection); - QSignalSpy registryAnnouncedSpy(®istry, &Registry::interfacesAnnounced); - QVERIFY(registryAnnouncedSpy.isValid()); - registry.setup(); - QVERIFY(registryAnnouncedSpy.wait()); - - const auto compositorData = registry.interface(Registry::Interface::Compositor); - const auto shellData = registry.interface(Registry::Interface::Shell); - const auto shmData = registry.interface(Registry::Interface::Shm); - QScopedPointer compositor(registry.createCompositor(compositorData.name, compositorData.version)); - QVERIFY(!compositor.isNull()); - QScopedPointer shell(registry.createShell(shellData.name, shellData.version)); - QVERIFY(!shell.isNull()); - - QScopedPointer surface(compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); QSignalSpy surfaceRenderedSpy(surface.data(), &Surface::frameRendered); QVERIFY(surfaceRenderedSpy.isValid()); - QScopedPointer shellSurface(shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); - connection->flush(); + Test::flushWaylandConnection(); QVERIFY(waylandServer()->clients().isEmpty()); // now dispatch should give us the client waylandServer()->dispatch(); @@ -132,15 +109,10 @@ QVERIFY(waylandServer()->clients().first()->iconGeometry().isNull()); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - QScopedPointer shm(registry.createShmPool(shmData.name, shmData.version)); - QVERIFY(!shm.isNull()); - surface->attachBuffer(shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); + Test::render(surface.data(), QSize(100, 50), Qt::blue); surface->commit(); - connection->flush(); + Test::flushWaylandConnection(); QVERIFY(shellClientAddedSpy.wait()); QCOMPARE(workspace()->allClientList().count(), 1); QCOMPARE(workspace()->allClientList().first(), waylandServer()->clients().first()); @@ -155,11 +127,6 @@ // this should tear down everything again QVERIFY(shellClientRemovedSpy.wait()); QVERIFY(waylandServer()->clients().isEmpty()); - - // cleanup - connection->deleteLater(); - thread->quit(); - thread->wait(); } } diff --git a/autotests/integration/struts_test.cpp b/autotests/integration/struts_test.cpp --- a/autotests/integration/struts_test.cpp +++ b/autotests/integration/struts_test.cpp @@ -28,16 +28,9 @@ #include "shell_client.h" #include -#include #include -#include -#include #include -#include -#include #include -#include -#include #include #include @@ -66,15 +59,8 @@ void test363804(); private: - KWayland::Client::ConnectionThread *m_connection = nullptr; KWayland::Client::Compositor *m_compositor = nullptr; - KWayland::Client::ServerSideDecorationManager *m_deco = nullptr; - KWayland::Client::Seat *m_seat = nullptr; - KWayland::Client::ShmPool *m_shm = nullptr; - KWayland::Client::Shell *m_shell = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; KWayland::Client::PlasmaShell *m_plasmaShell = nullptr; - QThread *m_thread = nullptr; }; void StrutsTest::initTestCase() @@ -98,99 +84,18 @@ void StrutsTest::init() { - using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); - QSignalSpy decorationSpy(®istry, &Registry::serverSideDecorationManagerAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - QVERIFY(seatSpy.isValid()); - QVERIFY(decorationSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - QVERIFY(!seatSpy.isEmpty()); - QVERIFY(!decorationSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); - m_seat = registry.createSeat(seatSpy.first().first().value(), seatSpy.first().last().value(), this); - QVERIFY(m_seat->isValid()); - m_deco = registry.createServerSideDecorationManager(decorationSpy.first().first().value(), decorationSpy.first().last().value()); - QVERIFY(m_deco->isValid()); - m_plasmaShell = registry.createPlasmaShell(registry.interface(Registry::Interface::PlasmaShell).name, - registry.interface(Registry::Interface::PlasmaShell).version, - this); - QVERIFY(m_plasmaShell); - QSignalSpy hasPointerSpy(m_seat, &Seat::hasPointerChanged); - QVERIFY(hasPointerSpy.isValid()); - QVERIFY(hasPointerSpy.wait()); + QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::PlasmaShell)); + m_compositor = Test::waylandCompositor(); + m_plasmaShell = Test::waylandPlasmaShell(); screens()->setCurrent(0); Cursor::setPos(QPoint(640, 512)); + QVERIFY(waylandServer()->clients().isEmpty()); } void StrutsTest::cleanup() { - delete m_compositor; - m_compositor = nullptr; - delete m_deco; - m_deco = nullptr; - delete m_seat; - m_seat = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_plasmaShell; - m_plasmaShell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_connection->deleteLater(); - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - m_connection = nullptr; - } - while (!waylandServer()->clients().isEmpty()) { - QCoreApplication::instance()->processEvents(QEventLoop::WaitForMoreEvents); - } - QVERIFY(waylandServer()->clients().isEmpty()); + Test::destroyWaylandConnection(); } void StrutsTest::testWaylandStruts_data() @@ -252,21 +157,18 @@ // create the panels QSignalSpy windowCreatedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(windowCreatedSpy.isValid()); + QHash clients; for (auto it = windowGeometries.constBegin(), end = windowGeometries.constEnd(); it != end; it++) { const QRect windowGeometry = *it; - Surface *surface = m_compositor->createSurface(m_compositor); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + Surface *surface = Test::createSurface(m_compositor); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); Q_UNUSED(shellSurface) PlasmaShellSurface *plasmaSurface = m_plasmaShell->createSurface(surface, surface); plasmaSurface->setPosition(windowGeometry.topLeft()); plasmaSurface->setRole(PlasmaShellSurface::Role::Panel); // map the window - QImage img(windowGeometry.size(), QImage::Format_RGB32); - img.fill(Qt::red); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(QPoint(0, 0), windowGeometry.size())); - surface->commit(Surface::CommitFlag::None); + Test::render(surface, windowGeometry.size(), Qt::red, QImage::Format_RGB32); QVERIFY(windowCreatedSpy.wait()); QCOMPARE(windowCreatedSpy.count(), 1); @@ -277,6 +179,7 @@ QVERIFY(c->isDock()); QVERIFY(c->hasStrut()); windowCreatedSpy.clear(); + clients.insert(surface, c); } // some props are independent of struts - those first @@ -299,15 +202,23 @@ QTEST(workspace()->clientArea(PlacementArea, 1, 1), "screen1Maximized"); QTEST(workspace()->clientArea(MaximizeArea, 1, 1), "screen1Maximized"); QTEST(workspace()->clientArea(WorkArea, 0, 1), "workArea"); + + // delete all surfaces + for (auto it = clients.begin(); it != clients.end(); it++) { + QSignalSpy destroyedSpy(it.value(), &QObject::destroyed); + QVERIFY(destroyedSpy.isValid()); + delete it.key(); + QVERIFY(destroyedSpy.wait()); + } } void StrutsTest::testMoveWaylandPanel() { // this test verifies that repositioning a Wayland panel updates the client area using namespace KWayland::Client; const QRect windowGeometry(0, 1000, 1280, 24); - QScopedPointer surface(m_compositor->createSurface()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer surface(Test::createSurface()); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); Q_UNUSED(shellSurface) QScopedPointer plasmaSurface(m_plasmaShell->createSurface(surface.data())); plasmaSurface->setPosition(windowGeometry.topLeft()); @@ -317,11 +228,7 @@ QVERIFY(windowCreatedSpy.isValid()); // map the window - QImage img(windowGeometry.size(), QImage::Format_RGB32); - img.fill(Qt::red); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(QPoint(0, 0), windowGeometry.size())); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), windowGeometry.size(), Qt::red, QImage::Format_RGB32); QVERIFY(windowCreatedSpy.wait()); QCOMPARE(windowCreatedSpy.count(), 1); @@ -362,8 +269,8 @@ // create first top panel const QRect windowGeometry(0, 0, 1280, 60); - QScopedPointer surface(m_compositor->createSurface()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer surface(Test::createSurface()); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); Q_UNUSED(shellSurface) QScopedPointer plasmaSurface(m_plasmaShell->createSurface(surface.data())); plasmaSurface->setPosition(windowGeometry.topLeft()); @@ -373,11 +280,7 @@ QVERIFY(windowCreatedSpy.isValid()); // map the first panel - QImage img(windowGeometry.size(), QImage::Format_RGB32); - img.fill(Qt::red); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(QPoint(0, 0), windowGeometry.size())); - surface->commit(Surface::CommitFlag::None); + Test::render(surface.data(), windowGeometry.size(), Qt::red, QImage::Format_RGB32); QVERIFY(windowCreatedSpy.wait()); QCOMPARE(windowCreatedSpy.count(), 1); @@ -398,18 +301,14 @@ // create another bottom panel const QRect windowGeometry2(0, 874, 1280, 150); - QScopedPointer surface2(m_compositor->createSurface()); - QScopedPointer shellSurface2(m_shell->createSurface(surface2.data())); + QScopedPointer surface2(Test::createSurface()); + QScopedPointer shellSurface2(Test::createShellSurface(surface2.data())); Q_UNUSED(shellSurface2) QScopedPointer plasmaSurface2(m_plasmaShell->createSurface(surface2.data())); plasmaSurface2->setPosition(windowGeometry2.topLeft()); plasmaSurface2->setRole(PlasmaShellSurface::Role::Panel); - QImage img2(windowGeometry2.size(), QImage::Format_RGB32); - img2.fill(Qt::blue); - surface2->attachBuffer(m_shm->createBuffer(img2)); - surface2->damage(QRect(QPoint(0, 0), windowGeometry2.size())); - surface2->commit(Surface::CommitFlag::None); + Test::render(surface2.data(), windowGeometry2.size(), Qt::blue, QImage::Format_RGB32); QVERIFY(windowCreatedSpy.wait()); QCOMPARE(windowCreatedSpy.count(), 1); diff --git a/autotests/integration/test_helpers.cpp b/autotests/integration/test_helpers.cpp new file mode 100644 --- /dev/null +++ b/autotests/integration/test_helpers.cpp @@ -0,0 +1,281 @@ +/******************************************************************** +KWin - the KDE window manager +This file is part of the KDE project. + +Copyright (C) 2015 Martin Gräßlin + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ +#include "kwin_wayland_test.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace KWayland::Client; + +namespace KWin +{ +namespace Test +{ + +static struct { + ConnectionThread *connection = nullptr; + EventQueue *queue = nullptr; + Compositor *compositor = nullptr; + ServerSideDecorationManager *decoration = nullptr; + Shell *shell = nullptr; + ShmPool *shm = nullptr; + Seat *seat = nullptr; + PlasmaShell *plasmaShell = nullptr; + PlasmaWindowManagement *windowManagement = nullptr; + QThread *thread = nullptr; +} s_waylandConnection; + +bool setupWaylandConnection(const QString &socketName, AdditionalWaylandInterfaces flags) +{ + if (s_waylandConnection.connection) { + return false; + } + // setup connection + s_waylandConnection.connection = new ConnectionThread; + QSignalSpy connectedSpy(s_waylandConnection.connection, &ConnectionThread::connected); + if (!connectedSpy.isValid()) { + return false; + } + s_waylandConnection.connection->setSocketName(socketName); + + s_waylandConnection.thread = new QThread(kwinApp()); + s_waylandConnection.connection->moveToThread(s_waylandConnection.thread); + s_waylandConnection.thread->start(); + + s_waylandConnection.connection->initConnection(); + if (!connectedSpy.wait()) { + return false; + } + + s_waylandConnection.queue = new EventQueue; + s_waylandConnection.queue->setup(s_waylandConnection.connection); + if (!s_waylandConnection.queue->isValid()) { + return false; + } + + Registry registry; + registry.setEventQueue(s_waylandConnection.queue); + QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); + if (!allAnnounced.isValid()) { + return false; + } + registry.create(s_waylandConnection.connection); + if (!registry.isValid()) { + return false; + } + registry.setup(); + if (!allAnnounced.wait()) { + return false; + } + + s_waylandConnection.compositor = registry.createCompositor(registry.interface(Registry::Interface::Compositor).name, registry.interface(Registry::Interface::Compositor).version); + if (!s_waylandConnection.compositor->isValid()) { + return false; + } + s_waylandConnection.shm = registry.createShmPool(registry.interface(Registry::Interface::Shm).name, registry.interface(Registry::Interface::Shm).version); + if (!s_waylandConnection.shm->isValid()) { + return false; + } + s_waylandConnection.shell = registry.createShell(registry.interface(Registry::Interface::Shell).name, registry.interface(Registry::Interface::Shell).version); + if (!s_waylandConnection.shell->isValid()) { + return false; + } + if (flags.testFlag(AdditionalWaylandInterface::Seat)) { + s_waylandConnection.seat = registry.createSeat(registry.interface(Registry::Interface::Seat).name, registry.interface(Registry::Interface::Seat).version); + if (!s_waylandConnection.seat->isValid()) { + return false; + } + } + if (flags.testFlag(AdditionalWaylandInterface::Decoration)) { + s_waylandConnection.decoration = registry.createServerSideDecorationManager(registry.interface(Registry::Interface::ServerSideDecorationManager).name, + registry.interface(Registry::Interface::ServerSideDecorationManager).version); + if (!s_waylandConnection.decoration->isValid()) { + return false; + } + } + if (flags.testFlag(AdditionalWaylandInterface::PlasmaShell)) { + s_waylandConnection.plasmaShell = registry.createPlasmaShell(registry.interface(Registry::Interface::PlasmaShell).name, + registry.interface(Registry::Interface::PlasmaShell).version); + if (!s_waylandConnection.plasmaShell->isValid()) { + return false; + } + } + if (flags.testFlag(AdditionalWaylandInterface::WindowManagement)) { + s_waylandConnection.windowManagement = registry.createPlasmaWindowManagement(registry.interface(Registry::Interface::PlasmaWindowManagement).name, + registry.interface(Registry::Interface::PlasmaWindowManagement).version); + if (!s_waylandConnection.windowManagement->isValid()) { + return false; + } + } + + return true; +} + +void destroyWaylandConnection() +{ + delete s_waylandConnection.compositor; + s_waylandConnection.compositor = nullptr; + delete s_waylandConnection.windowManagement; + s_waylandConnection.windowManagement = nullptr; + delete s_waylandConnection.plasmaShell; + s_waylandConnection.plasmaShell = nullptr; + delete s_waylandConnection.decoration; + s_waylandConnection.decoration = nullptr; + delete s_waylandConnection.decoration; + s_waylandConnection.decoration = nullptr; + delete s_waylandConnection.seat; + s_waylandConnection.seat = nullptr; + delete s_waylandConnection.shell; + s_waylandConnection.shell = nullptr; + delete s_waylandConnection.shm; + s_waylandConnection.shm = nullptr; + delete s_waylandConnection.queue; + s_waylandConnection.queue = nullptr; + if (s_waylandConnection.thread) { + QSignalSpy spy(s_waylandConnection.connection, &QObject::destroyed); + s_waylandConnection.connection->deleteLater(); + QVERIFY(spy.wait()); + s_waylandConnection.thread->quit(); + s_waylandConnection.thread->wait(); + delete s_waylandConnection.thread; + s_waylandConnection.thread = nullptr; + s_waylandConnection.connection = nullptr; + } +} + +ConnectionThread *waylandConnection() +{ + return s_waylandConnection.connection; +} + +Compositor *waylandCompositor() +{ + return s_waylandConnection.compositor; +} + +Shell *waylandShell() +{ + return s_waylandConnection.shell; +} + +ShmPool *waylandShmPool() +{ + return s_waylandConnection.shm; +} + +Seat *waylandSeat() +{ + return s_waylandConnection.seat; +} + +ServerSideDecorationManager *waylandServerSideDecoration() +{ + return s_waylandConnection.decoration; +} + +PlasmaShell *waylandPlasmaShell() +{ + return s_waylandConnection.plasmaShell; +} + +PlasmaWindowManagement *waylandWindowManagement() +{ + return s_waylandConnection.windowManagement; +} + +bool waitForWaylandPointer() +{ + if (!s_waylandConnection.seat) { + return false; + } + QSignalSpy hasPointerSpy(s_waylandConnection.seat, &Seat::hasPointerChanged); + if (!hasPointerSpy.isValid()) { + return false; + } + return hasPointerSpy.wait(); +} + +bool waitForWaylandTouch() +{ + if (!s_waylandConnection.seat) { + return false; + } + QSignalSpy hasTouchSpy(s_waylandConnection.seat, &Seat::hasTouchChanged); + if (!hasTouchSpy.isValid()) { + return false; + } + return hasTouchSpy.wait(); +} + +void render(Surface *surface, const QSize &size, const QColor &color, const QImage::Format &format) +{ + QImage img(size, format); + img.fill(color); + surface->attachBuffer(s_waylandConnection.shm->createBuffer(img)); + surface->damage(QRect(QPoint(0, 0), size)); + surface->commit(Surface::CommitFlag::None); +} + +void flushWaylandConnection() +{ + if (s_waylandConnection.connection) { + s_waylandConnection.connection->flush(); + } +} + +Surface *createSurface(QObject *parent) +{ + if (!s_waylandConnection.compositor) { + return nullptr; + } + auto s = s_waylandConnection.compositor->createSurface(parent); + if (!s->isValid()) { + delete s; + return nullptr; + } + return s; +} + +ShellSurface *createShellSurface(Surface *surface, QObject *parent) +{ + if (!s_waylandConnection.shell) { + return nullptr; + } + auto s = s_waylandConnection.shell->createSurface(surface, parent); + if (!s->isValid()) { + delete s; + return nullptr; + } + return s; +} + +} +} diff --git a/autotests/integration/touch_input_test.cpp b/autotests/integration/touch_input_test.cpp --- a/autotests/integration/touch_input_test.cpp +++ b/autotests/integration/touch_input_test.cpp @@ -27,11 +27,8 @@ #include #include -#include -#include #include #include -#include #include #include @@ -53,14 +50,7 @@ private: AbstractClient *showWindow(); - KWayland::Client::ConnectionThread *m_connection = nullptr; - KWayland::Client::Compositor *m_compositor = nullptr; - KWayland::Client::Seat *m_seat = nullptr; - KWayland::Client::ShmPool *m_shm = nullptr; - KWayland::Client::Shell *m_shell = nullptr; KWayland::Client::Touch *m_touch = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; void TouchInputTest::initTestCase() @@ -84,57 +74,9 @@ void TouchInputTest::init() { using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - QVERIFY(seatSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - QVERIFY(!seatSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); - m_seat = registry.createSeat(seatSpy.first().first().value(), seatSpy.first().last().value(), this); - QVERIFY(m_seat->isValid()); - QSignalSpy hasTouchSpy(m_seat, &Seat::hasTouchChanged); - QVERIFY(hasTouchSpy.isValid()); - QVERIFY(hasTouchSpy.wait()); - m_touch = m_seat->createTouch(m_seat); + QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); + QVERIFY(Test::waitForWaylandTouch()); + m_touch = Test::waylandSeat()->createTouch(Test::waylandSeat()); QVERIFY(m_touch); QVERIFY(m_touch->isValid()); @@ -144,26 +86,9 @@ void TouchInputTest::cleanup() { - delete m_compositor; - m_compositor = nullptr; delete m_touch; m_touch = nullptr; - delete m_seat; - m_seat = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_connection->deleteLater(); - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - m_connection = nullptr; - } + Test::destroyWaylandConnection(); } AbstractClient *TouchInputTest::showWindow() @@ -178,18 +103,14 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); VERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); + Surface *surface = Test::createSurface(Test::waylandCompositor()); VERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); VERIFY(shellSurface); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface, QSize(100, 50), Qt::blue); - m_connection->flush(); + Test::flushWaylandConnection(); VERIFY(clientAddedSpy.wait()); AbstractClient *c = workspace()->activeClient(); VERIFY(c); diff --git a/autotests/integration/transient_no_input_test.cpp b/autotests/integration/transient_no_input_test.cpp --- a/autotests/integration/transient_no_input_test.cpp +++ b/autotests/integration/transient_no_input_test.cpp @@ -27,10 +27,7 @@ #include #include -#include -#include #include -#include #include namespace KWin @@ -46,14 +43,6 @@ void init(); void cleanup(); void testTransientNoFocus(); - -private: - KWayland::Client::ConnectionThread *m_connection = nullptr; - KWayland::Client::Compositor *m_compositor = nullptr; - KWayland::Client::ShmPool *m_shm = nullptr; - KWayland::Client::Shell *m_shell = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; void TransientNoInputTest::initTestCase() @@ -69,68 +58,12 @@ void TransientNoInputTest::init() { - using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); + QVERIFY(Test::setupWaylandConnection(s_socketName)); } void TransientNoInputTest::cleanup() { - delete m_compositor; - m_compositor = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - } - + Test::destroyWaylandConnection(); } void TransientNoInputTest::testTransientNoFocus() @@ -140,38 +73,30 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); QVERIFY(clientAddedSpy.isValid()); - QScopedPointer surface(m_compositor->createSurface()); + QScopedPointer surface(Test::createSurface()); QVERIFY(!surface.isNull()); - QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QScopedPointer shellSurface(Test::createShellSurface(surface.data())); QVERIFY(!shellSurface.isNull()); // let's render - QImage img(QSize(100, 50), QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(0, 0, 100, 50)); - surface->commit(); + Test::render(surface.data(), QSize(100, 50), Qt::blue); - m_connection->flush(); + Test::flushWaylandConnection(); QVERIFY(clientAddedSpy.wait()); AbstractClient *c = workspace()->activeClient(); QVERIFY(c); QCOMPARE(clientAddedSpy.first().first().value(), c); // let's create a transient with no input - QScopedPointer transientSurface(m_compositor->createSurface()); + QScopedPointer transientSurface(Test::createSurface()); QVERIFY(!transientSurface.isNull()); - QScopedPointer transientShellSurface(m_shell->createSurface(transientSurface.data())); + QScopedPointer transientShellSurface(Test::createShellSurface(transientSurface.data())); QVERIFY(!transientShellSurface.isNull()); transientShellSurface->setTransient(surface.data(), QPoint(10, 20), ShellSurface::TransientFlag::NoFocus); - m_connection->flush(); + Test::flushWaylandConnection(); // let's render - QImage img2(QSize(200, 20), QImage::Format_ARGB32); - img2.fill(Qt::red); - transientSurface->attachBuffer(m_shm->createBuffer(img2)); - transientSurface->damage(QRect(0, 0, 200, 20)); - transientSurface->commit(); - m_connection->flush(); + Test::render(transientSurface.data(), QSize(200, 20), Qt::red); + Test::flushWaylandConnection(); QVERIFY(clientAddedSpy.wait()); // get the latest ShellClient auto transientClient = clientAddedSpy.last().first().value(); diff --git a/autotests/integration/transient_placement.cpp b/autotests/integration/transient_placement.cpp --- a/autotests/integration/transient_placement.cpp +++ b/autotests/integration/transient_placement.cpp @@ -63,14 +63,6 @@ private: AbstractClient *showWindow(const QSize &size, bool decorated = false, KWayland::Client::Surface *parent = nullptr, const QPoint &offset = QPoint()); KWayland::Client::Surface *surfaceForClient(AbstractClient *c) const; - KWayland::Client::ConnectionThread *m_connection = nullptr; - KWayland::Client::Compositor *m_compositor = nullptr; - KWayland::Client::ServerSideDecorationManager *m_deco = nullptr; - KWayland::Client::Seat *m_seat = nullptr; - KWayland::Client::ShmPool *m_shm = nullptr; - KWayland::Client::Shell *m_shell = nullptr; - KWayland::Client::EventQueue *m_queue = nullptr; - QThread *m_thread = nullptr; }; void TransientPlacementTest::initTestCase() @@ -94,87 +86,15 @@ void TransientPlacementTest::init() { - using namespace KWayland::Client; - // setup connection - m_connection = new ConnectionThread; - QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); - QVERIFY(connectedSpy.isValid()); - m_connection->setSocketName(s_socketName); - - m_thread = new QThread(this); - m_connection->moveToThread(m_thread); - m_thread->start(); - - m_connection->initConnection(); - QVERIFY(connectedSpy.wait()); - - m_queue = new EventQueue(this); - QVERIFY(!m_queue->isValid()); - m_queue->setup(m_connection); - QVERIFY(m_queue->isValid()); - - Registry registry; - registry.setEventQueue(m_queue); - QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); - QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); - QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); - QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); - QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); - QVERIFY(allAnnounced.isValid()); - QVERIFY(shmSpy.isValid()); - QVERIFY(shellSpy.isValid()); - QVERIFY(compositorSpy.isValid()); - QVERIFY(seatSpy.isValid()); - registry.create(m_connection->display()); - QVERIFY(registry.isValid()); - registry.setup(); - QVERIFY(allAnnounced.wait()); - QVERIFY(!compositorSpy.isEmpty()); - QVERIFY(!shmSpy.isEmpty()); - QVERIFY(!shellSpy.isEmpty()); - QVERIFY(!seatSpy.isEmpty()); - - m_compositor = registry.createCompositor(compositorSpy.first().first().value(), compositorSpy.first().last().value(), this); - QVERIFY(m_compositor->isValid()); - m_shm = registry.createShmPool(shmSpy.first().first().value(), shmSpy.first().last().value(), this); - QVERIFY(m_shm->isValid()); - m_shell = registry.createShell(shellSpy.first().first().value(), shellSpy.first().last().value(), this); - QVERIFY(m_shell->isValid()); - m_seat = registry.createSeat(seatSpy.first().first().value(), seatSpy.first().last().value(), this); - QVERIFY(m_seat->isValid()); - QSignalSpy hasPointerSpy(m_seat, &Seat::hasPointerChanged); - QVERIFY(hasPointerSpy.isValid()); - QVERIFY(hasPointerSpy.wait()); - - m_deco = registry.createServerSideDecorationManager(registry.interface(Registry::Interface::ServerSideDecorationManager).name, registry.interface(Registry::Interface::ServerSideDecorationManager).version, this); - QVERIFY(m_deco->isValid()); + QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration)); screens()->setCurrent(0); Cursor::setPos(QPoint(640, 512)); } void TransientPlacementTest::cleanup() { - delete m_deco; - m_deco = nullptr; - delete m_compositor; - m_compositor = nullptr; - delete m_seat; - m_seat = nullptr; - delete m_shm; - m_shm = nullptr; - delete m_shell; - m_shell = nullptr; - delete m_queue; - m_queue = nullptr; - if (m_thread) { - m_connection->deleteLater(); - m_thread->quit(); - m_thread->wait(); - delete m_thread; - m_thread = nullptr; - m_connection = nullptr; - } + Test::destroyWaylandConnection(); } AbstractClient *TransientPlacementTest::showWindow(const QSize &size, bool decorated, KWayland::Client::Surface *parent, const QPoint &offset) @@ -189,30 +109,26 @@ QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); VERIFY(clientAddedSpy.isValid()); - Surface *surface = m_compositor->createSurface(m_compositor); + Surface *surface = Test::createSurface(Test::waylandCompositor()); VERIFY(surface); - ShellSurface *shellSurface = m_shell->createSurface(surface, surface); + ShellSurface *shellSurface = Test::createShellSurface(surface, surface); VERIFY(shellSurface); if (parent) { shellSurface->setTransient(parent, offset); } if (decorated) { - auto deco = m_deco->create(surface, surface); + auto deco = Test::waylandServerSideDecoration()->create(surface, surface); QSignalSpy decoSpy(deco, &ServerSideDecoration::modeChanged); VERIFY(decoSpy.isValid()); VERIFY(decoSpy.wait()); deco->requestMode(ServerSideDecoration::Mode::Server); VERIFY(decoSpy.wait()); COMPARE(deco->mode(), ServerSideDecoration::Mode::Server); } // let's render - QImage img(size, QImage::Format_ARGB32); - img.fill(Qt::blue); - surface->attachBuffer(m_shm->createBuffer(img)); - surface->damage(QRect(QPoint(0, 0), size)); - surface->commit(Surface::CommitFlag::None); + Test::render(surface, size, Qt::blue); - m_connection->flush(); + Test::flushWaylandConnection(); VERIFY(clientAddedSpy.wait()); AbstractClient *c = workspace()->activeClient(); VERIFY(c);