| 1 | // Exercise the installed client libraries without requiring a display server. |
| 2 | module main |
| 3 | |
| 4 | import 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] |
| 14 | struct C.XdmcpBuffer { |
| 15 | data &u8 |
| 16 | size int |
| 17 | pointer int |
| 18 | count int |
| 19 | } |
| 20 | |
| 21 | fn C.XauFileName() &char |
| 22 | fn C.XdmcpReadCARD16(&C.XdmcpBuffer, &u16) int |
| 23 | fn C.xcb_parse_display(&char, &&char, &int, &int) int |
| 24 | |
| 25 | fn 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 | |