forked from parsiya/golnk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaderutils_test.go
More file actions
executable file
·100 lines (97 loc) · 2.85 KB
/
headerutils_test.go
File metadata and controls
executable file
·100 lines (97 loc) · 2.85 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package lnk
import (
"testing"
"time"
)
func TestHotKey(t *testing.T) {
type args struct {
hotkey uint16
}
tests := []struct {
name string
args args
want string
}{
{"shift+0", args{uint16(0x0130)}, "SHIFT+0"},
{"shift+Z", args{uint16(0x015A)}, "SHIFT+Z"},
{"invalid-low", args{uint16(0x0101)}, "No Key Assigned"},
{"invalid-low", args{uint16(0x0001)}, "No Key Assigned"},
{"invalid-high", args{uint16(0x0035)}, "No Key Assigned"},
{"invalid-high", args{uint16(0x0535)}, "No Key Assigned"},
{"alt+F12", args{uint16(0x047B)}, "ALT+F12"},
{"ctrl+F12", args{uint16(0x027B)}, "CTRL+F12"},
{"invalid-low-between", args{uint16(0x025B)}, "No Key Assigned"},
{"invalid-low-between", args{uint16(0x0269)}, "No Key Assigned"},
{"invalid-low-over", args{uint16(0x0269)}, "No Key Assigned"},
{"alt+numlock", args{uint16(0x0490)}, "ALT+NUM LOCK"},
{"shift+scrolllock", args{uint16(0x0191)}, "SHIFT+SCROLL LOCK"},
{"invalid-low-over", args{uint16(0x01FF)}, "No Key Assigned"},
{"invalid-both-over", args{uint16(0x10FF)}, "No Key Assigned"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := HotKey(tt.args.hotkey); got != tt.want {
t.Errorf("HotKey() = %v, want %v", got, tt.want)
}
})
}
}
func Test_toTime(t *testing.T) {
type args struct {
ft [8]byte // filetime as read from disk
}
tests := []struct {
name string
args args
want time.Time
}{
{
name: "zero-time",
args: args{ft: [8]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}},
want: time.Time{},
},
{
name: "unix-epoch",
args: args{ft: [8]byte{0x00, 0x80, 0x3E, 0xD5, 0xDE, 0xB1, 0x9D, 0x01}},
want: time.Unix(0, 0),
},
{
name: "year-2000",
args: args{ft: [8]byte{0x00, 0xB0, 0x07, 0x70, 0x1D, 0x54, 0xBF, 0x01}},
want: time.Date(2000, 1, 1, 0, 0, 0, 0, time.Local),
},
{
name: "year-2023",
args: args{ft: [8]byte{0x00, 0x70, 0x5D, 0x48, 0xA6, 0x1D, 0xD9, 0x01}},
want: time.Date(2023, 1, 1, 0, 0, 0, 0, time.Local),
},
{
name: "with-time-components",
args: args{ft: [8]byte{0x80, 0xF8, 0x46, 0x29, 0x0F, 0x1E, 0xD9, 0x01}},
want: time.Date(2023, 1, 1, 12, 30, 45, 0, time.Local),
},
{
name: "with-microseconds",
args: args{ft: [8]byte{0x40, 0xB2, 0x33, 0xA6, 0xF1, 0x4C, 0xA3, 0x01}},
want: time.Date(1975, 1, 1, 0, 0, 0, 100000000, time.Local),
},
{
name: "leap-year-feb29",
args: args{ft: [8]byte{0x00, 0xF0, 0x66, 0x36, 0x7A, 0x82, 0xBF, 0x01}},
want: time.Date(2000, 2, 29, 0, 0, 0, 0, time.Local),
},
{
name: "end-of-day",
args: args{ft: [8]byte{0xC0, 0x2D, 0x62, 0x9A, 0xE6, 0x54, 0xBF, 0x01}},
want: time.Date(2000, 1, 1, 23, 59, 59, 900000000, time.Local),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := toTime(tt.args.ft)
if got != tt.want {
t.Errorf("%s: toTime() = %v, want %v", tt.name, got, tt.want)
}
})
}
}