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.
25 #include "xkbcomp-priv.h"
44 /* Or set this if xkb_components_from_rules() should fail. */
49 test_rules(struct xkb_context *ctx, struct test_data *data)
52 const struct xkb_rule_names rmlvo = {
53 data->rules, data->model, data->layout, data->variant, data->options
55 struct xkb_component_names kccgst;
57 fprintf(stderr, "\n\nChecking : %s\t%s\t%s\t%s\t%s\n", data->rules,
58 data->model, data->layout, data->variant, data->options);
60 if (data->should_fail)
61 fprintf(stderr, "Expecting: FAILURE\n");
63 fprintf(stderr, "Expecting: %s\t%s\t%s\t%s\n",
64 data->keycodes, data->types, data->compat, data->symbols);
66 if (!xkb_components_from_rules(ctx, &rmlvo, &kccgst)) {
67 fprintf(stderr, "Received : FAILURE\n");
68 return data->should_fail;
71 fprintf(stderr, "Received : %s\t%s\t%s\t%s\n",
72 kccgst.keycodes, kccgst.types, kccgst.compat, kccgst.symbols);
74 passed = streq(kccgst.keycodes, data->keycodes) &&
75 streq(kccgst.types, data->types) &&
76 streq(kccgst.compat, data->compat) &&
77 streq(kccgst.symbols, data->symbols);
79 free(kccgst.keycodes);
88 main(int argc, char *argv[])
90 struct xkb_context *ctx;
92 ctx = test_get_context(0);
95 struct test_data test1 = {
98 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
99 .options = "my_option",
101 .keycodes = "my_keycodes", .types = "my_types",
102 .compat = "my_compat|some:compat",
103 .symbols = "my_symbols+extra_variant",
105 assert(test_rules(ctx, &test1));
107 struct test_data test2 = {
110 .model = "", .layout = "", .variant = "", .options = "",
112 .keycodes = "default_keycodes", .types = "default_types",
113 .compat = "default_compat", .symbols = "default_symbols",
115 assert(test_rules(ctx, &test2));
117 struct test_data test3 = {
120 .model = "pc104", .layout = "foo", .variant = "", .options = "",
122 .keycodes = "something(pc104)", .types = "default_types",
123 .compat = "default_compat", .symbols = "default_symbols",
125 assert(test_rules(ctx, &test3));
127 struct test_data test4 = {
130 .model = "foo", .layout = "ar", .variant = "bar", .options = "",
132 .keycodes = "default_keycodes", .types = "default_types",
133 .compat = "default_compat", .symbols = "my_symbols+(bar)",
135 assert(test_rules(ctx, &test4));
137 struct test_data test5 = {
140 .model = NULL, .layout = "my_layout,second_layout", .variant = "my_variant",
141 .options = "my_option",
145 assert(test_rules(ctx, &test5));
147 struct test_data test6 = {
150 .model = "", .layout = "br,al,cn,az", .variant = "",
151 .options = "some:opt",
153 .keycodes = "default_keycodes", .types = "default_types",
154 .compat = "default_compat",
155 .symbols = "default_symbols+extra:1+extra:2+extra:3+extra:4",
157 assert(test_rules(ctx, &test6));
159 struct test_data test7 = {
160 .rules = "multiple-options",
162 .model = "my_model", .layout = "my_layout", .variant = "my_variant",
163 .options = "option3,option1,colon:opt,option11",
165 .keycodes = "my_keycodes", .types = "my_types",
166 .compat = "my_compat+some:compat+group(bla)",
167 .symbols = "my_symbols+extra_variant+compose(foo)+keypad(bar)+altwin(menu)",
169 assert(test_rules(ctx, &test7));
171 xkb_context_unref(ctx);