-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathflags_test.go
133 lines (130 loc) · 2.97 KB
/
flags_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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package sspi
import (
"strconv"
"testing"
)
func Test_verifySelectiveFlags(t *testing.T) {
type args struct {
flags uint32
establishedFlags uint32
}
tests := []struct {
name string
args args
wantValid bool
wantMissing uint32
wantExtra uint32
}{
{
name: "all zeros",
args: args{
flags: binary("00000"),
establishedFlags: binary("00000"),
},
wantValid: true,
wantMissing: binary("00000"),
wantExtra: binary("00000"),
},
{
name: "all ones",
args: args{
flags: binary("11111"),
establishedFlags: binary("11111"),
},
wantValid: true,
wantMissing: binary("00000"),
wantExtra: binary("00000"),
},
{
name: "missing one bit",
args: args{
flags: binary("11111"),
establishedFlags: binary("11011"),
},
wantValid: false,
wantMissing: binary("00100"),
wantExtra: binary("00000"),
},
{
name: "missing two bits",
args: args{
flags: binary("11111"),
establishedFlags: binary("01011"),
},
wantValid: false,
wantMissing: binary("10100"),
wantExtra: binary("00000"),
},
{
name: "missing all bits",
args: args{
flags: binary("11101"),
establishedFlags: binary("00000"),
},
wantValid: false,
wantMissing: binary("11101"),
wantExtra: binary("00000"),
},
{
name: "one extra bit",
args: args{
flags: binary("00111"),
establishedFlags: binary("01111"),
},
wantValid: true,
wantMissing: binary("00000"),
wantExtra: binary("01000"),
},
{
name: "two extra bits",
args: args{
flags: binary("01000"),
establishedFlags: binary("11001"),
},
wantValid: true,
wantMissing: binary("00000"),
wantExtra: binary("10001"),
},
{
name: "all extra bits",
args: args{
flags: binary("00000"),
establishedFlags: binary("11111"),
},
wantValid: true,
wantMissing: binary("00000"),
wantExtra: binary("11111"),
},
{
name: "missing and extra bits",
args: args{
flags: binary("00101"),
establishedFlags: binary("11001"),
},
wantValid: false,
wantMissing: binary("00100"),
wantExtra: binary("11000"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotValid, gotMissing, gotExtra := verifySelectiveFlags(tt.args.flags, tt.args.establishedFlags)
if gotValid != tt.wantValid {
t.Errorf("verifySelectiveFlags() gotValid = %v, want %v", gotValid, tt.wantValid)
}
if gotMissing != tt.wantMissing {
t.Errorf("verifySelectiveFlags() gotMissing = %v, want %v", gotMissing, tt.wantMissing)
}
if gotExtra != tt.wantExtra {
t.Errorf("verifySelectiveFlags() gotExtra = %v, want %v", gotExtra, tt.wantExtra)
}
})
}
}
func binary(b string) uint32 {
n, err := strconv.ParseUint(b, 2, 32)
if err != nil {
panic(err) // programmer error due to invalid test data
}
return uint32(n)
}