1package headless
2
3import (
4 "image"
5 "image/color"
6 "testing"
7
8 "github.com/bnema/neferwl/internal/ports"
9)
10
11func TestCursorDraw(t *testing.T) {
12 dst := image.NewRGBA(image.Rect(0, 0, 10, 10))
13 for i := range dst.Pix {
14 dst.Pix[i] = 255
15 }
16 // 2x2: opaque red, transparent, half black, opaque blue; hotspot (1,1).
17 c := &Cursor{}
18 c.set(ports.CursorImage{W: 2, H: 2, HotX: 1, HotY: 1, Pixels: []byte{0, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0, 128, 255, 0, 0, 255}})
19 c.Move(5, 5)
20 c.draw(dst)
21 for p, want := range map[image.Point]color.RGBA{{4, 4}: {255, 0, 0, 255}, {5, 4}: {255, 255, 255, 255}, {4, 5}: {127, 127, 127, 255}, {5, 5}: {0, 0, 255, 255}} {
22 if got := dst.RGBAAt(p.X, p.Y); got != want {
23 t.Errorf("%v = %v, want %v", p, got, want)
24 }
25 }
26 // Off the edge: clipped, no panic.
27 c.Move(0, 0)
28 c.draw(dst)
29 c.Move(100, -3)
30 c.draw(dst)
31}