github.com/bluenviron/mediacommon@v1.9.3/pkg/codecs/h264/emulation_prevention_test.go (about)

     1  package h264
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestEmulationPreventionRemove(t *testing.T) {
    10  	for _, ca := range []struct {
    11  		name   string
    12  		unproc []byte
    13  		proc   []byte
    14  	}{
    15  		{
    16  			"base",
    17  			[]byte{
    18  				0x00, 0x00, 0x00,
    19  				0x00, 0x00, 0x01,
    20  				0x00, 0x00, 0x02,
    21  				0x00, 0x00, 0x03,
    22  			},
    23  			[]byte{
    24  				0x00, 0x00, 0x03, 0x00,
    25  				0x00, 0x00, 0x03, 0x01,
    26  				0x00, 0x00, 0x03, 0x02,
    27  				0x00, 0x00, 0x03, 0x03,
    28  			},
    29  		},
    30  		{
    31  			"double emulation byte",
    32  			[]byte{
    33  				0x00, 0x00, 0x00,
    34  				0x00, 0x00,
    35  			},
    36  			[]byte{
    37  				0x00, 0x00, 0x03,
    38  				0x00, 0x00, 0x03, 0x00,
    39  			},
    40  		},
    41  		{
    42  			"terminal emulation byte",
    43  			[]byte{
    44  				0x00, 0x00,
    45  			},
    46  			[]byte{
    47  				0x00, 0x00, 0x03,
    48  			},
    49  		},
    50  	} {
    51  		t.Run(ca.name, func(t *testing.T) {
    52  			unproc := EmulationPreventionRemove(ca.proc)
    53  			require.Equal(t, ca.unproc, unproc)
    54  		})
    55  	}
    56  }
    57  
    58  func FuzzEmulationPreventionRemove(f *testing.F) {
    59  	f.Fuzz(func(_ *testing.T, b []byte) {
    60  		EmulationPreventionRemove(b)
    61  	})
    62  }