Debian Codegraph @

test/x11.c

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