mirror of
https://github.com/aler9/gortsplib
synced 2025-10-04 14:52:46 +08:00
improve coverage
This commit is contained in:
@@ -246,7 +246,7 @@ func TestRequestWriteErrors(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"body",
|
"body",
|
||||||
62,
|
80,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
|
@@ -203,7 +203,7 @@ func TestResponseWriteErrors(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"body",
|
"body",
|
||||||
30,
|
49,
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
|
@@ -110,9 +110,6 @@ func (h *Authenticate) Read(v base.HeaderValue) error {
|
|||||||
|
|
||||||
case "algorithm":
|
case "algorithm":
|
||||||
h.Algorithm = &v
|
h.Algorithm = &v
|
||||||
|
|
||||||
default:
|
|
||||||
// ignore non-standard keys
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -213,6 +213,11 @@ func TestAutenticatehReadError(t *testing.T) {
|
|||||||
base.HeaderValue{"Basic"},
|
base.HeaderValue{"Basic"},
|
||||||
"unable to split between method and keys (Basic)",
|
"unable to split between method and keys (Basic)",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"invalid keys",
|
||||||
|
base.HeaderValue{`Basic key1="k`},
|
||||||
|
"apexes not closed (key1=\"k)",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"invalid method",
|
"invalid method",
|
||||||
base.HeaderValue{"Testing key1=val1"},
|
base.HeaderValue{"Testing key1=val1"},
|
||||||
|
@@ -79,9 +79,7 @@ func (h Authorization) Write() base.HeaderValue {
|
|||||||
|
|
||||||
return base.HeaderValue{"Basic " + response}
|
return base.HeaderValue{"Basic " + response}
|
||||||
|
|
||||||
case AuthDigest:
|
default: // AuthDigest
|
||||||
return h.DigestValues.Write()
|
return h.DigestValues.Write()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@@ -102,8 +102,8 @@ func TestAuthorizationReadError(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"digest invalid",
|
"digest invalid",
|
||||||
base.HeaderValue{`Basic`},
|
base.HeaderValue{`Digest test="v`},
|
||||||
"invalid authorization header",
|
"apexes not closed (test=\"v)",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
|
@@ -170,6 +170,11 @@ func TestTransportReadError(t *testing.T) {
|
|||||||
base.HeaderValue{"a", "b"},
|
base.HeaderValue{"a", "b"},
|
||||||
"value provided multiple times ([a b])",
|
"value provided multiple times ([a b])",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"invalid keys",
|
||||||
|
base.HeaderValue{`key1="k`},
|
||||||
|
"apexes not closed (key1=\"k)",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"protocol not found",
|
"protocol not found",
|
||||||
base.HeaderValue{`invalid;unicast;client_port=14186-14187`},
|
base.HeaderValue{`invalid;unicast;client_port=14186-14187`},
|
||||||
|
@@ -33,7 +33,7 @@ func (r *RingBuffer) Close() {
|
|||||||
r.event.signal()
|
r.event.signal()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset restores Pull().
|
// Reset restores Pull() after a Close().
|
||||||
func (r *RingBuffer) Reset() {
|
func (r *RingBuffer) Reset() {
|
||||||
for i := uint64(0); i < r.bufferSize; i++ {
|
for i := uint64(0); i < r.bufferSize; i++ {
|
||||||
atomic.SwapPointer(&r.buffer[i], nil)
|
atomic.SwapPointer(&r.buffer[i], nil)
|
||||||
|
@@ -58,6 +58,13 @@ func TestClose(t *testing.T) {
|
|||||||
|
|
||||||
r.Close()
|
r.Close()
|
||||||
<-done
|
<-done
|
||||||
|
|
||||||
|
r.Reset()
|
||||||
|
|
||||||
|
r.Push([]byte{0x05, 0x06, 0x07, 0x08})
|
||||||
|
|
||||||
|
_, ok := r.Pull()
|
||||||
|
require.Equal(t, true, ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkPushPullContinuous(b *testing.B) {
|
func BenchmarkPushPullContinuous(b *testing.B) {
|
||||||
|
@@ -84,11 +84,11 @@ func (c *MPEG4AudioConfig) Decode(byts []byte) error {
|
|||||||
c.SampleRate = sampleRates[sampleRateIndex]
|
c.SampleRate = sampleRates[sampleRateIndex]
|
||||||
|
|
||||||
case sampleRateIndex == 15:
|
case sampleRateIndex == 15:
|
||||||
sampleRateIndex, err := r.ReadBits(24)
|
tmp, err := r.ReadBits(24)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.SampleRate = int(sampleRateIndex)
|
c.SampleRate = int(tmp)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("invalid sample rate index (%d)", sampleRateIndex)
|
return fmt.Errorf("invalid sample rate index (%d)", sampleRateIndex)
|
||||||
|
@@ -12,36 +12,36 @@ var configCases = []struct {
|
|||||||
dec MPEG4AudioConfig
|
dec MPEG4AudioConfig
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "aac-lc 44.1khz mono",
|
"aac-lc 44.1khz mono",
|
||||||
enc: []byte{0x12, 0x08, 0x56, 0xe5, 0x00},
|
[]byte{0x12, 0x08, 0x56, 0xe5, 0x00},
|
||||||
dec: MPEG4AudioConfig{
|
MPEG4AudioConfig{
|
||||||
Type: MPEG4AudioTypeAACLC,
|
Type: MPEG4AudioTypeAACLC,
|
||||||
SampleRate: 44100,
|
SampleRate: 44100,
|
||||||
ChannelCount: 1,
|
ChannelCount: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "aac-lc 48khz stereo",
|
"aac-lc 48khz stereo",
|
||||||
enc: []byte{17, 144},
|
[]byte{17, 144},
|
||||||
dec: MPEG4AudioConfig{
|
MPEG4AudioConfig{
|
||||||
Type: MPEG4AudioTypeAACLC,
|
Type: MPEG4AudioTypeAACLC,
|
||||||
SampleRate: 48000,
|
SampleRate: 48000,
|
||||||
ChannelCount: 2,
|
ChannelCount: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "aac-lc 96khz stereo",
|
"aac-lc 96khz stereo",
|
||||||
enc: []byte{0x10, 0x10, 0x56, 0xE5, 0x00},
|
[]byte{0x10, 0x10, 0x56, 0xE5, 0x00},
|
||||||
dec: MPEG4AudioConfig{
|
MPEG4AudioConfig{
|
||||||
Type: MPEG4AudioTypeAACLC,
|
Type: MPEG4AudioTypeAACLC,
|
||||||
SampleRate: 96000,
|
SampleRate: 96000,
|
||||||
ChannelCount: 2,
|
ChannelCount: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "aac-lc 44.1khz 5.1",
|
"aac-lc 44.1khz 5.1",
|
||||||
enc: []byte{0x12, 0x30},
|
[]byte{0x12, 0x30},
|
||||||
dec: MPEG4AudioConfig{
|
MPEG4AudioConfig{
|
||||||
Type: MPEG4AudioTypeAACLC,
|
Type: MPEG4AudioTypeAACLC,
|
||||||
SampleRate: 44100,
|
SampleRate: 44100,
|
||||||
ChannelCount: 6,
|
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())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user