1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Robert Carr <robert.carr@canonical.com>
*/
#include "mir/input/xkb_mapper.h"
#include <xkbcommon/xkbcommon-keysyms.h>
#include <xkbcommon/xkbcommon.h>
#include <linux/input.h>
#include <gtest/gtest.h>
namespace mircv = mir::input::receiver;
namespace
{
static int map_key(mircv::XKBMapper &mapper, MirKeyAction action, int scan_code)
{
MirKeyEvent ev;
ev.action = action;
ev.scan_code = scan_code;
ev.repeat_count = 0;
mapper.update_state_and_map_event(ev);
return ev.key_code;
}
static int map_repeated_key(mircv::XKBMapper &mapper, MirKeyAction action, int scan_code)
{
MirKeyEvent ev;
ev.action = action;
ev.scan_code = scan_code;
ev.repeat_count = 1;
mapper.update_state_and_map_event(ev);
return ev.key_code;
}
}
TEST(XKBMapper, maps_generic_us_english_keys)
{
mircv::XKBMapper mapper;
EXPECT_EQ(XKB_KEY_4, map_key(mapper, mir_key_action_down, KEY_4));
EXPECT_EQ(XKB_KEY_Shift_L, map_key(mapper, mir_key_action_down, KEY_LEFTSHIFT));
EXPECT_EQ(XKB_KEY_dollar, map_key(mapper, mir_key_action_down, KEY_4));
EXPECT_EQ(XKB_KEY_dollar, map_key(mapper, mir_key_action_up, KEY_4));
EXPECT_EQ(XKB_KEY_Shift_L, map_key(mapper, mir_key_action_up, KEY_LEFTSHIFT));
EXPECT_EQ(XKB_KEY_4, map_key(mapper, mir_key_action_down, KEY_4));
}
TEST(XKBMapper, key_action_multiple_does_not_update_modifier_state)
{
mircv::XKBMapper mapper;
EXPECT_EQ(XKB_KEY_Shift_R, map_key(mapper, mir_key_action_multiple, KEY_RIGHTSHIFT));
EXPECT_EQ(XKB_KEY_7, map_key(mapper, mir_key_action_down, KEY_7));
}
TEST(XKBMapper, key_repeats_do_not_recurse_modifier_state)
{
mircv::XKBMapper mapper;
EXPECT_EQ(XKB_KEY_Shift_R, map_key(mapper, mir_key_action_down, KEY_RIGHTSHIFT));
EXPECT_EQ(XKB_KEY_Shift_R, map_repeated_key(mapper, mir_key_action_down, KEY_RIGHTSHIFT));
EXPECT_EQ(XKB_KEY_ampersand, map_key(mapper, mir_key_action_down, KEY_7));
EXPECT_EQ(XKB_KEY_Shift_R, map_key(mapper, mir_key_action_up, KEY_RIGHTSHIFT));
EXPECT_EQ(XKB_KEY_7, map_key(mapper, mir_key_action_down, KEY_7));
}
|