github.com/bluenviron/mediacommon@v1.9.3/pkg/formats/mpegts/opus_access_unit_test.go (about) 1 package mpegts 2 3 import ( 4 "bytes" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 var opusAccessUnitCases = []struct { 11 name string 12 dec opusAccessUnit 13 enc []byte 14 }{ 15 { 16 "a", 17 opusAccessUnit{ 18 ControlHeader: opusControlHeader{ 19 PayloadSize: 123, 20 StartTrimFlag: true, 21 ControlExtensionFlag: true, 22 StartTrim: 20, 23 ControlExtensionLength: 40, 24 }, 25 Packet: bytes.Repeat([]byte{1}, 123), 26 }, 27 []byte{ 28 0x7f, 0xf4, 0x7b, 0x00, 0x14, 0x28, 0x00, 0x00, 29 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 30 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 31 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 33 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 34 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 35 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 36 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 37 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 38 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 39 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 40 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 41 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 42 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 43 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 44 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 45 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 46 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 47 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 48 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 49 0x01, 50 }, 51 }, 52 } 53 54 func TestOpusAccessUnitMarshal(t *testing.T) { 55 for _, ca := range opusAccessUnitCases { 56 t.Run(ca.name, func(t *testing.T) { 57 s := ca.dec.marshalSize() 58 buf := make([]byte, s) 59 n, err := ca.dec.marshalTo(buf) 60 require.NoError(t, err) 61 require.Equal(t, s, n) 62 require.Equal(t, ca.enc, buf) 63 }) 64 } 65 } 66 67 func TestOpusAccessUnitUnmarshal(t *testing.T) { 68 for _, ca := range opusAccessUnitCases { 69 t.Run(ca.name, func(t *testing.T) { 70 var h opusAccessUnit 71 _, err := h.unmarshal(ca.enc) 72 require.NoError(t, err) 73 require.Equal(t, ca.dec, h) 74 }) 75 } 76 } 77 78 func FuzzOpusAccessUnitUnmarshal(f *testing.F) { 79 f.Fuzz(func(_ *testing.T, b []byte) { 80 var h opusAccessUnit 81 h.unmarshal(b) //nolint:errcheck 82 }) 83 }