Changeset View
Changeset View
Standalone View
Standalone View
autotests/integration/touch_input_test.cpp
Show All 21 Lines | |||||
22 | #include "cursor.h" | 22 | #include "cursor.h" | ||
23 | #include "shell_client.h" | 23 | #include "shell_client.h" | ||
24 | #include "screens.h" | 24 | #include "screens.h" | ||
25 | #include "wayland_server.h" | 25 | #include "wayland_server.h" | ||
26 | #include "workspace.h" | 26 | #include "workspace.h" | ||
27 | 27 | | |||
28 | #include <KWayland/Client/compositor.h> | 28 | #include <KWayland/Client/compositor.h> | ||
29 | #include <KWayland/Client/connection_thread.h> | 29 | #include <KWayland/Client/connection_thread.h> | ||
30 | #include <KWayland/Client/event_queue.h> | | |||
31 | #include <KWayland/Client/registry.h> | | |||
32 | #include <KWayland/Client/seat.h> | 30 | #include <KWayland/Client/seat.h> | ||
33 | #include <KWayland/Client/shell.h> | 31 | #include <KWayland/Client/shell.h> | ||
34 | #include <KWayland/Client/shm_pool.h> | | |||
35 | #include <KWayland/Client/surface.h> | 32 | #include <KWayland/Client/surface.h> | ||
36 | #include <KWayland/Client/touch.h> | 33 | #include <KWayland/Client/touch.h> | ||
37 | 34 | | |||
38 | namespace KWin | 35 | namespace KWin | ||
39 | { | 36 | { | ||
40 | 37 | | |||
41 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_touch_input-0"); | 38 | static const QString s_socketName = QStringLiteral("wayland_test_kwin_touch_input-0"); | ||
42 | 39 | | |||
43 | class TouchInputTest : public QObject | 40 | class TouchInputTest : public QObject | ||
44 | { | 41 | { | ||
45 | Q_OBJECT | 42 | Q_OBJECT | ||
46 | private Q_SLOTS: | 43 | private Q_SLOTS: | ||
47 | void initTestCase(); | 44 | void initTestCase(); | ||
48 | void init(); | 45 | void init(); | ||
49 | void cleanup(); | 46 | void cleanup(); | ||
50 | void testMultipleTouchPoints(); | 47 | void testMultipleTouchPoints(); | ||
51 | void testCancel(); | 48 | void testCancel(); | ||
52 | void testTouchMouseAction(); | 49 | void testTouchMouseAction(); | ||
53 | 50 | | |||
54 | private: | 51 | private: | ||
55 | AbstractClient *showWindow(); | 52 | AbstractClient *showWindow(); | ||
56 | KWayland::Client::ConnectionThread *m_connection = nullptr; | | |||
57 | KWayland::Client::Compositor *m_compositor = nullptr; | | |||
58 | KWayland::Client::Seat *m_seat = nullptr; | | |||
59 | KWayland::Client::ShmPool *m_shm = nullptr; | | |||
60 | KWayland::Client::Shell *m_shell = nullptr; | | |||
61 | KWayland::Client::Touch *m_touch = nullptr; | 53 | KWayland::Client::Touch *m_touch = nullptr; | ||
62 | KWayland::Client::EventQueue *m_queue = nullptr; | | |||
63 | QThread *m_thread = nullptr; | | |||
64 | }; | 54 | }; | ||
65 | 55 | | |||
66 | void TouchInputTest::initTestCase() | 56 | void TouchInputTest::initTestCase() | ||
67 | { | 57 | { | ||
68 | qRegisterMetaType<KWin::ShellClient*>(); | 58 | qRegisterMetaType<KWin::ShellClient*>(); | ||
69 | qRegisterMetaType<KWin::AbstractClient*>(); | 59 | qRegisterMetaType<KWin::AbstractClient*>(); | ||
70 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | 60 | QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); | ||
71 | QVERIFY(workspaceCreatedSpy.isValid()); | 61 | QVERIFY(workspaceCreatedSpy.isValid()); | ||
72 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | 62 | kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); | ||
73 | QMetaObject::invokeMethod(kwinApp()->platform(), "setOutputCount", Qt::DirectConnection, Q_ARG(int, 2)); | 63 | QMetaObject::invokeMethod(kwinApp()->platform(), "setOutputCount", Qt::DirectConnection, Q_ARG(int, 2)); | ||
74 | waylandServer()->init(s_socketName.toLocal8Bit()); | 64 | waylandServer()->init(s_socketName.toLocal8Bit()); | ||
75 | 65 | | |||
76 | kwinApp()->start(); | 66 | kwinApp()->start(); | ||
77 | QVERIFY(workspaceCreatedSpy.wait()); | 67 | QVERIFY(workspaceCreatedSpy.wait()); | ||
78 | QCOMPARE(screens()->count(), 2); | 68 | QCOMPARE(screens()->count(), 2); | ||
79 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | 69 | QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); | ||
80 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | 70 | QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); | ||
81 | waylandServer()->initWorkspace(); | 71 | waylandServer()->initWorkspace(); | ||
82 | } | 72 | } | ||
83 | 73 | | |||
84 | void TouchInputTest::init() | 74 | void TouchInputTest::init() | ||
85 | { | 75 | { | ||
86 | using namespace KWayland::Client; | 76 | using namespace KWayland::Client; | ||
87 | // setup connection | 77 | QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Seat)); | ||
88 | m_connection = new ConnectionThread; | 78 | QVERIFY(Test::waitForWaylandTouch()); | ||
89 | QSignalSpy connectedSpy(m_connection, &ConnectionThread::connected); | 79 | m_touch = Test::waylandSeat()->createTouch(Test::waylandSeat()); | ||
90 | QVERIFY(connectedSpy.isValid()); | | |||
91 | m_connection->setSocketName(s_socketName); | | |||
92 | | ||||
93 | m_thread = new QThread(this); | | |||
94 | m_connection->moveToThread(m_thread); | | |||
95 | m_thread->start(); | | |||
96 | | ||||
97 | m_connection->initConnection(); | | |||
98 | QVERIFY(connectedSpy.wait()); | | |||
99 | | ||||
100 | m_queue = new EventQueue(this); | | |||
101 | QVERIFY(!m_queue->isValid()); | | |||
102 | m_queue->setup(m_connection); | | |||
103 | QVERIFY(m_queue->isValid()); | | |||
104 | | ||||
105 | Registry registry; | | |||
106 | registry.setEventQueue(m_queue); | | |||
107 | QSignalSpy compositorSpy(®istry, &Registry::compositorAnnounced); | | |||
108 | QSignalSpy shmSpy(®istry, &Registry::shmAnnounced); | | |||
109 | QSignalSpy shellSpy(®istry, &Registry::shellAnnounced); | | |||
110 | QSignalSpy seatSpy(®istry, &Registry::seatAnnounced); | | |||
111 | QSignalSpy allAnnounced(®istry, &Registry::interfacesAnnounced); | | |||
112 | QVERIFY(allAnnounced.isValid()); | | |||
113 | QVERIFY(shmSpy.isValid()); | | |||
114 | QVERIFY(shellSpy.isValid()); | | |||
115 | QVERIFY(compositorSpy.isValid()); | | |||
116 | QVERIFY(seatSpy.isValid()); | | |||
117 | registry.create(m_connection->display()); | | |||
118 | QVERIFY(registry.isValid()); | | |||
119 | registry.setup(); | | |||
120 | QVERIFY(allAnnounced.wait()); | | |||
121 | QVERIFY(!compositorSpy.isEmpty()); | | |||
122 | QVERIFY(!shmSpy.isEmpty()); | | |||
123 | QVERIFY(!shellSpy.isEmpty()); | | |||
124 | QVERIFY(!seatSpy.isEmpty()); | | |||
125 | | ||||
126 | m_compositor = registry.createCompositor(compositorSpy.first().first().value<quint32>(), compositorSpy.first().last().value<quint32>(), this); | | |||
127 | QVERIFY(m_compositor->isValid()); | | |||
128 | m_shm = registry.createShmPool(shmSpy.first().first().value<quint32>(), shmSpy.first().last().value<quint32>(), this); | | |||
129 | QVERIFY(m_shm->isValid()); | | |||
130 | m_shell = registry.createShell(shellSpy.first().first().value<quint32>(), shellSpy.first().last().value<quint32>(), this); | | |||
131 | QVERIFY(m_shell->isValid()); | | |||
132 | m_seat = registry.createSeat(seatSpy.first().first().value<quint32>(), seatSpy.first().last().value<quint32>(), this); | | |||
133 | QVERIFY(m_seat->isValid()); | | |||
134 | QSignalSpy hasTouchSpy(m_seat, &Seat::hasTouchChanged); | | |||
135 | QVERIFY(hasTouchSpy.isValid()); | | |||
136 | QVERIFY(hasTouchSpy.wait()); | | |||
137 | m_touch = m_seat->createTouch(m_seat); | | |||
138 | QVERIFY(m_touch); | 80 | QVERIFY(m_touch); | ||
139 | QVERIFY(m_touch->isValid()); | 81 | QVERIFY(m_touch->isValid()); | ||
140 | 82 | | |||
141 | screens()->setCurrent(0); | 83 | screens()->setCurrent(0); | ||
142 | Cursor::setPos(QPoint(1280, 512)); | 84 | Cursor::setPos(QPoint(1280, 512)); | ||
143 | } | 85 | } | ||
144 | 86 | | |||
145 | void TouchInputTest::cleanup() | 87 | void TouchInputTest::cleanup() | ||
146 | { | 88 | { | ||
147 | delete m_compositor; | | |||
148 | m_compositor = nullptr; | | |||
149 | delete m_touch; | 89 | delete m_touch; | ||
150 | m_touch = nullptr; | 90 | m_touch = nullptr; | ||
151 | delete m_seat; | 91 | Test::destroyWaylandConnection(); | ||
152 | m_seat = nullptr; | | |||
153 | delete m_shm; | | |||
154 | m_shm = nullptr; | | |||
155 | delete m_shell; | | |||
156 | m_shell = nullptr; | | |||
157 | delete m_queue; | | |||
158 | m_queue = nullptr; | | |||
159 | if (m_thread) { | | |||
160 | m_connection->deleteLater(); | | |||
161 | m_thread->quit(); | | |||
162 | m_thread->wait(); | | |||
163 | delete m_thread; | | |||
164 | m_thread = nullptr; | | |||
165 | m_connection = nullptr; | | |||
166 | } | | |||
167 | } | 92 | } | ||
168 | 93 | | |||
169 | AbstractClient *TouchInputTest::showWindow() | 94 | AbstractClient *TouchInputTest::showWindow() | ||
170 | { | 95 | { | ||
171 | using namespace KWayland::Client; | 96 | using namespace KWayland::Client; | ||
172 | #define VERIFY(statement) \ | 97 | #define VERIFY(statement) \ | ||
173 | if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ | 98 | if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ | ||
174 | return nullptr; | 99 | return nullptr; | ||
175 | #define COMPARE(actual, expected) \ | 100 | #define COMPARE(actual, expected) \ | ||
176 | if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ | 101 | if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ | ||
177 | return nullptr; | 102 | return nullptr; | ||
178 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | 103 | QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); | ||
179 | VERIFY(clientAddedSpy.isValid()); | 104 | VERIFY(clientAddedSpy.isValid()); | ||
180 | 105 | | |||
181 | Surface *surface = m_compositor->createSurface(m_compositor); | 106 | Surface *surface = Test::createSurface(Test::waylandCompositor()); | ||
182 | VERIFY(surface); | 107 | VERIFY(surface); | ||
183 | ShellSurface *shellSurface = m_shell->createSurface(surface, surface); | 108 | ShellSurface *shellSurface = Test::createShellSurface(surface, surface); | ||
184 | VERIFY(shellSurface); | 109 | VERIFY(shellSurface); | ||
185 | // let's render | 110 | // let's render | ||
186 | QImage img(QSize(100, 50), QImage::Format_ARGB32); | 111 | Test::render(surface, QSize(100, 50), Qt::blue); | ||
187 | img.fill(Qt::blue); | | |||
188 | surface->attachBuffer(m_shm->createBuffer(img)); | | |||
189 | surface->damage(QRect(0, 0, 100, 50)); | | |||
190 | surface->commit(Surface::CommitFlag::None); | | |||
191 | 112 | | |||
192 | m_connection->flush(); | 113 | Test::flushWaylandConnection(); | ||
193 | VERIFY(clientAddedSpy.wait()); | 114 | VERIFY(clientAddedSpy.wait()); | ||
194 | AbstractClient *c = workspace()->activeClient(); | 115 | AbstractClient *c = workspace()->activeClient(); | ||
195 | VERIFY(c); | 116 | VERIFY(c); | ||
196 | COMPARE(clientAddedSpy.first().first().value<ShellClient*>(), c); | 117 | COMPARE(clientAddedSpy.first().first().value<ShellClient*>(), c); | ||
197 | 118 | | |||
198 | #undef VERIFY | 119 | #undef VERIFY | ||
199 | #undef COMPARE | 120 | #undef COMPARE | ||
200 | 121 | | |||
▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines |