package main import ( "encoding/binary" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestAudioVersionId(t *testing.T) { bytes := []byte{0xff, 0xe8, 0, 0} h, err := newHeader(binary.BigEndian.Uint32(bytes)) require.NoError(t, err) assert.Equal(t, AudioVersionReserved, h.AudioVersionId()) bytes = []byte{0xff, 0xf0, 0, 0} h, err = newHeader(binary.BigEndian.Uint32(bytes)) require.NoError(t, err) assert.Equal(t, AudioVersionMPEG2, h.AudioVersionId()) bytes = []byte{0xff, 0xff, 0, 0} h, err = newHeader(binary.BigEndian.Uint32(bytes)) require.NoError(t, err) assert.Equal(t, AudioVersionMPEG1, h.AudioVersionId()) bytes = []byte{0xff, 0xe0, 0, 0} h, err = newHeader(binary.BigEndian.Uint32(bytes)) require.NoError(t, err) assert.Equal(t, AudioVersionMPEG25, h.AudioVersionId()) } // func TestLayerIndex(t *testing.T) { // bytes := []byte{0xff, 0xe2, 0, 0} // h, err := newHeader(binary.BigEndian.Uint32(bytes)) // require.NoError(t, err) // assert.Equal(t, LayerIndexIII, h.LayerIndex()) // bytes = []byte{0xff, 0xe4, 0, 0} // h, err = newHeader(binary.BigEndian.Uint32(bytes)) // require.NoError(t, err) // assert.Equal(t, LayerIndexII, h.LayerIndex()) // bytes = []byte{0xff, 0xe6, 0, 0} // h, err = newHeader(binary.BigEndian.Uint32(bytes)) // require.NoError(t, err) // assert.Equal(t, LayerIndexI, h.LayerIndex()) // } // func TestIsProtected(t *testing.T) { // bytes := []byte{0xff, 0xe1, 0, 0} // h, err := newHeader(binary.BigEndian.Uint32(bytes)) // require.NoError(t, err) // assert.True(t, h.IsProtected()) // bytes = []byte{0xff, 0xe0, 0, 0} // h, err = newHeader(binary.BigEndian.Uint32(bytes)) // require.NoError(t, err) // assert.False(t, h.IsProtected()) // } // func TestBitRate(t *testing.T) { // testCases := []struct { // name string // bytes []byte // expBitRate uint32 // }{ // { // "empty header", // []byte{0, 0, 0, 0}, // 0, // }, // { // "MPEG1 LayerI 32kbps", // []byte{0xff, 0xfe, 0x10, 0}, // 32, // }, // { // "MPEG1 LayerI 448kbps", // []byte{0xff, 0xfe, 0xe0, 0}, // 448, // }, // { // "MPEG1 LayerII 32kbps", // []byte{0xff, 0xfc, 0x10, 0}, // 32, // }, // { // "MPEG1 LayerII 448kbps", // []byte{0xff, 0xfc, 0xe0, 0}, // 384, // }, // { // "MPEG1 LayerIII 32kbps", // []byte{0xff, 0xfa, 0x10, 0}, // 32, // }, // { // "MPEG1 LayerIII 128kbps", // []byte{0xff, 0xfa, 0x90, 0}, // 128, // }, // { // "MPEG1 LayerIII 160kbps", // []byte{0xff, 0xfa, 0xa0, 0}, // 160, // }, // { // "MPEG1 LayerIII 192kbps", // []byte{0xff, 0xfb, 0xb0, 0}, // 192, // }, // { // "MPEG1 LayerIII 320kbps", // []byte{0xff, 0xfa, 0xe0, 0}, // 320, // }, // { // "MPEG1 LayerIII reserved", // []byte{0xff, 0xfa, 0xf0, 0}, // 0, // }, // { // "MPEG2 LayerI 32kbps", // []byte{0xff, 0xf6, 0x10, 0}, // 32, // }, // { // "MPEG2 LayerI 256", // []byte{0xff, 0xf6, 0xe0, 0}, // 256, // }, // { // "MPEG2 LayerII 32kbps", // []byte{0xff, 0xf4, 0x10, 0}, // 8, // }, // { // "MPEG2 LayerII 160kbps", // []byte{0xff, 0xf4, 0xe0, 0}, // 160, // }, // { // "MPEG2 LayerIII 32kbps", // []byte{0xff, 0xf2, 0x10, 0}, // 8, // }, // { // "MPEG2 LayerIII 160kbps", // []byte{0xff, 0xf2, 0xe0, 0}, // 160, // }, // { // "MPEG25 LayerI 32kbps", // []byte{0xff, 0xe6, 0x10, 0}, // 32, // }, // { // "MPEG25 LayerI 256", // []byte{0xff, 0xe6, 0xe0, 0}, // 256, // }, // { // "MPEG25 LayerII 32kbps", // []byte{0xff, 0xe4, 0x10, 0}, // 8, // }, // { // "MPEG25 LayerII 160kbps", // []byte{0xff, 0xe4, 0xe0, 0}, // 160, // }, // { // "MPEG25 LayerIII 32kbps", // []byte{0xff, 0xe2, 0x10, 0}, // 8, // }, // { // "MPEG25 LayerIII 160kbps", // []byte{0xff, 0xe2, 0xe0, 0}, // 160, // }, // { // "full header", // []byte{1, 1, 1, 1}, // 0, // }, // } // for _, tc := range testCases { // t.Run(tc.name, func(t *testing.T) { // h, err := newHeader(binary.BigEndian.Uint32(tc.bytes)) // require.NoError(t, err) // assert.Equal(t, tc.expBitRate, h.BitRate()) // }) // } // } // func TestSampleRate(t *testing.T) { // testCases := []struct { // name string // bytes []byte // expSampleRate uint32 // }{ // { // "MPEG1 44.1k", // []byte{0xff, 0xfa, 0x90, 0}, // 44100, // }, // { // "MPEG1 48k", // []byte{0xff, 0xfa, 0x94, 0}, // 48000, // }, // { // "MPEG1 32k", // []byte{0xff, 0xfa, 0x98, 0}, // 32000, // }, // { // "MPEG1 Reserved", // []byte{0xff, 0xfa, 0x9c, 0}, // 32000, // }, // } // for _, tc := range testCases { // t.Run(tc.name, func(t *testing.T) { // h, err := newHeader(binary.BigEndian.Uint32(tc.bytes)) // require.NoError(t, err) // assert.Equal(t, int(tc.expSampleRate), int(h.SampleRate())) // }) // } // }