win32-api 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,2 +1,8 @@
1
+ = 1.0.1 - 27-Sep-2007
2
+ * Functions declared with a void prototype no longer require an explicit nil
3
+ argument to fulfill the arity requirement. You can still call them with an
4
+ explicit nil if you wish, however.
5
+ * Fixed the gemspec for the native build.
6
+
1
7
  = 1.0.0 - 14-Sep-2007
2
8
  * Initial release
data/ext/win32/api.c CHANGED
@@ -2,7 +2,7 @@
2
2
  #include <windows.h>
3
3
 
4
4
  #define MAX_BUF 1024
5
- #define WINDOWS_API_VERSION "1.0.0"
5
+ #define WINDOWS_API_VERSION "1.0.1"
6
6
 
7
7
  #define _T_VOID 0
8
8
  #define _T_LONG 1
@@ -69,8 +69,20 @@ char* StringError(DWORD dwError){
69
69
  static VALUE callback_init(int argc, VALUE* argv, VALUE self)
70
70
  {
71
71
  VALUE v_proto, v_return, v_proc;
72
+ int i;
72
73
 
73
74
  rb_scan_args(argc, argv, "11", &v_proto, &v_return);
75
+
76
+ /* Validate prototype characters */
77
+ for(i = 0; i < RSTRING(v_proto)->len; i++){
78
+ switch(RSTRING(v_proto)->ptr[i]){
79
+ case 'I': case 'L': case 'P': case 'V':
80
+ break;
81
+ default:
82
+ rb_raise(cCallbackError, "Illegal prototype '%c'",
83
+ RSTRING(v_proto)->ptr[i]);
84
+ }
85
+ }
74
86
 
75
87
  if(NIL_P(v_return) || RARRAY(v_return)->len == 0)
76
88
  v_return = rb_str_new2("L");
@@ -305,7 +317,7 @@ DWORD CallbackFunction(PARAM param)
305
317
  argv[i] = INT2NUM(param.params[i]);
306
318
  break;
307
319
  default:
308
- rb_raise(cCallbackError, "Illegal prototype '%s'", a_proto[i]);
320
+ rb_raise(cCallbackError, "Illegal prototype '%c'", a_proto[i]);
309
321
  }
310
322
  }
311
323
 
