-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathppm_test.go
71 lines (64 loc) · 1.71 KB
/
ppm_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
// Test PPM files.
package netpbm
import (
"bytes"
"compress/flate"
"testing"
)
// TestNetpbmDecodePGMPPMOpts determines if netpbm.Decode can decode a PGM file
// with PPM options.
func TestNetpbmDecodePGMPPMOpts(t *testing.T) {
r := flate.NewReader(bytes.NewBufferString(pgmRaw))
defer r.Close()
img, err := Decode(r, &DecodeOptions{
Target: PPM,
Exact: false,
})
if err != nil {
t.Fatal(err)
}
if img.Format() != PPM {
t.Fatalf("Expected PPM but received %s", img.Format())
}
}
// TestDecodePBMEncodePPM confirms that a PBM file can be re-encoded as PPM.
func TestDecodePBMEncodePPM(t *testing.T) {
var w bytes.Buffer
img := imageFromString(t, pbmRaw, PBM)
opts := &EncodeOptions{Format: PPM}
err := Encode(&w, img, opts)
if err != nil {
t.Fatal(err)
}
}
// TestDecodePGMEncodePPM confirms that a PGM file can be re-encoded as PPM.
func TestDecodePGMEncodePPM(t *testing.T) {
var w bytes.Buffer
img := imageFromString(t, pgmRaw, PGM)
opts := &EncodeOptions{Format: PPM}
err := Encode(&w, img, opts)
if err != nil {
t.Fatal(err)
}
}
// TestNetpbmDecodePlainPBMPPMOpts determines if netpbm.Decode can decode a
// plain PBM file with PPM options.
func TestNetpbmDecodePlainPBMPPMOpts(t *testing.T) {
r := flate.NewReader(bytes.NewBufferString(pbmPlain))
defer r.Close()
img, err := Decode(r, &DecodeOptions{
Target: PPM,
Exact: false,
})
if err != nil {
t.Fatal(err)
}
if img.Format() != PPM {
t.Fatalf("Expected PPM but received %s", img.Format())
}
}
// TestAddRemoveAlphaPPM determines if we can add an alpha channel to a PPM
// file, remove it, and wind up with the same PPM image as we started with.
func TestAddRemoveAlphaPPM(t *testing.T) {
addRemoveAlpha(t, ppmRaw, nil, nil)
}