win32-api 1.4.5-x86-mswin32-60 → 1.4.6-x86-mswin32-60
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.
- data/CHANGES +132 -125
- data/MANIFEST +9 -9
- data/README +101 -103
- data/Rakefile +105 -120
- data/ext/win32/api.c +946 -948
- data/lib/win32/api.so +0 -0
- data/test/test_win32_api.rb +140 -140
- data/test/test_win32_api_callback.rb +74 -74
- data/test/test_win32_api_function.rb +66 -66
- data/win32-api.gemspec +29 -31
- metadata +16 -8
- data/ext/extconf.rb +0 -11
    
        data/lib/win32/api.so
    CHANGED
    
    | Binary file | 
    
        data/test/test_win32_api.rb
    CHANGED
    
    | @@ -1,140 +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
         | 
| 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
         | 
| @@ -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 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 20 | 
            -
             | 
| 21 | 
            -
               
         | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
               
         | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
               
         | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
               
         | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
               
         | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 73 | 
            -
             | 
| 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(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
         | 
| @@ -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
         |