newEndpoint no longer references *Device, but receives individual values
extracted from the device. Makes testing easier.
This commit is contained in:
@@ -141,7 +141,7 @@ func (d *Device) OpenEndpoint(cfgNum, ifNum, setNum, epNum uint8) (Endpoint, err
|
|||||||
return nil, fmt.Errorf("usb: unknown endpoint %02x", epNum)
|
return nil, fmt.Errorf("usb: unknown endpoint %02x", epNum)
|
||||||
}
|
}
|
||||||
|
|
||||||
end := newEndpoint(d, *ifs, *ep)
|
end := newEndpoint(d.handle, *ifs, *ep, d.ReadTimeout, d.WriteTimeout)
|
||||||
|
|
||||||
// Set the configuration
|
// Set the configuration
|
||||||
activeConf, err := libusb.getConfig(d.handle)
|
activeConf, err := libusb.getConfig(d.handle)
|
||||||
|
@@ -78,12 +78,12 @@ func (e *endpoint) transfer(buf []byte, timeout time.Duration) (int, error) {
|
|||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEndpoint(d *Device, s InterfaceSetup, e EndpointInfo) *endpoint {
|
func newEndpoint(h *libusbDevHandle, s InterfaceSetup, e EndpointInfo, rt, wt time.Duration) *endpoint {
|
||||||
return &endpoint{
|
return &endpoint{
|
||||||
InterfaceSetup: s,
|
InterfaceSetup: s,
|
||||||
EndpointInfo: e,
|
EndpointInfo: e,
|
||||||
h: d.handle,
|
h: h,
|
||||||
readTimeout: d.ReadTimeout,
|
readTimeout: rt,
|
||||||
writeTimeout: d.WriteTimeout,
|
writeTimeout: wt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,6 +17,7 @@ package usb
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestEndpoint(t *testing.T) {
|
func TestEndpoint(t *testing.T) {
|
||||||
@@ -61,10 +62,7 @@ func TestEndpoint(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
lib := newFakeLibusb()
|
lib := newFakeLibusb()
|
||||||
libusb = lib
|
libusb = lib
|
||||||
ep := &endpoint{
|
ep := newEndpoint(nil, epCfg.InterfaceSetup, epCfg.EndpointInfo, time.Second, time.Second)
|
||||||
InterfaceSetup: epCfg.InterfaceSetup,
|
|
||||||
EndpointInfo: epCfg.EndpointInfo,
|
|
||||||
}
|
|
||||||
op, ok := reflect.TypeOf(ep).MethodByName(epCfg.method)
|
op, ok := reflect.TypeOf(ep).MethodByName(epCfg.method)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("method %s not found in endpoint struct", epCfg.method)
|
t.Fatalf("method %s not found in endpoint struct", epCfg.method)
|
||||||
|
Reference in New Issue
Block a user