64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.piksar.eu/piotr/groundstation/internal/display"
|
|
)
|
|
|
|
type recordingCanvas struct {
|
|
width, height int
|
|
lines []string
|
|
clears, flushes int
|
|
}
|
|
|
|
func (c *recordingCanvas) Size() (int, int) { return c.width, c.height }
|
|
func (c *recordingCanvas) Clear() { c.clears++ }
|
|
func (c *recordingCanvas) Text(_, _ int, message string) {
|
|
c.lines = append(c.lines, message)
|
|
}
|
|
func (c *recordingCanvas) Flush() { c.flushes++ }
|
|
|
|
func TestBuildTargetWiresSharedVideoPresenceToFallback(t *testing.T) {
|
|
opener, template, err := buildTarget("x11")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
x11, ok := opener.(display.X11Opener)
|
|
if !ok {
|
|
t.Fatalf("opener %T must be the X11 target", opener)
|
|
}
|
|
if x11.Video == nil {
|
|
t.Fatal("x11 opener must observe the video presence signal")
|
|
}
|
|
|
|
canvas := &recordingCanvas{width: 800, height: 600}
|
|
template.Draw(canvas)
|
|
if len(canvas.lines) != 1 || canvas.lines[0] != "Brak połączenia WFB" {
|
|
t.Fatalf("lines=%q want the exact fallback text", canvas.lines)
|
|
}
|
|
|
|
// The opener and the template must share one presence signal so the
|
|
// video lifecycle observed by the session drives the fallback.
|
|
x11.Video.SetActive(true)
|
|
canvas.lines = nil
|
|
template.Draw(canvas)
|
|
if len(canvas.lines) != 0 {
|
|
t.Fatalf("lines=%q must disappear while video is present", canvas.lines)
|
|
}
|
|
|
|
x11.Video.SetActive(false)
|
|
canvas.lines = nil
|
|
template.Draw(canvas)
|
|
if len(canvas.lines) != 1 || canvas.lines[0] != "Brak połączenia WFB" {
|
|
t.Fatalf("lines=%q want the fallback back after video end", canvas.lines)
|
|
}
|
|
}
|
|
|
|
func TestBuildTargetRejectsUnknownTarget(t *testing.T) {
|
|
if _, _, err := buildTarget("hdmi-mirror"); err == nil {
|
|
t.Fatal("unknown target must fail")
|
|
}
|
|
}
|