-
Notifications
You must be signed in to change notification settings - Fork 0
/
reader_test.go
executable file
·81 lines (72 loc) · 1.63 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package pbm_test
import (
"bytes"
"os"
"strings"
"testing"
"github.com/slashformotion/pbm"
)
func TestDecodeConfigErrorNil(t *testing.T) {
testString := `P4
24 24
`
r := strings.NewReader(testString)
_, err := pbm.DecodeConfig(r)
if err != nil {
t.Error("Decode Config should not return an error on valid string")
}
}
func TestDecodeConfigErrorNotNil(t *testing.T) {
testString := `P2
24 24
`
r := strings.NewReader(testString)
_, err := pbm.DecodeConfig(r)
if err == nil {
t.Error("Decode Config should return an error on invalid string")
}
}
func TestDecodeConfigNegativeDims(t *testing.T) {
testString := `P4
24 -24
`
r := strings.NewReader(testString)
_, err := pbm.DecodeConfig(r)
if err == nil {
t.Error("Decode Config should return an error on invalid dimension")
}
}
func TestDecode(t *testing.T) {
testString := `P4
4 1
`
testBytes := []byte(testString)
testBytes = append(testBytes, byte(0x0f))
r := bytes.NewReader(testBytes)
_, err := pbm.Decode(r)
if err != nil {
t.Error("Decode should not return an error on valid bytes")
}
}
func TestDecodeFiles(t *testing.T) {
filepaths := []string{"fixtures/sample_1280_853.pbm", "fixtures/sample_1920_1280.pbm", "fixtures/sample_5184_3456.pbm", "fixtures/sample_640_426.pbm"}
for _, path := range filepaths {
f, err := os.Open(path)
if err != nil {
panic(err)
}
defer func() {
err := f.Close()
if err != nil {
panic(err)
}
}()
img, err := pbm.Decode(f)
if err != nil {
t.Errorf("Decode should not return an error on valid file, got=%v (file=%v)", err, path)
}
if img == nil {
t.Error("Decode should not return a nil img")
}
}
}