Skip to content

Commit aadf80a

Browse files
committed
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)
1 parent 711a21c commit aadf80a

File tree

14 files changed

+69
-27
lines changed

14 files changed

+69
-27
lines changed

frame/frame.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (frame *Frame) Hash(md5sum hash.Hash) {
171171
buf[2] = uint8(sample >> 16)
172172
md5sum.Write(buf[:])
173173
default:
174-
log.Printf("frame.Frame.Hash: support for %d-bit sample size not yet implemented.\n", bps)
174+
log.Printf("frame.Frame.Hash: support for %d-bit sample size not yet implemented", bps)
175175
}
176176
}
177177
}
@@ -312,12 +312,16 @@ func (frame *Frame) parseHeader() error {
312312
case 0x2:
313313
// 010: 12 bits-per-sample.
314314
frame.BitsPerSample = 12
315+
// TODO(u): Remove log message when the test cases have been extended.
316+
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)
315317
case 0x4:
316318
// 100: 16 bits-per-sample.
317319
frame.BitsPerSample = 16
318320
case 0x5:
319321
// 101: 20 bits-per-sample.
320322
frame.BitsPerSample = 20
323+
// TODO(u): Remove log message when the test cases have been extended.
324+
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)
321325
case 0x6:
322326
// 110: 24 bits-per-sample.
323327
frame.BitsPerSample = 24
@@ -362,6 +366,8 @@ func (frame *Frame) parseHeader() error {
362366
case n == 0x1:
363367
// 0001: 192 samples.
364368
frame.BlockSize = 192
369+
// TODO(u): Remove log message when the test cases have been extended.
370+
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)
365371
case n >= 0x2 && n <= 0x5:
366372
// 0010-0101: 576 * 2^(n-2) samples.
367373
frame.BlockSize = 576 * (1 << (n - 2))
@@ -412,6 +418,8 @@ func (frame *Frame) parseHeader() error {
412418
case 0x2:
413419
// 0010: 176.4 kHz.
414420
frame.SampleRate = 176400
421+
// TODO(u): Remove log message when the test cases have been extended.
422+
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)
415423
case 0x3:
416424
// 0011: 192 kHz.
417425
frame.SampleRate = 192000
@@ -421,12 +429,16 @@ func (frame *Frame) parseHeader() error {
421429
case 0x5:
422430
// 0101: 16 kHz.
423431
frame.SampleRate = 16000
432+
// TODO(u): Remove log message when the test cases have been extended.
433+
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)
424434
case 0x6:
425435
// 0110: 22.05 kHz.
426436
frame.SampleRate = 22050
427437
case 0x7:
428438
// 0111: 24 kHz.
429439
frame.SampleRate = 24000
440+
// TODO(u): Remove log message when the test cases have been extended.
441+
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)
430442
case 0x8:
431443
// 1000: 32 kHz.
432444
frame.SampleRate = 32000
@@ -446,6 +458,8 @@ func (frame *Frame) parseHeader() error {
446458
return unexpected(err)
447459
}
448460
frame.SampleRate = uint32(x * 1000)
461+
// TODO(u): Remove log message when the test cases have been extended.
462+
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)
449463
case 0xD:
450464
// 1101: get 16 bit sample rate (in Hz) from the end of the header.
451465
x, err = br.Read(16)
@@ -460,6 +474,8 @@ func (frame *Frame) parseHeader() error {
460474
return unexpected(err)
461475
}
462476
frame.SampleRate = uint32(x * 10)
477+
// TODO(u): Remove log message when the test cases have been extended.
478+
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)
463479
default:
464480
// 1111: invalid.
465481
return errors.New("frame.Frame.parseHeader: invalid sample rate bit pattern (1111)")

frame/frame_test.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"crypto/md5"
66
"io"
7+
"log"
78
"testing"
89

