github.com/v2fly/v2ray-core/v4@v4.45.2/transport/internet/headers/srtp/srtp_test.go (about)

     1  package srtp_test
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/v2fly/v2ray-core/v4/common"
     8  	"github.com/v2fly/v2ray-core/v4/common/buf"
     9  	. "github.com/v2fly/v2ray-core/v4/transport/internet/headers/srtp"
    10  )
    11  
    12  func TestSRTPWrite(t *testing.T) {
    13  	content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
    14  	srtpRaw, err := New(context.Background(), &Config{})
    15  	common.Must(err)
    16  
    17  	srtp := srtpRaw.(*SRTP)
    18  
    19  	payload := buf.New()
    20  	srtp.Serialize(payload.Extend(srtp.Size()))
    21  	payload.Write(content)
    22  
    23  	expectedLen := int32(len(content)) + srtp.Size()
    24  	if payload.Len() != expectedLen {
    25  		t.Error("expected ", expectedLen, " of bytes, but got ", payload.Len())
    26  	}
    27  }