Simple app to transform IEC 61851-24 CAN bus dump to human readable messages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chademo-log/files_test.go

46 lines
991 B

package main
import (
"reflect"
"testing"
"time"
)
func TestFromString(t *testing.T) {
type args struct {
text *string
}
var dump = "(2022-07-08 16:54:15.587099) can0 100 [8] 00 00 00 00 00 00 64 00"
var timestamp = time.Date(2022, 07, 8, 16, 54, 15, 587099, time.Local) //"2022-07-08 16:54:15.587099"
tests := []struct {
name string
args args
want *CanFrame
}{
// TODO: Add test cases.
{
name: "Candump parsing test",
args: args{text: &dump},
want: &CanFrame{
canid: CAN_ID_100,
date: &timestamp,
payload: &[]uint8{0, 0, 0, 0, 0, 0, 0x64, 0},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var got = fromString(tt.args.text)
var isDate = got.date.Compare(*tt.want.date) == 0
var isPayload = reflect.DeepEqual(*got.payload, *tt.want.payload)
var isId = got.canid == tt.want.canid
if isDate && isPayload && isId {
t.Errorf("fromString() = %v, want %v", got, tt.want)
}
})
}
}