@@ -373,10 +385,19 @@ static VALUE api_call(int argc, VALUE* argv, VALUE self){
373
385
 
374
386
  v_proto = rb_iv_get(self, "@prototype");
375
387
 
376
- if(RARRAY(v_proto)->len != RARRAY(v_args)->len)
377
- rb_raise(rb_eArgError, "wrong number of parameters: expected %d, got %d",
378
- RARRAY(v_proto)->len, RARRAY(v_args)->len
379
- );
388
+ /* For void prototypes, allow either no args or an explicit nil */
389
+ if(RARRAY(v_proto)->len != RARRAY(v_args)->len){
390
+ char* c = StringValuePtr(RARRAY(v_proto)->ptr[0]);
391
+ if(!strcmp(c, "V")){
392
+ rb_ary_push(v_args, Qnil);
393
+ }
394
+ else{
395
+ rb_raise(rb_eArgError,
396
+ "wrong number of parameters: expected %d, got %d",
397
+ RARRAY(v_proto)->len, RARRAY(v_args)->len
398
+ );
399
+ }
400
+ }
380
401
 
381
402
  for(i = 0; i < RARRAY(v_proto)->len; i++){
382
403
  v_arg = RARRAY(v_args)->ptr[i];
data/test/tc_win32_api.rb CHANGED
@@ -12,10 +12,11 @@ class TC_Win32_API < Test::Unit::TestCase
12
12
  def setup
13
13
  @buf = 0.chr * 260
14
14
  @api = API.new('GetCurrentDirectory', 'LP')
15
+ @gle = API.new('GetLastError', 'V', 'L')
15
16
  end
16
17
 
17
18
  def test_version
18
- assert_equal('1.0.0', API::VERSION)
19
+ assert_equal('1.0.1', API::VERSION)
19
20
  end
20
21
 
21
22
  def test_call
@@ -24,6 +25,11 @@ class TC_Win32_API < Test::Unit::TestCase
24
25
  assert_equal(Dir.pwd.tr('/', "\\"), @buf.strip)
25
26
  end
26
27
 
28
+ def test_call_with_void
29
+ assert_nothing_raised{ @gle.call }
30
+ assert_nothing_raised{ @gle.call(nil) }
31
+ end
32
+
27
33
  def test_dll_name
28
34
  assert_respond_to(@api, :dll_name)
29
35
  assert_equal('kernel32', @api.dll_name)
@@ -57,5 +63,6 @@ class TC_Win32_API < Test::Unit::TestCase
57
63
  def teardown
58
64
  @buf = nil
59
65
  @api = nil
66
+ @gle = nil
60
67
  end
61
68
  end
@@ -1,58 +1,58 @@
1
- ############################################################################
2
- # tc_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 'win32/api'
8
- require 'test/unit'
9
- include Win32
10
-
11
- class TC_Win32_API_Callback < Test::Unit::TestCase
12
- def setup
13
- @buffer = 0.chr * 260
14
- @api_ew = API.new('EnumWindows', 'KP', 'L', 'user32')
15
- @api_gwt = API.new('GetWindowText', 'LPI', 'I', 'user32')
16
- @callback = nil
17
- end
18
-
19
- def test_constructor
20
- assert_respond_to(API::Callback, :new)
21
- assert_nothing_raised{ API::Callback.new('LP', 'I') }
22
- assert_nothing_raised{ API::Callback.new('LP', 'I'){} }
23
- end
24
-
25
- def test_prototype
26
- assert_nothing_raised{ @callback = API::Callback.new('LP', 'I') }
27
- assert_respond_to(@callback, :prototype)
28
- assert_equal('LP', @callback.prototype)
29
- end
30
-
31
- def test_return_value
32
- assert_nothing_raised{ @callback = API::Callback.new('LP', 'I') }
33
- assert_respond_to(@callback, :return_type)
34
- assert_equal('I', @callback.return_type)
35
- end
36
-
37
- def test_callback
38
- assert_nothing_raised{
39
- @callback = API::Callback.new('LP', 'I'){ |handle, param|
40
- buf = "\0" * 200
41
- @api_gwt.call(handle, buf, 200);
42
- buf.index(param).nil? ? true : false
43
- }
44
- }
45
- assert_nothing_raised{ @api_ew.call(@callback, 'UEDIT32') }
46
- end
47
-
48
- def test_constructor_expected_errors
49
- assert_raise(API::Callback::Error){ API::Callback.new('X') }
50
- end
51
-
52
- def teardown
53
- @buffer = nil
54
- @api_ew = nil
55
- @api_gwt = nil
56
- @callback = nil
57
- end
1
+ ############################################################################
2
+ # tc_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 'win32/api'
8
+ require 'test/unit'
9
+ include Win32
10
+
11
+ class TC_Win32_API_Callback < Test::Unit::TestCase
12
+ def setup
13
+ @buffer = 0.chr * 260
14
+ @api_ew = API.new('EnumWindows', 'KP', 'L', 'user32')
15
+ @api_gwt = API.new('GetWindowText', 'LPI', 'I', 'user32')
16
+ @callback = nil
17
+ end
18
+
19
+ def test_constructor
20
+ assert_respond_to(API::Callback, :new)
21
+ assert_nothing_raised{ API::Callback.new('LP', 'I') }
22
+ assert_nothing_raised{ API::Callback.new('LP', 'I'){} }
23
+ end
24
+
25
+ def test_prototype
26
+ assert_nothing_raised{ @callback = API::Callback.new('LP', 'I') }
27
+ assert_respond_to(@callback, :prototype)
28
+ assert_equal('LP', @callback.prototype)
29
+ end
30
+
31
+ def test_return_value
32
+ assert_nothing_raised{ @callback = API::Callback.new('LP', 'I') }
33
+ assert_respond_to(@callback, :return_type)
34
+ assert_equal('I', @callback.return_type)
35
+ end
36
+
37
+ def test_callback
38
+ assert_nothing_raised{
39
+ @callback = API::Callback.new('LP', 'I'){ |handle, param|
40
+ buf = "\0" * 200
41
+ @api_gwt.call(handle, buf, 200);
42
+ buf.index(param).nil? ? true : false
43
+ }
44
+ }
45
+ assert_nothing_raised{ @api_ew.call(@callback, 'UEDIT32') }
46
+ end
47
+
48
+ def test_constructor_expected_errors
49
+ assert_raise(API::Callback::Error){ API::Callback.new('X') }
50
+ end
51
+
52
+ def teardown
53
+ @buffer = nil
54
+ @api_ew = nil
55
+ @api_gwt = nil
56
+ @callback = nil
57
+ end
58
58
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: win32-api
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.0
7
- date: 2007-09-14 00:00:00 -06:00
6
+ version: 1.0.1
7
+ date: 2007-09-27 00:00:00 -06:00
8
8
  summary: A superior replacement for Win32API
9
9
  require_paths:
10
10
  - lib
@@ -31,12 +31,12 @@ authors:
31
31
  files:
32
32
  - ext/extconf.rb
33
33
  - ext/win32
34
+ - ext/win32/api.c
34
35
  - test/tc_win32_api.rb
35
36
  - test/tc_win32_api_callback.rb
36
37
  - README
37
38
  - CHANGES
38
39
  - MANIFEST
39
- - ext/win32/api.c
40
40
  test_files:
41
41
  - test/tc_win32_api.rb
42
42
  - test/tc_win32_api_callback.rb