2 * Copyright © 2012 Ran Benita <ran234@gmail.com>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
29 #include "xkbcommon/xkbcommon.h"
49 /* Or set this if xkb_components_from_rules() should fail. */
54 test_rules(struct xkb_context *ctx, struct test_data *data)
57 const struct xkb_rule_names rmlvo = {
58 data->rules, data->model, data->layout, data->variant, data->options
60 struct xkb_component_names *kccgst;
62 fprintf(stderr, "\n\nChecking : %s\t%s\t%s\t%s\t%s\n", data->rules,
63 data->model, data->layout, data->variant, data->options);
65 if (data->should_fail)
66 fprintf(stderr, "Expecting: NULL\n");
68 fprintf(stderr, "Expecting: %s\t%s\t%s\t%s\n",
69 data->keycodes, data->types, data->compat, data->symbols);
71 kccgst = xkb_components_from_rules(ctx, &rmlvo);
73 fprintf(stderr, "Received: NULL\n");
74 return data->should_fail;
77 fprintf(stderr, "Received : %s\t%s\t%s\t%s\n",
78 kccgst->keycodes, kccgst->types, kccgst->compat, kccgst->symbols);
80 passed = streq(kccgst->keycodes, data->keycodes) &&
81 streq(kccgst->types, data->types) &&
82 streq(kccgst->compat, data->compat) &&
83 streq(kccgst->symbols, data->symbols);
85 free(kccgst->keycodes);
88 free(kccgst->symbols);
97 struct xkb_context *ctx;
98 const char *srcdir = getenv("srcdir");
101 ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES);
104 assert(asprintf(&path, "%s/test/data", srcdir ? srcdir : ".") > 0);
105 assert(xkb_context_include_path_append(ctx, test_get_path("")));
108 struct test_data test1 = {
111 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
112 .options = "my_option",
114 .keycodes = "my_keycodes", .types = "my_types",
115 .compat = "my_compat+some:compat",
116 .symbols = "my_symbols+extra_variant",
118 assert(test_rules(ctx, &test1));
120 struct test_data test2 = {
123 .model = "", .layout = "", .variant = "", .options = "",
125 .keycodes = "default_keycodes", .types = "default_types",
126 .compat = "default_compat", .symbols = "default_symbols",
128 assert(test_rules(ctx, &test2));
130 struct test_data test3 = {
133 .model = "pc104", .layout = "foo", .variant = "", .options = "",
135 .keycodes = "something(pc104)", .types = "default_types",
136 .compat = "default_compat", .symbols = "default_symbols",
138 assert(test_rules(ctx, &test3));
140 struct test_data test4 = {
143 .model = "foo", .layout = "ar", .variant = "bar", .options = "",
145 .keycodes = "default_keycodes", .types = "default_types",
146 .compat = "default_compat", .symbols = "my_symbols+(bar)",
148 assert(test_rules(ctx, &test4));
150 struct test_data test5 = {
153 .model = NULL, .layout = "my_layout,second_layout", .variant = "my_variant",
154 .options = "my_option",
158 assert(test_rules(ctx, &test5));
160 struct test_data test6 = {
163 .model = "", .layout = "br,al,cn,az", .variant = "",
164 .options = "some:opt",
166 .keycodes = "default_keycodes", .types = "default_types",
167 .compat = "default_compat",
168 .symbols = "default_symbols+extra:1+extra:2+extra:3+extra:4",
170 assert(test_rules(ctx, &test6));
172 struct test_data test7 = {
173 .rules = "multiple-options",
175 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
176 .options = "option3,option1,colon:opt,option11",
178 .keycodes = "my_keycodes", .types = "my_types",
179 .compat = "my_compat+some:compat+group(bla)",
180 .symbols = "my_symbols+extra_variant+compose(foo)+keypad(bar)+altwin(menu)",
182 assert(test_rules(ctx, &test7));
184 xkb_context_unref(ctx);