Files
questshock/modding/hacked/ss1/content/audio/wav/Load_test.go
T

66 lines
1.8 KiB
Go

package wav_test
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/inkyblackness/hacked/ss1/content/audio/wav"
)
func TestLoadReturnsErrorOnNil(t *testing.T) {
_, err := wav.Load(nil)
assert.NotNil(t, err)
}
func TestLoadExtractsDataOfL8(t *testing.T) {
input := []byte{
0x52, 0x49, 0x46, 0x46, // "RIFF"
0x29, 0x00, 0x00, 0x00, // len(RIFF)
0x57, 0x41, 0x56, 0x45, // "WAVE"
0x66, 0x6d, 0x74, 0x20, // "fmt "
0x10, 0x00, 0x00, 0x00, // len(fmt)
0x01, 0x00, // fmt:type
0x01, 0x00, // fmt:channels
0x22, 0x56, 0x00, 0x00, // fmt:samples/sec
0x22, 0x56, 0x00, 0x00, // fmt:avgBytes/sec
0x01, 0x00, // fmt:blockAlign
0x08, 0x00, // fmt:bits/sample
0x64, 0x61, 0x74, 0x61, // "data"
0x05, 0x00, 0x00, 0x00, // len(data)
0x00, 0x40, 0x80, 0xC0, 0xFF} // data
data, err := wav.Load(bytes.NewReader(input))
require.Nil(t, err)
assert.Equal(t, float32(22050), data.SampleRate)
assert.Equal(t, []byte{0x00, 0x40, 0x80, 0xC0, 0xFF}, data.Samples)
}
func TestLoadExtractsDataOfL16(t *testing.T) {
input := []byte{
0x52, 0x49, 0x46, 0x46, // "RIFF"
0x2E, 0x00, 0x00, 0x00, // len(RIFF)
0x57, 0x41, 0x56, 0x45, // "WAVE"
0x66, 0x6d, 0x74, 0x20, // "fmt "
0x10, 0x00, 0x00, 0x00, // len(fmt)
0x01, 0x00, // fmt:type
0x01, 0x00, // fmt:channels
0x22, 0x56, 0x00, 0x00, // fmt:samples/sec
0x44, 0xAC, 0x00, 0x00, // fmt:avgBytes/sec
0x02, 0x00, // fmt:blockAlign
0x10, 0x00, // fmt:bits/sample
0x64, 0x61, 0x74, 0x61, // "data"
0x0A, 0x00, 0x00, 0x00, // len(data)
0xAA, 0x00, 0xAA, 0x40, 0xAA, 0x7F, 0xAA, 0xC0, 0xAA, 0xFF} // data
data, err := wav.Load(bytes.NewReader(input))
require.Nil(t, err)
assert.Equal(t, float32(22050), data.SampleRate)
assert.Equal(t, []byte{0x80, 0xC0, 0xFF, 0x40, 0x7F}, data.Samples)
}