github.com/gop9/olt@v0.0.0-20200202132135-d956aad50b08/gio/app/headless/headless_test.go (about)

     1  // SPDX-License-Identifier: Unlicense OR MIT
     2  
     3  package headless
     4  
     5  import (
     6  	"image"
     7  	"image/color"
     8  	"testing"
     9  
    10  	"github.com/gop9/olt/gio/f32"
    11  	"github.com/gop9/olt/gio/op"
    12  	"github.com/gop9/olt/gio/op/paint"
    13  )
    14  
    15  func TestHeadless(t *testing.T) {
    16  	sz := image.Point{X: 800, Y: 600}
    17  	w, err := NewWindow(sz.X, sz.Y)
    18  	if err != nil {
    19  		t.Skipf("headless windows not supported: %v", err)
    20  	}
    21  
    22  	col := color.RGBA{A: 0xff, R: 0xcc, G: 0xcc}
    23  	var ops op.Ops
    24  	paint.ColorOp{Color: col}.Add(&ops)
    25  	// Paint only part of the screen to avoid the glClear optimization.
    26  	paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{
    27  		X: float32(sz.X) - 100,
    28  		Y: float32(sz.Y) - 100,
    29  	}}}.Add(&ops)
    30  	w.Frame(&ops)
    31  
    32  	img, err := w.Screenshot()
    33  	if err != nil {
    34  		t.Fatal(err)
    35  	}
    36  	if isz := img.Bounds().Size(); isz != sz {
    37  		t.Errorf("got %v screenshot, expected %v", isz, sz)
    38  	}
    39  	if got := img.RGBAAt(0, 0); got != col {
    40  		t.Errorf("got color %v, expected %v", got, col)
    41  	}
    42  }