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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
package wifi
import (
"reflect"
"testing"
)
func TestInterfaceTypeString(t *testing.T) {
tests := []struct {
t InterfaceType
s string
}{
{
t: InterfaceTypeUnspecified,
s: "unspecified",
},
{
t: InterfaceTypeAdHoc,
s: "ad-hoc",
},
{
t: InterfaceTypeStation,
s: "station",
},
{
t: InterfaceTypeAP,
s: "access point",
},
{
t: InterfaceTypeWDS,
s: "wireless distribution",
},
{
t: InterfaceTypeMonitor,
s: "monitor",
},
{
t: InterfaceTypeMeshPoint,
s: "mesh point",
},
{
t: InterfaceTypeP2PClient,
s: "P2P client",
},
{
t: InterfaceTypeP2PGroupOwner,
s: "P2P group owner",
},
{
t: InterfaceTypeP2PDevice,
s: "P2P device",
},
{
t: InterfaceTypeOCB,
s: "outside context of BSS",
},
{
t: InterfaceTypeNAN,
s: "near-me area network",
},
{
t: InterfaceTypeNAN + 1,
s: "unknown(13)",
},
}
for _, tt := range tests {
t.Run(tt.s, func(t *testing.T) {
if want, got := tt.s, tt.t.String(); want != got {
t.Fatalf("unexpected interface type string:\n- want: %q\n- got: %q",
want, got)
}
})
}
}
func TestBSSStatusString(t *testing.T) {
tests := []struct {
t BSSStatus
s string
}{
{
t: BSSStatusAuthenticated,
s: "authenticated",
},
{
t: BSSStatusAssociated,
s: "associated",
},
{
t: BSSStatusIBSSJoined,
s: "IBSS joined",
},
{
t: 3,
s: "unknown(3)",
},
}
for _, tt := range tests {
t.Run(tt.s, func(t *testing.T) {
if want, got := tt.s, tt.t.String(); want != got {
t.Fatalf("unexpected BSS status string:\n- want: %q\n- got: %q",
want, got)
}
})
}
}
func Test_parseIEs(t *testing.T) {
tests := []struct {
name string
b []byte
ies []ie
err error
}{
{
name: "empty",
},
{
name: "too short",
b: []byte{0x00},
err: errInvalidIE,
},
{
name: "length too long",
b: []byte{0x00, 0xff, 0x00},
err: errInvalidIE,
},
{
name: "OK one",
b: []byte{0x00, 0x03, 'f', 'o', 'o'},
ies: []ie{{
ID: 0,
Data: []byte("foo"),
}},
},
{
name: "OK three",
b: []byte{
0x00, 0x03, 'f', 'o', 'o',
0x01, 0x00,
0x02, 0x06, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
},
ies: []ie{
{
ID: 0,
Data: []byte("foo"),
},
{
ID: 1,
Data: []byte{},
},
{
ID: 2,
Data: []byte{0x11, 0x22, 0x33, 0x44, 0x55, 0x66},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ies, err := parseIEs(tt.b)
if want, got := tt.err, err; want != got {
t.Fatalf("unexpected error:\n- want: %v\n- got: %v",
want, got)
}
if err != nil {
t.Logf("err: %v", err)
return
}
if want, got := tt.ies, ies; !reflect.DeepEqual(want, got) {
t.Fatalf("unexpected ies:\n- want: %v\n- got: %v",
want, got)
}
})
}
}
|