This commit is contained in:
Kyle Lemons
2012-03-27 19:40:22 -07:00
parent 25c01a9f60
commit e5a0531ed2
7 changed files with 297 additions and 365 deletions

View File

@@ -18,9 +18,30 @@ func TestEnum(t *testing.T) {
defer c.Close()
c.Debug(0)
cnt := 0
devs, err := c.ListDevices(func(bus, addr int, desc *Descriptor) bool {
cnt++
logDevice := func(t *testing.T, desc *Descriptor) {
t.Logf("%03d.%03d %s", desc.Bus, desc.Address, usbid.Describe(desc))
t.Logf("- Protocol: %s", usbid.Classify(desc))
for _, cfg := range desc.Configs {
t.Logf("- %s:", cfg)
for _, alt := range cfg.Interfaces {
t.Logf(" --------------")
for _, iface := range alt {
t.Logf(" - %s", iface)
t.Logf(" - %s", usbid.Classify(iface))
for _, end := range iface.Endpoints {
t.Logf(" - %s (packet size: %d bytes)", end, end.MaxPacketSize)
}
}
}
t.Logf(" --------------")
}
}
descs := []*Descriptor{}
devs, err := c.ListDevices(func(desc *Descriptor) bool {
logDevice(t, desc)
descs = append(descs, desc)
return true
})
defer func() {
@@ -32,41 +53,13 @@ func TestEnum(t *testing.T) {
t.Fatalf("list: %s", err)
}
if got, want := len(devs), cnt; got != want {
t.Errorf("len(devs) = %d, want %d", got, want)
if got, want := len(devs), len(descs); got != want {
t.Fatalf("len(devs) = %d, want %d", got, want)
}
for _, dev := range devs {
desc, err := dev.Descriptor()
if err != nil {
t.Errorf("desc: %s", err)
continue
}
bus := dev.BusNumber()
addr := dev.Address()
t.Logf("%03d:%03d %s", bus, addr, usbid.Describe(desc))
t.Logf("- Protocol: %s", usbid.Classify(desc))
cfgs, err := dev.Configurations()
if err != nil {
t.Errorf(" - configs: %s", err)
continue
}
for _, cfg := range cfgs {
t.Logf("- %s:", cfg)
for _, alt := range cfg.Interfaces {
t.Logf(" --------------")
for _, iface := range alt {
t.Logf(" - %s", iface)
t.Logf(" - %s", usbid.Classify(iface))
for _, end := range iface.Endpoints {
t.Logf(" - %s", end)
}
}
}
t.Logf(" --------------")
for i := range devs {
if got, want := devs[i].Descriptor, descs[i]; got != want {
t.Errorf("dev[%d].Descriptor = %p, want %p", i, got, want)
}
}
}