libusb 0.6.4-x64-mingw32 → 0.7.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,4 +38,51 @@ class TestLibusbContext < Minitest::Test
38
38
  @c.debug = 4
39
39
  @c.debug = 0
40
40
  end
41
+
42
+ def test_left_references
43
+ @test_devs = @c.devices
44
+ assert_raises(LIBUSB::RemainingReferencesError) do
45
+ @c.exit
46
+ end
47
+ @c = nil
48
+ end
49
+
50
+ def test_double_exit
51
+ @c.exit
52
+ end
53
+
54
+ def test_log_callback
55
+ skip "only supported on Linux" unless RUBY_PLATFORM=~/linux/
56
+ skip "libusb version older than 1.0.27" if Gem::Version.new(LIBUSB.version) < Gem::Version.new("1.0.27")
57
+
58
+ LIBUSB.set_options OPTION_LOG_CB: [nil], OPTION_LOG_LEVEL: LIBUSB::LOG_LEVEL_NONE
59
+ begin
60
+ called = Hash.new { |h, k| h[k] = [] }
61
+ LIBUSB.set_options OPTION_LOG_CB: proc{|*a| called[:global] << a }, OPTION_LOG_LEVEL: LIBUSB::LOG_LEVEL_DEBUG
62
+
63
+ c = LIBUSB::Context.new OPTION_LOG_CB: proc{|*a| called[:ctx1] << a }, OPTION_NO_DEVICE_DISCOVERY: nil
64
+ c.devices
65
+ c.set_log_cb(LIBUSB::LOG_CB_CONTEXT){|*a| called[:ctx2] << a }
66
+ c.devices
67
+
68
+ #pp called
69
+ assert_nil called[:global][0][0]
70
+ assert_equal :LOG_LEVEL_DEBUG, called[:global][0][1], called[:global][0][2]
71
+ assert_match(/libusb_init_context/, called[:global].join)
72
+ assert_match(/no device discovery/, called[:global].join)
73
+
74
+ assert_operator called[:ctx1].size, :>, called[:ctx2].size
75
+ assert_equal c, called[:ctx1][-1][0]
76
+ assert_equal :LOG_LEVEL_DEBUG, called[:ctx1][-1][1]
77
+ assert_match(/libusb_get_device_list/, called[:ctx1][-1][2])
78
+ assert_match(/no device discovery/, called[:ctx1].join)
79
+
80
+ assert_equal c, called[:ctx2][-1][0]
81
+ assert_equal :LOG_LEVEL_DEBUG, called[:ctx2][-1][1]
82
+ assert_match(/libusb_get_device_list/, called[:ctx2][-1][2])
83
+
84
+ ensure
85
+ LIBUSB.set_options OPTION_LOG_CB: [nil], OPTION_LOG_LEVEL: LIBUSB::LOG_LEVEL_NONE
86
+ end
87
+ end
41
88
  end
@@ -119,7 +119,7 @@ class TestLibusbDescriptors < Minitest::Test
119
119
 
120
120
  usb.devices.each do |dev|
121
121
  dev.endpoints.each do |ep|
122
- if dev.device_speed == :SPEED_SUPER
122
+ if [:SPEED_SUPER, :SPEED_SUPER_PLUS].include?(dev.device_speed)
123
123
  ss = ep.ss_companion
124
124
  assert_match(/SsCompanion/, ss.inspect, "SsCompanion#inspect should work")
125
125
 
@@ -172,14 +172,19 @@ class TestLibusbDescriptors < Minitest::Test
172
172
  def test_device_filter_hubs
173
173
  devs1 = []
174
174
  usb.devices.each do |dev|
175
- dev.settings.each do |if_desc|
176
- if if_desc.bInterfaceClass == CLASS_HUB
177
- devs1 << dev
175
+ if dev.bDeviceClass==CLASS_PER_INTERFACE
176
+ dev.settings.each do |if_desc|
177
+ if if_desc.bInterfaceClass==CLASS_HUB
178
+ devs1 << dev
179
+ end
178
180
  end
181
+ else
182
+ devs1 << dev if dev.bDeviceClass == CLASS_HUB
179
183
  end
180
184
  end
181
185
 
182
186
  devs2 = usb.devices( bClass: CLASS_HUB )
187
+
183
188
  assert_equal devs1.sort, devs2.sort, "devices and devices with filter should deliver the same device"
184
189
  end
185
190
 
@@ -189,11 +194,11 @@ class TestLibusbDescriptors < Minitest::Test
189
194
  if ep
190
195
  assert_operator dev.max_packet_size(ep), :>, 0, "#{dev.inspect} should have a usable packet size"
191
196
  assert_operator dev.max_packet_size(ep.bEndpointAddress), :>, 0, "#{dev.inspect} should have a usable packet size"
192
- assert_operator dev.max_iso_packet_size(ep), :>, 0, "#{dev.inspect} should have a usable iso packet size"
193
- assert_operator dev.max_iso_packet_size(ep.bEndpointAddress), :>, 0, "#{dev.inspect} should have a usable iso packet size"
197
+ assert_operator dev.max_iso_packet_size(ep), :>=, 0, "#{dev.inspect} should have a usable iso packet size"
198
+ assert_operator dev.max_iso_packet_size(ep.bEndpointAddress), :>=, 0, "#{dev.inspect} should have a usable iso packet size"
194
199
  assert_operator dev.bus_number, :>=, 0, "#{dev.inspect} should have a bus_number"
