diff options
author | Christoph Reimann <oss@arcor.de> | 2010-08-16 18:11:40 +0200 |
---|---|---|
committer | Christoph Reimann <oss@arcor.de> | 2010-08-16 18:11:40 +0200 |
commit | 77f4c8a0ad5962be7033228c7147228dce4035fb (patch) | |
tree | 07e3b0ceb86587c4b8821b3ffcaa87cf16621905 | |
parent | 541e038d6656008bd0f038eafc2b73b43d8d738d (diff) |
-rw-r--r-- | check_xkb.c | 153 | ||||
-rw-r--r-- | xkb_util.c | 40 | ||||
-rw-r--r-- | xkb_util.h | 9 |
3 files changed, 197 insertions, 5 deletions
diff --git a/check_xkb.c b/check_xkb.c index 20b0b18..179ff13 100644 --- a/check_xkb.c +++ b/check_xkb.c @@ -3,10 +3,8 @@ #include <stdio.h> #include <X11/XKBlib.h> -#include <X11/Xlibint.h> #include "xkb_util.h" -#include <xcb/xcb_event.h> #include <check.h> @@ -40,6 +38,7 @@ START_TEST(check_xkb_get_names_request) "Xlib: XkbGetNames() failed\n"); /* check if serialize and unpack work properly */ + printf(" testing serialize & unpack for switch with variable fields\n"); names_buffer = xcb_xkb_get_names_value_list(get_names_reply); l0 = xcb_xkb_get_names_value_list_unpack (names_buffer, get_names_reply->nTypes, @@ -78,6 +77,7 @@ START_TEST(check_xkb_get_names_request) xlib_result = p; xcb_result = names; /* 1. check fixed size fields */ + printf(" checking fixed size fields\n"); fail_unless(xcb_result.keycodesName == xlib_result->names->keycodes, NULL); fail_unless(xcb_result.geometryName == xlib_result->names->geometry, NULL); fail_unless(xcb_result.symbolsName == xlib_result->names->symbols, NULL); @@ -89,6 +89,7 @@ START_TEST(check_xkb_get_names_request) /* typeNames */ length = xcb_xkb_get_names_value_list_type_names_length(get_names_reply, &xcb_result); + printf(" checking typenames (%d items)\n", length); fail_unless(length == xlib_result->map->num_types, NULL); for(i=0; i<length; i++) { fail_unless(xcb_result.typeNames[i] == xlib_result->map->types[i].name, NULL); @@ -97,6 +98,7 @@ START_TEST(check_xkb_get_names_request) /* ktLevelNames - the length of the list is calculated with sumof */ length = xcb_xkb_get_names_value_list_n_levels_per_type_length(get_names_reply, &xcb_result); + printf(" checking ktLevelNames (%d items), special case: sumof expression\n", length); fail_unless(length == xlib_result->map->num_types, NULL); idx = 0; for(i=0; i<length; i++) { @@ -109,6 +111,7 @@ START_TEST(check_xkb_get_names_request) /* groups */ length = xcb_xkb_get_names_value_list_groups_length(get_names_reply, &xcb_result); + printf(" checking groups (%d items)\n", length); // the number of elements is calculated on-the-fly in Xlib (see _XkbReadAtoms) for(i=0; i<length; i++) { fail_unless(xcb_result.groups[i] == xlib_result->names->groups[i], NULL); @@ -116,6 +119,7 @@ START_TEST(check_xkb_get_names_request) /* keyAliases */ length = xcb_xkb_get_names_value_list_key_aliases_length(get_names_reply, &xcb_result); + printf(" checking keyAliases (%d items)\n", length); fail_unless(length == xlib_result->names->num_key_aliases); for(i=0; i<length; i++) { for(j=0; j<4; j++) { @@ -123,6 +127,149 @@ START_TEST(check_xkb_get_names_request) fail_unless(xcb_result.keyAliases[i].alias[j] == xlib_result->names->key_aliases[i].alias[j]); } } + + XCloseDisplay (d); + xcb_disconnect (c); + + printf("... done!\n\n"); +} +END_TEST + +/* + * check the result of issuing a GetKbdByName request with Xlib and xcb + * test for special case: nested switch statements + */ +START_TEST(check_xkb_get_kbd_by_name_request) +{ + /* xcb */ + xcb_connection_t *c; + xcb_generic_error_t *e = NULL; + xcb_xkb_use_extension_reply_t *reply; + xcb_xkb_get_kbd_by_name_request_t aux, *aux_p; + xcb_xkb_get_kbd_by_name_cookie_t cookie; + xcb_xkb_get_kbd_by_name_reply_t *get_kbd_reply; + xcb_xkb_get_kbd_by_name_replies_t names = {0}; + xcb_xkb_key_type_iterator_t iter; + void *buffer = NULL; + char *buf = NULL; + int l0, l1, l2, i, j, idx, length; + + /* Xlib */ + Display *d = XkbOpenDisplay(NULL, 0, 0, 0, 0, 0); + XkbDescPtr xlib_result = XkbGetKeyboardByName(d, XkbUseCoreKbd, NULL, + //XkbGBN_AllComponentsMask, + //XkbGBN_AllComponentsMask, + XkbGBN_TypesMask, XkbGBN_TypesMask, + False); + fail_if(0 == xlib_result, "Xlib: XkbGetKeyboardByName() failed\n"); + + printf("checking the GetKbdByName request (xcb vs. Xlib)\n"); + + c = xcb_connect (NULL, NULL); + reply = xcb_xkb_util_query_extension(c, 1, 0, &e); + fail_if(e != NULL, "xcb: cannot initialize XKB!?\n"); + + /* in the protocol description, variable size fields are followed by fixed size fields + in the request, no switch is involved */ + aux.deviceSpec = XCB_XKB_ID_USE_CORE_KBD ; + aux.need = xcb_xkb_util_all_gbn_details_mask; + aux.want = xcb_xkb_util_all_gbn_details_mask; + aux.load = 0; + aux.pad0 = 0; + aux.keymapsSpecLen = 0; + aux.keycodesSpecLen = 0; + aux.typesSpecLen = 0; + aux.compatMapSpecLen = 0; + aux.symbolsSpecLen = 0; + aux.geometrySpecLen = 0; + aux_p = &aux; + + printf(" testing serialize/unserialize/sizeof for special case: intermixed variable and fixed size fields\n"); + l0 = xcb_xkb_get_kbd_by_name_serialize(&buffer, &aux, 0, 0, 0, 0, 0, 0); + l1 = xcb_xkb_get_kbd_by_name_unserialize (buffer, &aux_p); + l2 = xcb_xkb_get_kbd_by_name_sizeof(buffer); + fail_unless(l0 == l1, "unserializing a previously serialized data type gives a different buffer length!"); + fail_unless(l0 == l2, "applying sizeof on a previously serialized data type gives a different buffer length!"); + + /* compare the structs bytewise */ + for (i=0; i<l0; i++) { + /* printf(" %d vs. %d\n", ((char *)&aux)[i], ((char *)aux_p)[i]); */ + fail_unless(((char *)&aux)[i] == ((char *)aux_p)[i], + "unserialized structure differs from previously serialized one!"); + } + free(buffer); + buffer = NULL; + l2 = xcb_xkb_get_kbd_by_name_serialize(&buffer, &aux, 0, 0, 0, 0, 0, 0); + free(buffer); + buffer = NULL; + fail_unless(l0 == l2, "serializing a previously unserialized data type gives a different buffer length!"); + + /* explicitly perform the GetKbdByName request */ + printf(" checking request & reply for special case: nested switch statements\n"); + cookie = xcb_xkb_get_kbd_by_name (c, XCB_XKB_ID_USE_CORE_KBD, + XCB_XKB_GBN_DETAIL_TYPES, XCB_XKB_GBN_DETAIL_TYPES, + //xcb_xkb_util_all_gbn_details_mask, xcb_xkb_util_all_gbn_details_mask, + 0, /* load */ + 0, /* keymapsSpecLen */ + 0, /* keymapsSpec */ + 0, /* keycodesSpecLen */ + 0, /* keycodesSpec */ + 0, /* typesSpecLen */ + 0, /* typesSpec */ + 0, /* compatMapSpecLen */ + 0, /* compatMapSpec */ + 0, /* symbolsSpecLen */ + 0, /* symbolsSpec */ + 0, /* geometrySpecLen */ + 0 /* geometrySpec */); + get_kbd_reply = xcb_xkb_get_kbd_by_name_reply (c, cookie, &e); + fail_if(e != NULL, "xcb: xcb_xkb_get_kbd_by_name() failed\n"); + + printf(" reply->length: %d (xcb)\n", get_kbd_reply->length); + + buffer = xcb_xkb_get_kbd_by_name_replies (get_kbd_reply); + l0 = xcb_xkb_get_kbd_by_name_replies_unpack (buffer, get_kbd_reply->reported, &names); + + if (get_kbd_reply->reported & XCB_XKB_GBN_DETAIL_TYPES) { + printf(" checking bitcase replies.types (xcb: nTypes=%d, l0=%d)\n", names.types.nTypes, l0); + fail_unless(xlib_result->device_spec == names.types.typeDeviceID, + "device_specs differ\n"); + fail_unless(xlib_result->min_key_code == names.types.typeMinKeyCode, + "min_key_code differs\n"); + fail_unless(xlib_result->max_key_code == names.types.typeMaxKeyCode, + "max_key_code differs\n"); + printf(" contents of some fields: (should be small integers, please 'check by inspection')\n"); + printf(" present: %d\n", names.types.present); + printf(" first_type %d\n", names.types.firstType); + printf(" nTypes: %d\n", names.types.nTypes); + printf(" totalTypes: %d\n", names.types.totalTypes); + printf(" totalVModMapKeys: %d\n", names.types.totalVModMapKeys); + + /* + buf = (char *)buffer; + for(i=0; i<200; i++) + printf(" %d: %d\n", i, buf[i]); + */ + + iter = xcb_xkb_get_map_map_types_rtrn_iterator((xcb_xkb_get_map_reply_t *)&names.types, &names.types.map); + l1 = xcb_xkb_get_map_map_types_rtrn_length((xcb_xkb_get_map_reply_t *)&names.types, &names.types.map); + printf(" checking bitcase replies.types.map.types_rtrn (%d items)\n", l1); + for(i=0; i<l1; i++) { + XkbKeyTypePtr xlib_type = &xlib_result->map->types[i]; + xcb_xkb_key_type_t *xcb_type = iter.data; + fail_unless(xlib_type->mods.mask == xcb_type->mods_mask); + fail_unless(xlib_type->mods.real_mods == xcb_type->mods_mods); + fail_unless(xlib_type->mods.vmods == xcb_type->mods_vmods); + fail_unless(xlib_type->num_levels == xcb_type->numLevels); + fail_unless(xlib_type->map_count == xcb_type->nMapEntries); + fail_unless((0!=xlib_type->preserve) == xcb_type->hasPreserve); + xcb_xkb_key_type_next(&iter); + } +} + XCloseDisplay (d); + xcb_disconnect (c); + + printf("... done!\n\n"); } END_TEST @@ -134,6 +281,7 @@ xkb_test_suite (void) /* Core test case */ TCase *tc_core = tcase_create ("Core"); tcase_add_test (tc_core, check_xkb_get_names_request); + tcase_add_test (tc_core, check_xkb_get_kbd_by_name_request); suite_add_tcase (s, tc_core); return s; @@ -152,3 +300,4 @@ main (void) printf("\n"); return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } + @@ -4,7 +4,9 @@ /* // check compile time library version int -xcb_xkb_util_library_version(int *lib_major_in_out, int *lib_minor_in_out); +xcb_xkb_util_library_version(int *lib_major_in_out, int *lib_minor_in_out) { + +} */ xcb_xkb_use_extension_reply_t * @@ -172,5 +174,41 @@ xcb_xkb_util_get_map(xcb_connection_t *c, reply->totalKeyExplicit, reply->totalModMapKeys, reply->totalVModMapKeys, reply->present, _aux); } + + return reply; +} + +xcb_xkb_get_kbd_by_name_reply_t * +xcb_xkb_util_get_kbd_by_name (xcb_connection_t *c, + xcb_xkb_device_spec_t device_spec, + uint16_t need, + uint16_t want, + xcb_xkb_get_kbd_by_name_replies_t *_aux, + xcb_generic_error_t **e) { + xcb_xkb_get_kbd_by_name_cookie_t cookie; + xcb_xkb_get_kbd_by_name_reply_t *reply; + void *buffer; + + cookie = xcb_xkb_get_kbd_by_name (c, device_spec, need, want, + 0, /* load */ + 0, /* keymapsSpecLen */ + 0, /* keymapsSpec */ + 0, /* keycodesSpecLen */ + 0, /* keycodesSpec */ + 0, /* typesSpecLen */ + 0, /* typesSpec */ + 0, /* compatMapSpecLen */ + 0, /* compatMapSpec */ + 0, /* symbolsSpecLen */ + 0, /* symbolsSpec */ + 0, /* geometrySpecLen */ + 0 /* geometrySpec */); + reply = xcb_xkb_get_kbd_by_name_reply (c, cookie, e); + + if (!(*e)) { + buffer = xcb_xkb_get_kbd_by_name_replies (reply); + xcb_xkb_get_kbd_by_name_replies_unpack (buffer, reply->reported, _aux); + } + return reply; } @@ -7,9 +7,8 @@ #define xcb_xkb_util_all_client_map_parts_mask (XCB_XKB_MAP_PART_KEY_TYPES | XCB_XKB_MAP_PART_KEY_SYMS | XCB_XKB_MAP_PART_MODIFIER_MAP) #define xcb_xkb_util_all_server_map_parts_mask (XCB_XKB_MAP_PART_EXPLICIT_COMPONENTS | XCB_XKB_MAP_PART_KEY_ACTIONS | XCB_XKB_MAP_PART_KEY_BEHAVIORS | XCB_XKB_MAP_PART_VIRTUAL_MODS | XCB_XKB_MAP_PART_VIRTUAL_MOD_MAP) #define xcb_xkb_util_all_map_parts_mask (xcb_xkb_util_all_client_map_parts_mask|xcb_xkb_util_all_server_map_parts_mask) - #define xcb_xkb_util_all_name_details_mask (XCB_XKB_NAME_DETAIL_KEYCODES | XCB_XKB_NAME_DETAIL_GEOMETRY | XCB_XKB_NAME_DETAIL_SYMBOLS | XCB_XKB_NAME_DETAIL_PHYS_SYMBOLS | XCB_XKB_NAME_DETAIL_TYPES | XCB_XKB_NAME_DETAIL_COMPAT | XCB_XKB_NAME_DETAIL_KEY_TYPE_NAMES | XCB_XKB_NAME_DETAIL_KT_LEVEL_NAMES | XCB_XKB_NAME_DETAIL_INDICATOR_NAMES | XCB_XKB_NAME_DETAIL_KEY_NAMES | XCB_XKB_NAME_DETAIL_KEY_ALIASES | XCB_XKB_NAME_DETAIL_VIRTUAL_MOD_NAMES | XCB_XKB_NAME_DETAIL_GROUP_NAMES | XCB_XKB_NAME_DETAIL_RG_NAMES) - +#define xcb_xkb_util_all_gbn_details_mask (XCB_XKB_GBN_DETAIL_TYPES | XCB_XKB_GBN_DETAIL_COMPAT_MAP | XCB_XKB_GBN_DETAIL_CLIENT_SYMBOLS | XCB_XKB_GBN_DETAIL_SERVER_SYMBOLS | XCB_XKB_GBN_DETAIL_INDICATOR_MAPS | XCB_XKB_GBN_DETAIL_KEY_NAMES | XCB_XKB_GBN_DETAIL_GEOMETRY | XCB_XKB_GBN_DETAIL_OTHER_NAMES) xcb_xkb_use_extension_reply_t * xcb_xkb_util_query_extension(xcb_connection_t *c, @@ -33,4 +32,10 @@ xcb_xkb_get_map_reply_t * xcb_xkb_util_get_map(xcb_connection_t *c, uint16_t map_components, xcb_xkb_get_map_map_t *_aux, xcb_generic_error_t **e); +xcb_xkb_get_kbd_by_name_reply_t * xcb_xkb_util_get_kbd_by_name (xcb_connection_t *c, + xcb_xkb_device_spec_t device_spec, + uint16_t need, + uint16_t want, + xcb_xkb_get_kbd_by_name_replies_t *_aux, + xcb_generic_error_t **e); #endif |