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
6b4fb9f8
Commit
6b4fb9f8
authored
Jun 22, 2011
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
image: basic test for the 16-bits-per-color-channel types.
R=r CC=golang-dev
https://golang.org/cl/4635059
parent
c8443d72
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
24 deletions
+55
-24
image_test.go
src/pkg/image/image_test.go
+55
-24
No files found.
src/pkg/image/image_test.go
View file @
6b4fb9f8
...
...
@@ -8,6 +8,12 @@ import (
"testing"
)
type
image
interface
{
Image
Set
(
int
,
int
,
Color
)
SubImage
(
Rectangle
)
Image
}
func
cmp
(
t
*
testing
.
T
,
cm
ColorModel
,
c0
,
c1
Color
)
bool
{
r0
,
g0
,
b0
,
a0
:=
cm
.
Convert
(
c0
)
.
RGBA
()
r1
,
g1
,
b1
,
a1
:=
cm
.
Convert
(
c1
)
.
RGBA
()
...
...
@@ -15,12 +21,7 @@ func cmp(t *testing.T, cm ColorModel, c0, c1 Color) bool {
}
func
TestImage
(
t
*
testing
.
T
)
{
type
buffered
interface
{
Image
Set
(
int
,
int
,
Color
)
SubImage
(
Rectangle
)
Image
}
testImage
:=
[]
Image
{
testImage
:=
[]
image
{
NewRGBA
(
10
,
10
),
NewRGBA64
(
10
,
10
),
NewNRGBA
(
10
,
10
),
...
...
@@ -35,36 +36,66 @@ func TestImage(t *testing.T) {
}),
}
for
_
,
m
:=
range
testImage
{
b
:=
m
.
(
buffered
)
if
!
Rect
(
0
,
0
,
10
,
10
)
.
Eq
(
b
.
Bounds
())
{
t
.
Errorf
(
"%T: want bounds %v, got %v"
,
b
,
Rect
(
0
,
0
,
10
,
10
),
b
.
Bounds
())
if
!
Rect
(
0
,
0
,
10
,
10
)
.
Eq
(
m
.
Bounds
())
{
t
.
Errorf
(
"%T: want bounds %v, got %v"
,
m
,
Rect
(
0
,
0
,
10
,
10
),
m
.
Bounds
())
continue
}
if
!
cmp
(
t
,
m
.
ColorModel
(),
Transparent
,
m
.
At
(
6
,
3
))
{
t
.
Errorf
(
"%T: at (6, 3), want a zero color, got %v"
,
m
,
m
.
At
(
6
,
3
))
continue
}
m
.
Set
(
6
,
3
,
Opaque
)
if
!
cmp
(
t
,
m
.
ColorModel
(),
Opaque
,
m
.
At
(
6
,
3
))
{
t
.
Errorf
(
"%T: at (6, 3), want a non-zero color, got %v"
,
m
,
m
.
At
(
6
,
3
))
continue
}
if
!
cmp
(
t
,
b
.
ColorModel
(),
Transparent
,
b
.
At
(
6
,
3
))
{
t
.
Errorf
(
"%T: at (6, 3), want a zero color, got %v"
,
b
,
b
.
At
(
6
,
3
))
m
=
m
.
SubImage
(
Rect
(
3
,
2
,
9
,
8
))
.
(
image
)
if
!
Rect
(
3
,
2
,
9
,
8
)
.
Eq
(
m
.
Bounds
())
{
t
.
Errorf
(
"%T: sub-image want bounds %v, got %v"
,
m
,
Rect
(
3
,
2
,
9
,
8
),
m
.
Bounds
())
continue
}
b
.
Set
(
6
,
3
,
Opaque
)
if
!
cmp
(
t
,
b
.
ColorModel
(),
Opaque
,
b
.
At
(
6
,
3
))
{
t
.
Errorf
(
"%T: at (6, 3), want a non-zero color, got %v"
,
b
,
b
.
At
(
6
,
3
))
if
!
cmp
(
t
,
m
.
ColorModel
(),
Opaque
,
m
.
At
(
6
,
3
))
{
t
.
Errorf
(
"%T: sub-image at (6, 3), want a non-zero color, got %v"
,
m
,
m
.
At
(
6
,
3
))
continue
}
b
=
b
.
SubImage
(
Rect
(
3
,
2
,
9
,
8
))
.
(
buffered
)
if
!
Rect
(
3
,
2
,
9
,
8
)
.
Eq
(
b
.
Bounds
())
{
t
.
Errorf
(
"%T: sub-image want bounds %v, got %v"
,
b
,
Rect
(
3
,
2
,
9
,
8
),
b
.
Bounds
())
if
!
cmp
(
t
,
m
.
ColorModel
(),
Transparent
,
m
.
At
(
3
,
3
))
{
t
.
Errorf
(
"%T: sub-image at (3, 3), want a zero color, got %v"
,
m
,
m
.
At
(
3
,
3
))
continue
}
if
!
cmp
(
t
,
b
.
ColorModel
(),
Opaque
,
b
.
At
(
6
,
3
))
{
t
.
Errorf
(
"%T: sub-image at (6, 3), want a non-zero color, got %v"
,
b
,
b
.
At
(
6
,
3
))
m
.
Set
(
3
,
3
,
Opaque
)
if
!
cmp
(
t
,
m
.
ColorModel
(),
Opaque
,
m
.
At
(
3
,
3
))
{
t
.
Errorf
(
"%T: sub-image at (3, 3), want a non-zero color, got %v"
,
m
,
m
.
At
(
3
,
3
))
continue
}
if
!
cmp
(
t
,
b
.
ColorModel
(),
Transparent
,
b
.
At
(
3
,
3
))
{
t
.
Errorf
(
"%T: sub-image at (3, 3), want a zero color, got %v"
,
b
,
b
.
At
(
3
,
3
))
}
}
func
Test16BitsPerColorChannel
(
t
*
testing
.
T
)
{
testColorModel
:=
[]
ColorModel
{
RGBA64ColorModel
,
NRGBA64ColorModel
,
Alpha16ColorModel
,
Gray16ColorModel
,
}
for
_
,
cm
:=
range
testColorModel
{
c
:=
cm
.
Convert
(
RGBA64Color
{
0x1234
,
0x1234
,
0x1234
,
0x1234
})
// Premultiplied alpha.
r
,
_
,
_
,
_
:=
c
.
RGBA
()
if
r
!=
0x1234
{
t
.
Errorf
(
"%T: want red value 0x%04x got 0x%04x"
,
c
,
0x1234
,
r
)
continue
}
b
.
Set
(
3
,
3
,
Opaque
)
if
!
cmp
(
t
,
b
.
ColorModel
(),
Opaque
,
b
.
At
(
3
,
3
))
{
t
.
Errorf
(
"%T: sub-image at (3, 3), want a non-zero color, got %v"
,
b
,
b
.
At
(
3
,
3
))
}
testImage
:=
[]
image
{
NewRGBA64
(
10
,
10
),
NewNRGBA64
(
10
,
10
),
NewAlpha16
(
10
,
10
),
NewGray16
(
10
,
10
),
}
for
_
,
m
:=
range
testImage
{
m
.
Set
(
1
,
2
,
NRGBA64Color
{
0xffff
,
0xffff
,
0xffff
,
0x1357
})
// Non-premultiplied alpha.
r
,
_
,
_
,
_
:=
m
.
At
(
1
,
2
)
.
RGBA
()
if
r
!=
0x1357
{
t
.
Errorf
(
"%T: want red value 0x%04x got 0x%04x"
,
m
,
0x1357
,
r
)
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