195
200
  assert_operator dev.device_address, :>=, 0, "#{dev.inspect} should have a device_address"
196
- assert_operator([:SPEED_UNKNOWN, :SPEED_LOW, :SPEED_FULL, :SPEED_HIGH, :SPEED_SUPER], :include?, dev.device_speed, "#{dev.inspect} should have a device_speed")
201
+ assert_operator([:SPEED_UNKNOWN, :SPEED_LOW, :SPEED_FULL, :SPEED_HIGH, :SPEED_SUPER, :SPEED_SUPER_PLUS], :include?, dev.device_speed, "#{dev.inspect} should have a device_speed")
197
202
  path = dev.port_numbers
198
203
  assert_kind_of Array, path, "#{dev.inspect} should have port_numbers"
199
204
  path = dev.port_path
@@ -201,12 +206,40 @@ class TestLibusbDescriptors < Minitest::Test
201
206
  path.each do |port|
202
207
  assert_operator port, :>, 0, "#{dev.inspect} should have proper port_path entries"
203
208
  end
204
- assert_equal path[-1], dev.port_number, "#{dev.inspect} should have a port number out of the port_path"
205
- if parent=dev.parent
206
- assert_kind_of Device, parent, "#{dev.inspect} should have a parent"
207
- assert_equal path[-2], parent.port_number, "#{dev.inspect} should have a parent port number out of the port_path"
209
+ if path.empty?
210
+ assert_nil dev.port_number
211
+ else
212
+ assert_equal path[-1], dev.port_number, "#{dev.inspect} should have a port number out of the port_path"
213
+ if parent=dev.parent
214
+ assert_kind_of Device, parent, "#{dev.inspect} should have a parent"
215
+ assert_equal path[-2], parent.port_number, "#{dev.inspect} should have a parent port number out of the port_path" if parent.port_number
216
+ end
208
217
  end
209
218
  end
210
219
  end
211
220
  end
221
+
222
+ def test_wrap_sys_device
223
+ skip unless RUBY_PLATFORM =~ /linux/
224
+ d = usb.devices[0]
225
+ File.open(format("/dev/bus/usb/%03d/%03d", d.bus_number, d.device_address), "w+") do |io|
226
+ devh = usb.wrap_sys_device(io)
227
+ devh.kernel_driver_active?(0)
228
+ devh.close
229
+
230
+ usb.wrap_sys_device(io) do |devh|
231
+ devh.kernel_driver_active?(0)
232
+ end
233
+ end
234
+ end
235
+
236
+ def test_wrap_sys_device_failure
237
+ skip unless RUBY_PLATFORM =~ /linux/
238
+ d = usb.devices[0]
239
+ assert_raises(LIBUSB::ERROR_OTHER) do
240
+ File.open(format("/dev/bus/usb/%03d/%03d", d.bus_number, d.device_address), "r") do |io|
241
+ usb.wrap_sys_device(io).kernel_driver_active?(0)
242
+ end
243
+ end
244
+ end
212
245
  end
@@ -34,4 +34,19 @@ class TestLibusbGc < Minitest::Test
34
34
  GC.start
35
35
  assert_equal ps, ep.wMaxPacketSize, "GC should not free EndpointDescriptor"
36
36
  end
37
+
38
+ def test_log_cb
39
+ LIBUSB.set_options OPTION_LOG_CB: proc{}, OPTION_LOG_LEVEL: LIBUSB::LOG_LEVEL_DEBUG
40
+
41
+ c = LIBUSB::Context.new OPTION_LOG_CB: proc{}, OPTION_NO_DEVICE_DISCOVERY: nil
42
+ GC.start
43
+ c.devices
44
+ c.set_log_cb(LIBUSB::LOG_CB_CONTEXT){}
45
+ c.devices
46
+ GC.start
47
+ c.devices
48
+
49
+ ensure
50
+ LIBUSB.set_options OPTION_LOG_CB: [nil], OPTION_LOG_LEVEL: LIBUSB::LOG_LEVEL_NONE
51
+ end
37
52
  end
@@ -26,7 +26,9 @@ class TestLibusbHotplug < Minitest::Test
26
26
  end
27
27
 
28
28
  def teardown
29
- @ctx.exit
29
+ # No need to release the LIBUSB::Context any longer.
30
+ # It is cleaned up by the GC.
31
+ # @ctx.exit
30
32
  end
31
33
 
32
34
  def test_enumerate
@@ -47,4 +47,10 @@ class TestLibusbIsoTransfer < Minitest::Test
47
47
  tr.submit!
48
48
  end
49
49
  end
50
+
51
+ def test_max_alt_packet_size
52
+ d = Context.new.devices[0]
53
+ size = d.max_alt_packet_size d.interfaces[0], d.settings[0], d.endpoints[0]
54
+ assert_operator 0, :<=, size
55
+ end
50
56
  end
