started adding fakelibusb functions for testing device.go

This commit is contained in:
Sebastian Zagrodzki
2017-03-06 11:38:03 +01:00
parent 810a98e9fa
commit 0099228bc3
2 changed files with 64 additions and 40 deletions

View File

@@ -82,46 +82,6 @@ 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)