windows-api 0.4.4 → 0.4.5

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.
@@ -1,60 +1,60 @@
1
- require 'windows/unicode'
2
- require 'windows/msvcrt/string'
3
-
4
- # This is a class that simplifies wide string handling. It is NOT meant
5
- # for general consumption, but for internal use by the Win32Utils Team.
6
- # Use at your own risk.
7
- #
8
- class WideString < String
9
- include Windows::Unicode
10
- include Windows::MSVCRT::String
11
-
12
- ACP = CP_ACP
13
- UTF7 = CP_UTF7
14
- UTF8 = CP_UTF8
15
-
16
- # Get or set the encoding of the wide string object
17
- #
18
- attr_accessor :encoding
19
-
20
- # Creates a new wide +string+ with the given +encoding+, or UTF8 if
21
- # no encoding is specified.
22
- #
23
- def initialize(string, encoding = UTF8)
24
- super(multi_to_wide(string, encoding))
25
- @encoding = encoding
26
- end
27
-
28
- # Returns the multibyte version of the wide string.
29
- #
30
- def to_multi
31
- wide_to_multi(self, @encoding)
32
- end
33
-
34
- # Replaces the wide string with a multibyte version.
35
- #
36
- def to_multi!
37
- self.replace(wide_to_multi(self, @encoding))
38
- end
39
-
40
- alias to_s to_multi
41
- alias to_str to_multi
42
- alias inspect to_multi
43
-
44
- # Strips the trailing two null characters from the string.
45
- #
46
- def wstrip
47
- self[0..-3] if string[-2..-1] == "\000\000"
48
- end
49
-
50
- # The length of the wide string in chars.
51
- #
52
- def length
53
- wcslen(self) * 2
54
- end
55
-
56
- # The size of the wide string in bytes.
57
- def size
58
- wcslen(self)
59
- end
1
+ require 'windows/unicode'
2
+ require 'windows/msvcrt/string'
3
+
4
+ # This is a class that simplifies wide string handling. It is NOT meant
5
+ # for general consumption, but for internal use by the Win32Utils Team.
6
+ # Use at your own risk.
7
+ #
8
+ class WideString < String
9
+ include Windows::Unicode
10
+ include Windows::MSVCRT::String
11
+
12
+ ACP = CP_ACP
13
+ UTF7 = CP_UTF7
14
+ UTF8 = CP_UTF8
15
+
16
+ # Get or set the encoding of the wide string object
17
+ #
18
+ attr_accessor :encoding
19
+
20
+ # Creates a new wide +string+ with the given +encoding+, or UTF8 if
21
+ # no encoding is specified.
22
+ #
23
+ def initialize(string, encoding = UTF8)
24
+ super(multi_to_wide(string, encoding))
25
+ @encoding = encoding
26
+ end
27
+
28
+ # Returns the multibyte version of the wide string.
29
+ #
30
+ def to_multi
31
+ wide_to_multi(self, @encoding)
32
+ end
33
+
34
+ # Replaces the wide string with a multibyte version.
35
+ #
36
+ def to_multi!
37
+ self.replace(wide_to_multi(self, @encoding))
38
+ end
39
+
40
+ alias to_s to_multi
41
+ alias to_str to_multi
42
+ alias inspect to_multi
43
+
44
+ # Strips the trailing two null characters from the string.
45
+ #
46
+ def wstrip
47
+ self[0..-3] if string[-2..-1] == "\000\000"
48
+ end
49
+
50
+ # The length of the wide string in chars.
51
+ #
52
+ def length
53
+ wcslen(self) * 2
54
+ end
55
+
56
+ # The size of the wide string in bytes.
57
+ def size
58
+ wcslen(self)
59
+ end
60
60
  end
