test: Add flags argument to test_get_context()
[platform/upstream/libxkbcommon.git] / test / keyseq.c
1 /*
2  * Copyright © 2012 Ran Benita <ran234@gmail.com>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23
24 #include <linux/input.h>
25
26 #include "test.h"
27
28 int
29 main(void)
30 {
31     struct xkb_context *ctx = test_get_context(0);
32     struct xkb_keymap *keymap;
33
34     assert(ctx);
35     keymap = test_compile_rules(ctx, "evdev", "evdev",
36                                 "us,il,ru,de", ",,phonetic,neo",
37                                 "grp:alt_shift_toggle,grp:menu_toggle");
38     assert(keymap);
39
40     assert(test_key_seq(keymap,
41                         KEY_H,  BOTH,  XKB_KEY_h,  NEXT,
42                         KEY_E,  BOTH,  XKB_KEY_e,  NEXT,
43                         KEY_L,  BOTH,  XKB_KEY_l,  NEXT,
44                         KEY_L,  BOTH,  XKB_KEY_l,  NEXT,
45                         KEY_O,  BOTH,  XKB_KEY_o,  FINISH));
46
47     /* Simple shifted level. */
48     assert(test_key_seq(keymap,
49                         KEY_H,          BOTH,  XKB_KEY_h,        NEXT,
50                         KEY_LEFTSHIFT,  DOWN,  XKB_KEY_Shift_L,  NEXT,
51                         KEY_E,          BOTH,  XKB_KEY_E,        NEXT,
52                         KEY_L,          BOTH,  XKB_KEY_L,        NEXT,
53                         KEY_LEFTSHIFT,  UP,    XKB_KEY_Shift_L,  NEXT,
54                         KEY_L,          BOTH,  XKB_KEY_l,        NEXT,
55                         KEY_O,          BOTH,  XKB_KEY_o,        FINISH));
56
57     /* Key repeat shifted and unshifted in the middle. */
58     assert(test_key_seq(keymap,
59                         KEY_H,           DOWN,    XKB_KEY_h,        NEXT,
60                         KEY_H,           REPEAT,  XKB_KEY_h,        NEXT,
61                         KEY_H,           REPEAT,  XKB_KEY_h,        NEXT,
62                         KEY_LEFTSHIFT,   DOWN,    XKB_KEY_Shift_L,  NEXT,
63                         KEY_H,           REPEAT,  XKB_KEY_H,        NEXT,
64                         KEY_H,           REPEAT,  XKB_KEY_H,        NEXT,
65                         KEY_LEFTSHIFT,   UP,      XKB_KEY_Shift_L,  NEXT,
66                         KEY_H,           REPEAT,  XKB_KEY_h,        NEXT,
67                         KEY_H,           REPEAT,  XKB_KEY_h,        NEXT,
68                         KEY_H,           UP,      XKB_KEY_h,        NEXT,
69                         KEY_H,           BOTH,    XKB_KEY_h,        FINISH));
70
71     /* Base modifier cleared on key release... */
72     assert(test_key_seq(keymap,
73                         KEY_H,          BOTH,  XKB_KEY_h,        NEXT,
74                         KEY_LEFTSHIFT,  DOWN,  XKB_KEY_Shift_L,  NEXT,
75                         KEY_E,          BOTH,  XKB_KEY_E,        NEXT,
76                         KEY_L,          BOTH,  XKB_KEY_L,        NEXT,
77                         KEY_LEFTSHIFT,  DOWN,  XKB_KEY_Shift_L,  NEXT,
78                         KEY_L,          BOTH,  XKB_KEY_L,        NEXT,
79                         KEY_O,          BOTH,  XKB_KEY_O,        FINISH));
80
81     /* ... But only by the keycode that set it. */
82     assert(test_key_seq(keymap,
83                         KEY_H,           BOTH,  XKB_KEY_h,        NEXT,
84                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,  NEXT,
85                         KEY_E,           BOTH,  XKB_KEY_E,        NEXT,
86                         KEY_L,           BOTH,  XKB_KEY_L,        NEXT,
87                         KEY_RIGHTSHIFT,  UP,    XKB_KEY_Shift_R,  NEXT,
88                         KEY_L,           BOTH,  XKB_KEY_L,        NEXT,
89                         KEY_O,           BOTH,  XKB_KEY_O,        FINISH));
90
91     /*
92      * A base modifier should only be cleared when no other key affecting
93      * the modifier is down.
94      */
95     assert(test_key_seq(keymap,
96                         KEY_H,           BOTH,  XKB_KEY_h,        NEXT,
97                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,  NEXT,
98                         KEY_E,           BOTH,  XKB_KEY_E,        NEXT,
99                         KEY_RIGHTSHIFT,  DOWN,  XKB_KEY_Shift_R,  NEXT,
100                         KEY_L,           BOTH,  XKB_KEY_L,        NEXT,
101                         KEY_RIGHTSHIFT,  UP,    XKB_KEY_Shift_R,  NEXT,
102                         KEY_L,           BOTH,  XKB_KEY_L,        NEXT,
103                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Shift_L,  NEXT,
104                         KEY_O,           BOTH,  XKB_KEY_o,        FINISH));
105
106     /*
107      * Two key presses from the same key (e.g. if two keyboards use the
108      * same xkb_state) should only be released after two releases.
109      */
110     assert(test_key_seq(keymap,
111                         KEY_H,           BOTH,  XKB_KEY_h,        NEXT,
112                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,  NEXT,
113                         KEY_H,           BOTH,  XKB_KEY_H,        NEXT,
114                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,  NEXT,
115                         KEY_H,           BOTH,  XKB_KEY_H,        NEXT,
116                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Shift_L,  NEXT,
117                         KEY_H,           BOTH,  XKB_KEY_H,        NEXT,
118                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Shift_L,  NEXT,
119                         KEY_H,           BOTH,  XKB_KEY_h,        FINISH));
120
121     /* Same as above with locked modifiers. */
122     assert(test_key_seq(keymap,
123                         KEY_H,           BOTH,  XKB_KEY_h,          NEXT,
124                         KEY_CAPSLOCK,    DOWN,  XKB_KEY_Caps_Lock,  NEXT,
125                         KEY_H,           BOTH,  XKB_KEY_H,          NEXT,
126                         KEY_CAPSLOCK,    DOWN,  XKB_KEY_Caps_Lock,  NEXT,
127                         KEY_H,           BOTH,  XKB_KEY_H,          NEXT,
128                         KEY_CAPSLOCK,    UP,    XKB_KEY_Caps_Lock,  NEXT,
129                         KEY_H,           BOTH,  XKB_KEY_H,          NEXT,
130                         KEY_CAPSLOCK,    UP,    XKB_KEY_Caps_Lock,  NEXT,
131                         KEY_H,           BOTH,  XKB_KEY_H,          NEXT,
132                         KEY_CAPSLOCK,    BOTH,  XKB_KEY_Caps_Lock,  NEXT,
133                         KEY_H,           BOTH,  XKB_KEY_h,          FINISH));
134
135     /* Group switching / locking. */
136     assert(test_key_seq(keymap,
137                         KEY_H,        BOTH,  XKB_KEY_h,               NEXT,
138                         KEY_E,        BOTH,  XKB_KEY_e,               NEXT,
139                         KEY_COMPOSE,  BOTH,  XKB_KEY_ISO_Next_Group,  NEXT,
140                         KEY_K,        BOTH,  XKB_KEY_hebrew_lamed,    NEXT,
141                         KEY_F,        BOTH,  XKB_KEY_hebrew_kaph,     NEXT,
142                         KEY_COMPOSE,  BOTH,  XKB_KEY_ISO_Next_Group,  NEXT,
143                         KEY_COMPOSE,  BOTH,  XKB_KEY_ISO_Next_Group,  NEXT,
144                         KEY_COMPOSE,  BOTH,  XKB_KEY_ISO_Next_Group,  NEXT,
145                         KEY_O,        BOTH,  XKB_KEY_o,               FINISH));
146
147     assert(test_key_seq(keymap,
148                         KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L,        NEXT,
149                         KEY_LEFTALT,   DOWN, XKB_KEY_ISO_Next_Group, NEXT,
150                         KEY_LEFTALT,   UP,   XKB_KEY_ISO_Next_Group, NEXT,
151                         KEY_LEFTSHIFT, UP,   XKB_KEY_Shift_L,        FINISH));
152
153     assert(test_key_seq(keymap,
154                         KEY_LEFTALT,   DOWN, XKB_KEY_Alt_L,          NEXT,
155                         KEY_LEFTSHIFT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
156                         KEY_LEFTSHIFT, UP,   XKB_KEY_ISO_Next_Group, NEXT,
157                         KEY_LEFTALT,   UP,   XKB_KEY_Alt_L,          FINISH));
158
159     /* Locked modifiers. */
160     assert(test_key_seq(keymap,
161                         KEY_CAPSLOCK,  BOTH,  XKB_KEY_Caps_Lock,  NEXT,
162                         KEY_H,         BOTH,  XKB_KEY_H,          NEXT,
163                         KEY_E,         BOTH,  XKB_KEY_E,          NEXT,
164                         KEY_L,         BOTH,  XKB_KEY_L,          NEXT,
165                         KEY_L,         BOTH,  XKB_KEY_L,          NEXT,
166                         KEY_O,         BOTH,  XKB_KEY_O,          FINISH));
167
168     assert(test_key_seq(keymap,
169                         KEY_H,         BOTH,  XKB_KEY_h,          NEXT,
170                         KEY_E,         BOTH,  XKB_KEY_e,          NEXT,
171                         KEY_CAPSLOCK,  BOTH,  XKB_KEY_Caps_Lock,  NEXT,
172                         KEY_L,         BOTH,  XKB_KEY_L,          NEXT,
173                         KEY_L,         BOTH,  XKB_KEY_L,          NEXT,
174                         KEY_CAPSLOCK,  BOTH,  XKB_KEY_Caps_Lock,  NEXT,
175                         KEY_O,         BOTH,  XKB_KEY_o,          FINISH));
176
177     assert(test_key_seq(keymap,
178                         KEY_H,         BOTH,  XKB_KEY_h,          NEXT,
179                         KEY_CAPSLOCK,  DOWN,  XKB_KEY_Caps_Lock,  NEXT,
180                         KEY_E,         BOTH,  XKB_KEY_E,          NEXT,
181                         KEY_L,         BOTH,  XKB_KEY_L,          NEXT,
182                         KEY_L,         BOTH,  XKB_KEY_L,          NEXT,
183                         KEY_CAPSLOCK,  UP,    XKB_KEY_Caps_Lock,  NEXT,
184                         KEY_O,         BOTH,  XKB_KEY_O,          FINISH));
185
186     assert(test_key_seq(keymap,
187                         KEY_H,         BOTH,  XKB_KEY_h,          NEXT,
188                         KEY_E,         BOTH,  XKB_KEY_e,          NEXT,
189                         KEY_CAPSLOCK,  UP,    XKB_KEY_Caps_Lock,  NEXT,
190                         KEY_L,         BOTH,  XKB_KEY_l,          NEXT,
191                         KEY_L,         BOTH,  XKB_KEY_l,          NEXT,
192                         KEY_O,         BOTH,  XKB_KEY_o,          FINISH));
193
194     /*
195      * A key release affecting a locked modifier should clear it
196      * regardless of the key press.
197      */
198     /* assert(test_key_seq(keymap, */
199     /*                     KEY_H,         BOTH,  XKB_KEY_h,          NEXT, */
200     /*                     KEY_CAPSLOCK,  DOWN,  XKB_KEY_Caps_Lock,  NEXT, */
201     /*                     KEY_E,         BOTH,  XKB_KEY_E,          NEXT, */
202     /*                     KEY_L,         BOTH,  XKB_KEY_L,          NEXT, */
203     /*                     KEY_CAPSLOCK,  UP,    XKB_KEY_Caps_Lock,  NEXT, */
204     /*                     KEY_L,         BOTH,  XKB_KEY_L,          NEXT, */
205     /*                     KEY_CAPSLOCK,  UP,    XKB_KEY_Caps_Lock,  NEXT, */
206     /*                     KEY_O,         BOTH,  XKB_KEY_o,          FINISH)); */
207
208     /* Simple Num Lock sanity check. */
209     assert(test_key_seq(keymap,
210                         KEY_KP1,      BOTH,  XKB_KEY_KP_End,    NEXT,
211                         KEY_NUMLOCK,  BOTH,  XKB_KEY_Num_Lock,  NEXT,
212                         KEY_KP1,      BOTH,  XKB_KEY_KP_1,      NEXT,
213                         KEY_KP2,      BOTH,  XKB_KEY_KP_2,      NEXT,
214                         KEY_NUMLOCK,  BOTH,  XKB_KEY_Num_Lock,  NEXT,
215                         KEY_KP2,      BOTH,  XKB_KEY_KP_Down,   FINISH));
216
217     /* Test that the aliases in the ru(phonetic) symbols map work. */
218     assert(test_key_seq(keymap,
219                         KEY_COMPOSE,     BOTH,  XKB_KEY_ISO_Next_Group,  NEXT,
220                         KEY_COMPOSE,     BOTH,  XKB_KEY_ISO_Next_Group,  NEXT,
221                         KEY_1,           BOTH,  XKB_KEY_1,               NEXT,
222                         KEY_Q,           BOTH,  XKB_KEY_Cyrillic_ya,     NEXT,
223                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,         NEXT,
224                         KEY_1,           BOTH,  XKB_KEY_exclam,          NEXT,
225                         KEY_Q,           BOTH,  XKB_KEY_Cyrillic_YA,     NEXT,
226                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Shift_L,         NEXT,
227                         KEY_V,           BOTH,  XKB_KEY_Cyrillic_zhe,    NEXT,
228                         KEY_CAPSLOCK,    BOTH,  XKB_KEY_Caps_Lock,       NEXT,
229                         KEY_1,           BOTH,  XKB_KEY_1,               NEXT,
230                         KEY_V,           BOTH,  XKB_KEY_Cyrillic_ZHE,    NEXT,
231                         KEY_RIGHTSHIFT,  DOWN,  XKB_KEY_Shift_R,         NEXT,
232                         KEY_V,           BOTH,  XKB_KEY_Cyrillic_zhe,    NEXT,
233                         KEY_RIGHTSHIFT,  UP,    XKB_KEY_Shift_R,         NEXT,
234                         KEY_V,           BOTH,  XKB_KEY_Cyrillic_ZHE,    FINISH));
235
236 #define KS(name) xkb_keysym_from_name(name, 0)
237
238     /* Test that levels (1-5) in de(neo) symbols map work. */
239     assert(test_key_seq(keymap,
240                         /* Switch to the group. */
241                         KEY_COMPOSE,     BOTH,  XKB_KEY_ISO_Next_Group,    NEXT,
242                         KEY_COMPOSE,     BOTH,  XKB_KEY_ISO_Next_Group,    NEXT,
243                         KEY_COMPOSE,     BOTH,  XKB_KEY_ISO_Next_Group,    NEXT,
244
245                         /* Level 1. */
246                         KEY_1,           BOTH,  XKB_KEY_1,                 NEXT,
247                         KEY_Q,           BOTH,  XKB_KEY_x,                 NEXT,
248                         KEY_KP7,         BOTH,  XKB_KEY_KP_7,              NEXT,
249                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
250
251                         /* Level 2 with Shift. */
252                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,           NEXT,
253                         KEY_1,           BOTH,  XKB_KEY_degree,            NEXT,
254                         KEY_Q,           BOTH,  XKB_KEY_X,                 NEXT,
255                         KEY_KP7,         BOTH,  KS("U2714"),               NEXT,
256                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
257                         /*
258                          * XXX: de(neo) uses shift(both_capslock) which causes
259                          * the interesting result in the next line. Since it's
260                          * a key release, it doesn't actually lock the modifier,
261                          * and applications by-and-large ignore the keysym on
262                          * release(?). Is this a problem?
263                          */
264                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Caps_Lock,         NEXT,
265
266                         /* Level 2 with the Lock modifier. */
267                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,           NEXT,
268                         KEY_RIGHTSHIFT,  BOTH,  XKB_KEY_Caps_Lock,         NEXT,
269                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Caps_Lock,         NEXT,
270                         KEY_6,           BOTH,  XKB_KEY_6,                 NEXT,
271                         KEY_H,           BOTH,  XKB_KEY_S,                 NEXT,
272                         KEY_KP3,         BOTH,  XKB_KEY_KP_3,              NEXT,
273                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
274                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,           NEXT,
275                         KEY_RIGHTSHIFT,  BOTH,  XKB_KEY_Caps_Lock,         NEXT,
276                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Caps_Lock,         NEXT,
277
278                         /* Level 3. */
279                         KEY_CAPSLOCK,    DOWN,  XKB_KEY_ISO_Level3_Shift,  NEXT,
280                         KEY_6,           BOTH,  XKB_KEY_cent,              NEXT,
281                         KEY_Q,           BOTH,  XKB_KEY_ellipsis,          NEXT,
282                         KEY_KP7,         BOTH,  KS("U2195"),               NEXT,
283                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
284                         KEY_CAPSLOCK,    UP,    XKB_KEY_ISO_Level3_Shift,  NEXT,
285
286                         /* Level 4. */
287                         KEY_CAPSLOCK,    DOWN,  XKB_KEY_ISO_Level3_Shift,  NEXT,
288                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,           NEXT,
289                         KEY_5,           BOTH,  XKB_KEY_malesymbol,        NEXT,
290                         KEY_E,           BOTH,  XKB_KEY_Greek_lambda,      NEXT,
291                         KEY_SPACE,       BOTH,  XKB_KEY_nobreakspace,      NEXT,
292                         KEY_KP8,         BOTH,  XKB_KEY_intersection,      NEXT,
293                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
294                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Caps_Lock,         NEXT,
295                         KEY_CAPSLOCK,    UP,    XKB_KEY_ISO_Level3_Shift,  NEXT,
296
297                         /* Level 5. */
298                         KEY_RIGHTALT,    DOWN,  XKB_KEY_ISO_Level5_Shift,  NEXT,
299                         KEY_5,           BOTH,  XKB_KEY_periodcentered,    NEXT,
300                         KEY_E,           BOTH,  XKB_KEY_Up,                NEXT,
301                         KEY_SPACE,       BOTH,  XKB_KEY_KP_0,              NEXT,
302                         KEY_KP8,         BOTH,  XKB_KEY_KP_Up,             NEXT,
303                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
304                         KEY_RIGHTALT,    UP,    XKB_KEY_ISO_Level5_Shift,  NEXT,
305
306                         KEY_V,           BOTH,  XKB_KEY_p,               FINISH));
307
308     xkb_keymap_unref(keymap);
309     assert(ctx);
310     keymap = test_compile_rules(ctx, "evdev", "", "us,il,ru", "",
311                                 "grp:alt_shift_toggle_bidir,grp:menu_toggle");
312     assert(keymap);
313
314     assert(test_key_seq(keymap,
315                         KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L,        NEXT,
316                         KEY_LEFTALT,   DOWN, XKB_KEY_ISO_Prev_Group, NEXT,
317                         KEY_LEFTALT,   UP,   XKB_KEY_ISO_Prev_Group, NEXT,
318                         KEY_LEFTSHIFT, UP,   XKB_KEY_Shift_L,        FINISH));
319
320     assert(test_key_seq(keymap,
321                         KEY_LEFTALT,   DOWN, XKB_KEY_Alt_L,          NEXT,
322                         KEY_LEFTSHIFT, DOWN, XKB_KEY_ISO_Prev_Group, NEXT,
323                         KEY_LEFTSHIFT, UP,   XKB_KEY_ISO_Prev_Group, NEXT,
324                         KEY_LEFTALT,   UP,   XKB_KEY_Alt_L,          FINISH));
325
326     /* Check backwards (negative) group switching and wrapping. */
327     assert(test_key_seq(keymap,
328                         KEY_H,         BOTH, XKB_KEY_h,              NEXT,
329                         KEY_COMPOSE,   BOTH, XKB_KEY_ISO_Next_Group, NEXT,
330                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,     NEXT,
331                         KEY_COMPOSE,   BOTH, XKB_KEY_ISO_Next_Group, NEXT,
332                         KEY_H,         BOTH, XKB_KEY_Cyrillic_er,    NEXT,
333                         KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L,        NEXT,
334                         KEY_LEFTALT,   BOTH, XKB_KEY_ISO_Prev_Group, NEXT,
335                         KEY_LEFTSHIFT, UP,   XKB_KEY_Shift_L,        NEXT,
336                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,     NEXT,
337                         KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L,        NEXT,
338                         KEY_LEFTALT,   BOTH, XKB_KEY_ISO_Prev_Group, NEXT,
339                         KEY_LEFTSHIFT, UP,   XKB_KEY_Shift_L,        NEXT,
340                         KEY_H,         BOTH, XKB_KEY_h,              NEXT,
341                         KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L,        NEXT,
342                         KEY_LEFTALT,   BOTH, XKB_KEY_ISO_Prev_Group, NEXT,
343                         KEY_LEFTSHIFT, UP,   XKB_KEY_Shift_L,        NEXT,
344                         KEY_H,         BOTH, XKB_KEY_Cyrillic_er,    NEXT,
345                         KEY_COMPOSE,   BOTH, XKB_KEY_ISO_Next_Group, NEXT,
346                         KEY_H,         BOTH, XKB_KEY_h,              FINISH));
347
348     xkb_keymap_unref(keymap);
349     keymap = test_compile_rules(ctx, "evdev", "", "us,il,ru", "",
350                                 "grp:switch,grp:lswitch,grp:menu_toggle");
351     assert(keymap);
352
353     /* Test depressed group works (Mode_switch). */
354     assert(test_key_seq(keymap,
355                         KEY_H,         BOTH, XKB_KEY_h,                 NEXT,
356                         KEY_RIGHTALT,  DOWN, XKB_KEY_Mode_switch,       NEXT,
357                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,        NEXT,
358                         KEY_RIGHTALT,  UP,   XKB_KEY_ISO_Level3_Shift,  NEXT,
359                         KEY_H,         BOTH, XKB_KEY_h,                 NEXT,
360                         KEY_RIGHTALT,  DOWN, XKB_KEY_Mode_switch,       NEXT,
361                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,        NEXT,
362                         KEY_RIGHTALT,  UP,   XKB_KEY_ISO_Level3_Shift,  NEXT,
363                         KEY_H,         BOTH, XKB_KEY_h,                 FINISH));
364
365     /* Test locked+depressed group works, with wrapping and accumulation. */
366     assert(test_key_seq(keymap,
367                         KEY_H,         BOTH, XKB_KEY_h,                 NEXT,
368                         KEY_COMPOSE,   BOTH, XKB_KEY_ISO_Next_Group,    NEXT,
369                         KEY_LEFTALT,   DOWN, XKB_KEY_Mode_switch,       NEXT,
370                         KEY_H,         BOTH, XKB_KEY_Cyrillic_er,       NEXT,
371                         KEY_LEFTALT,   UP,   XKB_KEY_Mode_switch,       NEXT,
372                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,        NEXT,
373                         KEY_COMPOSE,   BOTH, XKB_KEY_ISO_Next_Group,    NEXT,
374                         KEY_LEFTALT,   DOWN, XKB_KEY_Mode_switch,       NEXT,
375                         /* Should wrap back to first group. */
376                         KEY_H,         BOTH, XKB_KEY_h,                 NEXT,
377                         KEY_LEFTALT,   UP,   XKB_KEY_Mode_switch,       NEXT,
378                         KEY_H,         BOTH, XKB_KEY_Cyrillic_er,       NEXT,
379                         KEY_COMPOSE,   BOTH, XKB_KEY_ISO_Next_Group,    NEXT,
380                         KEY_H,         BOTH, XKB_KEY_h,                 NEXT,
381                         /* Two SetGroup(+1)'s should add up. */
382                         KEY_RIGHTALT,  DOWN, XKB_KEY_Mode_switch,       NEXT,
383                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,        NEXT,
384                         KEY_LEFTALT,   DOWN, XKB_KEY_Mode_switch,       NEXT,
385                         KEY_H,         BOTH, XKB_KEY_Cyrillic_er,       NEXT,
386                         KEY_LEFTALT,   UP,   XKB_KEY_Mode_switch,       NEXT,
387                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,        NEXT,
388                         KEY_RIGHTALT,  UP,   XKB_KEY_ISO_Level3_Shift,  NEXT,
389                         KEY_H,         BOTH, XKB_KEY_h,                 FINISH));
390
391     xkb_keymap_unref(keymap);
392     keymap = test_compile_file(ctx, "keymaps/unbound-vmod.xkb");
393     assert(keymap);
394
395     assert(test_key_seq(keymap,
396                         KEY_H,         BOTH, XKB_KEY_h,                 NEXT,
397                         KEY_Z,         BOTH, XKB_KEY_y,                 NEXT,
398                         KEY_MINUS,     BOTH, XKB_KEY_ssharp,            NEXT,
399                         KEY_Z,         BOTH, XKB_KEY_y,                 FINISH));
400
401     xkb_keymap_unref(keymap);
402     xkb_context_unref(ctx);
403     return 0;
404 }