win32-api 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,135 +1,135 @@
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
- @gcd = API.new('GetCurrentDirectory', 'LP')
18
- @gle = API.new('GetLastError', 'V', 'L')
19
- @str = API.new('strstr', 'PP', 'P', 'msvcrt')
20
- end
21
-
22
- def test_version
23
- assert_equal('1.4.2', API::VERSION)
24
- end
25
-
26
- def test_constructor_basic
27
- assert_nothing_raised{ API.new('GetCurrentDirectory') }
28
- assert_nothing_raised{ API.new('GetCurrentDirectory', 'LP') }
29
- assert_nothing_raised{ API.new('GetCurrentDirectory', 'LP', 'L') }
30
- assert_nothing_raised{ API.new('GetCurrentDirectory', 'LP', 'L', 'kernel32') }
31
- end
32
-
33
- def test_call
34
- assert_respond_to(@gcd, :call)
35
- assert_nothing_raised{ @gcd.call(@buf.length, @buf) }
36
- assert_equal(Dir.pwd.tr('/', "\\"), @buf.strip)
37
- end
38
-
39
- def test_call_with_void
40
- assert_nothing_raised{ @gle.call }
41
- assert_nothing_raised{ @gle.call(nil) }
42
- end
43
-
44
- def test_dll_name
45
- assert_respond_to(@gcd, :dll_name)
46
- assert_equal('kernel32', @gcd.dll_name)
47
- end
48
-
49
- def test_function_name
50
- assert_respond_to(@gcd, :function_name)
51
- assert_equal('GetCurrentDirectory', @gcd.function_name)
52
- assert_equal('strstr', @str.function_name)
53
- end
54
-
55
- def test_effective_function_name_default
56
- assert_respond_to(@gcd, :effective_function_name)
57
- assert_equal('GetCurrentDirectoryA', @gcd.effective_function_name)
58
- assert_equal('strstr', @str.effective_function_name)
59
- end
60
-
61
- def test_effective_function_name_default_explicit_ansi
62
- @gcd = API.new('GetCurrentDirectoryA', 'LP')
63
- assert_equal('GetCurrentDirectoryA', @gcd.effective_function_name)
64
- end
65
-
66
- def test_effective_function_name_default_explicit_wide
67
- @gcd = API.new('GetCurrentDirectoryW', 'LP')
68
- assert_equal('GetCurrentDirectoryW', @gcd.effective_function_name)
69
- end
70
-
71
- def test_prototype
72
- assert_respond_to(@gcd, :prototype)
73
- assert_equal(['L', 'P'], @gcd.prototype)
74
- end
75
-
76
- def test_return_type
77
- assert_respond_to(@gcd, :return_type)
78
- assert_equal('L', @gcd.return_type)
79
- end
80
-
81
- def test_constructor_high_iteration
82
- assert_nothing_raised{
83
- 1000.times{ API.new('GetUserName', 'P', 'P', 'advapi32') }
84
- }
85
- end
86
-
87
- def test_constructor_expected_failures
88
- assert_raise(ArgumentError){ API.new }
89
- assert_raise(ArgumentError){ API.new('GetUserName', ('L' * 21), 'X') }
90
- assert_raise(API::LoadLibraryError){ API.new('GetUserName', 'PL', 'I', 'foo') }
91
- assert_raise(API::PrototypeError){ API.new('GetUserName', 'X', 'I', 'advapi32') }
92
- assert_raise(API::PrototypeError){ API.new('GetUserName', 'PL', 'X', 'advapi32') }
93
- end
94
-
95
- def test_constructor_expected_failure_messages
96
- assert_raise_message("Unable to load function 'Zap', 'ZapA', or 'ZapW'"){
97
- API.new('Zap')
98
- }
99
-
100
- assert_raise_message("Unable to load function 'strxxx'"){
101
- API.new('strxxx', 'P', 'L', 'msvcrt')
102
- }
103
-
104
- assert_raise_message("Illegal prototype 'X'"){
105
- API.new('GetUserName', 'X', 'I', 'advapi32')
106
- }
107
-
108
- assert_raise_message("Illegal return type 'Y'"){
109
- API.new('GetUserName', 'PL', 'Y', 'advapi32')
110
- }
111
- end
112
-
113
- def test_call_expected_failures
114
- assert_raise(TypeError){ @gcd.call('test', @buf) }
115
- end
116
-
117
- def test_error_classes
118
- assert_not_nil(Win32::API::Error)
119
- assert_not_nil(Win32::API::LoadLibraryError)
120
- assert_not_nil(Win32::API::PrototypeError)
121
- end
122
-
123
- def test_error_class_relationships
124
- assert_kind_of(RuntimeError, Win32::API::Error.new)
125
- assert_kind_of(Win32::API::Error, Win32::API::LoadLibraryError.new)
126
- assert_kind_of(Win32::API::Error, Win32::API::PrototypeError.new)
127
- end
128
-
129
- def teardown
130
- @buf = nil
131
- @gcd = nil
132
- @gle = nil
133
- @str = nil
134
- end
135
- end
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
+ @gcd = API.new('GetCurrentDirectory', 'LP')
18
+ @gle = API.new('GetLastError', 'V', 'L')
19
+ @str = API.new('strstr', 'PP', 'P', 'msvcrt')
20
+ end
21
+
22
+ def test_version
23
+ assert_equal('1.4.3', API::VERSION)
24
+ end
25
+
26
+ def test_constructor_basic
27
+ assert_nothing_raised{ API.new('GetCurrentDirectory') }
28
+ assert_nothing_raised{ API.new('GetCurrentDirectory', 'LP') }
29
+ assert_nothing_raised{ API.new('GetCurrentDirectory', 'LP', 'L') }
30
+ assert_nothing_raised{ API.new('GetCurrentDirectory', 'LP', 'L', 'kernel32') }
31
+ end
32
+
33
+ def test_call
34
+ assert_respond_to(@gcd, :call)
35
+ assert_nothing_raised{ @gcd.call(@buf.length, @buf) }
36
+ assert_equal(Dir.pwd.tr('/', "\\"), @buf.strip)
37
+ end
38
+
39
+ def test_call_with_void
40
+ assert_nothing_raised{ @gle.call }
41
+ assert_nothing_raised{ @gle.call(nil) }
42
+ end
43
+
44
+ def test_dll_name
45
+ assert_respond_to(@gcd, :dll_name)
46
+ assert_equal('kernel32', @gcd.dll_name)
47
+ end
48
+
49
+ def test_function_name
50
+ assert_respond_to(@gcd, :function_name)
51
+ assert_equal('GetCurrentDirectory', @gcd.function_name)
52
+ assert_equal('strstr', @str.function_name)
53
+ end
54
+
55
+ def test_effective_function_name_default
56
+ assert_respond_to(@gcd, :effective_function_name)
57
+ assert_equal('GetCurrentDirectoryA', @gcd.effective_function_name)
58
+ assert_equal('strstr', @str.effective_function_name)
59
+ end
60
+
61
+ def test_effective_function_name_default_explicit_ansi
62
+ @gcd = API.new('GetCurrentDirectoryA', 'LP')
63
+ assert_equal('GetCurrentDirectoryA', @gcd.effective_function_name)
64
+ end
65
+
66
+ def test_effective_function_name_default_explicit_wide
67
+ @gcd = API.new('GetCurrentDirectoryW', 'LP')
68
+ assert_equal('GetCurrentDirectoryW', @gcd.effective_function_name)
69
+ end
70
+
71
+ def test_prototype
72
+ assert_respond_to(@gcd, :prototype)
73
+ assert_equal(['L', 'P'], @gcd.prototype)
74
+ end
75
+
76
+ def test_return_type
77
+ assert_respond_to(@gcd, :return_type)
78
+ assert_equal('L', @gcd.return_type)
79
+ end
80
+
81
+ def test_constructor_high_iteration
82
+ assert_nothing_raised{
83
+ 1000.times{ API.new('GetUserName', 'P', 'P', 'advapi32') }
84
+ }
85
+ end
86
+
87
+ def test_constructor_expected_failures
88
+ assert_raise(ArgumentError){ API.new }
89
+ assert_raise(ArgumentError){ API.new('GetUserName', ('L' * 21), 'X') }
90
+ assert_raise(API::LoadLibraryError){ API.new('GetUserName', 'PL', 'I', 'foo') }
91
+ assert_raise(API::PrototypeError){ API.new('GetUserName', 'X', 'I', 'advapi32') }
92
+ assert_raise(API::PrototypeError){ API.new('GetUserName', 'PL', 'X', 'advapi32') }
93
+ end
94
+
95
+ def test_constructor_expected_failure_messages
96
+ assert_raise_message("Unable to load function 'Zap', 'ZapA', or 'ZapW'"){
97
+ API.new('Zap')
98
+ }
99
+
100
+ assert_raise_message("Unable to load function 'strxxx'"){
101
+ API.new('strxxx', 'P', 'L', 'msvcrt')
102
+ }
103
+
104
+ assert_raise_message("Illegal prototype 'X'"){
105
+ API.new('GetUserName', 'X', 'I', 'advapi32')
106
+ }
107
+
108
+ assert_raise_message("Illegal return type 'Y'"){
109
+ API.new('GetUserName', 'PL', 'Y', 'advapi32')
110
+ }
111
+ end
112
+
113
+ def test_call_expected_failures
114
+ assert_raise(TypeError){ @gcd.call('test', @buf) }
115
+ end
116
+
117
+ def test_error_classes
118
+ assert_not_nil(Win32::API::Error)
119
+ assert_not_nil(Win32::API::LoadLibraryError)
120
+ assert_not_nil(Win32::API::PrototypeError)
121
+ end
122
+
123
+ def test_error_class_relationships
124
+ assert_kind_of(RuntimeError, Win32::API::Error.new)
125
+ assert_kind_of(Win32::API::Error, Win32::API::LoadLibraryError.new)
126
+ assert_kind_of(Win32::API::Error, Win32::API::PrototypeError.new)
127
+ end
128
+
129
+ def teardown
130
+ @buf = nil
131
+ @gcd = nil
132
+ @gle = nil
133
+ @str = nil
134
+ end
135
+ end
@@ -1,74 +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(Fixnum, @callback.address)
44
- assert_equal(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
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(Fixnum, @callback.address)
44
+ assert_equal(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
@@ -1,66 +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
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