2012-09-12 09:54:07 -06:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2009 Dan Nicholson
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-07-24 10:54:14 -06:00
|
|
|
|
#include "test.h"
|
2012-03-30 17:44:39 -06:00
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
test_string(const char *string, xkb_keysym_t expected)
|
2009-01-20 19:57:22 -07:00
|
|
|
|
{
|
2012-03-30 17:44:39 -06:00
|
|
|
|
xkb_keysym_t keysym;
|
|
|
|
|
|
2012-05-09 06:22:34 -06:00
|
|
|
|
keysym = xkb_keysym_from_name(string);
|
2012-03-30 17:44:39 -06:00
|
|
|
|
|
|
|
|
|
fprintf(stderr, "Expected string %s -> %x\n", string, expected);
|
|
|
|
|
fprintf(stderr, "Received string %s -> %x\n\n", string, keysym);
|
|
|
|
|
|
|
|
|
|
return keysym == expected;
|
2009-01-20 19:57:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-30 17:44:39 -06:00
|
|
|
|
static int
|
|
|
|
|
test_keysym(xkb_keysym_t keysym, const char *expected)
|
2009-01-20 19:57:22 -07:00
|
|
|
|
{
|
2010-10-08 13:33:18 -06:00
|
|
|
|
char s[16];
|
|
|
|
|
|
2012-05-09 06:22:34 -06:00
|
|
|
|
xkb_keysym_get_name(keysym, s, sizeof(s));
|
2012-03-30 17:44:39 -06:00
|
|
|
|
|
|
|
|
|
fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
|
|
|
|
|
fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
|
|
|
|
|
|
2012-07-24 10:54:14 -06:00
|
|
|
|
return streq(s, expected);
|
2009-01-20 19:57:22 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 06:10:28 -06:00
|
|
|
|
static int
|
|
|
|
|
test_utf8(xkb_keysym_t keysym, const char *expected)
|
|
|
|
|
{
|
|
|
|
|
char s[8];
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
ret = xkb_keysym_to_utf8(keysym, s, sizeof(s));
|
|
|
|
|
if (ret <= 0)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "Expected keysym %#x -> %s\n", keysym, expected);
|
|
|
|
|
fprintf(stderr, "Received keysym %#x -> %s\n\n", keysym, s);
|
|
|
|
|
|
2012-07-24 10:54:14 -06:00
|
|
|
|
return streq(s, expected);
|
2012-06-08 06:10:28 -06:00
|
|
|
|
}
|
|
|
|
|
|
2012-03-30 17:44:39 -06:00
|
|
|
|
int
|
|
|
|
|
main(void)
|
2009-01-20 19:57:22 -07:00
|
|
|
|
{
|
2012-03-30 17:44:39 -06:00
|
|
|
|
assert(test_string("Undo", 0xFF65));
|
2012-05-09 07:05:00 -06:00
|
|
|
|
assert(test_string("ThisKeyShouldNotExist", XKB_KEY_NoSymbol));
|
2012-03-30 17:44:39 -06:00
|
|
|
|
assert(test_string("XF86_Switch_VT_5", 0x1008FE05));
|
|
|
|
|
assert(test_string("VoidSymbol", 0xFFFFFF));
|
|
|
|
|
assert(test_string("U4567", 0x1004567));
|
|
|
|
|
assert(test_string("0x10203040", 0x10203040));
|
|
|
|
|
|
|
|
|
|
assert(test_keysym(0x1008FF56, "XF86Close"));
|
|
|
|
|
assert(test_keysym(0x0, "NoSymbol"));
|
|
|
|
|
assert(test_keysym(0x1008FE20, "XF86Ungrab"));
|
|
|
|
|
assert(test_keysym(0x01001234, "U1234"));
|
2009-01-20 19:57:22 -07:00
|
|
|
|
|
2012-06-08 06:10:28 -06:00
|
|
|
|
assert(test_utf8(XKB_KEY_y, "y"));
|
|
|
|
|
assert(test_utf8(XKB_KEY_u, "u"));
|
|
|
|
|
assert(test_utf8(XKB_KEY_m, "m"));
|
|
|
|
|
assert(test_utf8(XKB_KEY_Cyrillic_em, "м"));
|
|
|
|
|
assert(test_utf8(XKB_KEY_Cyrillic_u, "у"));
|
|
|
|
|
assert(test_utf8(XKB_KEY_exclam, "!"));
|
|
|
|
|
assert(test_utf8(XKB_KEY_oslash, "ø"));
|
|
|
|
|
assert(test_utf8(XKB_KEY_hebrew_aleph, "א"));
|
|
|
|
|
assert(test_utf8(XKB_KEY_Arabic_sheen, "ش"));
|
|
|
|
|
|
2012-06-08 07:54:31 -06:00
|
|
|
|
assert(test_utf8(XKB_KEY_space, " "));
|
|
|
|
|
assert(test_utf8(XKB_KEY_KP_Space, " "));
|
|
|
|
|
assert(test_utf8(XKB_KEY_9, "9"));
|
|
|
|
|
assert(test_utf8(XKB_KEY_KP_9, "9"));
|
|
|
|
|
assert(test_utf8(XKB_KEY_KP_Multiply, "*"));
|
|
|
|
|
assert(test_utf8(XKB_KEY_KP_Subtract, "-"));
|
|
|
|
|
|
2009-01-20 19:57:22 -07:00
|
|
|
|
return 0;
|
|
|
|
|
}
|