improve coverage

This commit is contained in:
aler9
2021-05-22 17:18:09 +02:00
parent cd378ad0bf
commit 53e8f32bd0
11 changed files with 77 additions and 25 deletions

View File

@@ -246,7 +246,7 @@ func TestRequestWriteErrors(t *testing.T) {
},
{
"body",
62,
80,
},
} {
t.Run(ca.name, func(t *testing.T) {

View File

@@ -203,7 +203,7 @@ func TestResponseWriteErrors(t *testing.T) {
},
{
"body",
30,
49,
},
} {
t.Run(ca.name, func(t *testing.T) {

View File

@@ -110,9 +110,6 @@ func (h *Authenticate) Read(v base.HeaderValue) error {
case "algorithm":
h.Algorithm = &v
default:
// ignore non-standard keys
}
}

View File

@@ -213,6 +213,11 @@ func TestAutenticatehReadError(t *testing.T) {
base.HeaderValue{"Basic"},
"unable to split between method and keys (Basic)",
},
{
"invalid keys",
base.HeaderValue{`Basic key1="k`},
"apexes not closed (key1=\"k)",
},
{
"invalid method",
base.HeaderValue{"Testing key1=val1"},

View File

@@ -79,9 +79,7 @@ func (h Authorization) Write() base.HeaderValue {
return base.HeaderValue{"Basic " + response}
case AuthDigest:
default: // AuthDigest
return h.DigestValues.Write()
}
return nil
}

View File

@@ -102,8 +102,8 @@ func TestAuthorizationReadError(t *testing.T) {
},
{
"digest invalid",
base.HeaderValue{`Basic`},
"invalid authorization header",
base.HeaderValue{`Digest test="v`},
"apexes not closed (test=\"v)",
},
} {
t.Run(ca.name, func(t *testing.T) {

View File

@@ -170,6 +170,11 @@ func TestTransportReadError(t *testing.T) {
base.HeaderValue{"a", "b"},
"value provided multiple times ([a b])",
},
{
"invalid keys",
base.HeaderValue{`key1="k`},
"apexes not closed (key1=\"k)",
},
{
"protocol not found",
base.HeaderValue{`invalid;unicast;client_port=14186-14187`},

View File

@@ -33,7 +33,7 @@ func (r *RingBuffer) Close() {
r.event.signal()
}
// Reset restores Pull().
// Reset restores Pull() after a Close().
func (r *RingBuffer) Reset() {
for i := uint64(0); i < r.bufferSize; i++ {
atomic.SwapPointer(&r.buffer[i], nil)

View File

@@ -58,6 +58,13 @@ func TestClose(t *testing.T) {
r.Close()
<-done
r.Reset()
r.Push([]byte{0x05, 0x06, 0x07, 0x08})
_, ok := r.Pull()
require.Equal(t, true, ok)
}
func BenchmarkPushPullContinuous(b *testing.B) {

View File

@@ -84,11 +84,11 @@ func (c *MPEG4AudioConfig) Decode(byts []byte) error {
c.SampleRate = sampleRates[sampleRateIndex]
case sampleRateIndex == 15:
sampleRateIndex, err := r.ReadBits(24)
tmp, err := r.ReadBits(24)
if err != nil {
return err
}
c.SampleRate = int(sampleRateIndex)
c.SampleRate = int(tmp)
default:
return fmt.Errorf("invalid sample rate index (%d)", sampleRateIndex)

View File

@@ -12,36 +12,36 @@ var configCases = []struct {
dec MPEG4AudioConfig
}{
{
name: "aac-lc 44.1khz mono",
enc: []byte{0x12, 0x08, 0x56, 0xe5, 0x00},
dec: MPEG4AudioConfig{
"aac-lc 44.1khz mono",
[]byte{0x12, 0x08, 0x56, 0xe5, 0x00},
MPEG4AudioConfig{
Type: MPEG4AudioTypeAACLC,
SampleRate: 44100,
ChannelCount: 1,
},
},
{
name: "aac-lc 48khz stereo",
enc: []byte{17, 144},
dec: MPEG4AudioConfig{
"aac-lc 48khz stereo",
[]byte{17, 144},
MPEG4AudioConfig{
Type: MPEG4AudioTypeAACLC,
SampleRate: 48000,
ChannelCount: 2,
},
},
{
name: "aac-lc 96khz stereo",
enc: []byte{0x10, 0x10, 0x56, 0xE5, 0x00},
dec: MPEG4AudioConfig{
"aac-lc 96khz stereo",
[]byte{0x10, 0x10, 0x56, 0xE5, 0x00},
MPEG4AudioConfig{
Type: MPEG4AudioTypeAACLC,
SampleRate: 96000,
ChannelCount: 2,
},
},
{
name: "aac-lc 44.1khz 5.1",
enc: []byte{0x12, 0x30},
dec: MPEG4AudioConfig{
"aac-lc 44.1khz 5.1",
[]byte{0x12, 0x30},
MPEG4AudioConfig{
Type: MPEG4AudioTypeAACLC,
SampleRate: 44100,
ChannelCount: 6,
@@ -59,3 +59,43 @@ func TestConfigDecode(t *testing.T) {
})
}
}
func TestConfigDecodeErrors(t *testing.T) {
for _, ca := range []struct {
name string
byts []byte
err string
}{
{
"empty",
[]byte{},
"EOF",
},
{
"extended type missing",
[]byte{31 << 3},
"EOF",
},
{
"extended type invalid",
[]byte{31 << 3, 20},
"unsupported type: 32",
},
{
"sample rate missing",
[]byte{0x12},
"EOF",
},
{
"sample rate invalid",
[]byte{0x12 | 13>>5, 13 << 3},
"invalid channel configuration: 13",
},
} {
t.Run(ca.name, func(t *testing.T) {
var dec MPEG4AudioConfig
err := dec.Decode(ca.byts)
require.Equal(t, ca.err, err.Error())
})
}
}