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)
md5sum.Write(buf[:])
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:
// 010: 12 bits-per-sample.
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:
// 100: 16 bits-per-sample.
frame.BitsPerSample = 16
case 0x5:
// 101: 20 bits-per-sample.
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:
// 110: 24 bits-per-sample.
frame.BitsPerSample = 24
@ -362,6 +366,8 @@ func (frame *Frame) parseHeader() error {
case n == 0x1:
// 0001: 192 samples.
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:
// 0010-0101: 576 * 2^(n-2) samples.
frame.BlockSize = 576 * (1 << (n - 2))
@ -412,6 +418,8 @@ func (frame *Frame) parseHeader() error {
case 0x2:
// 0010: 176.4 kHz.
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:
// 0011: 192 kHz.
frame.SampleRate = 192000
@ -421,12 +429,16 @@ func (frame *Frame) parseHeader() error {
case 0x5:
// 0101: 16 kHz.
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:
// 0110: 22.05 kHz.
frame.SampleRate = 22050
case 0x7:
// 0111: 24 kHz.
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:
// 1000: 32 kHz.
frame.SampleRate = 32000
@ -446,6 +458,8 @@ func (frame *Frame) parseHeader() error {
return unexpected(err)
}
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:
// 1101: get 16 bit sample rate (in Hz) from the end of the header.
x, err = br.Read(16)
@ -460,6 +474,8 @@ func (frame *Frame) parseHeader() error {
return unexpected(err)
}
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:
// 1111: invalid.
return errors.New("frame.Frame.parseHeader: invalid sample rate bit pattern (1111)")

View file

@ -4,6 +4,7 @@ import (
"bytes"
"crypto/md5"
"io"
"log"
"testing"
"gopkg.in/mewkiz/flac.v1"
@ -12,29 +13,24 @@ import (
var golden = []struct {
name string
}{
// i=0
{
name: "../testdata/59996.flac",
},
// i=1
{
name: "../testdata/172960.flac",
},
// i=2
{
name: "../testdata/189983.flac",
},
// i=3
{
name: "../testdata/love.flac",
},
{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)

View file

@ -398,6 +398,8 @@ func (subframe *Subframe) decodeRicePart(br *bits.Reader, paramSize uint) error
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 {
// 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.
@ -413,7 +415,8 @@ func (subframe *Subframe) decodeRicePart(br *bits.Reader, paramSize uint) error
}
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
}

View file

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"log"
)
const (
@ -92,21 +93,29 @@ func decodeUTF8Int(r io.Reader) (n uint64, err error) {
// total: 21 bits (3 + 6 + 6 + 6)
l = 3
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:
// if c0 == 111110xx
// total: 26 bits (2 + 6 + 6 + 6 + 6)
l = 4
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:
// if c0 == 1111110x
// total: 31 bits (1 + 6 + 6 + 6 + 6 + 6)
l = 5
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:
// if c0 == 11111110
// total: 36 bits (0 + 6 + 6 + 6 + 6 + 6 + 6)
l = 6
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.

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:
* [59996.flac]
* [172960.flac]
* [189983.flac]
* [19875]
* [44127]
* [59996]
* [80574]
* [172960]
* [189983]
* [191885]
* [212768]
* [220014]
* [243749]
* [256529]
* [257344]
[59996.flac]: http://www.freesound.org/people/qubodup/sounds/59996/
[172960.flac]: http://www.freesound.org/people/qubodup/sounds/172960/
[189983.flac]: http://www.freesound.org/people/raygrote/sounds/189983/
[19875]: http://freesound.org/people/yawfle/sounds/19875/
[44127]: http://freesound.org/people/dland/sounds/44127/
[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/