| 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# = (*RawPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RawPacket#)(nil) // assert is a Packet |
| 13 | |
| 14 | func TestRawPacketRoundTripscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/TestRawPacketRoundTrip().(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 | for _, test := range []struct { |
| 16 | Name string |
| 17 | Packet RawPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RawPacket# |
| 18 | WantMarshalError error |
| 19 | WantUnmarshalError error |
| 20 | }{ |
| 21 | { |
| 22 | Name: "valid", |
| 23 | Packet: RawPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RawPacket#([]byte{ |
| 24 | // v=2, p=0, count=1, BYE, len=12 |
| 25 | 0x81, 0xcb, 0x00, 0x0c, |
| 26 | // ssrc=0x902f9e2e |
| 27 | 0x90, 0x2f, 0x9e, 0x2e, |
| 28 | // len=3, text=FOO |
| 29 | 0x03, 0x46, 0x4f, 0x4f, |
| 30 | }), |
| 31 | }, |
| 32 | { |
| 33 | Name: "short header", |
| 34 | Packet: RawPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RawPacket#([]byte{0x00}), |
| 35 | WantUnmarshalError: errPacketTooShortscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errPacketTooShort., |
| 36 | }, |
| 37 | { |
| 38 | Name: "invalid header", |
| 39 | Packet: RawPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RawPacket#([]byte{ |
| 40 | // v=0, p=0, count=0, RR, len=4 |
| 41 | 0x00, 0xc9, 0x00, 0x04, |
| 42 | }), |
| 43 | WantUnmarshalError: errBadVersionscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/errBadVersion., |
| 44 | }, |
| 45 | } { |
| 46 | data, err := test.Packet.Marshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RawPacket#Marshal().() |
| 47 | 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.WantMarshalError, "Marshal %q", test.Name) |
| 48 | if err != nil { |
| 49 | continue |
| 50 | } |
| 51 | |
| 52 | var decoded RawPacketscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RawPacket# |
| 53 | |
| 54 | err = decoded.Unmarshalscip-go gomod github.com/pion/rtcp . `github.com/pion/rtcp`/RawPacket#Unmarshal().(data) |
| 55 | 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.WantUnmarshalError, "Unmarshal %q", test.Name) |
| 56 | if err != nil { |
| 57 | continue |
| 58 | } |
| 59 | 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.Packet, decoded, "Unmarshal %q", test.Name) |
| 60 | } |
| 61 | } |