Permalink
Browse files

Improve test coverage.

  • Loading branch information...
aaron42net committed Nov 6, 2016
1 parent d523eed commit b7d808c00586382a1dc2efac5fb9a4245c5ea591
View
@@ -8,7 +8,7 @@ import (
const (
// FotomatVersion is updated by git-hooks/pre-commit
FotomatVersion = "2.6.194"
FotomatVersion = "2.6.195"
)
var (
View
@@ -82,7 +82,7 @@ func TestFormatCanLoad(t *testing.T) {
}
func TestFormatOrientation(t *testing.T) {
for i := 1; i <= 8; i++ {
for i := 0; i <= 8; i++ {
filename := "orient" + strconv.Itoa(i) + ".jpg"
m, err := Jpeg.MetadataFile(TestdataPath + filename)
@@ -138,8 +138,7 @@ func TestSwitchToLossy(t *testing.T) {
// And make sure that lossless webp is larger.
thumb = convert(img, SaveOptions{AllowWebp: true, Lossless: true})
assert.Nil(t, isSize(thumb, Webp, 256, 169))
// TODO: https://github.com/jcupitt/libvips/issues/410
// assert.NotEqual(t, len(thumb), lossyLen) // Lossless should be larger
assert.NotEqual(t, len(thumb), lossyLen) // Lossless should be larger
// Make sure LossyIfPhoto returns lossy.
thumb = convert(img, SaveOptions{Format: Webp, Lossless: true, LossyIfPhoto: true})
View
Binary file not shown.
View
Binary file not shown.
View
@@ -20,6 +20,28 @@ func TestOptionsMetadata(t *testing.T) {
assert.Equal(t, err, nil)
}
func TestOptionsValidation(t *testing.T) {
m := format.Metadata{Width: 640, Height: 480, Format: format.Jpeg}
_, err := Options{BlurSigma: 10}.Check(m)
assert.Equal(t, err, ErrBadOption)
_, err = Options{BlurSigma: -1}.Check(m)
assert.Equal(t, err, ErrBadOption)
_, err = Options{Width: -1}.Check(m)
assert.Equal(t, err, ErrTooSmall)
_, err = Options{Height: -1}.Check(m)
assert.Equal(t, err, ErrTooSmall)
_, err = Options{Width: 32767}.Check(m)
assert.Equal(t, err, ErrTooBig)
_, err = Options{Height: 32767}.Check(m)
assert.Equal(t, err, ErrTooBig)
}
func TestOptionsCrop(t *testing.T) {
m := format.Metadata{Width: 640, Height: 480, Format: format.Jpeg}
View
@@ -59,6 +59,9 @@ func TestErrors(t *testing.T) {
// Make sure director return status is working
ps.status = 403
assert.Equal(t, ps.getStatus("2px.png"), 403)
// Make sure NewProxy returns nil on bad input
assert.Nil(t, NewProxy(nil, nil, 0, nil))
}
type proxyServer struct {
@@ -33,6 +33,9 @@ func TestValidation(t *testing.T) {
// Load a 2x2 pixel image.
assert.Nil(t, tryNew("2px.png"))
// Load a CMYK image.
assert.Nil(t, tryNew("cmyk.jpg"))
// Return ErrTooBig on a 34000x16 PNG image.
assert.Equal(t, tryNew("34000px.png"), ErrTooBig)
@@ -105,6 +108,12 @@ func TestCrop(t *testing.T) {
if assert.Nil(t, err) {
assert.Nil(t, isSize(thumb, format.Jpeg, 398, 299, false))
}
// Verify cropping to fit, same result size.
thumb, err = Thumbnail(img, Options{Width: 796, Height: 1072, Crop: true})
if assert.Nil(t, err) {
assert.Nil(t, isSize(thumb, format.Jpeg, 398, 536, false))
}
}
func TestBlurSharpen(t *testing.T) {
@@ -147,7 +156,7 @@ func TestAlpha(t *testing.T) {
}
func TestRotation(t *testing.T) {
for i := 1; i <= 8; i++ {
for i := 0; i <= 8; i++ {
// Verify that New() correctly translates dimensions.
img := image("orient" + strconv.Itoa(i) + ".jpg")

0 comments on commit b7d808c

Please sign in to comment.