Changeset View
Changeset View
Standalone View
Standalone View
autotests/client/test_wayland_surface.cpp
Show All 19 Lines | |||||
20 | // Qt | 20 | // Qt | ||
21 | #include <QtTest/QtTest> | 21 | #include <QtTest/QtTest> | ||
22 | #include <QImage> | 22 | #include <QImage> | ||
23 | #include <QPainter> | 23 | #include <QPainter> | ||
24 | // KWin | 24 | // KWin | ||
25 | #include "../../src/client/compositor.h" | 25 | #include "../../src/client/compositor.h" | ||
26 | #include "../../src/client/connection_thread.h" | 26 | #include "../../src/client/connection_thread.h" | ||
27 | #include "../../src/client/event_queue.h" | 27 | #include "../../src/client/event_queue.h" | ||
28 | #include "../../src/client/idleinhibit.h" | ||||
28 | #include "../../src/client/output.h" | 29 | #include "../../src/client/output.h" | ||
29 | #include "../../src/client/surface.h" | 30 | #include "../../src/client/surface.h" | ||
30 | #include "../../src/client/region.h" | 31 | #include "../../src/client/region.h" | ||
31 | #include "../../src/client/registry.h" | 32 | #include "../../src/client/registry.h" | ||
32 | #include "../../src/client/shm_pool.h" | 33 | #include "../../src/client/shm_pool.h" | ||
33 | #include "../../src/server/buffer_interface.h" | 34 | #include "../../src/server/buffer_interface.h" | ||
34 | #include "../../src/server/compositor_interface.h" | 35 | #include "../../src/server/compositor_interface.h" | ||
35 | #include "../../src/server/display.h" | 36 | #include "../../src/server/display.h" | ||
37 | #include "../../src/server/idleinhibit_interface.h" | ||||
36 | #include "../../src/server/surface_interface.h" | 38 | #include "../../src/server/surface_interface.h" | ||
37 | // Wayland | 39 | // Wayland | ||
38 | #include <wayland-client-protocol.h> | 40 | #include <wayland-client-protocol.h> | ||
39 | 41 | | |||
42 | using KWayland::Client::Registry; | ||||
43 | | ||||
40 | class TestWaylandSurface : public QObject | 44 | class TestWaylandSurface : public QObject | ||
41 | { | 45 | { | ||
42 | Q_OBJECT | 46 | Q_OBJECT | ||
43 | public: | 47 | public: | ||
44 | explicit TestWaylandSurface(QObject *parent = nullptr); | 48 | explicit TestWaylandSurface(QObject *parent = nullptr); | ||
45 | private Q_SLOTS: | 49 | private Q_SLOTS: | ||
46 | void init(); | 50 | void init(); | ||
47 | void cleanup(); | 51 | void cleanup(); | ||
Show All 9 Lines | |||||
57 | void testDestroy(); | 61 | void testDestroy(); | ||
58 | void testUnmapOfNotMappedSurface(); | 62 | void testUnmapOfNotMappedSurface(); | ||
59 | void testDamageTracking(); | 63 | void testDamageTracking(); | ||
60 | void testSurfaceAt(); | 64 | void testSurfaceAt(); | ||
61 | void testDestroyAttachedBuffer(); | 65 | void testDestroyAttachedBuffer(); | ||
62 | void testDestroyWithPendingCallback(); | 66 | void testDestroyWithPendingCallback(); | ||
63 | void testOutput(); | 67 | void testOutput(); | ||
64 | void testDisconnect(); | 68 | void testDisconnect(); | ||
69 | void testInhibit(); | ||||
65 | 70 | | |||
66 | private: | 71 | private: | ||
67 | KWayland::Server::Display *m_display; | 72 | KWayland::Server::Display *m_display; | ||
68 | KWayland::Server::CompositorInterface *m_compositorInterface; | 73 | KWayland::Server::CompositorInterface *m_compositorInterface; | ||
74 | KWayland::Server::IdleInhibitManagerInterface *m_idleInhibitInterface = nullptr; | ||||
69 | KWayland::Client::ConnectionThread *m_connection; | 75 | KWayland::Client::ConnectionThread *m_connection; | ||
70 | KWayland::Client::Compositor *m_compositor; | 76 | KWayland::Client::Compositor *m_compositor; | ||
71 | KWayland::Client::ShmPool *m_shm; | 77 | KWayland::Client::ShmPool *m_shm; | ||
72 | KWayland::Client::EventQueue *m_queue; | 78 | KWayland::Client::EventQueue *m_queue; | ||
79 | KWayland::Client::IdleInhibitManager *m_idleInhibitManager = nullptr; | ||||
73 | QThread *m_thread; | 80 | QThread *m_thread; | ||
74 | }; | 81 | }; | ||
75 | 82 | | |||
76 | static const QString s_socketName = QStringLiteral("kwin-test-wayland-surface-0"); | 83 | static const QString s_socketName = QStringLiteral("kwin-test-wayland-surface-0"); | ||
77 | 84 | | |||
78 | TestWaylandSurface::TestWaylandSurface(QObject *parent) | 85 | TestWaylandSurface::TestWaylandSurface(QObject *parent) | ||
79 | : QObject(parent) | 86 | : QObject(parent) | ||
80 | , m_display(nullptr) | 87 | , m_display(nullptr) | ||
Show All 14 Lines | 96 | { | |||
95 | QVERIFY(m_display->isRunning()); | 102 | QVERIFY(m_display->isRunning()); | ||
96 | m_display->createShm(); | 103 | m_display->createShm(); | ||
97 | 104 | | |||
98 | m_compositorInterface = m_display->createCompositor(m_display); | 105 | m_compositorInterface = m_display->createCompositor(m_display); | ||
99 | QVERIFY(m_compositorInterface); | 106 | QVERIFY(m_compositorInterface); | ||
100 | m_compositorInterface->create(); | 107 | m_compositorInterface->create(); | ||
101 | QVERIFY(m_compositorInterface->isValid()); | 108 | QVERIFY(m_compositorInterface->isValid()); | ||
102 | 109 | | |||
110 | m_idleInhibitInterface = m_display->createIdleInhibitManager(IdleInhibitManagerInterfaceVersion::UnstableV1, m_display); | ||||
111 | QVERIFY(m_idleInhibitInterface); | ||||
112 | m_idleInhibitInterface->create(); | ||||
113 | QVERIFY(m_idleInhibitInterface->isValid()); | ||||
114 | | ||||
103 | // setup connection | 115 | // setup connection | ||
104 | m_connection = new KWayland::Client::ConnectionThread; | 116 | m_connection = new KWayland::Client::ConnectionThread; | ||
105 | QSignalSpy connectedSpy(m_connection, SIGNAL(connected())); | 117 | QSignalSpy connectedSpy(m_connection, SIGNAL(connected())); | ||
106 | m_connection->setSocketName(s_socketName); | 118 | m_connection->setSocketName(s_socketName); | ||
107 | 119 | | |||
108 | m_thread = new QThread(this); | 120 | m_thread = new QThread(this); | ||
109 | m_connection->moveToThread(m_thread); | 121 | m_connection->moveToThread(m_thread); | ||
110 | m_thread->start(); | 122 | m_thread->start(); | ||
Show All 27 Lines | |||||
138 | QVERIFY(allAnnounced.wait()); | 150 | QVERIFY(allAnnounced.wait()); | ||
139 | QVERIFY(!compositorSpy.isEmpty()); | 151 | QVERIFY(!compositorSpy.isEmpty()); | ||
140 | QVERIFY(!shmSpy.isEmpty()); | 152 | QVERIFY(!shmSpy.isEmpty()); | ||
141 | 153 | | |||
142 | m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this); | 154 | m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this); | ||
143 | QVERIFY(m_compositor->isValid()); | 155 | QVERIFY(m_compositor->isValid()); | ||
144 | m_shm = registry.createShmPool(shmSpy.first().first().value<quint32>(), shmSpy.first().last().value<quint32>(), this); | 156 | m_shm = registry.createShmPool(shmSpy.first().first().value<quint32>(), shmSpy.first().last().value<quint32>(), this); | ||
145 | QVERIFY(m_shm->isValid()); | 157 | QVERIFY(m_shm->isValid()); | ||
158 | | ||||
159 | m_idleInhibitManager = registry.createIdleInhibitManager(registry.interface(Registry::Interface::IdleInhibitManagerUnstableV1).name, registry.interface(Registry::Interface::IdleInhibitManagerUnstableV1).version, this); | ||||
160 | QVERIFY(m_idleInhibitManager->isValid()); | ||||
146 | } | 161 | } | ||
147 | 162 | | |||
148 | void TestWaylandSurface::cleanup() | 163 | void TestWaylandSurface::cleanup() | ||
149 | { | 164 | { | ||
150 | if (m_compositor) { | 165 | if (m_compositor) { | ||
151 | delete m_compositor; | 166 | delete m_compositor; | ||
152 | m_compositor = nullptr; | 167 | m_compositor = nullptr; | ||
153 | } | 168 | } | ||
▲ Show 20 Lines • Show All 932 Lines • ▼ Show 20 Line(s) | 1031 | { | |||
1086 | 1101 | | |||
1087 | //delete output client is on. | 1102 | //delete output client is on. | ||
1088 | //client should get an exit and be left on no outputs (which is allowed) | 1103 | //client should get an exit and be left on no outputs (which is allowed) | ||
1089 | serverOutput->deleteLater(); | 1104 | serverOutput->deleteLater(); | ||
1090 | QVERIFY(leftSpy.wait()); | 1105 | QVERIFY(leftSpy.wait()); | ||
1091 | QCOMPARE(serverSurface->outputs(), QVector<OutputInterface*>()); | 1106 | QCOMPARE(serverSurface->outputs(), QVector<OutputInterface*>()); | ||
1092 | } | 1107 | } | ||
1093 | 1108 | | |||
1109 | void TestWaylandSurface::testInhibit() | ||||
1110 | { | ||||
1111 | using namespace KWayland::Client; | ||||
1112 | using namespace KWayland::Server; | ||||
1113 | QScopedPointer<Surface> s(m_compositor->createSurface()); | ||||
1114 | // wait for the surface on the Server side | ||||
1115 | QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated); | ||||
1116 | QVERIFY(surfaceCreatedSpy.isValid()); | ||||
1117 | QVERIFY(surfaceCreatedSpy.wait()); | ||||
1118 | auto serverSurface = surfaceCreatedSpy.first().first().value<SurfaceInterface*>(); | ||||
1119 | QVERIFY(serverSurface); | ||||
1120 | QCOMPARE(serverSurface->inhibitsIdle(), false); | ||||
1121 | | ||||
1122 | QSignalSpy inhibitsChangedSpy(serverSurface, &SurfaceInterface::inhibitsIdleChanged); | ||||
1123 | QVERIFY(inhibitsChangedSpy.isValid()); | ||||
1124 | | ||||
1125 | // now create an idle inhibition | ||||
1126 | QScopedPointer<IdleInhibitor> inhibitor1(m_idleInhibitManager->createInhibitor(s.data())); | ||||
1127 | QVERIFY(inhibitsChangedSpy.wait()); | ||||
1128 | QCOMPARE(serverSurface->inhibitsIdle(), true); | ||||
1129 | | ||||
1130 | // creating a second idle inhibition should not trigger the signal | ||||
1131 | QScopedPointer<IdleInhibitor> inhibitor2(m_idleInhibitManager->createInhibitor(s.data())); | ||||
1132 | QVERIFY(!inhibitsChangedSpy.wait()); | ||||
1133 | QCOMPARE(serverSurface->inhibitsIdle(), true); | ||||
1134 | | ||||
1135 | // and also deleting the first inhibitor should not yet change the inhibition | ||||
1136 | inhibitor1.reset(); | ||||
1137 | QVERIFY(!inhibitsChangedSpy.wait()); | ||||
1138 | QCOMPARE(serverSurface->inhibitsIdle(), true); | ||||
1139 | | ||||
1140 | // but deleting also the second inhibitor should trigger | ||||
1141 | inhibitor2.reset(); | ||||
1142 | QVERIFY(inhibitsChangedSpy.wait()); | ||||
1143 | QCOMPARE(serverSurface->inhibitsIdle(), false); | ||||
1144 | QCOMPARE(inhibitsChangedSpy.count(), 2); | ||||
1145 | | ||||
1146 | // recreate inhibitor1 should inhibit again | ||||
1147 | inhibitor1.reset(m_idleInhibitManager->createInhibitor(s.data())); | ||||
1148 | QVERIFY(inhibitsChangedSpy.wait()); | ||||
1149 | QCOMPARE(serverSurface->inhibitsIdle(), true); | ||||
1150 | // and destroying should uninhibit | ||||
1151 | inhibitor1.reset(); | ||||
1152 | QVERIFY(inhibitsChangedSpy.wait()); | ||||
1153 | QCOMPARE(serverSurface->inhibitsIdle(), false); | ||||
1154 | QCOMPARE(inhibitsChangedSpy.count(), 4); | ||||
1155 | } | ||||
1156 | | ||||
1094 | QTEST_GUILESS_MAIN(TestWaylandSurface) | 1157 | QTEST_GUILESS_MAIN(TestWaylandSurface) | ||
1095 | #include "test_wayland_surface.moc" | 1158 | #include "test_wayland_surface.moc" |