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 streq(const char *s1, const char *s2)
56 if (s1 == NULL || s2 == NULL)
58 return strcmp(s1, s2) == 0;
62 test_rules(struct xkb_context *ctx, struct test_data *data)
65 const struct xkb_rule_names rmlvo = {
66 data->rules, data->model, data->layout, data->variant, data->options
68 struct xkb_component_names *kccgst;
70 fprintf(stderr, "\n\nChecking : %s\t%s\t%s\t%s\t%s\n", data->rules,
71 data->model, data->layout, data->variant, data->options);
73 if (data->should_fail)
74 fprintf(stderr, "Expecting: NULL\n");
76 fprintf(stderr, "Expecting: %s\t%s\t%s\t%s\t%s\n", data->keymap,
77 data->keycodes, data->types, data->compat, data->symbols);
79 kccgst = xkb_components_from_rules(ctx, &rmlvo);
81 fprintf(stderr, "Received: NULL\n");
82 return data->should_fail;
85 fprintf(stderr, "Received : %s\t%s\t%s\t%s\t%s\n", kccgst->keymap,
86 kccgst->keycodes, kccgst->types, kccgst->compat, kccgst->symbols);
88 passed = streq(kccgst->keymap, data->keymap) &&
89 streq(kccgst->keycodes, data->keycodes) &&
90 streq(kccgst->types, data->types) &&
91 streq(kccgst->compat, data->compat) &&
92 streq(kccgst->symbols, data->symbols);
95 free(kccgst->keycodes);
98 free(kccgst->symbols);
107 struct xkb_context *ctx;
108 const char *srcdir = getenv("srcdir");
111 ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES);
114 assert(asprintf(&path, "%s/test/data", srcdir ? srcdir : ".") > 0);
115 assert(xkb_context_include_path_append(ctx, path));
118 struct test_data test1 = {
121 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
122 .options = "my_option",
124 .keycodes = "my_keycodes", .types = "my_types",
125 .compat = "my_compat+some:compat",
126 .symbols = "my_symbols+extra_variant",
128 assert(test_rules(ctx, &test1));
130 struct test_data test2 = {
133 .model = "", .layout = "", .variant = "", .options = "",
135 .keycodes = "default_keycodes", .types = "default_types",
136 .compat = "default_compat", .symbols = "default_symbols",
138 assert(test_rules(ctx, &test2));
140 struct test_data test3 = {
143 .model = "pc104", .layout = "foo", .variant = "", .options = "",
145 .keycodes = "something(pc104)", .types = "default_types",
146 .compat = "default_compat", .symbols = "default_symbols",
148 assert(test_rules(ctx, &test3));
150 struct test_data test4 = {
153 .model = "foo", .layout = "ar", .variant = "bar", .options = "",
155 .keycodes = "default_keycodes", .types = "default_types",
156 .compat = "default_compat", .symbols = "my_symbols+(bar)",
158 assert(test_rules(ctx, &test4));
160 struct test_data test5 = {
163 .model = NULL, .layout = "my_layout,second_layout", .variant = "my_variant",
164 .options = "my_option",
168 assert(test_rules(ctx, &test5));
170 struct test_data test6 = {
173 .model = "", .layout = "br,al,cn,az", .variant = "",
174 .options = "some:opt",
176 .keycodes = "default_keycodes", .types = "default_types",
177 .compat = "default_compat",
178 .symbols = "default_symbols+extra:1+extra:2+extra:3+extra:4",
180 assert(test_rules(ctx, &test6));
182 xkb_context_unref(ctx);