-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpam_test.go
77 lines (69 loc) · 1.94 KB
/
pam_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
// Test PAM files.
package netpbm
import (
"bytes"
"compress/flate"
"testing"
)
// TestNetpbmDecodePGMPAMOpts determines if netpbm.Decode can decode a PGM file
// with PAM options.
func TestNetpbmDecodePGMPAMOpts(t *testing.T) {
r := flate.NewReader(bytes.NewBufferString(pgmRaw))
defer r.Close()
img, err := Decode(r, &DecodeOptions{
Target: PAM,
Exact: false,
})
if err != nil {
t.Fatal(err)
}
if img.Format() != PGM {
t.Fatalf("Expected PGM but received %s", img.Format())
}
}
// TestDecodePBMEncodePAM confirms that a PBM file can be re-encoded as PAM.
func TestDecodePBMEncodePAM(t *testing.T) {
var w bytes.Buffer
img := imageFromString(t, pbmRaw, PBM)
opts := &EncodeOptions{Format: PAM}
err := Encode(&w, img, opts)
if err != nil {
t.Fatal(err)
}
}
// TestDecodePGMEncodePAM confirms that a PGM file can be re-encoded as PAM.
func TestDecodePGMEncodePAM(t *testing.T) {
var w bytes.Buffer
img := imageFromString(t, pgmRaw, PGM)
opts := &EncodeOptions{Format: PAM}
err := Encode(&w, img, opts)
if err != nil {
t.Fatal(err)
}
}
// TestNetpbmDecodePlainPBMPAMOpts determines if netpbm.Decode can decode a
// plain PBM file with PAM options.
func TestNetpbmDecodePlainPBMPAMOpts(t *testing.T) {
r := flate.NewReader(bytes.NewBufferString(pbmPlain))
defer r.Close()
img, err := Decode(r, &DecodeOptions{
Target: PAM,
Exact: false,
})
if err != nil {
t.Fatal(err)
}
if img.Format() != PBM {
t.Fatalf("Expected PBM but received %s", img.Format())
}
}
// TestRemoveAlphaFromPAMRGBA checks if we can remove the alpha channel from an
// RGBA image and wind up with an RGB image.
func TestRemoveAlphaFromPAMRGBA(t *testing.T) {
removeCompareAlpha(t, pamRawColorAlpha, pamRawColor)
}
// TestRemoveAlphaFromPAMGrayA checks if we can remove the alpha channel from a
// grayscale + alpha image and wind up with a grayscale image.
func TestRemoveAlphaFromPAMGrayA(t *testing.T) {
removeCompareAlpha(t, pamRawGrayAlpha, pamRawGray)
}