forked from quickfixgo/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 4
/
fix_utc_timestamp_test.go
63 lines (52 loc) · 1.75 KB
/
fix_utc_timestamp_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
package quickfix_test
import (
"bytes"
"testing"
"time"
"github.com/alpacahq/quickfix"
)
func TestFIXUTCTimestampWrite(t *testing.T) {
ts := time.Date(2016, time.February, 8, 22, 7, 16, 954123123, time.UTC)
var tests = []struct {
precision quickfix.TimestampPrecision
val []byte
}{
{quickfix.Millis, []byte("20160208-22:07:16.954")},
{quickfix.Seconds, []byte("20160208-22:07:16")},
{quickfix.Micros, []byte("20160208-22:07:16.954123")},
{quickfix.Nanos, []byte("20160208-22:07:16.954123123")},
}
for _, test := range tests {
var f quickfix.FIXUTCTimestamp
f.Time = ts
f.Precision = test.precision
b := f.Write()
if !bytes.Equal(b, test.val) {
t.Errorf("got %s; want %s", b, test.val)
}
}
}
func TestFIXUTCTimestampRead(t *testing.T) {
var tests = []struct {
timeStr string
expectedTime time.Time
expectedPrecision quickfix.TimestampPrecision
}{
{"20160208-22:07:16.310", time.Date(2016, time.February, 8, 22, 7, 16, 310000000, time.UTC), quickfix.Millis},
{"20160208-22:07:16", time.Date(2016, time.February, 8, 22, 7, 16, 0, time.UTC), quickfix.Seconds},
{"20160208-22:07:16.123455", time.Date(2016, time.February, 8, 22, 7, 16, 123455000, time.UTC), quickfix.Micros},
{"20160208-22:07:16.954123123", time.Date(2016, time.February, 8, 22, 7, 16, 954123123, time.UTC), quickfix.Nanos},
}
for _, test := range tests {
var f quickfix.FIXUTCTimestamp
if err := f.Read([]byte(test.timeStr)); err != nil {
t.Errorf("Unexpected error: %v", err)
}
if !f.Time.Equal(test.expectedTime) {
t.Errorf("For Time expected %v got %v", test.expectedTime, f.Time)
}
if f.Precision != test.expectedPrecision {
t.Errorf("For NoMillis expected %v got %v", test.expectedPrecision, f.Precision)
}
}
}