Debian Codegraph @

adv_test.go

raw symbols SCIP
1 package gatt
2
3 import "testing"
4
5 // TODO:
6 func TestAppendField(t *testing.T) {}
7
8 // TODO:
9 func TestAppendFlags(t *testing.T) {}
10
11 func TestAppendName(t *testing.T) {
12 cases := []struct {
13 curr []byte
14 name string
15 wantBytes []byte
16 wantLen int
17 }{
18 {
19 curr: []byte{},
20 name: "ABCDE",
21 wantBytes: []byte{0x06, typeCompleteName, 'A', 'B', 'C', 'D', 'E'},
22 wantLen: 7,
23 },
24 {
25 curr: []byte("111111111122222222223333"),
26 name: "ABCDE",
27 wantBytes: append([]byte("111111111122222222223333"), []byte{0x06, typeCompleteName, 'A', 'B', 'C', 'D', 'E'}...),
28 wantLen: 31,
29 },
30 {
31 curr: []byte("1111111111222222222233333"),
32 name: "ABCDE",
33 wantBytes: append([]byte("1111111111222222222233333"), []byte{0x05, typeShortName, 'A', 'B', 'C', 'D'}...),
34 wantLen: 31,
35 },
36 }
37 for _, tt := range cases {
38 a := (&AdvPacket{tt.curr}).AppendName(tt.name)
39 wantBytes := [31]byte{}
40 copy(wantBytes[:], tt.wantBytes)
41 if a.Bytes() != wantBytes {
42 t.Errorf("%q a.AppendName(%q) got %x want %x", tt.curr, tt.name, a.Bytes(), tt.wantBytes)
43 }
44 if a.Len() != tt.wantLen {
45 t.Errorf("%q a.AppendName(%q) got %d want %d", tt.curr, tt.name, a.Len(), tt.wantLen)
46 }
47 }
48 }
49
50 // TODO:
51 func TestAppendManufacturerData(t *testing.T) {}
52
53 // TODO:
54 func TestAppendUUIDFit(t *testing.T) {
55 cases := []struct {
56 uu []UUID
57 want string
58 fit []UUID // if different than uu
59 }{
60 {
61 uu: []UUID{UUID16(0xFAFE)},
62 want: "0201060302fefa",
63 },
64 {
65 uu: []UUID{UUID16(0xFAFE), UUID16(0xFAF9)},
66 want: "0201060302fefa0302f9fa",
67 },
68 {
69 uu: []UUID{MustParseUUID("ABABABABABABABABABABABABABABABAB")},
70 want: "0201061106abababababababababababababababab",
71 },
72 {
73 uu: []UUID{
74 MustParseUUID("ABABABABABABABABABABABABABABABAB"),
75 MustParseUUID("CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD"),
76 },
77 want: "0201061106abababababababababababababababab",
78 fit: []UUID{MustParseUUID("ABABABABABABABABABABABABABABABAB")},
79 },
80 {
81 uu: []UUID{
82 UUID16(0xaaaa), UUID16(0xbbbb),
83 UUID16(0xcccc), UUID16(0xdddd),
84 UUID16(0xeeee), UUID16(0xffff),
85 UUID16(0xaaaa), UUID16(0xbbbb),
86 },
87 want: "0201060302aaaa0302bbbb0302cccc0302dddd0302eeee0302ffff0302aaaa",
88 fit: []UUID{
89 UUID16(0xaaaa), UUID16(0xbbbb),
90 UUID16(0xcccc), UUID16(0xdddd),
91 UUID16(0xeeee), UUID16(0xffff),
92 UUID16(0xaaaa),
93 },
94 },
95 }
96
97 _ = cases
98 // for _, tt := range cases {
99 // pack, fit := serviceAdvertisingPacket(tt.uu)
100 // if got := fmt.Sprintf("%x", pack); got != tt.want {
101 // t.Errorf("serviceAdvertisingPacket(%x) packet: got %q want %q", tt.uu, got, tt.want)
102 // }
103 // if tt.fit == nil {
104 // tt.fit = tt.uu
105 // }
106 // if !reflect.DeepEqual(fit, tt.fit) {
107 // t.Errorf("serviceAdvertisingPacket(%x) fit: got %x want %x", tt.uu, fit, tt.fit)
108 // }
109 // }
110 }