-
Notifications
You must be signed in to change notification settings - Fork 10
/
writer_test.go
65 lines (57 loc) · 1.03 KB
/
writer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package ico
import (
"testing"
"os"
"path/filepath"
"image"
"image/png"
)
func TestEncode(t *testing.T) {
t.Parallel()
origfile := "testdata/golang.ico"
file := "testdata/golang_test.ico"
f, err := os.Open("testdata/golang.png")
img, err := png.Decode(f)
if err != nil {
t.Fatal(err)
}
f.Close()
var newFile *os.File
if newFile, err = os.Create(filepath.Join(file)); err != nil {
t.Error(err)
}
err = Encode(newFile, img)
if err != nil {
t.Error(err)
}
newFile.Close()
f, err = os.Open(origfile)
if err != nil {
t.Error(err)
}
origICO, err := Decode(f)
if err != nil {
t.Fatal(err)
}
f.Close()
newFile, err = os.Open(file)
if err != nil {
t.Error(err)
}
newICO, err := Decode(newFile)
if err != nil {
t.Error(err)
}
newFile.Close()
inrgba, ok := origICO.(*image.NRGBA)
if !ok {
t.Fatal("not nrgba")
}
pnrgba, ok := newICO.(*image.NRGBA)
if !ok {
t.Fatal("new not nrgba")
}
if b, err := fastCompare(inrgba, pnrgba); err != nil || b != 0 {
t.Fatalf("pix differ %d %v\n", b, err)
}
}