tested for libusb-1.0.19 on windows (MinGw)

This commit is contained in:
nodtem66
2015-03-03 00:20:31 +07:00
parent ffbf8dd410
commit 897ea727f3
3 changed files with 69 additions and 17 deletions

View File

@@ -81,13 +81,53 @@ func TestEnum(t *testing.T) {
}
}
func TestOpenDeviceWithVidPid(t *testing.T) {
c := NewContext()
defer c.Close()
c.Debug(0)
// Accept for all device
devs, err := c.ListDevices(func(desc *Descriptor) bool {
return true
})
defer func() {
for _, d := range devs {
d.Close()
}
}()
if err != nil {
t.Fatalf("list: %s", err)
}
for i := range devs {
vid := devs[i].Vendor
pid := devs[i].Product
device, err := c.OpenDeviceWithVidPid((int)(vid), (int)(pid))
// if the context failed to open device
if err != nil {
t.Fail()
}
// if opened device was not valid
if device.Descriptor.Bus != devs[i].Bus ||
device.Descriptor.Address != devs[i].Address ||
device.Vendor != devs[i].Vendor ||
device.Product != devs[i].Product {
t.Fail()
}
}
}
func TestMultipleContexts(t *testing.T) {
var buf bytes.Buffer
log.SetOutput(&buf)
for i := 0; i < 2; i++ {
ctx := NewContext()
_, err := ctx.ListDevices(func(desc *Descriptor) bool {
return false
return true
})
if err != nil {
t.Fatal(err)