github.com/bluenviron/mediacommon@v1.9.3/pkg/codecs/av1/bitstream_test.go (about)

     1  package av1
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  var casesBitstream = []struct {
    10  	name string
    11  	enc  []byte
    12  	dec  [][]byte
    13  }{
    14  	{
    15  		"standard",
    16  		[]byte{
    17  			0x0a, 0x0e, 0x00, 0x00, 0x00, 0x4a, 0xab, 0xbf,
    18  			0xc3, 0x77, 0x6b, 0xe4, 0x40, 0x40, 0x40, 0x41,
    19  			0x0a, 0x0e, 0x00, 0x00, 0x00, 0x4a, 0xab, 0xbf,
    20  			0xc3, 0x77, 0x6b, 0xe4, 0x40, 0x40, 0x40, 0x41,
    21  		},
    22  		[][]byte{
    23  			{
    24  				0x08, 0x00, 0x00, 0x00, 0x4a, 0xab, 0xbf, 0xc3,
    25  				0x77, 0x6b, 0xe4, 0x40, 0x40, 0x40, 0x41,
    26  			},
    27  			{
    28  				0x08, 0x00, 0x00, 0x00, 0x4a, 0xab, 0xbf, 0xc3,
    29  				0x77, 0x6b, 0xe4, 0x40, 0x40, 0x40, 0x41,
    30  			},
    31  		},
    32  	},
    33  }
    34  
    35  func TestBitstreamUnmarshal(t *testing.T) {
    36  	for _, ca := range casesBitstream {
    37  		t.Run(ca.name, func(t *testing.T) {
    38  			dec, err := BitstreamUnmarshal(ca.enc, true)
    39  			require.NoError(t, err)
    40  			require.Equal(t, ca.dec, dec)
    41  		})
    42  	}
    43  }
    44  
    45  func TestBitstreamMarshal(t *testing.T) {
    46  	for _, ca := range casesBitstream {
    47  		t.Run(ca.name, func(t *testing.T) {
    48  			enc, err := BitstreamMarshal(ca.dec)
    49  			require.NoError(t, err)
    50  			require.Equal(t, ca.enc, enc)
    51  		})
    52  	}
    53  }
    54  
    55  func FuzzBitstreamUnmarshal(f *testing.F) {
    56  	f.Fuzz(func(_ *testing.T, b []byte) {
    57  		BitstreamUnmarshal(b, true) //nolint:errcheck
    58  	})
    59  }