mirror of
https://gitee.com/willfree/mlsr.git
synced 2026-10-04 19:42:02 +08:00
增加测试RouteCost
This commit is contained in:
1 parent
19fb515c69
commit
3e69ec2dea
1 file changed
+81
@@ -0,0 +1,81 @@
|
||||
// Package route
|
||||
// @Author: Wang Feng
|
||||
// @Description:
|
||||
// @Version: 0.1.0
|
||||
// @Date: 2022/5/26 12:02
|
||||
// @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
//
|
||||
|
||||
package route
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"minlib/encoding"
|
||||
"testing"
|
||||
)
|
||||
|
||||
//
|
||||
// TestRouteCost_SetRouteCost
|
||||
// @Description: 测试设置属性
|
||||
// @param t
|
||||
//
|
||||
func TestRouteCost_SetRouteCost(t *testing.T) {
|
||||
lsaSequenceNumber := RouteCost{}
|
||||
lsaSequenceNumber.SetRouteCost(77)
|
||||
if lsaSequenceNumber.RouteCost() != 77 {
|
||||
t.Fatal("RouteCost设置失败")
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// TestRouteCost_WireEncode
|
||||
// @Description: 测试编码
|
||||
// @param t
|
||||
//
|
||||
func TestRouteCost_WireEncode(t *testing.T) {
|
||||
linkCost := RouteCost{}
|
||||
linkCost.SetRouteCost(1234)
|
||||
|
||||
encoder := encoding.Encoder{}
|
||||
encoder.EncoderReset(encoding.MaxPacketSize, 0)
|
||||
length, err := linkCost.WireEncode(&encoder)
|
||||
if err != nil {
|
||||
t.Fatal("RouteCost编码失败", err.Error())
|
||||
}
|
||||
|
||||
buf, err := encoder.GetBuffer()
|
||||
if err != nil {
|
||||
t.Fatal("RouteCost获取buffer结果失败", err.Error())
|
||||
}
|
||||
|
||||
res := []byte{241, 1, 186, 2, 4, 210}
|
||||
if length != 6 || !bytes.Equal(buf, res) {
|
||||
fmt.Println("buf: ", buf)
|
||||
fmt.Println("res: ", res)
|
||||
t.Fatal("RouteCost编码内容错误", length, buf)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// TestRouteCost_WireDecode
|
||||
// @Description: 测试解码
|
||||
// @param t
|
||||
//
|
||||
func TestRouteCost_WireDecode(t *testing.T) {
|
||||
var buf [6]byte = [6]byte{241, 1, 186, 2, 4, 210}
|
||||
block, err := encoding.CreateBlockByBuffer(buf[:], true)
|
||||
if err != nil {
|
||||
t.Fatal("RouteCost创建Block失败", err.Error())
|
||||
}
|
||||
|
||||
linkCost := RouteCost{}
|
||||
err = linkCost.WireDecode(block)
|
||||
if err != nil {
|
||||
t.Fatal("RouteCost解码失败", err.Error())
|
||||
}
|
||||
|
||||
if linkCost.RouteCost() != 1234 {
|
||||
t.Fatal("RouteCost解码内容错误", linkCost.RouteCost())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user