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.
26 #include "test-config.h"
29 #include "xkbcomp/xkbcomp-priv.h"
30 #include "xkbcomp/rules.h"
48 /* Or set this if xkb_components_from_rules() should fail. */
53 test_rules(struct xkb_context *ctx, struct test_data *data)
56 const struct xkb_rule_names rmlvo = {
57 data->rules, data->model, data->layout, data->variant, data->options
59 struct xkb_component_names kccgst;
61 fprintf(stderr, "\n\nChecking : %s\t%s\t%s\t%s\t%s\n", data->rules,
62 data->model, data->layout, data->variant, data->options);
64 if (data->should_fail)
65 fprintf(stderr, "Expecting: FAILURE\n");
67 fprintf(stderr, "Expecting: %s\t%s\t%s\t%s\n",
68 data->keycodes, data->types, data->compat, data->symbols);
70 if (!xkb_components_from_rules(ctx, &rmlvo, &kccgst)) {
71 fprintf(stderr, "Received : FAILURE\n");
72 return data->should_fail;
75 fprintf(stderr, "Received : %s\t%s\t%s\t%s\n",
76 kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
78 passed = streq(kccgst.keycodes, data->keycodes) &&
79 streq(kccgst.types, data->types) &&
80 streq(kccgst.compat, data->compat) &&
81 streq(kccgst.symbols, data->symbols);
83 free(kccgst.keycodes);
92 main(int argc, char *argv[])
94 struct xkb_context *ctx;
96 setenv("XKB_CONFIG_ROOT", TEST_XKB_CONFIG_ROOT, 1);
98 ctx = test_get_context(0);
101 struct test_data test1 = {
102 .rules = "inc-src-simple",
104 .model = "my_model", .layout = "my_layout", .variant = "", .options = "",
106 .keycodes = "my_keycodes", .types = "default_types",
107 .compat = "default_compat", .symbols = "my_symbols",
109 assert(test_rules(ctx, &test1));
111 struct test_data test2 = {
112 .rules = "inc-src-nested",
114 .model = "my_model", .layout = "my_layout", .variant = "", .options = "",
116 .keycodes = "my_keycodes", .types = "default_types",
117 .compat = "default_compat", .symbols = "my_symbols",
119 assert(test_rules(ctx, &test2));
121 struct test_data test3 = {
122 .rules = "inc-src-looped",
124 .model = "my_model", .layout = "my_layout", .variant = "", .options = "",
128 assert(test_rules(ctx, &test3));
130 struct test_data test4 = {
131 .rules = "inc-src-before-after",
133 .model = "before_model", .layout = "my_layout", .variant = "", .options = "",
135 .keycodes = "my_keycodes", .types = "default_types",
136 .compat = "default_compat", .symbols = "default_symbols",
138 assert(test_rules(ctx, &test4));
140 struct test_data test5 = {
141 .rules = "inc-src-options",
143 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
144 .options = "option11,my_option,colon:opt,option111",
146 .keycodes = "my_keycodes", .types = "default_types",
147 .compat = "default_compat+substring+group(bla)|some:compat",
148 .symbols = "my_symbols+extra_variant+altwin(menu)",
150 assert(test_rules(ctx, &test5));
152 struct test_data test6 = {
153 .rules = "inc-src-loop-twice",
155 .model = "my_model", .layout = "my_layout", .variant = "", .options = "",
157 .keycodes = "my_keycodes", .types = "default_types",
158 .compat = "default_compat", .symbols = "my_symbols",
160 assert(test_rules(ctx, &test6));
162 xkb_context_unref(ctx);