Modify the test for device list, drop noop/multiple contexts.
This commit is contained in:
@@ -13,52 +13,26 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package usb_test
|
||||
package usb
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
. "github.com/kylelemons/gousb/usb"
|
||||
"github.com/kylelemons/gousb/usbid"
|
||||
)
|
||||
|
||||
func TestNoop(t *testing.T) {
|
||||
func TestListDevices(t *testing.T) {
|
||||
orig := libusb
|
||||
defer func() { libusb = orig }()
|
||||
libusb = newFakeLibusb()
|
||||
|
||||
c := NewContext()
|
||||
defer c.Close()
|
||||
c.Debug(0)
|
||||
}
|
||||
|
||||
func TestEnum(t *testing.T) {
|
||||
c := NewContext()
|
||||
defer c.Close()
|
||||
c.Debug(0)
|
||||
|
||||
logDevice := func(t *testing.T, desc *Descriptor) {
|
||||
t.Logf("%03d.%03d %s", desc.Bus, desc.Address, usbid.Describe(desc))
|
||||
t.Logf("- Protocol: %s", usbid.Classify(desc))
|
||||
|
||||
for _, cfg := range desc.Configs {
|
||||
t.Logf("- %s:", cfg)
|
||||
for _, alt := range cfg.Interfaces {
|
||||
t.Logf(" --------------")
|
||||
for _, iface := range alt.Setups {
|
||||
t.Logf(" - %s", iface)
|
||||
t.Logf(" - %s", usbid.Classify(iface))
|
||||
for _, end := range iface.Endpoints {
|
||||
t.Logf(" - %s (packet size: %d bytes)", end, end.MaxPacketSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Logf(" --------------")
|
||||
}
|
||||
}
|
||||
|
||||
descs := []*Descriptor{}
|
||||
devs, err := c.ListDevices(func(desc *Descriptor) bool {
|
||||
logDevice(t, desc)
|
||||
descs = append(descs, desc)
|
||||
return true
|
||||
})
|
||||
@@ -68,11 +42,14 @@ func TestEnum(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
if err != nil {
|
||||
t.Fatalf("list: %s", err)
|
||||
t.Fatalf("ListDevices(): %s", err)
|
||||
}
|
||||
|
||||
if got, want := len(devs), len(fakeDevices); got != want {
|
||||
t.Fatalf("len(devs) = %d, want %d (based on num fake devs)", got, want)
|
||||
}
|
||||
if got, want := len(devs), len(descs); got != want {
|
||||
t.Fatalf("len(devs) = %d, want %d", got, want)
|
||||
t.Fatalf("len(devs) = %d, want %d (based on num opened devices)", got, want)
|
||||
}
|
||||
|
||||
for i := range devs {
|
||||
@@ -81,22 +58,3 @@ func TestEnum(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ctx.Close()
|
||||
}
|
||||
log.SetOutput(os.Stderr)
|
||||
if buf.Len() > 0 {
|
||||
t.Errorf("Non zero output to log, while testing: %s", buf.String())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user