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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
package rtcp
import (
"errors"
"reflect"
"testing"
)
var _ Packet = (*PictureLossIndication)(nil) // assert is a Packet
func TestPictureLossIndicationUnmarshal(t *testing.T) {
for _, test := range []struct {
Name string
Data []byte
Want PictureLossIndication
WantError error
}{
{
Name: "valid",
Data: []byte{
// v=2, p=0, FMT=1, PSFB, len=1
0x81, 0xce, 0x00, 0x02,
// ssrc=0x0
0x00, 0x00, 0x00, 0x00,
// ssrc=0x4bc4fcb4
0x4b, 0xc4, 0xfc, 0xb4,
},
Want: PictureLossIndication{
SenderSSRC: 0x0,
MediaSSRC: 0x4bc4fcb4,
},
},
{
Name: "packet too short",
Data: []byte{
0x00, 0x00, 0x00, 0x00,
},
WantError: errPacketTooShort,
},
{
Name: "invalid header",
Data: []byte{
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
},
WantError: errBadVersion,
},
{
Name: "wrong type",
Data: []byte{
// v=2, p=0, FMT=1, RR, len=1
0x81, 0xc9, 0x00, 0x02,
// ssrc=0x0
0x00, 0x00, 0x00, 0x00,
// ssrc=0x4bc4fcb4
0x4b, 0xc4, 0xfc, 0xb4,
},
WantError: errWrongType,
},
{
Name: "wrong fmt",
Data: []byte{
// v=2, p=0, FMT=2, RR, len=1
0x82, 0xc9, 0x00, 0x02,
// ssrc=0x0
0x00, 0x00, 0x00, 0x00,
// ssrc=0x4bc4fcb4
0x4b, 0xc4, 0xfc, 0xb4,
},
WantError: errWrongType,
},
} {
var pli PictureLossIndication
err := pli.Unmarshal(test.Data)
if got, want := err, test.WantError; !errors.Is(got, want) {
t.Fatalf("Unmarshal %q rr: err = %v, want %v", test.Name, got, want)
}
if err != nil {
continue
}
if got, want := pli, test.Want; !reflect.DeepEqual(got, want) {
t.Fatalf("Unmarshal %q rr: got %v, want %v", test.Name, got, want)
}
}
}
func TestPictureLossIndicationRoundTrip(t *testing.T) {
for _, test := range []struct {
Name string
Packet PictureLossIndication
WantError error
}{
{
Name: "valid",
Packet: PictureLossIndication{
SenderSSRC: 1,
MediaSSRC: 2,
},
},
{
Name: "also valid",
Packet: PictureLossIndication{
SenderSSRC: 5000,
MediaSSRC: 6000,
},
},
} {
data, err := test.Packet.Marshal()
if got, want := err, test.WantError; !errors.Is(got, want) {
t.Fatalf("Marshal %q: err = %v, want %v", test.Name, got, want)
}
if err != nil {
continue
}
var decoded PictureLossIndication
if err := decoded.Unmarshal(data); err != nil {
t.Fatalf("Unmarshal %q: %v", test.Name, err)
}
if got, want := decoded, test.Packet; !reflect.DeepEqual(got, want) {
t.Fatalf("%q rr round trip: got %#v, want %#v", test.Name, got, want)
}
}
}
func TestPictureLossIndicationUnmarshalHeader(t *testing.T) {
for _, test := range []struct {
Name string
Data []byte
Want Header
WantError error
}{
{
Name: "valid header",
Data: []byte{
// v=2, p=0, FMT=1, PSFB, len=1
0x81, 0xce, 0x00, 0x02,
// ssrc=0x0
0x00, 0x00, 0x00, 0x00,
// ssrc=0x4bc4fcb4
0x4b, 0xc4, 0xfc, 0xb4,
},
Want: Header{
Count: FormatPLI,
Type: TypePayloadSpecificFeedback,
Length: pliLength,
},
},
} {
var pli PictureLossIndication
err := pli.Unmarshal(test.Data)
if got, want := err, test.WantError; !errors.Is(got, want) {
t.Fatalf("Unmarshal header %q rr: err = %v, want %v", test.Name, got, want)
}
if err != nil {
continue
}
if got, want := pli.Header(), test.Want; !reflect.DeepEqual(got, want) {
t.Fatalf("Unmarshal header %q rr: got %v, want %v", test.Name, got, want)
}
}
}
|