910
"gopkg.in/mewkiz/flac.v1"
@@ -12,29 +13,24 @@ import (
1213
var golden = []struct {
1314
name string
1415
}{
15-
// i=0
16-
{
17-
name: "../testdata/59996.flac",
18-
},
19-
20-
// i=1
21-
{
22-
name: "../testdata/172960.flac",
23-
},
24-
25-
// i=2
26-
{
27-
name: "../testdata/189983.flac",
28-
},
29-
30-
// i=3
31-
{
32-
name: "../testdata/love.flac",
33-
},
16+
{name: "../testdata/love.flac"}, // i=0
17+
{name: "../testdata/19875.flac"}, // i=1
18+
{name: "../testdata/44127.flac"}, // i=2
19+
{name: "../testdata/59996.flac"}, // i=3
20+
{name: "../testdata/80574.flac"}, // i=4
21+
{name: "../testdata/172960.flac"}, // i=5
22+
{name: "../testdata/189983.flac"}, // i=6
23+
{name: "../testdata/191885.flac"}, // i=7
24+
{name: "../testdata/212768.flac"}, // i=8
25+
{name: "../testdata/220014.flac"}, // i=9
26+
{name: "../testdata/243749.flac"}, // i=10
27+
{name: "../testdata/256529.flac"}, // i=11
28+
{name: "../testdata/257344.flac"}, // i=12
3429
}
3530

3631
func TestFrameHash(t *testing.T) {
3732
for i, g := range golden {
33+
log.Printf("i=%d: %v\n", i, g.name)
3834
stream, err := flac.ParseFile(g.name)
3935
if err != nil {
4036
t.Fatal(err)

frame/subframe.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ func (subframe *Subframe) decodeRicePart(br *bits.Reader, paramSize uint) error
398398
nsamples = subframe.NSamples/nparts - subframe.Order
399399
}
400400

401+
// TODO(u): Verify that decoding of subframes with Rice parameter escape
402+
// codes have been implemented correctly.
401403
if paramSize == 4 && param == 0xF || paramSize == 5 && param == 0x1F {
402404
// 1111 or 11111: Escape code, meaning the partition is in unencoded
403405
// 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
413415
}
414416
subframe.Samples = append(subframe.Samples, int32(sample))
415417
}
416-
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.")
418+
// TODO(u): Remove log message when the test cases have been extended.
419+
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.")
417420
return nil
418421
}
419422

frame/utf8.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"io"
7+
"log"
78
)
89

910
const (
@@ -92,21 +93,29 @@ func decodeUTF8Int(r io.Reader) (n uint64, err error) {
9293
// total: 21 bits (3 + 6 + 6 + 6)
9394
l = 3
9495
n = uint64(c0 & mask4)
96+
// TODO(u): Remove log message when the test cases have been extended.
97+
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)
9598
case c0 < t6:
9699
// if c0 == 111110xx
97100
// total: 26 bits (2 + 6 + 6 + 6 + 6)
98101
l = 4
99102
n = uint64(c0 & mask5)
103+
// TODO(u): Remove log message when the test cases have been extended.
104+
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)
100105
case c0 < t7:
101106
// if c0 == 1111110x
102107
// total: 31 bits (1 + 6 + 6 + 6 + 6 + 6)
103108
l = 5
104109
n = uint64(c0 & mask6)
110+
// TODO(u): Remove log message when the test cases have been extended.
111+
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)
105112
case c0 < t8:
106113
// if c0 == 11111110
107114
// total: 36 bits (0 + 6 + 6 + 6 + 6 + 6 + 6)
108115
l = 6
109116
n = 0
117+
// TODO(u): Remove log message when the test cases have been extended.
118+
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)
110119
}
111120

112121
// store bits from continuation bytes.

testdata/191885.flac

166 KB
Binary file not shown.

testdata/19875.flac

61 KB
Binary file not shown.

testdata/212768.flac

338 KB
Binary file not shown.

testdata/220014.flac

257 KB
Binary file not shown.

testdata/243749.flac

1.15 KB
Binary file not shown.

testdata/256529.flac

3.97 MB
Binary file not shown.

0 commit comments

Comments
 (0)