-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathplayoutdelayextension_test.go
More file actions
107 lines (78 loc) · 2.21 KB
/
playoutdelayextension_test.go
File metadata and controls
107 lines (78 loc) · 2.21 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package rtp
import (
"io"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPlayoutDelayExtensionTooSmall(t *testing.T) {
t1 := PlayoutDelayExtension{}
var rawData []byte
err := t1.Unmarshal(rawData)
assert.ErrorIs(t, err, errTooSmall)
}
func TestPlayoutDelayExtensionTooLarge(t *testing.T) {
t1 := PlayoutDelayExtension{MinDelay: 1 << 12, MaxDelay: 1 << 12}
_, err := t1.Marshal()
assert.ErrorIs(t, err, errPlayoutDelayInvalidValue)
_, err = t1.MarshalTo(make([]byte, 10))
assert.ErrorIs(t, err, errPlayoutDelayInvalidValue)
}
func TestPlayoutDelayExtension(t *testing.T) {
t1 := PlayoutDelayExtension{}
rawData := []byte{
0x01, 0x01, 0x00,
}
err := t1.Unmarshal(rawData)
assert.NoError(t, err)
t2 := PlayoutDelayExtension{
MinDelay: 1 << 4, MaxDelay: 1 << 8,
}
assert.Equal(t, t1, t2)
dstData, _ := t2.Marshal()
assert.Equal(t, dstData, rawData)
}
func TestPlayoutDelayExtensionExtraBytes(t *testing.T) {
t1 := PlayoutDelayExtension{}
rawData := []byte{
0x01, 0x01, 0x00, 0xff, 0xff,
}
err := t1.Unmarshal(rawData)
assert.NoError(t, err)
t2 := PlayoutDelayExtension{
MinDelay: 1 << 4, MaxDelay: 1 << 8,
}
assert.Equal(t, t1, t2)
}
func TestPlayoutDelayExtensionMarshalTo(t *testing.T) {
ext := PlayoutDelayExtension{MinDelay: 100, MaxDelay: 200}
buf := make([]byte, ext.MarshalSize())
n, err := ext.MarshalTo(buf)
assert.NoError(t, err)
assert.Equal(t, ext.MarshalSize(), n)
expected, _ := ext.Marshal()
assert.Equal(t, expected, buf)
_, err = ext.MarshalTo(nil)
assert.ErrorIs(t, err, io.ErrShortBuffer)
}
//nolint:gochecknoglobals
var (
playoutDelaySink []byte
playoutDelayBuf = make([]byte, playoutDelayExtensionSize)
playoutDelaySinkInt int
)
func BenchmarkPlayoutDelayExtension_Marshal(b *testing.B) {
ext := PlayoutDelayExtension{MinDelay: 100, MaxDelay: 200}
b.ReportAllocs()
for b.Loop() {
playoutDelaySink, _ = ext.Marshal()
}
}
func BenchmarkPlayoutDelayExtension_MarshalTo(b *testing.B) {
ext := PlayoutDelayExtension{MinDelay: 100, MaxDelay: 200}
b.ReportAllocs()
for b.Loop() {
playoutDelaySinkInt, _ = ext.MarshalTo(playoutDelayBuf)
}
}