-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
splash_test.go
98 lines (89 loc) · 2.21 KB
/
splash_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package splash
import (
"gioui.org/app"
"gioui.org/gpu/headless"
"gioui.org/layout"
"gioui.org/op"
"gioui.org/unit"
"github.com/gesellix/gioui-splash/assets"
"github.com/gesellix/gioui-splash/f32color"
"image"
"image/color"
"testing"
)
func TestRender(t *testing.T) {
logo, _ := assets.GetLogo()
size := image.Point{X: 640, Y: 360}
splash := NewSplash(
logo,
layout.Inset{
Top: 5,
Bottom: 10,
Left: 10,
Right: 10,
},
color.NRGBA{R: 100, G: 200, B: 100, A: 127},
)
splash.SetProgress(0.5)
run(t,
size,
func(ops *op.Ops) {
splash.Layout(app.NewContext(ops, app.FrameEvent{
Size: size,
Metric: unit.Metric{PxPerDp: 1},
}))
}, func(r result) {
},
)
}
func TestHeadless(t *testing.T) {
size := image.Point{X: 640, Y: 360}
w, release := newTestWindow(t, size)
defer release()
var ops op.Ops
colOrigin := color.NRGBA{R: 15, G: 26, B: 32, A: 255}
colProgress := color.NRGBA{R: 73, G: 148, B: 76, A: 255}
logo, _ := assets.GetLogo()
splash := NewSplash(
logo,
layout.Inset{
Top: 5,
Bottom: 10,
Left: 10,
Right: 10,
},
color.NRGBA{R: 100, G: 200, B: 100, A: 127},
)
splash.SetProgress(0.5)
splash.Layout(app.NewContext(&ops, app.FrameEvent{
Size: size,
Metric: unit.Metric{PxPerDp: 1},
}))
if err := w.Frame(&ops); err != nil {
t.Fatal(err)
}
img := image.NewRGBA(image.Rectangle{Max: w.Size()})
err := w.Screenshot(img)
if err != nil {
t.Fatal(err)
}
if isz := img.Bounds().Size(); isz != size {
t.Errorf("got %v screenshot, expected %v", isz, size)
}
if got := img.RGBAAt(0, 0); !colorsClose(got, f32color.NRGBAToRGBA(colOrigin)) || !alphaClose(got, f32color.NRGBAToRGBA(colOrigin)) {
t.Errorf("got color %v, expected %v", got, f32color.NRGBAToRGBA(colOrigin))
}
if got := img.RGBAAt(10, 345); !colorsClose(got, f32color.NRGBAToRGBA(colProgress)) || !alphaClose(got, f32color.NRGBAToRGBA(colProgress)) {
t.Errorf("got color %v, expected %v", got, f32color.NRGBAToRGBA(colProgress))
}
}
func newTestWindow(t *testing.T, sz image.Point) (*headless.Window, func()) {
t.Helper()
w, err := headless.NewWindow(sz.X, sz.Y)
if err != nil {
t.Errorf("headless windows not supported: %v", err)
}
return w, func() {
w.Release()
}
}