Debian Codegraph @

compound_packet_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 "testingscip-go gomod github.com/golang/go/src go1.24.0 testing/"
8
9 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/"
10 )
11
12 var _ Packetscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Packet# = (*CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#)(nil) // assert is a Packet
13
14 func TestReadEOFscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestReadEOF().(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#) {
15 shortHeader := []byte{
16 0x81, 0xc9, // missing type & len
17 }
18
19 _, err := Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Unmarshal().(shortHeader)
20 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Errorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Error().(t, err)
21 }
22
23 func TestBadCompoundscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestBadCompound().(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#) {
24 // trailing data!
25 badcompound := realPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/realPacket().()[:34]
26 packets, err := Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Unmarshal().(badcompound)
27 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Errorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Error().(t, err)
28
29 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Nil().(t, packets)
30
31 badcompound = realPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/realPacket().()[84:104]
32
33 packets, err = Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Unmarshal().(badcompound)
34 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)
35
36 compound := CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#(packets)
37
38 // this should return an error,
39 // it violates the "must start with RR or SR" rule
40 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/ErrorIs().(t, compound.Validatescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#Validate().(), errBadFirstPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errBadFirstPacket.)
41 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, 2, len(compound))
42
43 _, ok := compound[0].(*Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#)
44 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Truescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/True().(t, ok)
45
46 _, ok = compound[1].(*PictureLossIndicationscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/PictureLossIndication#)
47 assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Truescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/True().(t, ok)
48 }
49
50 func TestValidPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestValidPacket().(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#) {
51 cname := NewCNAMESourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/NewCNAMESourceDescription().(1234, "cname")
52
53 for _, test := range []struct {
54 Name string
55 Packet CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#
56 Err error
57 }{
58 {
59 Name: "empty",
60 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{},
61 Err: errEmptyCompoundscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errEmptyCompound.,
62 },
63 {
64 Name: "no cname",
65 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
66 &SenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SenderReport#{},
67 },
68 Err: errMissingCNAMEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errMissingCNAME.,
69 },
70 {
71 Name: "just BYE",
72 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
73 &Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{},
74 },
75 Err: errBadFirstPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errBadFirstPacket.,
76 },
77 {
78 Name: "SDES / no cname",
79 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
80 &SenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SenderReport#{},
81 &SourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#{},
82 },
83 Err: errMissingCNAMEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errMissingCNAME.,
84 },
85 {
86 Name: "just SR",
87 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
88 &SenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SenderReport#{},
89 cname,
90 },
91 Err: nil,
92 },
93 {
94 Name: "multiple SRs",
95 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
96 &SenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SenderReport#{},
97 &SenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SenderReport#{},
98 cname,
99 },
100 Err: errPacketBeforeCNAMEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketBeforeCNAME.,
101 },
102 {
103 Name: "just RR",
104 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
105 &ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{},
106 cname,
107 },
108 Err: nil,
109 },
110 {
111 Name: "multiple RRs",
112 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
113 &ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{},
114 &ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{},
115 cname,
116 },
117 Err: nil,
118 },
119 {
120 Name: "goodbye",
121 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
122 &ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{},
123 cname,
124 &Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{},
125 },
126 Err: nil,
127 },
128 } {
129 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, test.Packet.Validatescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#Validate().(), test.Err, "Validate(%s)", test.Name)
130 }
131 }
132
133 func TestCNAMEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestCNAME().(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#) {
134 cname := NewCNAMESourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/NewCNAMESourceDescription().(1234, "cname")
135
136 for _, test := range []struct {
137 Name string
138 Packet CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#
139 Err error
140 Text string
141 }{
142 {
143 Name: "no cname",
144 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
145 &SenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SenderReport#{},
146 },
147 Err: errMissingCNAMEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errMissingCNAME.,
148 },
149 {
150 Name: "SDES / no cname",
151 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
152 &SenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SenderReport#{},
153 &SourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SourceDescription#{},
154 },
155 Err: errMissingCNAMEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errMissingCNAME.,
156 },
157 {
158 Name: "just SR",
159 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
160 &SenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SenderReport#{},
161 cname,
162 },
163 Err: nil,
164 Text: "cname",
165 },
166 {
167 Name: "multiple SRs",
168 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
169 &SenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SenderReport#{},
170 &SenderReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/SenderReport#{},
171 cname,
172 },
173 Err: errPacketBeforeCNAMEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketBeforeCNAME.,
174 Text: "cname",
175 },
176 {
177 Name: "just RR",
178 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
179 &ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{},
180 cname,
181 },
182 Err: nil,
183 Text: "cname",
184 },
185 {
186 Name: "multiple RRs",
187 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
188 &ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{},
189 &ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{},
190 cname,
191 },
192 Err: nil,
193 Text: "cname",
194 },
195 {
196 Name: "goodbye",
197 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
198 &ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{},
199 cname,
200 &Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{},
201 },
202 Err: nil,
203 Text: "cname",
204 },
205 } {
206 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, test.Packet.Validatescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#Validate().(), test.Err, "Validate(%s)", test.Name)
207
208 name, err := test.Packet.CNAMEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#CNAME().()
209 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.Err, "CNAME(%s)", test.Name)
210 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.Text, name, "CNAME(%s)", test.Name)
211 }
212 }
213
214 func TestCompoundPacketRoundTripscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestCompoundPacketRoundTrip().(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#) {
215 cname := NewCNAMESourceDescriptionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/NewCNAMESourceDescription().(1234, "cname")
216
217 for _, test := range []struct {
218 Name string
219 Packet CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#
220 Err error
221 }{
222 {
223 Name: "bye",
224 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
225 &ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{},
226 cname,
227 &Goodbyescip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#{
228 Sourcesscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/Goodbye#Sources.: []uint32{1234},
229 },
230 },
231 },
232 {
233 Name: "no cname",
234 Packet: CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#{
235 &ReceiverReportscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/ReceiverReport#{},
236 },
237 Err: errMissingCNAMEscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errMissingCNAME.,
238 },
239 } {
240 data, err := test.Packet.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#Marshal().()
241 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.Err, "Marshal(%v)", test.Name)
242 if err != nil {
243 continue
244 }
245
246 var c CompoundPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#
247 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, c.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#Unmarshal().(data), "Unmarshal(%v)", test.Name)
248
249 data2, err := c.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/CompoundPacket#Marshal().()
250 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, err, "Marshal(%v)", test.Name)
251 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, data, data2, "Marshal(%v) mismatch", test.Name)
252 }
253 }