Add a test for InEndpoint.Read. Use ID for vid/pid in OpenDevice...
This commit is contained in:
@@ -146,3 +146,34 @@ func TestEndpointInfo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEndpointIn(t *testing.T) {
|
||||
defer func(i libusbIntf) { libusb = i }(libusb)
|
||||
|
||||
lib := newFakeLibusb()
|
||||
libusb = lib
|
||||
|
||||
ctx := NewContext()
|
||||
d, err := ctx.OpenDeviceWithVidPid(0x9999, 0x0001)
|
||||
if err != nil {
|
||||
t.Fatalf("OpenDeviceWithVidPid(0x9999, 0x0001): got error %v, want nil", err)
|
||||
}
|
||||
ep, err := d.InEndpoint(1, 0, 0, 2)
|
||||
if err != nil {
|
||||
t.Fatalf("InEndpoint(1, 0, 0, 2): got error %v, want nil", err)
|
||||
}
|
||||
dataTransferred := 100
|
||||
go func() {
|
||||
fakeT := lib.waitForSubmitted()
|
||||
fakeT.length = dataTransferred
|
||||
fakeT.status = TransferCompleted
|
||||
close(fakeT.done)
|
||||
}()
|
||||
buf := make([]byte, 512)
|
||||
got, err := ep.Read(buf)
|
||||
if err != nil {
|
||||
t.Errorf("ep.Read: got error %v, want nil", err)
|
||||
} else if got != dataTransferred {
|
||||
t.Errorf("ep.Read: got %d, want %d", got, dataTransferred)
|
||||
}
|
||||
}
|
||||
|
@@ -82,7 +82,7 @@ func (c *Context) ListDevices(each func(desc *Descriptor) bool) ([]*Device, erro
|
||||
// If there were any errors during device list traversal, it is possible
|
||||
// it will return a non-nil device and non-nil error. A Device.Close() must
|
||||
// be called to release the device if the returned device wasn't nil.
|
||||
func (c *Context) OpenDeviceWithVidPid(vid, pid int) (*Device, error) {
|
||||
func (c *Context) OpenDeviceWithVidPid(vid, pid ID) (*Device, error) {
|
||||
var found bool
|
||||
devs, err := c.ListDevices(func(desc *Descriptor) bool {
|
||||
if found {
|
||||
|
@@ -60,7 +60,7 @@ func TestOpenDeviceWithVidPid(t *testing.T) {
|
||||
libusb = newFakeLibusb()
|
||||
|
||||
for _, d := range []struct {
|
||||
vid, pid int
|
||||
vid, pid ID
|
||||
exists bool
|
||||
}{
|
||||
{0x7777, 0x0003, false},
|
||||
|
Reference in New Issue
Block a user