16#include <linux/input.h>
22using namespace std::literals;
33 void testButton_data();
35 void testScrollWheel_data();
36 void testScrollWheel();
37 void testScrollFinger_data();
38 void testScrollFinger();
39 void testScrollContinuous_data();
40 void testScrollContinuous();
42 void testAbsoluteMotion();
46 Device *m_device =
nullptr;
49void TestLibinputPointerEvent::init()
53 m_nativeDevice->
deviceSize = QSizeF(12.5, 13.8);
54 m_device =
new Device(m_nativeDevice);
57void TestLibinputPointerEvent::cleanup()
62 delete m_nativeDevice;
63 m_nativeDevice =
nullptr;
66void TestLibinputPointerEvent::testType_data()
68 QTest::addColumn<libinput_event_type>(
"type");
70 QTest::newRow(
"motion") << LIBINPUT_EVENT_POINTER_MOTION;
71 QTest::newRow(
"absolute motion") << LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE;
72 QTest::newRow(
"button") << LIBINPUT_EVENT_POINTER_BUTTON;
73 QTest::newRow(
"scroll wheel") << LIBINPUT_EVENT_POINTER_SCROLL_WHEEL;
74 QTest::newRow(
"scroll finger") << LIBINPUT_EVENT_POINTER_SCROLL_FINGER;
75 QTest::newRow(
"scroll continuous") << LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS;
78void TestLibinputPointerEvent::testType()
82 QFETCH(libinput_event_type, type);
84 pointerEvent->
device = m_nativeDevice;
88 QCOMPARE(event->type(), type);
89 QCOMPARE(event->device(), m_device);
90 QCOMPARE(event->nativeDevice(), m_nativeDevice);
97void TestLibinputPointerEvent::testButton_data()
99 QTest::addColumn<libinput_button_state>(
"buttonState");
100 QTest::addColumn<KWin::InputRedirection::PointerButtonState>(
"expectedButtonState");
101 QTest::addColumn<quint32>(
"button");
102 QTest::addColumn<quint32>(
"time");
108void TestLibinputPointerEvent::testButton()
112 pointerEvent->
device = m_nativeDevice;
113 pointerEvent->
type = LIBINPUT_EVENT_POINTER_BUTTON;
114 QFETCH(libinput_button_state, buttonState);
116 QFETCH(quint32, button);
117 pointerEvent->
button = button;
118 QFETCH(quint32, time);
119 pointerEvent->
time = std::chrono::milliseconds(time);
124 QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_BUTTON);
125 QTEST(pe->buttonState(),
"expectedButtonState");
126 QCOMPARE(pe->button(), button);
127 QCOMPARE(pe->time(), pointerEvent->
time);
130void TestLibinputPointerEvent::testScrollWheel_data()
132 QTest::addColumn<bool>(
"horizontal");
133 QTest::addColumn<bool>(
"vertical");
134 QTest::addColumn<QPointF>(
"value");
135 QTest::addColumn<QPoint>(
"valueV120");
136 QTest::addColumn<quint32>(
"time");
138 QTest::newRow(
"wheel/horizontal") <<
true <<
false << QPointF(3.0, 0.0) << QPoint(120, 0) << 100u;
139 QTest::newRow(
"wheel/vertical") <<
false <<
true << QPointF(0.0, 2.5) << QPoint(0, 120) << 200u;
140 QTest::newRow(
"wheel/both") <<
true <<
true << QPointF(1.1, 4.2) << QPoint(120, 120) << 300u;
143void TestLibinputPointerEvent::testScrollWheel()
147 pointerEvent->
device = m_nativeDevice;
148 pointerEvent->
type = LIBINPUT_EVENT_POINTER_SCROLL_WHEEL;
149 QFETCH(
bool, horizontal);
150 QFETCH(
bool, vertical);
151 QFETCH(QPointF, value);
152 QFETCH(QPoint, valueV120);
153 QFETCH(quint32, time);
160 pointerEvent->
time = std::chrono::milliseconds(time);
165 QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_SCROLL_WHEEL);
172 QCOMPARE(pe->time(), pointerEvent->
time);
175void TestLibinputPointerEvent::testScrollFinger_data()
177 QTest::addColumn<bool>(
"horizontal");
178 QTest::addColumn<bool>(
"vertical");
179 QTest::addColumn<QPointF>(
"value");
180 QTest::addColumn<quint32>(
"time");
182 QTest::newRow(
"finger/horizontal") <<
true <<
false << QPointF(3.0, 0.0) << 400u;
183 QTest::newRow(
"stop finger/horizontal") <<
true <<
false << QPointF(0.0, 0.0) << 500u;
184 QTest::newRow(
"finger/vertical") <<
false <<
true << QPointF(0.0, 2.5) << 600u;
185 QTest::newRow(
"stop finger/vertical") <<
false <<
true << QPointF(0.0, 0.0) << 700u;
186 QTest::newRow(
"finger/both") <<
true <<
true << QPointF(1.1, 4.2) << 800u;
187 QTest::newRow(
"stop finger/both") <<
true <<
true << QPointF(0.0, 0.0) << 900u;
190void TestLibinputPointerEvent::testScrollFinger()
194 pointerEvent->
device = m_nativeDevice;
195 pointerEvent->
type = LIBINPUT_EVENT_POINTER_SCROLL_FINGER;
196 QFETCH(
bool, horizontal);
197 QFETCH(
bool, vertical);
198 QFETCH(QPointF, value);
199 QFETCH(quint32, time);
204 pointerEvent->
time = std::chrono::milliseconds(time);
209 QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
214 QCOMPARE(pe->time(), pointerEvent->
time);
217void TestLibinputPointerEvent::testScrollContinuous_data()
219 QTest::addColumn<bool>(
"horizontal");
220 QTest::addColumn<bool>(
"vertical");
221 QTest::addColumn<QPointF>(
"value");
222 QTest::addColumn<quint32>(
"time");
224 QTest::newRow(
"continuous/horizontal") <<
true <<
false << QPointF(3.0, 0.0) << 1000u;
225 QTest::newRow(
"continuous/vertical") <<
false <<
true << QPointF(0.0, 2.5) << 1100u;
226 QTest::newRow(
"continuous/both") <<
true <<
true << QPointF(1.1, 4.2) << 1200u;
229void TestLibinputPointerEvent::testScrollContinuous()
233 pointerEvent->
device = m_nativeDevice;
234 pointerEvent->
type = LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS;
235 QFETCH(
bool, horizontal);
236 QFETCH(
bool, vertical);
237 QFETCH(QPointF, value);
238 QFETCH(quint32, time);
243 pointerEvent->
time = std::chrono::milliseconds(time);
248 QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS);
253 QCOMPARE(pe->time(), pointerEvent->
time);
256void TestLibinputPointerEvent::testMotion()
260 pointerEvent->
device = m_nativeDevice;
261 pointerEvent->
type = LIBINPUT_EVENT_POINTER_MOTION;
262 pointerEvent->
delta = QPointF(2.1, 4.5);
263 pointerEvent->
time = 500ms;
268 QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_MOTION);
269 QCOMPARE(pe->time(), pointerEvent->
time);
270 QCOMPARE(pe->delta(), QPointF(2.1, 4.5));
273void TestLibinputPointerEvent::testAbsoluteMotion()
277 pointerEvent->
device = m_nativeDevice;
278 pointerEvent->
type = LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE;
280 pointerEvent->
time = 500ms;
285 QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE);
286 QCOMPARE(pe->time(), pointerEvent->
time);
287 QCOMPARE(pe->absolutePos(), QPointF(6.25, 6.9));
288 QCOMPARE(pe->absolutePos(QSize(1280, 1024)), QPointF(640, 512));
292#include "pointer_event_test.moc"