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.
59 lines
1.3 KiB
59 lines
1.3 KiB
package can
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
frame_hr = "(2022-07-08 16:54:15.587099) can0 100 [8] 00 00 00 00 00 00 64 00"
|
|
frame_m = "(1670578900.771868) can0 00004021#00000000FCFFFFFF"
|
|
)
|
|
|
|
func Test_fromString(t *testing.T) {
|
|
var time_m, err1 = time.ParseInLocation("2006-01-02T15:04:05.000000", "2022-12-09T09:41:40.771868", time.Local)
|
|
var time_p, err2 = time.ParseInLocation("2006-01-02 15:04:05.000000", "2022-07-08 16:54:15.587099", time.Local)
|
|
|
|
if err1 != nil || err2 != nil {
|
|
t.Error()
|
|
}
|
|
|
|
//time_m = time_m.In(time.Local)
|
|
//time_p = time_p.In(time.Local)
|
|
|
|
type args struct {
|
|
text string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want *CanFrame
|
|
}{
|
|
{
|
|
name: "Machine readable time",
|
|
args: args{text: frame_m},
|
|
want: &CanFrame{
|
|
Date: &time_m,
|
|
CanId: 0x4021,
|
|
Payload: &[]uint8{00, 00, 00, 00, 0xFC, 0xFF, 0xFF, 0xFF},
|
|
},
|
|
},
|
|
{
|
|
name: "Human readable time",
|
|
args: args{text: frame_hr},
|
|
want: &CanFrame{
|
|
Date: &time_p,
|
|
CanId: 0x100,
|
|
Payload: &[]uint8{00, 00, 00, 00, 00, 00, 0x64, 00},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := fromString(tt.args.text); !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("fromString() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|