graphics: Better test for a crash

This commit is contained in:
Hajime Hoshi 2019-01-11 00:31:17 +09:00
parent 876e483d0c
commit 6783aaae56
2 changed files with 14 additions and 10 deletions

View File

@ -1339,3 +1339,17 @@ func TestImageAddressRepeat(t *testing.T) {
}
}
}
func TestReplacePixelsAfterClear(t *testing.T) {
const w, h = 256, 256
img, _ := NewImage(w, h, FilterDefault)
img.ReplacePixels(make([]byte, 4*w*h))
// Clear used to call DrawImage to clear the image, which was the cause of crash. It is because after
// DrawImage is called, ReplacePixels for a region is forbidden.
//
// Now ReplacePixels was always called at Clear instead.
img.Clear()
img.ReplacePixels(make([]byte, 4*w*h))
// The test passes if this doesn't crash.
}

View File

@ -287,13 +287,3 @@ func TestReplacePixelsAfterDrawImage(t *testing.T) {
}
}
}
func TestVariousReplacePixelsMustNotCrash(t *testing.T) {
const w, h = 256, 256
img0 := NewImage(w, h)
defer img0.Dispose()
img0.ReplacePixels(nil)
img0.ReplacePixels(make([]byte, 4*w*h))
img0.ReplacePixels(nil)
img0.ReplacePixels(make([]byte, 4*w*h))
}