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.
31 test_string(const char *string, xkb_keysym_t expected)
35 keysym = xkb_keysym_from_name(string);
37 fprintf(stderr, "Expected string %s -> %x\n", string, expected);
38 fprintf(stderr, "Received string %s -> %x\n\n", string, keysym);
40 return keysym == expected;
44 test_keysym(xkb_keysym_t keysym, const char *expected)
48 xkb_keysym_get_name(keysym, s, sizeof(s));
50 fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
51 fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
53 return streq(s, expected);
57 test_utf8(xkb_keysym_t keysym, const char *expected)
62 ret = xkb_keysym_to_utf8(keysym, s, sizeof(s));
66 fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
67 fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
69 return streq(s, expected);
75 assert(test_string("Undo", 0xFF65));
76 assert(test_string("ThisKeyShouldNotExist", XKB_KEY_NoSymbol));
77 assert(test_string("XF86_Switch_VT_5", 0x1008FE05));
78 assert(test_string("VoidSymbol", 0xFFFFFF));
79 assert(test_string("U4567", 0x1004567));
80 assert(test_string("0x10203040", 0x10203040));
82 assert(test_keysym(0x1008FF56, "XF86Close"));
83 assert(test_keysym(0x0, "NoSymbol"));
84 assert(test_keysym(0x1008FE20, "XF86Ungrab"));
85 assert(test_keysym(0x01001234, "U1234"));
87 assert(test_utf8(XKB_KEY_y, "y"));
88 assert(test_utf8(XKB_KEY_u, "u"));
89 assert(test_utf8(XKB_KEY_m, "m"));
90 assert(test_utf8(XKB_KEY_Cyrillic_em, "м"));
91 assert(test_utf8(XKB_KEY_Cyrillic_u, "у"));
92 assert(test_utf8(XKB_KEY_exclam, "!"));
93 assert(test_utf8(XKB_KEY_oslash, "ø"));
94 assert(test_utf8(XKB_KEY_hebrew_aleph, "א"));
95 assert(test_utf8(XKB_KEY_Arabic_sheen, "ش"));
97 assert(test_utf8(XKB_KEY_space, " "));
98 assert(test_utf8(XKB_KEY_KP_Space, " "));
99 assert(test_utf8(XKB_KEY_9, "9"));
100 assert(test_utf8(XKB_KEY_KP_9, "9"));
101 assert(test_utf8(XKB_KEY_KP_Multiply, "*"));
102 assert(test_utf8(XKB_KEY_KP_Subtract, "-"));