diff --git a/src/wayland/test_wayland_registry.cpp b/src/wayland/test_wayland_registry.cpp index cecd575038..2cd6242262 100644 --- a/src/wayland/test_wayland_registry.cpp +++ b/src/wayland/test_wayland_registry.cpp @@ -22,6 +22,11 @@ along with this program. If not, see . // KWin #include "../../wayland_client/connection_thread.h" #include "../../wayland_client/registry.h" +#include "../wayland_server/compositor_interface.h" +#include "../../wayland_server/display.h" +#include "../wayland_server/output_interface.h" +#include "../wayland_server/seat_interface.h" +#include "../wayland_server/shell_interface.h" // Wayland #include @@ -40,64 +45,52 @@ private Q_SLOTS: void testBindOutput(); void testBindShm(); void testBindSeat(); - - // TODO: add tests for removal - requires more control over the compositor + void testRemoval(); private: - QProcess *m_westonProcess; + KWin::WaylandServer::Display *m_display; + KWin::WaylandServer::CompositorInterface *m_compositor; + KWin::WaylandServer::OutputInterface *m_output; + KWin::WaylandServer::SeatInterface *m_seat; + KWin::WaylandServer::ShellInterface *m_shell; }; static const QString s_socketName = QStringLiteral("kwin-test-wayland-registry-0"); TestWaylandRegistry::TestWaylandRegistry(QObject *parent) : QObject(parent) - , m_westonProcess(nullptr) + , m_display(nullptr) + , m_compositor(nullptr) + , m_output(nullptr) + , m_seat(nullptr) + , m_shell(nullptr) { } void TestWaylandRegistry::init() { - QVERIFY(!m_westonProcess); - // starts weston - m_westonProcess = new QProcess(this); - m_westonProcess->setProgram(QStringLiteral("weston")); - - m_westonProcess->setArguments(QStringList({QStringLiteral("--socket=%1").arg(s_socketName), QStringLiteral("--use-pixman")})); - m_westonProcess->start(); - QVERIFY(m_westonProcess->waitForStarted()); - - // wait for the socket to appear - QDir runtimeDir(qgetenv("XDG_RUNTIME_DIR")); - if (runtimeDir.exists(s_socketName)) { - return; - } - QFileSystemWatcher *socketWatcher = new QFileSystemWatcher(QStringList({runtimeDir.absolutePath()}), this); - QSignalSpy socketSpy(socketWatcher, SIGNAL(directoryChanged(QString))); - - // limit to maximum of 10 waits - for (int i = 0; i < 10; ++i) { - QVERIFY(socketSpy.wait()); - if (runtimeDir.exists(s_socketName)) { - delete socketWatcher; - return; - } - } + m_display = new KWin::WaylandServer::Display(); + m_display->setSocketName(s_socketName); + m_display->start(); + m_display->createShm(); + m_compositor = m_display->createCompositor(); + m_compositor->create(); + m_output = m_display->createOutput(); + m_output->create(); + m_seat = m_display->createSeat(); + m_seat->create(); + m_shell = m_display->createShell(); + m_shell->create(); } void TestWaylandRegistry::cleanup() { - // terminates weston - m_westonProcess->terminate(); - QVERIFY(m_westonProcess->waitForFinished()); - delete m_westonProcess; - m_westonProcess = nullptr; + delete m_display; + m_display = nullptr; } void TestWaylandRegistry::testCreate() { - if (m_westonProcess->state() != QProcess::Running) { - QSKIP("This test requires a running wayland server"); - } KWin::Wayland::ConnectionThread connection; QSignalSpy connectedSpy(&connection, SIGNAL(connected())); connection.setSocketName(s_socketName); @@ -113,9 +106,6 @@ void TestWaylandRegistry::testCreate() } #define TEST_BIND(interface, signalName, bindMethod, destroyFunction) \ - if (m_westonProcess->state() != QProcess::Running) { \ - QSKIP("This test requires a running wayland server"); \ - } \ KWin::Wayland::ConnectionThread connection; \ QSignalSpy connectedSpy(&connection, SIGNAL(connected())); \ connection.setSocketName(s_socketName); \ @@ -176,5 +166,82 @@ void TestWaylandRegistry::testBindShm() #undef TEST_BIND +void TestWaylandRegistry::testRemoval() +{ + KWin::Wayland::ConnectionThread connection; + QSignalSpy connectedSpy(&connection, SIGNAL(connected())); + connection.setSocketName(s_socketName); + connection.initConnection(); + QVERIFY(connectedSpy.wait()); + connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::aboutToBlock, &connection, + [&connection] { + wl_display_flush(connection.display()); + } + ); + + KWin::Wayland::Registry registry; + QSignalSpy shmAnnouncedSpy(®istry, SIGNAL(shmAnnounced(quint32,quint32))); + QVERIFY(shmAnnouncedSpy.isValid()); + QSignalSpy compositorAnnouncedSpy(®istry, SIGNAL(compositorAnnounced(quint32,quint32))); + QVERIFY(compositorAnnouncedSpy.isValid()); + QSignalSpy outputAnnouncedSpy(®istry, SIGNAL(outputAnnounced(quint32,quint32))); + QVERIFY(outputAnnouncedSpy.isValid()); + QSignalSpy shellAnnouncedSpy(®istry, SIGNAL(shellAnnounced(quint32,quint32))); + QVERIFY(shellAnnouncedSpy.isValid()); + QSignalSpy seatAnnouncedSpy(®istry, SIGNAL(seatAnnounced(quint32,quint32))); + QVERIFY(seatAnnouncedSpy.isValid()); + + QVERIFY(!registry.isValid()); + registry.create(connection.display()); + registry.setup(); + + QVERIFY(shmAnnouncedSpy.wait()); + QVERIFY(!compositorAnnouncedSpy.isEmpty()); + QVERIFY(!outputAnnouncedSpy.isEmpty()); + QVERIFY(!shellAnnouncedSpy.isEmpty()); + QVERIFY(!seatAnnouncedSpy.isEmpty()); + + QVERIFY(registry.hasInterface(KWin::Wayland::Registry::Interface::Compositor)); + QVERIFY(registry.hasInterface(KWin::Wayland::Registry::Interface::Output)); + QVERIFY(registry.hasInterface(KWin::Wayland::Registry::Interface::Seat)); + QVERIFY(registry.hasInterface(KWin::Wayland::Registry::Interface::Shell)); + QVERIFY(registry.hasInterface(KWin::Wayland::Registry::Interface::Shm)); + QVERIFY(!registry.hasInterface(KWin::Wayland::Registry::Interface::FullscreenShell)); + + QSignalSpy seatRemovedSpy(®istry, SIGNAL(seatRemoved(quint32))); + QVERIFY(seatRemovedSpy.isValid()); + + delete m_seat; + QVERIFY(seatRemovedSpy.wait()); + QCOMPARE(seatRemovedSpy.first().first(), seatAnnouncedSpy.first().first()); + QVERIFY(!registry.hasInterface(KWin::Wayland::Registry::Interface::Seat)); + + QSignalSpy shellRemovedSpy(®istry, SIGNAL(shellRemoved(quint32))); + QVERIFY(shellRemovedSpy.isValid()); + + delete m_shell; + QVERIFY(shellRemovedSpy.wait()); + QCOMPARE(shellRemovedSpy.first().first(), shellAnnouncedSpy.first().first()); + QVERIFY(!registry.hasInterface(KWin::Wayland::Registry::Interface::Shell)); + + QSignalSpy outputRemovedSpy(®istry, SIGNAL(outputRemoved(quint32))); + QVERIFY(outputRemovedSpy.isValid()); + + delete m_output; + QVERIFY(outputRemovedSpy.wait()); + QCOMPARE(outputRemovedSpy.first().first(), outputAnnouncedSpy.first().first()); + QVERIFY(!registry.hasInterface(KWin::Wayland::Registry::Interface::Output)); + + QSignalSpy compositorRemovedSpy(®istry, SIGNAL(compositorRemoved(quint32))); + QVERIFY(compositorRemovedSpy.isValid()); + + delete m_compositor; + QVERIFY(compositorRemovedSpy.wait()); + QCOMPARE(compositorRemovedSpy.first().first(), compositorAnnouncedSpy.first().first()); + QVERIFY(!registry.hasInterface(KWin::Wayland::Registry::Interface::Compositor)); + + // cannot test shmRemoved as there is no functionality for it +} + QTEST_MAIN(TestWaylandRegistry) #include "test_wayland_registry.moc"