autotests: Make xdg-toplevel-decoration-v1 factory function return a std::unique_ptr

This commit is contained in:
Vlad Zahorodnii 2024-03-10 21:52:47 +02:00
parent b4e2241ded
commit 2922b8d0a7
5 changed files with 37 additions and 33 deletions

View file

@ -70,7 +70,7 @@ private Q_SLOTS:
void testTooltipDoesntEatKeyEvents(); void testTooltipDoesntEatKeyEvents();
private: private:
std::tuple<Window *, std::unique_ptr<KWayland::Client::Surface>, std::unique_ptr<Test::XdgToplevel>> showWindow(); std::tuple<Window *, std::unique_ptr<KWayland::Client::Surface>, std::unique_ptr<Test::XdgToplevel>, std::unique_ptr<Test::XdgToplevelDecorationV1>> showWindow();
}; };
#define MOTION(target) Test::pointerMotion(target, timestamp++) #define MOTION(target) Test::pointerMotion(target, timestamp++)
@ -79,23 +79,23 @@ private:
#define RELEASE Test::pointerButtonReleased(BTN_LEFT, timestamp++) #define RELEASE Test::pointerButtonReleased(BTN_LEFT, timestamp++)
std::tuple<Window *, std::unique_ptr<KWayland::Client::Surface>, std::unique_ptr<Test::XdgToplevel>> DecorationInputTest::showWindow() std::tuple<Window *, std::unique_ptr<KWayland::Client::Surface>, std::unique_ptr<Test::XdgToplevel>, std::unique_ptr<Test::XdgToplevelDecorationV1>> DecorationInputTest::showWindow()
{ {
#define VERIFY(statement) \ #define VERIFY(statement) \
if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__)) \ if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__)) \
return {nullptr, nullptr, nullptr}; return {nullptr, nullptr, nullptr, nullptr};
#define COMPARE(actual, expected) \ #define COMPARE(actual, expected) \
if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)) \ if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)) \
return {nullptr, nullptr, nullptr}; return {nullptr, nullptr, nullptr, nullptr};
std::unique_ptr<KWayland::Client::Surface> surface{Test::createSurface()}; std::unique_ptr<KWayland::Client::Surface> surface{Test::createSurface()};
VERIFY(surface.get()); VERIFY(surface.get());
std::unique_ptr<Test::XdgToplevel> shellSurface = Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly); std::unique_ptr<Test::XdgToplevel> shellSurface = Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly);
VERIFY(shellSurface.get()); VERIFY(shellSurface.get());
Test::XdgToplevelDecorationV1 *decoration = Test::createXdgToplevelDecorationV1(shellSurface.get(), shellSurface.get()); std::unique_ptr<Test::XdgToplevelDecorationV1> decoration = Test::createXdgToplevelDecorationV1(shellSurface.get());
VERIFY(decoration); VERIFY(decoration.get());
QSignalSpy decorationConfigureRequestedSpy(decoration, &Test::XdgToplevelDecorationV1::configureRequested); QSignalSpy decorationConfigureRequestedSpy(decoration.get(), &Test::XdgToplevelDecorationV1::configureRequested);
QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested); QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested);
decoration->set_mode(Test::XdgToplevelDecorationV1::mode_server_side); decoration->set_mode(Test::XdgToplevelDecorationV1::mode_server_side);
@ -112,7 +112,7 @@ std::tuple<Window *, std::unique_ptr<KWayland::Client::Surface>, std::unique_ptr
#undef VERIFY #undef VERIFY
#undef COMPARE #undef COMPARE
return {window, std::move(surface), std::move(shellSurface)}; return {window, std::move(surface), std::move(shellSurface), std::move(decoration)};
} }
void DecorationInputTest::initTestCase() void DecorationInputTest::initTestCase()
@ -172,7 +172,7 @@ void DecorationInputTest::testAxis()
{ {
static constexpr double oneTick = 15; static constexpr double oneTick = 15;
const auto [window, surface, shellSurface] = showWindow(); const auto [window, surface, shellSurface, decoration] = showWindow();
QVERIFY(window); QVERIFY(window);
QVERIFY(window->isDecorated()); QVERIFY(window->isDecorated());
QVERIFY(!window->noBorder()); QVERIFY(!window->noBorder());
@ -216,7 +216,7 @@ void KWin::DecorationInputTest::testDoubleClickOnAllDesktops()
group.sync(); group.sync();
workspace()->slotReconfigure(); workspace()->slotReconfigure();
const auto [window, surface, shellSurface] = showWindow(); const auto [window, surface, shellSurface, decoration] = showWindow();
QVERIFY(window); QVERIFY(window);
QVERIFY(window->isDecorated()); QVERIFY(window->isDecorated());
QVERIFY(!window->noBorder()); QVERIFY(!window->noBorder());
@ -247,7 +247,7 @@ void DecorationInputTest::testDoubleClickClose()
group.sync(); group.sync();
workspace()->slotReconfigure(); workspace()->slotReconfigure();
auto [window, surface, shellSurface] = showWindow(); auto [window, surface, shellSurface, decoration] = showWindow();
QVERIFY(window); QVERIFY(window);
QVERIFY(window->isDecorated()); QVERIFY(window->isDecorated());
quint32 timestamp = 1; quint32 timestamp = 1;
@ -277,7 +277,7 @@ void KWin::DecorationInputTest::testDoubleTap()
group.sync(); group.sync();
workspace()->slotReconfigure(); workspace()->slotReconfigure();
const auto [window, surface, shellSurface] = showWindow(); const auto [window, surface, shellSurface, decoration] = showWindow();
QVERIFY(window); QVERIFY(window);
QVERIFY(window->isDecorated()); QVERIFY(window->isDecorated());
QVERIFY(!window->noBorder()); QVERIFY(!window->noBorder());
@ -302,7 +302,7 @@ void KWin::DecorationInputTest::testDoubleTap()
void DecorationInputTest::testHover() void DecorationInputTest::testHover()
{ {
const auto [window, surface, shellSurface] = showWindow(); const auto [window, surface, shellSurface, decoration] = showWindow();
QVERIFY(window); QVERIFY(window);
QVERIFY(window->isDecorated()); QVERIFY(window->isDecorated());
QVERIFY(!window->noBorder()); QVERIFY(!window->noBorder());
@ -361,7 +361,7 @@ void DecorationInputTest::testPressToMove_data()
void DecorationInputTest::testPressToMove() void DecorationInputTest::testPressToMove()
{ {
const auto [window, surface, shellSurface] = showWindow(); const auto [window, surface, shellSurface, decoration] = showWindow();
QVERIFY(window); QVERIFY(window);
QVERIFY(window->isDecorated()); QVERIFY(window->isDecorated());
QVERIFY(!window->noBorder()); QVERIFY(!window->noBorder());
@ -418,7 +418,7 @@ void DecorationInputTest::testTapToMove_data()
void DecorationInputTest::testTapToMove() void DecorationInputTest::testTapToMove()
{ {
const auto [window, surface, shellSurface] = showWindow(); const auto [window, surface, shellSurface, decoration] = showWindow();
QVERIFY(window); QVERIFY(window);
QVERIFY(window->isDecorated()); QVERIFY(window->isDecorated());
QVERIFY(!window->noBorder()); QVERIFY(!window->noBorder());
@ -482,7 +482,7 @@ void DecorationInputTest::testResizeOutsideWindow()
workspace()->slotReconfigure(); workspace()->slotReconfigure();
// now create window // now create window
const auto [window, surface, shellSurface] = showWindow(); const auto [window, surface, shellSurface, decoration] = showWindow();
QVERIFY(window); QVERIFY(window);
QVERIFY(window->isDecorated()); QVERIFY(window->isDecorated());
QVERIFY(!window->noBorder()); QVERIFY(!window->noBorder());
@ -576,7 +576,7 @@ void DecorationInputTest::testModifierClickUnrestrictedMove()
QCOMPARE(options->commandAll3(), Options::MouseUnrestrictedMove); QCOMPARE(options->commandAll3(), Options::MouseUnrestrictedMove);
// create a window // create a window
const auto [window, surface, shellSurface] = showWindow(); const auto [window, surface, shellSurface, decoration] = showWindow();
QVERIFY(window); QVERIFY(window);
QVERIFY(window->isDecorated()); QVERIFY(window->isDecorated());
QVERIFY(!window->noBorder()); QVERIFY(!window->noBorder());
@ -638,7 +638,7 @@ void DecorationInputTest::testModifierScrollOpacity()
group.sync(); group.sync();
workspace()->slotReconfigure(); workspace()->slotReconfigure();
const auto [window, surface, shellSurface] = showWindow(); const auto [window, surface, shellSurface, decoration] = showWindow();
QVERIFY(window); QVERIFY(window);
QVERIFY(window->isDecorated()); QVERIFY(window->isDecorated());
QVERIFY(!window->noBorder()); QVERIFY(!window->noBorder());
@ -696,7 +696,7 @@ void DecorationInputTest::testTouchEvents()
{ {
// this test verifies that the decoration gets a hover leave event on touch release // this test verifies that the decoration gets a hover leave event on touch release
// see BUG 386231 // see BUG 386231
const auto [window, surface, shellSurface] = showWindow(); const auto [window, surface, shellSurface, decoration] = showWindow();
QVERIFY(window); QVERIFY(window);
QVERIFY(window->isDecorated()); QVERIFY(window->isDecorated());
QVERIFY(!window->noBorder()); QVERIFY(!window->noBorder());
@ -742,7 +742,7 @@ void DecorationInputTest::testTooltipDoesntEatKeyEvents()
QVERIFY(keyboard); QVERIFY(keyboard);
QSignalSpy enteredSpy(keyboard, &KWayland::Client::Keyboard::entered); QSignalSpy enteredSpy(keyboard, &KWayland::Client::Keyboard::entered);
const auto [window, surface, shellSurface] = showWindow(); const auto [window, surface, shellSurface, decoration] = showWindow();
QVERIFY(window); QVERIFY(window);
QVERIFY(window->isDecorated()); QVERIFY(window->isDecorated());
QVERIFY(!window->noBorder()); QVERIFY(!window->noBorder());

View file

@ -709,7 +709,7 @@ std::unique_ptr<XdgPopup> createXdgPopupSurface(KWayland::Client::Surface *surfa
XdgPositioner *positioner, XdgPositioner *positioner,
CreationSetup configureMode = CreationSetup::CreateAndConfigure); CreationSetup configureMode = CreationSetup::CreateAndConfigure);
XdgToplevelDecorationV1 *createXdgToplevelDecorationV1(XdgToplevel *toplevel, QObject *parent = nullptr); std::unique_ptr<XdgToplevelDecorationV1> createXdgToplevelDecorationV1(XdgToplevel *toplevel);
IdleInhibitorV1 *createIdleInhibitorV1(KWayland::Client::Surface *surface); IdleInhibitorV1 *createIdleInhibitorV1(KWayland::Client::Surface *surface);
AutoHideScreenEdgeV1 *createAutoHideScreenEdgeV1(KWayland::Client::Surface *surface, uint32_t border); AutoHideScreenEdgeV1 *createAutoHideScreenEdgeV1(KWayland::Client::Surface *surface, uint32_t border);
CursorShapeDeviceV1 *createCursorShapeDeviceV1(KWayland::Client::Pointer *pointer); CursorShapeDeviceV1 *createCursorShapeDeviceV1(KWayland::Client::Pointer *pointer);

View file

@ -1035,7 +1035,7 @@ std::unique_ptr<XdgPopup> createXdgPopupSurface(KWayland::Client::Surface *surfa
return xdgPopup; return xdgPopup;
} }
XdgToplevelDecorationV1 *createXdgToplevelDecorationV1(XdgToplevel *toplevel, QObject *parent) std::unique_ptr<XdgToplevelDecorationV1> createXdgToplevelDecorationV1(XdgToplevel *toplevel)
{ {
XdgDecorationManagerV1 *manager = s_waylandConnection.xdgDecorationManagerV1; XdgDecorationManagerV1 *manager = s_waylandConnection.xdgDecorationManagerV1;
@ -1044,7 +1044,7 @@ XdgToplevelDecorationV1 *createXdgToplevelDecorationV1(XdgToplevel *toplevel, QO
return nullptr; return nullptr;
} }
return new XdgToplevelDecorationV1(manager, toplevel, parent); return std::make_unique<XdgToplevelDecorationV1>(manager, toplevel);
} }
IdleInhibitorV1 *createIdleInhibitorV1(KWayland::Client::Surface *surface) IdleInhibitorV1 *createIdleInhibitorV1(KWayland::Client::Surface *surface)

View file

@ -51,6 +51,7 @@ private:
Window *window; Window *window;
std::unique_ptr<KWayland::Client::Surface> surface; std::unique_ptr<KWayland::Client::Surface> surface;
std::unique_ptr<Test::XdgToplevel> shellSurface; std::unique_ptr<Test::XdgToplevel> shellSurface;
std::unique_ptr<Test::XdgToplevelDecorationV1> decoration;
}; };
WindowHandle showWindow(bool decorated = false); WindowHandle showWindow(bool decorated = false);
KWayland::Client::Touch *m_touch = nullptr; KWayland::Client::Touch *m_touch = nullptr;
@ -97,17 +98,18 @@ TouchInputTest::WindowHandle TouchInputTest::showWindow(bool decorated)
{ {
#define VERIFY(statement) \ #define VERIFY(statement) \
if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__)) \ if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__)) \
return {nullptr, nullptr}; return {};
#define COMPARE(actual, expected) \ #define COMPARE(actual, expected) \
if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)) \ if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__)) \
return {nullptr, nullptr}; return {};
std::unique_ptr<KWayland::Client::Surface> surface = Test::createSurface(); std::unique_ptr<KWayland::Client::Surface> surface = Test::createSurface();
VERIFY(surface.get()); VERIFY(surface.get());
std::unique_ptr<Test::XdgToplevel> shellSurface = Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly); std::unique_ptr<Test::XdgToplevel> shellSurface = Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly);
VERIFY(shellSurface.get()); VERIFY(shellSurface.get());
std::unique_ptr<Test::XdgToplevelDecorationV1> decoration;
if (decorated) { if (decorated) {
auto decoration = Test::createXdgToplevelDecorationV1(shellSurface.get(), shellSurface.get()); decoration = Test::createXdgToplevelDecorationV1(shellSurface.get());
decoration->set_mode(Test::XdgToplevelDecorationV1::mode_server_side); decoration->set_mode(Test::XdgToplevelDecorationV1::mode_server_side);
} }
QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested); QSignalSpy surfaceConfigureRequestedSpy(shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested);
@ -123,7 +125,7 @@ TouchInputTest::WindowHandle TouchInputTest::showWindow(bool decorated)
#undef VERIFY #undef VERIFY
#undef COMPARE #undef COMPARE
return {window, std::move(surface), std::move(shellSurface)}; return {window, std::move(surface), std::move(shellSurface), std::move(decoration)};
} }
void TouchInputTest::testTouchHidesCursor() void TouchInputTest::testTouchHidesCursor()
@ -161,7 +163,7 @@ void TouchInputTest::testMultipleTouchPoints_data()
void TouchInputTest::testMultipleTouchPoints() void TouchInputTest::testMultipleTouchPoints()
{ {
QFETCH(bool, decorated); QFETCH(bool, decorated);
auto [window, surface, shellSurface] = showWindow(decorated); auto [window, surface, shellSurface, decoration] = showWindow(decorated);
QCOMPARE(window->isDecorated(), decorated); QCOMPARE(window->isDecorated(), decorated);
window->move(QPoint(100, 100)); window->move(QPoint(100, 100));
QVERIFY(window); QVERIFY(window);
@ -216,7 +218,7 @@ void TouchInputTest::testMultipleTouchPoints()
void TouchInputTest::testCancel() void TouchInputTest::testCancel()
{ {
auto [window, surface, shellSurface] = showWindow(); auto [window, surface, shellSurface, decoration] = showWindow();
window->move(QPoint(100, 100)); window->move(QPoint(100, 100));
QVERIFY(window); QVERIFY(window);
QSignalSpy sequenceStartedSpy(m_touch, &KWayland::Client::Touch::sequenceStarted); 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 // this test verifies that a touch down on an inactive window will activate it
// create two windows // create two windows
auto [c1, surface, shellSurface] = showWindow(); auto [c1, surface, shellSurface, decoration] = showWindow();
QVERIFY(c1); QVERIFY(c1);
auto [c2, surface2, shellSurface2] = showWindow(); auto [c2, surface2, shellSurface2, decoration2] = showWindow();
QVERIFY(c2); QVERIFY(c2);
QVERIFY(!c1->isActive()); QVERIFY(!c1->isActive());

View file

@ -175,6 +175,7 @@ private:
Window *m_window; Window *m_window;
std::unique_ptr<KWayland::Client::Surface> m_surface; std::unique_ptr<KWayland::Client::Surface> m_surface;
std::unique_ptr<Test::XdgToplevel> m_shellSurface; std::unique_ptr<Test::XdgToplevel> m_shellSurface;
std::unique_ptr<Test::XdgToplevelDecorationV1> m_decoration;
std::unique_ptr<QSignalSpy> m_toplevelConfigureRequestedSpy; std::unique_ptr<QSignalSpy> m_toplevelConfigureRequestedSpy;
std::unique_ptr<QSignalSpy> m_surfaceConfigureRequestedSpy; std::unique_ptr<QSignalSpy> m_surfaceConfigureRequestedSpy;
@ -238,14 +239,14 @@ void TestXdgShellWindowRules::createTestWindow(ClientFlags flags)
// Create an xdg surface. // Create an xdg surface.
m_surface = Test::createSurface(); m_surface = Test::createSurface();
m_shellSurface = Test::createXdgToplevelSurface(m_surface.get(), Test::CreationSetup::CreateOnly); 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 // Add signal watchers
m_toplevelConfigureRequestedSpy = std::make_unique<QSignalSpy>(m_shellSurface.get(), &Test::XdgToplevel::configureRequested); m_toplevelConfigureRequestedSpy = std::make_unique<QSignalSpy>(m_shellSurface.get(), &Test::XdgToplevel::configureRequested);
m_surfaceConfigureRequestedSpy = std::make_unique<QSignalSpy>(m_shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested); m_surfaceConfigureRequestedSpy = std::make_unique<QSignalSpy>(m_shellSurface->xdgSurface(), &Test::XdgSurface::configureRequested);
m_shellSurface->set_app_id(QStringLiteral("org.kde.foo")); m_shellSurface->set_app_id(QStringLiteral("org.kde.foo"));
decoration->set_mode(decorationMode); m_decoration->set_mode(decorationMode);
// Wait for the initial configure event // Wait for the initial configure event
m_surface->commit(KWayland::Client::Surface::CommitFlag::None); m_surface->commit(KWayland::Client::Surface::CommitFlag::None);
@ -277,6 +278,7 @@ void TestXdgShellWindowRules::destroyTestWindow()
{ {
m_surfaceConfigureRequestedSpy.reset(); m_surfaceConfigureRequestedSpy.reset();
m_toplevelConfigureRequestedSpy.reset(); m_toplevelConfigureRequestedSpy.reset();
m_decoration.reset();
m_shellSurface.reset(); m_shellSurface.reset();
m_surface.reset(); m_surface.reset();
QVERIFY(Test::waitForWindowClosed(m_window)); QVERIFY(Test::waitForWindowClosed(m_window));