Kirika/hasher/hasher_test.go
DataHoarder bd069cdf05
Some checks failed
continuous-integration/drone/push Build is failing
General code inspection cleanup
2022-10-03 11:34:56 +02:00

104 lines
3 KiB
Go

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 TestHasher24(t *testing.T) {
fp, err := os.Open(test.SingleSample24)
if err != nil {
t.Error(err)
return
}
defer fp.Close()
source, analyzerChannel, err := guess.GetAnalyzerDecoder("flac").OpenAnalyzer(fp)
if err != nil {
t.Error(err)
return
}
chans := analyzerChannel.Split(2)
crc32 := NewHasher(chans[0], HashtypeCrc32)
sha256 := NewHasher(chans[1], HashtypeSha256)
//Decode
audio.NewNullSink().Process(source)
crc32.Wait()
sha256.Wait()
expectCrc32, _ := hex.DecodeString("A54636CD")
if bytes.Compare(crc32.GetResult(), expectCrc32) != 0 {
t.Errorf("Wrong CRC32 %08X != %08X", crc32.GetResult(), expectCrc32)
}
expectSha256, _ := hex.DecodeString("9B6715ED75B6C8074B749C630AC9C626994080DEACBEA363976391366DA4E4FA")
if bytes.Compare(sha256.GetResult(), expectSha256) != 0 {
t.Errorf("Wrong SHA256 %08X != %08X", sha256.GetResult(), expectSha256)
}
}
func TestHasher16(t *testing.T) {
fp, err := os.Open(test.SingleSample16)
if err != nil {
t.Error(err)
return
}
defer fp.Close()
source, analyzerChannel, err := guess.GetAnalyzerDecoder("flac").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)
}
}