-
Notifications
You must be signed in to change notification settings - Fork 3
/
revisit_image_test.go
133 lines (107 loc) · 2.4 KB
/
revisit_image_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package gorevisit
import (
"image/color"
"image/draw"
"image/gif"
"image/jpeg"
"image/png"
"math/rand"
"testing"
)
func mockTransform(src draw.Image) {
orig := src.Bounds()
numToMod := (orig.Max.X * orig.Max.Y) / 2
for i := 0; i < numToMod; i++ {
x := rand.Intn(orig.Max.X)
y := rand.Intn(orig.Max.Y)
origColor := src.At(x, y).(color.RGBA)
origColor.R += 30
origColor.B += 30
origColor.G += 30
src.Set(x, y, origColor)
}
}
func TestNewRevisitImageWithJPEG(t *testing.T) {
jpegMsg, err := NewRevisitMsgFromFiles("./fixtures/bob.jpg")
if err != nil {
t.Fatal(err)
}
ri, err := NewRevisitImageFromMsg(jpegMsg)
if err != nil {
t.Fatal(err)
}
if len(ri.Rgbas) != 1 {
t.Errorf("ri.Rgbas length should be 1, is %d", len(ri.Rgbas))
}
if len(ri.Delay) != 1 {
t.Errorf("ri.Delay length should be 1, is %d", len(ri.Delay))
}
if ri.LoopCount != 0 {
t.Errorf("LoopCount should be 0, is %d", ri.LoopCount)
}
ri.Transform(mockTransform)
m, err := ri.RevisitMsg()
if err != nil {
t.Error(err)
}
_, err = jpeg.Decode(m.ImageByteReader())
if err != nil {
t.Error(err)
}
}
func TestNewRevisitImageWithPNG(t *testing.T) {
pngMsg, err := NewRevisitMsgFromFiles("./fixtures/connie.png")
if err != nil {
t.Fatal(err)
}
ri, err := NewRevisitImageFromMsg(pngMsg)
if err != nil {
t.Fatal(err)
}
if len(ri.Rgbas) != 1 {
t.Errorf("ri.Rgbas length should be 1, is %d", len(ri.Rgbas))
}
if len(ri.Delay) != 1 {
t.Errorf("ri.Delay length should be 1, is %d", len(ri.Delay))
}
if ri.LoopCount != 0 {
t.Errorf("LoopCount should be 0, is %d", ri.LoopCount)
}
ri.Transform(mockTransform)
m, err := ri.RevisitMsg()
if err != nil {
t.Error(err)
}
_, err = png.Decode(m.ImageByteReader())
if err != nil {
t.Error(err)
}
}
func TestNewRevisitImageWithGIF(t *testing.T) {
gifMsg, err := NewRevisitMsgFromFiles("./fixtures/bob.gif")
if err != nil {
t.Fatal(err)
}
ri, err := NewRevisitImageFromMsg(gifMsg)
if err != nil {
t.Fatal(err)
}
if len(ri.Rgbas) != 4 {
t.Errorf("ri.Rgbas length should be 4, is %d", len(ri.Rgbas))
}
if len(ri.Delay) != 4 {
t.Errorf("ri.Delay length should be 4, is %d", len(ri.Delay))
}
if ri.LoopCount != 0 {
t.Errorf("LoopCount should be 0, is %d", ri.LoopCount)
}
ri.Transform(mockTransform)
m, err := ri.RevisitMsg()
if err != nil {
t.Error(err)
}
_, err = gif.Decode(m.ImageByteReader())
if err != nil {
t.Error(err)
}
}