forked from electricbubble/gidevice
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
usbmux_test.go
67 lines (53 loc) · 1.15 KB
/
usbmux_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
package giDevice
import (
"github.com/SonicCloudOrg/sonic-gidevice/pkg/libimobiledevice"
"testing"
"time"
)
var um Usbmux
func setupUsbmux(t *testing.T) {
var err error
um, err = NewUsbmux()
if err != nil {
t.Fatal(err)
}
}
func Test_usbmux_Devices(t *testing.T) {
setupUsbmux(t)
devices, err := um.Devices()
if err != nil {
t.Fatal(err)
}
for _, dev := range devices {
t.Log(dev.Properties().SerialNumber, dev.Properties().ProductID, dev.Properties().DeviceID)
}
}
func Test_usbmux_ReadBUID(t *testing.T) {
setupUsbmux(t)
buid, err := um.ReadBUID()
if err != nil {
t.Fatal(err)
}
t.Log(buid)
}
func Test_usbmux_Listen(t *testing.T) {
setupUsbmux(t)
devNotifier := make(chan Device)
cancelFunc, err := um.Listen(devNotifier)
if err != nil {
t.Fatal(err)
}
go func() {
time.Sleep(20 * time.Second)
cancelFunc()
}()
for dev := range devNotifier {
if dev.Properties().ConnectionType != "" {
t.Log(dev.Properties().SerialNumber, dev.Properties().ProductID, dev.Properties().DeviceID)
} else {
t.Log(libimobiledevice.MessageTypeDeviceRemove, dev.Properties().DeviceID)
}
}
time.Sleep(5 * time.Second)
t.Log("Done")
}