From aa2cc874e248c029c929a7f7afacbf88c1e71799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 9 Mar 2016 16:16:29 +0100 Subject: [PATCH 1/3] [server] Declare metatype for KWayland::Server::PlasmaShellSurfaceInterface::Role --- src/wayland/plasmashell_interface.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wayland/plasmashell_interface.h b/src/wayland/plasmashell_interface.h index eca7f39089..ae7d23a50f 100644 --- a/src/wayland/plasmashell_interface.h +++ b/src/wayland/plasmashell_interface.h @@ -170,4 +170,6 @@ private: } } +Q_DECLARE_METATYPE(KWayland::Server::PlasmaShellSurfaceInterface::Role) + #endif From e3dc783548810818becd32d7f1e69ef59e0ecdc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 9 Mar 2016 16:17:01 +0100 Subject: [PATCH 2/3] [autotests] Add test case for PlasmaShellSurface setting role --- src/wayland/autotests/client/CMakeLists.txt | 12 ++ .../autotests/client/test_plasmashell.cpp | 194 ++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 src/wayland/autotests/client/test_plasmashell.cpp diff --git a/src/wayland/autotests/client/CMakeLists.txt b/src/wayland/autotests/client/CMakeLists.txt index a73f94cc62..36310fb74f 100644 --- a/src/wayland/autotests/client/CMakeLists.txt +++ b/src/wayland/autotests/client/CMakeLists.txt @@ -233,3 +233,15 @@ add_executable(testServerSideDecoration ${testServerSideDecoration_SRCS}) target_link_libraries( testServerSideDecoration Qt5::Test Qt5::Gui KF5::WaylandClient KF5::WaylandServer Wayland::Client) add_test(kwayland-testServerSideDecoration testServerSideDecoration) ecm_mark_as_test(testServerSideDecoration) + + +######################################################## +# Test PlasmaShell +######################################################## +set( testPlasmaShell_SRCS + test_plasmashell.cpp + ) +add_executable(testPlasmaShell ${testPlasmaShell_SRCS}) +target_link_libraries( testPlasmaShell Qt5::Test Qt5::Gui KF5::WaylandClient KF5::WaylandServer Wayland::Client) +add_test(kwayland-testPlasmaShell testPlasmaShell) +ecm_mark_as_test(testPlasmaShell) diff --git a/src/wayland/autotests/client/test_plasmashell.cpp b/src/wayland/autotests/client/test_plasmashell.cpp new file mode 100644 index 0000000000..56bd6ea797 --- /dev/null +++ b/src/wayland/autotests/client/test_plasmashell.cpp @@ -0,0 +1,194 @@ +/******************************************************************** +Copyright 2016 Martin Gräßlin + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) version 3, or any +later version accepted by the membership of KDE e.V. (or its +successor approved by the membership of KDE e.V.), which shall +act as a proxy defined in Section 6 of version 3 of the license. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library. If not, see . +*********************************************************************/ +// Qt +#include +// KWayland +#include "../../src/client/connection_thread.h" +#include "../../src/client/compositor.h" +#include "../../src/client/event_queue.h" +#include "../../src/client/registry.h" +#include "../../src/client/surface.h" +#include "../../src/client/plasmashell.h" +#include "../../src/server/display.h" +#include "../../src/server/compositor_interface.h" +#include "../../src/server/plasmashell_interface.h" + + +using namespace KWayland::Client; +using namespace KWayland::Server; + + +class TestPlasmaShell : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void init(); + void cleanup(); + + + void testRole_data(); + void testRole(); + +private: + Display *m_display = nullptr; + CompositorInterface *m_compositorInterface = nullptr; + PlasmaShellInterface *m_plasmaShellInterface = nullptr; + + ConnectionThread *m_connection = nullptr; + Compositor *m_compositor = nullptr; + EventQueue *m_queue = nullptr; + QThread *m_thread = nullptr; + Registry *m_registry = nullptr; + PlasmaShell *m_plasmaShell = nullptr; +}; + +static const QString s_socketName = QStringLiteral("kwayland-test-wayland-plasma-shell-0"); + +void TestPlasmaShell::init() +{ + delete m_display; + m_display = new Display(this); + m_display->setSocketName(s_socketName); + m_display->start(); + QVERIFY(m_display->isRunning()); + + m_compositorInterface = m_display->createCompositor(m_display); + m_compositorInterface->create(); + m_display->createShm(); + + m_plasmaShellInterface = m_display->createPlasmaShell(m_display); + m_plasmaShellInterface->create(); + + // setup connection + m_connection = new KWayland::Client::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()); + + m_registry = new Registry(); + QSignalSpy interfacesAnnouncedSpy(m_registry, &Registry::interfaceAnnounced); + QVERIFY(interfacesAnnouncedSpy.isValid()); + + QVERIFY(!m_registry->eventQueue()); + m_registry->setEventQueue(m_queue); + QCOMPARE(m_registry->eventQueue(), m_queue); + m_registry->create(m_connection); + QVERIFY(m_registry->isValid()); + m_registry->setup(); + + QVERIFY(interfacesAnnouncedSpy.wait()); +#define CREATE(variable, factory, iface) \ + variable = m_registry->create##factory(m_registry->interface(Registry::Interface::iface).name, m_registry->interface(Registry::Interface::iface).version, this); \ + QVERIFY(variable); + + CREATE(m_compositor, Compositor, Compositor) + CREATE(m_plasmaShell, PlasmaShell, PlasmaShell) + +#undef CREATE + +} + +void TestPlasmaShell::cleanup() +{ +#define DELETE(name) \ + if (name) { \ + delete name; \ + name = nullptr; \ + } + DELETE(m_plasmaShell) + DELETE(m_compositor) + DELETE(m_queue) + DELETE(m_registry) +#undef DELETE + if (m_thread) { + m_thread->quit(); + m_thread->wait(); + delete m_thread; + m_thread = nullptr; + } + delete m_connection; + m_connection = nullptr; + + delete m_display; + m_display = nullptr; +} + +void TestPlasmaShell::testRole_data() +{ + QTest::addColumn("clientRole"); + QTest::addColumn("serverRole"); + + QTest::newRow("desktop") << PlasmaShellSurface::Role::Desktop << PlasmaShellSurfaceInterface::Role::Desktop; + QTest::newRow("osd") << PlasmaShellSurface::Role::OnScreenDisplay << PlasmaShellSurfaceInterface::Role::OnScreenDisplay; + QTest::newRow("panel") << PlasmaShellSurface::Role::Panel << PlasmaShellSurfaceInterface::Role::Panel; +} + +void TestPlasmaShell::testRole() +{ + // this test verifies that setting the role on a plasma shell surface works + + // first create signal spies + QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated); + QVERIFY(surfaceCreatedSpy.isValid()); + QSignalSpy plasmaSurfaceCreatedSpy(m_plasmaShellInterface, &PlasmaShellInterface::surfaceCreated); + QVERIFY(plasmaSurfaceCreatedSpy.isValid()); + + // create the surface + QScopedPointer s(m_compositor->createSurface()); + QScopedPointer ps(m_plasmaShell->createSurface(s.data())); + + // and get them on the server + QVERIFY(plasmaSurfaceCreatedSpy.wait()); + QCOMPARE(plasmaSurfaceCreatedSpy.count(), 1); + QCOMPARE(surfaceCreatedSpy.count(), 1); + + // verify that we got a plasma shell surface + auto sps = plasmaSurfaceCreatedSpy.first().first().value(); + QVERIFY(sps); + QVERIFY(sps->surface()); + QCOMPARE(sps->surface(), surfaceCreatedSpy.first().first().value()); + + // default role should be normal + QCOMPARE(sps->role(), PlasmaShellSurfaceInterface::Role::Normal); + + // now change it + QSignalSpy roleChangedSpy(sps, &PlasmaShellSurfaceInterface::roleChanged); + QVERIFY(roleChangedSpy.isValid()); + QFETCH(PlasmaShellSurface::Role, clientRole); + ps->setRole(clientRole); + QVERIFY(roleChangedSpy.wait()); + QCOMPARE(roleChangedSpy.count(), 1); + QTEST(sps->role(), "serverRole"); +} + +QTEST_GUILESS_MAIN(TestPlasmaShell) +#include "test_plasmashell.moc" From 1d8319cb3b8132987cd6dc5083ba24bf6f2b8e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 9 Mar 2016 16:19:33 +0100 Subject: [PATCH 3/3] [server] Default initialize the role of a PlasmaShellSurface We want Normal as default and not a random value. --- src/wayland/plasmashell_interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wayland/plasmashell_interface.cpp b/src/wayland/plasmashell_interface.cpp index 1b10f3ce89..f082534d0c 100644 --- a/src/wayland/plasmashell_interface.cpp +++ b/src/wayland/plasmashell_interface.cpp @@ -72,7 +72,7 @@ public: SurfaceInterface *surface; QPoint m_globalPos; - Role m_role; + Role m_role = Role::Normal; bool m_positionSet = false; PanelBehavior m_panelBehavior = PanelBehavior::AlwaysVisible; bool m_skipTaskbar = false;