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.
26 #include "evdev-scancodes.h"
30 test_rmlvo_va(struct xkb_context *context, const char *rules,
31 const char *model, const char *layout,
32 const char *variant, const char *options, va_list ap)
34 struct xkb_keymap *keymap;
37 keymap = test_compile_rules(context, rules, model, layout, variant,
42 fprintf(stderr, "Compiled '%s' '%s' '%s' '%s' '%s'\n",
43 strnull(rules), strnull(model), strnull(layout),
44 strnull(variant), strnull(options));
46 ret = test_key_seq_va(keymap, ap);
48 xkb_keymap_unref(keymap);
54 test_rmlvo(struct xkb_context *context, const char *rules,
55 const char *model, const char *layout, const char *variant,
56 const char *options, ...)
61 va_start(ap, options);
62 ret = test_rmlvo_va(context, rules, model, layout, variant, options, ap);
69 test_rmlvo_env(struct xkb_context *ctx, const char *rules, const char *model,
70 const char *layout, const char *variant, const char *options,
76 va_start (ap, options);
79 setenv("XKB_DEFAULT_RULES", rules, 1);
81 unsetenv("XKB_DEFAULT_RULES");
84 setenv("XKB_DEFAULT_MODEL", model, 1);
86 unsetenv("XKB_DEFAULT_MODEL");
89 setenv("XKB_DEFAULT_LAYOUT", layout, 1);
91 unsetenv("XKB_DEFAULT_LAYOUT");
93 if (!isempty(variant))
94 setenv("XKB_DEFAULT_VARIANT", variant, 1);
96 unsetenv("XKB_DEFAULT_VARIANT");
98 if (!isempty(options))
99 setenv("XKB_DEFAULT_OPTIONS", options, 1);
101 unsetenv("XKB_DEFAULT_OPTIONS");
103 ret = test_rmlvo_va(ctx, NULL, NULL, NULL, NULL, NULL, ap);
111 main(int argc, char *argv[])
113 struct xkb_context *ctx = test_get_context(CONTEXT_ALLOW_ENVIRONMENT_NAMES);
117 #define KS(name) xkb_keysym_from_name(name, 0)
119 assert(test_rmlvo(ctx, "evdev", "pc105", "us,il,ru,ca", ",,,multix", "grp:alts_toggle,ctrl:nocaps,compose:rwin",
120 KEY_Q, BOTH, XKB_KEY_q, NEXT,
121 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
122 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
123 KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT,
124 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
125 KEY_Q, BOTH, XKB_KEY_slash, NEXT,
126 KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L, NEXT,
127 KEY_Q, BOTH, XKB_KEY_Q, NEXT,
128 KEY_RIGHTMETA, BOTH, XKB_KEY_Multi_key, FINISH));
129 assert(test_rmlvo(ctx, "evdev", "pc105", "us,in", "", "grp:alts_toggle",
130 KEY_A, BOTH, XKB_KEY_a, NEXT,
131 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
132 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
133 KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT,
134 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
135 KEY_A, BOTH, KS("U094b"), FINISH));
136 assert(test_rmlvo(ctx, "evdev", "pc105", "us", "intl", "",
137 KEY_GRAVE, BOTH, XKB_KEY_dead_grave, FINISH));
138 assert(test_rmlvo(ctx, "evdev", "evdev", "us", "intl", "grp:alts_toggle",
139 KEY_GRAVE, BOTH, XKB_KEY_dead_grave, FINISH));
141 /* 20 is not a legal group; make sure this is handled gracefully. */
142 assert(test_rmlvo(ctx, "evdev", "", "us:20", "", "",
143 KEY_A, BOTH, XKB_KEY_a, FINISH));
145 /* Don't choke on missing values in RMLVO. Should just skip them.
146 Currently generates us,us,ca. */
147 assert(test_rmlvo(ctx, "evdev", "", "us,,ca", "", "grp:alts_toggle",
148 KEY_A, BOTH, XKB_KEY_a, NEXT,
149 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
150 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
151 KEY_RIGHTALT, UP, XKB_KEY_ISO_Next_Group, NEXT,
152 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
153 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
154 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
155 KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT,
156 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
157 KEY_APOSTROPHE, BOTH, XKB_KEY_dead_grave, FINISH));
159 assert(test_rmlvo(ctx, "", "", "", "", "",
160 KEY_A, BOTH, XKB_KEY_a, FINISH));
162 assert(!test_rmlvo(ctx, "does-not-exist", "", "", "", "",
163 KEY_A, BOTH, XKB_KEY_a, FINISH));
165 assert(test_rmlvo_env(ctx, "evdev", "", "us", "", "",
166 KEY_A, BOTH, XKB_KEY_a, FINISH));
167 assert(test_rmlvo_env(ctx, "evdev", "", "us", "", "ctrl:nocaps",
168 KEY_CAPSLOCK, BOTH, XKB_KEY_Control_L, FINISH));
170 /* Ignores multix and generates us,ca. */
171 assert(test_rmlvo_env(ctx, "evdev", "", "us,ca", ",,,multix", "grp:alts_toggle",
172 KEY_A, BOTH, XKB_KEY_a, NEXT,
173 KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
174 KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
175 KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT,
176 KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
177 KEY_GRAVE, UP, XKB_KEY_numbersign, FINISH));
179 assert(!test_rmlvo_env(ctx, "broken", "what-on-earth", "invalid", "", "",
180 KEY_A, BOTH, XKB_KEY_a, FINISH));
182 /* Ensure a keymap with an empty xkb_keycodes compiles fine. */
183 assert(test_rmlvo_env(ctx, "base", "empty", "empty", "", "",
184 KEY_A, BOTH, XKB_KEY_NoSymbol, FINISH));
186 /* Has an illegal escape sequence, but shouldn't fail. */
187 assert(test_rmlvo_env(ctx, "evdev", "", "cz", "bksl", "",
188 KEY_A, BOTH, XKB_KEY_a, FINISH));
190 xkb_context_unref(ctx);
192 ctx = test_get_context(0);
193 assert(test_rmlvo_env(ctx, "broken", "but", "ignored", "per", "ctx flags",
194 KEY_A, BOTH, XKB_KEY_a, FINISH));
196 /* Test response to invalid flags. */
198 struct xkb_rule_names rmlvo = { NULL };
199 assert(!xkb_keymap_new_from_names(ctx, &rmlvo, -1));
200 assert(!xkb_keymap_new_from_names(ctx, &rmlvo, 5453));
203 xkb_context_unref(ctx);