@@ -161,62 +161,104 @@ test_recursive(struct xkb_context *ctx)
161161 }
162162}
163163
164+ /* Test various multi-{keysym,action} syntaxes */
164165static 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
211253int
212254main (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
0 commit comments