win32-api 1.5.0-universal-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +154 -0
- data/MANIFEST +10 -0
- data/README +121 -0
- data/Rakefile +168 -0
- data/ext/win32/api.c +975 -0
- data/lib/win32/api.rb +12 -0
- data/lib/win32/ruby18/win32/api.so +0 -0
- data/lib/win32/ruby19/win32/api.so +0 -0
- data/lib/win32/ruby2_32/win32/api.so +0 -0
- data/lib/win32/ruby2_64/win32/api.so +0 -0
- data/test/test_win32_api.rb +145 -0
- data/test/test_win32_api_callback.rb +74 -0
- data/test/test_win32_api_function.rb +66 -0
- data/win32-api.gemspec +27 -0
- metadata +83 -0
data/lib/win32/api.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
if RUBY_VERSION.to_f < 1.9
|
2
|
+
require File.join(File.dirname(__FILE__), 'ruby18/win32/api')
|
3
|
+
elsif RUBY_VERSION.to_f < 2.0
|
4
|
+
require File.join(File.dirname(__FILE__), 'ruby19/win32/api')
|
5
|
+
else
|
6
|
+
require 'rbconfig'
|
7
|
+
if RbConfig::CONFIG['arch'] =~ /x64/i
|
8
|
+
require File.join(File.dirname(__FILE__), 'ruby2_64/win32/api')
|
9
|
+
else
|
10
|
+
require File.join(File.dirname(__FILE__), 'ruby2_32/win32/api')
|
11
|
+
end
|
12
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,145 @@
|
|
1
|
+
############################################################################
|
2
|
+
# test_win32_api.rb
|
3
|
+
#
|
4
|
+
# Test case for the Win32::API class. You should run this as Rake task,
|
5
|
+
# i.e. 'rake test', instead of running it directly.
|
6
|
+
############################################################################
|
7
|
+
require 'win32/api'
|
8
|
+
require 'test-unit'
|
9
|
+
include Win32
|
10
|
+
|
11
|
+
class TC_Win32_API < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
@buf = 0.chr * 260
|
14
|
+
@gfa = API.new('GetFileAttributes', 'S', 'L')
|
15
|
+
@gcd = API.new('GetCurrentDirectory', 'LP')
|
16
|
+
@gle = API.new('GetLastError', 'V', 'L')
|
17
|
+
@str = API.new('strstr', 'PP', 'P', 'msvcrt')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_version
|
21
|
+
assert_equal('1.5.0', API::VERSION)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_constructor_basic
|
25
|
+
assert_nothing_raised{ API.new('GetCurrentDirectory') }
|
26
|
+
assert_nothing_raised{ API.new('GetCurrentDirectory', 'LP') }
|
27
|
+
assert_nothing_raised{ API.new('GetCurrentDirectory', 'LP', 'L') }
|
28
|
+
assert_nothing_raised{ API.new('GetCurrentDirectory', 'LP', 'L', 'kernel32') }
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_call
|
32
|
+
assert_respond_to(@gcd, :call)
|
33
|
+
assert_nothing_raised{ @gcd.call(@buf.length, @buf) }
|
34
|
+
assert_equal(Dir.pwd.tr('/', "\\"), @buf.strip)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_call_with_void
|
38
|
+
assert_nothing_raised{ @gle.call }
|
39
|
+
assert_nothing_raised{ @gle.call(nil) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_call_return_value_on_failure
|
43
|
+
assert_equal(0xFFFFFFFF, @gfa.call('C:/foobarbazblah'))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_dll_name
|
47
|
+
assert_respond_to(@gcd, :dll_name)
|
48
|
+
assert_equal('kernel32', @gcd.dll_name)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_function_name
|
52
|
+
assert_respond_to(@gcd, :function_name)
|
53
|
+
assert_equal('GetCurrentDirectory', @gcd.function_name)
|
54
|
+
assert_equal('strstr', @str.function_name)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_effective_function_name_default
|
58
|
+
assert_respond_to(@gcd, :effective_function_name)
|
59
|
+
assert_equal('GetCurrentDirectoryA', @gcd.effective_function_name)
|
60
|
+
assert_equal('strstr', @str.effective_function_name)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_effective_function_name_default_explicit_ansi
|
64
|
+
@gcd = API.new('GetCurrentDirectoryA', 'LP')
|
65
|
+
assert_equal('GetCurrentDirectoryA', @gcd.effective_function_name)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_effective_function_name_default_explicit_wide
|
69
|
+
@gcd = API.new('GetCurrentDirectoryW', 'LP')
|
70
|
+
assert_equal('GetCurrentDirectoryW', @gcd.effective_function_name)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_prototype
|
74
|
+
assert_respond_to(@gcd, :prototype)
|
75
|
+
assert_equal(['L', 'P'], @gcd.prototype)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_return_type
|
79
|
+
assert_respond_to(@gcd, :return_type)
|
80
|
+
assert_equal('L', @gcd.return_type)
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_constructor_high_iteration
|
84
|
+
assert_nothing_raised{
|
85
|
+
1000.times{ API.new('GetUserName', 'P', 'P', 'advapi32') }
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_constructor_expected_failures
|
90
|
+
assert_raise(ArgumentError){ API.new }
|
91
|
+
assert_raise(ArgumentError){ API.new('GetUserName', ('L' * 21), 'X') }
|
92
|
+
assert_raise(API::LoadLibraryError){ API.new('GetUserName', 'PL', 'I', 'foo') }
|
93
|
+
assert_raise(API::PrototypeError){ API.new('GetUserName', 'X', 'I', 'advapi32') }
|
94
|
+
assert_raise(API::PrototypeError){ API.new('GetUserName', 'PL', 'X', 'advapi32') }
|
95
|
+
end
|
96
|
+
|
97
|
+
test "constructor returns expected error message if function not found" do
|
98
|
+
msg = "Unable to load function "
|
99
|
+
assert_raise_message(msg + "'Zap', 'ZapA', or 'ZapW'"){ API.new('Zap') }
|
100
|
+
assert_raise_message(msg + "'strxxx'"){ API.new('strxxx', 'P', 'L', 'msvcrt') }
|
101
|
+
end
|
102
|
+
|
103
|
+
test "constructor returns expected error message if prototype is invalid" do
|
104
|
+
msg = "Illegal prototype 'X'"
|
105
|
+
assert_raise_message(msg){ API.new('GetUserName', 'X', 'I', 'advapi32') }
|
106
|
+
end
|
107
|
+
|
108
|
+
test "constructor returns expected error message if return type is invalid" do
|
109
|
+
msg = "Illegal return type 'Y'"
|
110
|
+
assert_raise_message(msg){ API.new('GetUserName', 'PL', 'Y', 'advapi32') }
|
111
|
+
end
|
112
|
+
|
113
|
+
test "constructor returns expected error message if too many parameters" do
|
114
|
+
msg = "too many parameters: 25"
|
115
|
+
assert_raise_message(msg){ API.new('GetFileAttributes', 'S' * 25, 'L') }
|
116
|
+
end
|
117
|
+
|
118
|
+
test "call method returns expected error message if too many parameters" do
|
119
|
+
msg = "wrong number of parameters: expected 2, got 3"
|
120
|
+
assert_raise_message(msg){ @str.call('test', 'test', 'test') }
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_call_expected_failures
|
124
|
+
assert_raise(TypeError){ @gcd.call('test', @buf) }
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_error_classes
|
128
|
+
assert_not_nil(Win32::API::Error)
|
129
|
+
assert_not_nil(Win32::API::LoadLibraryError)
|
130
|
+
assert_not_nil(Win32::API::PrototypeError)
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_error_class_relationships
|
134
|
+
assert_kind_of(RuntimeError, Win32::API::Error.new)
|
135
|
+
assert_kind_of(Win32::API::Error, Win32::API::LoadLibraryError.new)
|
136
|
+
assert_kind_of(Win32::API::Error, Win32::API::PrototypeError.new)
|
137
|
+
end
|
138
|
+
|
139
|
+
def teardown
|
140
|
+
@buf = nil
|
141
|
+
@gcd = nil
|
142
|
+
@gle = nil
|
143
|
+
@str = nil
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
############################################################################
|
2
|
+
# test_win32_api_callback.rb
|
3
|
+
#
|
4
|
+
# Test case for the Win32::API::Callback class. You should run this as Rake
|
5
|
+
# task, i.e. 'rake test', instead of running it directly.
|
6
|
+
############################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'win32/api'
|
11
|
+
require 'test/unit'
|
12
|
+
include Win32
|
13
|
+
|
14
|
+
class TC_Win32_API_Callback < Test::Unit::TestCase
|
15
|
+
def setup
|
16
|
+
@buffer = 0.chr * 260
|
17
|
+
@api_ew = API.new('EnumWindows', 'KP', 'L', 'user32')
|
18
|
+
@api_gwt = API.new('GetWindowText', 'LPI', 'I', 'user32')
|
19
|
+
@callback = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_constructor
|
23
|
+
assert_respond_to(API::Callback, :new)
|
24
|
+
assert_nothing_raised{ API::Callback.new('LP', 'I') }
|
25
|
+
assert_nothing_raised{ API::Callback.new('LP', 'I'){} }
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_prototype
|
29
|
+
assert_nothing_raised{ @callback = API::Callback.new('LP', 'I') }
|
30
|
+
assert_respond_to(@callback, :prototype)
|
31
|
+
assert_equal('LP', @callback.prototype)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_return_value
|
35
|
+
assert_nothing_raised{ @callback = API::Callback.new('LP', 'I') }
|
36
|
+
assert_respond_to(@callback, :return_type)
|
37
|
+
assert_equal('I', @callback.return_type)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_address
|
41
|
+
assert_nothing_raised{ @callback = API::Callback.new('LP', 'I') }
|
42
|
+
assert_respond_to(@callback, :address)
|
43
|
+
assert_kind_of(Integer, @callback.address)
|
44
|
+
assert_true(@callback.address > 0)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_callback
|
48
|
+
assert_nothing_raised{
|
49
|
+
@callback = API::Callback.new('LP', 'I'){ |handle, param|
|
50
|
+
buf = "\0" * 200
|
51
|
+
@api_gwt.call(handle, buf, 200);
|
52
|
+
buf.index(param).nil? ? true : false
|
53
|
+
}
|
54
|
+
}
|
55
|
+
assert_nothing_raised{ @api_ew.call(@callback, 'UEDIT32') }
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_constructor_expected_errors
|
59
|
+
assert_raise(API::PrototypeError){ API::Callback.new('X') }
|
60
|
+
assert_raise(API::PrototypeError){ API::Callback.new('L', 'Y') }
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_constructor_expected_error_messages
|
64
|
+
assert_raise_message("Illegal prototype 'X'"){ API::Callback.new('X') }
|
65
|
+
assert_raise_message("Illegal return type 'Y'"){ API::Callback.new('L', 'Y') }
|
66
|
+
end
|
67
|
+
|
68
|
+
def teardown
|
69
|
+
@buffer = nil
|
70
|
+
@api_ew = nil
|
71
|
+
@api_gwt = nil
|
72
|
+
@callback = nil
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
########################################################################
|
2
|
+
# test_win32_api_function.rb
|
3
|
+
#
|
4
|
+
# Test case for the Win32::API::Function class. You should run these
|
5
|
+
# tests via the 'rake test' task.
|
6
|
+
########################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'win32/api'
|
12
|
+
include Win32
|
13
|
+
|
14
|
+
class TC_Win32_API_Function < Test::Unit::TestCase
|
15
|
+
def setup
|
16
|
+
@func = Win32::API::Function.new(123456789, 'LP', 'L')
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_constructor
|
20
|
+
assert_nothing_raised{ Win32::API::Function.new(1) }
|
21
|
+
assert_nothing_raised{ Win32::API::Function.new(1, 'LL') }
|
22
|
+
assert_nothing_raised{ Win32::API::Function.new(1, 'LL', 'I') }
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_subclass
|
26
|
+
assert_kind_of(Win32::API, @func)
|
27
|
+
assert_respond_to(@func, :call)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_address
|
31
|
+
assert_respond_to(@func, :address)
|
32
|
+
assert_equal(123456789, @func.address)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_prototype
|
36
|
+
assert_respond_to(@func, :prototype)
|
37
|
+
assert_equal(['L', 'P'], @func.prototype)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_return_type
|
41
|
+
assert_respond_to(@func, :return_type)
|
42
|
+
assert_equal('L', @func.return_type)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_expected_errors_from_arguments
|
46
|
+
assert_raise(ArgumentError){ Win32::API::Function.new }
|
47
|
+
assert_raise(TypeError){ Win32::API::Function.new('L') }
|
48
|
+
assert_raise(Win32::API::PrototypeError){ Win32::API::Function.new(1, 'X') }
|
49
|
+
assert_raise(Win32::API::PrototypeError){ Win32::API::Function.new(1, 'X', 'Y') }
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_expected_error_messages
|
53
|
+
assert_raise_message("Illegal prototype 'X'"){ API::Function.new(1, 'X') }
|
54
|
+
assert_raise_message("Illegal return type 'Y'"){ API::Function.new(1, 'L', 'Y') }
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_expected_errors_from_call
|
58
|
+
assert_raise(ArgumentError){ @func.call }
|
59
|
+
assert_raise(ArgumentError){ @func.call(1) }
|
60
|
+
assert_raise(ArgumentError){ @func.call(1, 'a', 2) }
|
61
|
+
end
|
62
|
+
|
63
|
+
def teardown
|
64
|
+
@func = nil
|
65
|
+
end
|
66
|
+
end
|
data/win32-api.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'win32-api'
|
5
|
+
spec.version = '1.5.0'
|
6
|
+
spec.authors = ['Daniel J. Berger', 'Park Heesob']
|
7
|
+
spec.license = 'Artistic 2.0'
|
8
|
+
spec.email = 'djberg96@gmail.com'
|
9
|
+
spec.homepage = 'http://github.com/djberg96/win32-api'
|
10
|
+
spec.summary = 'A superior replacement for Win32API'
|
11
|
+
spec.test_files = Dir['test/test*']
|
12
|
+
spec.extensions = ['ext/extconf.rb']
|
13
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
14
|
+
|
15
|
+
spec.rubyforge_project = 'win32utils'
|
16
|
+
spec.required_ruby_version = '>= 1.8.2'
|
17
|
+
spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST', 'ext/win32/api.c']
|
18
|
+
|
19
|
+
spec.add_development_dependency('test-unit', '>= 2.5.0')
|
20
|
+
|
21
|
+
spec.description = <<-EOF
|
22
|
+
The Win32::API library is meant as a replacement for the Win32API
|
23
|
+
library that ships as part of the standard library. It contains several
|
24
|
+
advantages over Win32API, including callback support, raw function
|
25
|
+
pointers, an additional string type, and more.
|
26
|
+
EOF
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: win32-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.5.0
|
5
|
+
platform: universal-mingw32
|
6
|
+
authors:
|
7
|
+
- Daniel J. Berger
|
8
|
+
- Park Heesob
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: test-unit
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.5.0
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 2.5.0
|
28
|
+
description: |2
|
29
|
+
The Win32::API library is meant as a replacement for the Win32API
|
30
|
+
library that ships as part of the standard library. It contains several
|
31
|
+
advantages over Win32API, including callback support, raw function
|
32
|
+
pointers, an additional string type, and more.
|
33
|
+
email: djberg96@gmail.com
|
34
|
+
executables: []
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files:
|
37
|
+
- README
|
38
|
+
- CHANGES
|
39
|
+
- MANIFEST
|
40
|
+
- ext/win32/api.c
|
41
|
+
files:
|
42
|
+
- CHANGES
|
43
|
+
- lib/win32/api.rb
|
44
|
+
- lib/win32/ruby18/win32/api.so
|
45
|
+
- lib/win32/ruby19/win32/api.so
|
46
|
+
- lib/win32/ruby2_32/win32/api.so
|
47
|
+
- lib/win32/ruby2_64/win32/api.so
|
48
|
+
- MANIFEST
|
49
|
+
- Rakefile
|
50
|
+
- README
|
51
|
+
- test/test_win32_api.rb
|
52
|
+
- test/test_win32_api_callback.rb
|
53
|
+
- test/test_win32_api_function.rb
|
54
|
+
- win32-api.gemspec
|
55
|
+
- ext/win32/api.c
|
56
|
+
homepage: http://github.com/djberg96/win32-api
|
57
|
+
licenses:
|
58
|
+
- Artistic 2.0
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.8.2
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project: win32utils
|
76
|
+
rubygems_version: 2.0.7
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: A superior replacement for Win32API
|
80
|
+
test_files:
|
81
|
+
- test/test_win32_api.rb
|
82
|
+
- test/test_win32_api_callback.rb
|
83
|
+
- test/test_win32_api_function.rb
|