Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/start_test.cpp
Show All 20 Lines | |||||
21 | #include "platform.h" | 21 | #include "platform.h" | ||
22 | #include "screens.h" | 22 | #include "screens.h" | ||
23 | #include "wayland_server.h" | 23 | #include "wayland_server.h" | ||
24 | #include "workspace.h" | 24 | #include "workspace.h" | ||
25 | #include "shell_client.h" | 25 | #include "shell_client.h" | ||
26 | 26 | | |||
27 | #include <KWayland/Client/connection_thread.h> | 27 | #include <KWayland/Client/connection_thread.h> | ||
28 | #include <KWayland/Client/compositor.h> | 28 | #include <KWayland/Client/compositor.h> | ||
29 | #include <KWayland/Client/event_queue.h> | | |||
30 | #include <KWayland/Client/registry.h> | | |||
31 | #include <KWayland/Client/shell.h> | 29 | #include <KWayland/Client/shell.h> | ||
32 | #include <KWayland/Client/shm_pool.h> | | |||
33 | #include <KWayland/Client/surface.h> | 30 | #include <KWayland/Client/surface.h> | ||
34 | 31 | | |||
35 | namespace KWin | 32 | namespace KWin | ||
36 | { | 33 | { | ||
37 | 34 | | |||
38 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_start_test-0"); | 35 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_start_test-0"); | ||
39 | 36 | | |||
40 | class StartTest : public QObject | 37 | class StartTest : public QObject | ||
41 | { | 38 | { | ||
42 | Q_OBJECT | 39 | Q_OBJECT | ||
43 | private Q_SLOTS: | 40 | private Q_SLOTS: | ||
44 | void initTestCase(); | 41 | void initTestCase(); | ||
42 | void cleanup(); | ||||
45 | void testScreens(); | 43 | void testScreens(); | ||
46 | void testNoWindowsAtStart(); | 44 | void testNoWindowsAtStart(); | ||
47 | void testCreateWindow(); | 45 | void testCreateWindow(); | ||
48 | }; | 46 | }; | ||
49 | 47 | | |||
50 | void StartTest::initTestCase() | 48 | void StartTest::initTestCase() | ||
51 | { | 49 | { | ||
52 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 50 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
53 | QVERIFY(workspaceCreatedSpy.isValid()); | 51 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
54 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | 52 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||
55 | waylandServer()->init(s_socketName.toLocal8Bit()); | 53 | waylandServer()->init(s_socketName.toLocal8Bit()); | ||
56 | kwinApp()->start(); | 54 | kwinApp()->start(); | ||
57 | QVERIFY(workspaceCreatedSpy.wait()); | 55 | QVERIFY(workspaceCreatedSpy.wait()); | ||
58 | } | 56 | } | ||
59 | 57 | | |||
58 | void StartTest::cleanup() | ||||
59 | { | ||||
60 | Test::destroyWaylandConnection(); | ||||
61 | } | ||||
62 | | ||||
60 | void StartTest::testScreens() | 63 | void StartTest::testScreens() | ||
61 | { | 64 | { | ||
62 | QCOMPARE(screens()->count(), 1); | 65 | QCOMPARE(screens()->count(), 1); | ||
63 | QCOMPARE(screens()->size(), QSize(1280, 1024)); | 66 | QCOMPARE(screens()->size(), QSize(1280, 1024)); | ||
64 | QCOMPARE(screens()->geometry(), QRect(0, 0, 1280, 1024)); | 67 | QCOMPARE(screens()->geometry(), QRect(0, 0, 1280, 1024)); | ||
65 | } | 68 | } | ||
66 | 69 | | |||
67 | void StartTest::testNoWindowsAtStart() | 70 | void StartTest::testNoWindowsAtStart() | ||
68 | { | 71 | { | ||
69 | QVERIFY(workspace()->clientList().isEmpty()); | 72 | QVERIFY(workspace()->clientList().isEmpty()); | ||
70 | QVERIFY(workspace()->desktopList().isEmpty()); | 73 | QVERIFY(workspace()->desktopList().isEmpty()); | ||
71 | QVERIFY(workspace()->allClientList().isEmpty()); | 74 | QVERIFY(workspace()->allClientList().isEmpty()); | ||
72 | QVERIFY(workspace()->deletedList().isEmpty()); | 75 | QVERIFY(workspace()->deletedList().isEmpty()); | ||
73 | QVERIFY(workspace()->unmanagedList().isEmpty()); | 76 | QVERIFY(workspace()->unmanagedList().isEmpty()); | ||
74 | QVERIFY(waylandServer()->clients().isEmpty()); | 77 | QVERIFY(waylandServer()->clients().isEmpty()); | ||
75 | } | 78 | } | ||
76 | 79 | | |||
77 | void StartTest::testCreateWindow() | 80 | void StartTest::testCreateWindow() | ||
78 | { | 81 | { | ||
79 | // first we need to connect to the server | 82 | // first we need to connect to the server | ||
80 | using namespace KWayland::Client; | 83 | using namespace KWayland::Client; | ||
81 | auto connection = new ConnectionThread; | 84 | QVERIFY(Test::setupWaylandConnection(s_socketName)); | ||
82 | QSignalSpy connectedSpy(connection, &ConnectionThread::connected); | | |||
83 | QVERIFY(connectedSpy.isValid()); | | |||
84 | connection->setSocketName(s_socketName); | | |||
85 | QThread *thread = new QThread(this); | | |||
86 | connection->moveToThread(thread); | | |||
87 | thread->start(); | | |||
88 | connection->initConnection(); | | |||
89 | QVERIFY(connectedSpy.wait()); | | |||
90 | 85 | | |||
91 | QSignalSpy shellClientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 86 | QSignalSpy shellClientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
92 | QVERIFY(shellClientAddedSpy.isValid()); | 87 | QVERIFY(shellClientAddedSpy.isValid()); | ||
93 | QSignalSpy shellClientRemovedSpy(waylandServer(), &WaylandServer::shellClientRemoved); | 88 | QSignalSpy shellClientRemovedSpy(waylandServer(), &WaylandServer::shellClientRemoved); | ||
94 | QVERIFY(shellClientRemovedSpy.isValid()); | 89 | QVERIFY(shellClientRemovedSpy.isValid()); | ||
95 | 90 | | |||
96 | { | 91 | { | ||
97 | EventQueue queue; | 92 | QScopedPointer<Surface> surface(Test::createSurface()); | ||
98 | queue.setup(connection); | | |||
99 | Registry registry; | | |||
100 | registry.setEventQueue(&queue); | | |||
101 | registry.create(connection); | | |||
102 | QSignalSpy registryAnnouncedSpy(®istry, &Registry::interfacesAnnounced); | | |||
103 | QVERIFY(registryAnnouncedSpy.isValid()); | | |||
104 | registry.setup(); | | |||
105 | QVERIFY(registryAnnouncedSpy.wait()); | | |||
106 | | ||||
107 | const auto compositorData = registry.interface(Registry::Interface::Compositor); | | |||
108 | const auto shellData = registry.interface(Registry::Interface::Shell); | | |||
109 | const auto shmData = registry.interface(Registry::Interface::Shm); | | |||
110 | QScopedPointer<KWayland::Client::Compositor> compositor(registry.createCompositor(compositorData.name, compositorData.version)); | | |||
111 | QVERIFY(!compositor.isNull()); | | |||
112 | QScopedPointer<Shell> shell(registry.createShell(shellData.name, shellData.version)); | | |||
113 | QVERIFY(!shell.isNull()); | | |||
114 | | ||||
115 | QScopedPointer<Surface> surface(compositor->createSurface()); | | |||
116 | QVERIFY(!surface.isNull()); | 93 | QVERIFY(!surface.isNull()); | ||
117 | QSignalSpy surfaceRenderedSpy(surface.data(), &Surface::frameRendered); | 94 | QSignalSpy surfaceRenderedSpy(surface.data(), &Surface::frameRendered); | ||
118 | QVERIFY(surfaceRenderedSpy.isValid()); | 95 | QVERIFY(surfaceRenderedSpy.isValid()); | ||
119 | 96 | | |||
120 | QScopedPointer<ShellSurface> shellSurface(shell->createSurface(surface.data())); | 97 | QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data())); | ||
121 | QVERIFY(!shellSurface.isNull()); | 98 | QVERIFY(!shellSurface.isNull()); | ||
122 | connection->flush(); | 99 | Test::flushWaylandConnection(); | ||
123 | QVERIFY(waylandServer()->clients().isEmpty()); | 100 | QVERIFY(waylandServer()->clients().isEmpty()); | ||
124 | // now dispatch should give us the client | 101 | // now dispatch should give us the client | ||
125 | waylandServer()->dispatch(); | 102 | waylandServer()->dispatch(); | ||
126 | QCOMPARE(waylandServer()->clients().count(), 1); | 103 | QCOMPARE(waylandServer()->clients().count(), 1); | ||
127 | // but still not yet in workspace | 104 | // but still not yet in workspace | ||
128 | QVERIFY(workspace()->allClientList().isEmpty()); | 105 | QVERIFY(workspace()->allClientList().isEmpty()); | ||
129 | 106 | | |||
130 | // icon geometry accesses windowManagementInterface which only exists after window became visible | 107 | // icon geometry accesses windowManagementInterface which only exists after window became visible | ||
131 | // verify that accessing doesnt't crash | 108 | // verify that accessing doesnt't crash | ||
132 | QVERIFY(waylandServer()->clients().first()->iconGeometry().isNull()); | 109 | QVERIFY(waylandServer()->clients().first()->iconGeometry().isNull()); | ||
133 | 110 | | |||
134 | // let's render | 111 | // let's render | ||
135 | QImage img(QSize(100, 50), QImage::Format_ARGB32); | 112 | Test::render(surface.data(), QSize(100, 50), Qt::blue); | ||
136 | img.fill(Qt::blue); | | |||
137 | QScopedPointer<ShmPool> shm(registry.createShmPool(shmData.name, shmData.version)); | | |||
138 | QVERIFY(!shm.isNull()); | | |||
139 | surface->attachBuffer(shm->createBuffer(img)); | | |||
140 | surface->damage(QRect(0, 0, 100, 50)); | | |||
141 | surface->commit(); | 113 | surface->commit(); | ||
142 | 114 | | |||
143 | connection->flush(); | 115 | Test::flushWaylandConnection(); | ||
144 | QVERIFY(shellClientAddedSpy.wait()); | 116 | QVERIFY(shellClientAddedSpy.wait()); | ||
145 | QCOMPARE(workspace()->allClientList().count(), 1); | 117 | QCOMPARE(workspace()->allClientList().count(), 1); | ||
146 | QCOMPARE(workspace()->allClientList().first(), waylandServer()->clients().first()); | 118 | QCOMPARE(workspace()->allClientList().first(), waylandServer()->clients().first()); | ||
147 | QVERIFY(workspace()->activeClient()); | 119 | QVERIFY(workspace()->activeClient()); | ||
148 | QCOMPARE(workspace()->activeClient()->pos(), QPoint(0, 0)); | 120 | QCOMPARE(workspace()->activeClient()->pos(), QPoint(0, 0)); | ||
149 | QCOMPARE(workspace()->activeClient()->size(), QSize(100, 50)); | 121 | QCOMPARE(workspace()->activeClient()->size(), QSize(100, 50)); | ||
150 | QCOMPARE(workspace()->activeClient()->geometry(), QRect(0, 0, 100, 50)); | 122 | QCOMPARE(workspace()->activeClient()->geometry(), QRect(0, 0, 100, 50)); | ||
151 | 123 | | |||
152 | // and kwin will render it | 124 | // and kwin will render it | ||
153 | QVERIFY(surfaceRenderedSpy.wait()); | 125 | QVERIFY(surfaceRenderedSpy.wait()); | ||
154 | } | 126 | } | ||
155 | // this should tear down everything again | 127 | // this should tear down everything again | ||
156 | QVERIFY(shellClientRemovedSpy.wait()); | 128 | QVERIFY(shellClientRemovedSpy.wait()); | ||
157 | QVERIFY(waylandServer()->clients().isEmpty()); | 129 | QVERIFY(waylandServer()->clients().isEmpty()); | ||
158 | | ||||
159 | // cleanup | | |||
160 | connection->deleteLater(); | | |||
161 | thread->quit(); | | |||
162 | thread->wait(); | | |||
163 | } | 130 | } | ||
164 | 131 | | |||
165 | } | 132 | } | ||
166 | 133 | | |||
167 | WAYLANDTEST_MAIN(KWin::StartTest) | 134 | WAYLANDTEST_MAIN(KWin::StartTest) | ||
168 | #include "start_test.moc" | 135 | #include "start_test.moc" |