From 389ae4e2b3e83fa4b4cecbaf90eea567e4c69e3a Mon Sep 17 00:00:00 2001 From: Sebastian Zagrodzki Date: Fri, 10 Mar 2017 08:48:21 -0500 Subject: [PATCH] EndpointInfo tests --- usb/config.go | 2 +- usb/config_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 usb/config_test.go diff --git a/usb/config.go b/usb/config.go index 3205ee4..f967595 100644 --- a/usb/config.go +++ b/usb/config.go @@ -42,7 +42,7 @@ func (e EndpointInfo) Direction() EndpointDirection { } func (e EndpointInfo) String() string { - return fmt.Sprintf("Endpoint %d %-3s %s - %s %s [%d %d]", + return fmt.Sprintf("Endpoint #%d %-3s %s - %s %s [%d %d]", e.Number(), e.Direction(), e.TransferType(), IsoSyncType(e.Attributes)&ISO_SYNC_TYPE_MASK, IsoUsageType(e.Attributes)&ISO_USAGE_TYPE_MASK, diff --git a/usb/config_test.go b/usb/config_test.go new file mode 100644 index 0000000..f4cbbcf --- /dev/null +++ b/usb/config_test.go @@ -0,0 +1,32 @@ +package usb + +import "testing" + +func TestEndpointInfo(t *testing.T) { + for _, tc := range []struct { + ep EndpointInfo + want string + }{ + { + ep: EndpointInfo{ + Address: 0x86, + Attributes: 0x02, + MaxPacketSize: 512, + }, + want: "Endpoint #6 IN bulk - unsynchronized data [512 0]", + }, + { + ep: EndpointInfo{ + Address: 0x02, + Attributes: 0x05, + MaxPacketSize: 512, + MaxIsoPacket: 512, + }, + want: "Endpoint #2 OUT isochronous - asynchronous data [512 512]", + }, + } { + if got := tc.ep.String(); got != tc.want { + t.Errorf("%#v.String(): got %q, want %q", tc.ep, got, tc.want) + } + } +}