Skip to content

Commit 35aa91c

Browse files
committed
symbols: Add tests for multiple actions per level
1 parent a367236 commit 35aa91c

File tree

5 files changed

+454
-44
lines changed

5 files changed

+454
-44
lines changed

test/buffercomp.c

Lines changed: 85 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -161,62 +161,104 @@ test_recursive(struct xkb_context *ctx)
161161
}
162162
}
163163

164+
/* Test various multi-{keysym,action} syntaxes */
164165
static void
165-
test_multi_keysyms(struct xkb_context *ctx)
166+
test_multi_keysyms_actions(struct xkb_context *ctx)
166167
{
167168
struct xkb_keymap *keymap;
168-
const char* const invalid_keymaps[] = {
169-
#define make_keymap(keysyms) \
170-
"xkb_keymap {\n" \
171-
" xkb_keycodes {\n" \
172-
" minimum= 8;\n" \
173-
" maximum= 10;\n" \
174-
" <AE01> = 10;\n" \
175-
" };\n" \
176-
" xkb_types { include \"basic\" };\n" \
177-
" xkb_compat { include \"basic\" };\n" \
178-
" xkb_symbols {\n" \
179-
" key <AE01> { [ " keysyms " ] };\n" \
180-
" };\n" \
181-
"};"
182-
make_keymap("{}"),
183-
make_keymap("{ a }"),
184-
make_keymap("{ {} }"),
185-
make_keymap("{ a, {} }"),
186-
make_keymap("{ {}, b }"),
187-
make_keymap("{ a, { b } }"),
188-
make_keymap("{ { a }, b }"),
189-
make_keymap("{ { a, b }, c }"),
190-
make_keymap("{ a, { b, c } }"),
191-
make_keymap("{ a, {}, c }"),
192-
make_keymap("{ a, b, {} }"),
193-
make_keymap("{ {}, b, c }"),
194-
make_keymap("{ { a, b }, c, d }"),
195-
make_keymap("{ a, { b, c }, d }"),
196-
make_keymap("{ a, b, { c, d } }"),
197-
make_keymap("{ { a, b }, { c, d } }"),
198-
};
199-
const size_t len = ARRAY_SIZE(invalid_keymaps);
200169

201-
for (size_t k = 0; k < len; k++) {
202-
fprintf(stderr, "*** test_multi_keysyms: #%zu ***\n", k + 1);
203-
keymap = test_compile_buffer(ctx, invalid_keymaps[k],
204-
strlen(invalid_keymaps[k]));
205-
assert_printf(!keymap,
206-
"The following symbols *do* parse:\n%s\n",
207-
invalid_keymaps[k]);
208-
}
170+
/* Macros to define the tests */
171+
#define make_keymap(keysyms, actions) \
172+
"xkb_keymap {\n" \
173+
" xkb_keycodes {\n" \
174+
" minimum= 8;\n" \
175+
" maximum= 10;\n" \
176+
" <AE01> = 10;\n" \
177+
" };\n" \
178+
" xkb_types { include \"basic\" };\n" \
179+
" xkb_compat { include \"basic\" };\n" \
180+
" xkb_symbols {\n" \
181+
" key <AE01> { " keysyms actions " };\n" \
182+
" };\n" \
183+
"};"
184+
#define make_keymap_with_keysyms(keysyms) \
185+
make_keymap("[" keysyms "]", "")
186+
#define make_keymap_with_actions(actions) \
187+
make_keymap("", "actions[1] = [" actions "]")
188+
#define test_keymaps \
189+
make_keymaps_with(make_keymap_with_keysyms, \
190+
"a", "b", "c", "d"), \
191+
make_keymaps_with(make_keymap_with_actions, \
192+
"SetMods(modifiers=Control)", \
193+
"SetGroup(group=+1)", \
194+
"Private(data=\"foo\")", \
195+
"Private(data=\"bar\")")
196+
#define run_test(kind, condition, msg, ...) do { \
197+
const char* const keymaps[] = { test_keymaps }; \
198+
for (size_t k = 0; k < ARRAY_SIZE(keymaps); k++) { \
199+
fprintf(stderr, \
200+
"*** test_multi_keysyms_actions: " kind "#%zu ***\n", \
201+
k + 1); \
202+
keymap = test_compile_buffer(ctx, keymaps[k], \
203+
strlen(keymaps[k])); \
204+
assert_printf(condition, \
205+
"The following symbols " msg " parse:\n%s\n", \
206+
keymaps[k]); \
207+
__VA_ARGS__; \
208+
} \
209+
} while (0)
210+
211+
/* Test: valid keymaps */
212+
#define make_keymaps_with(func, a, b, c, d) \
213+
func(a), \
214+
func(a", "b), \
215+
func("{ "a", "b" }"), \
216+
func("{ "a", "b", "c" }"), \
217+
func(a", { "b", "c" }"), \
218+
func("{ "a", "b" }, "c), \
219+
func("{ "a", "b" }, { "c", "d" }"), \
220+
func("{ "a", "b" }, "c", { "d", "a" }"), \
221+
func("{ "a", "b" }, { "c", "d" }, "a)
222+
run_test("valid", keymap != NULL, "does *not*", xkb_keymap_unref(keymap));
223+
#undef make_keymaps_with
224+
225+
/* Test: invalid keymaps */
226+
#define make_keymaps_with(func, a, b, c, d) \
227+
func("{}"), \
228+
func("{ {} }"), \
229+
func("{ "a" }"), \
230+
func("{ "a", {} }"), \
231+
func("{ {}, "b" }"), \
232+
func("{ {}, {} }"), \
233+
func("{ "a", { "b" } }"), \
234+
func("{ { "a" }, "b" }"), \
235+
func("{ { "a", "b" }, "c" }"), \
236+
func("{ "a", { "b", "c" } }"), \
237+
func("{ "a", {}, "c" }"), \
238+
func("{ "a", "b", {} }"), \
239+
func("{ {}, "b", "c" }"), \
240+
func("{ { "a", "b" }, "c", "d" }"), \
241+
func("{ "a", { "b", "c" }, "d" }"), \
242+
func("{ "a", "b", { "c", "d" } }"), \
243+
func("{ { "a", "b" }, { "c", "d" } }")
244+
run_test("invalid", keymap == NULL, "*does*");
245+
#undef make_keymap
246+
#undef make_keymap_with_actions
247+
#undef make_keymap_with_keysyms
248+
#undef make_keymaps_with
249+
#undef test_keymaps
250+
#undef run_test
209251
}
210252

