1//go:build linux
2
3package wayland
4
5import (
6 "fmt"
7 "testing"
8
9 "github.com/bnema/wlturbo/protocol/viewporter"
10)
11
12func TestPhysicalSizeCeilsFractionalScale(t *testing.T) {
13 for _, tc := range []struct {
14 width, height int32
15 scale float64
16 wantW, wantH int32
17 }{
18 {3, 5, 1.25, 4, 7}, {3, 5, 1.5, 5, 8}, {4, 6, 1.5, 6, 9}, {3, 5, 1.25 + 1e-12, 4, 7},
19 } {
20 w := &Window{Width: tc.width, Height: tc.height, Scale: tc.scale, Viewport: &viewporter.WpViewport{}}
21 x, y, err := w.PhysicalSize()
22 if err != nil || x != tc.wantW || y != tc.wantH {
23 t.Fatalf("%dx%d scale %g: %dx%d err=%v; want %dx%d", tc.width, tc.height, tc.scale, x, y, err, tc.wantW, tc.wantH)
24 }
25 }
26}
27
28func TestFeedbackAppliedOnLoop(t *testing.T) {
29 w := &Window{events: make(chan Event, 2), readerStop: make(chan struct{})}
30 w.readerStarted.Store(true)
31 go w.feedbackFailure(fmt.Errorf("feedback failed"))
32 ev := <-w.events
33 if w.feedbackErr != nil {
34 t.Fatal("reader mutated loop-owned error")
35 }
36 if err := w.Apply(ev); err == nil || w.feedbackErr == nil {
37 t.Fatalf("apply: %v feedback: %v", err, w.feedbackErr)
38 }
39}