AtlatestRepositorysigil-ui

sigil-ui / tree / test / waylandtitle.sgl

1;;; Run in an owned compositor with its client protocol trace enabled.
2(import (sigil test) (sigil shell) (sigil fs) (sigil string) (sigil time) (sigil process)
3 (sigil ui wayland) (sigil ui raster))
4(requires (tools swaymsg))
5(define trace-file (or (getenv "SIGIL_UI_TEST_CLIENT_TRACE")
6 (error "Title tests require a client trace in an owned compositor")))
7(define (commits) (string-count (read-file-string trace-file) ".commit()"))
8(define (settle surface ms)
9 (let ((end (+ (current-jiffy) (* (/ ms 1000) (jiffies-per-second)))))
10 (let loop ()
11 (when (< (current-jiffy) end)
12 (wayland-dispatch surface 5)
13 (loop)))))
14(test "title updates reach the compositor once without a surface commit"
15 (let ((surface (open-wayland-surface title: "Initial title")))
16 (dynamic-wind (lambda () #f)
17 (lambda ()
18 (wayland-present! surface
19 (make-canvas (wayland-surface-device-width surface) (wayland-surface-device-height surface)))
20 (settle surface 150)
21 (let ((before (commits)))
22 (assert-false (wayland-set-title! surface "Initial title"))
23 (assert-true (wayland-set-title! surface "Updated title"))
24 (assert-false (wayland-set-title! surface "Updated title"))
25 (settle surface 100)
26 (assert-true (string-contains?
27 (out swaymsg -t get_tree timeout: 3) "Updated title"))
28 (assert-equal before (commits))))
29 (lambda () (wayland-surface-close! surface)))))
30(test "title updates reject invalid text children and closed handles"
31 (let* ((surface (open-wayland-surface title: "Title validation"))
32 (child (open-wayland-subsurface surface width: 20 height: 20)))
33 (dynamic-wind (lambda () #f)
34 (lambda ()
35 (assert-error (wayland-set-title! surface #f))
36 (assert-error (wayland-set-title! surface (string (integer->char 0))))
37 (assert-error (wayland-set-title! surface (make-string 4096 #\x)))
38 (assert-error (wayland-set-title! child "Not a toplevel"))
39 (wayland-surface-close! surface)
40 (assert-error (wayland-set-title! surface "Closed")))
41 (lambda () (wayland-surface-close! child) (wayland-surface-close! surface)))))