internal/rendertest: create test suit for drawing operations

Uses app/headless to create a set of test cases for drawing operations, including clipping
textures and transforms. This commit tests for approximate pixel matches, if future changes affect
local drawing operations it will be easy to change the reference images, it thus becomes and
should be an intentional operation if changes lead to local changes in drawn results.

Ideally we should be able to make the tests check for exact pixel matches down the line to ensure
consistent results between platforms.

Signed-off-by: Viktor <viktor.ogeman@gmail.com>
This commit is contained in:
Viktor
2020-06-20 23:29:52 +02:00
committed by Elias Naur
parent 24951a7ee7
commit e3bb94ebb0
28 changed files with 460 additions and 10 deletions
+17 -10
View File
@@ -38,33 +38,40 @@ func init() {
squares = paint.NewImageOp(im)
}
func drawImage(size int, draw func(o *op.Ops)) (im *image.RGBA, err error) {
func drawImage(size int, ops *op.Ops, draw func(o *op.Ops)) (im *image.RGBA, err error) {
sz := image.Point{X: size, Y: size}
w, err := headless.NewWindow(sz.X, sz.Y)
if err != nil {
return im, err
}
ops := new(op.Ops)
draw(ops)
w.Frame(ops)
return w.Screenshot()
}
func run(t *testing.T, f func(o *op.Ops)) result {
img, err := drawImage(128, f)
if err != nil {
t.Error("error rendering:", err)
func run(t *testing.T, f func(o *op.Ops), c func(r result)) {
// draw a few times and check that it is correct each time, to
// ensure any caching effects still generate the correct images.
ok := true
var img *image.RGBA
var err error
ops := new(op.Ops)
for i := 0; i < 3; i++ {
ops.Reset()
img, err = drawImage(128, ops, f)
if err != nil {
t.Error("error rendering:", err)
}
// check for a reference image and make sure we are identical.
ok = ok && verifyRef(t, img)
c(result{t: t, img: img})
}
// check for a reference image and make sure we are identical.
ok := verifyRef(t, img)
if *dumpImages || !ok {
if err := saveImage(t.Name()+".png", img); err != nil {
t.Error(err)
}
}
return result{t: t, img: img}
}
func verifyRef(t *testing.T, img *image.RGBA) (ok bool) {