From 3e69ec2dea4c0cd3be3444f9db929bd94e13fbda Mon Sep 17 00:00:00 2001 From: free will <2647778488@qq.com> Date: Thu, 26 May 2022 12:08:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95RouteCost?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- route/RouteCost_test.go | 81 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 route/RouteCost_test.go diff --git a/route/RouteCost_test.go b/route/RouteCost_test.go new file mode 100644 index 0000000..bf4d5b3 --- /dev/null +++ b/route/RouteCost_test.go @@ -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()) + } +}