srtp_test.go 652 B

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