-
Notifications
You must be signed in to change notification settings - Fork 0
/
gifview_test.go
56 lines (50 loc) · 1.3 KB
/
gifview_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
package gifview
import (
"path/filepath"
"testing"
)
func TestImageLoad(t *testing.T) {
// Exercise failure paths
errorTests := []struct {
path string
err string
}{
{"missing.gif", "Unable to open file: open testdata/missing.gif: no such file or directory"},
{"bad.gif", "Unable to decode GIF: gif: reading header: unexpected EOF"},
{"odd.gif", "Unable to convert frame 0: pixelview: Can't process image with uneven height"},
}
for _, s := range errorTests {
t.Run(s.path, func(t *testing.T) {
_, err := FromImagePath(filepath.Join("testdata", s.path))
if err.Error() != s.err {
t.Errorf("Expected: %v, Got: %v", s.err, err)
}
})
}
// Load a good gif
t.Run("good.gif", func(t *testing.T) {
_, err := FromImagePath(filepath.Join("testdata", "good.gif"))
if err != nil {
t.Errorf("Expected: nil, Got: %v", err)
}
})
}
func TestCurrentFrame(t *testing.T) {
t.Run("good.gif", func(t *testing.T) {
g, err := FromImagePath(filepath.Join("testdata", "good.gif"))
if err != nil {
t.Errorf("Expected: nil, Got: %v", err)
}
f := g.GetCurrentFrame()
if f < 0 || f > 2 {
t.Errorf("Expected less than 2, Got: %v", f)
}
})
t.Run("empty.gif", func(t *testing.T) {
g := NewGifView()
f := g.GetCurrentFrame()
if f != 0 {
t.Errorf("Expected 0, Got: %v", f)
}
})
}