-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchunk_decoder_test.go
74 lines (52 loc) · 1.45 KB
/
chunk_decoder_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
package pngstructure
import (
"path"
"testing"
"github.com/dsoprea/go-logging"
)
func TestChunkDecoder_decodeIHDR(t *testing.T) {
assetsPath := getTestAssetsPath()
filepath := path.Join(assetsPath, "Selection_058.png")
pmp := NewPngMediaParser()
intfc, err := pmp.ParseFile(filepath)
log.PanicIf(err)
cs := intfc.(*ChunkSlice)
index := cs.Index()
ihdrRawSlice, found := index["IHDR"]
if found != true {
t.Fatalf("Could not find IHDR chunk.")
}
cd := NewChunkDecoder()
ihdrRaw, err := cd.Decode(ihdrRawSlice[0])
log.PanicIf(err)
ihdr := ihdrRaw.(*ChunkIHDR)
expected := &ChunkIHDR{
Width: 1472,
Height: 598,
BitDepth: 8,
ColorType: 2,
CompressionMethod: 0,
FilterMethod: 0,
InterlaceMethod: 0,
}
if *ihdr != *expected {
t.Fatalf("ihdr not correct")
}
}
func ExampleChunkDecoder_Decode() {
filepath := path.Join(assetsPath, "Selection_058.png")
pmp := NewPngMediaParser()
intfc, err := pmp.ParseFile(filepath)
log.PanicIf(err)
cs := intfc.(*ChunkSlice)
index := cs.Index()
ihdrRawSlice, found := index["IHDR"]
if found != true {
log.Panicf("IHDR chunk not found")
}
cd := NewChunkDecoder()
ihdrRaw, err := cd.Decode(ihdrRawSlice[0])
log.PanicIf(err)
ihdr := ihdrRaw.(*ChunkIHDR)
ihdr = ihdr
}