Changeset View
Changeset View
Standalone View
Standalone View
autotests/libinput/pointer_event_test.cpp
Show All 21 Lines | |||||
22 | #include "../../libinput/events.h" | 22 | #include "../../libinput/events.h" | ||
23 | 23 | | |||
24 | #include <QtTest> | 24 | #include <QtTest> | ||
25 | 25 | | |||
26 | #include <linux/input.h> | 26 | #include <linux/input.h> | ||
27 | 27 | | |||
28 | Q_DECLARE_METATYPE(libinput_event_type) | 28 | Q_DECLARE_METATYPE(libinput_event_type) | ||
29 | Q_DECLARE_METATYPE(libinput_button_state) | 29 | Q_DECLARE_METATYPE(libinput_button_state) | ||
30 | Q_DECLARE_METATYPE(libinput_pointer_axis_source) | ||||
30 | 31 | | |||
31 | using namespace KWin::LibInput; | 32 | using namespace KWin::LibInput; | ||
32 | 33 | | |||
33 | class TestLibinputPointerEvent : public QObject | 34 | class TestLibinputPointerEvent : public QObject | ||
34 | { | 35 | { | ||
35 | Q_OBJECT | 36 | Q_OBJECT | ||
36 | private Q_SLOTS: | 37 | private Q_SLOTS: | ||
37 | void init(); | 38 | void init(); | ||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | 113 | { | |||
131 | QCOMPARE(pe->timeMicroseconds(), quint64(time * 1000)); | 132 | QCOMPARE(pe->timeMicroseconds(), quint64(time * 1000)); | ||
132 | } | 133 | } | ||
133 | 134 | | |||
134 | void TestLibinputPointerEvent::testAxis_data() | 135 | void TestLibinputPointerEvent::testAxis_data() | ||
135 | { | 136 | { | ||
136 | QTest::addColumn<bool>("horizontal"); | 137 | QTest::addColumn<bool>("horizontal"); | ||
137 | QTest::addColumn<bool>("vertical"); | 138 | QTest::addColumn<bool>("vertical"); | ||
138 | QTest::addColumn<QPointF>("value"); | 139 | QTest::addColumn<QPointF>("value"); | ||
140 | QTest::addColumn<QPoint>("discreteValue"); | ||||
141 | QTest::addColumn<libinput_pointer_axis_source>("axisSource"); | ||||
142 | QTest::addColumn<KWin::InputRedirection::PointerAxisSource>("expectedAxisSource"); | ||||
139 | QTest::addColumn<quint32>("time"); | 143 | QTest::addColumn<quint32>("time"); | ||
140 | 144 | | |||
141 | QTest::newRow("horizontal") << true << false << QPointF(3.0, 0.0) << 100u; | 145 | QTest::newRow("wheel/horizontal") << true << false << QPointF(3.0, 0.0) << QPoint(1, 0) << LIBINPUT_POINTER_AXIS_SOURCE_WHEEL << KWin::InputRedirection::PointerAxisSourceWheel << 100u; | ||
142 | QTest::newRow("vertical") << false << true << QPointF(0.0, 2.5) << 200u; | 146 | QTest::newRow("wheel/vertical") << false << true << QPointF(0.0, 2.5) << QPoint(0, 1) << LIBINPUT_POINTER_AXIS_SOURCE_WHEEL << KWin::InputRedirection::PointerAxisSourceWheel << 200u; | ||
143 | QTest::newRow("both") << true << true << QPointF(1.1, 4.2) << 300u; | 147 | QTest::newRow("wheel/both") << true << true << QPointF(1.1, 4.2) << QPoint(1, 1) << LIBINPUT_POINTER_AXIS_SOURCE_WHEEL << KWin::InputRedirection::PointerAxisSourceWheel << 300u; | ||
148 | | ||||
149 | QTest::newRow("finger/horizontal") << true << false << QPointF(3.0, 0.0) << QPoint(0, 0) << LIBINPUT_POINTER_AXIS_SOURCE_FINGER << KWin::InputRedirection::PointerAxisSourceFinger << 400u; | ||||
150 | QTest::newRow("stop finger/horizontal") << true << false << QPointF(0.0, 0.0) << QPoint(0, 0) << LIBINPUT_POINTER_AXIS_SOURCE_FINGER << KWin::InputRedirection::PointerAxisSourceFinger << 500u; | ||||
151 | QTest::newRow("finger/vertical") << false << true << QPointF(0.0, 2.5) << QPoint(0, 0) << LIBINPUT_POINTER_AXIS_SOURCE_FINGER << KWin::InputRedirection::PointerAxisSourceFinger << 600u; | ||||
152 | QTest::newRow("stop finger/vertical") << false << true << QPointF(0.0, 0.0) << QPoint(0, 0) << LIBINPUT_POINTER_AXIS_SOURCE_FINGER << KWin::InputRedirection::PointerAxisSourceFinger << 700u; | ||||
153 | QTest::newRow("finger/both") << true << true << QPointF(1.1, 4.2) << QPoint(0, 0) << LIBINPUT_POINTER_AXIS_SOURCE_FINGER << KWin::InputRedirection::PointerAxisSourceFinger << 800u; | ||||
154 | QTest::newRow("stop finger/both") << true << true << QPointF(0.0, 0.0) << QPoint(0, 0) << LIBINPUT_POINTER_AXIS_SOURCE_FINGER << KWin::InputRedirection::PointerAxisSourceFinger << 900u; | ||||
155 | | ||||
156 | QTest::newRow("continuous/horizontal") << true << false << QPointF(3.0, 0.0) << QPoint(0, 0) << LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS << KWin::InputRedirection::PointerAxisSourceContinuous << 1000u; | ||||
157 | QTest::newRow("continuous/vertical") << false << true << QPointF(0.0, 2.5) << QPoint(0, 0) << LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS << KWin::InputRedirection::PointerAxisSourceContinuous << 1100u; | ||||
158 | QTest::newRow("continuous/both") << true << true << QPointF(1.1, 4.2) << QPoint(0, 0) << LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS << KWin::InputRedirection::PointerAxisSourceContinuous << 1200u; | ||||
144 | } | 159 | } | ||
145 | 160 | | |||
146 | void TestLibinputPointerEvent::testAxis() | 161 | void TestLibinputPointerEvent::testAxis() | ||
147 | { | 162 | { | ||
148 | // this test verifies pointer axis functionality | 163 | // this test verifies pointer axis functionality | ||
149 | libinput_event_pointer *pointerEvent = new libinput_event_pointer; | 164 | libinput_event_pointer *pointerEvent = new libinput_event_pointer; | ||
150 | pointerEvent->device = m_nativeDevice; | 165 | pointerEvent->device = m_nativeDevice; | ||
151 | pointerEvent->type = LIBINPUT_EVENT_POINTER_AXIS; | 166 | pointerEvent->type = LIBINPUT_EVENT_POINTER_AXIS; | ||
152 | QFETCH(bool, horizontal); | 167 | QFETCH(bool, horizontal); | ||
153 | QFETCH(bool, vertical); | 168 | QFETCH(bool, vertical); | ||
154 | QFETCH(QPointF, value); | 169 | QFETCH(QPointF, value); | ||
170 | QFETCH(QPoint, discreteValue); | ||||
171 | QFETCH(libinput_pointer_axis_source, axisSource); | ||||
155 | QFETCH(quint32, time); | 172 | QFETCH(quint32, time); | ||
156 | pointerEvent->horizontalAxis = horizontal; | 173 | pointerEvent->horizontalAxis = horizontal; | ||
157 | pointerEvent->verticalAxis = vertical; | 174 | pointerEvent->verticalAxis = vertical; | ||
158 | pointerEvent->horizontalAxisValue = value.x(); | 175 | pointerEvent->horizontalAxisValue = value.x(); | ||
159 | pointerEvent->verticalAxisValue = value.y(); | 176 | pointerEvent->verticalAxisValue = value.y(); | ||
177 | pointerEvent->horizontalDiscreteAxisValue = discreteValue.x(); | ||||
178 | pointerEvent->verticalDiscreteAxisValue = discreteValue.y(); | ||||
179 | pointerEvent->axisSource = axisSource; | ||||
160 | pointerEvent->time = time; | 180 | pointerEvent->time = time; | ||
161 | 181 | | |||
162 | QScopedPointer<Event> event(Event::create(pointerEvent)); | 182 | QScopedPointer<Event> event(Event::create(pointerEvent)); | ||
163 | auto pe = dynamic_cast<PointerEvent*>(event.data()); | 183 | auto pe = dynamic_cast<PointerEvent*>(event.data()); | ||
164 | QVERIFY(pe); | 184 | QVERIFY(pe); | ||
165 | QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_AXIS); | 185 | QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_AXIS); | ||
166 | QCOMPARE(pe->axis().contains(KWin::InputRedirection::PointerAxisHorizontal), horizontal); | 186 | QCOMPARE(pe->axis().contains(KWin::InputRedirection::PointerAxisHorizontal), horizontal); | ||
167 | QCOMPARE(pe->axis().contains(KWin::InputRedirection::PointerAxisVertical), vertical); | 187 | QCOMPARE(pe->axis().contains(KWin::InputRedirection::PointerAxisVertical), vertical); | ||
168 | QCOMPARE(pe->axisValue(KWin::InputRedirection::PointerAxisHorizontal), value.x()); | 188 | QCOMPARE(pe->axisValue(KWin::InputRedirection::PointerAxisHorizontal), value.x()); | ||
169 | QCOMPARE(pe->axisValue(KWin::InputRedirection::PointerAxisVertical), value.y()); | 189 | QCOMPARE(pe->axisValue(KWin::InputRedirection::PointerAxisVertical), value.y()); | ||
190 | QCOMPARE(pe->discreteAxisValue(KWin::InputRedirection::PointerAxisHorizontal), discreteValue.x()); | ||||
191 | QCOMPARE(pe->discreteAxisValue(KWin::InputRedirection::PointerAxisVertical), discreteValue.y()); | ||||
192 | QTEST(pe->axisSource(), "expectedAxisSource"); | ||||
170 | QCOMPARE(pe->time(), time); | 193 | QCOMPARE(pe->time(), time); | ||
171 | } | 194 | } | ||
172 | 195 | | |||
173 | void TestLibinputPointerEvent::testMotion() | 196 | void TestLibinputPointerEvent::testMotion() | ||
174 | { | 197 | { | ||
175 | // this test verifies pointer motion (delta) | 198 | // this test verifies pointer motion (delta) | ||
176 | libinput_event_pointer *pointerEvent = new libinput_event_pointer; | 199 | libinput_event_pointer *pointerEvent = new libinput_event_pointer; | ||
177 | pointerEvent->device = m_nativeDevice; | 200 | pointerEvent->device = m_nativeDevice; | ||
Show All 32 Lines |