-
Notifications
You must be signed in to change notification settings - Fork 51
/
dvb_test.go
70 lines (60 loc) · 2.07 KB
/
dvb_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
package astits
import (
"bytes"
"testing"
"time"
"github.com/asticode/go-astikit"
"github.com/stretchr/testify/assert"
)
var (
dvbDurationMinutes = time.Hour + 45*time.Minute
dvbDurationMinutesBytes = []byte{0x1, 0x45} // 0145
dvbDurationSeconds = time.Hour + 45*time.Minute + 30*time.Second
dvbDurationSecondsBytes = []byte{0x1, 0x45, 0x30} // 014530
dvbTime, _ = time.Parse("2006-01-02 15:04:05", "1993-10-13 12:45:00")
dvbTimeBytes = []byte{0xc0, 0x79, 0x12, 0x45, 0x0} // C079124500
)
func TestParseDVBTime(t *testing.T) {
d, err := parseDVBTime(astikit.NewBytesIterator(dvbTimeBytes))
assert.Equal(t, dvbTime, d)
assert.NoError(t, err)
}
func TestParseDVBDurationMinutes(t *testing.T) {
d, err := parseDVBDurationMinutes(astikit.NewBytesIterator(dvbDurationMinutesBytes))
assert.Equal(t, dvbDurationMinutes, d)
assert.NoError(t, err)
}
func TestParseDVBDurationSeconds(t *testing.T) {
d, err := parseDVBDurationSeconds(astikit.NewBytesIterator(dvbDurationSecondsBytes))
assert.Equal(t, dvbDurationSeconds, d)
assert.NoError(t, err)
}
func TestWriteDVBTime(t *testing.T) {
buf := &bytes.Buffer{}
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf})
n, err := writeDVBTime(w, dvbTime)
assert.NoError(t, err)
assert.Equal(t, n, buf.Len())
assert.Equal(t, dvbTimeBytes, buf.Bytes())
}
func TestWriteDVBDurationMinutes(t *testing.T) {
buf := &bytes.Buffer{}
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf})
n, err := writeDVBDurationMinutes(w, dvbDurationMinutes)
assert.NoError(t, err)
assert.Equal(t, n, buf.Len())
assert.Equal(t, dvbDurationMinutesBytes, buf.Bytes())
}
func TestWriteDVBDurationSeconds(t *testing.T) {
buf := &bytes.Buffer{}
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: buf})
n, err := writeDVBDurationSeconds(w, dvbDurationSeconds)
assert.NoError(t, err)
assert.Equal(t, n, buf.Len())
assert.Equal(t, dvbDurationSecondsBytes, buf.Bytes())
}
func BenchmarkDVBTime(b *testing.B) {
for i := 0; i < b.N; i++ {
parseDVBTime(astikit.NewBytesIterator(dvbTimeBytes))
}
}