forked from pressly/goico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader_test.go
57 lines (49 loc) · 1.03 KB
/
reader_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
package ico
import (
"bytes"
"fmt"
"image/jpeg"
"io/ioutil"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
const (
testICO = "testdata/wiki.ico"
testPNG = "testdata/wiki.png"
)
func TestDecodeAll(t *testing.T) {
t.Parallel()
assert := assert.New(t)
files, _ := filepath.Glob("testdata/favicons/*.ico")
for i, f := range files {
fmt.Println()
fmt.Println(i, "WORKING WITH", f)
fmt.Println()
icoData, err := ioutil.ReadFile(f)
assert.NoError(err, f)
r := bytes.NewReader(icoData)
ic, err := DecodeAll(r)
assert.NoError(err, f)
if err != nil {
continue
}
for i, im := range ic.Image {
var jpgName string
if len(ic.Image) == 1 {
jpgName = f + ".jpg"
} else {
jpgName = f + fmt.Sprintf("-%d.jpg", i)
}
jpgData, err := ioutil.ReadFile(jpgName)
assert.NoError(err, jpgName)
r = bytes.NewReader(jpgData)
jpgImage, err := jpeg.Decode(r)
assert.NoError(err, jpgName)
if err != nil {
continue
}
assert.Equal(im.Bounds(), jpgImage.Bounds())
}
}
}