1#!perl -T 2 3use lib "t"; 4use TestTools; 5use Test::More tests => 8; 6use Device::USB; 7use strict; 8use warnings; 9 10my $usb = Device::USB->new(); 11 12ok( defined $usb, "Object successfully created" ); 13can_ok( $usb, "find_device" ); 14 15ok( !defined $usb->find_device( 0xFFFF, 0xFFFF ), "No device found" ); 16 17my $busses = $usb->list_busses(); 18ok( defined $busses, "USB busses found" ); 19 20my $found_device = TestTools::find_an_installed_device( 0, @{$busses} ); 21 22SKIP: 23{ 24 skip "No USB devices installed", 4 unless defined $found_device; 25 26 my $vendor = $found_device->idVendor(); 27 my $product = $found_device->idProduct(); 28 29 my $dev = $usb->find_device( $vendor, $product ); 30 31 ok( defined $dev, "Device found." ); 32 is_deeply( $dev, $found_device, "first device matches" ); 33 34 my $count = @{$busses}; 35 skip "Only one USB device installed", 2 if $count < 2; 36 37 $found_device = undef; 38 for(my $i = 1; $i < $count; ++$i) 39 { 40 my $dev = TestTools::find_an_installed_device( $i, @{$busses} ); 41 next unless defined $dev; 42 43 # New vendor/product combination 44 if($vendor != $dev->idVendor() || $product != $dev->idProduct()) 45 { 46 $found_device = $dev; 47 last; 48 } 49 } 50 51 skip "No accessible device found", 2 unless defined $found_device; 52 $vendor = $found_device->idVendor(); 53 $product = $found_device->idProduct(); 54 55 $dev = $usb->find_device( $vendor, $product ); 56 57 ok( defined $dev, "Device found." ); 58 is_deeply( $dev, $found_device, "second device matches" ); 59} 60 61