2 * Copyright © 2009 Dan Nicholson
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:
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
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.
24 #include "evdev-scancodes.h"
28 test_rmlvo_va(struct xkb_context *context, const char *rules,
29 const char *model, const char *layout,
30 const char *variant, const char *options, va_list ap)
32 struct xkb_keymap *keymap;
35 keymap = test_compile_rules(context, rules, model, layout, variant,
40 fprintf(stderr, "Compiled '%s' '%s' '%s' '%s' '%s'\n",
41 strnull(rules), strnull(model), strnull(layout),
42 strnull(variant), strnull(options));
44 ret = test_key_seq_va(keymap, ap);
46 xkb_keymap_unref(keymap);
52 test_rmlvo(struct xkb_context *context, const char *rules,
53 const char *model, const char *layout, const char *variant,
54 const char *options, ...)
59 va_start(ap, options);
60 ret = test_rmlvo_va(context, rules, model, layout, variant, options, ap);
67 test_rmlvo_env(struct xkb_context *ctx, const char *rules, const char *model,
68 const char *layout, const char *variant, const char *options,
74 va_start (ap, options);
77 setenv("XKB_DEFAULT_RULES", rules, 1);
79 unsetenv("XKB_DEFAULT_RULES");
82 setenv("XKB_DEFAULT_MODEL", model, 1);
84 unsetenv("XKB_DEFAULT_MODEL");
87 setenv("XKB_DEFAULT_LAYOUT", layout, 1);
89 unsetenv("XKB_DEFAULT_LAYOUT");
91 if (!isempty(variant))
92 setenv("XKB_DEFAULT_VARIANT", variant, 1);
94 unsetenv("XKB_DEFAULT_VARIANT");
96 if (!isempty(options))
97 setenv("XKB_DEFAULT_OPTIONS", options, 1);
99 unsetenv("XKB_DEFAULT_OPTIONS");
101 ret = test_rmlvo_va(ctx, NULL, NULL, NULL, NULL, NULL, ap);
109 main(int argc, char *argv[])
111 struct xkb_context *ctx = test_get_context(CONTEXT_ALLOW_ENVIRONMENT_NAMES);
115 #define KS(name) xkb_keysym_from_name(name, 0)
117 assert(test_rmlvo(ctx, "evdev", "pc105", "us,il,ru,ca", ",,,multix", "grp:alts_toggle,ctrl:nocaps,compose:rwin",
118 KEY_Q, BOTH, XKB_KEY_q, NEXT,
119 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
120 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
121 KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT,
122 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
123 KEY_Q, BOTH, XKB_KEY_slash, NEXT,
124 KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L, NEXT,
125 KEY_Q, BOTH, XKB_KEY_Q, NEXT,
126 KEY_RIGHTMETA, BOTH, XKB_KEY_Multi_key, FINISH));
127 assert(test_rmlvo(ctx, "evdev", "pc105", "us,in", "", "grp:alts_toggle",
128 KEY_A, BOTH, XKB_KEY_a, NEXT,
129 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
130 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
131 KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT,
132 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
133 KEY_A, BOTH, KS("U094b"), FINISH));
134 assert(test_rmlvo(ctx, "evdev", "pc105", "us", "intl", "",
135 KEY_GRAVE, BOTH, XKB_KEY_dead_grave, FINISH));
136 assert(test_rmlvo(ctx, "evdev", "evdev", "us", "intl", "grp:alts_toggle",
137 KEY_GRAVE, BOTH, XKB_KEY_dead_grave, FINISH));
139 /* 20 is not a legal group; make sure this is handled gracefully. */
140 assert(test_rmlvo(ctx, "evdev", "", "us:20", "", "",
141 KEY_A, BOTH, XKB_KEY_a, FINISH));
143 /* Don't choke on missing values in RMLVO. Should just skip them.
144 Currently generates us,us,ca. */
145 assert(test_rmlvo(ctx, "evdev", "", "us,,ca", "", "grp:alts_toggle",
146 KEY_A, BOTH, XKB_KEY_a, NEXT,
147 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
148 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
149 KEY_RIGHTALT, UP, XKB_KEY_ISO_Next_Group, NEXT,
150 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
151 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
152 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
153 KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT,
154 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
155 KEY_APOSTROPHE, BOTH, XKB_KEY_dead_grave, FINISH));
157 assert(test_rmlvo(ctx, "", "", "", "", "",
158 KEY_A, BOTH, XKB_KEY_a, FINISH));
160 assert(!test_rmlvo(ctx, "does-not-exist", "", "", "", "",
161 KEY_A, BOTH, XKB_KEY_a, FINISH));
163 assert(test_rmlvo_env(ctx, "evdev", "", "us", "", "",
164 KEY_A, BOTH, XKB_KEY_a, FINISH));
165 assert(test_rmlvo_env(ctx, "evdev", "", "us", "", "ctrl:nocaps",
166 KEY_CAPSLOCK, BOTH, XKB_KEY_Control_L, FINISH));
168 /* Ignores multix and generates us,ca. */
169 assert(test_rmlvo_env(ctx, "evdev", "", "us,ca", ",,,multix", "grp:alts_toggle",
170 KEY_A, BOTH, XKB_KEY_a, NEXT,
171 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
172 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
173 KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT,
174 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
175 KEY_GRAVE, UP, XKB_KEY_numbersign, FINISH));
177 assert(!test_rmlvo_env(ctx, "broken", "what-on-earth", "invalid", "", "",
178 KEY_A, BOTH, XKB_KEY_a, FINISH));
180 /* Ensure a keymap with an empty xkb_keycodes compiles fine. */
181 assert(test_rmlvo_env(ctx, "base", "empty", "empty", "", "",
182 KEY_A, BOTH, XKB_KEY_NoSymbol, FINISH));
184 /* Has an illegal escape sequence, but shouldn't fail. */
185 assert(test_rmlvo_env(ctx, "evdev", "", "cz", "bksl", "",
186 KEY_A, BOTH, XKB_KEY_a, FINISH));
188 xkb_context_unref(ctx);
190 ctx = test_get_context(0);
191 assert(test_rmlvo_env(ctx, "broken", "but", "ignored", "per", "ctx flags",
192 KEY_A, BOTH, XKB_KEY_a, FINISH));
194 /* Test response to invalid flags. */
196 struct xkb_rule_names rmlvo = { NULL };
197 assert(!xkb_keymap_new_from_names(ctx, &rmlvo, -1));
198 assert(!xkb_keymap_new_from_names(ctx, &rmlvo, 5453));
201 xkb_context_unref(ctx);