flacgo/frame/frame_test.go
mewmew aadf80aa28 frame: Extend test cases to increase code coverage.
Test a corpus of 585 public domain FLAC files with a duration of less than 1 minute from freesound.org.

Out of these files, the following increased code coverage and where thus added to the test suit.

* 19875 (sample rate 48 kHz)
* 44127 (8 bits-per-sample, sample rate 22254)
* 80574 (sample rate 22050)
* 191885 (block size 1, verbatim)
* 212768 (sample rate 88200)
* 220014 (utf-8 continuation byte)
* 243749 (sample rate 8000)
* 257344 (sample rate 32000)
* 256529 (sample rate 192000)
2016-02-11 04:12:51 +01:00

61 lines
1.5 KiB
Go

package frame_test
import (
"bytes"
"crypto/md5"
"io"
"log"
"testing"
"gopkg.in/mewkiz/flac.v1"
)
var golden = []struct {
name string
}{
{name: "../testdata/love.flac"}, // i=0
{name: "../testdata/19875.flac"}, // i=1
{name: "../testdata/44127.flac"}, // i=2
{name: "../testdata/59996.flac"}, // i=3
{name: "../testdata/80574.flac"}, // i=4
{name: "../testdata/172960.flac"}, // i=5
{name: "../testdata/189983.flac"}, // i=6
{name: "../testdata/191885.flac"}, // i=7
{name: "../testdata/212768.flac"}, // i=8
{name: "../testdata/220014.flac"}, // i=9
{name: "../testdata/243749.flac"}, // i=10
{name: "../testdata/256529.flac"}, // i=11
{name: "../testdata/257344.flac"}, // i=12
}
func TestFrameHash(t *testing.T) {
for i, g := range golden {
log.Printf("i=%d: %v\n", i, g.name)
stream, err := flac.ParseFile(g.name)
if err != nil {
t.Fatal(err)
}
defer stream.Close()
md5sum := md5.New()
for frameNum := 0; ; frameNum++ {
frame, err := stream.ParseNext()
if err != nil {
if err == io.EOF {
break
}
t.Errorf("i=%d, frameNum=%d: error while parsing frame; %v", i, frameNum, err)
continue
}
frame.Hash(md5sum)
}
want := stream.Info.MD5sum[:]
got := md5sum.Sum(nil)
// Verify the decoded audio samples by comparing the MD5 checksum that is
// stored in StreamInfo with the computed one.
if !bytes.Equal(got, want) {
t.Errorf("i=%d: MD5 checksum mismatch for decoded audio samples; expected %32x, got %32x", i, want, got)
}
}
}