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();
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++)
@ -79,23 +79,23 @@ private:
#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) \
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<KWayland::Client::Surface> surface{Test::createSurface()};
VERIFY(surface.get());
std::unique_ptr<Test::XdgToplevel> 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<Test::XdgToplevelDecorationV1> 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<Window *, std::unique_ptr<KWayland::Client::Surface>, 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());

View file

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

View file

@ -1035,7 +1035,7 @@ std::unique_ptr<XdgPopup> createXdgPopupSurface(KWayland::Client::Surface *surfa
return xdgPopup;
}
XdgToplevelDecorationV1 *createXdgToplevelDecorationV1(XdgToplevel *toplevel, QObject *parent)
std::unique_ptr<XdgToplevelDecorationV1> 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<XdgToplevelDecorationV1>(manager, toplevel);
}
IdleInhibitorV1 *createIdleInhibitorV1(KWayland::Client::Surface *surface)

View file

@ -51,6 +51,7 @@ private:
Window *window;
std::unique_ptr<KWayland::Client::Surface> surface;
std::unique_ptr<Test::XdgToplevel> shellSurface;
std::unique_ptr<Test::XdgToplevelDecorationV1> 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<KWayland::Client::Surface> surface = Test::createSurface();
VERIFY(surface.get());
std::unique_ptr<Test::XdgToplevel> shellSurface = Test::createXdgToplevelSurface(surface.get(), Test::CreationSetup::CreateOnly);
VERIFY(shellSurface.get());
std::unique_ptr<Test::XdgToplevelDecorationV1> 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());

View file

@ -175,6 +175,7 @@ private:
Window *m_window;
std::unique_ptr<KWayland::Client::Surface> m_surface;
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_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<QSignalSpy>(m_shellSurface.get(), &Test::XdgToplevel::configureRequested);
m_surfaceConfigureRequestedSpy = std::make_unique<QSignalSpy>(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));