github.com/xmplusdev/xmcore@v1.8.11-0.20240412132628-5518b55526af/transport/internet/headers/utp/utp_test.go (about)

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