Permalink
Browse files

Add tests for using Interface instances instead of Fixnums

  • Loading branch information...
1 parent 9ee5cd6 commit 2754d7aecd10fe03d3ae4aee31191fd71b4e8c61 @larskanis committed Sep 28, 2012
Showing with 8 additions and 4 deletions.
  1. +8 −4 test/test_libusb_mass_storage2.rb
@@ -22,17 +22,21 @@ class TestLibusbMassStorage2 < Test::Unit::TestCase
attr_accessor :usb
attr_accessor :device
+ attr_accessor :interface
def setup
@usb = Context.new
@usb.debug = 3
@device = usb.devices( :bClass=>CLASS_MASS_STORAGE, :bSubClass=>[0x06,0x01], :bProtocol=>0x50 ).last
abort "no mass storage device found" unless @device
+ @interface = device.interfaces.first
+
# Ensure kernel driver is detached
device.open do |dev|
- if RUBY_PLATFORM=~/linux/i && dev.kernel_driver_active?(0)
- dev.detach_kernel_driver(0)
+ if RUBY_PLATFORM=~/linux/i && dev.kernel_driver_active?(interface)
+ assert dev.kernel_driver_active?(0), "DevHandle#kernel_driver_active? may be called with an Interface instance or a Fixnum"
+ dev.detach_kernel_driver(interface)
end
end
end
@@ -49,7 +53,7 @@ def test_open_with_block
def test_claim_interface_with_block
res = device.open do |dev|
- dev.claim_interface(0) do |dev2|
+ dev.claim_interface(interface) do |dev2|
assert_kind_of DevHandle, dev2
assert_kind_of String, dev2.string_descriptor_ascii(1)
12345
@@ -59,7 +63,7 @@ def test_claim_interface_with_block
end
def test_open_interface
- res = device.open_interface(0) do |dev|
+ res = device.open_interface(interface) do |dev|
assert_kind_of DevHandle, dev
assert_kind_of String, dev.string_descriptor_ascii(1)
12345

0 comments on commit 2754d7a

Please sign in to comment.