AtlatestRepositorysigil-desktop
sigil-desktop / tree / testtest-window-live.sgl
1
;;; The window calls with a window open (0.11.0). Needs a display: run it2
;;; on a headless X server, never on someone's desktop, e.g.3
;;;4
;;; Xvfb :74 -screen 0 1700x900x24 +extension GLX -nolisten tcp &5
;;; env -u WAYLAND_DISPLAY DISPLAY=:74 sigil test test/test-window-live.sgl6
;;;7
;;; With no display (DISPLAY and WAYLAND_DISPLAY both unset) it says so and8
;;; checks nothing; the no-window answers are test-window.sgl's.9
;;;10
;;; On the first frame: monitor-size is a proper list of two positive11
;;; integers; set-fullscreen! #t makes fullscreen? #t and the framebuffer12
;;; the monitor's size (a frame later: the platform resizes between frames);13
;;; set-fullscreen! #f brings back the windowed size; window-set-size! asks14
;;; for a new size and gets it (no window manager on Xvfb to refuse).16
(import (sigil test)17
(sigil desktop)18
(sigil list)19
(sigil process))21
(define (display?)22
(or (getenv "DISPLAY") (getenv "WAYLAND_DISPLAY")))24
(define *seen* '()) ; (name . value) in the order seen25
(define (see! name v) (set! *seen* (append *seen* (list (cons name v)))))26
(define (seen name) (let ((e (assoc name *seen*))) (and e (cdr e))))28
(define *n* 0)29
(define (frame dt)30
(set! *n* (+ *n* 1))31
(case *n*32
((1) (see! "monitor-size" (monitor-size))33
(see! "window size" (list (window-width) (window-height)))34
(see! "windowed" (list (frame-width) (frame-height)))35
(see! "fullscreen? before" (fullscreen?))36
(see! "set-fullscreen! on" (set-fullscreen! #t)))37
((4) (see! "fullscreen? on" (fullscreen?))38
(see! "size on" (list (frame-width) (frame-height)))39
(see! "set-fullscreen! off" (set-fullscreen! #f)))40
((7) (see! "fullscreen? off" (fullscreen?))41
(see! "size off" (list (frame-width) (frame-height)))42
(see! "window-set-size!" (window-set-size! 400 176)))43
((10) (see! "size set" (list (frame-width) (frame-height)))44
(see! "window size set" (list (window-width) (window-height)))45
(request-quit))46
(else #f)))48
(when (display?)49
(app-run (lambda () #f) frame (lambda () #f) "sigil-desktop window test" 640 360))51
(define (positive-ints? l n)52
(and (list? l) (= (length l) n) (every (lambda (x) (and (integer? x) (> x 0))) l)))54
(test-group "the window, with a window open"55
(if (not (display?))56
(test "no display: nothing checked (see the header)"57
(assert-true #t))58
(begin59
(test "monitor-size is a proper list of two positive integers"60
(assert-true (positive-ints? (seen "monitor-size") 2)))61
(test "the window opened at its asked size"62
(assert-equal (list 640 360) (seen "windowed")))63
(test "set-fullscreen! #t: fullscreen, at the monitor's size"64
(assert-false (seen "fullscreen? before"))65
(assert-true (seen "set-fullscreen! on"))66
(assert-true (seen "fullscreen? on"))67
(assert-equal (seen "monitor-size") (seen "size on")))68
(test "set-fullscreen! #f: back to the windowed size"69
(assert-true (seen "set-fullscreen! off"))70
(assert-false (seen "fullscreen? off"))71
(assert-equal (list 640 360) (seen "size off")))72
(test "window-set-size! asks, and the window takes it"73
(assert-true (seen "window-set-size!"))74
(assert-equal (list 400 176) (seen "size set")))75
;; Xvfb has no output scale: screen units are framebuffer pixels76
(test "window-width and window-height: the window in screen units"77
(assert-equal (list 640 360) (seen "window size"))78
(assert-equal (list 400 176) (seen "window size set"))))))