xref: /aosp_15_r20/external/libxkbcommon/test/compose.c (revision 2b949d0487e80d67f1fda82db69e101e761f8064)
1*2b949d04SAndroid Build Coastguard Worker /*
2*2b949d04SAndroid Build Coastguard Worker  * Copyright © 2014 Ran Benita <[email protected]>
3*2b949d04SAndroid Build Coastguard Worker  *
4*2b949d04SAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a
5*2b949d04SAndroid Build Coastguard Worker  * copy of this software and associated documentation files (the "Software"),
6*2b949d04SAndroid Build Coastguard Worker  * to deal in the Software without restriction, including without limitation
7*2b949d04SAndroid Build Coastguard Worker  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*2b949d04SAndroid Build Coastguard Worker  * and/or sell copies of the Software, and to permit persons to whom the
9*2b949d04SAndroid Build Coastguard Worker  * Software is furnished to do so, subject to the following conditions:
10*2b949d04SAndroid Build Coastguard Worker  *
11*2b949d04SAndroid Build Coastguard Worker  * The above copyright notice and this permission notice (including the next
12*2b949d04SAndroid Build Coastguard Worker  * paragraph) shall be included in all copies or substantial portions of the
13*2b949d04SAndroid Build Coastguard Worker  * Software.
14*2b949d04SAndroid Build Coastguard Worker  *
15*2b949d04SAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*2b949d04SAndroid Build Coastguard Worker  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*2b949d04SAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*2b949d04SAndroid Build Coastguard Worker  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*2b949d04SAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*2b949d04SAndroid Build Coastguard Worker  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*2b949d04SAndroid Build Coastguard Worker  * DEALINGS IN THE SOFTWARE.
22*2b949d04SAndroid Build Coastguard Worker  */
23*2b949d04SAndroid Build Coastguard Worker 
24*2b949d04SAndroid Build Coastguard Worker #include "config.h"
25*2b949d04SAndroid Build Coastguard Worker 
26*2b949d04SAndroid Build Coastguard Worker #include "xkbcommon/xkbcommon-compose.h"
27*2b949d04SAndroid Build Coastguard Worker 
28*2b949d04SAndroid Build Coastguard Worker #include "test.h"
29*2b949d04SAndroid Build Coastguard Worker 
30*2b949d04SAndroid Build Coastguard Worker static const char *
compose_status_string(enum xkb_compose_status status)31*2b949d04SAndroid Build Coastguard Worker compose_status_string(enum xkb_compose_status status)
32*2b949d04SAndroid Build Coastguard Worker {
33*2b949d04SAndroid Build Coastguard Worker     switch (status) {
34*2b949d04SAndroid Build Coastguard Worker     case XKB_COMPOSE_NOTHING:
35*2b949d04SAndroid Build Coastguard Worker         return "nothing";
36*2b949d04SAndroid Build Coastguard Worker     case XKB_COMPOSE_COMPOSING:
37*2b949d04SAndroid Build Coastguard Worker         return "composing";
38*2b949d04SAndroid Build Coastguard Worker     case XKB_COMPOSE_COMPOSED:
39*2b949d04SAndroid Build Coastguard Worker         return "composed";
40*2b949d04SAndroid Build Coastguard Worker     case XKB_COMPOSE_CANCELLED:
41*2b949d04SAndroid Build Coastguard Worker         return "cancelled";
42*2b949d04SAndroid Build Coastguard Worker     }
43*2b949d04SAndroid Build Coastguard Worker 
44*2b949d04SAndroid Build Coastguard Worker     return "<invalid-status>";
45*2b949d04SAndroid Build Coastguard Worker }
46*2b949d04SAndroid Build Coastguard Worker 
47*2b949d04SAndroid Build Coastguard Worker static const char *
feed_result_string(enum xkb_compose_feed_result result)48*2b949d04SAndroid Build Coastguard Worker feed_result_string(enum xkb_compose_feed_result result)
49*2b949d04SAndroid Build Coastguard Worker {
50*2b949d04SAndroid Build Coastguard Worker     switch (result) {
51*2b949d04SAndroid Build Coastguard Worker     case XKB_COMPOSE_FEED_IGNORED:
52*2b949d04SAndroid Build Coastguard Worker         return "ignored";
53*2b949d04SAndroid Build Coastguard Worker     case XKB_COMPOSE_FEED_ACCEPTED:
54*2b949d04SAndroid Build Coastguard Worker         return "accepted";
55*2b949d04SAndroid Build Coastguard Worker     }
56*2b949d04SAndroid Build Coastguard Worker 
57*2b949d04SAndroid Build Coastguard Worker     return "<invalid-result>";
58*2b949d04SAndroid Build Coastguard Worker }
59*2b949d04SAndroid Build Coastguard Worker 
60*2b949d04SAndroid Build Coastguard Worker /*
61*2b949d04SAndroid Build Coastguard Worker  * Feed a sequence of keysyms to a fresh compose state and test the outcome.
62*2b949d04SAndroid Build Coastguard Worker  *
63*2b949d04SAndroid Build Coastguard Worker  * The varargs consists of lines in the following format:
64*2b949d04SAndroid Build Coastguard Worker  *      <input keysym> <expected feed result> <expected status> <expected string> <expected keysym>
65*2b949d04SAndroid Build Coastguard Worker  * Terminated by a line consisting only of XKB_KEY_NoSymbol.
66*2b949d04SAndroid Build Coastguard Worker  */
67*2b949d04SAndroid Build Coastguard Worker static bool
test_compose_seq_va(struct xkb_compose_table * table,va_list ap)68*2b949d04SAndroid Build Coastguard Worker test_compose_seq_va(struct xkb_compose_table *table, va_list ap)
69*2b949d04SAndroid Build Coastguard Worker {
70*2b949d04SAndroid Build Coastguard Worker     int ret;
71*2b949d04SAndroid Build Coastguard Worker     struct xkb_compose_state *state;
72*2b949d04SAndroid Build Coastguard Worker     char buffer[64];
73*2b949d04SAndroid Build Coastguard Worker 
74*2b949d04SAndroid Build Coastguard Worker     state = xkb_compose_state_new(table, XKB_COMPOSE_STATE_NO_FLAGS);
75*2b949d04SAndroid Build Coastguard Worker     assert(state);
76*2b949d04SAndroid Build Coastguard Worker 
77*2b949d04SAndroid Build Coastguard Worker     for (int i = 1; ; i++) {
78*2b949d04SAndroid Build Coastguard Worker         xkb_keysym_t input_keysym;
79*2b949d04SAndroid Build Coastguard Worker         enum xkb_compose_feed_result result, expected_result;
80*2b949d04SAndroid Build Coastguard Worker         enum xkb_compose_status status, expected_status;
81*2b949d04SAndroid Build Coastguard Worker         const char *expected_string;
82*2b949d04SAndroid Build Coastguard Worker         xkb_keysym_t keysym, expected_keysym;
83*2b949d04SAndroid Build Coastguard Worker 
84*2b949d04SAndroid Build Coastguard Worker         input_keysym = va_arg(ap, xkb_keysym_t);
85*2b949d04SAndroid Build Coastguard Worker         if (input_keysym == XKB_KEY_NoSymbol)
86*2b949d04SAndroid Build Coastguard Worker             break;
87*2b949d04SAndroid Build Coastguard Worker 
88*2b949d04SAndroid Build Coastguard Worker         expected_result = va_arg(ap, enum xkb_compose_feed_result);
89*2b949d04SAndroid Build Coastguard Worker         expected_status = va_arg(ap, enum xkb_compose_status);
90*2b949d04SAndroid Build Coastguard Worker         expected_string = va_arg(ap, const char *);
91*2b949d04SAndroid Build Coastguard Worker         expected_keysym = va_arg(ap, xkb_keysym_t);
92*2b949d04SAndroid Build Coastguard Worker 
93*2b949d04SAndroid Build Coastguard Worker         result = xkb_compose_state_feed(state, input_keysym);
94*2b949d04SAndroid Build Coastguard Worker 
95*2b949d04SAndroid Build Coastguard Worker         if (result != expected_result) {
96*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "after feeding %d keysyms:\n", i);
97*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "expected feed result: %s\n",
98*2b949d04SAndroid Build Coastguard Worker                     feed_result_string(expected_result));
99*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "got feed result: %s\n",
100*2b949d04SAndroid Build Coastguard Worker                     feed_result_string(result));
101*2b949d04SAndroid Build Coastguard Worker             goto fail;
102*2b949d04SAndroid Build Coastguard Worker         }
103*2b949d04SAndroid Build Coastguard Worker 
104*2b949d04SAndroid Build Coastguard Worker         status = xkb_compose_state_get_status(state);
105*2b949d04SAndroid Build Coastguard Worker         if (status != expected_status) {
106*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "after feeding %d keysyms:\n", i);
107*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "expected status: %s\n",
108*2b949d04SAndroid Build Coastguard Worker                     compose_status_string(expected_status));
109*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "got status: %s\n",
110*2b949d04SAndroid Build Coastguard Worker                     compose_status_string(status));
111*2b949d04SAndroid Build Coastguard Worker             goto fail;
112*2b949d04SAndroid Build Coastguard Worker         }
113*2b949d04SAndroid Build Coastguard Worker 
114*2b949d04SAndroid Build Coastguard Worker         ret = xkb_compose_state_get_utf8(state, buffer, sizeof(buffer));
115*2b949d04SAndroid Build Coastguard Worker         if (ret < 0 || (size_t) ret >= sizeof(buffer)) {
116*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "after feeding %d keysyms:\n", i);
117*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "expected string: %s\n", expected_string);
118*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "got error: %d\n", ret);
119*2b949d04SAndroid Build Coastguard Worker             goto fail;
120*2b949d04SAndroid Build Coastguard Worker         }
121*2b949d04SAndroid Build Coastguard Worker         if (!streq(buffer, expected_string)) {
122*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "after feeding %d keysyms:\n", i);
123*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "expected string: %s\n", strempty(expected_string));
124*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "got string: %s\n", buffer);
125*2b949d04SAndroid Build Coastguard Worker             goto fail;
126*2b949d04SAndroid Build Coastguard Worker         }
127*2b949d04SAndroid Build Coastguard Worker 
128*2b949d04SAndroid Build Coastguard Worker         keysym = xkb_compose_state_get_one_sym(state);
129*2b949d04SAndroid Build Coastguard Worker         if (keysym != expected_keysym) {
130*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "after feeding %d keysyms:\n", i);
131*2b949d04SAndroid Build Coastguard Worker             xkb_keysym_get_name(expected_keysym, buffer, sizeof(buffer));
132*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "expected keysym: %s\n", buffer);
133*2b949d04SAndroid Build Coastguard Worker             xkb_keysym_get_name(keysym, buffer, sizeof(buffer));
134*2b949d04SAndroid Build Coastguard Worker             fprintf(stderr, "got keysym (%#x): %s\n", keysym, buffer);
135*2b949d04SAndroid Build Coastguard Worker             goto fail;
136*2b949d04SAndroid Build Coastguard Worker         }
137*2b949d04SAndroid Build Coastguard Worker     }
138*2b949d04SAndroid Build Coastguard Worker 
139*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_unref(state);
140*2b949d04SAndroid Build Coastguard Worker     return true;
141*2b949d04SAndroid Build Coastguard Worker 
142*2b949d04SAndroid Build Coastguard Worker fail:
143*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_unref(state);
144*2b949d04SAndroid Build Coastguard Worker     return false;
145*2b949d04SAndroid Build Coastguard Worker }
146*2b949d04SAndroid Build Coastguard Worker 
147*2b949d04SAndroid Build Coastguard Worker static bool
test_compose_seq(struct xkb_compose_table * table,...)148*2b949d04SAndroid Build Coastguard Worker test_compose_seq(struct xkb_compose_table *table, ...)
149*2b949d04SAndroid Build Coastguard Worker {
150*2b949d04SAndroid Build Coastguard Worker     va_list ap;
151*2b949d04SAndroid Build Coastguard Worker     bool ok;
152*2b949d04SAndroid Build Coastguard Worker     va_start(ap, table);
153*2b949d04SAndroid Build Coastguard Worker     ok = test_compose_seq_va(table, ap);
154*2b949d04SAndroid Build Coastguard Worker     va_end(ap);
155*2b949d04SAndroid Build Coastguard Worker     return ok;
156*2b949d04SAndroid Build Coastguard Worker }
157*2b949d04SAndroid Build Coastguard Worker 
158*2b949d04SAndroid Build Coastguard Worker static bool
test_compose_seq_buffer(struct xkb_context * ctx,const char * buffer,...)159*2b949d04SAndroid Build Coastguard Worker test_compose_seq_buffer(struct xkb_context *ctx, const char *buffer, ...)
160*2b949d04SAndroid Build Coastguard Worker {
161*2b949d04SAndroid Build Coastguard Worker     va_list ap;
162*2b949d04SAndroid Build Coastguard Worker     bool ok;
163*2b949d04SAndroid Build Coastguard Worker     struct xkb_compose_table *table;
164*2b949d04SAndroid Build Coastguard Worker     table = xkb_compose_table_new_from_buffer(ctx, buffer, strlen(buffer), "",
165*2b949d04SAndroid Build Coastguard Worker                                               XKB_COMPOSE_FORMAT_TEXT_V1,
166*2b949d04SAndroid Build Coastguard Worker                                               XKB_COMPOSE_COMPILE_NO_FLAGS);
167*2b949d04SAndroid Build Coastguard Worker     assert(table);
168*2b949d04SAndroid Build Coastguard Worker     va_start(ap, buffer);
169*2b949d04SAndroid Build Coastguard Worker     ok = test_compose_seq_va(table, ap);
170*2b949d04SAndroid Build Coastguard Worker     va_end(ap);
171*2b949d04SAndroid Build Coastguard Worker     xkb_compose_table_unref(table);
172*2b949d04SAndroid Build Coastguard Worker     return ok;
173*2b949d04SAndroid Build Coastguard Worker }
174*2b949d04SAndroid Build Coastguard Worker 
175*2b949d04SAndroid Build Coastguard Worker static void
test_seqs(struct xkb_context * ctx)176*2b949d04SAndroid Build Coastguard Worker test_seqs(struct xkb_context *ctx)
177*2b949d04SAndroid Build Coastguard Worker {
178*2b949d04SAndroid Build Coastguard Worker     struct xkb_compose_table *table;
179*2b949d04SAndroid Build Coastguard Worker     char *path;
180*2b949d04SAndroid Build Coastguard Worker     FILE *file;
181*2b949d04SAndroid Build Coastguard Worker 
182*2b949d04SAndroid Build Coastguard Worker     path = test_get_path("locale/en_US.UTF-8/Compose");
183*2b949d04SAndroid Build Coastguard Worker     file = fopen(path, "rb");
184*2b949d04SAndroid Build Coastguard Worker     assert(file);
185*2b949d04SAndroid Build Coastguard Worker     free(path);
186*2b949d04SAndroid Build Coastguard Worker 
187*2b949d04SAndroid Build Coastguard Worker     table = xkb_compose_table_new_from_file(ctx, file, "",
188*2b949d04SAndroid Build Coastguard Worker                                             XKB_COMPOSE_FORMAT_TEXT_V1,
189*2b949d04SAndroid Build Coastguard Worker                                             XKB_COMPOSE_COMPILE_NO_FLAGS);
190*2b949d04SAndroid Build Coastguard Worker     assert(table);
191*2b949d04SAndroid Build Coastguard Worker     fclose(file);
192*2b949d04SAndroid Build Coastguard Worker 
193*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq(table,
194*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_tilde,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
195*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_space,          XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "~",    XKB_KEY_asciitilde,
196*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
197*2b949d04SAndroid Build Coastguard Worker 
198*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq(table,
199*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_tilde,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
200*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_space,          XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "~",    XKB_KEY_asciitilde,
201*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_tilde,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
202*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_space,          XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "~",    XKB_KEY_asciitilde,
203*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
204*2b949d04SAndroid Build Coastguard Worker 
205*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq(table,
206*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_tilde,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
207*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_tilde,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "~",    XKB_KEY_asciitilde,
208*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
209*2b949d04SAndroid Build Coastguard Worker 
210*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq(table,
211*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_acute,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
212*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_space,          XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "'",    XKB_KEY_apostrophe,
213*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_Caps_Lock,      XKB_COMPOSE_FEED_IGNORED,   XKB_COMPOSE_COMPOSED,   "'",    XKB_KEY_apostrophe,
214*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
215*2b949d04SAndroid Build Coastguard Worker 
216*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq(table,
217*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_acute,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
218*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_acute,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "´",    XKB_KEY_acute,
219*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
220*2b949d04SAndroid Build Coastguard Worker 
221*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq(table,
222*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_Multi_key,      XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
223*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_Shift_L,        XKB_COMPOSE_FEED_IGNORED,   XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
224*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
225*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_Caps_Lock,      XKB_COMPOSE_FEED_IGNORED,   XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
226*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_Control_L,      XKB_COMPOSE_FEED_IGNORED,   XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
227*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_T,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "@",    XKB_KEY_at,
228*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
229*2b949d04SAndroid Build Coastguard Worker 
230*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq(table,
231*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_7,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_NOTHING,    "",     XKB_KEY_NoSymbol,
232*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_a,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_NOTHING,    "",     XKB_KEY_NoSymbol,
233*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_b,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_NOTHING,    "",     XKB_KEY_NoSymbol,
234*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
235*2b949d04SAndroid Build Coastguard Worker 
236*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq(table,
237*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_Multi_key,      XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
238*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_apostrophe,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
239*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_7,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_CANCELLED,  "",     XKB_KEY_NoSymbol,
240*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_7,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_NOTHING,    "",     XKB_KEY_NoSymbol,
241*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_Caps_Lock,      XKB_COMPOSE_FEED_IGNORED,   XKB_COMPOSE_NOTHING,    "",     XKB_KEY_NoSymbol,
242*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
243*2b949d04SAndroid Build Coastguard Worker 
244*2b949d04SAndroid Build Coastguard Worker     xkb_compose_table_unref(table);
245*2b949d04SAndroid Build Coastguard Worker 
246*2b949d04SAndroid Build Coastguard Worker     /* Make sure one-keysym sequences work. */
247*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq_buffer(ctx,
248*2b949d04SAndroid Build Coastguard Worker         "<A>          :  \"foo\"  X \n"
249*2b949d04SAndroid Build Coastguard Worker         "<B> <A>      :  \"baz\"  Y \n",
250*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,  "foo",   XKB_KEY_X,
251*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,  "foo",   XKB_KEY_X,
252*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_C,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_NOTHING,   "",      XKB_KEY_NoSymbol,
253*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_B,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING, "",      XKB_KEY_NoSymbol,
254*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,  "baz",   XKB_KEY_Y,
255*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
256*2b949d04SAndroid Build Coastguard Worker 
257*2b949d04SAndroid Build Coastguard Worker     /* No sequences at all. */
258*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq_buffer(ctx,
259*2b949d04SAndroid Build Coastguard Worker         "",
260*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_NOTHING,   "",      XKB_KEY_NoSymbol,
261*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_B,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_NOTHING,   "",      XKB_KEY_NoSymbol,
262*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_C,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_NOTHING,   "",      XKB_KEY_NoSymbol,
263*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_Multi_key,      XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_NOTHING,   "",      XKB_KEY_NoSymbol,
264*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_acute,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_NOTHING,   "",      XKB_KEY_NoSymbol,
265*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
266*2b949d04SAndroid Build Coastguard Worker 
267*2b949d04SAndroid Build Coastguard Worker     /* Only keysym - string derived from keysym. */
268*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq_buffer(ctx,
269*2b949d04SAndroid Build Coastguard Worker         "<A> <B>     :  X \n"
270*2b949d04SAndroid Build Coastguard Worker         "<B> <A>     :  dollar \n"
271*2b949d04SAndroid Build Coastguard Worker         "<C>         :  dead_acute \n",
272*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING, "",      XKB_KEY_NoSymbol,
273*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_B,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,  "X",     XKB_KEY_X,
274*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_B,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING, "",      XKB_KEY_NoSymbol,
275*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,  "$",     XKB_KEY_dollar,
276*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_C,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,  "",      XKB_KEY_dead_acute,
277*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
278*2b949d04SAndroid Build Coastguard Worker 
279*2b949d04SAndroid Build Coastguard Worker     /* Make sure a cancelling keysym doesn't start a new sequence. */
280*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq_buffer(ctx,
281*2b949d04SAndroid Build Coastguard Worker         "<A> <B>     :  X \n"
282*2b949d04SAndroid Build Coastguard Worker         "<C> <D>     :  Y \n",
283*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING, "",      XKB_KEY_NoSymbol,
284*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_C,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_CANCELLED, "",      XKB_KEY_NoSymbol,
285*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_D,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_NOTHING,   "",      XKB_KEY_NoSymbol,
286*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING, "",      XKB_KEY_NoSymbol,
287*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_C,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_CANCELLED, "",      XKB_KEY_NoSymbol,
288*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_C,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING, "",      XKB_KEY_NoSymbol,
289*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_D,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,  "Y",     XKB_KEY_Y,
290*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
291*2b949d04SAndroid Build Coastguard Worker }
292*2b949d04SAndroid Build Coastguard Worker 
293*2b949d04SAndroid Build Coastguard Worker static void
test_conflicting(struct xkb_context * ctx)294*2b949d04SAndroid Build Coastguard Worker test_conflicting(struct xkb_context *ctx)
295*2b949d04SAndroid Build Coastguard Worker {
296*2b949d04SAndroid Build Coastguard Worker     // new is prefix of old
297*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq_buffer(ctx,
298*2b949d04SAndroid Build Coastguard Worker         "<A> <B> <C>  :  \"foo\"  A \n"
299*2b949d04SAndroid Build Coastguard Worker         "<A> <B>      :  \"bar\"  B \n",
300*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
301*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_B,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
302*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_C,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "foo",  XKB_KEY_A,
303*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
304*2b949d04SAndroid Build Coastguard Worker 
305*2b949d04SAndroid Build Coastguard Worker     // old is a prefix of new
306*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq_buffer(ctx,
307*2b949d04SAndroid Build Coastguard Worker         "<A> <B>      :  \"bar\"  B \n"
308*2b949d04SAndroid Build Coastguard Worker         "<A> <B> <C>  :  \"foo\"  A \n",
309*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
310*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_B,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
311*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_C,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "foo",  XKB_KEY_A,
312*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
313*2b949d04SAndroid Build Coastguard Worker 
314*2b949d04SAndroid Build Coastguard Worker     // new duplicate of old
315*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq_buffer(ctx,
316*2b949d04SAndroid Build Coastguard Worker         "<A> <B>      :  \"bar\"  B \n"
317*2b949d04SAndroid Build Coastguard Worker         "<A> <B>      :  \"bar\"  B \n",
318*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
319*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_B,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "bar",  XKB_KEY_B,
320*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_C,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_NOTHING,    "",     XKB_KEY_NoSymbol,
321*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
322*2b949d04SAndroid Build Coastguard Worker 
323*2b949d04SAndroid Build Coastguard Worker     // new same length as old #1
324*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq_buffer(ctx,
325*2b949d04SAndroid Build Coastguard Worker         "<A> <B>      :  \"foo\"  A \n"
326*2b949d04SAndroid Build Coastguard Worker         "<A> <B>      :  \"bar\"  B \n",
327*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
328*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_B,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "bar",  XKB_KEY_B,
329*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
330*2b949d04SAndroid Build Coastguard Worker 
331*2b949d04SAndroid Build Coastguard Worker     // new same length as old #2
332*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq_buffer(ctx,
333*2b949d04SAndroid Build Coastguard Worker         "<A> <B>      :  \"foo\"  A \n"
334*2b949d04SAndroid Build Coastguard Worker         "<A> <B>      :  \"foo\"  B \n",
335*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
336*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_B,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "foo",  XKB_KEY_B,
337*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
338*2b949d04SAndroid Build Coastguard Worker 
339*2b949d04SAndroid Build Coastguard Worker     // new same length as old #3
340*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq_buffer(ctx,
341*2b949d04SAndroid Build Coastguard Worker         "<A> <B>      :  \"foo\"  A \n"
342*2b949d04SAndroid Build Coastguard Worker         "<A> <B>      :  \"bar\"  A \n",
343*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_A,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
344*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_B,              XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "bar",  XKB_KEY_A,
345*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
346*2b949d04SAndroid Build Coastguard Worker }
347*2b949d04SAndroid Build Coastguard Worker 
348*2b949d04SAndroid Build Coastguard Worker static void
test_state(struct xkb_context * ctx)349*2b949d04SAndroid Build Coastguard Worker test_state(struct xkb_context *ctx)
350*2b949d04SAndroid Build Coastguard Worker {
351*2b949d04SAndroid Build Coastguard Worker     struct xkb_compose_table *table;
352*2b949d04SAndroid Build Coastguard Worker     struct xkb_compose_state *state;
353*2b949d04SAndroid Build Coastguard Worker     char *path;
354*2b949d04SAndroid Build Coastguard Worker     FILE *file;
355*2b949d04SAndroid Build Coastguard Worker 
356*2b949d04SAndroid Build Coastguard Worker     path = test_get_path("locale/en_US.UTF-8/Compose");
357*2b949d04SAndroid Build Coastguard Worker     file = fopen(path, "rb");
358*2b949d04SAndroid Build Coastguard Worker     assert(file);
359*2b949d04SAndroid Build Coastguard Worker     free(path);
360*2b949d04SAndroid Build Coastguard Worker 
361*2b949d04SAndroid Build Coastguard Worker     table = xkb_compose_table_new_from_file(ctx, file, "",
362*2b949d04SAndroid Build Coastguard Worker                                             XKB_COMPOSE_FORMAT_TEXT_V1,
363*2b949d04SAndroid Build Coastguard Worker                                             XKB_COMPOSE_COMPILE_NO_FLAGS);
364*2b949d04SAndroid Build Coastguard Worker     assert(table);
365*2b949d04SAndroid Build Coastguard Worker     fclose(file);
366*2b949d04SAndroid Build Coastguard Worker 
367*2b949d04SAndroid Build Coastguard Worker     state = xkb_compose_state_new(table, XKB_COMPOSE_STATE_NO_FLAGS);
368*2b949d04SAndroid Build Coastguard Worker     assert(state);
369*2b949d04SAndroid Build Coastguard Worker 
370*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_NOTHING);
371*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_reset(state);
372*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_NOTHING);
373*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_feed(state, XKB_KEY_NoSymbol);
374*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_NOTHING);
375*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_feed(state, XKB_KEY_Multi_key);
376*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_COMPOSING);
377*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_reset(state);
378*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_NOTHING);
379*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_feed(state, XKB_KEY_Multi_key);
380*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_COMPOSING);
381*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_feed(state, XKB_KEY_Multi_key);
382*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_CANCELLED);
383*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_feed(state, XKB_KEY_Multi_key);
384*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_COMPOSING);
385*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_feed(state, XKB_KEY_Multi_key);
386*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_CANCELLED);
387*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_reset(state);
388*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_NOTHING);
389*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_feed(state, XKB_KEY_dead_acute);
390*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_COMPOSING);
391*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_feed(state, XKB_KEY_A);
392*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_COMPOSED);
393*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_reset(state);
394*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_NOTHING);
395*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_feed(state, XKB_KEY_dead_acute);
396*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_COMPOSING);
397*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_feed(state, XKB_KEY_A);
398*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_COMPOSED);
399*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_reset(state);
400*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_feed(state, XKB_KEY_NoSymbol);
401*2b949d04SAndroid Build Coastguard Worker     assert(xkb_compose_state_get_status(state) == XKB_COMPOSE_NOTHING);
402*2b949d04SAndroid Build Coastguard Worker 
403*2b949d04SAndroid Build Coastguard Worker     xkb_compose_state_unref(state);
404*2b949d04SAndroid Build Coastguard Worker     xkb_compose_table_unref(table);
405*2b949d04SAndroid Build Coastguard Worker }
406*2b949d04SAndroid Build Coastguard Worker 
407*2b949d04SAndroid Build Coastguard Worker static void
test_XCOMPOSEFILE(struct xkb_context * ctx)408*2b949d04SAndroid Build Coastguard Worker test_XCOMPOSEFILE(struct xkb_context *ctx)
409*2b949d04SAndroid Build Coastguard Worker {
410*2b949d04SAndroid Build Coastguard Worker     struct xkb_compose_table *table;
411*2b949d04SAndroid Build Coastguard Worker     char *path;
412*2b949d04SAndroid Build Coastguard Worker 
413*2b949d04SAndroid Build Coastguard Worker     path = test_get_path("locale/en_US.UTF-8/Compose");
414*2b949d04SAndroid Build Coastguard Worker     setenv("XCOMPOSEFILE", path, 1);
415*2b949d04SAndroid Build Coastguard Worker     free(path);
416*2b949d04SAndroid Build Coastguard Worker 
417*2b949d04SAndroid Build Coastguard Worker     table = xkb_compose_table_new_from_locale(ctx, "blabla",
418*2b949d04SAndroid Build Coastguard Worker                                               XKB_COMPOSE_COMPILE_NO_FLAGS);
419*2b949d04SAndroid Build Coastguard Worker     assert(table);
420*2b949d04SAndroid Build Coastguard Worker 
421*2b949d04SAndroid Build Coastguard Worker     unsetenv("XCOMPOSEFILE");
422*2b949d04SAndroid Build Coastguard Worker 
423*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq(table,
424*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_tilde,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
425*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_space,          XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "~",    XKB_KEY_asciitilde,
426*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
427*2b949d04SAndroid Build Coastguard Worker 
428*2b949d04SAndroid Build Coastguard Worker     xkb_compose_table_unref(table);
429*2b949d04SAndroid Build Coastguard Worker }
430*2b949d04SAndroid Build Coastguard Worker 
431*2b949d04SAndroid Build Coastguard Worker static void
test_from_locale(struct xkb_context * ctx)432*2b949d04SAndroid Build Coastguard Worker test_from_locale(struct xkb_context *ctx)
433*2b949d04SAndroid Build Coastguard Worker {
434*2b949d04SAndroid Build Coastguard Worker     struct xkb_compose_table *table;
435*2b949d04SAndroid Build Coastguard Worker     char *path;
436*2b949d04SAndroid Build Coastguard Worker 
437*2b949d04SAndroid Build Coastguard Worker     path = test_get_path("locale");
438*2b949d04SAndroid Build Coastguard Worker     setenv("XLOCALEDIR", path, 1);
439*2b949d04SAndroid Build Coastguard Worker     free(path);
440*2b949d04SAndroid Build Coastguard Worker 
441*2b949d04SAndroid Build Coastguard Worker     /* Direct directory name match. */
442*2b949d04SAndroid Build Coastguard Worker     table = xkb_compose_table_new_from_locale(ctx, "en_US.UTF-8",
443*2b949d04SAndroid Build Coastguard Worker                                               XKB_COMPOSE_COMPILE_NO_FLAGS);
444*2b949d04SAndroid Build Coastguard Worker     assert(table);
445*2b949d04SAndroid Build Coastguard Worker     xkb_compose_table_unref(table);
446*2b949d04SAndroid Build Coastguard Worker 
447*2b949d04SAndroid Build Coastguard Worker     /* Direct locale name match. */
448*2b949d04SAndroid Build Coastguard Worker     table = xkb_compose_table_new_from_locale(ctx, "C.UTF-8",
449*2b949d04SAndroid Build Coastguard Worker                                               XKB_COMPOSE_COMPILE_NO_FLAGS);
450*2b949d04SAndroid Build Coastguard Worker     assert(table);
451*2b949d04SAndroid Build Coastguard Worker     xkb_compose_table_unref(table);
452*2b949d04SAndroid Build Coastguard Worker 
453*2b949d04SAndroid Build Coastguard Worker     /* Alias. */
454*2b949d04SAndroid Build Coastguard Worker     table = xkb_compose_table_new_from_locale(ctx, "univ.utf8",
455*2b949d04SAndroid Build Coastguard Worker                                               XKB_COMPOSE_COMPILE_NO_FLAGS);
456*2b949d04SAndroid Build Coastguard Worker     assert(table);
457*2b949d04SAndroid Build Coastguard Worker     xkb_compose_table_unref(table);
458*2b949d04SAndroid Build Coastguard Worker 
459*2b949d04SAndroid Build Coastguard Worker     /* Special case - C. */
460*2b949d04SAndroid Build Coastguard Worker     table = xkb_compose_table_new_from_locale(ctx, "C",
461*2b949d04SAndroid Build Coastguard Worker                                               XKB_COMPOSE_COMPILE_NO_FLAGS);
462*2b949d04SAndroid Build Coastguard Worker     assert(table);
463*2b949d04SAndroid Build Coastguard Worker     xkb_compose_table_unref(table);
464*2b949d04SAndroid Build Coastguard Worker 
465*2b949d04SAndroid Build Coastguard Worker     /* Bogus - not found. */
466*2b949d04SAndroid Build Coastguard Worker     table = xkb_compose_table_new_from_locale(ctx, "blabla",
467*2b949d04SAndroid Build Coastguard Worker                                               XKB_COMPOSE_COMPILE_NO_FLAGS);
468*2b949d04SAndroid Build Coastguard Worker     assert(!table);
469*2b949d04SAndroid Build Coastguard Worker 
470*2b949d04SAndroid Build Coastguard Worker     unsetenv("XLOCALEDIR");
471*2b949d04SAndroid Build Coastguard Worker }
472*2b949d04SAndroid Build Coastguard Worker 
473*2b949d04SAndroid Build Coastguard Worker 
474*2b949d04SAndroid Build Coastguard Worker static void
test_modifier_syntax(struct xkb_context * ctx)475*2b949d04SAndroid Build Coastguard Worker test_modifier_syntax(struct xkb_context *ctx)
476*2b949d04SAndroid Build Coastguard Worker {
477*2b949d04SAndroid Build Coastguard Worker     const char *table_string;
478*2b949d04SAndroid Build Coastguard Worker 
479*2b949d04SAndroid Build Coastguard Worker     /* We don't do anything with the modifiers, but make sure we can parse
480*2b949d04SAndroid Build Coastguard Worker      * them. */
481*2b949d04SAndroid Build Coastguard Worker 
482*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq_buffer(ctx,
483*2b949d04SAndroid Build Coastguard Worker         "None <A>          : X \n"
484*2b949d04SAndroid Build Coastguard Worker         "Shift <B>         : Y \n"
485*2b949d04SAndroid Build Coastguard Worker         "Ctrl <C>          : Y \n"
486*2b949d04SAndroid Build Coastguard Worker         "Alt <D>           : Y \n"
487*2b949d04SAndroid Build Coastguard Worker         "Caps <E>          : Y \n"
488*2b949d04SAndroid Build Coastguard Worker         "Lock <F>          : Y \n"
489*2b949d04SAndroid Build Coastguard Worker         "Shift Ctrl <G>    : Y \n"
490*2b949d04SAndroid Build Coastguard Worker         "~Shift <H>        : Y \n"
491*2b949d04SAndroid Build Coastguard Worker         "~Shift Ctrl <I>   : Y \n"
492*2b949d04SAndroid Build Coastguard Worker         "Shift ~Ctrl <J>   : Y \n"
493*2b949d04SAndroid Build Coastguard Worker         "Shift ~Ctrl ~Alt <K> : Y \n"
494*2b949d04SAndroid Build Coastguard Worker         "! Shift <B>       : Y \n"
495*2b949d04SAndroid Build Coastguard Worker         "! Ctrl <C>        : Y \n"
496*2b949d04SAndroid Build Coastguard Worker         "! Alt <D>         : Y \n"
497*2b949d04SAndroid Build Coastguard Worker         "! Caps <E>        : Y \n"
498*2b949d04SAndroid Build Coastguard Worker         "! Lock <F>        : Y \n"
499*2b949d04SAndroid Build Coastguard Worker         "! Shift Ctrl <G>  : Y \n"
500*2b949d04SAndroid Build Coastguard Worker         "! ~Shift <H>      : Y \n"
501*2b949d04SAndroid Build Coastguard Worker         "! ~Shift Ctrl <I> : Y \n"
502*2b949d04SAndroid Build Coastguard Worker         "! Shift ~Ctrl <J> : Y \n"
503*2b949d04SAndroid Build Coastguard Worker         "! Shift ~Ctrl ~Alt <K> : Y \n"
504*2b949d04SAndroid Build Coastguard Worker         "<L> ! Shift <M>   : Y \n"
505*2b949d04SAndroid Build Coastguard Worker         "None <N> ! Shift <O> : Y \n"
506*2b949d04SAndroid Build Coastguard Worker         "None <P> ! Shift <Q> : Y \n",
507*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
508*2b949d04SAndroid Build Coastguard Worker 
509*2b949d04SAndroid Build Coastguard Worker     fprintf(stderr, "<START bad input string>\n");
510*2b949d04SAndroid Build Coastguard Worker     table_string =
511*2b949d04SAndroid Build Coastguard Worker         "! None <A>        : X \n"
512*2b949d04SAndroid Build Coastguard Worker         "! Foo <B>         : X \n"
513*2b949d04SAndroid Build Coastguard Worker         "None ! Shift <C>  : X \n"
514*2b949d04SAndroid Build Coastguard Worker         "! ! <D>           : X \n"
515*2b949d04SAndroid Build Coastguard Worker         "! ~ <E>           : X \n"
516*2b949d04SAndroid Build Coastguard Worker         "! ! <F>           : X \n"
517*2b949d04SAndroid Build Coastguard Worker         "! Ctrl ! Ctrl <G> : X \n"
518*2b949d04SAndroid Build Coastguard Worker         "<H> !             : X \n"
519*2b949d04SAndroid Build Coastguard Worker         "<I> None          : X \n"
520*2b949d04SAndroid Build Coastguard Worker         "None None <J>     : X \n"
521*2b949d04SAndroid Build Coastguard Worker         "<K>               : !Shift X \n";
522*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_compose_table_new_from_buffer(ctx, table_string,
523*2b949d04SAndroid Build Coastguard Worker                                               strlen(table_string), "C",
524*2b949d04SAndroid Build Coastguard Worker                                               XKB_COMPOSE_FORMAT_TEXT_V1,
525*2b949d04SAndroid Build Coastguard Worker                                               XKB_COMPOSE_COMPILE_NO_FLAGS));
526*2b949d04SAndroid Build Coastguard Worker     fprintf(stderr, "<END bad input string>\n");
527*2b949d04SAndroid Build Coastguard Worker }
528*2b949d04SAndroid Build Coastguard Worker 
529*2b949d04SAndroid Build Coastguard Worker static void
test_include(struct xkb_context * ctx)530*2b949d04SAndroid Build Coastguard Worker test_include(struct xkb_context *ctx)
531*2b949d04SAndroid Build Coastguard Worker {
532*2b949d04SAndroid Build Coastguard Worker     char *path, *table_string;
533*2b949d04SAndroid Build Coastguard Worker 
534*2b949d04SAndroid Build Coastguard Worker     path = test_get_path("locale/en_US.UTF-8/Compose");
535*2b949d04SAndroid Build Coastguard Worker     assert(path);
536*2b949d04SAndroid Build Coastguard Worker 
537*2b949d04SAndroid Build Coastguard Worker     /* We don't have a mechanism to change the include paths like we
538*2b949d04SAndroid Build Coastguard Worker      * have for keymaps. So we must include the full path. */
539*2b949d04SAndroid Build Coastguard Worker     table_string = asprintf_safe("<dead_tilde> <space>   : \"foo\" X\n"
540*2b949d04SAndroid Build Coastguard Worker                                  "include \"%s\"\n"
541*2b949d04SAndroid Build Coastguard Worker                                  "<dead_tilde> <dead_tilde> : \"bar\" Y\n", path);
542*2b949d04SAndroid Build Coastguard Worker     assert(table_string);
543*2b949d04SAndroid Build Coastguard Worker 
544*2b949d04SAndroid Build Coastguard Worker     assert(test_compose_seq_buffer(ctx, table_string,
545*2b949d04SAndroid Build Coastguard Worker         /* No conflict. */
546*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_acute,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
547*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_acute,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "´",    XKB_KEY_acute,
548*2b949d04SAndroid Build Coastguard Worker 
549*2b949d04SAndroid Build Coastguard Worker         /* Comes before - doesn't override. */
550*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_tilde,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
551*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_space,          XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "~",    XKB_KEY_asciitilde,
552*2b949d04SAndroid Build Coastguard Worker 
553*2b949d04SAndroid Build Coastguard Worker         /* Comes after - does override. */
554*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_tilde,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSING,  "",     XKB_KEY_NoSymbol,
555*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_dead_tilde,     XKB_COMPOSE_FEED_ACCEPTED,  XKB_COMPOSE_COMPOSED,   "bar",  XKB_KEY_Y,
556*2b949d04SAndroid Build Coastguard Worker 
557*2b949d04SAndroid Build Coastguard Worker         XKB_KEY_NoSymbol));
558*2b949d04SAndroid Build Coastguard Worker 
559*2b949d04SAndroid Build Coastguard Worker     free(path);
560*2b949d04SAndroid Build Coastguard Worker     free(table_string);
561*2b949d04SAndroid Build Coastguard Worker }
562*2b949d04SAndroid Build Coastguard Worker 
563*2b949d04SAndroid Build Coastguard Worker int
main(int argc,char * argv[])564*2b949d04SAndroid Build Coastguard Worker main(int argc, char *argv[])
565*2b949d04SAndroid Build Coastguard Worker {
566*2b949d04SAndroid Build Coastguard Worker     struct xkb_context *ctx;
567*2b949d04SAndroid Build Coastguard Worker 
568*2b949d04SAndroid Build Coastguard Worker     ctx = test_get_context(CONTEXT_NO_FLAG);
569*2b949d04SAndroid Build Coastguard Worker     assert(ctx);
570*2b949d04SAndroid Build Coastguard Worker 
571*2b949d04SAndroid Build Coastguard Worker     test_seqs(ctx);
572*2b949d04SAndroid Build Coastguard Worker     test_conflicting(ctx);
573*2b949d04SAndroid Build Coastguard Worker     test_XCOMPOSEFILE(ctx);
574*2b949d04SAndroid Build Coastguard Worker     test_from_locale(ctx);
575*2b949d04SAndroid Build Coastguard Worker     test_state(ctx);
576*2b949d04SAndroid Build Coastguard Worker     test_modifier_syntax(ctx);
577*2b949d04SAndroid Build Coastguard Worker     test_include(ctx);
578*2b949d04SAndroid Build Coastguard Worker 
579*2b949d04SAndroid Build Coastguard Worker     xkb_context_unref(ctx);
580*2b949d04SAndroid Build Coastguard Worker     return 0;
581*2b949d04SAndroid Build Coastguard Worker }
582