forked from jdgordon/go-nmea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fir_test.go
71 lines (69 loc) · 1.84 KB
/
fir_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
package nmea
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestFIR(t *testing.T) {
var tests = []struct {
name string
raw string
err string
msg FIR
}{
{
name: "good sentence",
raw: "$FRFIR,E,103000,FD,PT,000,007,A,V,Fire Alarm : TEST PT7 Name TEST DZ2 Name*7A",
msg: FIR{
Type: TypeEventOrAlarmFIR,
Time: Time{
Valid: true,
Hour: 10,
Minute: 30,
Second: 0,
Millisecond: 0,
},
SystemIndicator: "FD",
DivisionIndicator1: "PT",
DivisionIndicator2: 0,
FireDetectorNumberOrCount: 7,
Condition: ConditionActivationFIR,
AlarmAckState: AlarmStateNotAcknowledgedFIR,
Message: "Fire Alarm : TEST PT7 Name TEST DZ2 Name",
},
},
{
name: "invalid nmea: Type",
raw: "$FRFIR,x,103000,FD,PT,000,007,A,V,Fire Alarm : TEST PT7 Name TEST DZ2 Name*47",
err: "nmea: FRFIR invalid message type: x",
},
{
name: "invalid nmea: Time",
raw: "$FRFIR,E,1x3000,FD,PT,000,007,A,V,Fire Alarm : TEST PT7 Name TEST DZ2 Name*32",
err: "nmea: FRFIR invalid time: 1x3000",
},
{
name: "invalid nmea: Condition",
raw: "$FRFIR,E,103000,FD,PT,000,007,_,V,Fire Alarm : TEST PT7 Name TEST DZ2 Name*64",
err: "nmea: FRFIR invalid condition: _",
},
{
name: "invalid nmea: AlarmAckState",
raw: "$FRFIR,E,103000,FD,PT,000,007,A,_,Fire Alarm : TEST PT7 Name TEST DZ2 Name*73",
err: "nmea: FRFIR invalid alarm acknowledgement state: _",
},
}
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)
fir := m.(FIR)
fir.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, fir)
}
})
}
}