2 * Copyright © 2009 Daniel Stone
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.
23 * Author: Daniel Stone <daniel@fooishbar.org>
31 #include "xkbcommon/xkbcommon.h"
35 struct xkb_component_names new;
36 struct xkb_component_names old;
38 const char *exp_keycodes;
39 const char *exp_compat;
40 const char *exp_symbols;
41 const char *exp_types;
44 static struct test_data *
47 return calloc(1, sizeof(struct test_data));
51 free_data(struct test_data *data)
53 free(data->new.keycodes);
54 free(data->new.compat);
55 free(data->new.symbols);
56 free(data->new.types);
57 free(data->old.keycodes);
58 free(data->old.compat);
59 free(data->old.symbols);
60 free(data->old.types);
65 set_new(struct test_data *data, const char *keycodes, const char *compat,
66 const char *symbols, const char *types)
68 data->new.keycodes = strdup(keycodes);
69 data->new.compat = strdup(compat);
70 data->new.symbols = strdup(symbols);
71 data->new.types = strdup(types);
75 set_old(struct test_data *data, const char *keycodes, const char *compat,
76 const char *symbols, const char *types)
78 data->old.keycodes = strdup(keycodes);
79 data->old.compat = strdup(compat);
80 data->old.symbols = strdup(symbols);
81 data->old.types = strdup(types);
86 set_exp(struct test_data *data, const char *keycodes, const char *compat,
87 const char *symbols, const char *types)
89 data->exp_keycodes = keycodes;
90 data->exp_compat = compat;
91 data->exp_symbols = symbols;
92 data->exp_types = types;
96 test_canonicalise(struct test_data *data)
98 fprintf(stderr, "New: %s %s %s %s\n", data->new.keycodes,
99 data->new.compat, data->new.symbols, data->new.types);
101 fprintf(stderr, "Old: %s %s %s %s\n", data->old.keycodes,
102 data->old.compat, data->old.symbols, data->old.types);
103 fprintf(stderr, "Expected: %s %s %s %s\n", data->exp_keycodes,
104 data->exp_compat, data->exp_symbols, data->exp_types);
107 xkb_canonicalise_components(&data->new, &data->old);
109 xkb_canonicalise_components(&data->new, NULL);
111 fprintf(stderr, "Received: %s %s %s %s\n\n", data->new.keycodes,
112 data->new.compat, data->new.symbols, data->new.types);
114 return (strcmp(data->new.keycodes, data->exp_keycodes) == 0) &&
115 (strcmp(data->new.compat, data->exp_compat) == 0) &&
116 (strcmp(data->new.symbols, data->exp_symbols) == 0) &&
117 (strcmp(data->new.types, data->exp_types) == 0);
123 struct test_data *twopart, *onepart;
125 twopart = new_data();
126 set_new(twopart, "+inet(pc104)", "%+complete", "pc(pc104)+%+ctrl(nocaps)", "|complete");
127 set_old(twopart, "xfree86", "basic", "us(dvorak)", "xfree86");
128 set_exp(twopart, "xfree86+inet(pc104)", "basic+complete", "pc(pc104)+us(dvorak)+ctrl(nocaps)", "xfree86|complete");
129 assert(test_canonicalise(twopart));
132 onepart = new_data();
133 set_new(onepart, "evdev", "complete", "pc(pc104)+us+compose(ralt)", "complete");
134 set_exp(onepart, "evdev", "complete", "pc(pc104)+us+compose(ralt)", "complete");
135 assert(test_canonicalise(onepart));