-
Notifications
You must be signed in to change notification settings - Fork 64
/
activetest_test.go
114 lines (93 loc) · 2.96 KB
/
activetest_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright 2015 Tony Bai.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package cmpp_test
import (
"testing"
"github.com/bigwhite/gocmpp"
)
func TestCmppActiveTestReqPktPack(t *testing.T) {
p := &cmpp.CmppActiveTestReqPkt{}
data, err := p.Pack(seqId)
if err != nil {
t.Fatal("CmppActiveTestReqPkt pack error:", err)
}
if p.SeqId != seqId {
t.Fatalf("After pack, seqId is %d, not equal to expected: %d\n", p.SeqId, seqId)
}
// data after pack expected:
dataExpected := []byte{
0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x17,
}
l1 := len(data)
l2 := len(dataExpected)
if l1 != l2 {
t.Fatalf("After pack, data length is %d, not equal to length expected: %d\n", l1, l2)
}
for i := 0; i < l1; i++ {
if data[i] != dataExpected[i] {
t.Fatalf("After pack, data[%d] is %x, not equal to dataExpected[%d]: %x\n", i, data[i], i, dataExpected[i])
}
}
}
func TestCmppActiveTestReqUnpack(t *testing.T) {
// cmpp active test request packet data:
data := []byte{
0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x17,
}
p := &cmpp.CmppActiveTestReqPkt{}
err := p.Unpack(data[8:])
if err != nil {
t.Fatal("CmppActiveTestReqPkt unpack error:", err)
}
if p.SeqId != seqId {
t.Fatalf("After unpack, seqId in packet is %x, not equal to the expected value: %x\n", p.SeqId, seqId)
}
}
func TestCmppActiveTestRspPktPack(t *testing.T) {
p := &cmpp.CmppActiveTestRspPkt{}
data, err := p.Pack(seqId)
if err != nil {
t.Fatal("CmppActiveTestRspPkt pack error:", err)
}
if p.SeqId != seqId {
t.Fatalf("After pack, seqId is %d, not equal to expected: %d\n", p.SeqId, seqId)
}
// data after pack expected:
dataExpected := []byte{
0x00, 0x00, 0x00, 0x0d, 0x80, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x17, 0x00,
}
l1 := len(data)
l2 := len(dataExpected)
if l1 != l2 {
t.Fatalf("After pack, data length is %d, not equal to length expected: %d\n", l1, l2)
}
for i := 0; i < l1; i++ {
if data[i] != dataExpected[i] {
t.Fatalf("After pack, data[%d] is %x, not equal to dataExpected[%d]: %x\n", i, data[i], i, dataExpected[i])
}
}
}
func TestCmppActiveTestRspUnpack(t *testing.T) {
// cmpp active test response packet data:
data := []byte{
0x00, 0x00, 0x00, 0x0d, 0x80, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x17, 0x00,
}
p := &cmpp.CmppActiveTestRspPkt{}
err := p.Unpack(data[8:])
if err != nil {
t.Fatal("CmppActiveTestRspPkt unpack error:", err)
}
if p.SeqId != seqId {
t.Fatalf("After unpack, seqId in packet is %x, not equal to the expected value: %x\n", p.SeqId, seqId)
}
}