diff --git a/cmd/gogio/e2e_test.go b/cmd/gogio/e2e_test.go index 935b88f1..0f1c707c 100644 --- a/cmd/gogio/e2e_test.go +++ b/cmd/gogio/e2e_test.go @@ -32,16 +32,58 @@ func runEndToEndTest(t *testing.T, driver TestDriver) { width, height := 800, 600 cleanups := driver.Start(t, "testdata/red.go", width, height) - // We expect to receive a 800x600px screenshot that's filled with - // 0xdeadbeef as the color. + // We expect to receive a 800x600px screenshot. img := driver.Screenshot() size := img.Bounds().Size() if size.X != width || size.Y != height { t.Fatalf("expected dimensions to be %d*%d, got %d*%d", width, height, size.X, size.Y) } - wantColor(t, img, 5, 5, 0xdede, 0xadad, 0xbebe) - wantColor(t, img, width-5, height-5, 0xdede, 0xadad, 0xbebe) + + // The colors are split in four rectangular sections. Check the corners + // of each of the sections. We check the corners left to right, top to + // bottom, like when reading left-to-right text. + + // The top left should be 0xdeadbe. + { + minX, minY := 5, 5 + maxX, maxY := (width/2)-5, (height/2)-5 + wantColor(t, img, minX, minY, 0xdede, 0xadad, 0xbebe) + wantColor(t, img, maxX, minY, 0xdede, 0xadad, 0xbebe) + wantColor(t, img, minX, maxY, 0xdede, 0xadad, 0xbebe) + wantColor(t, img, maxX, maxY, 0xdede, 0xadad, 0xbebe) + } + + // The top right should be 0xffffff. + { + minX, minY := (width/2)+5, 5 + maxX, maxY := width-5, (height/2)-5 + wantColor(t, img, minX, minY, 0xffff, 0xffff, 0xffff) + wantColor(t, img, maxX, minY, 0xffff, 0xffff, 0xffff) + wantColor(t, img, minX, maxY, 0xffff, 0xffff, 0xffff) + wantColor(t, img, maxX, maxY, 0xffff, 0xffff, 0xffff) + } + + // The bottom left should be 0x000000. + { + minX, minY := 5, (height/2)+5 + maxX, maxY := (width/2)-5, height-5 + wantColor(t, img, minX, minY, 0x0000, 0x0000, 0x0000) + wantColor(t, img, maxX, minY, 0x0000, 0x0000, 0x0000) + wantColor(t, img, minX, maxY, 0x0000, 0x0000, 0x0000) + wantColor(t, img, maxX, maxY, 0x0000, 0x0000, 0x0000) + } + + // The bottom right is black (0x000000) with 0x80 alpha, so we should + // see gray (0xbbbbbb). + { + minX, minY := (width/2)+5, (height/2)+5 + maxX, maxY := width-5, height-5 + wantColor(t, img, minX, minY, 0xbbbb, 0xbbbb, 0xbbbb) + wantColor(t, img, maxX, minY, 0xbbbb, 0xbbbb, 0xbbbb) + wantColor(t, img, minX, maxY, 0xbbbb, 0xbbbb, 0xbbbb) + wantColor(t, img, maxX, maxY, 0xbbbb, 0xbbbb, 0xbbbb) + } // Run the cleanup funcs from last to first, as if they were defers. for i := len(cleanups) - 1; i >= 0; i-- { diff --git a/cmd/gogio/testdata/red.go b/cmd/gogio/testdata/red.go index 819f89e4..37db0c1c 100644 --- a/cmd/gogio/testdata/red.go +++ b/cmd/gogio/testdata/red.go @@ -25,7 +25,11 @@ func main() { } func loop(w *app.Window) error { - background := color.RGBA{R: 0xde, G: 0xad, B: 0xbe, A: 0xff} + topLeft := color.RGBA{R: 0xde, G: 0xad, B: 0xbe, A: 0xff} + topRight := color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff} + botLeft := color.RGBA{R: 0x00, G: 0x00, B: 0x00, A: 0xff} + botRight := color.RGBA{R: 0x00, G: 0x00, B: 0x00, A: 0x80} + ops := new(op.Ops) for { e := <-w.Events() @@ -34,11 +38,55 @@ func loop(w *app.Window) error { return e.Err case system.FrameEvent: ops.Reset() - paint.ColorOp{Color: background}.Add(ops) - paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{ - X: float32(e.Size.X), - Y: float32(e.Size.Y), - }}}.Add(ops) + + paint.ColorOp{Color: topLeft}.Add(ops) + paint.PaintOp{Rect: f32.Rectangle{ + Min: f32.Point{ + X: 0, + Y: 0, + }, + Max: f32.Point{ + X: float32(e.Size.X)/2, + Y: float32(e.Size.Y)/2, + }, + }}.Add(ops) + + paint.ColorOp{Color: topRight}.Add(ops) + paint.PaintOp{Rect: f32.Rectangle{ + Min: f32.Point{ + X: float32(e.Size.X)/2, + Y: 0, + }, + Max: f32.Point{ + X: float32(e.Size.X), + Y: float32(e.Size.Y)/2, + }, + }}.Add(ops) + + paint.ColorOp{Color: botLeft}.Add(ops) + paint.PaintOp{Rect: f32.Rectangle{ + Min: f32.Point{ + X: 0, + Y: float32(e.Size.Y)/2, + }, + Max: f32.Point{ + X: float32(e.Size.X)/2, + Y: float32(e.Size.Y), + }, + }}.Add(ops) + + paint.ColorOp{Color: botRight}.Add(ops) + paint.PaintOp{Rect: f32.Rectangle{ + Min: f32.Point{ + X: float32(e.Size.X)/2, + Y: float32(e.Size.Y)/2, + }, + Max: f32.Point{ + X: float32(e.Size.X), + Y: float32(e.Size.Y), + }, + }}.Add(ops) + e.Frame(ops) } }