|
|
|
@ -79,13 +79,49 @@ func TestLayer(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPaddingBytes(t *testing.T) {
|
|
|
|
|
bytes := []byte{0xff, 0xe0, 0x2, 0}
|
|
|
|
|
h := header(bytes)
|
|
|
|
|
assert.Equal(t, 1, h.PaddingBytes())
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
name string
|
|
|
|
|
bytes []byte
|
|
|
|
|
expPadding int
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
"MPEG1 Layer3 128kbps 44.1k, no padding",
|
|
|
|
|
[]byte{0xff, 0xfa, 0x90, 0},
|
|
|
|
|
0,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"MPEG1 Layer3 128kbps 44.1k, padding",
|
|
|
|
|
[]byte{0xff, 0xfa, 0x92, 0},
|
|
|
|
|
1,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"MPEG2 Layer1 144kbps 24k, no padding",
|
|
|
|
|
[]byte{0xff, 0xf6, 0x94, 0},
|
|
|
|
|
0,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"MPEG2 Layer1 144kbps 24k, padding",
|
|
|
|
|
[]byte{0xff, 0xf6, 0x96, 0},
|
|
|
|
|
4,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"MPEG25 Layer2 56kbps 8k, no padding",
|
|
|
|
|
[]byte{0xff, 0xe4, 0x78, 0},
|
|
|
|
|
0,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"MPEG25 Layer2 56kbps 8k, padding",
|
|
|
|
|
[]byte{0xff, 0xe4, 0x7a, 0},
|
|
|
|
|
1,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bytes = []byte{0xff, 0xe0, 0x0, 0}
|
|
|
|
|
h = header(bytes)
|
|
|
|
|
assert.Equal(t, 0, h.PaddingBytes())
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
|
h := header(tc.bytes)
|
|
|
|
|
assert.Equal(t, tc.expPadding, h.PaddingBytes())
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestIsProtected(t *testing.T) {
|
|
|
|
@ -385,3 +421,49 @@ func TestSampleRate(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestLen(t *testing.T) {
|
|
|
|
|
testCases := []struct {
|
|
|
|
|
name string
|
|
|
|
|
bytes []byte
|
|
|
|
|
expLen int
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
"MPEG1 Layer3 128kbps 44.1k, no padding",
|
|
|
|
|
[]byte{0xff, 0xfa, 0x90, 0},
|
|
|
|
|
417,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"MPEG1 Layer3 128kbps 44.1k, padding",
|
|
|
|
|
[]byte{0xff, 0xfa, 0x92, 0},
|
|
|
|
|
418,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"MPEG2 Layer1 144kbps 24k, no padding",
|
|
|
|
|
[]byte{0xff, 0xf6, 0x94, 0},
|
|
|
|
|
288,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"MPEG2 Layer1 144kbps 24k, padding",
|
|
|
|
|
[]byte{0xff, 0xf6, 0x96, 0},
|
|
|
|
|
292,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"MPEG25 Layer2 56kbps 8k, no padding",
|
|
|
|
|
[]byte{0xff, 0xe4, 0x78, 0},
|
|
|
|
|
1008,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"MPEG25 Layer2 56kbps 8k, padding",
|
|
|
|
|
[]byte{0xff, 0xe4, 0x7a, 0},
|
|
|
|
|
1009,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
|
h := header(tc.bytes)
|
|
|
|
|
assert.Equal(t, tc.expLen, h.Len())
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|