xref: /aosp_15_r20/external/libxkbcommon/test/keysym.c (revision 2b949d0487e80d67f1fda82db69e101e761f8064)
1*2b949d04SAndroid Build Coastguard Worker /*
2*2b949d04SAndroid Build Coastguard Worker  * Copyright © 2009 Dan Nicholson
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 #include "config.h"
24*2b949d04SAndroid Build Coastguard Worker 
25*2b949d04SAndroid Build Coastguard Worker #include <locale.h>
26*2b949d04SAndroid Build Coastguard Worker 
27*2b949d04SAndroid Build Coastguard Worker #include "test.h"
28*2b949d04SAndroid Build Coastguard Worker #include "keysym.h" /* For unexported is_lower/upper/keypad() */
29*2b949d04SAndroid Build Coastguard Worker 
30*2b949d04SAndroid Build Coastguard Worker static int
test_string(const char * string,xkb_keysym_t expected)31*2b949d04SAndroid Build Coastguard Worker test_string(const char *string, xkb_keysym_t expected)
32*2b949d04SAndroid Build Coastguard Worker {
33*2b949d04SAndroid Build Coastguard Worker     xkb_keysym_t keysym;
34*2b949d04SAndroid Build Coastguard Worker 
35*2b949d04SAndroid Build Coastguard Worker     keysym = xkb_keysym_from_name(string, 0);
36*2b949d04SAndroid Build Coastguard Worker 
37*2b949d04SAndroid Build Coastguard Worker     fprintf(stderr, "Expected string %s -> %x\n", string, expected);
38*2b949d04SAndroid Build Coastguard Worker     fprintf(stderr, "Received string %s -> %x\n\n", string, keysym);
39*2b949d04SAndroid Build Coastguard Worker 
40*2b949d04SAndroid Build Coastguard Worker     return keysym == expected;
41*2b949d04SAndroid Build Coastguard Worker }
42*2b949d04SAndroid Build Coastguard Worker 
43*2b949d04SAndroid Build Coastguard Worker static int
test_casestring(const char * string,xkb_keysym_t expected)44*2b949d04SAndroid Build Coastguard Worker test_casestring(const char *string, xkb_keysym_t expected)
45*2b949d04SAndroid Build Coastguard Worker {
46*2b949d04SAndroid Build Coastguard Worker     xkb_keysym_t keysym;
47*2b949d04SAndroid Build Coastguard Worker 
48*2b949d04SAndroid Build Coastguard Worker     keysym = xkb_keysym_from_name(string, XKB_KEYSYM_CASE_INSENSITIVE);
49*2b949d04SAndroid Build Coastguard Worker 
50*2b949d04SAndroid Build Coastguard Worker     fprintf(stderr, "Expected casestring %s -> %x\n", string, expected);
51*2b949d04SAndroid Build Coastguard Worker     fprintf(stderr, "Received casestring %s -> %x\n\n", string, keysym);
52*2b949d04SAndroid Build Coastguard Worker 
53*2b949d04SAndroid Build Coastguard Worker     return keysym == expected;
54*2b949d04SAndroid Build Coastguard Worker }
55*2b949d04SAndroid Build Coastguard Worker 
56*2b949d04SAndroid Build Coastguard Worker static int
test_keysym(xkb_keysym_t keysym,const char * expected)57*2b949d04SAndroid Build Coastguard Worker test_keysym(xkb_keysym_t keysym, const char *expected)
58*2b949d04SAndroid Build Coastguard Worker {
59*2b949d04SAndroid Build Coastguard Worker     char s[16];
60*2b949d04SAndroid Build Coastguard Worker 
61*2b949d04SAndroid Build Coastguard Worker     xkb_keysym_get_name(keysym, s, sizeof(s));
62*2b949d04SAndroid Build Coastguard Worker 
63*2b949d04SAndroid Build Coastguard Worker     fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
64*2b949d04SAndroid Build Coastguard Worker     fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
65*2b949d04SAndroid Build Coastguard Worker 
66*2b949d04SAndroid Build Coastguard Worker     return streq(s, expected);
67*2b949d04SAndroid Build Coastguard Worker }
68*2b949d04SAndroid Build Coastguard Worker 
69*2b949d04SAndroid Build Coastguard Worker static int
test_utf8(xkb_keysym_t keysym,const char * expected)70*2b949d04SAndroid Build Coastguard Worker test_utf8(xkb_keysym_t keysym, const char *expected)
71*2b949d04SAndroid Build Coastguard Worker {
72*2b949d04SAndroid Build Coastguard Worker     char s[8];
73*2b949d04SAndroid Build Coastguard Worker     int ret;
74*2b949d04SAndroid Build Coastguard Worker 
75*2b949d04SAndroid Build Coastguard Worker     ret = xkb_keysym_to_utf8(keysym, s, sizeof(s));
76*2b949d04SAndroid Build Coastguard Worker     if (ret <= 0)
77*2b949d04SAndroid Build Coastguard Worker         return ret;
78*2b949d04SAndroid Build Coastguard Worker 
79*2b949d04SAndroid Build Coastguard Worker     assert(expected != NULL);
80*2b949d04SAndroid Build Coastguard Worker 
81*2b949d04SAndroid Build Coastguard Worker     fprintf(stderr, "Expected keysym %#x -> %s (%u bytes)\n", keysym, expected,
82*2b949d04SAndroid Build Coastguard Worker             (unsigned) strlen(expected));
83*2b949d04SAndroid Build Coastguard Worker     fprintf(stderr, "Received keysym %#x -> %s (%u bytes)\n\n", keysym, s,
84*2b949d04SAndroid Build Coastguard Worker             (unsigned) strlen(s));
85*2b949d04SAndroid Build Coastguard Worker 
86*2b949d04SAndroid Build Coastguard Worker     return streq(s, expected);
87*2b949d04SAndroid Build Coastguard Worker }
88*2b949d04SAndroid Build Coastguard Worker 
89*2b949d04SAndroid Build Coastguard Worker static void
test_github_issue_42(void)90*2b949d04SAndroid Build Coastguard Worker test_github_issue_42(void)
91*2b949d04SAndroid Build Coastguard Worker {
92*2b949d04SAndroid Build Coastguard Worker     // Verify we are not dependent on locale, Turkish-i problem in particular.
93*2b949d04SAndroid Build Coastguard Worker     if (setlocale(LC_CTYPE, "tr_TR.UTF-8") == NULL) {
94*2b949d04SAndroid Build Coastguard Worker         // The locale is not available, probably; skip.
95*2b949d04SAndroid Build Coastguard Worker         return;
96*2b949d04SAndroid Build Coastguard Worker     }
97*2b949d04SAndroid Build Coastguard Worker 
98*2b949d04SAndroid Build Coastguard Worker     assert(test_string("i", XKB_KEY_i));
99*2b949d04SAndroid Build Coastguard Worker     assert(test_string("I", XKB_KEY_I));
100*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("i", XKB_KEY_i));
101*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("I", XKB_KEY_i));
102*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_upper(XKB_KEY_i) == XKB_KEY_I);
103*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_lower(XKB_KEY_I) == XKB_KEY_i);
104*2b949d04SAndroid Build Coastguard Worker 
105*2b949d04SAndroid Build Coastguard Worker     setlocale(LC_CTYPE, "C");
106*2b949d04SAndroid Build Coastguard Worker }
107*2b949d04SAndroid Build Coastguard Worker 
108*2b949d04SAndroid Build Coastguard Worker static void
get_keysym_name(xkb_keysym_t keysym,char * buffer,size_t size)109*2b949d04SAndroid Build Coastguard Worker get_keysym_name(xkb_keysym_t keysym, char *buffer, size_t size)
110*2b949d04SAndroid Build Coastguard Worker {
111*2b949d04SAndroid Build Coastguard Worker     int name_length = xkb_keysym_get_name(keysym, buffer, size);
112*2b949d04SAndroid Build Coastguard Worker     if (name_length < 0) {
113*2b949d04SAndroid Build Coastguard Worker         snprintf(buffer, size, "(unknown: 0x%lx)", (unsigned long)keysym);
114*2b949d04SAndroid Build Coastguard Worker     }
115*2b949d04SAndroid Build Coastguard Worker }
116*2b949d04SAndroid Build Coastguard Worker 
117*2b949d04SAndroid Build Coastguard Worker static int
test_utf32_to_keysym(uint32_t ucs,xkb_keysym_t expected)118*2b949d04SAndroid Build Coastguard Worker test_utf32_to_keysym(uint32_t ucs, xkb_keysym_t expected)
119*2b949d04SAndroid Build Coastguard Worker {
120*2b949d04SAndroid Build Coastguard Worker     char expected_name[64];
121*2b949d04SAndroid Build Coastguard Worker     char actual_name[64];
122*2b949d04SAndroid Build Coastguard Worker     xkb_keysym_t actual = xkb_utf32_to_keysym(ucs);
123*2b949d04SAndroid Build Coastguard Worker     get_keysym_name(expected, expected_name, 64);
124*2b949d04SAndroid Build Coastguard Worker     get_keysym_name(actual, actual_name, 64);
125*2b949d04SAndroid Build Coastguard Worker 
126*2b949d04SAndroid Build Coastguard Worker     fprintf(stderr, "Code point 0x%lx: expected keysym: %s, actual: %s\n\n",
127*2b949d04SAndroid Build Coastguard Worker             (unsigned long)ucs, expected_name, actual_name);
128*2b949d04SAndroid Build Coastguard Worker     return expected == actual;
129*2b949d04SAndroid Build Coastguard Worker }
130*2b949d04SAndroid Build Coastguard Worker 
131*2b949d04SAndroid Build Coastguard Worker int
main(void)132*2b949d04SAndroid Build Coastguard Worker main(void)
133*2b949d04SAndroid Build Coastguard Worker {
134*2b949d04SAndroid Build Coastguard Worker     assert(test_string("Undo", 0xFF65));
135*2b949d04SAndroid Build Coastguard Worker     assert(test_string("ThisKeyShouldNotExist", XKB_KEY_NoSymbol));
136*2b949d04SAndroid Build Coastguard Worker     assert(test_string("XF86_Switch_VT_5", 0x1008FE05));
137*2b949d04SAndroid Build Coastguard Worker     assert(test_string("VoidSymbol", 0xFFFFFF));
138*2b949d04SAndroid Build Coastguard Worker     assert(test_string("U4567", 0x1004567));
139*2b949d04SAndroid Build Coastguard Worker     assert(test_string("U+4567", XKB_KEY_NoSymbol));
140*2b949d04SAndroid Build Coastguard Worker     assert(test_string("U+4567ffff", XKB_KEY_NoSymbol));
141*2b949d04SAndroid Build Coastguard Worker     assert(test_string("U+4567ffffff", XKB_KEY_NoSymbol));
142*2b949d04SAndroid Build Coastguard Worker     assert(test_string("U   4567", XKB_KEY_NoSymbol));
143*2b949d04SAndroid Build Coastguard Worker     assert(test_string("U  +4567", XKB_KEY_NoSymbol));
144*2b949d04SAndroid Build Coastguard Worker     assert(test_string("0x10203040", 0x10203040));
145*2b949d04SAndroid Build Coastguard Worker     assert(test_string("0x102030400", XKB_KEY_NoSymbol));
146*2b949d04SAndroid Build Coastguard Worker     assert(test_string("0x010203040", XKB_KEY_NoSymbol));
147*2b949d04SAndroid Build Coastguard Worker     assert(test_string("0x+10203040", XKB_KEY_NoSymbol));
148*2b949d04SAndroid Build Coastguard Worker     assert(test_string("0x  10203040", XKB_KEY_NoSymbol));
149*2b949d04SAndroid Build Coastguard Worker     assert(test_string("0x  +10203040", XKB_KEY_NoSymbol));
150*2b949d04SAndroid Build Coastguard Worker     assert(test_string("0x-10203040", XKB_KEY_NoSymbol));
151*2b949d04SAndroid Build Coastguard Worker     assert(test_string("a", 0x61));
152*2b949d04SAndroid Build Coastguard Worker     assert(test_string("A", 0x41));
153*2b949d04SAndroid Build Coastguard Worker     assert(test_string("ch", 0xfea0));
154*2b949d04SAndroid Build Coastguard Worker     assert(test_string("Ch", 0xfea1));
155*2b949d04SAndroid Build Coastguard Worker     assert(test_string("CH", 0xfea2));
156*2b949d04SAndroid Build Coastguard Worker     assert(test_string("THORN", 0x00de));
157*2b949d04SAndroid Build Coastguard Worker     assert(test_string("Thorn", 0x00de));
158*2b949d04SAndroid Build Coastguard Worker     assert(test_string("thorn", 0x00fe));
159*2b949d04SAndroid Build Coastguard Worker     /* Max keysym. */
160*2b949d04SAndroid Build Coastguard Worker     assert(test_string("0xffffffff", 0xffffffff));
161*2b949d04SAndroid Build Coastguard Worker     /* Outside range. */
162*2b949d04SAndroid Build Coastguard Worker     assert(test_string("0x100000000", XKB_KEY_NoSymbol));
163*2b949d04SAndroid Build Coastguard Worker 
164*2b949d04SAndroid Build Coastguard Worker     assert(test_keysym(0x1008FF56, "XF86Close"));
165*2b949d04SAndroid Build Coastguard Worker     assert(test_keysym(0x0, "NoSymbol"));
166*2b949d04SAndroid Build Coastguard Worker     assert(test_keysym(0x1008FE20, "XF86Ungrab"));
167*2b949d04SAndroid Build Coastguard Worker     assert(test_keysym(0x01001234, "U1234"));
168*2b949d04SAndroid Build Coastguard Worker     /* 16-bit unicode padded to width 4. */
169*2b949d04SAndroid Build Coastguard Worker     assert(test_keysym(0x010002DE, "U02DE"));
170*2b949d04SAndroid Build Coastguard Worker     /* 32-bit unicode padded to width 8. */
171*2b949d04SAndroid Build Coastguard Worker     assert(test_keysym(0x0101F4A9, "U0001F4A9"));
172*2b949d04SAndroid Build Coastguard Worker 
173*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("Undo", 0xFF65));
174*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("UNDO", 0xFF65));
175*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("A", 0x61));
176*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("a", 0x61));
177*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("ThisKeyShouldNotExist", XKB_KEY_NoSymbol));
178*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("XF86_Switch_vT_5", 0x1008FE05));
179*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("xF86_SwitcH_VT_5", 0x1008FE05));
180*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("xF86SwiTch_VT_5", 0x1008FE05));
181*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("xF86Switch_vt_5", 0x1008FE05));
182*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("VoidSymbol", 0xFFFFFF));
183*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("vOIDsymBol", 0xFFFFFF));
184*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("U4567", 0x1004567));
185*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("u4567", 0x1004567));
186*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("0x10203040", 0x10203040));
187*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("0X10203040", 0x10203040));
188*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("THORN", 0x00fe));
189*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("Thorn", 0x00fe));
190*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("thorn", 0x00fe));
191*2b949d04SAndroid Build Coastguard Worker 
192*2b949d04SAndroid Build Coastguard Worker     assert(test_string("", XKB_KEY_NoSymbol));
193*2b949d04SAndroid Build Coastguard Worker     assert(test_casestring("", XKB_KEY_NoSymbol));
194*2b949d04SAndroid Build Coastguard Worker 
195*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_y, "y"));
196*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_u, "u"));
197*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_m, "m"));
198*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_Cyrillic_em, "м"));
199*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_Cyrillic_u, "у"));
200*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_exclam, "!"));
201*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_oslash, "ø"));
202*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_hebrew_aleph, "א"));
203*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_Arabic_sheen, "ش"));
204*2b949d04SAndroid Build Coastguard Worker 
205*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_space, " "));
206*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_KP_Space, " "));
207*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_BackSpace, "\b"));
208*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_Escape, "\033"));
209*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_KP_Separator, ","));
210*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_KP_Decimal, "."));
211*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_Tab, "\t"));
212*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_KP_Tab, "\t"));
213*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_hyphen, "­"));
214*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_Linefeed, "\n"));
215*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_Return, "\r"));
216*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_KP_Enter, "\r"));
217*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_KP_Equal, "="));
218*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_9, "9"));
219*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_KP_9, "9"));
220*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_KP_Multiply, "*"));
221*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(XKB_KEY_KP_Subtract, "-"));
222*2b949d04SAndroid Build Coastguard Worker 
223*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(0x10005d0, "א"));
224*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(0x110ffff, "\xf4\x8f\xbf\xbf"));
225*2b949d04SAndroid Build Coastguard Worker     assert(test_utf8(0x1110000, NULL) == 0);
226*2b949d04SAndroid Build Coastguard Worker 
227*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('y', XKB_KEY_y));
228*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('u', XKB_KEY_u));
229*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('m', XKB_KEY_m));
230*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0x43c, XKB_KEY_Cyrillic_em));
231*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0x443, XKB_KEY_Cyrillic_u));
232*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('!', XKB_KEY_exclam));
233*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0xF8, XKB_KEY_oslash));
234*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0x5D0, XKB_KEY_hebrew_aleph));
235*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0x634, XKB_KEY_Arabic_sheen));
236*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0x1F609, 0x0101F609)); // ;) emoji
237*2b949d04SAndroid Build Coastguard Worker 
238*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('\b', XKB_KEY_BackSpace));
239*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('\t', XKB_KEY_Tab));
240*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('\n', XKB_KEY_Linefeed));
241*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0x0b, XKB_KEY_Clear));
242*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('\r', XKB_KEY_Return));
243*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0x1b, XKB_KEY_Escape));
244*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0x7f, XKB_KEY_Delete));
245*2b949d04SAndroid Build Coastguard Worker 
246*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(' ', XKB_KEY_space));
247*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(',', XKB_KEY_comma));
248*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('.', XKB_KEY_period));
249*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('=', XKB_KEY_equal));
250*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('9', XKB_KEY_9));
251*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('*', XKB_KEY_asterisk));
252*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0xd7, XKB_KEY_multiply));
253*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym('-', XKB_KEY_minus));
254*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0x10fffd, 0x110fffd));
255*2b949d04SAndroid Build Coastguard Worker 
256*2b949d04SAndroid Build Coastguard Worker     // Unicode non-characters
257*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0xfdd0, XKB_KEY_NoSymbol));
258*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0xfdef, XKB_KEY_NoSymbol));
259*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0xfffe, XKB_KEY_NoSymbol));
260*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0xffff, XKB_KEY_NoSymbol));
261*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0x7fffe, XKB_KEY_NoSymbol));
262*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0x7ffff, XKB_KEY_NoSymbol));
263*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0xafffe, XKB_KEY_NoSymbol));
264*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0xaffff, XKB_KEY_NoSymbol));
265*2b949d04SAndroid Build Coastguard Worker 
266*2b949d04SAndroid Build Coastguard Worker     // Codepoints outside the Unicode planes
267*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0x110000, XKB_KEY_NoSymbol));
268*2b949d04SAndroid Build Coastguard Worker     assert(test_utf32_to_keysym(0xdeadbeef, XKB_KEY_NoSymbol));
269*2b949d04SAndroid Build Coastguard Worker 
270*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_is_lower(XKB_KEY_a));
271*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_is_lower(XKB_KEY_Greek_lambda));
272*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_is_lower(xkb_keysym_from_name("U03b1", 0))); /* GREEK SMALL LETTER ALPHA */
273*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_is_lower(xkb_keysym_from_name("U03af", 0))); /* GREEK SMALL LETTER IOTA WITH TONOS */
274*2b949d04SAndroid Build Coastguard Worker 
275*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_is_upper(XKB_KEY_A));
276*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_is_upper(XKB_KEY_Greek_LAMBDA));
277*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_is_upper(xkb_keysym_from_name("U0391", 0))); /* GREEK CAPITAL LETTER ALPHA */
278*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_is_upper(xkb_keysym_from_name("U0388", 0))); /* GREEK CAPITAL LETTER EPSILON WITH TONOS */
279*2b949d04SAndroid Build Coastguard Worker 
280*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_upper(XKB_KEY_a));
281*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_lower(XKB_KEY_A));
282*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_lower(XKB_KEY_Return));
283*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_upper(XKB_KEY_Return));
284*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_lower(XKB_KEY_hebrew_aleph));
285*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_upper(XKB_KEY_hebrew_aleph));
286*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_upper(xkb_keysym_from_name("U05D0", 0))); /* HEBREW LETTER ALEF */
287*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_lower(xkb_keysym_from_name("U05D0", 0))); /* HEBREW LETTER ALEF */
288*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_lower(XKB_KEY_8));
289*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_upper(XKB_KEY_8));
290*2b949d04SAndroid Build Coastguard Worker 
291*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_is_keypad(XKB_KEY_KP_Enter));
292*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_is_keypad(XKB_KEY_KP_6));
293*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_is_keypad(XKB_KEY_KP_Add));
294*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_keypad(XKB_KEY_Num_Lock));
295*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_keypad(XKB_KEY_1));
296*2b949d04SAndroid Build Coastguard Worker     assert(!xkb_keysym_is_keypad(XKB_KEY_Return));
297*2b949d04SAndroid Build Coastguard Worker 
298*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_upper(XKB_KEY_a) == XKB_KEY_A);
299*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_upper(XKB_KEY_A) == XKB_KEY_A);
300*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_lower(XKB_KEY_a) == XKB_KEY_a);
301*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_lower(XKB_KEY_A) == XKB_KEY_a);
302*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_upper(XKB_KEY_Return) == XKB_KEY_Return);
303*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_lower(XKB_KEY_Return) == XKB_KEY_Return);
304*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_upper(XKB_KEY_Greek_lambda) == XKB_KEY_Greek_LAMBDA);
305*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_upper(XKB_KEY_Greek_LAMBDA) == XKB_KEY_Greek_LAMBDA);
306*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_lower(XKB_KEY_Greek_lambda) == XKB_KEY_Greek_lambda);
307*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_lower(XKB_KEY_Greek_LAMBDA) == XKB_KEY_Greek_lambda);
308*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_upper(XKB_KEY_eacute) == XKB_KEY_Eacute);
309*2b949d04SAndroid Build Coastguard Worker     assert(xkb_keysym_to_lower(XKB_KEY_Eacute) == XKB_KEY_eacute);
310*2b949d04SAndroid Build Coastguard Worker 
311*2b949d04SAndroid Build Coastguard Worker     test_github_issue_42();
312*2b949d04SAndroid Build Coastguard Worker 
313*2b949d04SAndroid Build Coastguard Worker     return 0;
314*2b949d04SAndroid Build Coastguard Worker }
315