@@ -1,171 +1,171 @@
1
- ############################################################################
2
- # test_windows_api.rb
3
- #
4
- # Test case for the Windows::API class. You should run this as Rake task,
5
- # i.e. 'rake test', instead of running it directly.
6
- ############################################################################
7
- require 'windows/api'
8
- require 'test-unit'
9
- include Windows
10
-
11
- module Windows
12
- module Test
13
- API.auto_namespace = 'Windows::Test'
14
- API.auto_unicode = true
15
- API.auto_method = true
16
- API.auto_constant = true
17
- $test_method = API.new('GetCurrentDirectory', 'PP', 'L')
18
- end
19
-
20
- module Foo
21
- API.auto_namespace = 'Windows::Foo'
22
- API.auto_unicode = false
23
- API.auto_method = false
24
- API.auto_constant = false
25
- $foo_method = API.new('GetSystemDirectory', 'PL', 'L')
26
- end
27
-
28
- module Bar
29
- API.auto_namespace = 'Windows::Bar'
30
- API.auto_constant = true
31
- API.auto_method = true
32
- $bar_method = API.new('GetUserName', 'PP', 'I', 'advapi32')
33
- end
34
-
35
- module Baz
36
- API.auto_namespace = 'Windows::Baz'
37
- API.auto_constant = true
38
- API.auto_method = true
39
-
40
- # No ANSI equivalent for ReadDirectoryChangesW
41
- $strstr = API.new('strstr', 'PP', 'P', 'msvcrt')
42
- $umask = API.new('_umask', 'I', 'I', 'msvcrt')
43
- $wave = API.new('waveOutGetNumDevs', 'V', 'I', 'winmm')
44
- $read = API.new('ReadDirectoryChangesW', 'LPLILPPP', 'B')
45
- end
46
- end
47
-
48
- class TC_Windows_API < Test::Unit::TestCase
49
- include Windows::Test
50
- include Windows::Foo
51
- include Windows::Bar
52
- include Windows::Baz
53
-
54
- def setup
55
- @buf = 0.chr * 256
56
- @runtimes = ['msvcrt', 'msvcr80', 'msvcr90', 'msvcr100']
57
- end
58
-
59
- def test_version
60
- assert_equal('0.4.4', API::VERSION)
61
- end
62
-
63
- def test_full_data_types
64
- assert_nothing_raised{
65
- API.new('GetWindowsDirectory', ['LPTSTR', 'UINT'], 'BOOL')
66
- }
67
- end
68
-
69
- def test_msvcrt_constant
70
- assert_true(@runtimes.include?(Windows::MSVCRT_DLL))
71
- end
72
-
73
- # Validate that funcs like 'strstr' get an uppercase constant like 'Strstr'
74
- def test_lower_case_to_capitalized_constant
75
- assert_not_nil(Windows::Baz::Strstr)
76
- assert_not_nil(Windows::Baz::Umask)
77
- assert_not_nil(Windows::Baz::WaveOutGetNumDevs)
78
- end
79
-
80
- def test_explicit_wide_function_only
81
- assert_not_nil(Windows::Baz::ReadDirectoryChangesW)
82
- assert_false(Windows::Baz.constants.include?('ReadDirectoryChanges'))
83
- assert_false(Windows::Baz.constants.include?('ReadDirectoryChangesA'))
84
- end
85
-
86
- def test_lower_case_auto_methods
87
- assert_respond_to(self, :strstr)
88
- assert_respond_to(self, :umask)
89
- assert_respond_to(self, :_umask)
90
- assert_respond_to(self, :waveOutGetNumDevs)
91
- assert_equal('llo', strstr('hello', 'l'))
92
- end
93
-
94
- def test_auto_unicode
95
- assert_not_nil(Windows::Bar::GetUserName)
96
- assert_respond_to(self, :GetUserName)
97
- assert_not_respond_to(self, :GetUserNameA)
98
- assert_not_respond_to(self, :GetUserNameW)
99
- end
100
-
101
- def test_auto_constant
102
- assert_not_nil(Windows::Test::GetCurrentDirectory)
103
- assert_not_nil(Windows::Bar::GetUserName)
104
- assert_kind_of(Win32::API, Windows::Test::GetCurrentDirectory)
105
- assert_respond_to(Windows::Test::GetCurrentDirectory, :call)
106
- end
107
-
108
- def test_auto_method
109
- assert_respond_to(self, :GetCurrentDirectory)
110
- assert_respond_to(self, :GetCurrentDirectoryA)
111
- assert_respond_to(self, :GetCurrentDirectoryW)
112
- assert_not_respond_to(self, :GetSystemDirectory)
113
- assert_not_respond_to(self, :GetSystemDirectoryA)
114
- assert_not_respond_to(self, :GetSystemDirectoryW)
115
- end
116
-
117
- def test_call
118
- assert_respond_to($test_method, :call)
119
- assert_respond_to($foo_method, :call)
120
- assert_nothing_raised{ $test_method.call(@buf.length, @buf) }
121
- assert_nothing_raised{ $foo_method.call(@buf, @buf.length) }
122
- end
123
-
124
- def test_dll_name
125
- assert_respond_to($test_method, :dll_name)
126
- assert_equal('kernel32', $test_method.dll_name)
127
- end
128
-
129
- def test_function_name
130
- assert_respond_to($test_method, :function_name)
131
- assert_equal('GetCurrentDirectory', $test_method.function_name)
132
- end
133
-
134
- def test_prototype
135
- assert_respond_to($test_method, :prototype)
136
- assert_equal(['P', 'P'], $test_method.prototype)
137
- end
138
-
139
- def test_return_type
140
- assert_respond_to($test_method, :return_type)
141
- assert_equal('L', $test_method.return_type)
142
- end
143
-
144
- def test_effective_function_name
145
- assert_respond_to($test_method, :effective_function_name)
146
- assert_equal('GetCurrentDirectoryA', $test_method.effective_function_name)
147
- assert_equal('strstr', $strstr.effective_function_name)
148
- assert_equal('waveOutGetNumDevs', $wave.effective_function_name)
149
- assert_equal('ReadDirectoryChangesW', $read.effective_function_name)
150
- end
151
-
152
- def test_bad_prototype_raises_error
153
- assert_raise(Win32::API::PrototypeError){
154
- Windows::API.new('GetCurrentDirectory', 'XL', 'L')
155
- }
156
- assert_raise(Win32::API::PrototypeError){
157
- Windows::API.new('GetCurrentDirectory', 'PL', 'X')
158
- }
159
- end
160
-
161
- def test_bad_function_raises_error
162
- assert_raise(Win32::API::LoadLibraryError){
163
- Windows::API.new('GetCurrentFooBar', 'LL', 'L')
164
- }
165
- end
166
-
167
- def teardown
168
- @buf = nil
169
- @runtimes = nil
170
- end
171
- end
1
+ ############################################################################
2
+ # test_windows_api.rb
3
+ #
4
+ # Test case for the Windows::API class. You should run this as Rake task,
5
+ # i.e. 'rake test', instead of running it directly.
6
+ ############################################################################
7
+ require 'windows/api'
8
+ require 'test-unit'
9
+ include Windows
10
+
11
+ module Windows
12
+ module Test
13
+ API.auto_namespace = 'Windows::Test'
14
+ API.auto_unicode = true
15
+ API.auto_method = true
16
+ API.auto_constant = true
17
+ $test_method = API.new('GetCurrentDirectory', 'PP', 'L')
18
+ end
19
+
20
+ module Foo
21
+ API.auto_namespace = 'Windows::Foo'
22
+ API.auto_unicode = false
23
+ API.auto_method = false
24
+ API.auto_constant = false
25
+ $foo_method = API.new('GetSystemDirectory', 'PL', 'L')
26
+ end
27
+
28
+ module Bar
29
+ API.auto_namespace = 'Windows::Bar'
30
+ API.auto_constant = true
31
+ API.auto_method = true
32
+ $bar_method = API.new('GetUserName', 'PP', 'I', 'advapi32')
33
+ end
34
+
35
+ module Baz
36
+ API.auto_namespace = 'Windows::Baz'
37
+ API.auto_constant = true
38
+ API.auto_method = true
39
+
40
+ # No ANSI equivalent for ReadDirectoryChangesW
41
+ $strstr = API.new('strstr', 'PP', 'P', 'msvcrt')
42
+ $umask = API.new('_umask', 'I', 'I', 'msvcrt')
43
+ $wave = API.new('waveOutGetNumDevs', 'V', 'I', 'winmm')
44
+ $read = API.new('ReadDirectoryChangesW', 'LPLILPPP', 'B')
45
+ end
46
+ end
47
+
48
+ class TC_Windows_API < Test::Unit::TestCase
49
+ include Windows::Test
50
+ include Windows::Foo
51
+ include Windows::Bar
52
+ include Windows::Baz
53
+
54
+ def setup
55
+ @buf = 0.chr * 256
56
+ @runtimes = ['msvcrt', 'msvcr80', 'msvcr90', 'msvcr100', 'ucrtbase']
57
+ end
58
+
59
+ def test_version
60
+ assert_equal('0.4.4', API::VERSION)
61
+ end
62
+
63
+ def test_full_data_types
64
+ assert_nothing_raised{
65
+ API.new('GetWindowsDirectory', ['LPTSTR', 'UINT'], 'BOOL')
66
+ }
67
+ end
68
+
69
+ def test_msvcrt_constant
70
+ assert_true(@runtimes.include?(Windows::MSVCRT_DLL))
71
+ end
72
+
73
+ # Validate that funcs like 'strstr' get an uppercase constant like 'Strstr'
74
+ def test_lower_case_to_capitalized_constant
75
+ assert_not_nil(Windows::Baz::Strstr)
76
+ assert_not_nil(Windows::Baz::Umask)
77
+ assert_not_nil(Windows::Baz::WaveOutGetNumDevs)
78
+ end
79
+
80
+ def test_explicit_wide_function_only
81
+ assert_not_nil(Windows::Baz::ReadDirectoryChangesW)
82
+ assert_false(Windows::Baz.constants.include?('ReadDirectoryChanges'))
83
+ assert_false(Windows::Baz.constants.include?('ReadDirectoryChangesA'))
84
+ end
85
+
86
+ def test_lower_case_auto_methods
87
+ assert_respond_to(self, :strstr)
88
+ assert_respond_to(self, :umask)
89
+ assert_respond_to(self, :_umask)
90
+ assert_respond_to(self, :waveOutGetNumDevs)
91
+ assert_equal('llo', strstr('hello', 'l'))
92
+ end
93
+
94
+ def test_auto_unicode
95
+ assert_not_nil(Windows::Bar::GetUserName)
96
+ assert_respond_to(self, :GetUserName)
97
+ assert_not_respond_to(self, :GetUserNameA)
98
+ assert_not_respond_to(self, :GetUserNameW)
99
+ end
100
+
101
+ def test_auto_constant
102
+ assert_not_nil(Windows::Test::GetCurrentDirectory)
103
+ assert_not_nil(Windows::Bar::GetUserName)
104
+ assert_kind_of(Win32::API, Windows::Test::GetCurrentDirectory)
105
+ assert_respond_to(Windows::Test::GetCurrentDirectory, :call)
106
+ end
107
+
108
+ def test_auto_method
109
+ assert_respond_to(self, :GetCurrentDirectory)
110
+ assert_respond_to(self, :GetCurrentDirectoryA)
111
+ assert_respond_to(self, :GetCurrentDirectoryW)
112
+ assert_not_respond_to(self, :GetSystemDirectory)
113
+ assert_not_respond_to(self, :GetSystemDirectoryA)
114
+ assert_not_respond_to(self, :GetSystemDirectoryW)
115
+ end
116
+
117
+ def test_call
118
+ assert_respond_to($test_method, :call)
119
+ assert_respond_to($foo_method, :call)
120
+ assert_nothing_raised{ $test_method.call(@buf.length, @buf) }
121
+ assert_nothing_raised{ $foo_method.call(@buf, @buf.length) }
122
+ end
123
+
124
+ def test_dll_name
125
+ assert_respond_to($test_method, :dll_name)
126
+ assert_equal('kernel32', $test_method.dll_name)
127
+ end
128
+
129
+ def test_function_name
130
+ assert_respond_to($test_method, :function_name)
131
+ assert_equal('GetCurrentDirectory', $test_method.function_name)
132
+ end
133
+
134
+ def test_prototype
135
+ assert_respond_to($test_method, :prototype)
136
+ assert_equal(['P', 'P'], $test_method.prototype)
137
+ end
138
+
139
+ def test_return_type
140
+ assert_respond_to($test_method, :return_type)
141
+ assert_equal('L', $test_method.return_type)
142
+ end
143
+
144
+ def test_effective_function_name
145
+ assert_respond_to($test_method, :effective_function_name)
146
+ assert_equal('GetCurrentDirectoryA', $test_method.effective_function_name)
147
+ assert_equal('strstr', $strstr.effective_function_name)
148
+ assert_equal('waveOutGetNumDevs', $wave.effective_function_name)
149
+ assert_equal('ReadDirectoryChangesW', $read.effective_function_name)
150
+ end
151
+
152
+ def test_bad_prototype_raises_error
153
+ assert_raise(Win32::API::PrototypeError){
154
+ Windows::API.new('GetCurrentDirectory', 'XL', 'L')
155
+ }
156
+ assert_raise(Win32::API::PrototypeError){
157
+ Windows::API.new('GetCurrentDirectory', 'PL', 'X')
158
+ }
159
+ end
160
+
161
+ def test_bad_function_raises_error
162
+ assert_raise(Win32::API::LoadLibraryError){
163
+ Windows::API.new('GetCurrentFooBar', 'LL', 'L')
164
+ }
165
+ end
166
+
167
+ def teardown
168
+ @buf = nil
169
+ @runtimes = nil
170
+ end
171
+ end
data/windows-api.gemspec CHANGED
@@ -2,19 +2,21 @@ require 'rubygems'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'windows-api'
5
- spec.version = '0.4.4'
6
- spec.author = 'Daniel J. Berger'
5
+ spec.version = '0.4.5'
6
+ spec.authors = ['Daniel J. Berger', 'Hiroshi Hatake']
7
7
  spec.license = 'Artistic 2.0'
