test: Add buffer test
package sfu
import (
+ "testing"
+
"github.com/pion/rtp"
+ "github.com/pion/webrtc/v3"
+ "github.com/stretchr/testify/assert"
)
func CreateTestPacket(pktStamp *SequenceNumberAndTimeStamp) *rtp.Packet {
@@ -36,3 +40,68 @@ func CreateTestListPackets(snsAndTSs []SequenceNumberAndTimeStamp) (packetList [
return packetList
}
+
+func TestNewBuffer(t *testing.T) {
+ me := webrtc.MediaEngine{}
+ me.RegisterDefaultCodecs()
+ api := webrtc.NewAPI(webrtc.WithMediaEngine(me))
+ p, _ := api.NewPeerConnection(webrtc.Configuration{})
+ track, _ := p.NewTrack(webrtc.DefaultPayloadTypeVP8, 1234, "test", "pion")
+
+ type args struct {
+ track *webrtc.Track
+ o BufferOptions
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Must not be nil and add packets in sequence",
+ args: args{
+ track: track,
+ o: BufferOptions{
+ TWCCExt: 0,
+ BufferTime: 1e3,
+ MaxBitRate: 1e3,
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ tt := tt
+ t.Run(tt.name, func(t *testing.T) {
+ var TestPackets = []*rtp.Packet{
+ {
+ Header: rtp.Header{
+ SequenceNumber: 65533,
+ },
+ },
+ {
+ Header: rtp.Header{
+ SequenceNumber: 65534,
+ },
+ },
+ {
+ Header: rtp.Header{
+ SequenceNumber: 2,
+ },
+ },
+ {
+ Header: rtp.Header{
+ SequenceNumber: 65535,
+ },
+ },
+ }
+ buff := NewBuffer(tt.args.track, tt.args.o)
+ assert.NotNil(t, buff)
+
+ for _, p := range TestPackets {
+ buff.push(p)
+ }
+ assert.Equal(t, 6, buff.pktQueue.size)
+ assert.Equal(t, uint32(1<<16), buff.cycles)
+ assert.Equal(t, uint16(2), buff.maxSeqNo)
+ })
+ }
+}
