-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmarshal_test.go
102 lines (86 loc) · 2.55 KB
/
marshal_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
package zcl
import (
"github.com/shimmeringbee/zigbee"
"github.com/stretchr/testify/assert"
"testing"
)
func Test_Marshal(t *testing.T) {
type Command struct {
FieldOne uint8
}
clusterID := zigbee.ClusterID(0xbeef)
commandID := CommandIdentifier(0xcc)
manufacturer := zigbee.ManufacturerCode(0x1020)
cr := NewCommandRegistry()
cr.RegisterGlobal(commandID, &Command{})
cr.RegisterLocal(clusterID, manufacturer, ClientToServer, commandID, &Command{})
t.Run("a manufacturer specific header and global message marshals", func(t *testing.T) {
in := Message{
FrameType: FrameGlobal,
Direction: ClientToServer,
TransactionSequence: 0x40,
Manufacturer: 0x1020,
ClusterID: 0x8888,
SourceEndpoint: 0x03,
DestinationEndpoint: 0x04,
Command: &Command{
FieldOne: 0xaa,
},
}
expectedOut := zigbee.ApplicationMessage{
ClusterID: 0x8888,
SourceEndpoint: 0x03,
DestinationEndpoint: 0x04,
Data: []byte{0b00000100, 0x20, 0x10, 0x40, 0xcc, 0xaa},
}
actualOut, err := cr.Marshal(in)
assert.NoError(t, err)
assert.Equal(t, expectedOut, actualOut)
})
t.Run("no manufacturer specific header and global message marshals", func(t *testing.T) {
in := Message{
FrameType: FrameGlobal,
Direction: ClientToServer,
TransactionSequence: 0x40,
Manufacturer: 0x0,
ClusterID: 0x8888,
SourceEndpoint: 0x03,
DestinationEndpoint: 0x04,
Command: &Command{
FieldOne: 0xaa,
},
}
expectedOut := zigbee.ApplicationMessage{
ClusterID: 0x8888,
SourceEndpoint: 0x03,
DestinationEndpoint: 0x04,
Data: []byte{0b00000000, 0x40, 0xcc, 0xaa},
}
actualOut, err := cr.Marshal(in)
assert.NoError(t, err)
assert.Equal(t, expectedOut, actualOut)
})
t.Run("a manufacturer specific header and a local message marshals", func(t *testing.T) {
in := Message{
FrameType: FrameLocal,
Direction: ClientToServer,
TransactionSequence: 0x40,
Manufacturer: manufacturer,
ClusterID: clusterID,
SourceEndpoint: 0x03,
DestinationEndpoint: 0x04,
Command: &Command{
FieldOne: 0xaa,
},
}
expectedOut := zigbee.ApplicationMessage{
ClusterID: clusterID,
SourceEndpoint: 0x03,
DestinationEndpoint: 0x04,
Data: []byte{0b00000101, 0x20, 0x10, 0x40, 0xcc, 0xaa},
}
actualOut, err := cr.Marshal(in)
assert.NoError(t, err)
assert.Equal(t, expectedOut, actualOut)
})
}