forked from jonaz/gombus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathframe_test.go
More file actions
80 lines (68 loc) · 1.74 KB
/
Copy pathframe_test.go
File metadata and controls
80 lines (68 loc) · 1.74 KB
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
package gombus
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
// fcbFcvFrame captures the FCB/FCV mutator interface common to ShortFrame
// and LongFrame, so the round-trip test below can exercise both.
type fcbFcvFrame interface {
SetFCB()
ClearFCB()
SetFCV()
ClearFCV()
C() C
}
func assertFCBFCVRoundTrip(t *testing.T, f fcbFcvFrame) {
t.Helper()
f.SetFCB()
assert.True(t, f.C().FCB())
f.ClearFCB()
assert.False(t, f.C().FCB())
f.SetFCV()
assert.True(t, f.C().FCV())
f.ClearFCV()
assert.False(t, f.C().FCV())
}
func TestShortFrameAccessors(t *testing.T) {
f := NewShortFrame()
f.SetAddress(0x05)
f.SetC(0x40)
f.SetChecksum()
assert.Equal(t, byte(0x05), f.A())
assert.Equal(t, C(0x40), f.C())
assert.Equal(t, "10 40 05 45 16", fmt.Sprintf("% x", f))
}
func TestShortFrameFCBFCV(t *testing.T) {
f := NewShortFrame()
f.SetC(0x40)
assertFCBFCVRoundTrip(t, f)
}
func TestLongFrameAccessors(t *testing.T) {
f := LongFrame{0x68, 0x06, 0x06, 0x68, 0x73, 0x01, 0x50, 0x01, 0x7a, 0x03, 0x00, 0x16}
f.SetLength()
f.SetChecksum()
assert.Equal(t, 6, f.L())
assert.Equal(t, byte(0x01), f.A())
assert.Equal(t, byte(0x50), f.CI())
assert.Equal(t, C(0x73), f.C())
}
func TestLongFrameFCBFCV(t *testing.T) {
f := LongFrame{0x68, 0x06, 0x06, 0x68, 0x73, 0x01, 0x50, 0x01, 0x7a, 0x03, 0x00, 0x16}
assertFCBFCVRoundTrip(t, f)
}
func TestCBitsRoundTrip(t *testing.T) {
cases := []struct {
c C
fcb, fcv bool
}{
{0x00, false, false},
{ControlMaskFcb, true, false},
{ControlMaskFcv, false, true},
{ControlMaskFcb | ControlMaskFcv, true, true},
}
for _, tc := range cases {
assert.Equal(t, tc.fcb, tc.c.FCB(), "FCB for c=0x%x", byte(tc.c))
assert.Equal(t, tc.fcv, tc.c.FCV(), "FCV for c=0x%x", byte(tc.c))
}
}