mirror of
https://github.com/bluenviron/mediacommon.git
synced 2025-09-26 21:01:14 +08:00
70 lines
1.0 KiB
Go
70 lines
1.0 KiB
Go
//go:build go1.18
|
|
// +build go1.18
|
|
|
|
package h264
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var casesAVCC = []struct {
|
|
name string
|
|
enc []byte
|
|
dec [][]byte
|
|
}{
|
|
{
|
|
"single",
|
|
[]byte{
|
|
0x00, 0x00, 0x00, 0x03,
|
|
0xaa, 0xbb, 0xcc,
|
|
},
|
|
[][]byte{
|
|
{0xaa, 0xbb, 0xcc},
|
|
},
|
|
},
|
|
{
|
|
"multiple",
|
|
[]byte{
|
|
0x00, 0x00, 0x00, 0x02,
|
|
0xaa, 0xbb,
|
|
0x00, 0x00, 0x00, 0x02,
|
|
0xcc, 0xdd,
|
|
0x00, 0x00, 0x00, 0x02,
|
|
0xee, 0xff,
|
|
},
|
|
[][]byte{
|
|
{0xaa, 0xbb},
|
|
{0xcc, 0xdd},
|
|
{0xee, 0xff},
|
|
},
|
|
},
|
|
}
|
|
|
|
func TestAVCCUnmarshal(t *testing.T) {
|
|
for _, ca := range casesAVCC {
|
|
t.Run(ca.name, func(t *testing.T) {
|
|
dec, err := AVCCUnmarshal(ca.enc)
|
|
require.NoError(t, err)
|
|
require.Equal(t, ca.dec, dec)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAVCCMarshal(t *testing.T) {
|
|
for _, ca := range casesAVCC {
|
|
t.Run(ca.name, func(t *testing.T) {
|
|
enc, err := AVCCMarshal(ca.dec)
|
|
require.NoError(t, err)
|
|
require.Equal(t, ca.enc, enc)
|
|
})
|
|
}
|
|
}
|
|
|
|
func FuzzAVCCUnmarshal(f *testing.F) {
|
|
f.Fuzz(func(t *testing.T, b []byte) {
|
|
AVCCUnmarshal(b)
|
|
})
|
|
}
|