211253
int
212254
main(int argc, char *argv[])
213255
{
214256
test_init();
215257

216-
struct xkb_context *ctx = test_get_context(CONTEXT_NO_FLAG);
217258
struct xkb_keymap *keymap;
218259
char *original, *dump;
219260

261+
struct xkb_context *ctx = test_get_context(CONTEXT_NO_FLAG);
220262
assert(ctx);
221263

222264
/* Load in a prebuilt keymap, make sure we can compile it from memory,
@@ -272,7 +314,7 @@ main(int argc, char *argv[])
272314
free(dump);
273315

274316
test_recursive(ctx);
275-
test_multi_keysyms(ctx);
317+
test_multi_keysyms_actions(ctx);
276318

277319
xkb_context_unref(ctx);
278320

test/data/keymaps/stringcomp.data

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,13 @@ xkb_symbols "pc_us_ru_2_ca(multix)_3_de(neo)_4_inet(evdev)" {
17281728
type= "CTRL+ALT",
17291729
symbols[Group1]= [ F12, F12, F12, F12, XF86Switch_VT_12 ]
17301730
};
1731+
key <AB11> {
1732+
repeat= No,
1733+
symbols[Group1]= [ Control_L, { Control_L, Mode_switch } ],
1734+
actions[Group1]= [ SetMods(modifiers=Control), { SetMods(modifiers=Control), SetGroup(group=+1) } ],
1735+
symbols[Group2]= [ { Control_L, Mode_switch }, Control_L ],
1736+
actions[Group2]= [ { SetMods(modifiers=Control), SetGroup(group=+1) }, SetMods(modifiers=Control) ]
1737+
};
17311738
key <KATA> { [ Katakana ] };
17321739
key <HIRA> { [ Hiragana ] };
17331740
key <HENK> { [ Henkan_Mode ] };

test/data/symbols/awesome

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ xkb_symbols "awesome" {
1919
key <AC01> { [ a, A, Return, Return ] };
2020
key <AC02> { [ s, S, Left] };
2121
key <AC03> { [ d, D, Down] };
22-
key <AC04> { [ f, F, Righ] };
22+
key <AC04> { [ f, F, Right] };
2323
key <AC05> { [ g, G, BackSpace, BackSpace ] };
2424

2525
key <AB05> { [ b, B, Delete, Delete ] };
26+
27+
key <LCTL> {
28+
symbols[1] = [ {Control_L, ISO_Next_Group } ],
29+
actions[1] = [ {SetMods(modifiers=Control), SetGroup(group=+1) } ]
30+
};
2631
};

test/data/symbols/multiple_actions

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
default alphanumeric_keys modifier_keys
2+
xkb_symbols "basic" {
3+
name[1] = "Multiple actions";
4+
5+
virtual_modifiers Alt, Super, LevelThree;
6+
7+
// Multiple keysyms but no actions: OK
8+
key <LCTL> {
9+
symbols[1] = [ { Control_L, ISO_Group_Shift } ]
10+
};
11+
// Multiple actions but no keysyms: OK, but will use NoSymbol
12+
key <RCTL> {
13+
actions[1] = [ { SetMods(modifiers=Control), SetGroup(group=+1) } ]
14+
};
15+
// Multiple keysyms and matching actions
16+
key <LVL3> {
17+
virtualModifiers = LevelThree,
18+
symbols[1] = [ { ISO_Level3_Shift, ISO_Group_Shift } ],
19+
actions[1] = [ { SetMods(modifiers=LevelThree), SetGroup(group=+1) } ]
20+
};
21+
// Multiple actions and matching keysyms
22+
key <MDSW> {
23+
virtualModifiers = LevelThree,
24+
actions[1] = [ { SetMods(modifiers=LevelThree), SetGroup(group=+1) } ],
25+
symbols[1] = [ { ISO_Level3_Shift, ISO_Group_Shift } ]
26+
};
27+
28+
// Incompatible actions and keysyms count: error
29+
key <LALT> {
30+
symbols[1] = [ Alt_L ],
31+
actions[1] = [ { SetMods(modifiers=Alt), SetGroup(group=+1) } ]
32+
};
33+
key <RALT> {
34+
symbols[1] = [ { Alt_R, ISO_Group_Shift } ],
35+
actions[1] = [ SetMods(modifiers=Alt) ]
36+
};
37+
key <LWIN> {
38+
symbols[1] = [ { Super_L, ISO_Group_Shift } ],
39+
actions[1] = [ { SetMods(modifiers=Super), SetGroup(group=+1), NoAction() } ]
40+
};
41+
key <RWIN> {
42+
symbols[1] = [ { Super_R, ISO_Group_Shift , NoSymbol } ],
43+
actions[1] = [ { SetMods(modifiers=Super), SetGroup(group=+1) } ]
44+
};
45+
46+
// Incompatible categories
47+
key <AB11> {
48+
symbols[1] = [ { Control_L, Shift_L } ]
49+
};
50+
modifier_map Control { <AB11> };
51+
key <AE13> {
52+
symbols[1] = [ { Control_L, Shift_L } ],
53+
actions[1] = [ { SetMods(modifiers=Control), SetMods(modifiers=Shift) } ]
54+
};
55+
56+
// Various overrides, different keysyms, no explicit actions
57+
key <AB01> { [ x ] };
58+
key <AB01> { [ { Control_L, ISO_Group_Shift } ] };
59+
60+
key <AB02> { [ { Control_L, ISO_Group_Shift } ] };
61+
key <AB02> { [ x ] };
62+
63+
// Various overrides, no keysyms, explicit actions
64+
key <AB03> { actions[1] = [ SetMods(modifiers=LevelThree) ] };
65+
key <AB03> { actions[1] = [ { SetMods(modifiers=LevelThree), SetGroup(group=+1) } ] };
66+
67+
key <AB04> { actions[1] = [ { SetMods(modifiers=LevelThree), SetGroup(group=+1) } ] };
68+
key <AB04> { actions[1] = [ SetMods(modifiers=LevelThree) ] };
69+
70+
// Various overrides, different keysyms & actions
71+
key <AB05> {
72+
virtualModifiers = LevelThree,
73+
symbols[1] = [ Control_L ],
74+
actions[1] = [ SetMods(modifiers=Control) ]
75+
};
76+
key <AB05> {
77+
symbols[1] = [ { ISO_Level3_Shift, ISO_Group_Shift } ],
78+
actions[1] = [ { SetMods(modifiers=LevelThree), SetGroup(group=+1) } ]
79+
};
80+
81+
key <AB06> {
82+
virtualModifiers = LevelThree,
83+
symbols[1] = [ { ISO_Level3_Shift, ISO_Group_Shift } ],
84+
actions[1] = [ { SetMods(modifiers=LevelThree), SetGroup(group=+1) } ]
85+
};
86+
key <AB06> {
87+
symbols[1] = [ Control_L ],
88+
actions[1] = [ SetMods(modifiers=Control) ]
89+
};
90+
91+
// Various overrides, same keysyms but different actions
92+
key <AB07> {
93+
virtualModifiers = LevelThree,
94+
symbols[1] = [ { ISO_Level3_Shift, ISO_Group_Shift } ],
95+
actions[1] = [ { SetMods(modifiers=Control), Private(type=254, data="foo") } ]
96+
};
97+
key <AB07> {
98+
symbols[1] = [ { ISO_Level3_Shift, ISO_Group_Shift } ],
99+
actions[1] = [ { SetMods(modifiers=LevelThree), SetGroup(group=+1) } ]
100+
};
101+
102+
// Mix various number of keysyms/actions
103+
key <AC01> {
104+
symbols[1] = [ ISO_Level3_Shift , { ISO_Level3_Shift, ISO_Group_Shift } ]
105+
};
106+
key <AC02> {
107+
actions[1] = [ SetMods(modifiers=LevelThree), { SetMods(modifiers=LevelThree), SetGroup(group=+1) } ]
108+
};
109+
key <AC03> {
110+
symbols[1] = [ ISO_Level3_Shift , { ISO_Level3_Shift, ISO_Group_Shift } ],
111+
actions[1] = [ SetMods(modifiers=LevelThree), { SetMods(modifiers=LevelThree), SetGroup(group=+1) } ]
112+
};
113+
key <AC04> {
114+
symbols[1] = [ { ISO_Level3_Shift, ISO_Group_Shift }, ISO_Level3_Shift ]
115+
};
116+
key <AC05> {
117+
actions[1] = [ { SetMods(modifiers=LevelThree), SetGroup(group=+1) }, SetMods(modifiers=LevelThree) ]
118+
};
119+
key <AC06> {
120+
symbols[1] = [ { ISO_Level3_Shift, ISO_Group_Shift }, ISO_Level3_Shift ],
121+
actions[1] = [ { SetMods(modifiers=LevelThree), SetGroup(group=+1) }, SetMods(modifiers=LevelThree) ]
122+
};
123+
key <AC07> {
124+
symbols[1] = [ ISO_Level3_Shift , { ISO_Level3_Shift, ISO_Group_Shift }, { ISO_Level3_Shift, ISO_Group_Shift } ]
125+
};
126+
key <AC08> {
127+
actions[1] = [ SetMods(modifiers=LevelThree), { SetMods(modifiers=LevelThree), SetGroup(group=+1) }, { SetMods(modifiers=LevelThree), SetGroup(group=+1) } ]
128+
};
129+
key <AC09> {
130+
symbols[1] = [ ISO_Level3_Shift , { ISO_Level3_Shift, ISO_Group_Shift }, { ISO_Level3_Shift, ISO_Group_Shift } ],
131+
actions[1] = [ SetMods(modifiers=LevelThree), { SetMods(modifiers=LevelThree), SetGroup(group=+1) }, { SetMods(modifiers=LevelThree), SetGroup(group=+1) } ]
132+
};
133+
134+
// Using modifier_map (may trigger multiple interprets)
135+
key <AD01> { symbols[1] = [ { a, b } ] };
136+
modifier_map Shift { <AD01> };
137+
138+
// Our only alphanum key ✨
139+
key <AE02> { [ 2, at ] };
140+
};

0 commit comments

Comments
 (0)