@@ -61,7 +61,7 @@ class TestLibusbMassStorage < Minitest::Test
61
61
  dev.close if dev
62
62
  end
63
63
 
64
- def do_transfer(method, args)
64
+ def do_transfer(method, **args)
65
65
  if @asynchron
66
66
  stop = false
67
67
  transfer = dev.send(method, args) do |tr|
@@ -78,14 +78,14 @@ class TestLibusbMassStorage < Minitest::Test
78
78
  end
79
79
  transfer.result
80
80
  else
81
- dev.send(method, args)
81
+ dev.send(method, **args)
82
82
  end
83
83
  end
84
- def control_transfer(args)
85
- do_transfer(:control_transfer, args)
84
+ def control_transfer(**args)
85
+ do_transfer(:control_transfer, **args)
86
86
  end
87
- def bulk_transfer(args)
88
- do_transfer(:bulk_transfer, args)
87
+ def bulk_transfer(**args)
88
+ do_transfer(:bulk_transfer, **args)
89
89
  end
90
90
 
91
91
  def send_mass_storage_command(cdb, data_length, direction=ENDPOINT_IN)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libusb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.7.0
5
5
  platform: x64-mingw32
6
6
  authors:
7
7
  - Lars Kanis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-05 00:00:00.000000000 Z
11
+ date: 2024-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -24,62 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake-compiler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '1.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '1.0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake-compiler-dock
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0.2'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0.2'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.0'
69
- - !ruby/object:Gem::Dependency
70
- name: yard
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '0.6'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '0.6'
83
27
  description: LIBUSB is a Ruby binding that gives Ruby programmers access to arbitrary
84
28
  USB devices
85
29
  email:
@@ -88,6 +32,8 @@ executables: []
88
32
  extensions: []
89
33
  extra_rdoc_files: []
90
34
  files:
35
+ - ".appveyor.yml"
36
+ - ".github/workflows/ci.yml"
91
37
  - ".gitignore"
92
38
  - ".travis.yml"
93
39
  - ".yardopts"
@@ -96,7 +42,6 @@ files:
96
42
  - History.md
97
43
  - README.md
98
44
  - Rakefile
99
- - appveyor.yml
100
45
  - lib/libusb-1.0.dll
101
46
  - lib/libusb.rb
102
47
  - lib/libusb/bos.rb
@@ -105,6 +50,7 @@ files:
105
50
  - lib/libusb/configuration.rb
106
51
  - lib/libusb/constants.rb
107
52
  - lib/libusb/context.rb
53
+ - lib/libusb/context_reference.rb
108
54
  - lib/libusb/dependencies.rb
109
55
  - lib/libusb/dev_handle.rb
110
56
  - lib/libusb/device.rb
@@ -152,15 +98,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
98
  requirements:
153
99
  - - ">="
154
100
  - !ruby/object:Gem::Version
155
- version: 1.9.3
101
+ version: 2.5.0
156
102
  required_rubygems_version: !ruby/object:Gem::Requirement
157
103
  requirements:
158
104
  - - ">="
159
105
  - !ruby/object:Gem::Version
160
106
  version: '0'
161
107
  requirements: []
162
- rubyforge_project:
163
- rubygems_version: 2.7.3
108
+ rubygems_version: 3.3.26
164
109
  signing_key:
165
110
  specification_version: 4
166
111
  summary: Access USB devices from Ruby via libusb-1.0
data/appveyor.yml DELETED
@@ -1,36 +0,0 @@
1
- init:
2
- - SET PATH=C:/Ruby%ruby_version%/bin;%PATH%
3
- - SET RAKEOPT=-rdevkit
4
- install:
5
- - ps: |
6
- if ($env:ruby_version -like "*head*") {
7
- $(new-object net.webclient).DownloadFile("https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-$env:ruby_version.exe", "$pwd/ruby-setup.exe")
8
- cmd /c ruby-setup.exe /verysilent /dir=C:/Ruby$env:ruby_version
9
- }
10
- - ruby --version
11
- - gem --version
12
- - ps: |
13
- if ($env:BROKEN_SSL -eq "true") {
14
- $(New-Object Net.WebClient).DownloadFile('https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt', "$env:TMP/ca-bundle.crt")
15
- $env:SSL_CERT_FILE = "$env:TMP/ca-bundle.crt"
16
- Write-Host "Using SSL CA list $env:SSL_CERT_FILE" -foreground Green
17
- }
18
- - gem install bundler --conservative
19
- - bundle config force_ruby_platform true
20
- - bundle install
21
- build_script:
22
- - bundle exec rake compile
23
- test_script:
24
- - bundle exec rake travis
25
- environment:
26
- matrix:
27
- - ruby_version: "head-x64"
28
- - ruby_version: "200"
29
- BROKEN_SSL: true
30
- - ruby_version: "21-x64"
31
- BROKEN_SSL: true
32
- - ruby_version: "22"
33
- BROKEN_SSL: true
34
- - ruby_version: "23-x64"
35
- BROKEN_SSL: true
36
- - ruby_version: "24"