2 * Copyright © 2012 Ran Benita <ran234@gmail.com>
3 * Copyright © 2019 Red Hat, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 #include "test-config.h"
28 #include "xkbcomp/xkbcomp-priv.h"
29 #include "xkbcomp/rules.h"
47 /* Or set this if xkb_components_from_rules() should fail. */
52 test_rules(struct xkb_context *ctx, struct test_data *data)
55 const struct xkb_rule_names rmlvo = {
56 data->rules, data->model, data->layout, data->variant, data->options
58 struct xkb_component_names kccgst;
60 fprintf(stderr, "\n\nChecking : %s\t%s\t%s\t%s\t%s\n", data->rules,
61 data->model, data->layout, data->variant, data->options);
63 if (data->should_fail)
64 fprintf(stderr, "Expecting: FAILURE\n");
66 fprintf(stderr, "Expecting: %s\t%s\t%s\t%s\n",
67 data->keycodes, data->types, data->compat, data->symbols);
69 if (!xkb_components_from_rules(ctx, &rmlvo, &kccgst)) {
70 fprintf(stderr, "Received : FAILURE\n");
71 return data->should_fail;
74 fprintf(stderr, "Received : %s\t%s\t%s\t%s\n",
75 kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
77 passed = streq(kccgst.keycodes, data->keycodes) &&
78 streq(kccgst.types, data->types) &&
79 streq(kccgst.compat, data->compat) &&
80 streq(kccgst.symbols, data->symbols);
82 free(kccgst.keycodes);
91 main(int argc, char *argv[])
93 struct xkb_context *ctx;
95 setenv("XKB_CONFIG_ROOT", TEST_XKB_CONFIG_ROOT, 1);
97 ctx = test_get_context(0);
100 struct test_data test1 = {
101 .rules = "inc-src-simple",
103 .model = "my_model", .layout = "my_layout", .variant = "", .options = "",
105 .keycodes = "my_keycodes", .types = "default_types",
106 .compat = "default_compat", .symbols = "my_symbols",
108 assert(test_rules(ctx, &test1));
110 struct test_data test2 = {
111 .rules = "inc-src-nested",
113 .model = "my_model", .layout = "my_layout", .variant = "", .options = "",
115 .keycodes = "my_keycodes", .types = "default_types",
116 .compat = "default_compat", .symbols = "my_symbols",
118 assert(test_rules(ctx, &test2));
120 struct test_data test3 = {
121 .rules = "inc-src-looped",
123 .model = "my_model", .layout = "my_layout", .variant = "", .options = "",
127 assert(test_rules(ctx, &test3));
129 struct test_data test4 = {
130 .rules = "inc-src-before-after",
132 .model = "before_model", .layout = "my_layout", .variant = "", .options = "",
134 .keycodes = "my_keycodes", .types = "default_types",
135 .compat = "default_compat", .symbols = "default_symbols",
137 assert(test_rules(ctx, &test4));
139 struct test_data test5 = {
140 .rules = "inc-src-options",
142 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
143 .options = "option11,my_option,colon:opt,option111",
145 .keycodes = "my_keycodes", .types = "default_types",
146 .compat = "default_compat+substring+group(bla)|some:compat",
147 .symbols = "my_symbols+extra_variant+altwin(menu)",
149 assert(test_rules(ctx, &test5));
151 struct test_data test6 = {
152 .rules = "inc-src-loop-twice",
154 .model = "my_model", .layout = "my_layout", .variant = "", .options = "",
156 .keycodes = "my_keycodes", .types = "default_types",
157 .compat = "default_compat", .symbols = "my_symbols",
159 assert(test_rules(ctx, &test6));
161 xkb_context_unref(ctx);