89 lines
1.7 KiB
Go
89 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestPlateMessage(t *testing.T) {
|
|
data := []byte{0x20, 0x04, 0x55, 0x4e, 0x31, 0x58, 0x00, 0x00, 0x03, 0xe8}
|
|
p, err := decodePlateMessage(data)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if p.plate != "UN1X" {
|
|
t.Error("plate wrong")
|
|
}
|
|
if p.timestamp != time.Unix(0x000003e8, 0) {
|
|
t.Error("timestamp wrong")
|
|
}
|
|
}
|
|
|
|
func TestWantHeartbeatMessage(t *testing.T) {
|
|
data := []byte{0x40, 0x00, 0x00, 0x00, 0x0a}
|
|
h, err := decodeWantHeartbeatMessage(data)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if *h != wantHeartbeatMessage(10) {
|
|
t.Error("Wrong duration")
|
|
}
|
|
}
|
|
|
|
func TestAmCameraMessage(t *testing.T) {
|
|
data := []byte{0x80, 0x00, 0x42, 0x00, 0x64, 0x00, 0x3c}
|
|
m, err := decodeAmCameraMessage(data)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if m.road != 66 {
|
|
t.Error("wrong road")
|
|
}
|
|
if m.mile != 100 {
|
|
t.Error("wrong mile")
|
|
}
|
|
if m.limit != 60 {
|
|
t.Error("wrong limit")
|
|
}
|
|
}
|
|
|
|
func TestAmDispatcherMessage(t *testing.T) {
|
|
data := []byte{0x81, 0x01, 0x00, 0x42}
|
|
m, err := decodeAmDispatcherMessage(data)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if m.numroads != 1 {
|
|
t.Error("wrong numroads")
|
|
}
|
|
if len(m.roads) != 1 {
|
|
t.Error("wrong length of roads")
|
|
}
|
|
if m.roads[0] != 66 {
|
|
t.Error("wrong roads[0]")
|
|
}
|
|
}
|
|
|
|
func TestAmDispatcherMessageLong(t *testing.T) {
|
|
data := []byte{0x81, 0x03, 0x00, 0x42, 0x01, 0x70, 0x13, 0x88}
|
|
m, err := decodeAmDispatcherMessage(data)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if m.numroads != 3 {
|
|
t.Error("wrong numroads")
|
|
}
|
|
if len(m.roads) != 3 {
|
|
t.Error("wrong length of roads")
|
|
}
|
|
if m.roads[0] != 66 {
|
|
t.Error("wrong roads[0]")
|
|
}
|
|
if m.roads[1] != 368 {
|
|
t.Error("wrong roads[0]")
|
|
}
|
|
if m.roads[2] != 5000 {
|
|
t.Error("wrong roads[0]")
|
|
}
|
|
}
|