Debian Codegraph @

goodbye_test.go

raw symbols SCIP
1 // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
2 // SPDX-License-Identifier: MIT
3
4 package rtcpscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/
5
6 import (
7 "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/"
8 "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/"
9
10 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/"
11 )
12
13 var _ Packetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet# = (*Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#)(nil) // assert is a Packet
14
15 func TestGoodbyeUnmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestGoodbyeUnmarshal().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
16 for _, test := range []struct {
17 Name string
18 Data []byte
19 Want Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#
20 WantError error
21 }{
22 {
23 Name: "valid",
24 Data: []byte{
25 // v=2, p=0, count=1, BYE, len=12
26 0x81, 0xcb, 0x00, 0x0c,
27 // ssrc=0x902f9e2e
28 0x90, 0x2f, 0x9e, 0x2e,
29 // len=3, text=FOO
30 0x03, 0x46, 0x4f, 0x4f,
31 },
32 Want: Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
33 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: []uint32{0x902f9e2e},
34 Reasonscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Reason.: "FOO",
35 },
36 },
37 {
38 Name: "invalid octet count",
39 Data: []byte{
40 // v=2, p=0, count=1, BYE, len=12
41 0x81, 0xcb, 0x00, 0x0c,
42 // ssrc=0x902f9e2e
43 0x90, 0x2f, 0x9e, 0x2e,
44 // len=4, text=FOO
45 0x04, 0x46, 0x4f, 0x4f,
46 },
47 WantError: errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.,
48 },
49 {
50 Name: "wrong type",
51 Data: []byte{
52 // v=2, p=0, count=1, SDES, len=12
53 0x81, 0xca, 0x00, 0x0c,
54 // ssrc=0x902f9e2e
55 0x90, 0x2f, 0x9e, 0x2e,
56 // len=3, text=FOO
57 0x03, 0x46, 0x4f, 0x4f,
58 },
59 WantError: errWrongTypescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errWrongType.,
60 },
61 {
62 Name: "short reason",
63 Data: []byte{
64 // v=2, p=0, count=1, BYE, len=12
65 0x81, 0xcb, 0x00, 0x0c,
66 // ssrc=0x902f9e2e
67 0x90, 0x2f, 0x9e, 0x2e,
68 // len=3, text=F + padding
69 0x01, 0x46, 0x00, 0x00,
70 },
71 Want: Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
72 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: []uint32{0x902f9e2e},
73 Reasonscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Reason.: "F",
74 },
75 },
76 {
77 Name: "not byte aligned",
78 Data: []byte{
79 // v=2, p=0, count=1, BYE, len=10
80 0x81, 0xcb, 0x00, 0x0a,
81 // ssrc=0x902f9e2e
82 0x90, 0x2f, 0x9e, 0x2e,
83 // len=1, text=F
84 0x01, 0x46,
85 },
86 WantError: errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.,
87 },
88 {
89 Name: "bad count in header",
90 Data: []byte{
91 // v=2, p=0, count=2, BYE, len=8
92 0x82, 0xcb, 0x00, 0x0c,
93 // ssrc=0x902f9e2e
94 0x90, 0x2f, 0x9e, 0x2e,
95 },
96 WantError: errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.,
97 },
98 {
99 Name: "empty packet",
100 Data: []byte{
101 // v=2, p=0, count=0, BYE, len=4
102 0x80, 0xcb, 0x00, 0x04,
103 },
104 Want: Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
105 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: []uint32{},
106 Reasonscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Reason.: "",
107 },
108 },
109 {
110 Name: "nil",
111 Data: nil,
112 WantError: errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort.,
113 },
114 } {
115 var bye Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#
116 err := bye.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Unmarshal().(test.Data)
117 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.ErrorIsfscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/ErrorIsf().(t, err, test.WantError, "Unmarshal %q bye mismatch", test.Name)
118 if err != nil {
119 continue
120 }
121
122 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalfscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equalf().(t, test.Want, bye, "Unmarshal %q bye mismatch", test.Name)
123 }
124 }
125
126 func TestGoodbyeRoundTripscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestGoodbyeRoundTrip().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
127 // a slice with enough sources to overflow an 5-bit int
128 var tooManySources []uint32
129 var tooLongText stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Builderscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#
130
131 for range 1 << 5 {
132 tooManySources = append(tooManySources, 0x00)
133 }
134 for range 1 << 8 {
135 tooLongText.WriteStringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#WriteString().("x")
136 }
137
138 for _, test := range []struct {
139 Name string
140 Bye Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#
141 WantError error
142 }{
143 {
144 Name: "empty",
145 Bye: Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
146 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: []uint32{},
147 },
148 },
149 {
150 Name: "valid",
151 Bye: Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
152 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: []uint32{
153 0x01020304,
154 0x05060708,
155 },
156 Reasonscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Reason.: "because",
157 },
158 },
159 {
160 Name: "empty reason",
161 Bye: Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
162 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: []uint32{0x01020304},
163 Reasonscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Reason.: "",
164 },
165 },
166 {
167 Name: "reason no source",
168 Bye: Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
169 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: []uint32{},
170 Reasonscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Reason.: "foo",
171 },
172 },
173 {
174 Name: "short reason",
175 Bye: Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
176 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: []uint32{},
177 Reasonscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Reason.: "f",
178 },
179 },
180 {
181 Name: "count overflow",
182 Bye: Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
183 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: tooManySources,
184 },
185 WantError: errTooManySourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errTooManySources.,
186 },
187 {
188 Name: "reason too long",
189 Bye: Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
190 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: []uint32{},
191 Reasonscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Reason.: tooLongText.Stringscip-go gomod github.com/golang/go/src go1.24.0 strings/Builder#String().(),
192 },
193 WantError: errReasonTooLongscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errReasonTooLong.,
194 },
195 } {
196 data, err := test.Bye.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Marshal().()
197 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.ErrorIsfscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/ErrorIsf().(t, err, test.WantError, "Marshal %q", test.Name)
198 if err != nil {
199 continue
200 }
201
202 var bye Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#
203 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.NoErrorfscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/NoErrorf().(t, bye.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Unmarshal().(data), "Unmarshal %q", test.Name)
204 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalfscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equalf().(t, test.Bye, bye, "%q bye round trip mismatch", test.Name)
205 }
206 }
207
208 func TestGoodbyeRoundTripMaxFieldSizesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestGoodbyeRoundTripMaxFieldSizes().(t *testingscip-go gomod github.com/golang/go/src go1.24.0 testing/.Tscip-go gomod github.com/golang/go/src go1.24.0 testing/T#) {
209 sources := make([]uint32, countMaxscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/countMax.)
210 for i := range sources {
211 sources[i] = uint32(i + 1)
212 }
213
214 bye := Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
215 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: sources,
216 Reasonscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Reason.: stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.24.0 strings/Repeat().("x", sdesMaxOctetCountscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/sdesMaxOctetCount.),
217 }
218
219 data, err := bye.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Marshal().()
220 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/NoError().(t, err)
221 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Len().(t, data, bye.MarshalSizescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#MarshalSize().())
222
223 var decoded Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#
224 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/NoError().(t, decoded.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Unmarshal().(data))
225 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, bye, decoded)
226 }