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"
48 /* Or set this if xkb_components_from_rules() should fail. */
53 streq(const char *s1, const char *s2)
55 if (s1 == NULL || s2 == NULL)
57 return strcmp(s1, s2) == 0;
61 test_rules(struct xkb_context *ctx, struct test_data *data)
64 const struct xkb_rule_names rmlvo = {
65 data->rules, data->model, data->layout, data->variant, data->options
67 struct xkb_component_names *kccgst;
69 fprintf(stderr, "\n\nChecking : %s\t%s\t%s\t%s\t%s\n", data->rules,
70 data->model, data->layout, data->variant, data->options);
72 if (data->should_fail)
73 fprintf(stderr, "Expecting: NULL\n");
75 fprintf(stderr, "Expecting: %s\t%s\t%s\t%s\n",
76 data->keycodes, data->types, data->compat, data->symbols);
78 kccgst = xkb_components_from_rules(ctx, &rmlvo);
80 fprintf(stderr, "Received: NULL\n");
81 return data->should_fail;
84 fprintf(stderr, "Received : %s\t%s\t%s\t%s\n",
85 kccgst->keycodes, kccgst->types, kccgst->compat, kccgst->symbols);
87 passed = streq(kccgst->keycodes, data->keycodes) &&
88 streq(kccgst->types, data->types) &&
89 streq(kccgst->compat, data->compat) &&
90 streq(kccgst->symbols, data->symbols);
92 free(kccgst->keycodes);
95 free(kccgst->symbols);
104 struct xkb_context *ctx;
105 const char *srcdir = getenv("srcdir");
108 ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES);
111 assert(asprintf(&path, "%s/test/data", srcdir ? srcdir : ".") > 0);
112 assert(xkb_context_include_path_append(ctx, path));
115 struct test_data test1 = {
118 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
119 .options = "my_option",
121 .keycodes = "my_keycodes", .types = "my_types",
122 .compat = "my_compat+some:compat",
123 .symbols = "my_symbols+extra_variant",
125 assert(test_rules(ctx, &test1));
127 struct test_data test2 = {
130 .model = "", .layout = "", .variant = "", .options = "",
132 .keycodes = "default_keycodes", .types = "default_types",
133 .compat = "default_compat", .symbols = "default_symbols",
135 assert(test_rules(ctx, &test2));
137 struct test_data test3 = {
140 .model = "pc104", .layout = "foo", .variant = "", .options = "",
142 .keycodes = "something(pc104)", .types = "default_types",
143 .compat = "default_compat", .symbols = "default_symbols",
145 assert(test_rules(ctx, &test3));
147 struct test_data test4 = {
150 .model = "foo", .layout = "ar", .variant = "bar", .options = "",
152 .keycodes = "default_keycodes", .types = "default_types",
153 .compat = "default_compat", .symbols = "my_symbols+(bar)",
155 assert(test_rules(ctx, &test4));
157 struct test_data test5 = {
160 .model = NULL, .layout = "my_layout,second_layout", .variant = "my_variant",
161 .options = "my_option",
165 assert(test_rules(ctx, &test5));
167 struct test_data test6 = {
170 .model = "", .layout = "br,al,cn,az", .variant = "",
171 .options = "some:opt",
173 .keycodes = "default_keycodes", .types = "default_types",
174 .compat = "default_compat",
175 .symbols = "default_symbols+extra:1+extra:2+extra:3+extra:4",
177 assert(test_rules(ctx, &test6));
179 struct test_data test7 = {
180 .rules = "multiple-options",
182 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
183 .options = "option3,option1,colon:opt,option11",
185 .keycodes = "my_keycodes", .types = "my_types",
186 .compat = "my_compat+some:compat+group(bla)",
187 .symbols = "my_symbols+extra_variant+compose(foo)+keypad(bar)+altwin(menu)",
189 assert(test_rules(ctx, &test7));
191 xkb_context_unref(ctx);