File: audiolevelextension_test.go

package info (click to toggle)
golang-github-pion-rtp 1.7.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-backports, forky, sid, trixie
  • size: 472 kB
  • sloc: makefile: 2
file content (80 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download
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
package rtp

import (
	"bytes"
	"errors"
	"testing"
)

func TestAudioLevelExtensionTooSmall(t *testing.T) {
	a := AudioLevelExtension{}

	rawData := []byte{}

	if err := a.Unmarshal(rawData); !errors.Is(err, errTooSmall) {
		t.Fatal("err != errTooSmall")
	}
}

func TestAudioLevelExtensionVoiceTrue(t *testing.T) {
	a1 := AudioLevelExtension{}

	rawData := []byte{
		0x88,
	}

	if err := a1.Unmarshal(rawData); err != nil {
		t.Fatal("Unmarshal error on extension data")
	}

	a2 := AudioLevelExtension{
		Level: 8,
		Voice: true,
	}

	if a1 != a2 {
		t.Error("Unmarshal failed")
	}

	dstData, _ := a2.Marshal()
	if !bytes.Equal(dstData, rawData) {
		t.Error("Marshal failed")
	}
}

func TestAudioLevelExtensionVoiceFalse(t *testing.T) {
	a1 := AudioLevelExtension{}

	rawData := []byte{
		0x8,
	}

	if err := a1.Unmarshal(rawData); err != nil {
		t.Fatal("Unmarshal error on extension data")
	}

	a2 := AudioLevelExtension{
		Level: 8,
		Voice: false,
	}

	if a1 != a2 {
		t.Error("Unmarshal failed")
	}

	dstData, _ := a2.Marshal()
	if !bytes.Equal(dstData, rawData) {
		t.Error("Marshal failed")
	}
}

func TestAudioLevelExtensionLevelOverflow(t *testing.T) {
	a := AudioLevelExtension{
		Level: 128,
		Voice: false,
	}

	if _, err := a.Marshal(); !errors.Is(err, errAudioLevelOverflow) {
		t.Fatal("err != errAudioLevelOverflow")
	}
}