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.
27 #include "xkbcomp/xkbcomp-priv.h"
28 #include "xkbcomp/rules.h"
46 /* Or set this if xkb_components_from_rules() should fail. */
51 test_rules(struct xkb_context *ctx, struct test_data *data)
54 const struct xkb_rule_names rmlvo = {
55 data->rules, data->model, data->layout, data->variant, data->options
57 struct xkb_component_names kccgst;
59 fprintf(stderr, "\n\nChecking : %s\t%s\t%s\t%s\t%s\n", data->rules,
60 data->model, data->layout, data->variant, data->options);
62 if (data->should_fail)
63 fprintf(stderr, "Expecting: FAILURE\n");
65 fprintf(stderr, "Expecting: %s\t%s\t%s\t%s\n",
66 data->keycodes, data->types, data->compat, data->symbols);
68 if (!xkb_components_from_rules(ctx, &rmlvo, &kccgst)) {
69 fprintf(stderr, "Received : FAILURE\n");
70 return data->should_fail;
73 fprintf(stderr, "Received : %s\t%s\t%s\t%s\n",
74 kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
76 passed = streq(kccgst.keycodes, data->keycodes) &&
77 streq(kccgst.types, data->types) &&
78 streq(kccgst.compat, data->compat) &&
79 streq(kccgst.symbols, data->symbols);
81 free(kccgst.keycodes);
90 main(int argc, char *argv[])
92 struct xkb_context *ctx;
94 ctx = test_get_context(0);
97 struct test_data test1 = {
100 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
101 .options = "my_option",
103 .keycodes = "my_keycodes", .types = "my_types",
104 .compat = "my_compat|some:compat",
105 .symbols = "my_symbols+extra_variant",
107 assert(test_rules(ctx, &test1));
109 struct test_data test2 = {
112 .model = "", .layout = "", .variant = "", .options = "",
114 .keycodes = "default_keycodes", .types = "default_types",
115 .compat = "default_compat", .symbols = "default_symbols",
117 assert(test_rules(ctx, &test2));
119 struct test_data test3 = {
122 .model = "pc104", .layout = "foo", .variant = "", .options = "",
124 .keycodes = "something(pc104)", .types = "default_types",
125 .compat = "default_compat", .symbols = "default_symbols",
127 assert(test_rules(ctx, &test3));
129 struct test_data test4 = {
132 .model = "foo", .layout = "ar", .variant = "bar", .options = "",
134 .keycodes = "default_keycodes", .types = "default_types",
135 .compat = "default_compat", .symbols = "my_symbols+(bar)",
137 assert(test_rules(ctx, &test4));
139 struct test_data test5 = {
142 .model = NULL, .layout = "my_layout,second_layout", .variant = "my_variant",
143 .options = "my_option",
147 assert(test_rules(ctx, &test5));
149 struct test_data test6 = {
152 .model = "", .layout = "br,al,cn,az", .variant = "",
153 .options = "some:opt",
155 .keycodes = "default_keycodes", .types = "default_types",
156 .compat = "default_compat",
157 .symbols = "default_symbols+extra:1+extra:2+extra:3+extra:4",
159 assert(test_rules(ctx, &test6));
161 struct test_data test7 = {
162 .rules = "multiple-options",
164 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
165 .options = "option3,option1,colon:opt,option11",
167 .keycodes = "my_keycodes", .types = "my_types",
168 .compat = "my_compat+some:compat+group(bla)",
169 .symbols = "my_symbols+extra_variant+compose(foo)+keypad(bar)+altwin(menu)",
171 assert(test_rules(ctx, &test7));
173 xkb_context_unref(ctx);