Browse files

test updates

  • Loading branch information...
1 parent 278b33e commit 5e1f3cab89998257baffcdf397d0d90b4a802457 @tobi committed May 29, 2012
Showing with 19 additions and 153 deletions.
  1. +19 −153 image_test.go
View
172 image_test.go
@@ -1,6 +1,7 @@
package mogrify
import (
+ "bytes"
"os"
"testing"
)
@@ -87,168 +88,33 @@ func TestResampleFailure(t *testing.T) {
}
}
-func TestSave(t *testing.T) {
+func TestDecodeEncode(t *testing.T) {
img := asset("./assets/image.jpg")
defer img.Destroy()
- resized, _ := img.NewResampled(100, 100)
+ resized, err := img.NewResampled(100, 100)
- dest, _ := os.Create("/tmp/dest.jpg")
- defer dest.Close()
-
- EncodeJpg(dest, resized)
-
-}
-
-// func TestSaveToSuccess(t *testing.T) {
-// img := Open("./assets/image.jpg")
-
-// if img == nil {
-// t.Fail()
-// return
-// }
-
-// defer img.Destroy()
-
-// res := img.SaveFile("/tmp/img.jpg")
-// if res != nil {
-// t.Fail()
-// }
-// }
-
-// func TestSaveToFailure(t *testing.T) {
-// img := Open("./assets/image.jpg")
-
-// if img == nil {
-// t.Fail()
-// return
-// }
-
-// defer img.Destroy()
-
-// res := img.SaveFile("/dgksjogdsksdgsdkgsd;lfsd-does-not-exist/img.jpg")
-// if res == nil {
-// t.Fail()
-// }
-// }
-
-// func TestOpenBlopSuccess(t *testing.T) {
-// bytes, _ := ioutil.ReadFile("./assets/image.jpg")
-
-// img := NewImage()
-// res := img.OpenBlob(bytes)
-// defer img.Destroy()
-
-// if res != nil {
-// t.FailNow()
-// }
-
-// assertDimension(t, img, "600x399")
-// }
-
-// func TestOpenBlopSuccessPng(t *testing.T) {
-// bytes, _ := ioutil.ReadFile("./assets/example.com.png")
-
-// img := NewImage()
-// res := img.OpenBlob(bytes)
-// defer img.Destroy()
-
-// if res != nil {
-// t.FailNow()
-// }
-
-// if dim := img.Dimensions(); dim != "1280x500" {
-// t.Fatalf("Got wrong dimensions expected:1280x500 got %s", dim)
-// }
-// }
-
-// func TestOpenBlopFailure(t *testing.T) {
-
-// img := NewImage()
-// res := img.OpenBlob([]byte{'a'})
-// defer img.Destroy()
-
-// if res == nil {
-// t.Fail()
-// }
-
-// res = img.OpenBlob([]byte{})
-
-// if res == nil {
-// t.Fail()
-// }
-// }
-
-// func TestSaveToBlob(t *testing.T) {
-// img := Open("./assets/image.jpg")
-// defer img.Destroy()
-
-// fp, err := os.Create("/tmp/img3.jpg")
-// if err != nil {
-// t.Fail()
-// }
-
-// defer fp.Close()
-
-// _, err = img.Write(fp)
-
-// if err != nil {
-// t.Fail()
-// }
-
-// }
-
-// func TestTransformation(t *testing.T) {
-// img := Open("./assets/image.jpg")
-// defer img.Destroy()
-
-// img2, err := img.NewTransformation("", "100x50>")
-
-// if err != nil {
-// t.FailNow()
-// return
-// }
-
-// defer img2.Destroy()
-
-// assertDimension(t, img2, "75x50")
-
-// img3, err := img.NewTransformation("", "100x50!")
-// defer img3.Destroy()
-
-// if err != nil {
-// t.FailNow()
-// return
-// }
-
-// assertDimension(t, img3, "100x50")
+ if err != nil {
+ t.Error(err)
+ return
+ }
-// //img2.SaveFile("/tmp/img4.jpg")
-// }
+ assertDimension(t, resized, "100x100")
-// func TestReadFrom(t *testing.T) {
-// file, _ := os.Open("./assets/image.jpg")
-// image := NewImage()
-// image.ReadFrom(file)
-// assertDimension(t, image, "100x50")
-// }
+ dest, _ := os.Create("/tmp/dest.jpg")
+ defer dest.Close()
-// func BenchmarkAndMemoryTest(b *testing.B) {
-// var before runtime.MemStats
-// var after runtime.MemStats
+ var buffer bytes.Buffer
-// runtime.ReadMemStats(&before)
+ _, err = EncodeJpg(&buffer, resized)
-// work := func() {
-// img := Open("./assets/image.jpg")
-// img.Destroy()
-// }
+ if err != nil {
+ t.Error(err)
+ return
+ }
-// for i := 0; i < 100; i++ {
-// work()
-// }
+ roundtrip := DecodeJpg(&buffer)
-// runtime.ReadMemStats(&after)
+ assertDimension(t, roundtrip, "100x100")
-// log.Printf("sys memory before: %d after %d - diff: %d", before.HeapSys, after.HeapSys, after.HeapSys-before.HeapSys)
-// }
+}

0 comments on commit 5e1f3ca

Please sign in to comment.