test/keyseq: add test
[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 "evdev-scancodes.h"
25 #include "test.h"
26
27 int
28 main(void)
29 {
30     struct xkb_context *ctx = test_get_context(0);
31     struct xkb_keymap *keymap;
32
33     assert(ctx);
34     keymap = test_compile_rules(ctx, "evdev", "evdev",
35                                 "us,il,ru,de", ",,phonetic,neo",
36                                 "grp:alt_shift_toggle,grp:menu_toggle");
37     assert(keymap);
38
39     assert(test_key_seq(keymap,
40                         KEY_H,  BOTH,  XKB_KEY_h,  NEXT,
41                         KEY_E,  BOTH,  XKB_KEY_e,  NEXT,
42                         KEY_L,  BOTH,  XKB_KEY_l,  NEXT,
43                         KEY_L,  BOTH,  XKB_KEY_l,  NEXT,
44                         KEY_O,  BOTH,  XKB_KEY_o,  FINISH));
45
46     /* Simple shifted level. */
47     assert(test_key_seq(keymap,
48                         KEY_H,          BOTH,  XKB_KEY_h,        NEXT,
49                         KEY_LEFTSHIFT,  DOWN,  XKB_KEY_Shift_L,  NEXT,
50                         KEY_E,          BOTH,  XKB_KEY_E,        NEXT,
51                         KEY_L,          BOTH,  XKB_KEY_L,        NEXT,
52                         KEY_LEFTSHIFT,  UP,    XKB_KEY_Shift_L,  NEXT,
53                         KEY_L,          BOTH,  XKB_KEY_l,        NEXT,
54                         KEY_O,          BOTH,  XKB_KEY_o,        FINISH));
55
56     /* Key repeat shifted and unshifted in the middle. */
57     assert(test_key_seq(keymap,
58                         KEY_H,           DOWN,    XKB_KEY_h,        NEXT,
59                         KEY_H,           REPEAT,  XKB_KEY_h,        NEXT,
60                         KEY_H,           REPEAT,  XKB_KEY_h,        NEXT,
61                         KEY_LEFTSHIFT,   DOWN,    XKB_KEY_Shift_L,  NEXT,
62                         KEY_H,           REPEAT,  XKB_KEY_H,        NEXT,
63                         KEY_H,           REPEAT,  XKB_KEY_H,        NEXT,
64                         KEY_LEFTSHIFT,   UP,      XKB_KEY_Shift_L,  NEXT,
65                         KEY_H,           REPEAT,  XKB_KEY_h,        NEXT,
66                         KEY_H,           REPEAT,  XKB_KEY_h,        NEXT,
67                         KEY_H,           UP,      XKB_KEY_h,        NEXT,
68                         KEY_H,           BOTH,    XKB_KEY_h,        FINISH));
69
70     /* Base modifier cleared on key release... */
71     assert(test_key_seq(keymap,
72                         KEY_H,          BOTH,  XKB_KEY_h,        NEXT,
73                         KEY_LEFTSHIFT,  DOWN,  XKB_KEY_Shift_L,  NEXT,
74                         KEY_E,          BOTH,  XKB_KEY_E,        NEXT,
75                         KEY_L,          BOTH,  XKB_KEY_L,        NEXT,
76                         KEY_LEFTSHIFT,  DOWN,  XKB_KEY_Shift_L,  NEXT,
77                         KEY_L,          BOTH,  XKB_KEY_L,        NEXT,
78                         KEY_O,          BOTH,  XKB_KEY_O,        FINISH));
79
80     /* ... But only by the keycode that set it. */
81     assert(test_key_seq(keymap,
82                         KEY_H,           BOTH,  XKB_KEY_h,        NEXT,
83                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,  NEXT,
84                         KEY_E,           BOTH,  XKB_KEY_E,        NEXT,
85                         KEY_L,           BOTH,  XKB_KEY_L,        NEXT,
86                         KEY_RIGHTSHIFT,  UP,    XKB_KEY_Shift_R,  NEXT,
87                         KEY_L,           BOTH,  XKB_KEY_L,        NEXT,
88                         KEY_O,           BOTH,  XKB_KEY_O,        FINISH));
89
90     /*
91      * A base modifier should only be cleared when no other key affecting
92      * the modifier is down.
93      */
94     assert(test_key_seq(keymap,
95                         KEY_H,           BOTH,  XKB_KEY_h,        NEXT,
96                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,  NEXT,
97                         KEY_E,           BOTH,  XKB_KEY_E,        NEXT,
98                         KEY_RIGHTSHIFT,  DOWN,  XKB_KEY_Shift_R,  NEXT,
99                         KEY_L,           BOTH,  XKB_KEY_L,        NEXT,
100                         KEY_RIGHTSHIFT,  UP,    XKB_KEY_Shift_R,  NEXT,
101                         KEY_L,           BOTH,  XKB_KEY_L,        NEXT,
102                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Shift_L,  NEXT,
103                         KEY_O,           BOTH,  XKB_KEY_o,        FINISH));
104
105     /*
106      * Two key presses from the same key (e.g. if two keyboards use the
107      * same xkb_state) should only be released after two releases.
108      */
109     assert(test_key_seq(keymap,
110                         KEY_H,           BOTH,  XKB_KEY_h,        NEXT,
111                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,  NEXT,
112                         KEY_H,           BOTH,  XKB_KEY_H,        NEXT,
113                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,  NEXT,
114                         KEY_H,           BOTH,  XKB_KEY_H,        NEXT,
115                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Shift_L,  NEXT,
116                         KEY_H,           BOTH,  XKB_KEY_H,        NEXT,
117                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Shift_L,  NEXT,
118                         KEY_H,           BOTH,  XKB_KEY_h,        FINISH));
119
120     /* Same as above with locked modifiers. */
121     assert(test_key_seq(keymap,
122                         KEY_H,           BOTH,  XKB_KEY_h,          NEXT,
123                         KEY_CAPSLOCK,    DOWN,  XKB_KEY_Caps_Lock,  NEXT,
124                         KEY_H,           BOTH,  XKB_KEY_H,          NEXT,
125                         KEY_CAPSLOCK,    DOWN,  XKB_KEY_Caps_Lock,  NEXT,
126                         KEY_H,           BOTH,  XKB_KEY_H,          NEXT,
127                         KEY_CAPSLOCK,    UP,    XKB_KEY_Caps_Lock,  NEXT,
128                         KEY_H,           BOTH,  XKB_KEY_H,          NEXT,
129                         KEY_CAPSLOCK,    UP,    XKB_KEY_Caps_Lock,  NEXT,
130                         KEY_H,           BOTH,  XKB_KEY_H,          NEXT,
131                         KEY_CAPSLOCK,    BOTH,  XKB_KEY_Caps_Lock,  NEXT,
132                         KEY_H,           BOTH,  XKB_KEY_h,          FINISH));
133
134     /* Group switching / locking. */
135     assert(test_key_seq(keymap,
136                         KEY_H,        BOTH,  XKB_KEY_h,               NEXT,
137                         KEY_E,        BOTH,  XKB_KEY_e,               NEXT,
138                         KEY_COMPOSE,  BOTH,  XKB_KEY_ISO_Next_Group,  NEXT,
139                         KEY_K,        BOTH,  XKB_KEY_hebrew_lamed,    NEXT,
140                         KEY_F,        BOTH,  XKB_KEY_hebrew_kaph,     NEXT,
141                         KEY_COMPOSE,  BOTH,  XKB_KEY_ISO_Next_Group,  NEXT,
142                         KEY_COMPOSE,  BOTH,  XKB_KEY_ISO_Next_Group,  NEXT,
143                         KEY_COMPOSE,  BOTH,  XKB_KEY_ISO_Next_Group,  NEXT,
144                         KEY_O,        BOTH,  XKB_KEY_o,               FINISH));
145
146     assert(test_key_seq(keymap,
147                         KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L,        NEXT,
148                         KEY_LEFTALT,   DOWN, XKB_KEY_ISO_Next_Group, NEXT,
149                         KEY_LEFTALT,   UP,   XKB_KEY_ISO_Next_Group, NEXT,
150                         KEY_LEFTSHIFT, UP,   XKB_KEY_Shift_L,        FINISH));
151
152     assert(test_key_seq(keymap,
153                         KEY_LEFTALT,   DOWN, XKB_KEY_Alt_L,          NEXT,
154                         KEY_LEFTSHIFT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
155                         KEY_LEFTSHIFT, UP,   XKB_KEY_ISO_Next_Group, NEXT,
156                         KEY_LEFTALT,   UP,   XKB_KEY_Alt_L,          FINISH));
157
158     /* Locked modifiers. */
159     assert(test_key_seq(keymap,
160                         KEY_CAPSLOCK,  BOTH,  XKB_KEY_Caps_Lock,  NEXT,
161                         KEY_H,         BOTH,  XKB_KEY_H,          NEXT,
162                         KEY_E,         BOTH,  XKB_KEY_E,          NEXT,
163                         KEY_L,         BOTH,  XKB_KEY_L,          NEXT,
164                         KEY_L,         BOTH,  XKB_KEY_L,          NEXT,
165                         KEY_O,         BOTH,  XKB_KEY_O,          FINISH));
166
167     assert(test_key_seq(keymap,
168                         KEY_H,         BOTH,  XKB_KEY_h,          NEXT,
169                         KEY_E,         BOTH,  XKB_KEY_e,          NEXT,
170                         KEY_CAPSLOCK,  BOTH,  XKB_KEY_Caps_Lock,  NEXT,
171                         KEY_L,         BOTH,  XKB_KEY_L,          NEXT,
172                         KEY_L,         BOTH,  XKB_KEY_L,          NEXT,
173                         KEY_CAPSLOCK,  BOTH,  XKB_KEY_Caps_Lock,  NEXT,
174                         KEY_O,         BOTH,  XKB_KEY_o,          FINISH));
175
176     assert(test_key_seq(keymap,
177                         KEY_H,         BOTH,  XKB_KEY_h,          NEXT,
178                         KEY_CAPSLOCK,  DOWN,  XKB_KEY_Caps_Lock,  NEXT,
179                         KEY_E,         BOTH,  XKB_KEY_E,          NEXT,
180                         KEY_L,         BOTH,  XKB_KEY_L,          NEXT,
181                         KEY_L,         BOTH,  XKB_KEY_L,          NEXT,
182                         KEY_CAPSLOCK,  UP,    XKB_KEY_Caps_Lock,  NEXT,
183                         KEY_O,         BOTH,  XKB_KEY_O,          FINISH));
184
185     assert(test_key_seq(keymap,
186                         KEY_H,         BOTH,  XKB_KEY_h,          NEXT,
187                         KEY_E,         BOTH,  XKB_KEY_e,          NEXT,
188                         KEY_CAPSLOCK,  UP,    XKB_KEY_Caps_Lock,  NEXT,
189                         KEY_L,         BOTH,  XKB_KEY_l,          NEXT,
190                         KEY_L,         BOTH,  XKB_KEY_l,          NEXT,
191                         KEY_O,         BOTH,  XKB_KEY_o,          FINISH));
192
193     /*
194      * A key release affecting a locked modifier should clear it
195      * regardless of the key press.
196      */
197     /* assert(test_key_seq(keymap, */
198     /*                     KEY_H,         BOTH,  XKB_KEY_h,          NEXT, */
199     /*                     KEY_CAPSLOCK,  DOWN,  XKB_KEY_Caps_Lock,  NEXT, */
200     /*                     KEY_E,         BOTH,  XKB_KEY_E,          NEXT, */
201     /*                     KEY_L,         BOTH,  XKB_KEY_L,          NEXT, */
202     /*                     KEY_CAPSLOCK,  UP,    XKB_KEY_Caps_Lock,  NEXT, */
203     /*                     KEY_L,         BOTH,  XKB_KEY_L,          NEXT, */
204     /*                     KEY_CAPSLOCK,  UP,    XKB_KEY_Caps_Lock,  NEXT, */
205     /*                     KEY_O,         BOTH,  XKB_KEY_o,          FINISH)); */
206
207     /* Simple Num Lock sanity check. */
208     assert(test_key_seq(keymap,
209                         KEY_KP1,      BOTH,  XKB_KEY_KP_End,    NEXT,
210                         KEY_NUMLOCK,  BOTH,  XKB_KEY_Num_Lock,  NEXT,
211                         KEY_KP1,      BOTH,  XKB_KEY_KP_1,      NEXT,
212                         KEY_KP2,      BOTH,  XKB_KEY_KP_2,      NEXT,
213                         KEY_NUMLOCK,  BOTH,  XKB_KEY_Num_Lock,  NEXT,
214                         KEY_KP2,      BOTH,  XKB_KEY_KP_Down,   FINISH));
215
216     /* Test that the aliases in the ru(phonetic) symbols map work. */
217     assert(test_key_seq(keymap,
218                         KEY_COMPOSE,     BOTH,  XKB_KEY_ISO_Next_Group,  NEXT,
219                         KEY_COMPOSE,     BOTH,  XKB_KEY_ISO_Next_Group,  NEXT,
220                         KEY_1,           BOTH,  XKB_KEY_1,               NEXT,
221                         KEY_Q,           BOTH,  XKB_KEY_Cyrillic_ya,     NEXT,
222                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,         NEXT,
223                         KEY_1,           BOTH,  XKB_KEY_exclam,          NEXT,
224                         KEY_Q,           BOTH,  XKB_KEY_Cyrillic_YA,     NEXT,
225                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Shift_L,         NEXT,
226                         KEY_V,           BOTH,  XKB_KEY_Cyrillic_zhe,    NEXT,
227                         KEY_CAPSLOCK,    BOTH,  XKB_KEY_Caps_Lock,       NEXT,
228                         KEY_1,           BOTH,  XKB_KEY_1,               NEXT,
229                         KEY_V,           BOTH,  XKB_KEY_Cyrillic_ZHE,    NEXT,
230                         KEY_RIGHTSHIFT,  DOWN,  XKB_KEY_Shift_R,         NEXT,
231                         KEY_V,           BOTH,  XKB_KEY_Cyrillic_zhe,    NEXT,
232                         KEY_RIGHTSHIFT,  UP,    XKB_KEY_Shift_R,         NEXT,
233                         KEY_V,           BOTH,  XKB_KEY_Cyrillic_ZHE,    FINISH));
234
235 #define KS(name) xkb_keysym_from_name(name, 0)
236
237     /* Test that levels (1-5) in de(neo) symbols map work. */
238     assert(test_key_seq(keymap,
239                         /* Switch to the group. */
240                         KEY_COMPOSE,     BOTH,  XKB_KEY_ISO_Next_Group,    NEXT,
241                         KEY_COMPOSE,     BOTH,  XKB_KEY_ISO_Next_Group,    NEXT,
242                         KEY_COMPOSE,     BOTH,  XKB_KEY_ISO_Next_Group,    NEXT,
243
244                         /* Level 1. */
245                         KEY_1,           BOTH,  XKB_KEY_1,                 NEXT,
246                         KEY_Q,           BOTH,  XKB_KEY_x,                 NEXT,
247                         KEY_KP7,         BOTH,  XKB_KEY_KP_7,              NEXT,
248                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
249
250                         /* Level 2 with Shift. */
251                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,           NEXT,
252                         KEY_1,           BOTH,  XKB_KEY_degree,            NEXT,
253                         KEY_Q,           BOTH,  XKB_KEY_X,                 NEXT,
254                         KEY_KP7,         BOTH,  KS("U2714"),               NEXT,
255                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
256                         /*
257                          * XXX: de(neo) uses shift(both_capslock) which causes
258                          * the interesting result in the next line. Since it's
259                          * a key release, it doesn't actually lock the modifier,
260                          * and applications by-and-large ignore the keysym on
261                          * release(?). Is this a problem?
262                          */
263                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Caps_Lock,         NEXT,
264
265                         /* Level 2 with the Lock modifier. */
266                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,           NEXT,
267                         KEY_RIGHTSHIFT,  BOTH,  XKB_KEY_Caps_Lock,         NEXT,
268                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Caps_Lock,         NEXT,
269                         KEY_6,           BOTH,  XKB_KEY_6,                 NEXT,
270                         KEY_H,           BOTH,  XKB_KEY_S,                 NEXT,
271                         KEY_KP3,         BOTH,  XKB_KEY_KP_3,              NEXT,
272                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
273                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,           NEXT,
274                         KEY_RIGHTSHIFT,  BOTH,  XKB_KEY_Caps_Lock,         NEXT,
275                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Caps_Lock,         NEXT,
276
277                         /* Level 3. */
278                         KEY_CAPSLOCK,    DOWN,  XKB_KEY_ISO_Level3_Shift,  NEXT,
279                         KEY_6,           BOTH,  XKB_KEY_cent,              NEXT,
280                         KEY_Q,           BOTH,  XKB_KEY_ellipsis,          NEXT,
281                         KEY_KP7,         BOTH,  KS("U2195"),               NEXT,
282                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
283                         KEY_CAPSLOCK,    UP,    XKB_KEY_ISO_Level3_Shift,  NEXT,
284
285                         /* Level 4. */
286                         KEY_CAPSLOCK,    DOWN,  XKB_KEY_ISO_Level3_Shift,  NEXT,
287                         KEY_LEFTSHIFT,   DOWN,  XKB_KEY_Shift_L,           NEXT,
288                         KEY_5,           BOTH,  XKB_KEY_malesymbol,        NEXT,
289                         KEY_E,           BOTH,  XKB_KEY_Greek_lambda,      NEXT,
290                         KEY_SPACE,       BOTH,  XKB_KEY_nobreakspace,      NEXT,
291                         KEY_KP8,         BOTH,  XKB_KEY_intersection,      NEXT,
292                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
293                         KEY_LEFTSHIFT,   UP,    XKB_KEY_Caps_Lock,         NEXT,
294                         KEY_CAPSLOCK,    UP,    XKB_KEY_ISO_Level3_Shift,  NEXT,
295
296                         /* Level 5. */
297                         KEY_RIGHTALT,    DOWN,  XKB_KEY_ISO_Level5_Shift,  NEXT,
298                         /* XXX: xkeyboard-config is borked when de(neo) is
299                          *      not the first group - not our fault. We test
300                          *      Level5 seprately below with only de(neo). */
301                         /* KEY_5,           BOTH,  XKB_KEY_periodcentered,    NEXT, */
302                         /* KEY_E,           BOTH,  XKB_KEY_Up,                NEXT, */
303                         /* KEY_SPACE,       BOTH,  XKB_KEY_KP_0,              NEXT, */
304                         /* KEY_KP8,         BOTH,  XKB_KEY_KP_Up,             NEXT, */
305                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
306                         KEY_RIGHTALT,    UP,    XKB_KEY_ISO_Level5_Shift,  NEXT,
307
308                         KEY_V,           BOTH,  XKB_KEY_p,               FINISH));
309
310     xkb_keymap_unref(keymap);
311     keymap = test_compile_rules(ctx, "evdev", "", "de", "neo", "");
312     assert(keymap);
313     assert(test_key_seq(keymap,
314                         /* Level 5. */
315                         KEY_RIGHTALT,    DOWN,  XKB_KEY_ISO_Level5_Shift,  NEXT,
316                         KEY_5,           BOTH,  XKB_KEY_periodcentered,    NEXT,
317                         KEY_E,           BOTH,  XKB_KEY_Up,                NEXT,
318                         KEY_SPACE,       BOTH,  XKB_KEY_KP_0,              NEXT,
319                         KEY_KP8,         BOTH,  XKB_KEY_KP_Up,             NEXT,
320                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
321                         KEY_RIGHTALT,    UP,    XKB_KEY_ISO_Level5_Shift,  NEXT,
322
323                         /* Level 6. */
324                         KEY_RIGHTALT,    DOWN,  XKB_KEY_ISO_Level5_Shift,  NEXT,
325                         KEY_RIGHTSHIFT,  DOWN,  XKB_KEY_Shift_R,           NEXT,
326                         KEY_5,           BOTH,  XKB_KEY_NoSymbol,          NEXT,
327                         KEY_8,           BOTH,  XKB_KEY_ISO_Left_Tab,      NEXT,
328                         KEY_E,           BOTH,  XKB_KEY_Up,                NEXT,
329                         KEY_SPACE,       BOTH,  XKB_KEY_KP_0,              NEXT,
330                         KEY_KP8,         BOTH,  XKB_KEY_KP_Up,             NEXT,
331                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
332                         KEY_RIGHTSHIFT,  UP,    XKB_KEY_Caps_Lock,         NEXT,
333                         KEY_RIGHTALT,    UP,    XKB_KEY_ISO_Level5_Shift,  NEXT,
334
335                         /* Level 7. */
336                         KEY_RIGHTALT,    DOWN,  XKB_KEY_ISO_Level5_Shift,  NEXT,
337                         KEY_CAPSLOCK,    DOWN,  XKB_KEY_ISO_Level3_Shift,  NEXT,
338                         KEY_5,           BOTH,  KS("U2221"),               NEXT,
339                         KEY_E,           BOTH,  XKB_KEY_Greek_LAMBDA,      NEXT,
340                         KEY_SPACE,       BOTH,  KS("U202F"),               NEXT,
341                         KEY_KP8,         BOTH,  KS("U22C2"),               NEXT,
342                         KEY_ESC,         BOTH,  XKB_KEY_Escape,            NEXT,
343                         KEY_CAPSLOCK,    UP,    XKB_KEY_ISO_Level3_Shift,  NEXT,
344                         KEY_RIGHTALT,    UP,    XKB_KEY_ISO_Level5_Shift,  NEXT,
345
346                         /* Level 8. */
347                         KEY_RIGHTALT,    DOWN,  XKB_KEY_ISO_Level5_Shift,  NEXT,
348                         KEY_CAPSLOCK,    DOWN,  XKB_KEY_ISO_Level3_Shift,  NEXT,
349                         KEY_RIGHTSHIFT,  DOWN,  XKB_KEY_Shift_R,           NEXT,
350                         /* This doesn't actually lock Level5. Not our fault. */
351                         KEY_TAB,         BOTH,  XKB_KEY_ISO_Level5_Lock,   NEXT,
352                         KEY_RIGHTSHIFT,  UP,    XKB_KEY_Caps_Lock,         NEXT,
353                         KEY_CAPSLOCK,    UP,    XKB_KEY_ISO_Level3_Shift,  NEXT,
354                         KEY_RIGHTALT,    UP,    XKB_KEY_ISO_Level5_Shift,  NEXT,
355
356                         KEY_V,           BOTH,  XKB_KEY_p,                 FINISH));
357
358
359     xkb_keymap_unref(keymap);
360     keymap = test_compile_rules(ctx, "evdev", "", "us,il,ru", "",
361                                 "grp:alt_shift_toggle_bidir,grp:menu_toggle");
362     assert(keymap);
363
364     assert(test_key_seq(keymap,
365                         KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L,        NEXT,
366                         KEY_LEFTALT,   DOWN, XKB_KEY_ISO_Prev_Group, NEXT,
367                         KEY_LEFTALT,   UP,   XKB_KEY_ISO_Prev_Group, NEXT,
368                         KEY_LEFTSHIFT, UP,   XKB_KEY_Shift_L,        FINISH));
369
370     assert(test_key_seq(keymap,
371                         KEY_LEFTALT,   DOWN, XKB_KEY_Alt_L,          NEXT,
372                         KEY_LEFTSHIFT, DOWN, XKB_KEY_ISO_Prev_Group, NEXT,
373                         KEY_LEFTSHIFT, UP,   XKB_KEY_ISO_Prev_Group, NEXT,
374                         KEY_LEFTALT,   UP,   XKB_KEY_Alt_L,          FINISH));
375
376     /* Check backwards (negative) group switching and wrapping. */
377     assert(test_key_seq(keymap,
378                         KEY_H,         BOTH, XKB_KEY_h,              NEXT,
379                         KEY_COMPOSE,   BOTH, XKB_KEY_ISO_Next_Group, NEXT,
380                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,     NEXT,
381                         KEY_COMPOSE,   BOTH, XKB_KEY_ISO_Next_Group, NEXT,
382                         KEY_H,         BOTH, XKB_KEY_Cyrillic_er,    NEXT,
383                         KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L,        NEXT,
384                         KEY_LEFTALT,   BOTH, XKB_KEY_ISO_Prev_Group, NEXT,
385                         KEY_LEFTSHIFT, UP,   XKB_KEY_Shift_L,        NEXT,
386                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,     NEXT,
387                         KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L,        NEXT,
388                         KEY_LEFTALT,   BOTH, XKB_KEY_ISO_Prev_Group, NEXT,
389                         KEY_LEFTSHIFT, UP,   XKB_KEY_Shift_L,        NEXT,
390                         KEY_H,         BOTH, XKB_KEY_h,              NEXT,
391                         KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L,        NEXT,
392                         KEY_LEFTALT,   BOTH, XKB_KEY_ISO_Prev_Group, NEXT,
393                         KEY_LEFTSHIFT, UP,   XKB_KEY_Shift_L,        NEXT,
394                         KEY_H,         BOTH, XKB_KEY_Cyrillic_er,    NEXT,
395                         KEY_COMPOSE,   BOTH, XKB_KEY_ISO_Next_Group, NEXT,
396                         KEY_H,         BOTH, XKB_KEY_h,              FINISH));
397
398     xkb_keymap_unref(keymap);
399     keymap = test_compile_rules(ctx, "evdev", "", "us,il,ru", "",
400                                 "grp:switch,grp:lswitch,grp:menu_toggle");
401     assert(keymap);
402
403     /* Test depressed group works (Mode_switch). */
404     assert(test_key_seq(keymap,
405                         KEY_H,         BOTH, XKB_KEY_h,                 NEXT,
406                         KEY_RIGHTALT,  DOWN, XKB_KEY_Mode_switch,       NEXT,
407                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,        NEXT,
408                         KEY_RIGHTALT,  UP,   XKB_KEY_ISO_Level3_Shift,  NEXT,
409                         KEY_H,         BOTH, XKB_KEY_h,                 NEXT,
410                         KEY_RIGHTALT,  DOWN, XKB_KEY_Mode_switch,       NEXT,
411                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,        NEXT,
412                         KEY_RIGHTALT,  UP,   XKB_KEY_ISO_Level3_Shift,  NEXT,
413                         KEY_H,         BOTH, XKB_KEY_h,                 FINISH));
414
415     /* Test locked+depressed group works, with wrapping and accumulation. */
416     assert(test_key_seq(keymap,
417                         KEY_H,         BOTH, XKB_KEY_h,                 NEXT,
418                         KEY_COMPOSE,   BOTH, XKB_KEY_ISO_Next_Group,    NEXT,
419                         KEY_LEFTALT,   DOWN, XKB_KEY_Mode_switch,       NEXT,
420                         KEY_H,         BOTH, XKB_KEY_Cyrillic_er,       NEXT,
421                         KEY_LEFTALT,   UP,   XKB_KEY_Mode_switch,       NEXT,
422                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,        NEXT,
423                         KEY_COMPOSE,   BOTH, XKB_KEY_ISO_Next_Group,    NEXT,
424                         KEY_LEFTALT,   DOWN, XKB_KEY_Mode_switch,       NEXT,
425                         /* Should wrap back to first group. */
426                         KEY_H,         BOTH, XKB_KEY_h,                 NEXT,
427                         KEY_LEFTALT,   UP,   XKB_KEY_Mode_switch,       NEXT,
428                         KEY_H,         BOTH, XKB_KEY_Cyrillic_er,       NEXT,
429                         KEY_COMPOSE,   BOTH, XKB_KEY_ISO_Next_Group,    NEXT,
430                         KEY_H,         BOTH, XKB_KEY_h,                 NEXT,
431                         /* Two SetGroup(+1)'s should add up. */
432                         KEY_RIGHTALT,  DOWN, XKB_KEY_Mode_switch,       NEXT,
433                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,        NEXT,
434                         KEY_LEFTALT,   DOWN, XKB_KEY_Mode_switch,       NEXT,
435                         KEY_H,         BOTH, XKB_KEY_Cyrillic_er,       NEXT,
436                         KEY_LEFTALT,   UP,   XKB_KEY_Mode_switch,       NEXT,
437                         KEY_H,         BOTH, XKB_KEY_hebrew_yod,        NEXT,
438                         KEY_RIGHTALT,  UP,   XKB_KEY_ISO_Level3_Shift,  NEXT,
439                         KEY_H,         BOTH, XKB_KEY_h,                 FINISH));
440
441     xkb_keymap_unref(keymap);
442     keymap = test_compile_rules(ctx, "evdev", "", "us", "euro", "");
443     assert(keymap);
444
445     assert(test_key_seq(keymap,
446                         KEY_5,         BOTH, XKB_KEY_5,                 NEXT,
447                         KEY_RIGHTALT,  DOWN, XKB_KEY_ISO_Level3_Shift,  NEXT,
448                         KEY_5,         BOTH, XKB_KEY_EuroSign,          NEXT,
449                         KEY_RIGHTALT,  UP,   XKB_KEY_ISO_Level3_Shift,  FINISH));
450
451     xkb_keymap_unref(keymap);
452     keymap = test_compile_file(ctx, "keymaps/unbound-vmod.xkb");
453     assert(keymap);
454
455     assert(test_key_seq(keymap,
456                         KEY_H,         BOTH, XKB_KEY_h,                 NEXT,
457                         KEY_Z,         BOTH, XKB_KEY_y,                 NEXT,
458                         KEY_MINUS,     BOTH, XKB_KEY_ssharp,            NEXT,
459                         KEY_Z,         BOTH, XKB_KEY_y,                 FINISH));
460
461     xkb_keymap_unref(keymap);
462     xkb_context_unref(ctx);
463     return 0;
464 }