44 lines
1.5 KiB
Go
44 lines
1.5 KiB
Go
package moode
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"periph.io/x/conn/v3/physic"
|
|
|
|
"go.maze.io/harmon/player"
|
|
)
|
|
|
|
func TestParseAudioFormat(t *testing.T) {
|
|
testCases := []struct {
|
|
Test string
|
|
Want player.AudioFormat
|
|
}{
|
|
{"PCM 16/44.1 kHz, 2ch", player.AudioFormat{Encoding: "PCM", Bits: 16, SampleRate: 44100 * physic.Hertz, Channels: 2}},
|
|
{"FLAC 24/48.0 kHz, 2ch", player.AudioFormat{Encoding: "FLAC", Bits: 24, SampleRate: 48 * physic.KiloHertz, Channels: 2}},
|
|
{"MP3 16/44.1 kHz, 2ch", player.AudioFormat{Encoding: "MP3", Bits: 16, SampleRate: 44100 * physic.Hertz, Channels: 2}},
|
|
{"AAC 24/96.0 kHz, 2ch", player.AudioFormat{Encoding: "AAC", Bits: 24, SampleRate: 96 * physic.KiloHertz, Channels: 2}},
|
|
{"WAV 16/44.1 kHz, 1ch", player.AudioFormat{Encoding: "WAV", Bits: 16, SampleRate: 44100 * physic.Hertz, Channels: 1}},
|
|
}
|
|
for _, test := range testCases {
|
|
t.Run(test.Test, func(it *testing.T) {
|
|
f, err := parseAudioFormat(test.Test)
|
|
if err != nil {
|
|
it.Fatal(err)
|
|
}
|
|
if f.Encoding != test.Want.Encoding {
|
|
it.Errorf("expected encoding %q, got %q", test.Want.Encoding, f.Encoding)
|
|
}
|
|
if f.Bits != test.Want.Bits {
|
|
it.Errorf("expected bits %d, got %d", test.Want.Bits, f.Bits)
|
|
}
|
|
if f.SampleRate != test.Want.SampleRate {
|
|
it.Errorf("expected sample rate %d, got %d", test.Want.SampleRate, f.SampleRate)
|
|
}
|
|
if f.Channels != test.Want.Channels {
|
|
it.Errorf("expected channels %d, got %d", test.Want.Channels, f.Channels)
|
|
}
|
|
it.Log(f)
|
|
})
|
|
}
|
|
}
|