From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- libgo/go/image/png/writer_test.go | 86 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 libgo/go/image/png/writer_test.go (limited to 'libgo/go/image/png/writer_test.go') diff --git a/libgo/go/image/png/writer_test.go b/libgo/go/image/png/writer_test.go new file mode 100644 index 000000000..f218a5564 --- /dev/null +++ b/libgo/go/image/png/writer_test.go @@ -0,0 +1,86 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package png + +import ( + "bytes" + "fmt" + "image" + "io" + "os" + "testing" +) + +func diff(m0, m1 image.Image) os.Error { + b0, b1 := m0.Bounds(), m1.Bounds() + if !b0.Eq(b1) { + return fmt.Errorf("dimensions differ: %v vs %v", b0, b1) + } + for y := b0.Min.Y; y < b0.Max.Y; y++ { + for x := b0.Min.X; x < b0.Max.X; x++ { + r0, g0, b0, a0 := m0.At(x, y).RGBA() + r1, g1, b1, a1 := m1.At(x, y).RGBA() + if r0 != r1 || g0 != g1 || b0 != b1 || a0 != a1 { + return fmt.Errorf("colors differ at (%d, %d): %v vs %v", x, y, m0.At(x, y), m1.At(x, y)) + } + } + } + return nil +} + +func TestWriter(t *testing.T) { + // The filenames variable is declared in reader_test.go. + for _, fn := range filenames { + qfn := "testdata/pngsuite/" + fn + ".png" + // Read the image. + m0, err := readPng(qfn) + if err != nil { + t.Error(fn, err) + continue + } + // Read the image again, and push it through a pipe that encodes at the write end, and decodes at the read end. + pr, pw := io.Pipe() + defer pr.Close() + go func() { + defer pw.Close() + m1, err := readPng(qfn) + if err != nil { + t.Error(fn, err) + return + } + err = Encode(pw, m1) + if err != nil { + t.Error(fn, err) + return + } + }() + m2, err := Decode(pr) + if err != nil { + t.Error(fn, err) + continue + } + // Compare the two. + err = diff(m0, m2) + if err != nil { + t.Error(fn, err) + continue + } + } +} + +func BenchmarkEncodePaletted(b *testing.B) { + b.StopTimer() + img := image.NewPaletted(640, 480, + []image.Color{ + image.RGBAColor{0, 0, 0, 255}, + image.RGBAColor{255, 255, 255, 255}, + }) + b.StartTimer() + buffer := new(bytes.Buffer) + for i := 0; i < b.N; i++ { + buffer.Reset() + Encode(buffer, img) + } +} -- cgit v1.2.3