x11.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright © 2013 Ran Benita <ran234@gmail.com>
  3. * SPDX-License-Identifier: MIT
  4. */
  5. #include "config.h"
  6. #include "test-config.h"
  7. #include <stdlib.h>
  8. #include "test.h"
  9. #include "xvfb-wrapper.h"
  10. #include "xkbcommon/xkbcommon-x11.h"
  11. X11_TEST(test_basic)
  12. {
  13. struct xkb_context *ctx = test_get_context(CONTEXT_NO_FLAG);
  14. xcb_connection_t *conn;
  15. int ret;
  16. int32_t device_id;
  17. struct xkb_keymap *keymap;
  18. struct xkb_state *state;
  19. char *dump;
  20. int exit_code = EXIT_SUCCESS;
  21. /*
  22. * The next two steps depend on a running X server with XKB support.
  23. * If it fails, it's not necessarily an actual problem with the code.
  24. * So we don't want a FAIL here.
  25. */
  26. conn = xcb_connect(display, NULL);
  27. if (!conn || xcb_connection_has_error(conn)) {
  28. exit_code = TEST_SETUP_FAILURE;
  29. goto err_conn;
  30. }
  31. /* Reject invalid flags */
  32. assert(!xkb_x11_setup_xkb_extension(conn,
  33. XKB_X11_MIN_MAJOR_XKB_VERSION,
  34. XKB_X11_MIN_MINOR_XKB_VERSION,
  35. -1, NULL, NULL, NULL, NULL));
  36. assert(!xkb_x11_setup_xkb_extension(conn,
  37. XKB_X11_MIN_MAJOR_XKB_VERSION,
  38. XKB_X11_MIN_MINOR_XKB_VERSION,
  39. 0xffff, NULL, NULL, NULL, NULL));
  40. ret = xkb_x11_setup_xkb_extension(conn,
  41. XKB_X11_MIN_MAJOR_XKB_VERSION,
  42. XKB_X11_MIN_MINOR_XKB_VERSION,
  43. XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS,
  44. NULL, NULL, NULL, NULL);
  45. if (!ret) {
  46. exit_code = TEST_SETUP_FAILURE;
  47. goto err_conn;
  48. }
  49. device_id = xkb_x11_get_core_keyboard_device_id(conn);
  50. assert(device_id != -1);
  51. keymap = xkb_x11_keymap_new_from_device(ctx, conn, device_id,
  52. TEST_KEYMAP_COMPILE_FLAGS);
  53. assert(keymap);
  54. state = xkb_x11_state_new_from_device(keymap, conn, device_id);
  55. assert(state);
  56. dump = xkb_keymap_get_as_string(keymap, XKB_KEYMAP_USE_ORIGINAL_FORMAT);
  57. assert(dump);
  58. fputs(dump, stdout);
  59. /* TODO: Write some X11-specific tests. */
  60. free(dump);
  61. xkb_state_unref(state);
  62. xkb_keymap_unref(keymap);
  63. err_conn:
  64. xcb_disconnect(conn);
  65. xkb_context_unref(ctx);
  66. return exit_code;
  67. }
  68. int main(void) {
  69. test_init();
  70. return x11_tests_run();
  71. }