49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
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.LittleEndian.Uint32(bytes))
|
|
require.NoError(t, err)
|
|
assert.Equal(t, AudioVersionReserved, h.AudioVersionId())
|
|
|
|
bytes = []byte{0xff, 0xf0, 0, 0}
|
|
h, err = newHeader(binary.LittleEndian.Uint32(bytes))
|
|
require.NoError(t, err)
|
|
assert.Equal(t, AudioVersionMPEG2, h.AudioVersionId())
|
|
|
|
bytes = []byte{0xff, 0xff, 0, 0}
|
|
h, err = newHeader(binary.LittleEndian.Uint32(bytes))
|
|
require.NoError(t, err)
|
|
assert.Equal(t, AudioVersionMPEG1, h.AudioVersionId())
|
|
|
|
bytes = []byte{0xff, 0xe0, 0, 0}
|
|
h, err = newHeader(binary.LittleEndian.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.LittleEndian.Uint32(bytes))
|
|
require.NoError(t, err)
|
|
assert.Equal(t, LayerIndexIII, h.LayerIndex())
|
|
|
|
bytes = []byte{0xff, 0xe4, 0, 0}
|
|
h, err = newHeader(binary.LittleEndian.Uint32(bytes))
|
|
require.NoError(t, err)
|
|
assert.Equal(t, LayerIndexII, h.LayerIndex())
|
|
|
|
bytes = []byte{0xff, 0xe6, 0, 0}
|
|
h, err = newHeader(binary.LittleEndian.Uint32(bytes))
|
|
require.NoError(t, err)
|
|
assert.Equal(t, LayerIndexI, h.LayerIndex())
|
|
}
|