* transcode.c (econv_primitive_convert): add output_byteoffset
[ruby-svn.git] / test / win32ole / test_win32ole_type.rb
blobf8ea525ea9c83d552c8dfc705181c375576575c3
1 begin
2   require 'win32ole'
3 rescue LoadError
4 end
5 require "test/unit"
7 if defined?(WIN32OLE_TYPE)
8   class TestWIN32OLE_TYPE < Test::Unit::TestCase
10     def test_s_progids
11       progids = WIN32OLE_TYPE.progids
12       assert_instance_of(Array, progids)
13       assert(progids.size > 0)
14       assert_instance_of(String, progids[0])
15       assert(progids.include?("Shell.Application.1"))
16     end
18     def test_initialize
19       assert_raise(ArgumentError) {
20         WIN32OLE_TYPE.new
21       }
22       assert_raise(ArgumentError) {
23         WIN32OLE_TYPE.new("foo")
24       }
25       assert_raise(TypeError) {
26         WIN32OLE_TYPE.new(1, 2)
27       }
28       assert_raise(TypeError) {
29         WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", 1)
30       }
31       assert_raise(WIN32OLERuntimeError) {
32         WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "foo")
33       }
34       assert_raise(WIN32OLERuntimeError) {
35         WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Application")
36       }
37       ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
38       assert_instance_of(WIN32OLE_TYPE, ole_type)
39       assert_equal("Shell", ole_type.name)
40       assert_equal("Class", ole_type.ole_type)
41       assert_equal("{13709620-C279-11CE-A49E-444553540000}", ole_type.guid)
42       assert_equal("Shell.Application.1", ole_type.progid)
43       assert_equal(true, ole_type.visible?)
44       assert_equal("Shell", ole_type.to_s)
45       assert_equal(0, ole_type.major_version)
46       assert_equal(0, ole_type.minor_version)
47       assert_equal(5, ole_type.typekind)
48       assert_equal("Shell Object Type Information", ole_type.helpstring)
49       assert_equal(nil, ole_type.src_type)
50       assert_equal("", ole_type.helpfile)
51       assert_equal(0, ole_type.helpcontext)
52       assert_equal([], ole_type.variables)
53       assert(ole_type.ole_methods.select{|m|/NameSpace/i =~ m.name}.size > 0)
54       
55       ole_type2 = WIN32OLE_TYPE.new("{13709620-C279-11CE-A49E-444553540000}", "Shell")
56       assert_instance_of(WIN32OLE_TYPE, ole_type)
57       assert_equal(ole_type.name, ole_type2.name)
58       assert_equal(ole_type.ole_type, ole_type2.ole_type)
59       assert_equal(ole_type.guid, ole_type2.guid)
60       assert_equal(ole_type.progid, ole_type2.progid)
61       assert_equal(ole_type.visible?, ole_type2.visible?)
62       assert_equal(ole_type.to_s, ole_type2.to_s)
63       assert_equal(ole_type.major_version, ole_type2.major_version)
64       assert_equal(ole_type.minor_version, ole_type2.minor_version)
65       assert_equal(ole_type.typekind, ole_type2.typekind)
66       assert_equal(ole_type.helpstring, ole_type2.helpstring)
67       assert_equal(ole_type.src_type, ole_type2.src_type)
68       assert_equal(ole_type.helpfile, ole_type2.helpfile)
69       assert_equal(ole_type.helpcontext, ole_type2.helpcontext)
70       assert_equal(ole_type.variables.size, ole_type2.variables.size)
71       assert_equal(ole_type.ole_methods[0].name, ole_type2.ole_methods[0].name)
72       assert_equal(ole_type.ole_typelib.name, ole_type2.ole_typelib.name)
73       assert_equal(ole_type.implemented_ole_types.size, ole_type2.implemented_ole_types.size)
74       assert_equal(ole_type.inspect, ole_type2.inspect)
75     end
77     def setup
78       @ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "Shell")
79     end
81     def test_name
82       assert_equal("Shell", @ole_type.name)
83     end
85     def test_ole_type
86       assert_equal("Class", @ole_type.ole_type)
87     end
89     def test_guid
90       assert_equal("{13709620-C279-11CE-A49E-444553540000}", @ole_type.guid)
91     end
93     def test_progid
94       assert_equal("Shell.Application.1", @ole_type.progid)
95     end
97     def test_visible?
98       assert(@ole_type.visible?)
99       ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "IShellDispatch")
100       assert(!ole_type.visible?)
101     end
103     def test_to_s
104       assert_equal(@ole_type.to_s, @ole_type.name)
105     end
107     def test_major_version
108       assert_equal(0, @ole_type.major_version)
109       # ole_type = WIN32OLE_TYPE.new("Microsoft Word 11.0 Object Library", "Documents")
110       # assert_equal(8, ole_type.major_version)
111     end
113     def test_minor_version
114       assert_equal(0, @ole_type.minor_version)
115       # ole_type = WIN32OLE_TYPE.new("Microsoft Word 11.0 Object Library", "Documents")
116       # assert_equal(3, ole_type.minor_version)
117     end
119     def test_typekind
120       assert_equal(5, @ole_type.typekind)
121     end
123     def test_helpstring
124       assert_equal("Shell Object Type Information", @ole_type.helpstring)
125     end
127     def test_src_type
128       ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "DriveTypeConst")
129       assert_match(/__MIDL___MIDL_itf_scrrun_/, ole_type.src_type)
130       assert_equal(nil, @ole_type.src_type)
131     end
133     def test_helpfile
134       assert_equal("", @ole_type.helpfile)
135       ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "Folders")
136       assert_match(/VBENLR98\.CHM$/i, ole_type.helpfile)
137     end
139     def test_helpcontext
140       assert_equal(0, @ole_type.helpcontext)
141       ole_type = WIN32OLE_TYPE.new("Microsoft Scripting Runtime", "Folders")
142       assert_equal(2181929, ole_type.helpcontext)
143     end
145     def test_variables
146       variables = @ole_type.variables
147       assert_instance_of(Array, variables)
148       assert(variables.size == 0)
150       ole_type = WIN32OLE_TYPE.new("Microsoft Shell Controls And Automation", "ShellSpecialFolderConstants")
151       variables = ole_type.variables
152       assert_instance_of(Array, variables)
153       assert(variables.size > 0)
155       assert_instance_of(WIN32OLE_VARIABLE, variables[0])
156     end
158     def test_ole_methods
159       methods = @ole_type.ole_methods
160       assert_instance_of(Array, methods)
161       assert(methods.size > 0)
162       assert_instance_of(WIN32OLE_METHOD, methods[0]);
163       assert(methods.collect{|m| m.name}.include?("Application"))
164     end
166     def test_ole_typelib
167       tlib = @ole_type.ole_typelib
168       assert_instance_of(WIN32OLE_TYPELIB, tlib)
169       assert_equal("Microsoft Shell Controls And Automation", tlib.name)
170     end
172     def test_implemented_ole_types
173       ole_types = @ole_type.implemented_ole_types
174       assert_instance_of(Array, ole_types)
175       assert_equal(1, ole_types.size)
176       assert_match(/^IShellDispatch5{0,1}$/, ole_types[0].name)
178       ie_otype = WIN32OLE_TYPE.new("Microsoft Internet Controls", "InternetExplorer")
179       ole_types = ie_otype.implemented_ole_types
180       assert_equal(4, ole_types.size)
181       otype = ole_types.select{|t| t.name == "IWebBrowser2"}
182       assert_equal(1, otype.size)
183       otype = ole_types.select{|t| t.name == "IWebBrowserApp"}
184       assert_equal(1, otype.size)
185       otype = ole_types.select{|t| t.name == "DWebBrowserEvents2"}
186       assert_equal(1, otype.size)
187       otype = ole_types.select{|t| t.name == "DWebBrowserEvents"}  
188       assert_equal(1, otype.size)
189     end
191     def test_default_ole_types
192       ie_otype = WIN32OLE_TYPE.new("Microsoft Internet Controls", "InternetExplorer")
193       ole_types = ie_otype.default_ole_types
194       otype = ole_types.select{|t| t.name == "IWebBrowser2"}
195       assert_equal(1, otype.size)
196       otype = ole_types.select{|t| t.name == "IWebBrowserApp"}
197       assert_equal(0, otype.size)
198       otype = ole_types.select{|t| t.name == "DWebBrowserEvents2"}
199       assert_equal(1, otype.size)
200       otype = ole_types.select{|t| t.name == "DWebBrowserEvents"}  
201       assert_equal(0, otype.size)
202     end
204     def test_source_ole_types
205       ie_otype = WIN32OLE_TYPE.new("Microsoft Internet Controls", "InternetExplorer")
206       ole_types = ie_otype.source_ole_types
207       otype = ole_types.select{|t| t.name == "IWebBrowser2"}
208       assert_equal(0, otype.size)
209       otype = ole_types.select{|t| t.name == "IWebBrowserApp"}
210       assert_equal(0, otype.size)
211       otype = ole_types.select{|t| t.name == "DWebBrowserEvents2"}
212       assert_equal(1, otype.size)
213       otype = ole_types.select{|t| t.name == "DWebBrowserEvents"}  
214       assert_equal(1, otype.size)
215     end
217     def test_default_event_sources
218       ie_otype = WIN32OLE_TYPE.new("Microsoft Internet Controls", "InternetExplorer")
219       ole_types = ie_otype.default_event_sources
220       otype = ole_types.select{|t| t.name == "IWebBrowser2"}
221       assert_equal(0, otype.size)
222       otype = ole_types.select{|t| t.name == "IWebBrowserApp"}
223       assert_equal(0, otype.size)
224       otype = ole_types.select{|t| t.name == "DWebBrowserEvents2"}
225       assert_equal(1, otype.size)
226       otype = ole_types.select{|t| t.name == "DWebBrowserEvents"}  
227       assert_equal(0, otype.size)
228     end
230     def test_inspect
231       assert_equal("#<WIN32OLE_TYPE:Shell>", @ole_type.inspect)
232     end
233     # WIN32OLE_TYPE.typelibs will be obsoleted.
234     def test_s_typelibs
235       tlibs = WIN32OLE_TYPE.typelibs.sort
236       tlibs2 = WIN32OLE_TYPELIB.typelibs.collect{|t|t.name}.sort
237       assert_equal(tlibs2, tlibs)
238     end
240     # WIN32OLE_TYPE.ole_classes will be obsoleted.
241     def test_s_ole_classes
242       ots1 = WIN32OLE_TYPE.ole_classes("Microsoft Shell Controls And Automation")
243       ots2 = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation").ole_types
244       otns1 = ots1.collect{|t| t.name}.sort
245       otns2 = ots2.collect{|t| t.name}.sort
246       assert_equal(otns2, otns1)
247     end
248   end