pingtunnel/pingtunnel_test.go

95 lines
2.0 KiB
Go
Raw Normal View History

2018-12-18 11:17:57 +03:00
package pingtunnel
import (
"fmt"
2019-10-22 16:04:25 +03:00
"github.com/golang/protobuf/proto"
2018-12-18 11:17:57 +03:00
"testing"
)
2019-10-24 16:42:46 +03:00
func Test0001(t *testing.T) {
2018-12-18 11:17:57 +03:00
2019-10-22 16:04:25 +03:00
my := &MyMsg{}
my.Id = "12345"
my.Target = "111:11"
my.Type = 12
2019-10-26 07:01:30 +03:00
my.Data = make([]byte, 0)
2019-10-22 16:04:25 +03:00
dst, _ := proto.Marshal(my)
2018-12-18 11:17:57 +03:00
fmt.Println("dst = ", dst)
2019-10-22 16:04:25 +03:00
my1 := &MyMsg{}
proto.Unmarshal(dst, my1)
2018-12-18 11:17:57 +03:00
fmt.Println("my1 = ", my1)
2019-10-26 07:01:30 +03:00
fmt.Println("my1.Data = ", my1.Data)
2018-12-18 11:17:57 +03:00
2019-10-22 16:04:25 +03:00
proto.Unmarshal(dst[0:4], my1)
2018-12-18 11:17:57 +03:00
fmt.Println("my1 = ", my1)
2019-10-24 16:42:46 +03:00
fm := FrameMgr{}
2019-10-26 15:39:41 +03:00
fm.recvid = 4
2019-10-24 16:42:46 +03:00
fm.windowsize = 100
lr := &Frame{}
rr := &Frame{}
lr.Id = 1
2019-10-26 15:39:41 +03:00
rr.Id = 4
fmt.Println("fm.compareId(lr, rr) = ", fm.compareId((int)(lr.Id), (int)(rr.Id)))
2019-10-24 16:42:46 +03:00
lr.Id = 99
rr.Id = 8
2019-10-26 15:39:41 +03:00
fmt.Println("fm.compareId(lr, rr) = ", fm.compareId((int)(lr.Id), (int)(rr.Id)))
2019-10-24 16:42:46 +03:00
fm.recvid = 9000
lr.Id = 9998
rr.Id = 9999
2019-10-26 15:39:41 +03:00
fmt.Println("fm.compareId(lr, rr) = ", fm.compareId((int)(lr.Id), (int)(rr.Id)))
2019-10-24 16:42:46 +03:00
fm.recvid = 9000
lr.Id = 9998
rr.Id = 8
2019-10-26 15:39:41 +03:00
fmt.Println("fm.compareId(lr, rr) = ", fm.compareId((int)(lr.Id), (int)(rr.Id)))
2019-10-24 16:42:46 +03:00
fm.recvid = 0
lr.Id = 9998
rr.Id = 8
2019-10-26 15:39:41 +03:00
fmt.Println("fm.compareId(lr, rr) = ", fm.compareId((int)(lr.Id), (int)(rr.Id)))
fm.recvid = 0
fm.windowsize = 5
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(4, 10))
fm.recvid = 0
fm.windowsize = 5
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(5, 10))
fm.recvid = 4
fm.windowsize = 5
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(1, 10))
fm.recvid = 7
fm.windowsize = 5
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(1, 10))
fm.recvid = 7
fm.windowsize = 5
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(2, 10))
fm.recvid = 7
fm.windowsize = 5
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(9, 10))
2019-10-26 15:45:58 +03:00
fm.recvid = 10
fm.windowsize = 10000
fmt.Println("fm.isIdInRange = ", fm.isIdInRange(0, FRAME_MAX_ID))
2019-10-26 16:22:14 +03:00
fm.recvid = 7
fm.windowsize = 5
fmt.Println("fm.isIdOld = ", fm.isIdOld(2, 10))
fm.recvid = 7
fm.windowsize = 5
fmt.Println("fm.isIdOld = ", fm.isIdOld(1, 10))
fm.recvid = 3
fm.windowsize = 5
fmt.Println("fm.isIdOld = ", fm.isIdOld(1, 10))
2018-12-18 11:17:57 +03:00
}