KWin
Loading...
Searching...
No Matches
dont_crash_empty_deco.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "kwin_wayland_test.h"
10
11#include "core/output.h"
12#include "pointer_input.h"
13#include "wayland_server.h"
14#include "workspace.h"
15#include "x11window.h"
16
17#include <KDecoration2/Decoration>
18
19#include <linux/input.h>
20
21namespace KWin
22{
23
24static const QString s_socketName = QStringLiteral("wayland_test_kwin_dont_crash_empty_decoration-0");
25
26class DontCrashEmptyDecorationTest : public QObject
27{
28 Q_OBJECT
29private Q_SLOTS:
30 void initTestCase();
31 void init();
32 void testBug361551();
33};
34
35void DontCrashEmptyDecorationTest::initTestCase()
36{
38 QSKIP("no render node available");
39 return;
40 }
41 qRegisterMetaType<KWin::Window *>();
42 QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
43 QVERIFY(waylandServer()->init(s_socketName));
45 QRect(0, 0, 1280, 1024),
46 QRect(1280, 0, 1280, 1024),
47 });
48
49 // this test needs to enforce OpenGL compositing to get into the crashy condition
50 qputenv("KWIN_COMPOSE", QByteArrayLiteral("O2"));
51 kwinApp()->start();
52 QVERIFY(applicationStartedSpy.wait());
53 const auto outputs = workspace()->outputs();
54 QCOMPARE(outputs.count(), 2);
55 QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
56 QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
57 setenv("QT_QPA_PLATFORM", "wayland", true);
58}
59
60void DontCrashEmptyDecorationTest::init()
61{
62 workspace()->setActiveOutput(QPoint(640, 512));
63 input()->pointer()->warp(QPoint(640, 512));
64}
65
66void DontCrashEmptyDecorationTest::testBug361551()
67{
68 // this test verifies that resizing an X11 window to an invalid size does not result in crash on unmap
69 // when the DecorationRenderer gets copied to the Deleted
70 // there a repaint is scheduled and the resulting texture is invalid if the window size is invalid
71
72 // create an xcb window
74 auto c = connection.get();
75
76 QVERIFY(c);
77 QVERIFY(!xcb_connection_has_error(c));
78
79 xcb_window_t windowId = xcb_generate_id(c);
80 xcb_create_window(c, XCB_COPY_FROM_PARENT, windowId, rootWindow(), 0, 0, 10, 10, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
81 xcb_map_window(c, windowId);
82 xcb_flush(c);
83
84 // we should get a window for it
85 QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
86 QVERIFY(windowCreatedSpy.wait());
87 X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
88 QVERIFY(window);
89 QCOMPARE(window->window(), windowId);
90 QVERIFY(window->isDecorated());
91
92 // let's set a stupid geometry
93 window->moveResize({0, 0, 0, 0});
94 QCOMPARE(window->frameGeometry(), QRect(0, 0, 0, 0));
95
96 // and destroy the window again
97 xcb_unmap_window(c, windowId);
98 xcb_destroy_window(c, windowId);
99 xcb_flush(c);
100
101 QSignalSpy windowClosedSpy(window, &X11Window::closed);
102 QVERIFY(windowClosedSpy.wait());
103}
104
105}
106
108#include "dont_crash_empty_deco.moc"
PointerInputRedirection * pointer() const
Definition input.h:220
void warp(const QPointF &pos)
void windowAdded(KWin::Window *)
QList< Output * > outputs() const
Definition workspace.h:762
void setActiveOutput(Output *output)
#define WAYLANDTEST_MAIN(TestObject)
void setOutputConfig(const QList< QRect > &geometries)
XcbConnectionPtr createX11Connection()
QList< KWayland::Client::Output * > outputs
bool renderNodeAvailable()
std::unique_ptr< xcb_connection_t, XcbConnectionDeleter > XcbConnectionPtr
KWIN_EXPORT xcb_window_t rootWindow()
Definition xcb.h:24
WaylandServer * waylandServer()
Workspace * workspace()
Definition workspace.h:830
KWIN_EXPORT xcb_connection_t * connection()
Definition xcb.h:19
InputRedirection * input()
Definition input.h:549