chef-win32-api 1.11.0

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.
@@ -0,0 +1,15 @@
1
+ ##########################################################################
2
+ # extconf.rb
3
+ #
4
+ # The Windows::API binary should be built using the Rake task, i.e.
5
+ # 'rake build' or 'rake install'.
6
+ ##########################################################################
7
+ require 'mkmf'
8
+
9
+ if RbConfig::CONFIG['host_os'] =~ /mingw/
10
+ $CFLAGS << ' -fno-omit-frame-pointer'
11
+ end
12
+
13
+ have_func('strncpy_s')
14
+
15
+ create_makefile('win32/api')
data/lib/win32/api.rb ADDED
@@ -0,0 +1 @@
1
+ require "win32/api.so"
@@ -0,0 +1,151 @@
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.10.1', 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_last_error
47
+ @gfa.call('C:/foobarbazblah')
48
+ error_file_not_found = 2
49
+ assert_equal(error_file_not_found, API.last_error)
50
+ end
51
+
52
+ def test_dll_name
53
+ assert_respond_to(@gcd, :dll_name)
54
+ assert_equal('kernel32', @gcd.dll_name)
55
+ end
56
+
57
+ def test_function_name
58
+ assert_respond_to(@gcd, :function_name)
59
+ assert_equal('GetCurrentDirectory', @gcd.function_name)
60
+ assert_equal('strstr', @str.function_name)
61
+ end
62
+
63
+ def test_effective_function_name_default
64
+ assert_respond_to(@gcd, :effective_function_name)
65
+ assert_equal('GetCurrentDirectoryA', @gcd.effective_function_name)
66
+ assert_equal('strstr', @str.effective_function_name)
67
+ end
68
+
69
+ def test_effective_function_name_default_explicit_ansi
70
+ @gcd = API.new('GetCurrentDirectoryA', 'LP')
71
+ assert_equal('GetCurrentDirectoryA', @gcd.effective_function_name)
72
+ end
73
+
74
+ def test_effective_function_name_default_explicit_wide
75
+ @gcd = API.new('GetCurrentDirectoryW', 'LP')
76
+ assert_equal('GetCurrentDirectoryW', @gcd.effective_function_name)
77
+ end
78
+
79
+ def test_prototype
80
+ assert_respond_to(@gcd, :prototype)
81
+ assert_equal(['L', 'P'], @gcd.prototype)
82
+ end
83
+
84
+ def test_return_type
85
+ assert_respond_to(@gcd, :return_type)
86
+ assert_equal('L', @gcd.return_type)
87
+ end
88
+
89
+ def test_constructor_high_iteration
90
+ assert_nothing_raised{
91
+ 1000.times{ API.new('GetUserName', 'P', 'P', 'advapi32') }
92
+ }
93
+ end
94
+
95
+ def test_constructor_expected_failures
96
+ assert_raise(ArgumentError){ API.new }
97
+ assert_raise(ArgumentError){ API.new('GetUserName', ('L' * 21), 'X') }
98
+ assert_raise(API::LoadLibraryError){ API.new('GetUserName', 'PL', 'I', 'foo') }
99
+ assert_raise(API::PrototypeError){ API.new('GetUserName', 'X', 'I', 'advapi32') }
100
+ assert_raise(API::PrototypeError){ API.new('GetUserName', 'PL', 'X', 'advapi32') }
101
+ end
102
+
103
+ test "constructor returns expected error message if function not found" do
104
+ msg = "Unable to load function "
105
+ assert_raise_message(msg + "'Zap', 'ZapA', or 'ZapW'"){ API.new('Zap') }
106
+ assert_raise_message(msg + "'strxxx'"){ API.new('strxxx', 'P', 'L', 'msvcrt') }
107
+ end
108
+
109
+ test "constructor returns expected error message if prototype is invalid" do
110
+ msg = "Illegal prototype 'X'"
111
+ assert_raise_message(msg){ API.new('GetUserName', 'X', 'I', 'advapi32') }
112
+ end
113
+
114
+ test "constructor returns expected error message if return type is invalid" do
115
+ msg = "Illegal return type 'Y'"
116
+ assert_raise_message(msg){ API.new('GetUserName', 'PL', 'Y', 'advapi32') }
117
+ end
118
+
119
+ test "constructor returns expected error message if too many parameters" do
120
+ msg = "too many parameters: 25"
121
+ assert_raise_message(msg){ API.new('GetFileAttributes', 'S' * 25, 'L') }
122
+ end
123
+
124
+ test "call method returns expected error message if too many parameters" do
125
+ msg = "wrong number of parameters: expected 2, got 3"
126
+ assert_raise_message(msg){ @str.call('test', 'test', 'test') }
127
+ end
128
+
129
+ def test_call_expected_failures
130
+ assert_raise(TypeError){ @gcd.call('test', @buf) }
131
+ end
132
+
133
+ def test_error_classes
134
+ assert_not_nil(Win32::API::Error)
135
+ assert_not_nil(Win32::API::LoadLibraryError)
136
+ assert_not_nil(Win32::API::PrototypeError)
137
+ end
138
+
139
+ def test_error_class_relationships
140
+ assert_kind_of(RuntimeError, Win32::API::Error.new)
141
+ assert_kind_of(Win32::API::Error, Win32::API::LoadLibraryError.new)
142
+ assert_kind_of(Win32::API::Error, Win32::API::PrototypeError.new)
143
+ end
144
+
145
+ def teardown
146
+ @buf = nil
147
+ @gcd = nil
148
+ @gle = nil
149
+ @str = nil
150
+ end
151
+ end
@@ -0,0 +1,75 @@
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
+ omit "Callback feature is not handled properly for now"
49
+ assert_nothing_raised{
50
+ @callback = API::Callback.new('LP', 'I'){ |handle, param|
51
+ buf = "\0" * 200
52
+ @api_gwt.call(handle, buf, 200);
53
+ buf.index(param).nil? ? true : false
54
+ }
55
+ }
56
+ assert_nothing_raised{ @api_ew.call(@callback, 'UEDIT32') }
57
+ end
58
+
59
+ def test_constructor_expected_errors
60
+ assert_raise(API::PrototypeError){ API::Callback.new('X') }
61
+ assert_raise(API::PrototypeError){ API::Callback.new('L', 'Y') }
62
+ end
63
+
64
+ def test_constructor_expected_error_messages
65
+ assert_raise_message("Illegal prototype 'X'"){ API::Callback.new('X') }
66
+ assert_raise_message("Illegal return type 'Y'"){ API::Callback.new('L', 'Y') }
67
+ end
68
+
69
+ def teardown
70
+ @buffer = nil
71
+ @api_ew = nil
72
+ @api_gwt = nil
73
+ @callback = nil
74
+ end
75
+ 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
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chef-win32-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.11.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel J. Berger
8
+ - Park Heesob
9
+ - Hiroshi Hatake
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2025-03-05 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: 3.6.7
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 3.6.7
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake-compiler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 1.2.9
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.2.9
56
+ description: |2
57
+ The Win32::API library is meant as a replacement for the Win32API
58
+ library that ships as part of the standard library. It contains several
59
+ advantages over Win32API, including callback support, raw function
60
+ pointers, an additional string type, and more.
61
+ email: djberg96@gmail.com
62
+ executables: []
63
+ extensions:
64
+ - ext/win32/extconf.rb
65
+ extra_rdoc_files:
66
+ - CHANGES
67
+ - MANIFEST
68
+ - ext/win32/api.c
69
+ files:
70
+ - CHANGES
71
+ - Dockerfile
72
+ - Dockerfile.trunk
73
+ - Gemfile
74
+ - MANIFEST
75
+ - README.md
76
+ - RELEASE.md
77
+ - Rakefile
78
+ - appveyor.yml
79
+ - build-gem.bat
80
+ - chef-win32-api.gemspec
81
+ - ext/win32/api.c
82
+ - ext/win32/extconf.rb
83
+ - lib/win32/api.rb
84
+ - test/test_win32_api.rb
85
+ - test/test_win32_api_callback.rb
86
+ - test/test_win32_api_function.rb
87
+ homepage: http://github.com/cosmo0920/win32-api
88
+ licenses:
89
+ - Artistic-2.0
90
+ metadata: {}
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 3.1.6
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubygems_version: 3.6.5
106
+ specification_version: 4
107
+ summary: A superior replacement for Win32API
108
+ test_files:
109
+ - test/test_win32_api.rb
110
+ - test/test_win32_api_callback.rb
111
+ - test/test_win32_api_function.rb