16#include <linux/input.h>
21using namespace std::literals;
32 void testAbsoluteMotion_data();
33 void testAbsoluteMotion();
37 Device *m_device =
nullptr;
40void TestLibinputTouchEvent::init()
43 m_nativeDevice->
touch =
true;
44 m_nativeDevice->
deviceSize = QSizeF(12.5, 13.8);
45 m_device =
new Device(m_nativeDevice);
48void TestLibinputTouchEvent::cleanup()
53 delete m_nativeDevice;
54 m_nativeDevice =
nullptr;
57void TestLibinputTouchEvent::testType_data()
59 QTest::addColumn<libinput_event_type>(
"type");
60 QTest::addColumn<bool>(
"hasId");
62 QTest::newRow(
"down") << LIBINPUT_EVENT_TOUCH_DOWN <<
true;
63 QTest::newRow(
"up") << LIBINPUT_EVENT_TOUCH_UP <<
true;
64 QTest::newRow(
"motion") << LIBINPUT_EVENT_TOUCH_MOTION <<
true;
65 QTest::newRow(
"cancel") << LIBINPUT_EVENT_TOUCH_CANCEL <<
false;
66 QTest::newRow(
"frame") << LIBINPUT_EVENT_TOUCH_FRAME <<
false;
69void TestLibinputTouchEvent::testType()
73 QFETCH(libinput_event_type, type);
75 touchEvent->
device = m_nativeDevice;
80 QCOMPARE(event->type(), type);
81 QCOMPARE(event->device(), m_device);
82 QCOMPARE(event->nativeDevice(), m_nativeDevice);
85 QVERIFY(
dynamic_cast<TouchEvent *
>(event.get()));
89 QCOMPARE(
dynamic_cast<TouchEvent *
>(event.get())->
id(), 0);
93void TestLibinputTouchEvent::testAbsoluteMotion_data()
95 QTest::addColumn<libinput_event_type>(
"type");
96 QTest::newRow(
"down") << LIBINPUT_EVENT_TOUCH_DOWN;
97 QTest::newRow(
"motion") << LIBINPUT_EVENT_TOUCH_MOTION;
100void TestLibinputTouchEvent::testAbsoluteMotion()
104 touchEvent->
device = m_nativeDevice;
105 QFETCH(libinput_event_type, type);
108 touchEvent->
time = 500ms;
109 touchEvent->
slot = 1;
112 auto te =
dynamic_cast<TouchEvent *
>(
event.get());
114 QCOMPARE(te->type(), type);
115 QCOMPARE(te->time(), touchEvent->
time);
116 QCOMPARE(te->absolutePos(), QPointF(6.25, 6.9));
117 QCOMPARE(te->absolutePos(QSize(1280, 1024)), QPointF(640, 512));
121#include "touch_event_test.moc"