71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
//go:build !disable_format_tta && !disable_codec_tta
|
|
|
|
package hasher
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"git.gammaspectra.live/S.O.N.G/Kirika/audio"
|
|
"git.gammaspectra.live/S.O.N.G/Kirika/audio/format/guess"
|
|
"git.gammaspectra.live/S.O.N.G/Kirika/test"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestHasher16TTA(t *testing.T) {
|
|
|
|
fp, err := os.Open(test.SingleSample16TTA)
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
defer fp.Close()
|
|
source, analyzerChannel, err := guess.GetAnalyzerDecoder("tta").OpenAnalyzer(fp)
|
|
if err != nil {
|
|
t.Error(err)
|
|
return
|
|
}
|
|
|
|
channels := analyzerChannel.Split(4)
|
|
cueToolsCrc32 := NewHasher(channels[0].SkipStartSamples(Int16SamplesPerSector*10), HashtypeCrc32)
|
|
arChannels := channels[1].SkipStartSamples(Int16SamplesPerSector*5 - 1).Split(2)
|
|
accurateRipV1 := NewHasher(arChannels[0], HashtypeAccurateRipV1Start)
|
|
accurateRipV2 := NewHasher(arChannels[1], HashtypeAccurateRipV2Start)
|
|
crc32 := NewHasher(channels[2], HashtypeCrc32)
|
|
sha256Result := NewHasher(channels[3], HashtypeSha256)
|
|
|
|
//Decode
|
|
audio.NewNullSink().Process(source)
|
|
cueToolsCrc32.Wait()
|
|
accurateRipV1.Wait()
|
|
accurateRipV2.Wait()
|
|
crc32.Wait()
|
|
sha256Result.Wait()
|
|
|
|
expectCueToolsCrc32, _ := hex.DecodeString("18701E02")
|
|
if bytes.Compare(cueToolsCrc32.GetResult(), expectCueToolsCrc32) != 0 {
|
|
t.Errorf("Wrong CTDB CRC32 %08X != %08X", cueToolsCrc32.GetResult(), expectCueToolsCrc32)
|
|
}
|
|
|
|
expectAccurateRipV1, _ := hex.DecodeString("5593DA89")
|
|
if bytes.Compare(accurateRipV1.GetResult(), expectAccurateRipV1) != 0 {
|
|
t.Errorf("Wrong AccurateRip V1 %08X != %08X", accurateRipV1.GetResult(), expectAccurateRipV1)
|
|
}
|
|
|
|
expectAccurateRipV2, _ := hex.DecodeString("DAA40E75")
|
|
if bytes.Compare(accurateRipV2.GetResult(), expectAccurateRipV2) != 0 {
|
|
t.Errorf("Wrong AccurateRip V2 %08X != %08X", accurateRipV2.GetResult(), expectAccurateRipV2)
|
|
}
|
|
|
|
expectCrc32, _ := hex.DecodeString("50CE5057")
|
|
if bytes.Compare(crc32.GetResult(), expectCrc32) != 0 {
|
|
t.Errorf("Wrong CRC32 %08X != %08X", crc32.GetResult(), expectCrc32)
|
|
}
|
|
|
|
expectSha256, _ := hex.DecodeString("FEDF080D500D1A49DF8366BE619918D2A5D00413B7C7613A39DC00659FA25AC6")
|
|
if bytes.Compare(sha256Result.GetResult(), expectSha256) != 0 {
|
|
t.Errorf("Wrong SHA256 %X != %X", sha256Result.GetResult(), expectSha256)
|
|
}
|
|
|
|
}
|