8
- spec.email = 'djberg96@gmail.com'
8
+ spec.email = ['djberg96@gmail.com', "cosmo0920.oucc@gmail.com"]
9
9
  spec.homepage = 'https://github.com/djberg96/windows-api'
10
10
  spec.summary = 'An easier way to create methods using Win32::API'
11
11
  spec.test_files = Dir['test/test*.rb']
12
12
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
13
 
14
- spec.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
14
+ spec.extra_rdoc_files = ['README.rdoc', 'CHANGES', 'MANIFEST']
15
15
 
16
16
  spec.add_dependency('win32-api', '>= 1.4.5')
17
17
  spec.add_development_dependency('test-unit')
18
+ spec.add_development_dependency('rake')
19
+ spec.add_development_dependency('windows-pr','~>1.2.4')
18
20
 
19
21
  spec.description = <<-EOF
20
22
  The windows-api library provides features over and above the basic
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: windows-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
- autorequire:
8
+ - Hiroshi Hatake
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-03-19 00:00:00.000000000 Z
12
+ date: 2022-06-09 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: win32-api
@@ -38,24 +39,57 @@ dependencies:
38
39
  - - ">="
39
40
  - !ruby/object:Gem::Version
40
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: windows-pr
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.2.4
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.2.4
41
70
  description: |2
