Hash :
3150bca8
Author :
Date :
2025-03-30T09:54:02
xkbcomp: Make all components optional
We already accept *empty* components, such as: `xkb_compat {};`. Let’s
accept missing components as well, so that we can reduce the boilerplate
in our tests.
Note that we will still explicitly serialize empty components for
compatibility with previous xkbcommon versions and Xorg xkbcomp.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
/*
* Copyright © 2009 Dan Nicholson
* SPDX-License-Identifier: MIT
*/
#include "config.h"
#include "test.h"
static int
test_file(struct xkb_context *ctx, const char *path_rel)
{
struct xkb_keymap *keymap = test_compile_file(ctx, path_rel);
if (!keymap)
return 0;
xkb_keymap_unref(keymap);
return 1;
}
int
main(void)
{
test_init();
struct xkb_context *ctx = test_get_context(0);
assert(test_file(ctx, "keymaps/basic.xkb"));
assert(test_file(ctx, "keymaps/comprehensive-plus-geom.xkb"));
assert(test_file(ctx, "keymaps/no-types.xkb"));
assert(test_file(ctx, "keymaps/quartz.xkb"));
assert(test_file(ctx, "keymaps/no-aliases.xkb"));
assert(test_file(ctx, "keymaps/modmap-none.xkb"));
assert(test_file(ctx, "keymaps/invalid-escape-sequence.xkb"));
assert(!test_file(ctx, "keymaps/divide-by-zero.xkb"));
assert(!test_file(ctx, "keymaps/syntax-error.xkb"));
assert(!test_file(ctx, "keymaps/syntax-error2.xkb"));
assert(!test_file(ctx, "keymaps/empty-symbol-decl.xkb"));
assert(!test_file(ctx, "keymaps/invalid-qualified-type-field.xkb"));
assert(!test_file(ctx, "keymaps/invalid-qualified-symbols-field.xkb"));
assert(!test_file(ctx, "does not exist"));
/* Test response to invalid flags and formats. */
fclose(stdin);
assert(!xkb_keymap_new_from_file(ctx, NULL, XKB_KEYMAP_FORMAT_TEXT_V1, 0));
assert(!xkb_keymap_new_from_file(ctx, stdin, 0, 0));
assert(!xkb_keymap_new_from_file(ctx, stdin, XKB_KEYMAP_USE_ORIGINAL_FORMAT, 0));
assert(!xkb_keymap_new_from_file(ctx, stdin, 1234, 0));
assert(!xkb_keymap_new_from_file(ctx, stdin, XKB_KEYMAP_FORMAT_TEXT_V1, -1));
assert(!xkb_keymap_new_from_file(ctx, stdin, XKB_KEYMAP_FORMAT_TEXT_V1, 1234));
xkb_context_unref(ctx);
return 0;
}