Kirika/Kirika_test.go
2022-02-22 10:35:08 +01:00

63 lines
1.3 KiB
Go

package Kirika
import (
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format/flac"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format/mp3"
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format/opus"
"os"
"path"
"testing"
)
var TestSampleLocations = []string{
"resources/samples/cYsmix - Haunted House/",
"resources/samples/Babbe Music - RADIANT DANCEFLOOR/",
}
const BlockSize = 1024 * 64
func doTest(format format.Format, ext string, t *testing.T) {
for _, location := range TestSampleLocations {
entries, err := os.ReadDir(location)
if err != nil {
t.Error(err)
return
}
for _, f := range entries {
if path.Ext(f.Name()) == ext {
fullPath := path.Join(location, f.Name())
t.Run(f.Name(), func(t *testing.T) {
t.Parallel()
fp, err := os.Open(fullPath)
if err != nil {
t.Error(err)
return
}
defer fp.Close()
stream, err := format.Open(fp, BlockSize)
if err != nil {
t.Error(err)
return
}
//Decode
for range stream.GetAsBlockChannel() {
}
})
}
}
}
}
func TestFLACDecode(t *testing.T) {
doTest(flac.NewFormat(), ".flac", t)
}
func TestOpusDecode(t *testing.T) {
doTest(opus.NewFormat(), ".opus", t)
}
func TestMP3Decode(t *testing.T) {
doTest(mp3.NewFormat(), ".mp3", t)
}