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.
27 test_string(const char *string, xkb_keysym_t expected)
31 keysym = xkb_keysym_from_name(string);
33 fprintf(stderr, "Expected string %s -> %x\n", string, expected);
34 fprintf(stderr, "Received string %s -> %x\n\n", string, keysym);
36 return keysym == expected;
40 test_keysym(xkb_keysym_t keysym, const char *expected)
44 xkb_keysym_get_name(keysym, s, sizeof(s));
46 fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
47 fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
49 return streq(s, expected);
53 test_utf8(xkb_keysym_t keysym, const char *expected)
58 ret = xkb_keysym_to_utf8(keysym, s, sizeof(s));
62 fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
63 fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
65 return streq(s, expected);
71 assert(test_string("Undo", 0xFF65));
72 assert(test_string("ThisKeyShouldNotExist", XKB_KEY_NoSymbol));
73 assert(test_string("XF86_Switch_VT_5", 0x1008FE05));
74 assert(test_string("VoidSymbol", 0xFFFFFF));
75 assert(test_string("U4567", 0x1004567));
76 assert(test_string("0x10203040", 0x10203040));
78 assert(test_keysym(0x1008FF56, "XF86Close"));
79 assert(test_keysym(0x0, "NoSymbol"));
80 assert(test_keysym(0x1008FE20, "XF86Ungrab"));
81 assert(test_keysym(0x01001234, "U1234"));
83 assert(test_utf8(XKB_KEY_y, "y"));
84 assert(test_utf8(XKB_KEY_u, "u"));
85 assert(test_utf8(XKB_KEY_m, "m"));
86 assert(test_utf8(XKB_KEY_Cyrillic_em, "м"));
87 assert(test_utf8(XKB_KEY_Cyrillic_u, "у"));
88 assert(test_utf8(XKB_KEY_exclam, "!"));
89 assert(test_utf8(XKB_KEY_oslash, "ø"));
90 assert(test_utf8(XKB_KEY_hebrew_aleph, "א"));
91 assert(test_utf8(XKB_KEY_Arabic_sheen, "ش"));
93 assert(test_utf8(XKB_KEY_space, " "));
94 assert(test_utf8(XKB_KEY_KP_Space, " "));
95 assert(test_utf8(XKB_KEY_9, "9"));
96 assert(test_utf8(XKB_KEY_KP_9, "9"));
97 assert(test_utf8(XKB_KEY_KP_Multiply, "*"));
98 assert(test_utf8(XKB_KEY_KP_Subtract, "-"));