forked from joejulian/gio
0b84137f40
Signed-off-by: Elias Naur <mail@eliasnaur.com>
42 lines
825 B
Go
42 lines
825 B
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
package headless
|
|
|
|
import (
|
|
"image"
|
|
"image/color"
|
|
"testing"
|
|
|
|
"gioui.org/f32"
|
|
"gioui.org/op"
|
|
"gioui.org/op/paint"
|
|
)
|
|
|
|
func TestHeadless(t *testing.T) {
|
|
sz := image.Point{X: 800, Y: 600}
|
|
w, err := NewWindow(sz.X, sz.Y)
|
|
if err != nil {
|
|
t.Skipf("headless windows not supported: %v", err)
|
|
}
|
|
|
|
col := color.RGBA{A: 0xff, R: 0xcc, G: 0xcc}
|
|
var ops op.Ops
|
|
paint.ColorOp{Color: col}.Add(&ops)
|
|
paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{
|
|
X: float32(sz.X),
|
|
Y: float32(sz.Y),
|
|
}}}.Add(&ops)
|
|
w.Frame(&ops)
|
|
|
|
img, err := w.Screenshot()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if isz := img.Bounds().Size(); isz != sz {
|
|
t.Errorf("got %v screenshot, expected %v", isz, sz)
|
|
}
|
|
if got := img.RGBAAt(0, 0); got != col {
|
|
t.Errorf("got color %v, expected %v", got, col)
|
|
}
|
|
}
|