1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-29 23:36:25 -04:00

test case for cmd only segment

This commit is contained in:
Darien Raymond 2016-10-11 11:44:30 +02:00
parent e023859ef0
commit 78f87c4f60
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 28 additions and 1 deletions

View File

@ -149,7 +149,7 @@ func (this *CmdOnlySegment) Release() {
}
func ReadSegment(buf []byte) (Segment, []byte) {
if len(buf) <= 4 {
if len(buf) < 4 {
return nil, nil
}

View File

@ -69,3 +69,30 @@ func TestACKSegment(t *testing.T) {
assert.Uint32(seg2.NumberList[i]).Equals(seg.NumberList[i])
}
}
func TestCmdSegment(t *testing.T) {
assert := assert.On(t)
seg := &CmdOnlySegment{
Conv: 1,
Command: CommandPing,
Option: SegmentOptionClose,
SendingNext: 11,
ReceivinNext: 13,
PeerRTO: 15,
}
nBytes := seg.ByteSize()
bytes := seg.Bytes(nil)
assert.Int(len(bytes)).Equals(nBytes)
iseg, _ := ReadSegment(bytes)
seg2 := iseg.(*CmdOnlySegment)
assert.Uint16(seg2.Conv).Equals(seg.Conv)
assert.Byte(byte(seg2.Command)).Equals(byte(seg.Command))
assert.Byte(byte(seg2.Option)).Equals(byte(seg.Option))
assert.Uint32(seg2.SendingNext).Equals(seg.SendingNext)
assert.Uint32(seg2.ReceivinNext).Equals(seg.ReceivinNext)
assert.Uint32(seg2.PeerRTO).Equals(seg.PeerRTO)
}