-
Notifications
You must be signed in to change notification settings - Fork 19
/
decode_fail_test.go
46 lines (32 loc) · 1.53 KB
/
decode_fail_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
package ais
import "testing"
func TestDecodeFailMsgIDTooShort(t *testing.T) {
x := CodecNew(false, false)
data := []byte{0, 1, 0, 1}
if x.DecodePacket(data) != nil {
t.Error("Could decode 4-bit packet")
}
}
func TestDecodeStrictAlignment(t *testing.T) {
data := []byte{0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0}
x := CodecNew(false, false)
x.StrictByteAlignment = true
if x.DecodePacket(data) == nil {
t.Error("Failed to decode valid packet")
}
data = append(data, 0)
if x.DecodePacket(data) != nil {
t.Error("Could decode packet with invalid padding")
}
}
func TestDecodeDependentBitNotReceived(t *testing.T) {
data := []byte{0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 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}
x := CodecNew(false, false)
if x.DecodePacket(data) == nil {
t.Error("Failed to decode valid packet")
}
data = data[:139]
if x.DecodePacket(data) != nil {
t.Error("Decoded packet although IsAddressed was not received")
}
}