File: bbm_test.go

package info (click to toggle)
golang-github-adrianmo-go-nmea 1.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 900 kB
  • sloc: makefile: 15
file content (126 lines) | stat: -rw-r--r-- 3,711 bytes parent folder | download
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
package nmea

import (
	"github.com/stretchr/testify/assert"
	"testing"
)

func TestBBM(t *testing.T) {
	var tests = []struct {
		name string
		raw  string
		err  string
		msg  BBM
	}{
		{
			name: "Good single fragment message",
			raw:  "!AIBBM,26,2,1,3,8,177KQJ5000G?tO`K>RA1wUbN0TKH,0*2C",
			msg: BBM{
				NumFragments:     26,
				FragmentNumber:   2,
				MessageID:        1,
				Channel:          "3",
				VDLMessageNumber: 8,
				Payload: []byte{
					0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, // 10
					0x1, 0x1, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x0, 0x1, // 20
					0x1, 0x0, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, // 30
					0x0, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1, // 40
					0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // 50
					0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // 60
					0x0, 0x1, 0x0, 0x1, 0x1, 0x1, 0x0, 0x0, 0x1, 0x1, // 70
					0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x1, // 80
					0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, // 90
					0x0, 0x1, 0x1, 0x0, 0x1, 0x1, 0x0, 0x0, 0x1, 0x1, // 100
					0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x1, // 110
					0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, // 120
					0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x1, // 130
					0x0, 0x1, 0x1, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x1, // 140
					0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // 150
					0x1, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, // 160
					0x1, 0x1, 0x0, 0x1, 0x1, 0x0, 0x0, 0x0, // 168
				},
			},
		},
		{
			name: "Good single fragment message with padding",
			raw:  "!AIBBM,26,2,1,3,8,H77nSfPh4U=<E`H4U8G;:222220,2*6C",
			msg: BBM{
				NumFragments:     26,
				FragmentNumber:   2,
				MessageID:        1,
				Channel:          "3",
				VDLMessageNumber: 8,
				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: "Empty payload",
			raw:  "!AIBBM,26,2,1,3,8,,0*55",
			msg: BBM{
				NumFragments:     26,
				FragmentNumber:   2,
				MessageID:        1,
				Channel:          "3",
				VDLMessageNumber: 8,
				Payload:          []byte{},
			},
		},
		{
			name: "Invalid number of fragments",
			raw:  "!AIBBM,x,2,1,3,8,177KQJ5000G?tO`K>RA1wUbN0TKH,0*50",
			err:  "nmea: AIBBM invalid number of fragments: x",
		},
		{
			name: "Invalid symbol in payload",
			raw:  "!AIBBM,26,2,1,3,8,1 1,0*75",
			err:  "nmea: AIBBM invalid payload: data byte",
		},
		{
			name: "Negative number of fill bits",
			raw:  "!AIBBM,26,2,1,3,8,177KQJ5000G?tO`K>RA1wUbN0TKH,-1*00",
			err:  "nmea: AIBBM invalid payload: fill bits",
		},
		{
			name: "Too high number of fill bits",
			raw:  "!AIBBM,26,2,1,3,8,177KQJ5000G?tO`K>RA1wUbN0TKH,20*1e",
			err:  "nmea: AIBBM invalid payload: fill bits",
		},
		{
			name: "Negative number of bits",
			raw:  "!AIBBM,26,2,1,3,8,,2*57",
			err:  "nmea: AIBBM invalid payload: num bits",
		},
	}
	for _, tt := range tests {
		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)
				bbm := m.(BBM)
				bbm.BaseSentence = BaseSentence{}
				assert.Equal(t, tt.msg, bbm)
			}
		})
	}
}