42
71
  The windows-api library provides features over and above the basic
43
72
  interface provided by the win32-api library. Features included automatic
44
73
  constant generation, automatic defintion of ANSI and Unicode methods,
45
74
  special handling of functions that return a boolean value, and the
46
75
  ability to use native Windows type declarations.
47
- email: djberg96@gmail.com
76
+ email:
77
+ - djberg96@gmail.com
78
+ - cosmo0920.oucc@gmail.com
48
79
  executables: []
49
80
  extensions: []
50
81
  extra_rdoc_files:
51
- - README
82
+ - README.rdoc
52
83
  - CHANGES
53
84
  - MANIFEST
54
85
  files:
55
86
  - CHANGES
87
+ - Gemfile
88
+ - Gemfile.lock
56
89
  - MANIFEST
57
- - README
90
+ - README.rdoc
58
91
  - Rakefile
92
+ - appveyor.yml
59
93
  - lib/windows/api.rb
60
94
  - lib/windows/wide_string.rb
61
95
  - test/test_wide_string.rb
@@ -65,7 +99,7 @@ homepage: https://github.com/djberg96/windows-api
65
99
  licenses:
66
100
  - Artistic 2.0
67
101
  metadata: {}
68
- post_install_message:
102
+ post_install_message:
69
103
  rdoc_options: []
70
104
  require_paths:
71
105
  - lib
@@ -80,9 +114,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
114
  - !ruby/object:Gem::Version
81
115
  version: '0'
82
116
  requirements: []
83
- rubyforge_project:
84
- rubygems_version: 2.4.5
85
- signing_key:
117
+ rubygems_version: 3.2.32
118
+ signing_key:
86
119
  specification_version: 4
87
120
  summary: An easier way to create methods using Win32::API
88
121
  test_files: