| 1 |
/* |
| 2 |
* Copyright © 2009 Dan Nicholson |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "config.h" |
| 7 |
|
| 8 |
#include "test.h" |
| 9 |
#include "xkbcommon/xkbcommon.h" |
| 10 |
|
| 11 |
static int |
| 12 |
test_file(struct xkb_context *ctx, const char *path_rel) |
| 13 |
{ |
| 14 |
struct xkb_keymap *keymap = |
| 15 |
test_compile_file( ctx, XKB_KEYMAP_FORMAT_TEXT_V1, path_rel); |
| 16 |
|
| 17 |
if (!keymap) |
| 18 |
return 0; |
| 19 |
|
| 20 |
xkb_keymap_unref(keymap); |
| 21 |
return 1; |
| 22 |
} |
| 23 |
|
| 24 |
int |
| 25 |
main(void) |
| 26 |
{ |
| 27 |
test_init(); |
| 28 |
|
| 29 |
struct xkb_context *ctx = test_get_context(0); |
| 30 |
|
| 31 |
assert(test_file(ctx, "keymaps/basic.xkb")); |
| 32 |
assert(test_file(ctx, "keymaps/comprehensive-plus-geom.xkb")); |
| 33 |
assert(test_file(ctx, "keymaps/no-types.xkb")); |
| 34 |
assert(test_file(ctx, "keymaps/quartz.xkb")); |
| 35 |
assert(test_file(ctx, "keymaps/no-aliases.xkb")); |
| 36 |
assert(test_file(ctx, "keymaps/modmap-none.xkb")); |
| 37 |
assert(test_file(ctx, "keymaps/invalid-escape-sequence.xkb")); |
| 38 |
|
| 39 |
assert(!test_file(ctx, "keymaps/divide-by-zero.xkb")); |
| 40 |
assert(!test_file(ctx, "keymaps/syntax-error.xkb")); |
| 41 |
assert(!test_file(ctx, "keymaps/syntax-error2.xkb")); |
| 42 |
assert(!test_file(ctx, "keymaps/empty-symbol-decl.xkb")); |
| 43 |
assert(!test_file(ctx, "keymaps/invalid-qualified-type-field.xkb")); |
| 44 |
assert(!test_file(ctx, "keymaps/invalid-qualified-symbols-field.xkb")); |
| 45 |
assert(!test_file(ctx, "does not exist")); |
| 46 |
|
| 47 |
/* Test response to invalid flags and formats. */ |
| 48 |
fclose(stdin); |
| 49 |
assert(!xkb_keymap_new_from_file(ctx, NULL, XKB_KEYMAP_FORMAT_TEXT_V1, 0)); |
| 50 |
assert(!xkb_keymap_new_from_file(ctx, stdin, 0, 0)); |
| 51 |
assert(!xkb_keymap_new_from_file(ctx, stdin, XKB_KEYMAP_USE_ORIGINAL_FORMAT, 0)); |
| 52 |
assert(!xkb_keymap_new_from_file(ctx, stdin, 1234, 0)); |
| 53 |
assert(!xkb_keymap_new_from_file(ctx, stdin, XKB_KEYMAP_FORMAT_TEXT_V1, -1)); |
| 54 |
assert(!xkb_keymap_new_from_file(ctx, stdin, XKB_KEYMAP_FORMAT_TEXT_V1, 1234)); |
| 55 |
|
| 56 |
xkb_context_unref(ctx); |
| 57 |
|
| 58 |
return 0; |
| 59 |
} |