win32-api 1.4.6-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/lib/win32/api.so ADDED
Binary file
@@ -0,0 +1,140 @@
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 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'win32/api'
11
+ require 'test/unit'
12
+ include Win32
13
+
14
+ class TC_Win32_API < Test::Unit::TestCase
15
+ def setup
16
+ @buf = 0.chr * 260
17
+ @gfa = API.new('GetFileAttributes', 'S', 'L')
18
+ @gcd = API.new('GetCurrentDirectory', 'LP')
19
+ @gle = API.new('GetLastError', 'V', 'L')
20
+ @str = API.new('strstr', 'PP', 'P', 'msvcrt')
21
+ end
22
+
23
+ def test_version
24
+ assert_equal('1.4.5', API::VERSION)
25
+ end
26
+
27
+ def test_constructor_basic
28
+ assert_nothing_raised{ API.new('GetCurrentDirectory') }
29
+ assert_nothing_raised{ API.new('GetCurrentDirectory', 'LP') }
30
+ assert_nothing_raised{ API.new('GetCurrentDirectory', 'LP', 'L') }
31
+ assert_nothing_raised{ API.new('GetCurrentDirectory', 'LP', 'L', 'kernel32') }
32
+ end
33
+
34
+ def test_call
35
+ assert_respond_to(@gcd, :call)
36
+ assert_nothing_raised{ @gcd.call(@buf.length, @buf) }
37
+ assert_equal(Dir.pwd.tr('/', "\\"), @buf.strip)
38
+ end
39
+
40
+ def test_call_with_void
41
+ assert_nothing_raised{ @gle.call }
42
+ assert_nothing_raised{ @gle.call(nil) }
43
+ end
44
+
45
+ def test_call_return_value_on_failure
46
+ assert_equal(0xFFFFFFFF, @gfa.call('C:/foobarbazblah'))
47
+ end
48
+
49
+ def test_dll_name
50
+ assert_respond_to(@gcd, :dll_name)
51
+ assert_equal('kernel32', @gcd.dll_name)
52
+ end
53
+
54
+ def test_function_name
55
+ assert_respond_to(@gcd, :function_name)
56
+ assert_equal('GetCurrentDirectory', @gcd.function_name)
57
+ assert_equal('strstr', @str.function_name)
58
+ end
59
+
60
+ def test_effective_function_name_default
61
+ assert_respond_to(@gcd, :effective_function_name)
62
+ assert_equal('GetCurrentDirectoryA', @gcd.effective_function_name)
63
+ assert_equal('strstr', @str.effective_function_name)
64
+ end
65
+
66
+ def test_effective_function_name_default_explicit_ansi
67
+ @gcd = API.new('GetCurrentDirectoryA', 'LP')
68
+ assert_equal('GetCurrentDirectoryA', @gcd.effective_function_name)
69
+ end
70
+
71
+ def test_effective_function_name_default_explicit_wide
72
+ @gcd = API.new('GetCurrentDirectoryW', 'LP')
73
+ assert_equal('GetCurrentDirectoryW', @gcd.effective_function_name)
74
+ end
75
+
76
+ def test_prototype
77
+ assert_respond_to(@gcd, :prototype)
78
+ assert_equal(['L', 'P'], @gcd.prototype)
79
+ end
80
+
81
+ def test_return_type
82
+ assert_respond_to(@gcd, :return_type)
83
+ assert_equal('L', @gcd.return_type)
84
+ end
85
+
86
+ def test_constructor_high_iteration
87
+ assert_nothing_raised{
88
+ 1000.times{ API.new('GetUserName', 'P', 'P', 'advapi32') }
89
+ }
90
+ end
91
+
92
+ def test_constructor_expected_failures
93
+ assert_raise(ArgumentError){ API.new }
94
+ assert_raise(ArgumentError){ API.new('GetUserName', ('L' * 21), 'X') }
95
+ assert_raise(API::LoadLibraryError){ API.new('GetUserName', 'PL', 'I', 'foo') }
96
+ assert_raise(API::PrototypeError){ API.new('GetUserName', 'X', 'I', 'advapi32') }
97
+ assert_raise(API::PrototypeError){ API.new('GetUserName', 'PL', 'X', 'advapi32') }
98
+ end
99
+
100
+ def test_constructor_expected_failure_messages
101
+ assert_raise_message("Unable to load function 'Zap', 'ZapA', or 'ZapW'"){
102
+ API.new('Zap')
103
+ }
104
+
105
+ assert_raise_message("Unable to load function 'strxxx'"){
106
+ API.new('strxxx', 'P', 'L', 'msvcrt')
107
+ }
108
+
109
+ assert_raise_message("Illegal prototype 'X'"){
110
+ API.new('GetUserName', 'X', 'I', 'advapi32')
111
+ }
112
+
113
+ assert_raise_message("Illegal return type 'Y'"){
114
+ API.new('GetUserName', 'PL', 'Y', 'advapi32')
115
+ }
116
+ end
117
+
118
+ def test_call_expected_failures
119
+ assert_raise(TypeError){ @gcd.call('test', @buf) }
120
+ end
121
+
122
+ def test_error_classes
123
+ assert_not_nil(Win32::API::Error)
124
+ assert_not_nil(Win32::API::LoadLibraryError)
125
+ assert_not_nil(Win32::API::PrototypeError)
126
+ end
127
+
128
+ def test_error_class_relationships
129
+ assert_kind_of(RuntimeError, Win32::API::Error.new)
130
+ assert_kind_of(Win32::API::Error, Win32::API::LoadLibraryError.new)
131
+ assert_kind_of(Win32::API::Error, Win32::API::PrototypeError.new)
132
+ end
133
+
134
+ def teardown
135
+ @buf = nil
136
+ @gcd = nil
137
+ @gle = nil
138
+ @str = nil
139
+ end
140
+ 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,29 @@
1
+ require 'rubygems'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'win32-api'
5
+ spec.version = '1.4.6'
6
+ spec.authors = ['Daniel J. Berger', 'Park Heesob']
7
+ spec.license = 'Artistic 2.0'
8
+ spec.email = 'djberg96@gmail.com'
9
+ spec.homepage = 'http://www.rubyforge.org/projects/win32utils'
10
+ spec.platform = Gem::Platform::RUBY
11
+ spec.summary = 'A superior replacement for Win32API'
12
+ spec.has_rdoc = true
13
+ spec.test_files = Dir['test/test*']
14
+ spec.extensions = ['ext/extconf.rb']
15
+ spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
16
+
17
+ spec.rubyforge_project = 'win32utils'
18
+ spec.required_ruby_version = '>= 1.8.2'
19
+ spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST', 'ext/win32/api.c']
20
+
21
+ spec.add_development_dependency('test-unit', '>= 2.0.6')
22
+
23
+ spec.description = <<-EOF
24
+ The Win32::API library is meant as a replacement for the Win32API
25
+ library that ships as part of the standard library. It contains several
26
+ advantages over Win32API, including callback support, raw function
27
+ pointers, an additional string type, and more.
28
+ EOF
29
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: win32-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.6
5
+ platform: x86-mingw32
6
+ authors:
7
+ - Daniel J. Berger
8
+ - Park Heesob
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-02-09 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: test-unit
18
+ type: :development
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 2.0.6
25
+ version:
26
+ description: " The Win32::API library is meant as a replacement for the Win32API\n library that ships as part of the standard library. It contains several\n advantages over Win32API, including callback support, raw function\n pointers, an additional string type, and more.\n"
27
+ email: djberg96@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - README
34
+ - CHANGES
35
+ - MANIFEST
36
+ - ext/win32/api.c
37
+ files:
38
+ - CHANGES
39
+ - lib/win32/api.so
40
+ - MANIFEST
41
+ - Rakefile
42
+ - README
43
+ - test/test_win32_api.rb
44
+ - test/test_win32_api_callback.rb
45
+ - test/test_win32_api_function.rb
46
+ - win32-api.gemspec
47
+ - ext/win32/api.c
48
+ has_rdoc: true
49
+ homepage: http://www.rubyforge.org/projects/win32utils
50
+ licenses:
51
+ - Artistic 2.0
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.2
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project: win32utils
72
+ rubygems_version: 1.3.5
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: A superior replacement for Win32API
76
+ test_files:
77
+ - test/test_win32_api.rb
78
+ - test/test_win32_api_callback.rb
79
+ - test/test_win32_api_function.rb