-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathaudiolevelextension_test.go
More file actions
104 lines (82 loc) · 2.09 KB
/
audiolevelextension_test.go
File metadata and controls
104 lines (82 loc) · 2.09 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
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package rtp
import (
"io"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAudioLevelExtensionTooSmall(t *testing.T) {
a := AudioLevelExtension{}
rawData := []byte{}
assert.ErrorIs(t, a.Unmarshal(rawData), errTooSmall)
}
func TestAudioLevelExtensionVoiceTrue(t *testing.T) {
a1 := AudioLevelExtension{}
rawData := []byte{
0x88,
}
assert.NoError(t, a1.Unmarshal(rawData))
a2 := AudioLevelExtension{
Level: 8,
Voice: true,
}
assert.Equal(t, a2, a1)
dstData, _ := a2.Marshal()
assert.Equal(t, rawData, dstData)
}
func TestAudioLevelExtensionVoiceFalse(t *testing.T) {
a1 := AudioLevelExtension{}
rawData := []byte{
0x8,
}
assert.NoError(t, a1.Unmarshal(rawData))
a2 := AudioLevelExtension{
Level: 8,
Voice: false,
}
assert.Equal(t, a2, a1)
dstData, _ := a2.Marshal()
assert.Equal(t, rawData, dstData)
}
func TestAudioLevelExtensionLevelOverflow(t *testing.T) {
a := AudioLevelExtension{
Level: 128,
Voice: false,
}
_, err := a.Marshal()
assert.ErrorIs(t, err, errAudioLevelOverflow)
_, err = a.MarshalTo(make([]byte, 10))
assert.ErrorIs(t, err, errAudioLevelOverflow)
}
func TestAudioLevelExtensionMarshalTo(t *testing.T) {
a := AudioLevelExtension{Level: 8, Voice: true}
buf := make([]byte, a.MarshalSize())
n, err := a.MarshalTo(buf)
assert.NoError(t, err)
assert.Equal(t, a.MarshalSize(), n)
expected, _ := a.Marshal()
assert.Equal(t, expected, buf)
_, err = a.MarshalTo(nil)
assert.ErrorIs(t, err, io.ErrShortBuffer)
}
//nolint:gochecknoglobals
var (
audioLevelSink []byte
audioLevelBuf = make([]byte, audioLevelExtensionSize)
audioLevelSinkInt int
)
func BenchmarkAudioLevelExtension_Marshal(b *testing.B) {
ext := AudioLevelExtension{Level: 8, Voice: true}
b.ReportAllocs()
for b.Loop() {
audioLevelSink, _ = ext.Marshal()
}
}
func BenchmarkAudioLevelExtension_MarshalTo(b *testing.B) {
ext := AudioLevelExtension{Level: 8, Voice: true}
b.ReportAllocs()
for b.Loop() {
audioLevelSinkInt, _ = ext.MarshalTo(audioLevelBuf)
}
}