* transcode.c (econv_primitive_convert): add output_byteoffset
[ruby-svn.git] / test / win32ole / test_win32ole_method.rb
blob161b10233f1afdbb6aa4c43a3d1c8e70d62d8c60
1 begin
2   require 'win32ole'
3 rescue LoadError
4 end
5 require "test/unit"
7 if defined?(WIN32OLE_METHOD)
8   class TestWIN32OLE_METHOD < Test::Unit::TestCase
9     
10     def setup
11       ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
12       @m_open = WIN32OLE_METHOD.new(ole_type, "open")
13       @m_namespace = WIN32OLE_METHOD.new(ole_type, "namespace")
14       @m_parent = WIN32OLE_METHOD.new(ole_type, "parent")
15       @m_invoke = WIN32OLE_METHOD.new(ole_type, "invoke")
16       @m_browse_for_folder = WIN32OLE_METHOD.new(ole_type, "BrowseForFolder")
18       ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "File")
19       @m_file_name = WIN32OLE_METHOD.new(ole_type, "name")
21       ole_type = WIN32OLE_TYPE.new("Microsoft Internet Controls", "WebBrowser")
22       @m_navigate_complete = WIN32OLE_METHOD.new(ole_type, "NavigateComplete")
23     end
25     def test_initialize
26       ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
27       assert_raise(ArgumentError) {
28         method = WIN32OLE_METHOD.new("foo")
29       }
30       assert_raise(ArgumentError) {
31         method = WIN32OLE_METHOD.new(ole_type)
32       }
33       assert_raise(WIN32OLERuntimeError) {
34         method = WIN32OLE_METHOD.new(ole_type, "NonExistMethod")
35       }
36       assert_raise(TypeError) {
37         method = WIN32OLE_METHOD.new(ole_type, 1)
38       }
39       method  = WIN32OLE_METHOD.new(ole_type, "Open")
40       assert_instance_of(WIN32OLE_METHOD, method)
41       method  = WIN32OLE_METHOD.new(ole_type, "open")
42       assert_instance_of(WIN32OLE_METHOD, method)
43     end
45     def test_name
46       assert_equal("Open", @m_open.name)
47     end
49     def test_return_type
50       assert_equal("VOID", @m_open.return_type)
51       assert_equal("Folder", @m_namespace.return_type)
52     end
54     def test_return_vtype
55       assert_equal(24, @m_open.return_vtype)
56       assert_equal(26, @m_namespace.return_vtype)
57     end
59     def test_return_type_detail
60       assert_equal(['VOID'], @m_open.return_type_detail)
61       assert_equal(['PTR', 'USERDEFINED', 'Folder'], @m_namespace.return_type_detail)
62     end
64     def test_invoke_kind
65       assert_equal('FUNC', @m_open.invoke_kind)
66       assert_equal('FUNC', @m_namespace.invoke_kind)
67       assert_equal('PROPERTYGET', @m_parent.invoke_kind)
68     end
70     def test_invkind
71       assert_equal(1, @m_namespace.invkind)
72       assert_equal(2, @m_parent.invkind)
73     end
75     def test_visible?
76       assert(@m_namespace.visible?)
77       assert(!@m_invoke.visible?)
78     end
80     def test_event?
81       assert(@m_navigate_complete.event?)
82       assert(!@m_namespace.event?)
83     end
85     def test_event_interface
86       assert_equal("DWebBrowserEvents", @m_navigate_complete.event_interface)
87       assert_equal(nil, @m_namespace.event_interface)
88     end
90     def test_helpstring
91       assert_equal("Get special folder from ShellSpecialFolderConstants", @m_namespace.helpstring)
92     end
94     def test_helpfile
95       assert_equal("", @m_namespace.helpfile)
96       assert_match(/VBENLR.*\.CHM$/i, @m_file_name.helpfile)
97     end
99     def test_helpcontext
100       assert_equal(0, @m_namespace.helpcontext)
101       assert_equal(2181996, @m_file_name.helpcontext)
102     end
104     def test_dispid
105       assert_equal(1610743810, @m_namespace.dispid)
106     end
108     def test_offset_vtbl
109       assert_equal(24, @m_invoke.offset_vtbl)
110     end
112     def test_size_params
113       assert_equal(1, @m_open.size_params)
114       assert_equal(4, @m_browse_for_folder.size_params)
115     end
117     def test_size_opt_params
118       assert_equal(0, @m_open.size_opt_params)
119       assert_equal(1, @m_browse_for_folder.size_opt_params)
120     end
122     def test_params
123       params = @m_browse_for_folder.params
124       assert_instance_of(Array, params)
125       assert_equal(4, params.size) 
126       assert_instance_of(WIN32OLE_PARAM, params[0])
127     end
129     def test_to_s
130       assert_equal(@m_namespace.name, @m_namespace.to_s)
131     end
133     def test_inspect
134       assert_equal("#<WIN32OLE_METHOD:NameSpace>", @m_namespace.inspect)
135     end
137   end