-
Notifications
You must be signed in to change notification settings - Fork 2
/
packet_test.go
74 lines (52 loc) · 1.37 KB
/
packet_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
package tru
import (
"testing"
"github.com/teonet-go/tru/teolog"
)
// Distance func test
func TestDistance(t *testing.T) {
// Max uint32 = 0xFFFFFFFF
const maxPacketNum = 0xFFFFFFFF
log := teolog.New()
log.SetLevel(teolog.Debug)
var pac Packet
var d int
d = pac.distance(0, maxPacketNum)
log.Debug.Println(d)
d = pac.distance(maxPacketNum, 0)
log.Debug.Println(d)
d = pac.distance(0xFFFF, 0)
log.Debug.Println(d)
d = pac.distance(0, 0xFFFF)
log.Debug.Println(d)
d = pac.distance(1000, 2000)
log.Debug.Println(d)
d = pac.distance(10, maxPacketNum)
log.Debug.Println(d)
}
func TestPacStatusID(t *testing.T) {
log := teolog.New()
log.SetFlags(0)
log.SetLevel(teolog.Debug)
var maxid uint32 = packetIDLimit - 1
log.Debug.Printf("max id: %08X, %d", maxid, maxid)
log.Debug.Print()
pacUnpac := func(pac *Packet) {
// pack status and id
statid := pac.packStatID()
log.Debug.Printf("pack id: %05X, stsus: %02X, statid: %08X",
pac.id, pac.status, statid)
// unpack status and id
var pacout Packet
pacout.unpackStatID(statid)
log.Debug.Printf("unpack id: %05X, stsus: %02X, statid: %08X",
pacout.id, pacout.status, statid)
log.Debug.Print()
// compare
if pacout.id != pac.id || pacout.status != pac.status {
t.Error("wromg pac/unpack")
}
}
pacUnpac(&Packet{id: 48, status: 11})
pacUnpac(&Packet{id: maxid, status: 255})
}