2016-12-08 10:27:41 -05:00
|
|
|
package kcp_test
|
2018-08-07 18:26:01 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-02-16 15:31:50 -05:00
|
|
|
. "github.com/v2fly/v2ray-core/v4/transport/internet/kcp"
|
2018-08-07 18:26:01 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestKCPPacketReader(t *testing.T) {
|
|
|
|
reader := KCPPacketReader{
|
|
|
|
Security: &SimpleAuthenticator{},
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
Input []byte
|
|
|
|
Output []Segment
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Input: []byte{},
|
|
|
|
Output: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Input: []byte{1},
|
|
|
|
Output: nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
|
|
|
seg := reader.Read(testCase.Input)
|
|
|
|
if testCase.Output == nil && seg != nil {
|
|
|
|
t.Errorf("Expect nothing returned, but actually %v", seg)
|
|
|
|
} else if testCase.Output != nil && seg == nil {
|
|
|
|
t.Errorf("Expect some output, but got nil")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|