AtlatestRepositorysigil-ui
1
;;; Run with the controlled host directory first on the module search path.2
(import (sigil ui appkit) (sigil ui raster) (sigil ui mask) (sigil ui tree)3
(sigil ui theme) (prefix (sigil window appkit) host:))4
(define checks 0)5
(define (check condition label)6
(set! checks (+ checks 1))7
(unless condition (error "AppKit drawing adapter failed" label))8
(println "PASS: ~a" label))9
(define (raises? thunk)10
(guard (failure (#t #t)) (thunk) #f))11
(define window (open-appkit-window))12
(define other (open-appkit-window))13
(define canvas (make-canvas 20 16))14
(check (= 20 (appkit-window-device-width window)) "legacy canvas extent follows host raster width")15
(check (appkit-present! window canvas) "canvas forwards to host")16
(check (eq? (car (host:test-last)) (canvas-pixels canvas)) "original canvas bytes forwarded")17
(check (equal? (cdr (host:test-last)) '(20 16 1 #f)) "dimensions and current generation forwarded")18
(define before (host:test-calls))19
(check (appkit-present! window canvas '()) "empty damage succeeds")20
(check (= before (host:test-calls)) "empty damage does not present")21
(each rectangle '((-1 0 1 1) (0 0 21 1) (0 0 1 17) (0 0 1.5 1) (0 0 1))22
(check (raises? (lambda () (appkit-present! window canvas (list rectangle))))23
"malformed device damage rejected"))24
(check (= before (host:test-calls)) "invalid damage never reaches host")25
(define ui (appkit-make-ui window (make-theme '() '() '()) 0))26
(check (and (= (ui-width ui) 10) (= (ui-height ui) 8) (= (ui-scale ui) 2))27
"UI allocates at host raster scale")28
(check (appkit-present-ui! window ui '((0 0 10 8))) "logical UI damage converts to device damage")29
(check (not (appkit-present-ui! other ui '((0 0 10 8)))) "UI refuses another window")30
(host:test-generation! window 2)31
(define stale-before (host:test-calls))32
(check (not (appkit-present-ui! window ui '((0 0 10 8)))) "stale UI generation refused")33
(check (= stale-before (host:test-calls)) "stale UI does not reach host")34
(check (appkit-present! window canvas) "direct presentation snapshots the new generation")35
(check (= 2 (list-ref (host:test-last) 3)) "updated generation forwarded")36
(define alpha (make-mask 20 16 (make-bytevector 320 128)))37
(check (appkit-present-overlay! window canvas alpha) "overlay forwards to host")38
(check (eq? (list-ref (host:test-last) 4) (mask-alpha alpha)) "overlay alpha plane forwarded")39
(check (raises? (lambda ()40
(appkit-present-overlay! window canvas (make-mask 1 1 (bytevector 0)))))41
"mismatched overlay dimensions rejected")42
(println "RESULT PASS checks=~a" checks)