-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathframe_test.go
58 lines (50 loc) · 1.63 KB
/
frame_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
package zcl
import (
"github.com/shimmeringbee/bytecodec"
"github.com/stretchr/testify/assert"
"testing"
)
func Test_Header(t *testing.T) {
t.Run("manufacturer specific bit includes manufacturer ID in marshalled frame", func(t *testing.T) {
frame := Header{
Control: Control{
DisableDefaultResponse: false,
Direction: ClientToServer,
ManufacturerSpecific: true,
FrameType: FrameLocal,
},
Manufacturer: 0xaabb,
TransactionSequence: 0xcc,
CommandIdentifier: 0xdd,
}
data, err := bytecodec.Marshal(&frame)
assert.NoError(t, err)
assert.Equal(t, []byte{0b00000101, 0xbb, 0xaa, 0xcc, 0xdd}, data)
})
t.Run("absent manufacturer specific bit excludes manufacturer ID in marshalled frame", func(t *testing.T) {
frame := Header{
Control: Control{
DisableDefaultResponse: false,
Direction: ClientToServer,
ManufacturerSpecific: false,
FrameType: FrameLocal,
},
Manufacturer: 0xaabb,
TransactionSequence: 0xcc,
CommandIdentifier: 0xdd,
}
data, err := bytecodec.Marshal(&frame)
assert.NoError(t, err)
assert.Equal(t, []byte{0b00000001, 0xcc, 0xdd}, data)
})
}
func Test_ZCLMessage(t *testing.T) {
t.Run("a message without a manufacturer identifier is not identified as manufacturer specific", func(t *testing.T) {
message := Message{}
assert.False(t, message.isManufacturerSpecific())
})
t.Run("a message with a manufacturer identifier is identified as manufacturer specific", func(t *testing.T) {
message := Message{Manufacturer: 0x0001}
assert.True(t, message.isManufacturerSpecific())
})
}