KWin
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
switch_event_test.cpp
Go to the documentation of this file.
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
13
14#include <QTest>
15
16#include <memory>
17
19
20using namespace KWin::LibInput;
21using namespace std::literals;
22
23class TestLibinputSwitchEvent : public QObject
24{
25 Q_OBJECT
26private Q_SLOTS:
27 void init();
28 void cleanup();
29
30 void testToggled_data();
31 void testToggled();
32
33private:
34 std::unique_ptr<libinput_device> m_nativeDevice;
35 std::unique_ptr<Device> m_device;
36};
37
38void TestLibinputSwitchEvent::init()
39{
40 m_nativeDevice = std::make_unique<libinput_device>();
41 m_nativeDevice->switchDevice = true;
42 m_device = std::make_unique<Device>(m_nativeDevice.get());
43}
44
45void TestLibinputSwitchEvent::cleanup()
46{
47 m_device.reset();
48 m_nativeDevice.reset();
49}
50
51void TestLibinputSwitchEvent::testToggled_data()
52{
53 QTest::addColumn<KWin::LibInput::SwitchEvent::State>("state");
54
55 QTest::newRow("on") << KWin::LibInput::SwitchEvent::State::On;
56 QTest::newRow("off") << KWin::LibInput::SwitchEvent::State::Off;
57}
58
59void TestLibinputSwitchEvent::testToggled()
60{
62 nativeEvent->type = LIBINPUT_EVENT_SWITCH_TOGGLE;
63 nativeEvent->device = m_nativeDevice.get();
65 switch (state) {
66 case SwitchEvent::State::Off:
68 break;
69 case SwitchEvent::State::On:
71 break;
72 default:
73 Q_UNREACHABLE();
74 }
75 nativeEvent->time = 23456789us;
76
77 std::unique_ptr<Event> event(Event::create(nativeEvent));
78 auto se = dynamic_cast<SwitchEvent *>(event.get());
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(), 23456789us);
85}
86
87QTEST_GUILESS_MAIN(TestLibinputSwitchEvent)
88#include "switch_event_test.moc"
static std::unique_ptr< Event > create(libinput_event *event)
Definition events.cpp:19
Q_DECLARE_METATYPE(KWin::SwitchEvent::State)
libinput_device * device
std::chrono::microseconds time
libinput_event_type type