vinix-ports / tests / xcb / display.v
46 lines · 39 sloc · 1.14 KB · 204abb14b4b4dc15f0d1ed14ce09b0de8105d076
Raw
1// Exercise the installed client libraries without requiring a display server.
2module main
3
4import os
5
6#include <X11/Xauth.h>
7#include <X11/Xdmcp.h>
8#include <xcb/xcb.h>
9#flag -lXau
10#flag -lXdmcp
11#flag -lxcb
12
13@[typedef]
14struct C.XdmcpBuffer {
15 data &u8
16 size int
17 pointer int
18 count int
19}
20
21fn C.XauFileName() &char
22fn C.XdmcpReadCARD16(&C.XdmcpBuffer, &u16) int
23fn C.xcb_parse_display(&char, &&char, &int, &int) int
24
25fn main() {
26 os.setenv('XAUTHORITY', '/tmp/display-fixture.Xauthority', true)
27 assert unsafe { cstring_to_vstring(C.XauFileName()) } == '/tmp/display-fixture.Xauthority'
28
29 packet := [u8(0x12), 0x34]!
30 mut buffer := C.XdmcpBuffer{
31 data: unsafe { &packet[0] }
32 size: packet.len
33 count: packet.len
34 }
35 mut value := u16(0)
36 assert C.XdmcpReadCARD16(&buffer, &value) == 1
37 assert value == 0x1234 && buffer.pointer == 2
38
39 mut host := &char(unsafe { nil })
40 mut display, mut screen := 0, 0
41 assert C.xcb_parse_display(c'localhost:42.1', &host, &display, &screen) == 1
42 assert unsafe { cstring_to_vstring(host) } == 'localhost'
43 unsafe { C.free(host) }
44 assert display == 42 && screen == 1
45 println('Xau, Xdmcp and XCB display checks passed.')
46}
47