-
Notifications
You must be signed in to change notification settings - Fork 50
/
data_pat_test.go
68 lines (57 loc) · 1.58 KB
/
data_pat_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
package astits
import (
"bytes"
"testing"
"github.com/asticode/go-astikit"
"github.com/stretchr/testify/assert"
)
var pat = &PATData{
Programs: []*PATProgram{
{ProgramMapID: 3, ProgramNumber: 2},
{ProgramMapID: 5, ProgramNumber: 4},
},
TransportStreamID: 1,
}
func patBytes() []byte {
buf := &bytes.Buffer{}
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf})
w.Write(uint16(2)) // Program #1 number
w.Write("111") // Program #1 reserved bits
w.Write("0000000000011") // Program #1 map ID
w.Write(uint16(4)) // Program #2 number
w.Write("111") // Program #2 reserved bits
w.Write("0000000000101") // Program #3 map ID
return buf.Bytes()
}
func TestParsePATSection(t *testing.T) {
var b = patBytes()
d, err := parsePATSection(astikit.NewBytesIterator(b), len(b), uint16(1))
assert.Equal(t, d, pat)
assert.NoError(t, err)
}
func TestWritePATSection(t *testing.T) {
bw := &bytes.Buffer{}
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: bw})
n, err := writePATSection(w, pat)
assert.NoError(t, err)
assert.Equal(t, n, 8)
assert.Equal(t, n, bw.Len())
assert.Equal(t, patBytes(), bw.Bytes())
}
func BenchmarkParsePATSection(b *testing.B) {
b.ReportAllocs()
bs := patBytes()
for i := 0; i < b.N; i++ {
parsePATSection(astikit.NewBytesIterator(bs), len(bs), uint16(1))
}
}
func BenchmarkWritePATSection(b *testing.B) {
b.ReportAllocs()
bw := &bytes.Buffer{}
bw.Grow(1024)
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: bw})
for i := 0; i < b.N; i++ {
bw.Reset()
writePATSection(w, pat)
}
}