mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-09 09:24:43 +01:00
buffered: Add tests for #1050
This commit is contained in:
parent
27404b7ae3
commit
52a5ed0ad4
@ -15,7 +15,6 @@
|
|||||||
package buffered_test
|
package buffered_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"image/color"
|
"image/color"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@ -40,31 +39,132 @@ func TestMain(m *testing.M) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
if err := ebiten.Run(func(*ebiten.Image) error {
|
||||||
case f := <-mainCh:
|
f := <-mainCh
|
||||||
f()
|
f()
|
||||||
|
return nil
|
||||||
|
}, 320, 240, 1, ""); err != nil {
|
||||||
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetBeforeRun(t *testing.T) {
|
type testResult struct {
|
||||||
clr := color.RGBA{1, 2, 3, 4}
|
want color.RGBA
|
||||||
|
got <-chan color.RGBA
|
||||||
|
}
|
||||||
|
|
||||||
|
var testSetBeforeMainResult = func() testResult {
|
||||||
|
clr := color.RGBA{1, 2, 3, 4}
|
||||||
img, _ := ebiten.NewImage(16, 16, ebiten.FilterDefault)
|
img, _ := ebiten.NewImage(16, 16, ebiten.FilterDefault)
|
||||||
img.Set(0, 0, clr)
|
img.Set(0, 0, clr)
|
||||||
|
|
||||||
want := clr
|
ch := make(chan color.RGBA, 1)
|
||||||
var got color.RGBA
|
go func() {
|
||||||
|
runOnMainThread(func() {
|
||||||
|
ch <- img.At(0, 0).(color.RGBA)
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
runOnMainThread(func() {
|
return testResult{
|
||||||
quit := errors.New("quit")
|
want: clr,
|
||||||
if err := ebiten.Run(func(*ebiten.Image) error {
|
got: ch,
|
||||||
got = img.At(0, 0).(color.RGBA)
|
}
|
||||||
return quit
|
}()
|
||||||
}, 320, 240, 1, ""); err != nil && err != quit {
|
|
||||||
t.Fatal(err)
|
func TestSetBeforeMain(t *testing.T) {
|
||||||
}
|
got := <-testSetBeforeMainResult.got
|
||||||
})
|
want := testSetBeforeMainResult.want
|
||||||
|
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var testDrawImageBeforeMainResult = func() testResult {
|
||||||
|
const w, h = 16, 16
|
||||||
|
src, _ := ebiten.NewImage(w, h, ebiten.FilterDefault)
|
||||||
|
dst, _ := ebiten.NewImage(w, h, ebiten.FilterDefault)
|
||||||
|
src.Set(0, 0, color.White)
|
||||||
|
dst.DrawImage(src, nil)
|
||||||
|
|
||||||
|
ch := make(chan color.RGBA, 1)
|
||||||
|
go func() {
|
||||||
|
runOnMainThread(func() {
|
||||||
|
ch <- dst.At(0, 0).(color.RGBA)
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
|
return testResult{
|
||||||
|
want: color.RGBA{0xff, 0xff, 0xff, 0xff},
|
||||||
|
got: ch,
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
func TestDrawImageBeforeMain(t *testing.T) {
|
||||||
|
got := <-testDrawImageBeforeMainResult.got
|
||||||
|
want := testDrawImageBeforeMainResult.want
|
||||||
|
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var testDrawTrianglesBeforeMainResult = func() testResult {
|
||||||
|
const w, h = 16, 16
|
||||||
|
src, _ := ebiten.NewImage(w, h, ebiten.FilterDefault)
|
||||||
|
dst, _ := ebiten.NewImage(w, h, ebiten.FilterDefault)
|
||||||
|
src.Set(0, 0, color.White)
|
||||||
|
vs := []ebiten.Vertex{
|
||||||
|
{
|
||||||
|
DstX: 0,
|
||||||
|
DstY: 0,
|
||||||
|
SrcX: 0,
|
||||||
|
SrcY: 0,
|
||||||
|
ColorR: 1,
|
||||||
|
ColorG: 1,
|
||||||
|
ColorB: 1,
|
||||||
|
ColorA: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
DstX: w,
|
||||||
|
DstY: 0,
|
||||||
|
SrcX: w,
|
||||||
|
SrcY: 0,
|
||||||
|
ColorR: 1,
|
||||||
|
ColorG: 1,
|
||||||
|
ColorB: 1,
|
||||||
|
ColorA: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
DstX: 0,
|
||||||
|
DstY: h,
|
||||||
|
SrcX: 0,
|
||||||
|
SrcY: h,
|
||||||
|
ColorR: 1,
|
||||||
|
ColorG: 1,
|
||||||
|
ColorB: 1,
|
||||||
|
ColorA: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
dst.DrawTriangles(vs, []uint16{0, 1, 2}, src, nil)
|
||||||
|
|
||||||
|
ch := make(chan color.RGBA, 1)
|
||||||
|
go func() {
|
||||||
|
runOnMainThread(func() {
|
||||||
|
ch <- dst.At(0, 0).(color.RGBA)
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
|
return testResult{
|
||||||
|
want: color.RGBA{0xff, 0xff, 0xff, 0xff},
|
||||||
|
got: ch,
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
func TestDrawTrianglesBeforeMain(t *testing.T) {
|
||||||
|
got := <-testDrawTrianglesBeforeMainResult.got
|
||||||
|
want := testDrawTrianglesBeforeMainResult.want
|
||||||
|
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("got: %v, want: %v", got, want)
|
t.Errorf("got: %v, want: %v", got, want)
|
||||||
|
Loading…
Reference in New Issue
Block a user