tiff: re-organize some test cases, and make comment style consistent.

There is no code changes in this CL, just a copy/paste and some
wordsmithing.

Change-Id: I418e8aed5ab997fad4214e8049287cac4bce8bf6
Reviewed-on: https://go-review.googlesource.com/11274
Reviewed-by: Nigel Tao <nigeltao@golang.org>
This commit is contained in:
Nigel Tao 2015-06-19 15:56:41 +10:00
parent e5f3f2f6c0
commit d6cb0a28ce

View File

@ -38,9 +38,9 @@ func load(name string) (image.Image, error) {
return img, nil
}
// TestNoRPS tries to decode an image that has no RowsPerStrip tag.
// The tag is mandatory according to the spec but some software omits
// it in the case of a single strip.
// TestNoRPS tests decoding an image that has no RowsPerStrip tag. The tag is
// mandatory according to the spec but some software omits it in the case of a
// single strip.
func TestNoRPS(t *testing.T) {
_, err := load("no_rps.tiff")
if err != nil {
@ -48,8 +48,9 @@ func TestNoRPS(t *testing.T) {
}
}
// TestNoCompression tries to decode an images that has no Compression tag.
// This tag is mandatory, but most tools interpret a missing value as no compression.
// TestNoCompression tests decoding an image that has no Compression tag. This
// tag is mandatory, but most tools interpret a missing value as no
// compression.
func TestNoCompression(t *testing.T) {
_, err := load("no_compress.tiff")
if err != nil {
@ -176,8 +177,8 @@ func TestDecode(t *testing.T) {
compare(t, img0, img4)
}
// TestDecodeLZW tests that decoding a PNG image and a LZW-compressed TIFF image
// result in the same pixel data.
// TestDecodeLZW tests that decoding a PNG image and a LZW-compressed TIFF
// image result in the same pixel data.
func TestDecodeLZW(t *testing.T) {
img0, err := load("blue-purple-pink.png")
if err != nil {
@ -236,8 +237,36 @@ func replace(src []byte, find, repl string) ([]byte, error) {
return dst, nil
}
// TestTileTooBig checks that we do not panic when a tile is too big compared
// to the data available.
// TestZeroBitsPerSample tests that an IFD with a bitsPerSample of 0 does not
// cause a crash.
// Issue 10711.
func TestZeroBitsPerSample(t *testing.T) {
b0, err := ioutil.ReadFile(testdataDir + "bw-deflate.tiff")
if err != nil {
t.Fatal(err)
}
// Mutate the loaded image to have the problem.
// 02 01: tag number (tBitsPerSample)
// 03 00: data type (short, or uint16)
// 01 00 00 00: count
// ?? 00 00 00: value (1 -> 0)
b1, err := replace(b0,
"02 01 03 00 01 00 00 00 01 00 00 00",
"02 01 03 00 01 00 00 00 00 00 00 00",
)
if err != nil {
t.Fatal(err)
}
_, err = Decode(bytes.NewReader(b1))
if err == nil {
t.Fatal("Decode with 0 bits per sample: got nil error, want non-nil")
}
}
// TestTileTooBig tests that we do not panic when a tile is too big compared to
// the data available.
// Issue 10712
func TestTileTooBig(t *testing.T) {
b0, err := ioutil.ReadFile(testdataDir + "video-001-tile-64x64.tiff")
@ -283,8 +312,8 @@ func TestTileTooBig(t *testing.T) {
}
}
// Do not panic when image dimensions are zero, return zero-sized
// image instead.
// TestZeroSizedImages tests that decoding does not panic when image dimensions
// are zero, and returns a zero-sized image instead.
// Issue 10393.
func TestZeroSizedImages(t *testing.T) {
testsizes := []struct {
@ -308,8 +337,8 @@ func TestZeroSizedImages(t *testing.T) {
}
}
// TestLargeIFDEntry verifies that a large IFD entry does not cause Decode
// to panic.
// TestLargeIFDEntry tests that a large IFD entry does not cause Decode to
// panic.
// Issue 10596.
func TestLargeIFDEntry(t *testing.T) {
testdata := "II*\x00\x08\x00\x00\x00\f\x000000000000" +
@ -327,33 +356,6 @@ func TestLargeIFDEntry(t *testing.T) {
}
}
// TestZeroBitsPerSample verifies that an IFD with a bitsPerSample of 0 does not cause a crash.
// Issue 10711.
func TestZeroBitsPerSample(t *testing.T) {
b0, err := ioutil.ReadFile(testdataDir + "bw-deflate.tiff")
if err != nil {
t.Fatal(err)
}
// Mutate the loaded image to have the problem.
// 02 01: tag number (tBitsPerSample)
// 03 00: data type (short, or uint16)
// 01 00 00 00: count
// ?? 00 00 00: value (1 -> 0)
b1, err := replace(b0,
"02 01 03 00 01 00 00 00 01 00 00 00",
"02 01 03 00 01 00 00 00 00 00 00 00",
)
if err != nil {
t.Fatal(err)
}
_, err = Decode(bytes.NewReader(b1))
if err == nil {
t.Fatal("Decode with 0 bits per sample: got nil error, want non-nil")
}
}
// benchmarkDecode benchmarks the decoding of an image.
func benchmarkDecode(b *testing.B, filename string) {
b.StopTimer()