forked from paypal/gatt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adv_test.go
110 lines (103 loc) · 2.77 KB
/
adv_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
package gatt
import "testing"
// TODO:
func TestAppendField(t *testing.T) {}
// TODO:
func TestAppendFlags(t *testing.T) {}
func TestAppendName(t *testing.T) {
cases := []struct {
curr []byte
name string
wantBytes []byte
wantLen int
}{
{
curr: []byte{},
name: "ABCDE",
wantBytes: []byte{0x06, typeCompleteName, 'A', 'B', 'C', 'D', 'E'},
wantLen: 7,
},
{
curr: []byte("111111111122222222223333"),
name: "ABCDE",
wantBytes: append([]byte("111111111122222222223333"), []byte{0x06, typeCompleteName, 'A', 'B', 'C', 'D', 'E'}...),
wantLen: 31,
},
{
curr: []byte("1111111111222222222233333"),
name: "ABCDE",
wantBytes: append([]byte("1111111111222222222233333"), []byte{0x05, typeShortName, 'A', 'B', 'C', 'D'}...),
wantLen: 31,
},
}
for _, tt := range cases {
a := (&AdvPacket{tt.curr}).AppendName(tt.name)
wantBytes := [31]byte{}
copy(wantBytes[:], tt.wantBytes)
if a.Bytes() != wantBytes {
t.Errorf("%q a.AppendName(%q) got %x want %x", tt.curr, tt.name, a.Bytes(), tt.wantBytes)
}
if a.Len() != tt.wantLen {
t.Errorf("%q a.AppendName(%q) got %d want %d", tt.curr, tt.name, a.Len(), tt.wantLen)
}
}
}
// TODO:
func TestAppendManufacturerData(t *testing.T) {}
// TODO:
func TestAppendUUIDFit(t *testing.T) {
cases := []struct {
uu []UUID
want string
fit []UUID // if different than uu
}{
{
uu: []UUID{UUID16(0xFAFE)},
want: "0201060302fefa",
},
{
uu: []UUID{UUID16(0xFAFE), UUID16(0xFAF9)},
want: "0201060302fefa0302f9fa",
},
{
uu: []UUID{MustParseUUID("ABABABABABABABABABABABABABABABAB")},
want: "0201061106abababababababababababababababab",
},
{
uu: []UUID{
MustParseUUID("ABABABABABABABABABABABABABABABAB"),
MustParseUUID("CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD"),
},
want: "0201061106abababababababababababababababab",
fit: []UUID{MustParseUUID("ABABABABABABABABABABABABABABABAB")},
},
{
uu: []UUID{
UUID16(0xaaaa), UUID16(0xbbbb),
UUID16(0xcccc), UUID16(0xdddd),
UUID16(0xeeee), UUID16(0xffff),
UUID16(0xaaaa), UUID16(0xbbbb),
},
want: "0201060302aaaa0302bbbb0302cccc0302dddd0302eeee0302ffff0302aaaa",
fit: []UUID{
UUID16(0xaaaa), UUID16(0xbbbb),
UUID16(0xcccc), UUID16(0xdddd),
UUID16(0xeeee), UUID16(0xffff),
UUID16(0xaaaa),
},
},
}
_ = cases
// for _, tt := range cases {
// pack, fit := serviceAdvertisingPacket(tt.uu)
// if got := fmt.Sprintf("%x", pack); got != tt.want {
// t.Errorf("serviceAdvertisingPacket(%x) packet: got %q want %q", tt.uu, got, tt.want)
// }
// if tt.fit == nil {
// tt.fit = tt.uu
// }
// if !reflect.DeepEqual(fit, tt.fit) {
// t.Errorf("serviceAdvertisingPacket(%x) fit: got %x want %x", tt.uu, fit, tt.fit)
// }
// }
}