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\n",
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\n",
86 kccgst->keycodes, kccgst->types, kccgst->compat, kccgst->symbols);
88 passed = streq(kccgst->keycodes, data->keycodes) &&
89 streq(kccgst->types, data->types) &&
90 streq(kccgst->compat, data->compat) &&
91 streq(kccgst->symbols, data->symbols);
93 free(kccgst->keycodes);
96 free(kccgst->symbols);
105 struct xkb_context *ctx;
106 const char *srcdir = getenv("srcdir");
109 ctx = xkb_context_new(XKB_CONTEXT_NO_DEFAULT_INCLUDES);
112 assert(asprintf(&path, "%s/test/data", srcdir ? srcdir : ".") > 0);
113 assert(xkb_context_include_path_append(ctx, test_get_path("")));
116 struct test_data test1 = {
119 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
120 .options = "my_option",
122 .keycodes = "my_keycodes", .types = "my_types",
123 .compat = "my_compat+some:compat",
124 .symbols = "my_symbols+extra_variant",
126 assert(test_rules(ctx, &test1));
128 struct test_data test2 = {
131 .model = "", .layout = "", .variant = "", .options = "",
133 .keycodes = "default_keycodes", .types = "default_types",
134 .compat = "default_compat", .symbols = "default_symbols",
136 assert(test_rules(ctx, &test2));
138 struct test_data test3 = {
141 .model = "pc104", .layout = "foo", .variant = "", .options = "",
143 .keycodes = "something(pc104)", .types = "default_types",
144 .compat = "default_compat", .symbols = "default_symbols",
146 assert(test_rules(ctx, &test3));
148 struct test_data test4 = {
151 .model = "foo", .layout = "ar", .variant = "bar", .options = "",
153 .keycodes = "default_keycodes", .types = "default_types",
154 .compat = "default_compat", .symbols = "my_symbols+(bar)",
156 assert(test_rules(ctx, &test4));
158 struct test_data test5 = {
161 .model = NULL, .layout = "my_layout,second_layout", .variant = "my_variant",
162 .options = "my_option",
166 assert(test_rules(ctx, &test5));
168 struct test_data test6 = {
171 .model = "", .layout = "br,al,cn,az", .variant = "",
172 .options = "some:opt",
174 .keycodes = "default_keycodes", .types = "default_types",
175 .compat = "default_compat",
176 .symbols = "default_symbols+extra:1+extra:2+extra:3+extra:4",
178 assert(test_rules(ctx, &test6));
180 struct test_data test7 = {
181 .rules = "multiple-options",
183 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
184 .options = "option3,option1,colon:opt,option11",
186 .keycodes = "my_keycodes", .types = "my_types",
187 .compat = "my_compat+some:compat+group(bla)",
188 .symbols = "my_symbols+extra_variant+compose(foo)+keypad(bar)+altwin(menu)",
190 assert(test_rules(ctx, &test7));
192 xkb_context_unref(ctx);