1 /* 2 KWin - the KDE window manager 3 This file is part of the KDE project. 4 5 SPDX-FileCopyrightText: 2017 Martin Flöser <mgraesslin@kde.org> 6 7 SPDX-License-Identifier: GPL-2.0-or-later 8 */ 9 #include "mock_libinput.h" 10 11 #include "libinput/device.h" 12 #include "libinput/events.h" 13 14 #include <QtTest> 15 16 #include <memory> 17 18 Q_DECLARE_METATYPE(KWin::LibInput::SwitchEvent::State) 19 20 using namespace KWin::LibInput; 21 22 class TestLibinputSwitchEvent : public QObject 23 { 24 Q_OBJECT 25 private Q_SLOTS: 26 void init(); 27 void cleanup(); 28 29 void testToggled_data(); 30 void testToggled(); 31 32 private: 33 std::unique_ptr<libinput_device> m_nativeDevice; 34 std::unique_ptr<Device> m_device; 35 }; 36 init()37void TestLibinputSwitchEvent::init() 38 { 39 m_nativeDevice = std::make_unique<libinput_device>(); 40 m_nativeDevice->switchDevice = true; 41 m_device = std::make_unique<Device>(m_nativeDevice.get()); 42 } 43 cleanup()44void TestLibinputSwitchEvent::cleanup() 45 { 46 m_device.reset(); 47 m_nativeDevice.reset(); 48 } 49 testToggled_data()50void TestLibinputSwitchEvent::testToggled_data() 51 { 52 QTest::addColumn<KWin::LibInput::SwitchEvent::State>("state"); 53 54 QTest::newRow("on") << KWin::LibInput::SwitchEvent::State::On; 55 QTest::newRow("off") << KWin::LibInput::SwitchEvent::State::Off; 56 } 57 testToggled()58void TestLibinputSwitchEvent::testToggled() 59 { 60 libinput_event_switch *nativeEvent = new libinput_event_switch; 61 nativeEvent->type = LIBINPUT_EVENT_SWITCH_TOGGLE; 62 nativeEvent->device = m_nativeDevice.get(); 63 QFETCH(KWin::LibInput::SwitchEvent::State, state); 64 switch (state) { 65 case SwitchEvent::State::Off: 66 nativeEvent->state = libinput_event_switch::State::Off; 67 break; 68 case SwitchEvent::State::On: 69 nativeEvent->state = libinput_event_switch::State::On; 70 break; 71 default: 72 Q_UNREACHABLE(); 73 } 74 nativeEvent->time = 23; 75 nativeEvent->timeMicroseconds = 23456789; 76 77 QScopedPointer<Event> event(Event::create(nativeEvent)); 78 auto se = dynamic_cast<SwitchEvent*>(event.data()); 79 QVERIFY(se); 80 QCOMPARE(se->device(), m_device.get()); 81 QCOMPARE(se->nativeDevice(), m_nativeDevice.get()); 82 QCOMPARE(se->type(), LIBINPUT_EVENT_SWITCH_TOGGLE); 83 QCOMPARE(se->state(), state); 84 QCOMPARE(se->time(), 23u); 85 QCOMPARE(se->timeMicroseconds(), 23456789u); 86 } 87 88 QTEST_GUILESS_MAIN(TestLibinputSwitchEvent) 89 #include "switch_event_test.moc" 90