1*2b949d04SAndroid Build Coastguard Worker /*
2*2b949d04SAndroid Build Coastguard Worker * Copyright © 2009 Dan Nicholson
3*2b949d04SAndroid Build Coastguard Worker *
4*2b949d04SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a
5*2b949d04SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"),
6*2b949d04SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation
7*2b949d04SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*2b949d04SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the
9*2b949d04SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions:
10*2b949d04SAndroid Build Coastguard Worker *
11*2b949d04SAndroid Build Coastguard Worker * The above copyright notice and this permission notice (including the next
12*2b949d04SAndroid Build Coastguard Worker * paragraph) shall be included in all copies or substantial portions of the
13*2b949d04SAndroid Build Coastguard Worker * Software.
14*2b949d04SAndroid Build Coastguard Worker *
15*2b949d04SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*2b949d04SAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*2b949d04SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18*2b949d04SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*2b949d04SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*2b949d04SAndroid Build Coastguard Worker * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*2b949d04SAndroid Build Coastguard Worker * DEALINGS IN THE SOFTWARE.
22*2b949d04SAndroid Build Coastguard Worker */
23*2b949d04SAndroid Build Coastguard Worker
24*2b949d04SAndroid Build Coastguard Worker #include "config.h"
25*2b949d04SAndroid Build Coastguard Worker
26*2b949d04SAndroid Build Coastguard Worker #include "evdev-scancodes.h"
27*2b949d04SAndroid Build Coastguard Worker #include "test.h"
28*2b949d04SAndroid Build Coastguard Worker
29*2b949d04SAndroid Build Coastguard Worker static int
test_rmlvo_va(struct xkb_context * context,const char * rules,const char * model,const char * layout,const char * variant,const char * options,va_list ap)30*2b949d04SAndroid Build Coastguard Worker test_rmlvo_va(struct xkb_context *context, const char *rules,
31*2b949d04SAndroid Build Coastguard Worker const char *model, const char *layout,
32*2b949d04SAndroid Build Coastguard Worker const char *variant, const char *options, va_list ap)
33*2b949d04SAndroid Build Coastguard Worker {
34*2b949d04SAndroid Build Coastguard Worker struct xkb_keymap *keymap;
35*2b949d04SAndroid Build Coastguard Worker int ret;
36*2b949d04SAndroid Build Coastguard Worker
37*2b949d04SAndroid Build Coastguard Worker keymap = test_compile_rules(context, rules, model, layout, variant,
38*2b949d04SAndroid Build Coastguard Worker options);
39*2b949d04SAndroid Build Coastguard Worker if (!keymap)
40*2b949d04SAndroid Build Coastguard Worker return 0;
41*2b949d04SAndroid Build Coastguard Worker
42*2b949d04SAndroid Build Coastguard Worker fprintf(stderr, "Compiled '%s' '%s' '%s' '%s' '%s'\n",
43*2b949d04SAndroid Build Coastguard Worker strnull(rules), strnull(model), strnull(layout),
44*2b949d04SAndroid Build Coastguard Worker strnull(variant), strnull(options));
45*2b949d04SAndroid Build Coastguard Worker
46*2b949d04SAndroid Build Coastguard Worker ret = test_key_seq_va(keymap, ap);
47*2b949d04SAndroid Build Coastguard Worker
48*2b949d04SAndroid Build Coastguard Worker xkb_keymap_unref(keymap);
49*2b949d04SAndroid Build Coastguard Worker
50*2b949d04SAndroid Build Coastguard Worker return ret;
51*2b949d04SAndroid Build Coastguard Worker }
52*2b949d04SAndroid Build Coastguard Worker
53*2b949d04SAndroid Build Coastguard Worker static int
test_rmlvo(struct xkb_context * context,const char * rules,const char * model,const char * layout,const char * variant,const char * options,...)54*2b949d04SAndroid Build Coastguard Worker test_rmlvo(struct xkb_context *context, const char *rules,
55*2b949d04SAndroid Build Coastguard Worker const char *model, const char *layout, const char *variant,
56*2b949d04SAndroid Build Coastguard Worker const char *options, ...)
57*2b949d04SAndroid Build Coastguard Worker {
58*2b949d04SAndroid Build Coastguard Worker va_list ap;
59*2b949d04SAndroid Build Coastguard Worker int ret;
60*2b949d04SAndroid Build Coastguard Worker
61*2b949d04SAndroid Build Coastguard Worker va_start(ap, options);
62*2b949d04SAndroid Build Coastguard Worker ret = test_rmlvo_va(context, rules, model, layout, variant, options, ap);
63*2b949d04SAndroid Build Coastguard Worker va_end(ap);
64*2b949d04SAndroid Build Coastguard Worker
65*2b949d04SAndroid Build Coastguard Worker return ret;
66*2b949d04SAndroid Build Coastguard Worker }
67*2b949d04SAndroid Build Coastguard Worker
68*2b949d04SAndroid Build Coastguard Worker static int
test_rmlvo_env(struct xkb_context * ctx,const char * rules,const char * model,const char * layout,const char * variant,const char * options,...)69*2b949d04SAndroid Build Coastguard Worker test_rmlvo_env(struct xkb_context *ctx, const char *rules, const char *model,
70*2b949d04SAndroid Build Coastguard Worker const char *layout, const char *variant, const char *options,
71*2b949d04SAndroid Build Coastguard Worker ...)
72*2b949d04SAndroid Build Coastguard Worker {
73*2b949d04SAndroid Build Coastguard Worker va_list ap;
74*2b949d04SAndroid Build Coastguard Worker int ret;
75*2b949d04SAndroid Build Coastguard Worker
76*2b949d04SAndroid Build Coastguard Worker va_start (ap, options);
77*2b949d04SAndroid Build Coastguard Worker
78*2b949d04SAndroid Build Coastguard Worker if (!isempty(rules))
79*2b949d04SAndroid Build Coastguard Worker setenv("XKB_DEFAULT_RULES", rules, 1);
80*2b949d04SAndroid Build Coastguard Worker else
81*2b949d04SAndroid Build Coastguard Worker unsetenv("XKB_DEFAULT_RULES");
82*2b949d04SAndroid Build Coastguard Worker
83*2b949d04SAndroid Build Coastguard Worker if (!isempty(model))
84*2b949d04SAndroid Build Coastguard Worker setenv("XKB_DEFAULT_MODEL", model, 1);
85*2b949d04SAndroid Build Coastguard Worker else
86*2b949d04SAndroid Build Coastguard Worker unsetenv("XKB_DEFAULT_MODEL");
87*2b949d04SAndroid Build Coastguard Worker
88*2b949d04SAndroid Build Coastguard Worker if (!isempty(layout))
89*2b949d04SAndroid Build Coastguard Worker setenv("XKB_DEFAULT_LAYOUT", layout, 1);
90*2b949d04SAndroid Build Coastguard Worker else
91*2b949d04SAndroid Build Coastguard Worker unsetenv("XKB_DEFAULT_LAYOUT");
92*2b949d04SAndroid Build Coastguard Worker
93*2b949d04SAndroid Build Coastguard Worker if (!isempty(variant))
94*2b949d04SAndroid Build Coastguard Worker setenv("XKB_DEFAULT_VARIANT", variant, 1);
95*2b949d04SAndroid Build Coastguard Worker else
96*2b949d04SAndroid Build Coastguard Worker unsetenv("XKB_DEFAULT_VARIANT");
97*2b949d04SAndroid Build Coastguard Worker
98*2b949d04SAndroid Build Coastguard Worker if (!isempty(options))
99*2b949d04SAndroid Build Coastguard Worker setenv("XKB_DEFAULT_OPTIONS", options, 1);
100*2b949d04SAndroid Build Coastguard Worker else
101*2b949d04SAndroid Build Coastguard Worker unsetenv("XKB_DEFAULT_OPTIONS");
102*2b949d04SAndroid Build Coastguard Worker
103*2b949d04SAndroid Build Coastguard Worker ret = test_rmlvo_va(ctx, NULL, NULL, NULL, NULL, NULL, ap);
104*2b949d04SAndroid Build Coastguard Worker
105*2b949d04SAndroid Build Coastguard Worker va_end(ap);
106*2b949d04SAndroid Build Coastguard Worker
107*2b949d04SAndroid Build Coastguard Worker return ret;
108*2b949d04SAndroid Build Coastguard Worker }
109*2b949d04SAndroid Build Coastguard Worker
110*2b949d04SAndroid Build Coastguard Worker int
main(int argc,char * argv[])111*2b949d04SAndroid Build Coastguard Worker main(int argc, char *argv[])
112*2b949d04SAndroid Build Coastguard Worker {
113*2b949d04SAndroid Build Coastguard Worker struct xkb_context *ctx = test_get_context(CONTEXT_ALLOW_ENVIRONMENT_NAMES);
114*2b949d04SAndroid Build Coastguard Worker
115*2b949d04SAndroid Build Coastguard Worker assert(ctx);
116*2b949d04SAndroid Build Coastguard Worker
117*2b949d04SAndroid Build Coastguard Worker #define KS(name) xkb_keysym_from_name(name, 0)
118*2b949d04SAndroid Build Coastguard Worker
119*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo(ctx, "evdev", "pc105", "us,il,ru,ca", ",,,multix", "grp:alts_toggle,ctrl:nocaps,compose:rwin",
120*2b949d04SAndroid Build Coastguard Worker KEY_Q, BOTH, XKB_KEY_q, NEXT,
121*2b949d04SAndroid Build Coastguard Worker KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
122*2b949d04SAndroid Build Coastguard Worker KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
123*2b949d04SAndroid Build Coastguard Worker KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT,
124*2b949d04SAndroid Build Coastguard Worker KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
125*2b949d04SAndroid Build Coastguard Worker KEY_Q, BOTH, XKB_KEY_slash, NEXT,
126*2b949d04SAndroid Build Coastguard Worker KEY_LEFTSHIFT, DOWN, XKB_KEY_Shift_L, NEXT,
127*2b949d04SAndroid Build Coastguard Worker KEY_Q, BOTH, XKB_KEY_Q, NEXT,
128*2b949d04SAndroid Build Coastguard Worker KEY_RIGHTMETA, BOTH, XKB_KEY_Multi_key, FINISH));
129*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo(ctx, "evdev", "pc105", "us,in", "", "grp:alts_toggle",
130*2b949d04SAndroid Build Coastguard Worker KEY_A, BOTH, XKB_KEY_a, NEXT,
131*2b949d04SAndroid Build Coastguard Worker KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
132*2b949d04SAndroid Build Coastguard Worker KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
133*2b949d04SAndroid Build Coastguard Worker KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT,
134*2b949d04SAndroid Build Coastguard Worker KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
135*2b949d04SAndroid Build Coastguard Worker KEY_A, BOTH, KS("U094b"), FINISH));
136*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo(ctx, "evdev", "pc105", "us", "intl", "",
137*2b949d04SAndroid Build Coastguard Worker KEY_GRAVE, BOTH, XKB_KEY_dead_grave, FINISH));
138*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo(ctx, "evdev", "evdev", "us", "intl", "grp:alts_toggle",
139*2b949d04SAndroid Build Coastguard Worker KEY_GRAVE, BOTH, XKB_KEY_dead_grave, FINISH));
140*2b949d04SAndroid Build Coastguard Worker
141*2b949d04SAndroid Build Coastguard Worker /* 20 is not a legal group; make sure this is handled gracefully. */
142*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo(ctx, "evdev", "", "us:20", "", "",
143*2b949d04SAndroid Build Coastguard Worker KEY_A, BOTH, XKB_KEY_a, FINISH));
144*2b949d04SAndroid Build Coastguard Worker
145*2b949d04SAndroid Build Coastguard Worker /* Don't choke on missing values in RMLVO. Should just skip them.
146*2b949d04SAndroid Build Coastguard Worker Currently generates us,us,ca. */
147*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo(ctx, "evdev", "", "us,,ca", "", "grp:alts_toggle",
148*2b949d04SAndroid Build Coastguard Worker KEY_A, BOTH, XKB_KEY_a, NEXT,
149*2b949d04SAndroid Build Coastguard Worker KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
150*2b949d04SAndroid Build Coastguard Worker KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
151*2b949d04SAndroid Build Coastguard Worker KEY_RIGHTALT, UP, XKB_KEY_ISO_Next_Group, NEXT,
152*2b949d04SAndroid Build Coastguard Worker KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
153*2b949d04SAndroid Build Coastguard Worker KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
154*2b949d04SAndroid Build Coastguard Worker KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
155*2b949d04SAndroid Build Coastguard Worker KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT,
156*2b949d04SAndroid Build Coastguard Worker KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
157*2b949d04SAndroid Build Coastguard Worker KEY_APOSTROPHE, BOTH, XKB_KEY_dead_grave, FINISH));
158*2b949d04SAndroid Build Coastguard Worker
159*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo(ctx, "", "", "", "", "",
160*2b949d04SAndroid Build Coastguard Worker KEY_A, BOTH, XKB_KEY_a, FINISH));
161*2b949d04SAndroid Build Coastguard Worker
162*2b949d04SAndroid Build Coastguard Worker assert(!test_rmlvo(ctx, "does-not-exist", "", "", "", "",
163*2b949d04SAndroid Build Coastguard Worker KEY_A, BOTH, XKB_KEY_a, FINISH));
164*2b949d04SAndroid Build Coastguard Worker
165*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo_env(ctx, "evdev", "", "us", "", "",
166*2b949d04SAndroid Build Coastguard Worker KEY_A, BOTH, XKB_KEY_a, FINISH));
167*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo_env(ctx, "evdev", "", "us", "", "ctrl:nocaps",
168*2b949d04SAndroid Build Coastguard Worker KEY_CAPSLOCK, BOTH, XKB_KEY_Control_L, FINISH));
169*2b949d04SAndroid Build Coastguard Worker
170*2b949d04SAndroid Build Coastguard Worker /* Ignores multix and generates us,ca. */
171*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo_env(ctx, "evdev", "", "us,ca", ",,,multix", "grp:alts_toggle",
172*2b949d04SAndroid Build Coastguard Worker KEY_A, BOTH, XKB_KEY_a, NEXT,
173*2b949d04SAndroid Build Coastguard Worker KEY_LEFTALT, DOWN, XKB_KEY_Alt_L, NEXT,
174*2b949d04SAndroid Build Coastguard Worker KEY_RIGHTALT, DOWN, XKB_KEY_ISO_Next_Group, NEXT,
175*2b949d04SAndroid Build Coastguard Worker KEY_RIGHTALT, UP, XKB_KEY_ISO_Level3_Shift, NEXT,
176*2b949d04SAndroid Build Coastguard Worker KEY_LEFTALT, UP, XKB_KEY_Alt_L, NEXT,
177*2b949d04SAndroid Build Coastguard Worker KEY_GRAVE, UP, XKB_KEY_numbersign, FINISH));
178*2b949d04SAndroid Build Coastguard Worker
179*2b949d04SAndroid Build Coastguard Worker assert(!test_rmlvo_env(ctx, "broken", "what-on-earth", "invalid", "", "",
180*2b949d04SAndroid Build Coastguard Worker KEY_A, BOTH, XKB_KEY_a, FINISH));
181*2b949d04SAndroid Build Coastguard Worker
182*2b949d04SAndroid Build Coastguard Worker /* Ensure a keymap with an empty xkb_keycodes compiles fine. */
183*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo_env(ctx, "base", "empty", "empty", "", "",
184*2b949d04SAndroid Build Coastguard Worker KEY_A, BOTH, XKB_KEY_NoSymbol, FINISH));
185*2b949d04SAndroid Build Coastguard Worker
186*2b949d04SAndroid Build Coastguard Worker /* Has an illegal escape sequence, but shouldn't fail. */
187*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo_env(ctx, "evdev", "", "cz", "bksl", "",
188*2b949d04SAndroid Build Coastguard Worker KEY_A, BOTH, XKB_KEY_a, FINISH));
189*2b949d04SAndroid Build Coastguard Worker
190*2b949d04SAndroid Build Coastguard Worker xkb_context_unref(ctx);
191*2b949d04SAndroid Build Coastguard Worker
192*2b949d04SAndroid Build Coastguard Worker ctx = test_get_context(0);
193*2b949d04SAndroid Build Coastguard Worker assert(test_rmlvo_env(ctx, "broken", "but", "ignored", "per", "ctx flags",
194*2b949d04SAndroid Build Coastguard Worker KEY_A, BOTH, XKB_KEY_a, FINISH));
195*2b949d04SAndroid Build Coastguard Worker
196*2b949d04SAndroid Build Coastguard Worker /* Test response to invalid flags. */
197*2b949d04SAndroid Build Coastguard Worker {
198*2b949d04SAndroid Build Coastguard Worker struct xkb_rule_names rmlvo = { NULL };
199*2b949d04SAndroid Build Coastguard Worker assert(!xkb_keymap_new_from_names(ctx, &rmlvo, -1));
200*2b949d04SAndroid Build Coastguard Worker assert(!xkb_keymap_new_from_names(ctx, &rmlvo, 5453));
201*2b949d04SAndroid Build Coastguard Worker }
202*2b949d04SAndroid Build Coastguard Worker
203*2b949d04SAndroid Build Coastguard Worker xkb_context_unref(ctx);
204*2b949d04SAndroid Build Coastguard Worker return 0;
205*2b949d04SAndroid Build Coastguard Worker }
206