Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
093af4e5
Commit
093af4e5
authored
Oct 08, 2009
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PNG encoder unit test.
R=rsc,r APPROVED=r DELTA=84 (77 added, 6 deleted, 1 changed) OCL=35456 CL=35458
parent
55edf49a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
7 deletions
+78
-7
reader_test.go
src/pkg/image/png/reader_test.go
+9
-7
writer_test.go
src/pkg/image/png/writer_test.go
+69
-0
No files found.
src/pkg/image/png/reader_test.go
View file @
093af4e5
...
...
@@ -33,6 +33,14 @@ var filenames = []string {
//"basn6a16", // bit depth is not 8
}
func
readPng
(
filename
string
)
(
image
.
Image
,
os
.
Error
)
{
f
,
err
:=
os
.
Open
(
filename
,
os
.
O_RDONLY
,
0444
);
if
err
!=
nil
{
return
nil
,
err
;
}
defer
f
.
Close
();
return
Decode
(
f
);
}
// An approximation of the sng command-line tool.
func
sng
(
w
io
.
WriteCloser
,
filename
string
,
png
image
.
Image
)
{
...
...
@@ -103,13 +111,7 @@ func sng(w io.WriteCloser, filename string, png image.Image) {
func
TestReader
(
t
*
testing
.
T
)
{
for
_
,
fn
:=
range
filenames
{
// Read the .png file.
pf
,
err
:=
os
.
Open
(
"testdata/pngsuite/"
+
fn
+
".png"
,
os
.
O_RDONLY
,
0444
);
if
err
!=
nil
{
t
.
Error
(
fn
,
err
);
continue
}
defer
pf
.
Close
();
image
,
err
:=
Decode
(
pf
);
image
,
err
:=
readPng
(
"testdata/pngsuite/"
+
fn
+
".png"
);
if
err
!=
nil
{
t
.
Error
(
fn
,
err
);
continue
...
...
src/pkg/image/png/writer_test.go
0 → 100644
View file @
093af4e5
// 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
(
"fmt"
;
"image"
;
"io"
;
"os"
;
"testing"
;
)
func
diff
(
m0
,
m1
image
.
Image
)
os
.
Error
{
if
m0
.
Width
()
!=
m1
.
Width
()
||
m0
.
Height
()
!=
m1
.
Height
()
{
return
os
.
NewError
(
fmt
.
Sprintf
(
"dimensions differ: %dx%d vs %dx%d"
,
m0
.
Width
(),
m0
.
Height
(),
m1
.
Width
(),
m1
.
Height
()));
}
for
y
:=
0
;
y
<
m0
.
Height
();
y
++
{
for
x
:=
0
;
x
<
m0
.
Width
();
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
os
.
NewError
(
fmt
.
Sprintf
(
"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
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment