-
Notifications
You must be signed in to change notification settings - Fork 0
/
vdmvdo_test.go
102 lines (97 loc) · 3.19 KB
/
vdmvdo_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 nmea
import (
"testing"
"github.com/stretchr/testify/assert"
)
var vdmtests = []struct {
name string
raw string
err string
msg VDMVDO
}{
{
name: "Good single fragment message",
raw: "!AIVDM,1,1,,A,13aGt0PP0jPN@9fMPKVDJgwfR>`<,0*55",
msg: VDMVDO{
NumFragments: 1,
FragmentNumber: 1,
MessageID: 0,
Channel: "A",
Payload: []byte{0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0},
},
},
{
name: "Good single fragment message with padding",
raw: "!AIVDM,1,1,,A,H77nSfPh4U=<E`H4U8G;:222220,2*1F",
msg: VDMVDO{
NumFragments: 1,
FragmentNumber: 1,
MessageID: 0,
Channel: "A",
Payload: []byte{0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
},
},
{
name: "Good multipart fragment",
raw: "!AIVDM,2,2,4,B,00000000000,2*23",
msg: VDMVDO{
NumFragments: 2,
FragmentNumber: 2,
MessageID: 4,
Channel: "B",
Payload: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
},
},
{
name: "Empty payload",
raw: "!AIVDM,1,1,,1,,0*56",
msg: VDMVDO{
NumFragments: 1,
FragmentNumber: 1,
MessageID: 0,
Channel: "1",
Payload: []byte{},
},
},
{
name: "Invalid number of fragments",
raw: "!AIVDM,x,1,,1,000 00,0*0F",
err: "nmea: AIVDM invalid number of fragments: x",
},
{
name: "Invalid symbol in payload",
raw: "!AIVDM,1,1,,1,000 00,0*46",
err: "nmea: AIVDM invalid payload: data byte",
},
{
name: "Negative number of fill bits",
raw: "!AIVDM,1,1,,1,000,-3*48",
err: "nmea: AIVDM invalid payload: fill bits",
},
{
name: "Too high number of fill bits",
raw: "!AIVDO,1,1,,1,000,20*56",
err: "nmea: AIVDO invalid payload: fill bits",
},
{
name: "Negative number of bits",
raw: "!AIVDM,1,1,,1,,2*54",
err: "nmea: AIVDM invalid payload: num bits",
},
}
func TestVDM(t *testing.T) {
for _, tt := range vdmtests {
t.Run(tt.name, func(t *testing.T) {
m, err := Parse(tt.raw)
if tt.err != "" {
assert.Error(t, err)
assert.EqualError(t, err, tt.err)
} else {
assert.NoError(t, err)
vdm := m.(VDMVDO)
vdm.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, vdm)
}
})
}
}