win 0.3.26 → 0.3.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/HISTORY +4 -0
- data/VERSION +1 -1
- data/spec/win/library_spec.rb +44 -47
- data/spec/win/time_spec.rb +2 -2
- metadata +16 -7
- data/spec/spec.opts +0 -2
data/HISTORY
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.27
|
data/spec/win/library_spec.rb
CHANGED
@@ -3,9 +3,6 @@ require 'win/library'
|
|
3
3
|
require 'win/gui/message'
|
4
4
|
|
5
5
|
module LibraryTest
|
6
|
-
# include my_lib
|
7
|
-
# include WinTest
|
8
|
-
|
9
6
|
|
10
7
|
shared_examples_for 'defining macro with options' do
|
11
8
|
|
@@ -24,31 +21,32 @@ module LibraryTest
|
|
24
21
|
|
25
22
|
context 'renaming and aliasing' do
|
26
23
|
it ':camel_name option overrides default CamelCase name for attached function but leaves snake_case intact' do
|
27
|
-
@my_lib.function :FindWindow, 'PP', 'L', camel_name
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
@my_lib.function :FindWindow, 'PP', 'L', :camel_name => 'MyOwnName', &@def_block
|
25
|
+
p @my_lib.methods(false)
|
26
|
+
@my_lib.methods(false).should include :MyOwnName
|
27
|
+
@my_lib.methods(false).should include :find_window
|
28
|
+
@my_lib.methods(false).should_not include :FindWindow
|
31
29
|
end
|
32
30
|
|
33
31
|
it ':snake_name option overrides default snake_case name for defined method but leaves CamelCase intact' do
|
34
|
-
@my_lib.function :FindWindow, 'PP', 'L', snake_name
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
@my_lib.function :FindWindow, 'PP', 'L', :snake_name => 'my_own_find', &@def_block
|
33
|
+
@my_lib.methods(false).should include :FindWindow
|
34
|
+
@my_lib.methods(false).should include :my_own_find
|
35
|
+
@my_lib.methods(false).should_not include :find_window
|
38
36
|
end
|
39
37
|
|
40
38
|
it 'both :snake_name and :camel_name option can be used in one declaration' do
|
41
|
-
@my_lib.function :FindWindow, 'PP', 'L', camel_name
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
@my_lib.function :FindWindow, 'PP', 'L', :camel_name => 'MyOwnName', :snake_name => 'my_own_find', &@def_block
|
40
|
+
@my_lib.methods(false).should include :MyOwnName
|
41
|
+
@my_lib.methods(false).should_not include :FindWindow
|
42
|
+
@my_lib.methods(false).should include :my_own_find
|
43
|
+
@my_lib.methods(false).should_not include :find_window
|
46
44
|
end
|
47
45
|
|
48
46
|
it ':camel_only option means no snake_case method will be defined' do
|
49
|
-
@my_lib.function :FindWindow, 'PP', 'L', camel_only
|
50
|
-
|
51
|
-
|
47
|
+
@my_lib.function :FindWindow, 'PP', 'L', :camel_only => true, &@def_block
|
48
|
+
@my_lib.methods(false).should include :FindWindow
|
49
|
+
@my_lib.methods(false).should_not include :find_window
|
52
50
|
end
|
53
51
|
|
54
52
|
it 'automatically adds Rubyesque alias to IsXxx API test function' do
|
@@ -98,7 +96,7 @@ module LibraryTest
|
|
98
96
|
end
|
99
97
|
|
100
98
|
context 'defining API with :fails option converts zero result to nil' do
|
101
|
-
before(:each) { @my_lib.function :FindWindow, 'PP', 'L', fails
|
99
|
+
before(:each) { @my_lib.function :FindWindow, 'PP', 'L', :fails => 0, &@def_block }
|
102
100
|
|
103
101
|
it 'defines new instance method' do
|
104
102
|
@my_lib.respond_to?(:find_window).should be_true
|
@@ -123,7 +121,7 @@ module LibraryTest
|
|
123
121
|
end
|
124
122
|
|
125
123
|
context 'using DLL other than default user32, kernel32 with :dll option' do
|
126
|
-
before(:each) { @my_lib.function 'GetUserName', 'PP', 'I', :dll=> 'advapi32', &@def_block }
|
124
|
+
before(:each) { @my_lib.function 'GetUserName', 'PP', 'I', :dll => 'advapi32', &@def_block }
|
127
125
|
|
128
126
|
it 'defines new instance method with appropriate name' do
|
129
127
|
@my_lib.respond_to?(:GetUserName).should be_true
|
@@ -154,18 +152,14 @@ module LibraryTest
|
|
154
152
|
end
|
155
153
|
end
|
156
154
|
|
157
|
-
def should_count_args
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
args = (1..n).map { wrongs[rand(wrongs.size)] }
|
166
|
-
expect { @my_lib.send method, *args }.
|
167
|
-
to raise_error "wrong number of arguments (#{args.size} for #{rights.size})"
|
168
|
-
end
|
155
|
+
def should_count_args method, rights, wrongs
|
156
|
+
(0..8).each do |n|
|
157
|
+
if n == rights.size
|
158
|
+
expect { @my_lib.send method, *rights }.to_not raise_error
|
159
|
+
else
|
160
|
+
args = (1..n).map { wrongs[rand(wrongs.size)] }
|
161
|
+
expect { @my_lib.send method, *args }.
|
162
|
+
to raise_error "wrong number of arguments (#{args.size} for #{rights.size})"
|
169
163
|
end
|
170
164
|
end
|
171
165
|
end
|
@@ -197,19 +191,21 @@ module LibraryTest
|
|
197
191
|
end
|
198
192
|
|
199
193
|
describe '::function - attaches external API function and defines enhanced snake_case method on top of it' do
|
200
|
-
spec { use { @my_lib.function(:FindWindow, 'PP', 'l', aliases
|
194
|
+
spec { use { @my_lib.function(:FindWindow, 'PP', 'l', :aliases => nil, :boolean => nil, :fails => 0, &any_block) } }
|
201
195
|
|
202
196
|
context 'defining enhanced API function without definition block (using defaults)' do
|
203
197
|
it_should_behave_like 'defining macro with options'
|
204
198
|
|
205
199
|
it 'constructs argument prototype from uppercase string, enforces the args count' do
|
206
200
|
expect { @my_lib.function :FindWindow, 'PP', 'L' }.to_not raise_error
|
207
|
-
should_count_args :
|
201
|
+
should_count_args :FindWindow, [nil, nil], [nil, IMPOSSIBLE, 'cmd']
|
202
|
+
should_count_args :find_window, [nil, nil], [nil, IMPOSSIBLE, 'cmd']
|
208
203
|
end
|
209
204
|
|
210
205
|
it 'constructs argument prototype from (mixed) array, enforces the args count' do
|
211
206
|
expect { @my_lib.function :FindWindow, [:pointer, 'P'], 'L' }.to_not raise_error
|
212
|
-
should_count_args :
|
207
|
+
should_count_args :FindWindow, [nil, nil], [nil, IMPOSSIBLE, 'cmd']
|
208
|
+
should_count_args :find_window, [nil, nil], [nil, IMPOSSIBLE, 'cmd']
|
213
209
|
end
|
214
210
|
|
215
211
|
it 'defined snake_case method returns expected value when called' do
|
@@ -250,7 +246,7 @@ module LibraryTest
|
|
250
246
|
|
251
247
|
it 'passes arguments and underlying Win32::API object to the block' do
|
252
248
|
@my_lib.function(:FindWindow, 'PP', 'L') do |api, *args|
|
253
|
-
@api
|
249
|
+
@api = api
|
254
250
|
@args = args
|
255
251
|
end
|
256
252
|
expect { @my_lib.find_window(1, 2, 3) }.to_not raise_error
|
@@ -263,13 +259,13 @@ module LibraryTest
|
|
263
259
|
before(:each) do
|
264
260
|
@def_block = nil
|
265
261
|
@my_lib.function :SendMessage, [:ulong, :uint, :uint, :pointer], :int,
|
266
|
-
|
267
|
-
|
262
|
+
:alternative => [[:ulong, :uint, :uint, :long], :int,
|
263
|
+
lambda { |*args| Integer === args.last} ]
|
268
264
|
end
|
269
265
|
|
270
266
|
it 'defines camel and snake methods (as well as hidden Original/Alternative methods)' do
|
271
267
|
expect { @my_lib.send_message(any_handle, Win::Gui::Message::WM_GETTEXT,
|
272
|
-
|
268
|
+
buffer.size, buffer) }.to_not raise_error
|
273
269
|
expect {
|
274
270
|
@my_lib.send_message(any_handle, Win::Gui::Message::WM_GETTEXT, buffer.size, buffer.address)
|
275
271
|
}.to_not raise_error
|
@@ -296,18 +292,18 @@ module LibraryTest
|
|
296
292
|
|
297
293
|
context 'calling defined methods with attached block to preprocess the API function results' do
|
298
294
|
it 'defined method yields raw result to block attached to its invocation' do
|
299
|
-
@my_lib.function :FindWindow, 'PP', 'L', fails
|
295
|
+
@my_lib.function :FindWindow, 'PP', 'L', :fails => 0
|
300
296
|
@my_obj.find_window(nil, IMPOSSIBLE) { |result| result.should == 0 }
|
301
297
|
end
|
302
298
|
|
303
299
|
it 'defined method returns result of block attached to its invocation' do
|
304
|
-
@my_lib.function :FindWindow, 'PP', 'L', fails
|
300
|
+
@my_lib.function :FindWindow, 'PP', 'L', :fails => 0
|
305
301
|
return_value = @my_obj.find_window(nil, IMPOSSIBLE) { |result| 'Value' }
|
306
302
|
return_value.should == 'Value'
|
307
303
|
end
|
308
304
|
|
309
305
|
it 'defined method transforms result of block before returning it' do
|
310
|
-
@my_lib.function :FindWindow, 'PP', 'L', fails
|
306
|
+
@my_lib.function :FindWindow, 'PP', 'L', :fails => 0
|
311
307
|
return_value = @my_obj.find_window(nil, IMPOSSIBLE) { |result| 0 }
|
312
308
|
return_value.should_not == 0
|
313
309
|
return_value.should == nil
|
@@ -316,10 +312,11 @@ module LibraryTest
|
|
316
312
|
|
317
313
|
context 'defining API function without arguments - f(VOID)' do
|
318
314
|
it 'should enforce argument count to 0, NOT 1' do
|
319
|
-
@my_lib.function :GetForegroundWindow, [], 'L', fails
|
315
|
+
@my_lib.function :GetForegroundWindow, [], 'L', :fails => 0
|
320
316
|
p (@my_lib.methods-Win::Library.methods).sort
|
321
|
-
|
322
|
-
should_count_args :
|
317
|
+
should_count_args :GetForegroundWindow, [], [nil, 0, 123]
|
318
|
+
should_count_args :get_foreground_window, [], [nil, 0, 123]
|
319
|
+
should_count_args :foreground_window, [], [nil, 0, 123]
|
323
320
|
end
|
324
321
|
end
|
325
322
|
|
@@ -365,4 +362,4 @@ module LibraryTest
|
|
365
362
|
end
|
366
363
|
end
|
367
364
|
end
|
368
|
-
end
|
365
|
+
end
|
data/spec/win/time_spec.rb
CHANGED
@@ -26,12 +26,12 @@ describe Win::Time do
|
|
26
26
|
|
27
27
|
it "original api succeeds, the return value is nonzero, counter value returned at given pointer." do
|
28
28
|
QueryPerformanceCounter(count = FFI::MemoryPointer.new(:int64)).should be > 0
|
29
|
-
count.get_int64(0).should be >
|
29
|
+
count.get_int64(0).should be > 5_000_000
|
30
30
|
end
|
31
31
|
|
32
32
|
it "snake_case api succeeds, the return value is counter value (in counts)" do
|
33
33
|
count = query_performance_counter()
|
34
|
-
count.should be >
|
34
|
+
count.should be > 5_000_000
|
35
35
|
end
|
36
36
|
|
37
37
|
it "return (slightly) incremented counter values in successive function calls" do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: win
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.27
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- arvicco
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-11-11 00:00:00 +03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,16 +25,27 @@ dependencies:
|
|
25
25
|
type: :development
|
26
26
|
version_requirements: *id001
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
prerelease: false
|
30
30
|
requirement: &id002 !ruby/object:Gem::Requirement
|
31
31
|
none: false
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 0.
|
35
|
+
version: 1.0.13
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: ffi
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - "="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.9
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
38
49
|
description: Rubyesque interfaces and wrappers for Windows API functions pre-defined using FFI
|
39
50
|
email: arvitallian@gmail.com
|
40
51
|
executables: []
|
@@ -63,7 +74,6 @@ files:
|
|
63
74
|
- lib/win/time.rb
|
64
75
|
- lib/win.rb
|
65
76
|
- spec/extension_spec.rb
|
66
|
-
- spec/spec.opts
|
67
77
|
- spec/spec_helper.rb
|
68
78
|
- spec/win/dde_spec.rb
|
69
79
|
- spec/win/error_spec.rb
|
@@ -120,13 +130,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
130
|
requirements: []
|
121
131
|
|
122
132
|
rubyforge_project:
|
123
|
-
rubygems_version: 1.
|
133
|
+
rubygems_version: 1.6.2
|
124
134
|
signing_key:
|
125
135
|
specification_version: 3
|
126
136
|
summary: Rubyesque interfaces and wrappers for Windows API functions pre-defined using FFI
|
127
137
|
test_files:
|
128
138
|
- spec/extension_spec.rb
|
129
|
-
- spec/spec.opts
|
130
139
|
- spec/spec_helper.rb
|
131
140
|
- spec/win/dde_spec.rb
|
132
141
|
- spec/win/error_spec.rb
|
data/spec/spec.opts
DELETED