Skip to content

Commit

Permalink
frame: Add test cases. Currently 1/3 is failing the MD5 checksum test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mewmew committed Jan 30, 2015
1 parent 6e68e06 commit 4368146
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions frame/frame_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package frame_test

import (
"bytes"
"crypto/md5"
"io"
"testing"

"gopkg.in/mewkiz/flac.v1"
)

var golden = []struct {
name string
}{
// i=0
{
name: "../testdata/59996.flac",
},

// i=1
{
name: "../testdata/172960.flac",
},

// i=2
{
name: "../testdata/189983.flac",
},
}

func TestFrameHash(t *testing.T) {
for i, g := range golden {
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)
}
}
}

0 comments on commit 4368146

Please sign in to comment.