(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestBasic(t *testing.T) { |
| 13 | p := &Packet{} |
| 14 | |
| 15 | if err := p.Unmarshal([]byte{}); err == nil { |
| 16 | t.Fatal("Unmarshal did not error on zero length packet") |
| 17 | } |
| 18 | |
| 19 | rawPkt := []byte{ |
| 20 | 0x90, 0xe0, 0x69, 0x8f, 0xd9, 0xc2, 0x93, 0xda, 0x1c, 0x64, |
| 21 | 0x27, 0x82, 0x00, 0x01, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x98, 0x36, 0xbe, 0x88, 0x9e, |
| 22 | } |
| 23 | parsedPacket := &Packet{ |
| 24 | Header: Header{ |
| 25 | Marker: true, |
| 26 | Extension: true, |
| 27 | ExtensionProfile: 1, |
| 28 | Extensions: []Extension{ |
| 29 | {0, []byte{ |
| 30 | 0xFF, 0xFF, 0xFF, 0xFF, |
| 31 | }}, |
| 32 | }, |
| 33 | Version: 2, |
| 34 | PayloadType: 96, |
| 35 | SequenceNumber: 27023, |
| 36 | Timestamp: 3653407706, |
| 37 | SSRC: 476325762, |
| 38 | CSRC: []uint32{}, |
| 39 | }, |
| 40 | Payload: rawPkt[20:], |
| 41 | } |
| 42 | |
| 43 | // Unmarshal to the used Packet should work as well. |
| 44 | for i := 0; i < 2; i++ { |
| 45 | t.Run(fmt.Sprintf("Run%d", i+1), func(t *testing.T) { |
| 46 | if err := p.Unmarshal(rawPkt); err != nil { |
| 47 | t.Error(err) |
| 48 | } else if !reflect.DeepEqual(p, parsedPacket) { |
| 49 | t.Errorf("TestBasic unmarshal: got %#v, want %#v", p, parsedPacket) |
| 50 | } |
| 51 | |
| 52 | if parsedPacket.Header.MarshalSize() != 20 { |
| 53 | t.Errorf("wrong computed header marshal size") |
| 54 | } else if parsedPacket.MarshalSize() != len(rawPkt) { |
| 55 | t.Errorf("wrong computed marshal size") |
| 56 | } |
| 57 | |
| 58 | raw, err := p.Marshal() |
| 59 | if err != nil { |
| 60 | t.Error(err) |
| 61 | } else if !reflect.DeepEqual(raw, rawPkt) { |
| 62 | t.Errorf("TestBasic marshal: got %#v, want %#v", raw, rawPkt) |
| 63 | } |
| 64 | }) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func TestExtension(t *testing.T) { |
| 69 | p := &Packet{} |
nothing calls this directly
no test coverage detected
searching dependent graphs…