-
Notifications
You must be signed in to change notification settings - Fork 0
/
xbm_test.go
78 lines (67 loc) · 1.39 KB
/
xbm_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
66
67
68
69
70
71
72
73
74
75
76
77
78
package goxbm
import (
"bytes"
"image"
"image/png"
"testing"
)
func TestEncodeAgainstKnownValue(t *testing.T) {
png := getPngImage1()
existingXbm := getExistingXbmBytes1()
buf := bytes.NewBuffer([]byte{})
err := Encode(buf, png)
if err != nil {
t.Fatalf("Error encoding xbm: %s", err)
}
if bytes.Compare(buf.Bytes(), existingXbm) != 0 {
t.Error("Byte comparison failed on image 1")
}
png = getPngImage2()
existingXbm = getExistingXbmBytes2()
buf = bytes.NewBuffer([]byte{})
err = Encode(buf, png)
if err != nil {
t.Fatalf("Error encoding xbm: %s", err)
}
if bytes.Compare(buf.Bytes(), existingXbm) != 0 {
t.Error("Byte comparison failed on image 2")
}
}
func getExistingXbmBytes1() []byte {
imgBytes, err := Asset("test_image.xbm")
if err != nil {
panic(err)
}
return imgBytes
}
func getExistingXbmBytes2() []byte {
imgBytes, err := Asset("test_image2.xbm")
if err != nil {
panic(err)
}
return imgBytes
}
func getPngImage1() image.Image {
imgBytes, err := Asset("test_image.png")
if err != nil {
panic(err)
}
imgReader := bytes.NewReader(imgBytes)
img, err := png.Decode(imgReader)
if err != nil {
panic(err)
}
return img
}
func getPngImage2() image.Image {
imgBytes, err := Asset("test_image2.png")
if err != nil {
panic(err)
}
imgReader := bytes.NewReader(imgBytes)
img, err := png.Decode(imgReader)
if err != nil {
panic(err)
}
return img
}