feat: keep OSD always visible with pre-map fullscreen states (#3)
This commit is contained in:
+127
-96
@@ -1,61 +1,42 @@
|
||||
package display
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.piksar.eu/piotr/groundstation/internal/osd"
|
||||
)
|
||||
|
||||
// stubSource serves one fixed snapshot, or none.
|
||||
// stubSource serves one fixed snapshot state, or none.
|
||||
type stubSource struct {
|
||||
snapshot osd.Snapshot
|
||||
ok bool
|
||||
state osd.SnapshotState
|
||||
}
|
||||
|
||||
func (s stubSource) Latest() (osd.Snapshot, bool) { return s.snapshot, s.ok }
|
||||
func (s stubSource) Latest() (osd.Snapshot, osd.SnapshotState) { return s.snapshot, s.state }
|
||||
|
||||
// armedPendingSource is the contract state until the adaptive-link
|
||||
// producers exist: armed with a CH6 ceiling, everything else pending.
|
||||
func armedPendingSource(ceiling uint8) stubSource {
|
||||
// pendingSource is the contract state while the adaptive-link producers do
|
||||
// not exist: arm state and CH6 ceiling from the snapshot, everything else
|
||||
// explicitly pending.
|
||||
func pendingSource(armed bool, ceiling uint8) stubSource {
|
||||
return stubSource{snapshot: osd.Snapshot{
|
||||
Armed: true,
|
||||
Armed: armed,
|
||||
OpConfig: osd.OperatorConfig{MaxPower: ceiling},
|
||||
Policy: osd.GSPolicy{Pending: true},
|
||||
Ack: osd.VTXAck{Pending: true, Lifecycle: osd.VTXLifecyclePending},
|
||||
Link: osd.GSObservedLink{Known: false},
|
||||
}, ok: true}
|
||||
}, state: osd.SnapshotFresh}
|
||||
}
|
||||
|
||||
func TestOSDTemplateStaysTransparentWhileVideoAbsent(t *testing.T) {
|
||||
canvas := &fakeCanvas{width: 800, height: 600}
|
||||
|
||||
NewOSDTemplate(NewVideoPresence(), armedPendingSource(63)).Draw(canvas)
|
||||
|
||||
clears, flushes := canvas.drawCounts()
|
||||
if clears != 1 || flushes != 1 {
|
||||
t.Fatalf("clears=%d flushes=%d want 1 and 1", clears, flushes)
|
||||
}
|
||||
if lines := canvas.lines(); len(lines) != 0 {
|
||||
t.Fatalf("OSD lines=%q want none: without video the fallback canvas owns the screen", lines)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSDTemplateDrawsArmStateAndPendingContractWhileVideoPresent(t *testing.T) {
|
||||
canvas := &fakeCanvas{width: 800, height: 600}
|
||||
presence := NewVideoPresence()
|
||||
presence.SetActive(true)
|
||||
|
||||
NewOSDTemplate(presence, armedPendingSource(63)).Draw(canvas)
|
||||
|
||||
clears, flushes := canvas.drawCounts()
|
||||
if clears != 1 || flushes != 1 {
|
||||
t.Fatalf("clears=%d flushes=%d want 1 and 1", clears, flushes)
|
||||
}
|
||||
func assertLines(t *testing.T, canvas *fakeCanvas, want []string) {
|
||||
t.Helper()
|
||||
lines := canvas.lines()
|
||||
want := []string{"ARM ARMED", "VTX tbl:-- ceil:63 req:-- ack:--"}
|
||||
if len(lines) != len(want) {
|
||||
t.Fatalf("lines=%q want %q", lines, want)
|
||||
if len(lines) < len(want) {
|
||||
t.Fatalf("lines=%q want at least %q", lines, want)
|
||||
}
|
||||
// Compare only the most recent draw pass: the canvas accumulates lines
|
||||
// across passes.
|
||||
lines = lines[len(lines)-len(want):]
|
||||
for i := range want {
|
||||
if lines[i] != want[i] {
|
||||
t.Fatalf("line %d=%q want %q", i, lines[i], want[i])
|
||||
@@ -63,17 +44,89 @@ func TestOSDTemplateDrawsArmStateAndPendingContractWhileVideoPresent(t *testing.
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSDTemplateDrawsDisarmedState(t *testing.T) {
|
||||
func TestOSDTemplateRendersExplicitNoDataState(t *testing.T) {
|
||||
// Before any snapshot has ever existed the overlay must show explicit
|
||||
// unknown state plus the authoritative video state instead of a blank
|
||||
// overlay — including over the no-video fallback presentation.
|
||||
canvas := &fakeCanvas{width: 800, height: 600}
|
||||
|
||||
NewOSDTemplate(NewVideoPresence(), stubSource{}).Draw(canvas)
|
||||
|
||||
clears, flushes := canvas.drawCounts()
|
||||
if clears != 1 || flushes != 1 {
|
||||
t.Fatalf("clears=%d flushes=%d want 1 and 1", clears, flushes)
|
||||
}
|
||||
assertLines(t, canvas, []string{
|
||||
"NO DATA",
|
||||
"VTX tbl:-- ceil:-- req:-- ack:--",
|
||||
"VIDEO OFF",
|
||||
})
|
||||
}
|
||||
|
||||
func TestOSDTemplateDrawsFreshSnapshotWithVideoOff(t *testing.T) {
|
||||
// Fresh snapshot data renders on top of the no-video fallback
|
||||
// presentation; the observed video lifecycle shows as VIDEO OFF.
|
||||
canvas := &fakeCanvas{width: 800, height: 600}
|
||||
presence := NewVideoPresence()
|
||||
|
||||
NewOSDTemplate(presence, pendingSource(true, 63)).Draw(canvas)
|
||||
|
||||
assertLines(t, canvas, []string{
|
||||
"ARM ARMED",
|
||||
"VTX tbl:-- ceil:63 req:-- ack:--",
|
||||
"VIDEO OFF",
|
||||
})
|
||||
}
|
||||
|
||||
func TestOSDTemplateMarksStaleLastKnownData(t *testing.T) {
|
||||
// A snapshot beyond the freshness window stays visible as last-known
|
||||
// data, explicitly marked stale — never presented as current.
|
||||
canvas := &fakeCanvas{width: 800, height: 600}
|
||||
presence := NewVideoPresence()
|
||||
|
||||
NewOSDTemplate(presence, stubSource{snapshot: osd.Snapshot{
|
||||
Armed: true,
|
||||
OpConfig: osd.OperatorConfig{
|
||||
Table: osd.Table{Gen: 3, Hash: 0xcafe},
|
||||
MaxPower: 63,
|
||||
},
|
||||
Policy: osd.GSPolicy{Level: 42},
|
||||
Ack: osd.VTXAck{
|
||||
Table: osd.Table{Gen: 3},
|
||||
Level: 40,
|
||||
Lifecycle: osd.VTXLifecycleApplied,
|
||||
},
|
||||
}, state: osd.SnapshotStale}).Draw(canvas)
|
||||
|
||||
assertLines(t, canvas, []string{
|
||||
"ARM ARMED",
|
||||
"VTX tbl:3 ceil:63 req:42 ack:40",
|
||||
"DATA STALE",
|
||||
"VIDEO OFF",
|
||||
})
|
||||
}
|
||||
|
||||
func TestOSDTemplateStaysVisibleAcrossVideoTransition(t *testing.T) {
|
||||
// Video appearing fullscreen must not hide the OSD: the data lines stay
|
||||
// and only the authoritative VIDEO line flips.
|
||||
canvas := &fakeCanvas{width: 800, height: 600}
|
||||
presence := NewVideoPresence()
|
||||
template := NewOSDTemplate(presence, pendingSource(true, 63))
|
||||
|
||||
template.Draw(canvas)
|
||||
assertLines(t, canvas, []string{
|
||||
"ARM ARMED",
|
||||
"VTX tbl:-- ceil:63 req:-- ack:--",
|
||||
"VIDEO OFF",
|
||||
})
|
||||
|
||||
presence.SetActive(true)
|
||||
|
||||
NewOSDTemplate(presence, stubSource{ok: true}).Draw(canvas)
|
||||
|
||||
lines := canvas.lines()
|
||||
if len(lines) != 2 || lines[0] != "ARM OFF" {
|
||||
t.Fatalf("lines=%q want the disarmed arm state and the pending contract line", lines)
|
||||
}
|
||||
template.Draw(canvas)
|
||||
assertLines(t, canvas, []string{
|
||||
"ARM ARMED",
|
||||
"VTX tbl:-- ceil:63 req:-- ack:--",
|
||||
"VIDEO ON",
|
||||
})
|
||||
}
|
||||
|
||||
func TestOSDTemplateRendersSelectedTableRequestedAndAppliedStates(t *testing.T) {
|
||||
@@ -93,35 +146,30 @@ func TestOSDTemplateRendersSelectedTableRequestedAndAppliedStates(t *testing.T)
|
||||
Level: 40,
|
||||
Lifecycle: osd.VTXLifecycleApplied,
|
||||
},
|
||||
}, ok: true}).Draw(canvas)
|
||||
}, state: osd.SnapshotFresh}).Draw(canvas)
|
||||
|
||||
lines := canvas.lines()
|
||||
want := []string{"ARM ARMED", "VTX tbl:3 ceil:127 req:42 ack:40"}
|
||||
if len(lines) != len(want) {
|
||||
t.Fatalf("lines=%q want %q", lines, want)
|
||||
}
|
||||
for i := range want {
|
||||
if lines[i] != want[i] {
|
||||
t.Fatalf("line %d=%q want %q", i, lines[i], want[i])
|
||||
}
|
||||
}
|
||||
assertLines(t, canvas, []string{
|
||||
"ARM ARMED",
|
||||
"VTX tbl:3 ceil:127 req:42 ack:40",
|
||||
"VIDEO ON",
|
||||
})
|
||||
}
|
||||
|
||||
func TestOSDTemplateRendersAckErrorState(t *testing.T) {
|
||||
canvas := &fakeCanvas{width: 800, height: 600}
|
||||
presence := NewVideoPresence()
|
||||
presence.SetActive(true)
|
||||
|
||||
NewOSDTemplate(presence, stubSource{snapshot: osd.Snapshot{
|
||||
OpConfig: osd.OperatorConfig{MaxPower: 10},
|
||||
Policy: osd.GSPolicy{Pending: true},
|
||||
Ack: osd.VTXAck{Lifecycle: osd.VTXLifecycleError},
|
||||
}, ok: true}).Draw(canvas)
|
||||
}, state: osd.SnapshotFresh}).Draw(canvas)
|
||||
|
||||
lines := canvas.lines()
|
||||
if len(lines) != 2 || lines[1] != "VTX tbl:-- ceil:10 req:-- ack:ERR" {
|
||||
t.Fatalf("lines=%q want the acknowledged error state", lines)
|
||||
}
|
||||
assertLines(t, canvas, []string{
|
||||
"ARM OFF",
|
||||
"VTX tbl:-- ceil:10 req:-- ack:ERR",
|
||||
"VIDEO OFF",
|
||||
})
|
||||
}
|
||||
|
||||
func TestOSDTemplateRendersLevelZeroAsExplicitOff(t *testing.T) {
|
||||
@@ -130,59 +178,42 @@ func TestOSDTemplateRendersLevelZeroAsExplicitOff(t *testing.T) {
|
||||
// value — no producer yet — renders as the pending mark.
|
||||
canvas := &fakeCanvas{width: 800, height: 600}
|
||||
presence := NewVideoPresence()
|
||||
presence.SetActive(true)
|
||||
|
||||
NewOSDTemplate(presence, stubSource{snapshot: osd.Snapshot{
|
||||
OpConfig: osd.OperatorConfig{MaxPower: 0},
|
||||
Policy: osd.GSPolicy{Level: 0},
|
||||
Ack: osd.VTXAck{Level: 0, Lifecycle: osd.VTXLifecycleApplied},
|
||||
}, ok: true}).Draw(canvas)
|
||||
}, state: osd.SnapshotFresh}).Draw(canvas)
|
||||
|
||||
lines := canvas.lines()
|
||||
want := "VTX tbl:-- ceil:0 req:0 ack:0"
|
||||
if len(lines) != 2 || lines[1] != want {
|
||||
t.Fatalf("lines=%q want %q", lines, want)
|
||||
}
|
||||
assertLines(t, canvas, []string{
|
||||
"ARM OFF",
|
||||
"VTX tbl:-- ceil:0 req:0 ack:0",
|
||||
"VIDEO OFF",
|
||||
})
|
||||
}
|
||||
|
||||
func TestOSDTemplateStaysTransparentWithoutASnapshotWhileVideoPresent(t *testing.T) {
|
||||
canvas := &fakeCanvas{width: 800, height: 600}
|
||||
presence := NewVideoPresence()
|
||||
presence.SetActive(true)
|
||||
|
||||
NewOSDTemplate(presence, stubSource{}).Draw(canvas)
|
||||
|
||||
if lines := canvas.lines(); len(lines) != 0 {
|
||||
t.Fatalf("OSD lines=%q want none without a published snapshot", lines)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSDTemplateGatesOnObservedVideoPresenceNotSnapshotVideo(t *testing.T) {
|
||||
// The rendering gate is the video lifecycle the display observes on the
|
||||
// display server, never the snapshot's Video field: the supervisor's
|
||||
// field is its launcher knowledge, while the display trusts only the
|
||||
// presented video output itself.
|
||||
func TestOSDTemplateVideoLineUsesOnlyObservedLifecycle(t *testing.T) {
|
||||
// The VIDEO line is sourced from the video lifecycle the display
|
||||
// observes on the display server, never from the snapshot's Video
|
||||
// field (the supervisor's launcher knowledge).
|
||||
canvas := &fakeCanvas{width: 800, height: 600}
|
||||
presence := NewVideoPresence()
|
||||
|
||||
claimingVideo := stubSource{snapshot: osd.Snapshot{Armed: true, Video: true}, ok: true}
|
||||
NewOSDTemplate(presence, claimingVideo).Draw(canvas)
|
||||
if lines := canvas.lines(); len(lines) != 0 {
|
||||
t.Fatalf("lines=%q want none: snapshot presence must never replace the observed lifecycle", lines)
|
||||
}
|
||||
NewOSDTemplate(presence, stubSource{snapshot: osd.Snapshot{
|
||||
Video: true,
|
||||
}, state: osd.SnapshotFresh}).Draw(canvas)
|
||||
|
||||
denyingVideo := stubSource{snapshot: osd.Snapshot{Armed: true}, ok: true}
|
||||
presence.SetActive(true)
|
||||
NewOSDTemplate(presence, denyingVideo).Draw(canvas)
|
||||
if lines := canvas.lines(); len(lines) == 0 {
|
||||
t.Fatal("the observed video lifecycle must gate rendering even when the snapshot denies video")
|
||||
for _, line := range canvas.lines() {
|
||||
if strings.HasPrefix(line, "VIDEO") && line != "VIDEO OFF" {
|
||||
t.Fatalf("line=%q: snapshot presence must never replace the observed lifecycle", line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSDTemplateNeverDrawsTheFallbackText(t *testing.T) {
|
||||
canvas := &fakeCanvas{width: 800, height: 600}
|
||||
presence := NewVideoPresence()
|
||||
template := NewOSDTemplate(presence, armedPendingSource(63))
|
||||
template := NewOSDTemplate(presence, pendingSource(true, 63))
|
||||
|
||||
for _, active := range []bool{false, true, false} {
|
||||
presence.SetActive(active)
|
||||
|
||||
Reference in New Issue
Block a user