15#include <linux/input-event-codes.h>
20static const QString s_socketName = QStringLiteral(
"wayland_test_kwin_fakeinput-0");
30 void testPointerMotion();
31 void testMotionAbsolute();
32 void testPointerButton_data();
33 void testPointerButton();
34 void testPointerVerticalAxis();
35 void testPointerHorizontalAxis();
37 void testKeyboardKey_data();
38 void testKeyboardKey();
44void FakeInputTest::initTestCase()
49 QRect(0, 0, 1280, 1024),
50 QRect(1280, 0, 1280, 1024),
54 QVERIFY(applicationStartedSpy.wait());
57void FakeInputTest::init()
62 QVERIFY(deviceAddedSpy.wait());
63 m_inputDevice = deviceAddedSpy.last().at(0).value<
InputDevice *>();
66void FakeInputTest::cleanup()
71void FakeInputTest::testPointerMotion()
77 fakeInput->pointer_motion(wl_fixed_from_double(1), wl_fixed_from_double(2));
79 QVERIFY(pointerMotionSpy.isEmpty());
82 fakeInput->authenticate(QStringLiteral(
"org.kde.foobar"), QStringLiteral(
"foobar"));
83 fakeInput->pointer_motion(wl_fixed_from_double(1), wl_fixed_from_double(2));
84 QVERIFY(pointerMotionSpy.wait());
85 QCOMPARE(pointerMotionSpy.last().first().toPointF(), QPointF(1, 2));
88 fakeInput->pointer_motion(wl_fixed_from_double(0), wl_fixed_from_double(0));
89 QVERIFY(pointerMotionSpy.wait());
90 QCOMPARE(pointerMotionSpy.last().first().toPointF(), QPointF(0, 0));
93void FakeInputTest::testMotionAbsolute()
99 fakeInput->pointer_motion_absolute(wl_fixed_from_double(1), wl_fixed_from_double(2));
101 QVERIFY(pointerMotionAbsoluteSpy.isEmpty());
104 fakeInput->authenticate(QStringLiteral(
"org.kde.foobar"), QStringLiteral(
"foobar"));
105 fakeInput->pointer_motion_absolute(wl_fixed_from_double(1), wl_fixed_from_double(2));
106 QVERIFY(pointerMotionAbsoluteSpy.wait());
107 QCOMPARE(pointerMotionAbsoluteSpy.last().first().toPointF(), QPointF(1, 2));
110void FakeInputTest::testPointerButton_data()
112 QTest::addColumn<quint32>(
"linuxButton");
114 QTest::newRow(
"left") << quint32(BTN_LEFT);
115 QTest::newRow(
"right") << quint32(BTN_RIGHT);
116 QTest::newRow(
"middle") << quint32(BTN_MIDDLE);
117 QTest::newRow(
"side") << quint32(BTN_SIDE);
118 QTest::newRow(
"extra") << quint32(BTN_EXTRA);
119 QTest::newRow(
"forward") << quint32(BTN_FORWARD);
120 QTest::newRow(
"back") << quint32(BTN_BACK);
121 QTest::newRow(
"task") << quint32(BTN_TASK);
124void FakeInputTest::testPointerButton()
130 QFETCH(quint32, linuxButton);
131 fakeInput->button(linuxButton, WL_POINTER_BUTTON_STATE_PRESSED);
133 QVERIFY(pointerButtonSpy.isEmpty());
136 fakeInput->authenticate(QStringLiteral(
"org.kde.foobar"), QStringLiteral(
"foobar"));
137 fakeInput->button(linuxButton, WL_POINTER_BUTTON_STATE_PRESSED);
138 QVERIFY(pointerButtonSpy.wait());
139 QCOMPARE(pointerButtonSpy.last().at(0).value<quint32>(), linuxButton);
143 fakeInput->button(linuxButton, WL_POINTER_BUTTON_STATE_RELEASED);
144 QVERIFY(pointerButtonSpy.wait());
145 QCOMPARE(pointerButtonSpy.last().at(0).value<quint32>(), linuxButton);
149void FakeInputTest::testPointerVerticalAxis()
155 fakeInput->axis(WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_double(15));
157 QVERIFY(pointerAxisSpy.isEmpty());
160 fakeInput->authenticate(QStringLiteral(
"org.kde.foobar"), QStringLiteral(
"foobar"));
161 fakeInput->axis(WL_POINTER_AXIS_VERTICAL_SCROLL, wl_fixed_from_double(15));
162 QVERIFY(pointerAxisSpy.wait());
164 QCOMPARE(pointerAxisSpy.last().at(1).value<qreal>(), 15);
167void FakeInputTest::testPointerHorizontalAxis()
173 fakeInput->axis(WL_POINTER_AXIS_HORIZONTAL_SCROLL, wl_fixed_from_double(15));
175 QVERIFY(pointerAxisSpy.isEmpty());
178 fakeInput->authenticate(QStringLiteral(
"org.kde.foobar"), QStringLiteral(
"foobar"));
179 fakeInput->axis(WL_POINTER_AXIS_HORIZONTAL_SCROLL, wl_fixed_from_double(15));
180 QVERIFY(pointerAxisSpy.wait());
182 QCOMPARE(pointerAxisSpy.last().at(1).value<qreal>(), 15);
185void FakeInputTest::testTouch()
195 fakeInput->touch_down(0, wl_fixed_from_double(1), wl_fixed_from_double(2));
197 QVERIFY(touchDownSpy.isEmpty());
199 fakeInput->touch_motion(0, wl_fixed_from_double(3), wl_fixed_from_double(4));
201 QVERIFY(touchMotionSpy.isEmpty());
205 QVERIFY(touchUpSpy.isEmpty());
207 fakeInput->touch_down(1, wl_fixed_from_double(5), wl_fixed_from_double(6));
209 QVERIFY(touchDownSpy.isEmpty());
213 QVERIFY(touchFrameSpy.isEmpty());
217 QVERIFY(touchCanceledSpy.isEmpty());
220 fakeInput->authenticate(QStringLiteral(
"org.kde.foobar"), QStringLiteral(
"foobar"));
221 fakeInput->touch_down(0, wl_fixed_from_double(1), wl_fixed_from_double(2));
222 QVERIFY(touchDownSpy.wait());
223 QCOMPARE(touchDownSpy.count(), 1);
224 QCOMPARE(touchDownSpy.last().at(0).value<quint32>(), quint32(0));
225 QCOMPARE(touchDownSpy.last().at(1).toPointF(), QPointF(1, 2));
228 fakeInput->touch_down(0, wl_fixed_from_double(5), wl_fixed_from_double(6));
230 QCOMPARE(touchDownSpy.count(), 1);
232 fakeInput->touch_motion(0, wl_fixed_from_double(3), wl_fixed_from_double(4));
233 QVERIFY(touchMotionSpy.wait());
234 QCOMPARE(touchMotionSpy.count(), 1);
235 QCOMPARE(touchMotionSpy.last().at(0).value<quint32>(), quint32(0));
236 QCOMPARE(touchMotionSpy.last().at(1).toPointF(), QPointF(3, 4));
239 fakeInput->touch_motion(1, wl_fixed_from_double(3), wl_fixed_from_double(4));
241 QCOMPARE(touchMotionSpy.count(), 1);
244 QVERIFY(touchUpSpy.wait());
245 QCOMPARE(touchUpSpy.count(), 1);
246 QCOMPARE(touchUpSpy.last().at(0).value<quint32>(), quint32(0));
251 QCOMPARE(touchUpSpy.count(), 1);
253 fakeInput->touch_down(1, wl_fixed_from_double(5), wl_fixed_from_double(6));
254 QVERIFY(touchDownSpy.wait());
255 QCOMPARE(touchDownSpy.count(), 2);
256 QCOMPARE(touchDownSpy.last().at(0).value<quint32>(), quint32(1));
257 QCOMPARE(touchDownSpy.last().at(1).toPointF(), QPointF(5, 6));
260 QVERIFY(touchFrameSpy.wait());
261 QCOMPARE(touchFrameSpy.count(), 1);
264 QVERIFY(touchCanceledSpy.wait());
265 QCOMPARE(touchCanceledSpy.count(), 1);
268void FakeInputTest::testKeyboardKey_data()
270 QTest::addColumn<quint32>(
"linuxKey");
272 QTest::newRow(
"A") << quint32(KEY_A);
273 QTest::newRow(
"S") << quint32(KEY_S);
274 QTest::newRow(
"D") << quint32(KEY_D);
275 QTest::newRow(
"F") << quint32(KEY_F);
278void FakeInputTest::testKeyboardKey()
284 QFETCH(quint32, linuxKey);
285 fakeInput->keyboard_key(linuxKey, WL_KEYBOARD_KEY_STATE_PRESSED);
287 QVERIFY(keyboardKeySpy.isEmpty());
290 fakeInput->authenticate(QStringLiteral(
"org.kde.foobar"), QStringLiteral(
"foobar"));
291 fakeInput->keyboard_key(linuxKey, WL_KEYBOARD_KEY_STATE_PRESSED);
292 QVERIFY(keyboardKeySpy.wait());
293 QCOMPARE(keyboardKeySpy.last().at(0).value<quint32>(), linuxKey);
297 fakeInput->keyboard_key(linuxKey, WL_KEYBOARD_KEY_STATE_RELEASED);
298 QVERIFY(keyboardKeySpy.wait());
299 QCOMPARE(keyboardKeySpy.last().at(0).value<quint32>(), linuxKey);
306#include "fakeinput_test.moc"
#define WAYLANDTEST_MAIN(TestObject)
void destroyWaylandConnection()
void setOutputConfig(const QList< QRect > &geometries)
bool setupWaylandConnection(AdditionalWaylandInterfaces flags=AdditionalWaylandInterfaces())
FakeInput * waylandFakeInput()
WaylandServer * waylandServer()
InputRedirection * input()