-
Notifications
You must be signed in to change notification settings - Fork 1
/
wg26_test.go
95 lines (86 loc) · 1.81 KB
/
wg26_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
package wg26
import (
"encoding/binary"
"fmt"
"testing"
)
//
// Author: 陈哈哈 [email protected]
//
func TestParseFromSN(t *testing.T) {
testFields := func(id *Wg26Id) {
t.Log("CardSN: ", id.CardSN)
t.Log("CardHex: ", id.CardHex)
t.Logf("Wg26Start: %d", id.Wg26Start)
t.Logf("Wg26End: %d", id.Wg26End)
t.Log("Wg26SN: ", id.Wg26SN)
t.Log("FormatWg26SN: ", id.FormatWg26SN())
if "0005653307" != id.CardSN {
t.Fail()
}
if "56433B" != id.CardHex {
t.Fail()
}
if 86 != id.Wg26Start {
t.Fail()
}
if 17211 != id.Wg26End {
t.Fail()
}
if "086,17211" != id.FormatWg26SN() {
t.Fail()
}
}
testFields(ParseFromCardNumber("0005653307"))
testFields(ParseFromWg26([3]byte{0x56, 0x43, 0x3B}))
}
func TestParse1(t *testing.T) {
id := ParseFromCardNumberValue(3659533)
t.Log("CardSN: ", id.CardSN)
t.Log("CardHex: ", id.CardHex)
t.Logf("Wg26Start: %d", id.Wg26Start)
t.Logf("Wg26End: %d", id.Wg26End)
t.Log("Wg26SN: ", id.Wg26SN)
t.Log("FormatWg26SN(): ", id.FormatWg26SN())
if "0003659533" != id.CardSN {
t.Fail()
}
if "37D70D" != id.CardHex {
t.Fail()
}
if 55 != id.Wg26Start {
t.Fail()
}
if 55053 != id.Wg26End {
t.Fail()
}
if "055,55053" != id.FormatWg26SN() {
t.Fail()
}
}
func TestParse2(t *testing.T) {
data := []byte{0xfb, 0x7c, 0x83, 0x00}
wg26Id := fmt.Sprintf("%d", binary.LittleEndian.Uint32(data))
id := ParseFromWg26Number(wg26Id)
t.Log("CardSN: ", id.CardSN)
t.Log("CardHex: ", id.CardHex)
t.Logf("Wg26Start: %d", id.Wg26Start)
t.Logf("Wg26End: %d", id.Wg26End)
t.Log("Wg26SN: ", id.Wg26SN)
t.Log("FormatWg26SN: ", id.FormatWg26SN())
if "0005653307" != id.CardSN {
t.Fail()
}
if "56433B" != id.CardHex {
t.Fail()
}
if 86 != id.Wg26Start {
t.Fail()
}
if 17211 != id.Wg26End {
t.Fail()
}
if "086,17211" != id.FormatWg26SN() {
t.Fail()
}
}