-
Notifications
You must be signed in to change notification settings - Fork 4
/
pgm_test.go
48 lines (43 loc) · 1.05 KB
/
pgm_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
// Test PGM files.
package netpbm
import (
"bytes"
"compress/flate"
"testing"
)
// TestNetpbmDecodePBMPGMOpts determines if netpbm.Decode can decode a PBM file
// with PGM options.
func TestNetpbmDecodePBMPGMOpts(t *testing.T) {
r := flate.NewReader(bytes.NewBufferString(pbmRaw))
defer r.Close()
img, err := Decode(r, &DecodeOptions{
Target: PGM,
Exact: false,
})
if err != nil {
t.Fatal(err)
}
if img.Format() != PGM {
t.Fatalf("Expected PGM but received %s", img.Format())
}
}
// TestDecodePBMEncodePGM confirms that a PBM file can be re-encoded as PGM.
func TestDecodePBMEncodePGM(t *testing.T) {
var w bytes.Buffer
img := imageFromString(t, pbmRaw, PBM)
opts := &EncodeOptions{Format: PGM}
err := Encode(&w, img, opts)
if err != nil {
t.Fatal(err)
}
}
// TestDecodePPMEncodePGM confirms that a PPM file can be re-encoded as PGM.
func TestDecodePPMEncodePGM(t *testing.T) {
var w bytes.Buffer
img := imageFromString(t, ppmRaw, PPM)
opts := &EncodeOptions{Format: PGM}
err := Encode(&w, img, opts)
if err != nil {
t.Fatal(err)
}
}