Changeset View
Changeset View
Standalone View
Standalone View
autotests/libinput/input_event_test.cpp
Show All 17 Lines | |||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "mock_libinput.h" | 20 | #include "mock_libinput.h" | ||
21 | #include "../../libinput/device.h" | 21 | #include "../../libinput/device.h" | ||
22 | #include "../input_event.h" | 22 | #include "../input_event.h" | ||
23 | 23 | | |||
24 | #include <QtTest/QtTest> | 24 | #include <QtTest/QtTest> | ||
25 | 25 | | |||
26 | Q_DECLARE_METATYPE(KWin::SwitchEvent::State); | ||||
27 | | ||||
26 | using namespace KWin; | 28 | using namespace KWin; | ||
27 | using namespace KWin::LibInput; | 29 | using namespace KWin::LibInput; | ||
28 | 30 | | |||
29 | class InputEventsTest : public QObject | 31 | class InputEventsTest : public QObject | ||
30 | { | 32 | { | ||
31 | Q_OBJECT | 33 | Q_OBJECT | ||
32 | private Q_SLOTS: | 34 | private Q_SLOTS: | ||
33 | void testInitMouseEvent_data(); | 35 | void testInitMouseEvent_data(); | ||
34 | void testInitMouseEvent(); | 36 | void testInitMouseEvent(); | ||
35 | void testInitKeyEvent_data(); | 37 | void testInitKeyEvent_data(); | ||
36 | void testInitKeyEvent(); | 38 | void testInitKeyEvent(); | ||
37 | void testInitWheelEvent_data(); | 39 | void testInitWheelEvent_data(); | ||
38 | void testInitWheelEvent(); | 40 | void testInitWheelEvent(); | ||
41 | void testInitSwitchEvent_data(); | ||||
42 | void testInitSwitchEvent(); | ||||
39 | }; | 43 | }; | ||
40 | 44 | | |||
41 | void InputEventsTest::testInitMouseEvent_data() | 45 | void InputEventsTest::testInitMouseEvent_data() | ||
42 | { | 46 | { | ||
43 | QTest::addColumn<QEvent::Type>("type"); | 47 | QTest::addColumn<QEvent::Type>("type"); | ||
44 | 48 | | |||
45 | QTest::newRow("Press") << QEvent::MouseButtonPress; | 49 | QTest::newRow("Press") << QEvent::MouseButtonPress; | ||
46 | QTest::newRow("Release") << QEvent::MouseButtonRelease; | 50 | QTest::newRow("Release") << QEvent::MouseButtonRelease; | ||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 131 | { | |||
144 | QCOMPARE(event.modifiers(), Qt::ShiftModifier | Qt::ControlModifier); | 148 | QCOMPARE(event.modifiers(), Qt::ShiftModifier | Qt::ControlModifier); | ||
145 | QCOMPARE(event.timestamp(), 300ul); | 149 | QCOMPARE(event.timestamp(), 300ul); | ||
146 | QTEST(event.angleDelta(), "expectedAngleDelta"); | 150 | QTEST(event.angleDelta(), "expectedAngleDelta"); | ||
147 | // and our custom argument | 151 | // and our custom argument | ||
148 | QCOMPARE(event.device(), &d); | 152 | QCOMPARE(event.device(), &d); | ||
149 | 153 | | |||
150 | } | 154 | } | ||
151 | 155 | | |||
156 | void InputEventsTest::testInitSwitchEvent_data() | ||||
157 | { | ||||
158 | QTest::addColumn<KWin::SwitchEvent::State>("state"); | ||||
159 | QTest::addColumn<quint32>("timestamp"); | ||||
160 | QTest::addColumn<quint64>("micro"); | ||||
161 | | ||||
162 | QTest::newRow("on") << SwitchEvent::State::On << 23u << quint64{23456790}; | ||||
163 | QTest::newRow("off") << SwitchEvent::State::Off << 456892u << quint64{45689235987}; | ||||
164 | } | ||||
165 | | ||||
166 | void InputEventsTest::testInitSwitchEvent() | ||||
167 | { | ||||
168 | // this test verifies that a SwitchEvent is constructed correctly | ||||
169 | libinput_device device; | ||||
170 | Device d(&device); | ||||
171 | | ||||
172 | QFETCH(SwitchEvent::State, state); | ||||
173 | QFETCH(quint32, timestamp); | ||||
174 | QFETCH(quint64, micro); | ||||
175 | SwitchEvent event(state, timestamp, micro, &d); | ||||
176 | | ||||
177 | QCOMPARE(event.state(), state); | ||||
178 | QCOMPARE(event.timestamp(), ulong(timestamp)); | ||||
179 | QCOMPARE(event.timestampMicroseconds(), micro); | ||||
180 | QCOMPARE(event.device(), &d); | ||||
181 | } | ||||
182 | | ||||
152 | QTEST_GUILESS_MAIN(InputEventsTest) | 183 | QTEST_GUILESS_MAIN(InputEventsTest) | ||
153 | #include "input_event_test.moc" | 184 | #include "input_event_test.moc" |