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)
This commit is contained in:
mewmew 2016-02-11 04:05:58 +01:00
parent 711a21c5d6
commit aadf80aa28
14 changed files with 69 additions and 27 deletions

View file

@ -171,7 +171,7 @@ func (frame *Frame) Hash(md5sum hash.Hash) {
buf[2] = uint8(sample >> 16) buf[2] = uint8(sample >> 16)
md5sum.Write(buf[:]) md5sum.Write(buf[:])
default: default:
log.Printf("frame.Frame.Hash: support for %d-bit sample size not yet implemented.\n", bps) log.Printf("frame.Frame.Hash: support for %d-bit sample size not yet implemented", bps)
} }
} }
} }
@ -312,12 +312,16 @@ func (frame *Frame) parseHeader() error {
case 0x2: case 0x2:
// 010: 12 bits-per-sample. // 010: 12 bits-per-sample.
frame.BitsPerSample = 12 frame.BitsPerSample = 12
// TODO(u): Remove log message when the test cases have been extended.
log.Printf("frame.Frame.parseHeader: The flac library test cases do not yet include any audio files with %d bits-per-sample. If possible please consider contributing this audio sample to improve the reliability of the test cases.", frame.BitsPerSample)
case 0x4: case 0x4:
// 100: 16 bits-per-sample. // 100: 16 bits-per-sample.
frame.BitsPerSample = 16 frame.BitsPerSample = 16
case 0x5: case 0x5:
// 101: 20 bits-per-sample. // 101: 20 bits-per-sample.
frame.BitsPerSample = 20 frame.BitsPerSample = 20
// TODO(u): Remove log message when the test cases have been extended.
log.Printf("frame.Frame.parseHeader: The flac library test cases do not yet include any audio files with %d bits-per-sample. If possible please consider contributing this audio sample to improve the reliability of the test cases.", frame.BitsPerSample)
case 0x6: case 0x6:
// 110: 24 bits-per-sample. // 110: 24 bits-per-sample.
frame.BitsPerSample = 24 frame.BitsPerSample = 24
@ -362,6 +366,8 @@ func (frame *Frame) parseHeader() error {
case n == 0x1: case n == 0x1:
// 0001: 192 samples. // 0001: 192 samples.
frame.BlockSize = 192 frame.BlockSize = 192
// TODO(u): Remove log message when the test cases have been extended.
log.Printf("frame.Frame.parseHeader: The flac library test cases do not yet include any audio files with block size %d. If possible please consider contributing this audio sample to improve the reliability of the test cases.", frame.BlockSize)
case n >= 0x2 && n <= 0x5: case n >= 0x2 && n <= 0x5:
// 0010-0101: 576 * 2^(n-2) samples. // 0010-0101: 576 * 2^(n-2) samples.
frame.BlockSize = 576 * (1 << (n - 2)) frame.BlockSize = 576 * (1 << (n - 2))
@ -412,6 +418,8 @@ func (frame *Frame) parseHeader() error {
case 0x2: case 0x2:
// 0010: 176.4 kHz. // 0010: 176.4 kHz.
frame.SampleRate = 176400 frame.SampleRate = 176400
// TODO(u): Remove log message when the test cases have been extended.
log.Printf("frame.Frame.parseHeader: The flac library test cases do not yet include any audio files with sample rate %d. If possible please consider contributing this audio sample to improve the reliability of the test cases.", frame.SampleRate)
case 0x3: case 0x3:
// 0011: 192 kHz. // 0011: 192 kHz.
frame.SampleRate = 192000 frame.SampleRate = 192000
@ -421,12 +429,16 @@ func (frame *Frame) parseHeader() error {
case 0x5: case 0x5:
// 0101: 16 kHz. // 0101: 16 kHz.
frame.SampleRate = 16000 frame.SampleRate = 16000
// TODO(u): Remove log message when the test cases have been extended.
log.Printf("frame.Frame.parseHeader: The flac library test cases do not yet include any audio files with sample rate %d. If possible please consider contributing this audio sample to improve the reliability of the test cases.", frame.SampleRate)
case 0x6: case 0x6:
// 0110: 22.05 kHz. // 0110: 22.05 kHz.
frame.SampleRate = 22050 frame.SampleRate = 22050
case 0x7: case 0x7:
// 0111: 24 kHz. // 0111: 24 kHz.
frame.SampleRate = 24000 frame.SampleRate = 24000
// TODO(u): Remove log message when the test cases have been extended.
log.Printf("frame.Frame.parseHeader: The flac library test cases do not yet include any audio files with sample rate %d. If possible please consider contributing this audio sample to improve the reliability of the test cases.", frame.SampleRate)
case 0x8: case 0x8:
// 1000: 32 kHz. // 1000: 32 kHz.
frame.SampleRate = 32000 frame.SampleRate = 32000
@ -446,6 +458,8 @@ func (frame *Frame) parseHeader() error {
return unexpected(err) return unexpected(err)
} }
frame.SampleRate = uint32(x * 1000) frame.SampleRate = uint32(x * 1000)
// TODO(u): Remove log message when the test cases have been extended.
log.Printf("frame.Frame.parseHeader: The flac library test cases do not yet include any audio files with sample rate %d. If possible please consider contributing this audio sample to improve the reliability of the test cases.", frame.SampleRate)
case 0xD: case 0xD:
// 1101: get 16 bit sample rate (in Hz) from the end of the header. // 1101: get 16 bit sample rate (in Hz) from the end of the header.
x, err = br.Read(16) x, err = br.Read(16)
@ -460,6 +474,8 @@ func (frame *Frame) parseHeader() error {
return unexpected(err) return unexpected(err)
} }
frame.SampleRate = uint32(x * 10) frame.SampleRate = uint32(x * 10)
// TODO(u): Remove log message when the test cases have been extended.
log.Printf("frame.Frame.parseHeader: The flac library test cases do not yet include any audio files with sample rate %d. If possible please consider contributing this audio sample to improve the reliability of the test cases.", frame.SampleRate)
default: default:
// 1111: invalid. // 1111: invalid.
return errors.New("frame.Frame.parseHeader: invalid sample rate bit pattern (1111)") return errors.New("frame.Frame.parseHeader: invalid sample rate bit pattern (1111)")

View file

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"crypto/md5" "crypto/md5"
"io" "io"
"log"
"testing" "testing"
"gopkg.in/mewkiz/flac.v1" "gopkg.in/mewkiz/flac.v1"
@ -12,29 +13,24 @@ import (
var golden = []struct { var golden = []struct {
name string name string
}{ }{
// i=0 {name: "../testdata/love.flac"}, // i=0
{ {name: "../testdata/19875.flac"}, // i=1
name: "../testdata/59996.flac", {name: "../testdata/44127.flac"}, // i=2
}, {name: "../testdata/59996.flac"}, // i=3
{name: "../testdata/80574.flac"}, // i=4
// i=1 {name: "../testdata/172960.flac"}, // i=5
{ {name: "../testdata/189983.flac"}, // i=6
name: "../testdata/172960.flac", {name: "../testdata/191885.flac"}, // i=7
}, {name: "../testdata/212768.flac"}, // i=8
{name: "../testdata/220014.flac"}, // i=9
// i=2 {name: "../testdata/243749.flac"}, // i=10
{ {name: "../testdata/256529.flac"}, // i=11
name: "../testdata/189983.flac", {name: "../testdata/257344.flac"}, // i=12
},
// i=3
{
name: "../testdata/love.flac",
},
} }
func TestFrameHash(t *testing.T) { func TestFrameHash(t *testing.T) {
for i, g := range golden { for i, g := range golden {
log.Printf("i=%d: %v\n", i, g.name)
stream, err := flac.ParseFile(g.name) stream, err := flac.ParseFile(g.name)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View file

@ -398,6 +398,8 @@ func (subframe *Subframe) decodeRicePart(br *bits.Reader, paramSize uint) error
nsamples = subframe.NSamples/nparts - subframe.Order nsamples = subframe.NSamples/nparts - subframe.Order
} }
// TODO(u): Verify that decoding of subframes with Rice parameter escape
// codes have been implemented correctly.
if paramSize == 4 && param == 0xF || paramSize == 5 && param == 0x1F { if paramSize == 4 && param == 0xF || paramSize == 5 && param == 0x1F {
// 1111 or 11111: Escape code, meaning the partition is in unencoded // 1111 or 11111: Escape code, meaning the partition is in unencoded
// binary form using n bits per sample; n follows as a 5-bit number. // binary form using n bits per sample; n follows as a 5-bit number.
@ -413,7 +415,8 @@ func (subframe *Subframe) decodeRicePart(br *bits.Reader, paramSize uint) error
} }
subframe.Samples = append(subframe.Samples, int32(sample)) subframe.Samples = append(subframe.Samples, int32(sample))
} }
log.Printf("frame.Subframe.decodeRicePart: not yet implemented; Rice parameter escape code. Please send this file to us, we would like to verify this part of the code.") // TODO(u): Remove log message when the test cases have been extended.
log.Print("frame.Subframe.decodeRicePart: The flac library test cases do not yet include any audio files with Rice parameter escape codes. If possible please consider contributing this audio sample to improve the reliability of the test cases.")
return nil return nil
} }

View file

@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"log"
) )
const ( const (
@ -92,21 +93,29 @@ func decodeUTF8Int(r io.Reader) (n uint64, err error) {
// total: 21 bits (3 + 6 + 6 + 6) // total: 21 bits (3 + 6 + 6 + 6)
l = 3 l = 3
n = uint64(c0 & mask4) n = uint64(c0 & mask4)
// TODO(u): Remove log message when the test cases have been extended.
log.Printf("frame.decodeUTF8Int: The flac library test cases do not yet include any audio files with %d UTF-8 continuation bytes. If possible please consider contributing this audio sample to improve the reliability of the test cases.", l)
case c0 < t6: case c0 < t6:
// if c0 == 111110xx // if c0 == 111110xx
// total: 26 bits (2 + 6 + 6 + 6 + 6) // total: 26 bits (2 + 6 + 6 + 6 + 6)
l = 4 l = 4
n = uint64(c0 & mask5) n = uint64(c0 & mask5)
// TODO(u): Remove log message when the test cases have been extended.
log.Printf("frame.decodeUTF8Int: The flac library test cases do not yet include any audio files with %d UTF-8 continuation bytes. If possible please consider contributing this audio sample to improve the reliability of the test cases.", l)
case c0 < t7: case c0 < t7:
// if c0 == 1111110x // if c0 == 1111110x
// total: 31 bits (1 + 6 + 6 + 6 + 6 + 6) // total: 31 bits (1 + 6 + 6 + 6 + 6 + 6)
l = 5 l = 5
n = uint64(c0 & mask6) n = uint64(c0 & mask6)
// TODO(u): Remove log message when the test cases have been extended.
log.Printf("frame.decodeUTF8Int: The flac library test cases do not yet include any audio files with %d UTF-8 continuation bytes. If possible please consider contributing this audio sample to improve the reliability of the test cases.", l)
case c0 < t8: case c0 < t8:
// if c0 == 11111110 // if c0 == 11111110
// total: 36 bits (0 + 6 + 6 + 6 + 6 + 6 + 6) // total: 36 bits (0 + 6 + 6 + 6 + 6 + 6 + 6)
l = 6 l = 6
n = 0 n = 0
// TODO(u): Remove log message when the test cases have been extended.
log.Printf("frame.decodeUTF8Int: The flac library test cases do not yet include any audio files with %d UTF-8 continuation bytes. If possible please consider contributing this audio sample to improve the reliability of the test cases.", l)
} }
// store bits from continuation bytes. // store bits from continuation bytes.

BIN
testdata/191885.flac vendored Normal file

Binary file not shown.

BIN
testdata/19875.flac vendored Normal file

Binary file not shown.

BIN
testdata/212768.flac vendored Normal file

Binary file not shown.

BIN
testdata/220014.flac vendored Normal file

Binary file not shown.

BIN
testdata/243749.flac vendored Normal file

Binary file not shown.

BIN
testdata/256529.flac vendored Normal file

Binary file not shown.

BIN
testdata/257344.flac vendored Normal file

Binary file not shown.

BIN
testdata/44127.flac vendored Normal file

Binary file not shown.

BIN
testdata/80574.flac vendored Normal file

Binary file not shown.

30
testdata/README.md vendored
View file

@ -6,10 +6,28 @@ The testcase sounds have all been released into the [public domain].
The source of each sound is listed below: The source of each sound is listed below:
* [59996.flac] * [19875]
* [172960.flac] * [44127]
* [189983.flac] * [59996]
* [80574]
* [172960]
* [189983]
* [191885]
* [212768]
* [220014]
* [243749]
* [256529]
* [257344]
[59996.flac]: http://www.freesound.org/people/qubodup/sounds/59996/ [19875]: http://freesound.org/people/yawfle/sounds/19875/
[172960.flac]: http://www.freesound.org/people/qubodup/sounds/172960/ [44127]: http://freesound.org/people/dland/sounds/44127/
[189983.flac]: http://www.freesound.org/people/raygrote/sounds/189983/ [59996]: http://freesound.org/people/qubodup/sounds/59996/
[80574]: http://freesound.org/people/EsbenSloth/sounds/80574/
[172960]: http://freesound.org/people/qubodup/sounds/172960/
[189983]: http://freesound.org/people/raygrote/sounds/189983/
[191885]: http://freesound.org/people/Hedmarking/sounds/191885/
[212768]: http://freesound.org/people/qubodup/sounds/212768/
[220014]: http://freesound.org/people/djani00/sounds/220014/
[243749]: http://freesound.org/people/unfa/sounds/243749/
[256529]: http://freesound.org/people/tymorafarr/sounds/256529/
[257344]: http://freesound.org/people/arseniiv/sounds/257344/