44 lines
1.7 KiB
Go
44 lines
1.7 KiB
Go
package host
|
|
|
|
import "testing"
|
|
|
|
func TestFindDisplayByName(t *testing.T) {
|
|
displays := []DisplayInfo{{Name: "DISPLAY2"}, {Name: "DISPLAY1", Primary: true}}
|
|
for _, name := range []string{"", "Auto", "PRIMARY", "display1"} {
|
|
if display, ok := FindDisplayByName(displays, name); !ok || display == nil || display.Name != "DISPLAY1" {
|
|
t.Fatalf("FindDisplayByName(%q) = %+v, %t", name, display, ok)
|
|
}
|
|
}
|
|
display, ok := FindDisplayByName(displays, "display2")
|
|
if !ok || display == nil || display.Name != "DISPLAY2" {
|
|
t.Fatalf("secondary display = %+v, %t", display, ok)
|
|
}
|
|
display.Name = "changed"
|
|
if displays[0].Name != "DISPLAY2" {
|
|
t.Fatal("lookup returned a pointer into the original slice")
|
|
}
|
|
if display, ok := FindDisplayByName(displays, "missing"); ok || display != nil {
|
|
t.Fatalf("missing display = %+v, %t", display, ok)
|
|
}
|
|
if display, ok := FindDisplayByName(nil, "auto"); !ok || display != nil {
|
|
t.Fatalf("default with no displays = %+v, %t", display, ok)
|
|
}
|
|
}
|
|
|
|
func TestComputeWindowedTargetRect(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
name string
|
|
window, work, want WindowRect
|
|
}{
|
|
{"center", WindowRect{80, 90, 880, 690}, WindowRect{0, 40, 1920, 1080}, WindowRect{560, 260, 1360, 860}},
|
|
{"clamp width", WindowRect{0, 0, 2500, 600}, WindowRect{0, 40, 1920, 1080}, WindowRect{0, 260, 1920, 860}},
|
|
{"clamp height on negative screen", WindowRect{0, 0, 800, 1440}, WindowRect{-1920, -1080, 0, -40}, WindowRect{-1360, -1080, -560, -40}},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
if got := computeWindowedTargetRect(tc.window, tc.work); got != tc.want {
|
|
t.Fatalf("target rectangle = %+v, want %+v", got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|