From 2922b8d0a7002f5cbc1b533b5fb4e133f6825c3b Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sun, 10 Mar 2024 21:52:47 +0200 Subject: [PATCH] autotests: Make xdg-toplevel-decoration-v1 factory function return a std::unique_ptr --- .../integration/decoration_input_test.cpp | 40 +++++++++---------- autotests/integration/kwin_wayland_test.h | 2 +- autotests/integration/test_helpers.cpp | 4 +- autotests/integration/touch_input_test.cpp | 18 +++++---- .../integration/xdgshellwindow_rules_test.cpp | 6 ++- 5 files changed, 37 insertions(+), 33 deletions(-) diff --git a/autotests/integration/decoration_input_test.cpp b/autotests/integration/decoration_input_test.cpp index fd81bf1fc9..319354e5cf 100644 --- a/autotests/integration/decoration_input_test.cpp +++ b/autotests/integration/decoration_input_test.cpp @@ -70,7 +70,7 @@ private Q_SLOTS: void testTooltipDoesntEatKeyEvents(); private: - std::tuple, std::unique_ptr> showWindow(); + std::tuple, std::unique_ptr, std::unique_ptr> showWindow(); }; #define MOTION(target) Test::pointerMotion(target, timestamp++) @@ -79,23 +79,23 @@ private: #define RELEASE Test::pointerButtonReleased(BTN_LEFT, timestamp++) -std::tuple, std::unique_ptr> DecorationInputTest::showWindow() +std::tuple, std::unique_ptr, std::unique_ptr> DecorationInputTest::showWindow() { #define VERIFY(statement) \ if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__)) \ - return {nullptr, nullptr, nullptr}; + return {nullptr, nullptr, nullptr, nullptr}; #define COMPARE(actual, expected) \ if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)) \ - return {nullptr, nullptr, nullptr}; + return {nullptr, nullptr, nullptr, nullptr}; std::unique_ptr surface{Test::createSurface()}; VERIFY(surface.get()); std::unique_ptr shellSurface = Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly); VERIFY(shellSurface.get()); - Test::XdgToplevelDecorationV1 *decoration = Test::createXdgToplevelDecorationV1(shellSurface.get(), shellSurface.get()); - VERIFY(decoration); + std::unique_ptr decoration = Test::createXdgToplevelDecorationV1(shellSurface.get()); + VERIFY(decoration.get()); - QSignalSpy decorationConfigureRequestedSpy(decoration, &Test::XdgToplevelDecorationV1::configureRequested); + QSignalSpy decorationConfigureRequestedSpy(decoration.get(), &Test::XdgToplevelDecorationV1::configureRequested); QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested); decoration->set_mode(Test::XdgToplevelDecorationV1::mode_server_side); @@ -112,7 +112,7 @@ std::tuple, std::unique_ptr #undef VERIFY #undef COMPARE - return {window, std::move(surface), std::move(shellSurface)}; + return {window, std::move(surface), std::move(shellSurface), std::move(decoration)}; } void DecorationInputTest::initTestCase() @@ -172,7 +172,7 @@ void DecorationInputTest::testAxis() { static constexpr double oneTick = 15; - const auto [window, surface, shellSurface] = showWindow(); + const auto [window, surface, shellSurface, decoration] = showWindow(); QVERIFY(window); QVERIFY(window->isDecorated()); QVERIFY(!window->noBorder()); @@ -216,7 +216,7 @@ void KWin::DecorationInputTest::testDoubleClickOnAllDesktops() group.sync(); workspace()->slotReconfigure(); - const auto [window, surface, shellSurface] = showWindow(); + const auto [window, surface, shellSurface, decoration] = showWindow(); QVERIFY(window); QVERIFY(window->isDecorated()); QVERIFY(!window->noBorder()); @@ -247,7 +247,7 @@ void DecorationInputTest::testDoubleClickClose() group.sync(); workspace()->slotReconfigure(); - auto [window, surface, shellSurface] = showWindow(); + auto [window, surface, shellSurface, decoration] = showWindow(); QVERIFY(window); QVERIFY(window->isDecorated()); quint32 timestamp = 1; @@ -277,7 +277,7 @@ void KWin::DecorationInputTest::testDoubleTap() group.sync(); workspace()->slotReconfigure(); - const auto [window, surface, shellSurface] = showWindow(); + const auto [window, surface, shellSurface, decoration] = showWindow(); QVERIFY(window); QVERIFY(window->isDecorated()); QVERIFY(!window->noBorder()); @@ -302,7 +302,7 @@ void KWin::DecorationInputTest::testDoubleTap() void DecorationInputTest::testHover() { - const auto [window, surface, shellSurface] = showWindow(); + const auto [window, surface, shellSurface, decoration] = showWindow(); QVERIFY(window); QVERIFY(window->isDecorated()); QVERIFY(!window->noBorder()); @@ -361,7 +361,7 @@ void DecorationInputTest::testPressToMove_data() void DecorationInputTest::testPressToMove() { - const auto [window, surface, shellSurface] = showWindow(); + const auto [window, surface, shellSurface, decoration] = showWindow(); QVERIFY(window); QVERIFY(window->isDecorated()); QVERIFY(!window->noBorder()); @@ -418,7 +418,7 @@ void DecorationInputTest::testTapToMove_data() void DecorationInputTest::testTapToMove() { - const auto [window, surface, shellSurface] = showWindow(); + const auto [window, surface, shellSurface, decoration] = showWindow(); QVERIFY(window); QVERIFY(window->isDecorated()); QVERIFY(!window->noBorder()); @@ -482,7 +482,7 @@ void DecorationInputTest::testResizeOutsideWindow() workspace()->slotReconfigure(); // now create window - const auto [window, surface, shellSurface] = showWindow(); + const auto [window, surface, shellSurface, decoration] = showWindow(); QVERIFY(window); QVERIFY(window->isDecorated()); QVERIFY(!window->noBorder()); @@ -576,7 +576,7 @@ void DecorationInputTest::testModifierClickUnrestrictedMove() QCOMPARE(options->commandAll3(), Options::MouseUnrestrictedMove); // create a window - const auto [window, surface, shellSurface] = showWindow(); + const auto [window, surface, shellSurface, decoration] = showWindow(); QVERIFY(window); QVERIFY(window->isDecorated()); QVERIFY(!window->noBorder()); @@ -638,7 +638,7 @@ void DecorationInputTest::testModifierScrollOpacity() group.sync(); workspace()->slotReconfigure(); - const auto [window, surface, shellSurface] = showWindow(); + const auto [window, surface, shellSurface, decoration] = showWindow(); QVERIFY(window); QVERIFY(window->isDecorated()); QVERIFY(!window->noBorder()); @@ -696,7 +696,7 @@ void DecorationInputTest::testTouchEvents() { // this test verifies that the decoration gets a hover leave event on touch release // see BUG 386231 - const auto [window, surface, shellSurface] = showWindow(); + const auto [window, surface, shellSurface, decoration] = showWindow(); QVERIFY(window); QVERIFY(window->isDecorated()); QVERIFY(!window->noBorder()); @@ -742,7 +742,7 @@ void DecorationInputTest::testTooltipDoesntEatKeyEvents() QVERIFY(keyboard); QSignalSpy enteredSpy(keyboard, &KWayland::Client::Keyboard::entered); - const auto [window, surface, shellSurface] = showWindow(); + const auto [window, surface, shellSurface, decoration] = showWindow(); QVERIFY(window); QVERIFY(window->isDecorated()); QVERIFY(!window->noBorder()); diff --git a/autotests/integration/kwin_wayland_test.h b/autotests/integration/kwin_wayland_test.h index b75092af21..1bca957979 100644 --- a/autotests/integration/kwin_wayland_test.h +++ b/autotests/integration/kwin_wayland_test.h @@ -709,7 +709,7 @@ std::unique_ptr createXdgPopupSurface(KWayland::Client::Surface *surfa XdgPositioner *positioner, CreationSetup configureMode = CreationSetup::CreateAndConfigure); -XdgToplevelDecorationV1 *createXdgToplevelDecorationV1(XdgToplevel *toplevel, QObject *parent = nullptr); +std::unique_ptr createXdgToplevelDecorationV1(XdgToplevel *toplevel); IdleInhibitorV1 *createIdleInhibitorV1(KWayland::Client::Surface *surface); AutoHideScreenEdgeV1 *createAutoHideScreenEdgeV1(KWayland::Client::Surface *surface, uint32_t border); CursorShapeDeviceV1 *createCursorShapeDeviceV1(KWayland::Client::Pointer *pointer); diff --git a/autotests/integration/test_helpers.cpp b/autotests/integration/test_helpers.cpp index be53e08748..f909a03270 100644 --- a/autotests/integration/test_helpers.cpp +++ b/autotests/integration/test_helpers.cpp @@ -1035,7 +1035,7 @@ std::unique_ptr createXdgPopupSurface(KWayland::Client::Surface *surfa return xdgPopup; } -XdgToplevelDecorationV1 *createXdgToplevelDecorationV1(XdgToplevel *toplevel, QObject *parent) +std::unique_ptr createXdgToplevelDecorationV1(XdgToplevel *toplevel) { XdgDecorationManagerV1 *manager = s_waylandConnection.xdgDecorationManagerV1; @@ -1044,7 +1044,7 @@ XdgToplevelDecorationV1 *createXdgToplevelDecorationV1(XdgToplevel *toplevel, QO return nullptr; } - return new XdgToplevelDecorationV1(manager, toplevel, parent); + return std::make_unique(manager, toplevel); } IdleInhibitorV1 *createIdleInhibitorV1(KWayland::Client::Surface *surface) diff --git a/autotests/integration/touch_input_test.cpp b/autotests/integration/touch_input_test.cpp index 727dd387e5..b0fc1ffb90 100644 --- a/autotests/integration/touch_input_test.cpp +++ b/autotests/integration/touch_input_test.cpp @@ -51,6 +51,7 @@ private: Window *window; std::unique_ptr surface; std::unique_ptr shellSurface; + std::unique_ptr decoration; }; WindowHandle showWindow(bool decorated = false); KWayland::Client::Touch *m_touch = nullptr; @@ -97,17 +98,18 @@ TouchInputTest::WindowHandle TouchInputTest::showWindow(bool decorated) { #define VERIFY(statement) \ if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__)) \ - return {nullptr, nullptr}; + return {}; #define COMPARE(actual, expected) \ if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)) \ - return {nullptr, nullptr}; + return {}; std::unique_ptr surface = Test::createSurface(); VERIFY(surface.get()); std::unique_ptr shellSurface = Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly); VERIFY(shellSurface.get()); + std::unique_ptr decoration; if (decorated) { - auto decoration = Test::createXdgToplevelDecorationV1(shellSurface.get(), shellSurface.get()); + decoration = Test::createXdgToplevelDecorationV1(shellSurface.get()); decoration->set_mode(Test::XdgToplevelDecorationV1::mode_server_side); } QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested); @@ -123,7 +125,7 @@ TouchInputTest::WindowHandle TouchInputTest::showWindow(bool decorated) #undef VERIFY #undef COMPARE - return {window, std::move(surface), std::move(shellSurface)}; + return {window, std::move(surface), std::move(shellSurface), std::move(decoration)}; } void TouchInputTest::testTouchHidesCursor() @@ -161,7 +163,7 @@ void TouchInputTest::testMultipleTouchPoints_data() void TouchInputTest::testMultipleTouchPoints() { QFETCH(bool, decorated); - auto [window, surface, shellSurface] = showWindow(decorated); + auto [window, surface, shellSurface, decoration] = showWindow(decorated); QCOMPARE(window->isDecorated(), decorated); window->move(QPoint(100, 100)); QVERIFY(window); @@ -216,7 +218,7 @@ void TouchInputTest::testMultipleTouchPoints() void TouchInputTest::testCancel() { - auto [window, surface, shellSurface] = showWindow(); + auto [window, surface, shellSurface, decoration] = showWindow(); window->move(QPoint(100, 100)); QVERIFY(window); QSignalSpy sequenceStartedSpy(m_touch, &KWayland::Client::Touch::sequenceStarted); @@ -239,9 +241,9 @@ void TouchInputTest::testTouchMouseAction() // this test verifies that a touch down on an inactive window will activate it // create two windows - auto [c1, surface, shellSurface] = showWindow(); + auto [c1, surface, shellSurface, decoration] = showWindow(); QVERIFY(c1); - auto [c2, surface2, shellSurface2] = showWindow(); + auto [c2, surface2, shellSurface2, decoration2] = showWindow(); QVERIFY(c2); QVERIFY(!c1->isActive()); diff --git a/autotests/integration/xdgshellwindow_rules_test.cpp b/autotests/integration/xdgshellwindow_rules_test.cpp index 81c130d284..af811162de 100644 --- a/autotests/integration/xdgshellwindow_rules_test.cpp +++ b/autotests/integration/xdgshellwindow_rules_test.cpp @@ -175,6 +175,7 @@ private: Window *m_window; std::unique_ptr m_surface; std::unique_ptr m_shellSurface; + std::unique_ptr m_decoration; std::unique_ptr m_toplevelConfigureRequestedSpy; std::unique_ptr m_surfaceConfigureRequestedSpy; @@ -238,14 +239,14 @@ void TestXdgShellWindowRules::createTestWindow(ClientFlags flags) // Create an xdg surface. m_surface = Test::createSurface(); m_shellSurface = Test::createXdgToplevelSurface(m_surface.get(), Test::CreationSetup::CreateOnly); - Test::XdgToplevelDecorationV1 *decoration = Test::createXdgToplevelDecorationV1(m_shellSurface.get(), m_shellSurface.get()); + m_decoration = Test::createXdgToplevelDecorationV1(m_shellSurface.get()); // Add signal watchers m_toplevelConfigureRequestedSpy = std::make_unique(m_shellSurface.get(), &Test::XdgToplevel::configureRequested); m_surfaceConfigureRequestedSpy = std::make_unique(m_shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested); m_shellSurface->set_app_id(QStringLiteral("org.kde.foo")); - decoration->set_mode(decorationMode); + m_decoration->set_mode(decorationMode); // Wait for the initial configure event m_surface->commit(KWayland::Client::Surface::CommitFlag::None); @@ -277,6 +278,7 @@ void TestXdgShellWindowRules::destroyTestWindow() { m_surfaceConfigureRequestedSpy.reset(); m_toplevelConfigureRequestedSpy.reset(); + m_decoration.reset(); m_shellSurface.reset(); m_surface.reset(); QVERIFY(Test::waitForWindowClosed(m_window));