2 * Copyright © 2009 Dan Nicholson
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.
26 #include "keysym.h" /* For unexported is_lower/upper/keypad() */
29 test_string(const char *string, xkb_keysym_t expected)
33 keysym = xkb_keysym_from_name(string, 0);
35 fprintf(stderr, "Expected string %s -> %x\n", string, expected);
36 fprintf(stderr, "Received string %s -> %x\n\n", string, keysym);
38 return keysym == expected;
42 test_casestring(const char *string, xkb_keysym_t expected)
46 keysym = xkb_keysym_from_name(string, XKB_KEYSYM_CASE_INSENSITIVE);
48 fprintf(stderr, "Expected casestring %s -> %x\n", string, expected);
49 fprintf(stderr, "Received casestring %s -> %x\n\n", string, keysym);
51 return keysym == expected;
55 test_keysym(xkb_keysym_t keysym, const char *expected)
59 xkb_keysym_get_name(keysym, s, sizeof(s));
61 fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
62 fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
64 return streq(s, expected);
68 test_utf8(xkb_keysym_t keysym, const char *expected)
73 ret = xkb_keysym_to_utf8(keysym, s, sizeof(s));
77 fprintf(stderr, "Expected keysym %#x -> %s (%u bytes)\n", keysym, expected,
78 (unsigned) strlen(expected));
79 fprintf(stderr, "Received keysym %#x -> %s (%u bytes)\n\n", keysym, s,
80 (unsigned) strlen(s));
82 return streq(s, expected);
86 test_github_issue_42(void)
88 // Verify we are not dependent on locale, Turkish-i problem in particular.
89 if (setlocale(LC_CTYPE, "tr_TR.UTF-8") == NULL) {
90 // The locale is not available, probably; skip.
94 assert(test_string("i", XKB_KEY_i));
95 assert(test_string("I", XKB_KEY_I));
96 assert(test_casestring("i", XKB_KEY_i));
97 assert(test_casestring("I", XKB_KEY_i));
98 assert(xkb_keysym_to_upper(XKB_KEY_i) == XKB_KEY_I);
99 assert(xkb_keysym_to_lower(XKB_KEY_I) == XKB_KEY_i);
101 setlocale(LC_CTYPE, "C");
107 assert(test_string("Undo", 0xFF65));
108 assert(test_string("ThisKeyShouldNotExist", XKB_KEY_NoSymbol));
109 assert(test_string("XF86_Switch_VT_5", 0x1008FE05));
110 assert(test_string("VoidSymbol", 0xFFFFFF));
111 assert(test_string("U4567", 0x1004567));
112 assert(test_string("0x10203040", 0x10203040));
113 assert(test_string("a", 0x61));
114 assert(test_string("A", 0x41));
115 assert(test_string("ch", 0xfea0));
116 assert(test_string("Ch", 0xfea1));
117 assert(test_string("CH", 0xfea2));
118 assert(test_string("THORN", 0x00de));
119 assert(test_string("Thorn", 0x00de));
120 assert(test_string("thorn", 0x00fe));
122 assert(test_keysym(0x1008FF56, "XF86Close"));
123 assert(test_keysym(0x0, "NoSymbol"));
124 assert(test_keysym(0x1008FE20, "XF86Ungrab"));
125 assert(test_keysym(0x01001234, "U1234"));
126 /* 16-bit unicode padded to width 4. */
127 assert(test_keysym(0x010002DE, "U02DE"));
128 /* 32-bit unicode padded to width 8. */
129 assert(test_keysym(0x0101F4A9, "U0001F4A9"));
131 assert(test_casestring("Undo", 0xFF65));
132 assert(test_casestring("UNDO", 0xFF65));
133 assert(test_casestring("A", 0x61));
134 assert(test_casestring("a", 0x61));
135 assert(test_casestring("ThisKeyShouldNotExist", XKB_KEY_NoSymbol));
136 assert(test_casestring("XF86_Switch_vT_5", 0x1008FE05));
137 assert(test_casestring("xF86_SwitcH_VT_5", 0x1008FE05));
138 assert(test_casestring("xF86SwiTch_VT_5", 0x1008FE05));
139 assert(test_casestring("xF86Switch_vt_5", 0x1008FE05));
140 assert(test_casestring("VoidSymbol", 0xFFFFFF));
141 assert(test_casestring("vOIDsymBol", 0xFFFFFF));
142 assert(test_casestring("U4567", 0x1004567));
143 assert(test_casestring("u4567", 0x1004567));
144 assert(test_casestring("0x10203040", 0x10203040));
145 assert(test_casestring("0X10203040", 0x10203040));
146 assert(test_casestring("THORN", 0x00fe));
147 assert(test_casestring("Thorn", 0x00fe));
148 assert(test_casestring("thorn", 0x00fe));
150 assert(test_utf8(XKB_KEY_y, "y"));
151 assert(test_utf8(XKB_KEY_u, "u"));
152 assert(test_utf8(XKB_KEY_m, "m"));
153 assert(test_utf8(XKB_KEY_Cyrillic_em, "м"));
154 assert(test_utf8(XKB_KEY_Cyrillic_u, "у"));
155 assert(test_utf8(XKB_KEY_exclam, "!"));
156 assert(test_utf8(XKB_KEY_oslash, "ø"));
157 assert(test_utf8(XKB_KEY_hebrew_aleph, "א"));
158 assert(test_utf8(XKB_KEY_Arabic_sheen, "ش"));
160 assert(test_utf8(XKB_KEY_space, " "));
161 assert(test_utf8(XKB_KEY_KP_Space, " "));
162 assert(test_utf8(XKB_KEY_BackSpace, "\b"));
163 assert(test_utf8(XKB_KEY_Escape, "\033"));
164 assert(test_utf8(XKB_KEY_KP_Separator, ","));
165 assert(test_utf8(XKB_KEY_KP_Decimal, "."));
166 assert(test_utf8(XKB_KEY_Tab, "\t"));
167 assert(test_utf8(XKB_KEY_KP_Tab, "\t"));
168 assert(test_utf8(XKB_KEY_hyphen, ""));
169 assert(test_utf8(XKB_KEY_Linefeed, "\n"));
170 assert(test_utf8(XKB_KEY_Return, "\r"));
171 assert(test_utf8(XKB_KEY_KP_Enter, "\r"));
172 assert(test_utf8(XKB_KEY_KP_Equal, "="));
173 assert(test_utf8(XKB_KEY_9, "9"));
174 assert(test_utf8(XKB_KEY_KP_9, "9"));
175 assert(test_utf8(XKB_KEY_KP_Multiply, "*"));
176 assert(test_utf8(XKB_KEY_KP_Subtract, "-"));
178 assert(xkb_keysym_is_lower(XKB_KEY_a));
179 assert(xkb_keysym_is_lower(XKB_KEY_Greek_lambda));
180 assert(xkb_keysym_is_lower(xkb_keysym_from_name("U03b1", 0))); /* GREEK SMALL LETTER ALPHA */
181 assert(xkb_keysym_is_lower(xkb_keysym_from_name("U03af", 0))); /* GREEK SMALL LETTER IOTA WITH TONOS */
183 assert(xkb_keysym_is_upper(XKB_KEY_A));
184 assert(xkb_keysym_is_upper(XKB_KEY_Greek_LAMBDA));
185 assert(xkb_keysym_is_upper(xkb_keysym_from_name("U0391", 0))); /* GREEK CAPITAL LETTER ALPHA */
186 assert(xkb_keysym_is_upper(xkb_keysym_from_name("U0388", 0))); /* GREEK CAPITAL LETTER EPSILON WITH TONOS */
188 assert(!xkb_keysym_is_upper(XKB_KEY_a));
189 assert(!xkb_keysym_is_lower(XKB_KEY_A));
190 assert(!xkb_keysym_is_lower(XKB_KEY_Return));
191 assert(!xkb_keysym_is_upper(XKB_KEY_Return));
192 assert(!xkb_keysym_is_lower(XKB_KEY_hebrew_aleph));
193 assert(!xkb_keysym_is_upper(XKB_KEY_hebrew_aleph));
194 assert(!xkb_keysym_is_upper(xkb_keysym_from_name("U05D0", 0))); /* HEBREW LETTER ALEF */
195 assert(!xkb_keysym_is_lower(xkb_keysym_from_name("U05D0", 0))); /* HEBREW LETTER ALEF */
196 assert(!xkb_keysym_is_lower(XKB_KEY_8));
197 assert(!xkb_keysym_is_upper(XKB_KEY_8));
199 assert(xkb_keysym_is_keypad(XKB_KEY_KP_Enter));
200 assert(xkb_keysym_is_keypad(XKB_KEY_KP_6));
201 assert(xkb_keysym_is_keypad(XKB_KEY_KP_Add));
202 assert(!xkb_keysym_is_keypad(XKB_KEY_Num_Lock));
203 assert(!xkb_keysym_is_keypad(XKB_KEY_1));
204 assert(!xkb_keysym_is_keypad(XKB_KEY_Return));
206 assert(xkb_keysym_to_upper(XKB_KEY_a) == XKB_KEY_A);
207 assert(xkb_keysym_to_upper(XKB_KEY_A) == XKB_KEY_A);
208 assert(xkb_keysym_to_lower(XKB_KEY_a) == XKB_KEY_a);
209 assert(xkb_keysym_to_lower(XKB_KEY_A) == XKB_KEY_a);
210 assert(xkb_keysym_to_upper(XKB_KEY_Return) == XKB_KEY_Return);
211 assert(xkb_keysym_to_lower(XKB_KEY_Return) == XKB_KEY_Return);
212 assert(xkb_keysym_to_upper(XKB_KEY_Greek_lambda) == XKB_KEY_Greek_LAMBDA);
213 assert(xkb_keysym_to_upper(XKB_KEY_Greek_LAMBDA) == XKB_KEY_Greek_LAMBDA);
214 assert(xkb_keysym_to_lower(XKB_KEY_Greek_lambda) == XKB_KEY_Greek_lambda);
215 assert(xkb_keysym_to_lower(XKB_KEY_Greek_LAMBDA) == XKB_KEY_Greek_lambda);
216 assert(xkb_keysym_to_upper(XKB_KEY_eacute) == XKB_KEY_Eacute);
217 assert(xkb_keysym_to_lower(XKB_KEY_Eacute) == XKB_KEY_eacute);
219 test_github_issue_42();