improve tests

This commit is contained in:
aler9
2022-08-14 20:54:57 +02:00
parent 40c1ff8dfe
commit a0a168d26c
11 changed files with 78 additions and 28 deletions

View File

@@ -7,6 +7,23 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTrackH264Attributes(t *testing.T) {
track := &TrackH264{
PayloadType: 96,
SPS: []byte{0x01, 0x02},
PPS: []byte{0x03, 0x04},
}
require.Equal(t, 90000, track.ClockRate())
require.Equal(t, "", track.GetControl())
require.Equal(t, []byte{0x01, 0x02}, track.SafeSPS())
require.Equal(t, []byte{0x03, 0x04}, track.SafePPS())
track.SafeSetSPS([]byte{0x07, 0x08})
track.SafeSetPPS([]byte{0x09, 0x0A})
require.Equal(t, []byte{0x07, 0x08}, track.SafeSPS())
require.Equal(t, []byte{0x09, 0x0A}, track.SafePPS())
}
func TestTrackH264GetSPSPPSErrors(t *testing.T) { func TestTrackH264GetSPSPPSErrors(t *testing.T) {
for _, ca := range []struct { for _, ca := range []struct {
name string name string
@@ -165,22 +182,6 @@ func TestTrackH264GetSPSPPSErrors(t *testing.T) {
} }
} }
func TestTrackH264Params(t *testing.T) {
track := &TrackH264{
PayloadType: 96,
SPS: []byte{0x01, 0x02},
PPS: []byte{0x03, 0x04},
}
require.Equal(t, "", track.GetControl())
require.Equal(t, []byte{0x01, 0x02}, track.SafeSPS())
require.Equal(t, []byte{0x03, 0x04}, track.SafePPS())
track.SafeSetSPS([]byte{0x07, 0x08})
track.SafeSetPPS([]byte{0x09, 0x0A})
require.Equal(t, []byte{0x07, 0x08}, track.SafeSPS())
require.Equal(t, []byte{0x09, 0x0A}, track.SafePPS())
}
func TestTrackH264Clone(t *testing.T) { func TestTrackH264Clone(t *testing.T) {
track := &TrackH264{ track := &TrackH264{
PayloadType: 96, PayloadType: 96,

View File

@@ -7,13 +7,14 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTrackH265Params(t *testing.T) { func TestTrackH265Attributes(t *testing.T) {
track := &TrackH265{ track := &TrackH265{
PayloadType: 96, PayloadType: 96,
VPS: []byte{0x01, 0x02}, VPS: []byte{0x01, 0x02},
SPS: []byte{0x03, 0x04}, SPS: []byte{0x03, 0x04},
PPS: []byte{0x05, 0x06}, PPS: []byte{0x05, 0x06},
} }
require.Equal(t, 90000, track.ClockRate())
require.Equal(t, "", track.GetControl()) require.Equal(t, "", track.GetControl())
require.Equal(t, []byte{0x01, 0x02}, track.SafeVPS()) require.Equal(t, []byte{0x01, 0x02}, track.SafeVPS())
require.Equal(t, []byte{0x03, 0x04}, track.SafeSPS()) require.Equal(t, []byte{0x03, 0x04}, track.SafeSPS())

View File

@@ -1,4 +1,4 @@
package gortsplib package gortsplib //nolint:dupl
import ( import (
"testing" "testing"
@@ -7,6 +7,12 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTrackJPEGAttributes(t *testing.T) {
track := &TrackJPEG{}
require.Equal(t, 90000, track.ClockRate())
require.Equal(t, "", track.GetControl())
}
func TestTrackJPEGClone(t *testing.T) { func TestTrackJPEGClone(t *testing.T) {
track := &TrackJPEG{} track := &TrackJPEG{}

View File

@@ -1,4 +1,4 @@
package gortsplib package gortsplib //nolint:dupl
import ( import (
"testing" "testing"
@@ -7,8 +7,9 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTrackMPEG2AudioNew(t *testing.T) { func TestTrackMPEG2AudioAttributes(t *testing.T) {
track := &TrackMPEG2Audio{} track := &TrackMPEG2Audio{}
require.Equal(t, 90000, track.ClockRate())
require.Equal(t, "", track.GetControl()) require.Equal(t, "", track.GetControl())
} }

View File

@@ -1,4 +1,4 @@
package gortsplib package gortsplib //nolint:dupl
import ( import (
"testing" "testing"
@@ -7,8 +7,9 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTrackMPEG2VideoNew(t *testing.T) { func TestTrackMPEG2VideoAttributes(t *testing.T) {
track := &TrackMPEG2Video{} track := &TrackMPEG2Video{}
require.Equal(t, 90000, track.ClockRate())
require.Equal(t, "", track.GetControl()) require.Equal(t, "", track.GetControl())
} }

View File

@@ -9,6 +9,22 @@ import (
"github.com/aler9/gortsplib/pkg/mpeg4audio" "github.com/aler9/gortsplib/pkg/mpeg4audio"
) )
func TestTrackMPEG4AudioAttributes(t *testing.T) {
track := &TrackMPEG4Audio{
PayloadType: 96,
Config: &mpeg4audio.Config{
Type: 2,
SampleRate: 48000,
ChannelCount: 2,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
}
require.Equal(t, 48000, track.ClockRate())
require.Equal(t, "", track.GetControl())
}
func TestTrackMPEG4AudioClone(t *testing.T) { func TestTrackMPEG4AudioClone(t *testing.T) {
track := &TrackMPEG4Audio{ track := &TrackMPEG4Audio{
PayloadType: 96, PayloadType: 96,

View File

@@ -7,6 +7,16 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTrackOpusAttributes(t *testing.T) {
track := &TrackOpus{
PayloadType: 96,
SampleRate: 48000,
ChannelCount: 2,
}
require.Equal(t, 48000, track.ClockRate())
require.Equal(t, "", track.GetControl())
}
func TestTracOpusClone(t *testing.T) { func TestTracOpusClone(t *testing.T) {
track := &TrackOpus{ track := &TrackOpus{
PayloadType: 96, PayloadType: 96,

View File

@@ -1,4 +1,4 @@
package gortsplib package gortsplib //nolint:dupl
import ( import (
"testing" "testing"
@@ -7,8 +7,9 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTrackPCMANew(t *testing.T) { func TestTrackPCMAAttributes(t *testing.T) {
track := &TrackPCMA{} track := &TrackPCMA{}
require.Equal(t, 8000, track.ClockRate())
require.Equal(t, "", track.GetControl()) require.Equal(t, "", track.GetControl())
} }

View File

@@ -1,4 +1,4 @@
package gortsplib package gortsplib //nolint:dupl
import ( import (
"testing" "testing"
@@ -7,8 +7,9 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTrackPCMUNew(t *testing.T) { func TestTrackPCMUAttributes(t *testing.T) {
track := &TrackPCMU{} track := &TrackPCMU{}
require.Equal(t, 8000, track.ClockRate())
require.Equal(t, "", track.GetControl()) require.Equal(t, "", track.GetControl())
} }

View File

@@ -7,7 +7,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTracVP8Clone(t *testing.T) { func TestTrackVP8ttributes(t *testing.T) {
track := &TrackVP8{}
require.Equal(t, 90000, track.ClockRate())
require.Equal(t, "", track.GetControl())
}
func TestTrackVP8Clone(t *testing.T) {
maxFR := 123 maxFR := 123
maxFS := 456 maxFS := 456
track := &TrackVP8{ track := &TrackVP8{

View File

@@ -7,7 +7,13 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTracVP9Clone(t *testing.T) { func TestTrackVP9ttributes(t *testing.T) {
track := &TrackVP9{}
require.Equal(t, 90000, track.ClockRate())
require.Equal(t, "", track.GetControl())
}
func TestTrackVP9Clone(t *testing.T) {
maxFR := 123 maxFR := 123
maxFS := 456 maxFS := 456
profileID := 789 profileID := 789