utp_test.go 594 B

1234567891011121314151617181920212223242526
  1. package utp_test
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/v2fly/v2ray-core/v5/common"
  6. "github.com/v2fly/v2ray-core/v5/common/buf"
  7. . "github.com/v2fly/v2ray-core/v5/transport/internet/headers/utp"
  8. )
  9. func TestUTPWrite(t *testing.T) {
  10. content := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
  11. utpRaw, err := New(context.Background(), &Config{})
  12. common.Must(err)
  13. utp := utpRaw.(*UTP)
  14. payload := buf.New()
  15. utp.Serialize(payload.Extend(utp.Size()))
  16. payload.Write(content)
  17. if payload.Len() != int32(len(content))+utp.Size() {
  18. t.Error("unexpected payload length: ", payload.Len())
  19. }
  20. }