-
Notifications
You must be signed in to change notification settings - Fork 26
/
controlblock_test.go
144 lines (116 loc) · 3.07 KB
/
controlblock_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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package dmr
import "testing"
func testCSBK(want *ControlBlock, t *testing.T) *ControlBlock {
want.SrcID = 2042214
want.DstID = 2043044
data, err := want.Bytes()
if err != nil {
t.Fatalf("encode failed: %v", err)
}
test, err := ParseControlBlock(data)
if err != nil {
t.Fatalf("decode failed: %v", err)
}
if test.SrcID != want.SrcID || test.DstID != want.DstID {
t.Fatal("decode failed, ID wrong")
}
return test
}
func TestCSBKOutboundActivation(t *testing.T) {
want := &ControlBlock{
Opcode: OutboundActivationOpcode,
Data: &OutboundActivation{},
}
test := testCSBK(want, t)
_, ok := test.Data.(*OutboundActivation)
switch {
case !ok:
t.Fatalf("decode failed: expected UnitToUnitVoiceServiceRequest, got %T", test.Data)
default:
t.Logf("decode: %s", test.String())
}
}
func TestCSBKUnitToUnitVoiceServiceRequest(t *testing.T) {
want := &ControlBlock{
Opcode: UnitToUnitVoiceServiceRequestOpcode,
Data: &UnitToUnitVoiceServiceRequest{
Options: 0x2a,
},
}
test := testCSBK(want, t)
d, ok := test.Data.(*UnitToUnitVoiceServiceRequest)
switch {
case !ok:
t.Fatalf("decode failed: expected UnitToUnitVoiceServiceRequest, got %T", test.Data)
case d.Options != 0x2a:
t.Fatalf("decode failed, options wrong")
default:
t.Logf("decode: %s", test.String())
}
}
func TestCSBKUnitToUnitVoiceServiceAnswerResponse(t *testing.T) {
want := &ControlBlock{
Opcode: UnitToUnitVoiceServiceAnswerResponseOpcode,
Data: &UnitToUnitVoiceServiceAnswerResponse{
Options: 0x17,
Response: 0x2a,
},
}
test := testCSBK(want, t)
d, ok := test.Data.(*UnitToUnitVoiceServiceAnswerResponse)
switch {
case !ok:
t.Fatalf("decode failed: expected UnitToUnitVoiceServiceAnswerResponse, got %T", test.Data)
case d.Response != 0x2a:
t.Fatalf("decode failed, response wrong")
case d.Options != 0x17:
t.Fatalf("decode failed, options wrong")
default:
t.Logf("decode: %s", test.String())
}
}
func TestCSBKNegativeAcknowledgeResponse(t *testing.T) {
want := &ControlBlock{
Opcode: NegativeAcknowledgeResponseOpcode,
Data: &NegativeAcknowledgeResponse{
ServiceType: 0x01,
Reason: 0x02,
},
}
test := testCSBK(want, t)
d, ok := test.Data.(*NegativeAcknowledgeResponse)
switch {
case !ok:
t.Fatalf("decode failed: expected NegativeAcknowledgeResponse, got %T", test.Data)
case d.ServiceType != 0x01:
t.Fatalf("decode failed, service type wrong")
case d.Reason != 0x02:
t.Fatalf("decode failed, reason wrong")
default:
t.Logf("decode: %s", test.String())
}
}
func TestCSBKPreamble(t *testing.T) {
want := &ControlBlock{
Opcode: PreambleOpcode,
Data: &Preamble{
DataFollows: true,
DstIsGroup: false,
Blocks: 0x10,
},
}
test := testCSBK(want, t)
d, ok := test.Data.(*Preamble)
switch {
case !ok:
t.Fatalf("decode failed: expected Preamble, got %T", test.Data)
case !d.DataFollows:
t.Fatalf("decode failed, data follows wrong")
case d.DstIsGroup:
t.Fatalf("decode failed, dst is group wrong")
case d.Blocks != 0x10:
t.Fatalf("decode failed, blocks wrong")
default:
t.Logf("decode: %s", test.String())
}
}