internal/restorable: add more tests

This commit is contained in:
Hajime Hoshi 2022-03-21 03:04:52 +09:00
parent 72a6ab8da4
commit e55dbbf3cd

View File

@ -932,6 +932,7 @@ func TestOverlappedPixels(t *testing.T) {
pix0[idx+3] = 0xff pix0[idx+3] = 0xff
} }
} }
dst.ReplacePixels(pix0, 0, 0, 2, 2)
pix1 := make([]byte, 4*2*2) pix1 := make([]byte, 4*2*2)
for j := 0; j < 2; j++ { for j := 0; j < 2; j++ {
@ -943,8 +944,6 @@ func TestOverlappedPixels(t *testing.T) {
pix1[idx+3] = 0xff pix1[idx+3] = 0xff
} }
} }
dst.ReplacePixels(pix0, 0, 0, 2, 2)
dst.ReplacePixels(pix1, 1, 1, 2, 2) dst.ReplacePixels(pix1, 1, 1, 2, 2)
wantColors := []color.RGBA{ wantColors := []color.RGBA{
@ -1003,12 +1002,17 @@ func TestOverlappedPixels(t *testing.T) {
} }
} }
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil { pix2 := make([]byte, 4*2*2)
t.Fatal(err) for j := 0; j < 2; j++ {
for i := 0; i < 2; i++ {
idx := 4 * (j*2 + i)
pix2[idx] = 0
pix2[idx+1] = 0
pix2[idx+2] = 0xff
pix2[idx+3] = 0xff
} }
if err := restorable.RestoreIfNeeded(ui.GraphicsDriverForTesting()); err != nil {
t.Fatal(err)
} }
dst.ReplacePixels(pix2, 1, 1, 2, 2)
wantColors = []color.RGBA{ wantColors = []color.RGBA{
{0xff, 0, 0, 0xff}, {0xff, 0, 0, 0xff},
@ -1016,12 +1020,12 @@ func TestOverlappedPixels(t *testing.T) {
{0, 0, 0, 0}, {0, 0, 0, 0},
{0xff, 0, 0, 0xff}, {0xff, 0, 0, 0xff},
{0, 0, 0, 0}, {0, 0, 0xff, 0xff},
{0, 0, 0, 0}, {0, 0, 0xff, 0xff},
{0, 0, 0, 0}, {0, 0, 0, 0},
{0, 0xff, 0, 0xff}, {0, 0, 0xff, 0xff},
{0, 0xff, 0, 0xff}, {0, 0, 0xff, 0xff},
} }
for j := 0; j < 3; j++ { for j := 0; j < 3; j++ {
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
@ -1036,4 +1040,25 @@ func TestOverlappedPixels(t *testing.T) {
} }
} }
} }
if err := restorable.ResolveStaleImages(ui.GraphicsDriverForTesting()); err != nil {
t.Fatal(err)
}
if err := restorable.RestoreIfNeeded(ui.GraphicsDriverForTesting()); err != nil {
t.Fatal(err)
}
for j := 0; j < 3; j++ {
for i := 0; i < 3; i++ {
r, g, b, a, err := dst.At(ui.GraphicsDriverForTesting(), i, j)
if err != nil {
t.Fatal(err)
}
got := color.RGBA{r, g, b, a}
want := wantColors[3*j+i]
if got != want {
t.Errorf("color at (%d, %d): got %v, want: %v", i, j, got, want)
}
}
}
} }